]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/layers.c: delay popup unconstrain until after first commit
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 24 Feb 2024 22:05:02 +0000 (23:05 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 25 Feb 2024 11:49:03 +0000 (11:49 +0000)
Fixes: #1372
include/layers.h
src/layers.c

index d64c434fb07c5ed0710d654a2fc4715d98811c94..525830358368b106c46a8758384e23a92a7e912f 100644 (file)
@@ -28,6 +28,7 @@ struct lab_layer_popup {
        /* To simplify moving popup nodes from the bottom to the top layer */
        struct wlr_box output_toplevel_sx_box;
 
+       struct wl_listener commit;
        struct wl_listener destroy;
        struct wl_listener new_popup;
 };
index 79cffe94356b875bef4ef0b6d9378df9cfc72383..20e9e6838fb7f36a4317649ba999d4b172c74331 100644 (file)
@@ -260,14 +260,35 @@ popup_handle_destroy(struct wl_listener *listener, void *data)
                wl_container_of(listener, popup, destroy);
        wl_list_remove(&popup->destroy.link);
        wl_list_remove(&popup->new_popup.link);
+
+       /* Usually already removed unless there was no commit at all */
+       if (popup->commit.notify) {
+               wl_list_remove(&popup->commit.link);
+       }
+
        free(popup);
 }
 
+static void
+popup_handle_commit(struct wl_listener *listener, void *data)
+{
+       struct lab_layer_popup *popup =
+               wl_container_of(listener, popup, commit);
+
+       if (popup->wlr_popup->base->initial_commit) {
+               wlr_xdg_popup_unconstrain_from_box(popup->wlr_popup,
+                       &popup->output_toplevel_sx_box);
+
+               /* Prevent getting called over and over again */
+               wl_list_remove(&popup->commit.link);
+               popup->commit.notify = NULL;
+       }
+}
+
 static void popup_handle_new_popup(struct wl_listener *listener, void *data);
 
 static struct lab_layer_popup *
-create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_tree *parent,
-               struct wlr_box *output_toplevel_sx_box)
+create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_tree *parent)
 {
        struct lab_layer_popup *popup = znew(*popup);
        popup->wlr_popup = wlr_popup;
@@ -282,10 +303,13 @@ create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_tree *parent,
 
        popup->destroy.notify = popup_handle_destroy;
        wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
+
        popup->new_popup.notify = popup_handle_new_popup;
        wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
 
-       wlr_xdg_popup_unconstrain_from_box(wlr_popup, output_toplevel_sx_box);
+       popup->commit.notify = popup_handle_commit;
+       wl_signal_add(&wlr_popup->base->surface->events.commit, &popup->commit);
+
        return popup;
 }
 
@@ -297,8 +321,7 @@ popup_handle_new_popup(struct wl_listener *listener, void *data)
                wl_container_of(listener, lab_layer_popup, new_popup);
        struct wlr_xdg_popup *wlr_popup = data;
        struct lab_layer_popup *new_popup = create_popup(wlr_popup,
-               lab_layer_popup->scene_tree,
-               &lab_layer_popup->output_toplevel_sx_box);
+               lab_layer_popup->scene_tree);
        new_popup->output_toplevel_sx_box =
                lab_layer_popup->output_toplevel_sx_box;
 }
@@ -357,8 +380,7 @@ handle_new_popup(struct wl_listener *listener, void *data)
                .width = output_box.width,
                .height = output_box.height,
        };
-       struct lab_layer_popup *popup = create_popup(wlr_popup,
-               surface->tree, &output_toplevel_sx_box);
+       struct lab_layer_popup *popup = create_popup(wlr_popup, surface->tree);
        popup->output_toplevel_sx_box = output_toplevel_sx_box;
 
        if (surface->layer_surface->current.layer