]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Move OSD handler for view destruction to osd.c
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 22 Aug 2022 00:54:40 +0000 (02:54 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 28 Aug 2022 18:40:49 +0000 (20:40 +0200)
include/labwc.h
src/osd.c
src/view.c

index ead723492a520c446cf2467e9b8f8eaa7153d613..c5d78aad23c1a741427090830a7de73c42be21f2 100644 (file)
@@ -583,6 +583,8 @@ void osd_update(struct server *server);
 void osd_finish(struct server *server);
 /* Moves preview views back into their original stacking order and state */
 void osd_preview_restore(struct server *server);
+/* Notify OSD about a destroying view */
+void osd_on_view_destroy(struct view *view);
 
 /*
  * wlroots "input inhibitor" extension (required for swaylock) blocks
index acfdade1fc2e7211a5a8d74db6541ef37ee54335..da6f5028a20e8ce63554928e34f801a7a648174b 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -108,6 +108,52 @@ osd_update_preview_outlines(struct view *view)
        wlr_scene_node_set_position(&rect->tree->node, geo.x, geo.y);
 }
 
+void
+osd_on_view_destroy(struct view *view)
+{
+       assert(view);
+       struct osd_state *osd_state = &view->server->osd_state;
+
+       if (!osd_state->cycle_view) {
+               /* OSD not active, no need for clean up */
+               return;
+       }
+
+       if (osd_state->cycle_view == view) {
+               /*
+                * If we are the current OSD selected view, cycle
+                * to the next because we are dying.
+                */
+               osd_state->cycle_view = desktop_cycle_view(view->server,
+                       osd_state->cycle_view, LAB_CYCLE_DIR_BACKWARD);
+
+               /*
+                * If we cycled back to ourselves, then we have no more windows.
+                * Just close the OSD for good.
+                */
+               if (osd_state->cycle_view == view || !osd_state->cycle_view) {
+                       /* osd_finish() additionally resets cycle_view to NULL */
+                       osd_finish(view->server);
+               }
+       }
+
+       if (view->scene_tree) {
+               struct wlr_scene_node *node = &view->scene_tree->node;
+               if (osd_state->preview_anchor == node) {
+                       /*
+                        * If we are the anchor for the current OSD selected view,
+                        * replace the anchor with the node before us.
+                        */
+                       osd_state->preview_anchor = lab_wlr_scene_get_prev_node(node);
+               }
+       }
+
+       if (osd_state->cycle_view) {
+               /* Update the OSD to reflect the view has now gone. */
+               osd_update(view->server);
+       }
+}
+
 void
 osd_finish(struct server *server)
 {
index fa3a51ca71137ccef46caa440fd9e42da759baf2..68ccd17b7c8c24bafe567f048d7bade6697af542 100644 (file)
@@ -809,41 +809,11 @@ view_destroy(struct view *view)
                server->focused_view = NULL;
        }
 
-       struct osd_state *osd_state = &view->server->osd_state;
-       if (osd_state->cycle_view == view) {
-               /*
-                * If we are the current OSD selected view, cycle
-                * to the next because we are dying.
-                */
-               osd_state->cycle_view = desktop_cycle_view(server,
-                       osd_state->cycle_view, LAB_CYCLE_DIR_BACKWARD);
-
-               /*
-                * If we cycled back to ourselves, then we have no windows.
-                * just remove it and close the OSD for good.
-                */
-               if (osd_state->cycle_view == view || !osd_state->cycle_view) {
-                       /* osd_finish() additionally resets cycle_view to NULL */
-                       osd_finish(server);
-               }
-       }
-
-       if (osd_state->cycle_view) {
-               /* Update the OSD to reflect the view has now gone. */
-               osd_update(server);
-       }
+       osd_on_view_destroy(view);
 
        if (view->scene_tree) {
-               struct wlr_scene_node *node = &view->scene_tree->node;
-               if (osd_state->preview_anchor == node) {
-                       /*
-                        * If we are the anchor for the current OSD selected view,
-                        * replace the anchor with the node before us.
-                        */
-                       osd_state->preview_anchor = lab_wlr_scene_get_prev_node(node);
-               }
                ssd_destroy(view);
-               wlr_scene_node_destroy(node);
+               wlr_scene_node_destroy(&view->scene_tree->node);
                view->scene_tree = NULL;
        }