]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: handle button press on layer-surface (issue #41)
authorJohan Malm <jgm323@gmail.com>
Mon, 12 Jul 2021 15:44:30 +0000 (16:44 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 12 Jul 2021 15:44:30 +0000 (16:44 +0100)
include/labwc.h
src/cursor.c
src/desktop.c
src/layers.c
src/output.c

index f12870df97d46520a293b010c6fd3aed3e5a2467..c00dc3666451d786c4a80ae2f0159063fdda5476 100644 (file)
@@ -128,7 +128,7 @@ struct server {
 };
 
 struct output {
-       struct wl_list link;
+       struct wl_list link; /* server::outputs */
        struct server *server;
        struct wlr_output *wlr_output;
        struct wlr_output_damage *damage;
@@ -307,9 +307,13 @@ void desktop_focus_view(struct seat *seat, struct view *view);
  */
 struct view *desktop_cycle_view(struct server *server, struct view *current);
 void desktop_focus_topmost_mapped_view(struct server *server);
+
+/**
+ * desktop_view_at - find view or layer-surface at co-ordinate (lx, ly)
+ * Note: If surface points to layer-surface, view will be set to NULL
+ */
 struct view *desktop_view_at(struct server *server, double lx, double ly,
-                           struct wlr_surface **surface, double *sx,
-                           double *sy, int *view_area);
+       struct wlr_surface **surface, double *sx, double *sy, int *view_area);
 
 void cursor_init(struct seat *seat);
 
@@ -329,6 +333,7 @@ void output_damage_surface(struct output *output, struct wlr_surface *surface,
 void scale_box(struct wlr_box *box, float scale);
 
 void output_manager_init(struct server *server);
+struct output *output_from_wlr_output(struct server *server, struct wlr_output *wlr_output);
 
 void damage_all_outputs(struct server *server);
 void damage_view_whole(struct view *view);
index 0f85e4a7b10898d9ef91b5ddb335c09a1abc9ec4..9c1e5c4b09b710cccefe5cb453063811d5887e1e 100644 (file)
@@ -303,6 +303,7 @@ cursor_button(struct wl_listener *listener, void *data)
        struct wlr_surface *surface;
        int view_area;
        uint32_t resize_edges;
+
        struct view *view = desktop_view_at(server, server->seat.cursor->x,
                server->seat.cursor->y, &surface, &sx, &sy, &view_area);
 
@@ -336,9 +337,19 @@ cursor_button(struct wl_listener *listener, void *data)
                return;
        }
 
-       /* handle _press_ on desktop */
+       /* Handle _press_ on a layer surface */
+       if (!view && surface) {
+               /* ...if we've ended up here it must be a layer surface */
+               assert(wlr_surface_is_layer_surface(surface));
+               struct wlr_layer_surface_v1 *layer = wlr_layer_surface_v1_from_wlr_surface(surface);
+               if (layer->current.keyboard_interactive) {
+                       seat_set_focus_layer(&server->seat, layer);
+               }
+               return;
+       }
+
+       /* Handle _press_ on root window */
        if (!view) {
-               /* launch root-menu */
                action(server, "ShowMenu", "root-menu");
                return;
        }
index 6fce6c7c3c91a501431d6b5cd951fcc00c6cb776..26aa9cf1add7092e63472d74c0b023c66ed1bf15 100644 (file)
@@ -1,6 +1,7 @@
 #include "config.h"
 #include <assert.h>
 #include "labwc.h"
+#include "layers.h"
 #include "ssd.h"
 
 static void
@@ -249,16 +250,42 @@ _view_at(struct view *view, double lx, double ly, struct wlr_surface **surface,
        return false;
 }
 
+static struct
+wlr_surface *layer_surface_at(struct wl_list *layer, double lx, double ly,
+               double *sx, double *sy)
+{
+       struct lab_layer_surface *surface;
+       wl_list_for_each_reverse(surface, layer, link) {
+               double _sx = lx - surface->geo.x;
+               double _sy = ly - surface->geo.y;
+               struct wlr_surface *wlr_surface;
+               wlr_surface = wlr_layer_surface_v1_surface_at(surface->layer_surface,
+                                                             _sx, _sy, sx, sy);
+               if (wlr_surface) {
+                       return wlr_surface;
+               }
+       }
+       return NULL;
+}
+
 struct view *
 desktop_view_at(struct server *server, double lx, double ly,
                struct wlr_surface **surface, double *sx, double *sy,
                int *view_area)
 {
-       /*
-        * This iterates over all of our surfaces and attempts to find one under
-        * the cursor. It relies on server->views being ordered from
-        * top-to-bottom.
-        */
+       struct wlr_output *wlr_output = wlr_output_layout_output_at(
+                       server->output_layout, lx, ly);
+       struct output *output = output_from_wlr_output(server, wlr_output);
+
+       if ((*surface = layer_surface_at(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY],
+                                        lx, ly, sx, sy))) {
+               return NULL;
+       }
+       if ((*surface = layer_surface_at(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
+                                        lx, ly, sx, sy))) {
+               return NULL;
+       }
+
        struct view *view;
        wl_list_for_each (view, &server->views, link) {
                if (!view->mapped) {
@@ -275,5 +302,14 @@ desktop_view_at(struct server *server, double lx, double ly,
                        return view;
                }
        }
+
+       if ((*surface = layer_surface_at(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
+                                        lx, ly, sx, sy))) {
+               return NULL;
+       }
+       if ((*surface = layer_surface_at(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
+                                        lx, ly, sx, sy))) {
+               return NULL;
+       }
        return NULL;
 }
index d7651e78481afcb95c6fcd3d63d8d8bf1accb455..e340dce7caef6eaa9b1f3aa914d282f7ec840a58 100644 (file)
@@ -229,18 +229,6 @@ arrange_layers(struct output *output)
        }
 }
 
-static struct output *
-output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
-{
-       struct output *output;
-       wl_list_for_each(output, &server->outputs, link) {
-               if (output->wlr_output == wlr_output) {
-                       return output;
-               }
-       }
-       return NULL;
-}
-
 static void
 output_destroy_notify(struct wl_listener *listener, void *data)
 {
index d2427125525f91293bbbae5a0db3884054acf18f..ab002f7ed7772c73cfaaff7298ff558a1d7d14e9 100644 (file)
@@ -984,3 +984,15 @@ void output_manager_init(struct server *server)
        wl_signal_add(&server->output_manager->events.apply,
                &server->output_manager_apply);
 }
+
+struct output *
+output_from_wlr_output(struct server *server, struct wlr_output *wlr_output)
+{
+       struct output *output;
+       wl_list_for_each(output, &server->outputs, link) {
+               if (output->wlr_output == wlr_output) {
+                       return output;
+               }
+       }
+       return NULL;
+}