Skip to content

Commit

Permalink
Add next-view and previous-view keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sdilts committed Nov 7, 2024
1 parent abf9147 commit 8035635
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lisp/group.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,35 @@ to match."
(go :top)))))))

(defun group-maximize-current-frame (group)
"Remove all of the splits in the current window tree and replae it with the
currently focused frame"
(declare (type mahogany-group group))
(let* ((current-frame (mahogany-group-current-frame group))
(container (mahogany/tree:find-frame-container current-frame))
(tree-root (tree:root-tree container)))
(flet ((hide-and-disable (view-frame)
(alexandria:when-let (view (tree:frame-view view-frame))
(alexandria:when-let ((view (tree:frame-view view-frame)))
(ring-list:add-item (mahogany-group-hidden-views group) view))))
(tree:replace-frame tree-root current-frame #'hide-and-disable))))

(defun group-next-hidden (group)
(declare (type mahogany-group group))
(let ((current-frame (mahogany-group-current-frame group))
(hidden-views (mahogany-group-hidden-views group))
(next-view))
(when (> (ring-list:ring-list-size hidden-views) 0)
(alexandria:if-let ((view (tree:frame-view current-frame)))
(setf next-view (ring-list:swap-next hidden-views view))
(setf next-view (ring-list:pop-item hidden-views)))
(setf (tree:frame-view current-frame) next-view))))

(defun group-previous-hidden (group)
(declare (type mahogany-group group))
(let ((current-frame (mahogany-group-current-frame group))
(hidden-views (mahogany-group-hidden-views group))
(next-view))
(when (> (ring-list:ring-list-size hidden-views) 0)
(alexandria:if-let ((view (tree:frame-view current-frame)))
(setf next-view (ring-list:swap-previous hidden-views view))
(setf next-view (ring-list:pop-item-prev hidden-views)))
(setf (tree:frame-view current-frame) next-view))))
14 changes: 14 additions & 0 deletions lisp/key-bindings.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
(let ((group (mahogany-current-group *compositor-state*)))
(group-maximize-current-frame group)))

(defun next-view (sequence seat)
"Raise the next hidden view in the current group"
(declare (ignore sequence seat))
(let ((group (mahogany-current-group *compositor-state*)))
(group-next-hidden group)))

(defun previous-view (sequence seat)
"Raise the next hidden view in the current group"
(declare (ignore sequence seat))
(let ((group (mahogany-current-group *compositor-state*)))
(group-previous-hidden group)))

(setf (mahogany-state-keybindings *compositor-state*)
(list (define-kmap
(kbd "C-t") (define-kmap
Expand All @@ -37,4 +49,6 @@
(kbd "s") #'split-frame-v
(kbd "S") #'split-frame-h
(kbd "Q") #'maximize-current-frame
(kbd "n") #'next-view
(kbd "p") #'previous-view
(kbd "+") #'open-kcalc))))

0 comments on commit 8035635

Please sign in to comment.