]> git.mdlowis.com Git - proto/labwc.git/commitdiff
desktop: don't use LAB_NODE_LAYER_SUBSURFACE node type
authortokyo4j <hrak1529@gmail.com>
Mon, 8 Sep 2025 17:51:33 +0000 (02:51 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Tue, 9 Sep 2025 09:50:20 +0000 (18:50 +0900)
Instead, set ctx.type = LAB_NODE_LAYER_SURFACE for both layer-surfaces
and layer-subsurfaces.

This patch preserves the existing behaviors:
- Pressing a subsurface of an on-demand layer-surface gives pointer
  focus to the subsurface, but gives keyboard focus to the parent
  layer-surface (related: a5fcbfaf).
- Pressing a subsurface of a layer-surface doesn't close a popup
  (related: a89bcc3c).

include/common/node-type.h
include/common/surface-helpers.h [deleted file]
src/common/meson.build
src/common/surface-helpers.c [deleted file]
src/desktop.c
src/input/cursor.c

index 280a6c59f80222766eea7525e7b6a924c1cbf087..ac83b2b5ad18db048cccfc1bce624878a792bf1e 100644 (file)
@@ -49,7 +49,6 @@ enum lab_node_type {
        LAB_NODE_MENUITEM,
        LAB_NODE_OSD,
        LAB_NODE_LAYER_SURFACE,
-       LAB_NODE_LAYER_SUBSURFACE,
        LAB_NODE_UNMANAGED,
        LAB_NODE_ALL,
 
diff --git a/include/common/surface-helpers.h b/include/common/surface-helpers.h
deleted file mode 100644 (file)
index 1dd7fd7..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef LABWC_SURFACE_HELPERS_H
-#define LABWC_SURFACE_HELPERS_H
-
-struct wlr_surface;
-struct wlr_layer_surface_v1;
-
-/**
- * subsurface_parent_layer() - Get wlr_layer_surface from layer-subsurface
- * @wlr_surface: The wlr_surface of the wlr_subsurface for which to get the
- *               layer-surface.
- */
-struct wlr_layer_surface_v1 *subsurface_parent_layer(
-       struct wlr_surface *wlr_surface);
-
-#endif /* LABWC_SURFACE_HELPERS_H */
index b1087629f3f5b036df5dbda99bba1690ba2f8e82..39b4d4b4dbead4eda081f68100b5136be2154560 100644 (file)
@@ -17,7 +17,6 @@ labwc_sources += files(
   'parse-double.c',
   'scene-helpers.c',
   'set.c',
-  'surface-helpers.c',
   'spawn.c',
   'string-helpers.c',
   'xml.c',
diff --git a/src/common/surface-helpers.c b/src/common/surface-helpers.c
deleted file mode 100644 (file)
index f13a4d6..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-#include "common/surface-helpers.h"
-#include <wlr/types/wlr_layer_shell_v1.h>
-#include <wlr/types/wlr_subcompositor.h>
-#include <wlr/util/log.h>
-
-struct wlr_layer_surface_v1 *
-subsurface_parent_layer(struct wlr_surface *wlr_surface)
-{
-       struct wlr_subsurface *subsurface =
-               wlr_subsurface_try_from_wlr_surface(wlr_surface);
-       if (!subsurface) {
-               return NULL;
-       }
-       struct wlr_surface *parent = subsurface->parent;
-       if (!parent) {
-               wlr_log(WLR_DEBUG, "subsurface %p has no parent", subsurface);
-               return NULL;
-       }
-       struct wlr_layer_surface_v1 *wlr_layer_surface =
-               wlr_layer_surface_v1_try_from_wlr_surface(parent);
-       if (wlr_layer_surface) {
-               return wlr_layer_surface;
-       }
-       /* Recurse in case there are nested sub-surfaces */
-       return subsurface_parent_layer(parent);
-}
index 766a3e3a134c9a3cf13a91b6811e38333589d18f..eb712562b4e2be54317b466770287c9b57305887 100644 (file)
@@ -9,7 +9,6 @@
 #include <wlr/types/wlr_subcompositor.h>
 #include <wlr/types/wlr_xdg_shell.h>
 #include "common/scene-helpers.h"
-#include "common/surface-helpers.h"
 #include "dnd.h"
 #include "labwc.h"
 #include "layers.h"
@@ -312,9 +311,8 @@ get_cursor_context(struct server *server)
                                }
                                return ret;
                        case LAB_NODE_LAYER_SURFACE:
-                               ret.node = node;
                                ret.type = LAB_NODE_LAYER_SURFACE;
-                               ret.surface = get_surface_from_layer_node(node);
+                               ret.surface = lab_wlr_surface_from_node(ret.node);
                                return ret;
                        case LAB_NODE_LAYER_POPUP:
                                ret.node = node;
@@ -374,29 +372,6 @@ get_cursor_context(struct server *server)
                        }
                }
 
-               /* Edge-case nodes without node-descriptors */
-               if (node->type == WLR_SCENE_NODE_BUFFER) {
-                       struct wlr_surface *surface = lab_wlr_surface_from_node(node);
-
-                       /*
-                        * Handle layer-shell subsurfaces
-                        *
-                        * These don't have node-descriptors, but need to be
-                        * able to receive pointer actions so we have to process
-                        * them here.
-                        *
-                        * Test by running `gtk-layer-demo -k exclusive`, then
-                        * open the 'set margin' dialog and try setting the
-                        * margin with the pointer.
-                        */
-                       if (surface && wlr_subsurface_try_from_wlr_surface(surface)
-                                       && subsurface_parent_layer(surface)) {
-                               ret.surface = surface;
-                               ret.type = LAB_NODE_LAYER_SUBSURFACE;
-                               return ret;
-                       }
-               }
-
                /* node->parent is always a *wlr_scene_tree */
                node = node->parent ? &node->parent->node : NULL;
        }
index 36a9046b2d7690191127742030dc24dfdf2f274c..f3ae9f311832cb5e5f5815ef3bfb8dc6821bf8c0 100644 (file)
@@ -19,7 +19,6 @@
 #include "action.h"
 #include "common/macros.h"
 #include "common/mem.h"
-#include "common/surface-helpers.h"
 #include "config/mousebind.h"
 #include "config/rcxml.h"
 #include "dnd.h"
@@ -1075,6 +1074,25 @@ process_press_mousebinding(struct server *server, struct cursor_context *ctx,
        return consumed_by_frame_context;
 }
 
+static struct wlr_layer_surface_v1 *
+get_root_layer(struct wlr_surface *wlr_surface)
+{
+       assert(wlr_surface);
+       struct wlr_subsurface *subsurface =
+               wlr_subsurface_try_from_wlr_surface(wlr_surface);
+       if (subsurface) {
+               if (subsurface->parent) {
+                       return get_root_layer(subsurface->parent);
+               } else {
+                       /* never reached? */
+                       wlr_log(WLR_ERROR, "subsurface without parent");
+                       return NULL;
+               }
+       } else {
+               return wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface);
+       }
+}
+
 static uint32_t press_msec;
 
 bool
@@ -1107,16 +1125,8 @@ cursor_process_button_press(struct seat *seat, uint32_t button, uint32_t time_ms
         * the Focus action (used for normal views) does not work.
         */
        if (ctx.type == LAB_NODE_LAYER_SURFACE) {
-               wlr_log(WLR_DEBUG, "press on layer-surface");
-               struct wlr_layer_surface_v1 *layer =
-                       wlr_layer_surface_v1_try_from_wlr_surface(ctx.surface);
-               if (layer && layer->current.keyboard_interactive) {
-                       layer_try_set_focus(seat, layer);
-               }
-       } else if (ctx.type == LAB_NODE_LAYER_SUBSURFACE) {
-               wlr_log(WLR_DEBUG, "press on layer-subsurface");
-               struct wlr_layer_surface_v1 *layer =
-                       subsurface_parent_layer(ctx.surface);
+               wlr_log(WLR_DEBUG, "press on layer-(sub)surface");
+               struct wlr_layer_surface_v1 *layer = get_root_layer(ctx.surface);
                if (layer && layer->current.keyboard_interactive) {
                        layer_try_set_focus(seat, layer);
                }
@@ -1127,7 +1137,7 @@ cursor_process_button_press(struct seat *seat, uint32_t button, uint32_t time_ms
 #endif
        }
 
-       if (ctx.type != LAB_NODE_CLIENT && ctx.type != LAB_NODE_LAYER_SUBSURFACE
+       if (ctx.type != LAB_NODE_CLIENT && ctx.type != LAB_NODE_LAYER_SURFACE
                        && wlr_seat_pointer_has_grab(seat->seat)) {
                /*
                 * If we have an active popup grab (an open popup) we want to