Skip to content

Commit

Permalink
Properly hide views when they aren't on top
Browse files Browse the repository at this point in the history
  • Loading branch information
sdilts committed Nov 7, 2024
1 parent 9bff2ca commit f54cc72
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
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
37 changes: 29 additions & 8 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 @@ -111,8 +132,8 @@ currently focused frame"
(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)
Expand All @@ -122,8 +143,8 @@ currently focused frame"
(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 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)
Expand All @@ -133,6 +154,6 @@ currently focused frame"
(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 next-view (%swap-prev-hidden hidden-views view))
(setf next-view (%pop-hidden-item hidden-views)))
(setf (tree:frame-view current-frame) next-view))))

0 comments on commit f54cc72

Please sign in to comment.