Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to scroll through hidden views #79

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions heart/include/hrt/hrt_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ void hrt_view_focus(struct hrt_view *view, struct hrt_seat *seat);
**/
void hrt_view_unfocus(struct hrt_view *view, struct hrt_seat *seat);

/**
* Stop the given view from being displayed
**/
void hrt_view_set_hidden(struct hrt_view *view, bool hidden);


#endif
4 changes: 4 additions & 0 deletions heart/src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ void hrt_view_unfocus(struct hrt_view *view, struct hrt_seat *seat) {
wlr_xdg_toplevel_set_activated(toplevel, false);
wlr_seat_keyboard_notify_clear_focus(seat->seat);
}

void hrt_view_set_hidden(struct hrt_view *view, bool hidden) {
wlr_scene_node_set_enabled(&view->scene_tree->node, !hidden);
}
5 changes: 5 additions & 0 deletions lisp/bindings/hrt-bindings.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ it visible to the user."
(view (:pointer (:struct hrt-view)))
(seat (:pointer (:struct hrt-seat))))

(cffi:defcfun ("hrt_view_set_hidden" hrt-view-set-hidden) :void
"Stop the given view from being displayed"
(view (:pointer (:struct hrt-view)))
(hidden :bool))

;; next section imported from file build/include/hrt/hrt_output.h

(cffi:defcstruct hrt-output
Expand Down
1 change: 1 addition & 0 deletions lisp/bindings/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#:view-hrt-view
#:focus-view
#:unfocus-view
#:view-set-hidden
;; seat callbacks
#:button-event #:wheel-event #:keyboard-keypress-event
#:hrt-server
Expand Down
6 changes: 6 additions & 0 deletions lisp/bindings/wrappers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
(declare (type view view))
(hrt-view-unfocus (view-hrt-view view) seat))

(declaim (inline view-set-hidden))
(defun view-set-hidden (view hidden)
(declare (type view view)
(type boolean hidden))
(hrt-view-set-hidden (view-hrt-view view) hidden))

(defmethod mh/interface:set-dimensions ((view view) width height)
(hrt-view-set-size (view-hrt-view view) width height))

Expand Down
53 changes: 49 additions & 4 deletions lisp/group.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ to match."
(when (and (mahogany-group-current-frame group) (= 0 (hash-table-count output-map)))
(group-unfocus-frame group (mahogany-group-current-frame group) seat)))))

(defun %add-hidden (hidden-list view)
(ring-list:add-item hidden-list view)
(hrt:view-set-hidden view t))

(defun %swap-next-hidden (hidden-list view)
(let ((swapped (ring-list:swap-next hidden-list view)))
(hrt:view-set-hidden view t)
(hrt:view-set-hidden swapped nil)
swapped))

(defun %swap-prev-hidden (hidden-list view)
(let ((swapped (ring-list:swap-previous hidden-list view)))
(hrt:view-set-hidden view t)
(hrt:view-set-hidden swapped nil)
swapped))

(defun %pop-hidden-item (hidden-list)
(alexandria:when-let ((popped (ring-list:pop-item hidden-list)))
(hrt:view-set-hidden popped nil)
popped))

(defun group-add-view (group view)
(declare (type mahogany-group group)
(type hrt:view view))
Expand All @@ -72,7 +93,7 @@ to match."
(push view (mahogany-group-views group))
(alexandria:when-let ((current-frame (mahogany-group-current-frame group)))
(alexandria:when-let ((view (tree:frame-view current-frame)))
(ring-list:add-item hidden view))
(%add-hidden hidden view))
(setf (tree:frame-view current-frame) view))))

(defun group-remove-view (group view)
Expand All @@ -87,7 +108,7 @@ to match."
(dolist (f (mahogany/tree:get-populated-frames (mahogany/tree:root-tree container)))
(when (equalp (tree:frame-view f) view)
(setf (tree:frame-view f) nil)
(alexandria:when-let ((new-view (ring-list:pop-item hidden)))
(alexandria:when-let ((new-view (%pop-hidden-item hidden)))
(setf (tree:frame-view f) new-view)))))
output-map)
(ring-list:remove-item hidden view)
Expand All @@ -104,11 +125,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))
(ring-list:add-item (mahogany-group-hidden-views group) view))))
(alexandria:when-let ((view (tree:frame-view view-frame)))
(%add-hidden (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 (%swap-next-hidden hidden-views view))
(setf next-view (%pop-hidden-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 (%swap-prev-hidden hidden-views view))
(setf next-view (%pop-hidden-item 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))))
9 changes: 9 additions & 0 deletions lisp/ring-list/ring-list.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#:add-item
#:remove-item
#:pop-item
#:pop-item-prev
#:swap-next
#:swap-previous
#:swap-next-find
Expand Down Expand Up @@ -83,6 +84,14 @@ found and removed"
(%remove-item ring-list head)
(ring-item-item head))))

(defun pop-item-prev (ring-list)
(declare (type ring-list ring-list))
(let ((head (ring-item-prev (ring-list-head ring-list))))
(when head
(let ((prev (ring-item-prev head)))
(%remove-item ring-list prev)
(ring-item-item prev)))))

(defun %swap-find (ring-list item test swap-fn)
(declare (type ring-list ring-list)
(type (function (ring-list t) t) swap-fn)
Expand Down
Loading