From 9bff2cafc2aab7ec010cdd26883e0b66ccb53f26 Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Thu, 7 Nov 2024 07:13:23 -0700 Subject: [PATCH] Add next-view and previous-view keybindings --- lisp/group.lisp | 26 +++++++++++++++++++++++++- lisp/key-bindings.lisp | 14 ++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lisp/group.lisp b/lisp/group.lisp index 2157e6f..4b99bb6 100644 --- a/lisp/group.lisp +++ b/lisp/group.lisp @@ -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)))) diff --git a/lisp/key-bindings.lisp b/lisp/key-bindings.lisp index 16fe434..ee40c82 100644 --- a/lisp/key-bindings.lisp +++ b/lisp/key-bindings.lisp @@ -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 @@ -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))))