]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: Refactor view destruction some more
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 23 Apr 2022 01:44:41 +0000 (03:44 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 23 Apr 2022 07:59:06 +0000 (08:59 +0100)
include/labwc.h
src/view.c
src/xdg.c
src/xwayland.c

index 7446348e19f4da02931e7581cba0968afe5650fd..f6430a888e88795352de97a272ebef59ac56464c 100644 (file)
@@ -404,7 +404,7 @@ void view_update_app_id(struct view *view);
 void view_impl_map(struct view *view);
 void view_adjust_size(struct view *view, int *w, int *h);
 
-void view_handle_destroy(struct view *view);
+void view_destroy(struct view *view);
 
 void foreign_toplevel_handle_create(struct view *view);
 
index 6af744c0b7475a6b99d953f6cc55d592199649aa..22e03531198cbbc509a99da5e44398c75d87d2c4 100644 (file)
@@ -653,7 +653,7 @@ view_update_app_id(struct view *view)
 }
 
 void
-view_handle_destroy(struct view *view)
+view_destroy(struct view *view)
 {
        if (view->toplevel_handle) {
                wlr_foreign_toplevel_handle_v1_destroy(view->toplevel_handle);
@@ -671,37 +671,17 @@ view_handle_destroy(struct view *view)
                        view->server->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 (view->server->cycle_view == view) {
+                * just remove it and close the OSD for good. */
+               if (view->server->cycle_view == view || !view->server->cycle_view) {
                        view->server->cycle_view = NULL;
                        osd_finish(view->server);
                }
-       } else if (view->server->cycle_view != NULL) {
-               /* If we have an OSD, but are not the cycled view, just
-                * update the OSD to reflect the view has now gone. */
-               osd_update(view->server);
-       }
-
-       if (view->type == LAB_XDG_SHELL_VIEW) {
-               view->xdg_surface = NULL;
-       }
-#ifdef HAVE_XWAYLAND
-       if (view->type == LAB_XWAYLAND_VIEW) {
-               view->xwayland_surface = NULL;
        }
-#endif 
 
-       wl_list_remove(&view->link);
-       wl_list_remove(&view->destroy.link);
-#ifdef HAVE_XWAYLAND
-       if (view->type == LAB_XWAYLAND_VIEW) {
-               wl_list_remove(&view->map.link);
-               wl_list_remove(&view->unmap.link);
-               wl_list_remove(&view->request_configure.link);
-               wl_list_remove(&view->request_maximize.link);
-               wl_list_remove(&view->request_fullscreen.link);
+       if (view->server->cycle_view) {
+               /* Update the OSD to reflect the view has now gone. */
+               osd_update(view->server);
        }
-#endif
 
        if (view->scene_tree) {
                ssd_destroy(view);
@@ -709,5 +689,7 @@ view_handle_destroy(struct view *view)
                view->scene_tree = NULL;
        }
 
+       /* Remove view from server->views */
+       wl_list_remove(&view->link);
        free(view);
 }
index e9f3179e751c6b8e134875a01bd95cae512c7579..15d4d9c8cc9c9b6a701c278d53553fbdfc002b14 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -78,7 +78,16 @@ static void
 handle_destroy(struct wl_listener *listener, void *data)
 {
        struct view *view = wl_container_of(listener, view, destroy);
-       view_handle_destroy(view);
+       assert(view->type == LAB_XDG_SHELL_VIEW);
+
+       /* Reset XDG specific surface for good measure */
+       view->xdg_surface = NULL;
+
+       /* Remove XDG specific handlers */
+       wl_list_remove(&view->destroy.link);
+
+       /* And finally destroy / free the view */
+       view_destroy(view);
 }
 
 static void
index 65b526969d9d512eaaf694372a38e4425bc4412f..986803be33366d79342b0de396df8ad6570ca530 100644 (file)
@@ -96,7 +96,21 @@ static void
 handle_destroy(struct wl_listener *listener, void *data)
 {
        struct view *view = wl_container_of(listener, view, destroy);
-       view_handle_destroy(view);
+       assert(view->type == LAB_XWAYLAND_VIEW);
+
+       /* Reset XWayland specific surface for good measure */
+       view->xwayland_surface = NULL;
+
+       /* Remove XWayland specific handlers */
+       wl_list_remove(&view->map.link);
+       wl_list_remove(&view->unmap.link);
+       wl_list_remove(&view->request_configure.link);
+       wl_list_remove(&view->request_maximize.link);
+       wl_list_remove(&view->request_fullscreen.link);
+       wl_list_remove(&view->destroy.link);
+
+       /* And finally destroy / free the view */
+       view_destroy(view);
 }
 
 static void