]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add struct view_impl
authorJohan Malm <jgm323@gmail.com>
Wed, 2 Sep 2020 19:20:52 +0000 (20:20 +0100)
committerJohan Malm <jgm323@gmail.com>
Wed, 2 Sep 2020 19:20:52 +0000 (20:20 +0100)
Support .configure

include/labwc.h
src/view.c
src/xdg.c
src/xwl.c

index 4fa67c78f81b7fcdf00c3c286e431eaf55fee2d4..cbcabafd504baebf08ddb48be4eb3d7752ceac9b 100644 (file)
@@ -104,12 +104,20 @@ enum deco_part {
        /* Keep LAB_DECO_NONE last as iteration end-marker */
 };
 
+struct view_impl {
+       void (*configure)(struct view *view, struct wlr_box geo);
+};
+
 struct view {
+       struct server *server;
        enum view_type type;
+       const struct view_impl *impl;
        struct wl_list link;
-       struct server *server;
-       struct wlr_xdg_surface *xdg_surface;
-       struct wlr_xwayland_surface *xwayland_surface;
+
+       union {
+               struct wlr_xdg_surface *xdg_surface;
+               struct wlr_xwayland_surface *xwayland_surface;
+       };
        struct wlr_surface *surface;
 
        bool mapped;
index 5809b9ec80cab55648fec70f1caba6c4961f9df2..8974ad9e7632f7cfbef389c1fbc0942bc4849da1 100644 (file)
@@ -73,19 +73,13 @@ struct wlr_box view_geometry(struct view *view)
 void view_resize(struct view *view, struct wlr_box geo)
 {
        struct wlr_box border = view_get_surface_geometry(view);
-       switch (view->type) {
-       case LAB_XDG_SHELL_VIEW:
-               wlr_xdg_toplevel_set_size(view->xdg_surface,
-                                         geo.width - 2 * border.x,
-                                         geo.height - 2 * border.y);
-               break;
-       case LAB_XWAYLAND_VIEW:
-               wlr_xwayland_surface_configure(view->xwayland_surface, view->x,
-                                              view->y, geo.width, geo.height);
-               break;
-       default:
-               break;
-       }
+       struct wlr_box box = {
+               .x = view->x,
+               .y = view->y,
+               .width = geo.width - 2 * border.x,
+               .height = geo.height - 2 * border.y,
+       };
+       view->impl->configure(view, box);
 }
 
 static void move_to_front(struct view *view)
index e728f038e4c1ae71f2fc46b62d68741d63a5e637..5129c1a6bffdaf72c265113eb7b877bc6d12cb03 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -131,6 +131,16 @@ void xdg_toplevel_request_resize(struct wl_listener *listener, void *data)
        interactive_begin(view, LAB_CURSOR_RESIZE, event->edges);
 }
 
+static void xdg_toplevel_view_configure(struct view *view, struct wlr_box geo)
+{
+       wlr_xdg_toplevel_set_size(view->xdg_surface, (uint32_t)geo.width,
+                                 (uint32_t)geo.height);
+}
+
+static const struct view_impl xdg_toplevel_view_impl = {
+       .configure = xdg_toplevel_view_configure,
+};
+
 void xdg_surface_new(struct wl_listener *listener, void *data)
 {
        struct server *server =
@@ -143,6 +153,7 @@ void xdg_surface_new(struct wl_listener *listener, void *data)
        struct view *view = calloc(1, sizeof(struct view));
        view->server = server;
        view->type = LAB_XDG_SHELL_VIEW;
+       view->impl = &xdg_toplevel_view_impl;
        view->xdg_surface = xdg_surface;
 
        view->map.notify = xdg_surface_map;
index db950c3840eb325769e91cb2c1a6c6a6bf045cde..91925446527d3c25bbdf4ff2b09ab721f88d593e 100644 (file)
--- a/src/xwl.c
+++ b/src/xwl.c
@@ -80,6 +80,18 @@ void xwl_surface_configure(struct wl_listener *listener, void *data)
                                       event->y, event->width, event->height);
 }
 
+static void xwl_view_configure(struct view *view, struct wlr_box geo)
+{
+       return wlr_xwayland_surface_configure(view->xwayland_surface,
+                                             (int16_t)geo.x, (int16_t)geo.y,
+                                             (uint16_t)geo.width,
+                                             (uint16_t)geo.height);
+}
+
+static const struct view_impl xwl_view_impl = {
+       .configure = xwl_view_configure,
+};
+
 void xwl_surface_new(struct wl_listener *listener, void *data)
 {
        struct server *server =
@@ -90,6 +102,7 @@ void xwl_surface_new(struct wl_listener *listener, void *data)
        struct view *view = calloc(1, sizeof(struct view));
        view->server = server;
        view->type = LAB_XWAYLAND_VIEW;
+       view->impl = &xwl_view_impl;
        view->xwayland_surface = xwayland_surface;
 
        view->map.notify = xwl_surface_map;