]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: constrain view to top/left edge
authorJohan Malm <jgm323@gmail.com>
Thu, 17 Sep 2020 20:11:54 +0000 (21:11 +0100)
committerJohan Malm <jgm323@gmail.com>
Thu, 17 Sep 2020 20:11:54 +0000 (21:11 +0100)
include/labwc.h
src/deco.c
src/xdg.c
src/xwayland.c

index c76a6684109c767e862627310b1adc1fc1e8869c..c210ae7f1616a18d76f3086550ad2d59130fbeb1 100644 (file)
@@ -234,7 +234,8 @@ void keyboard_new(struct server *server, struct wlr_input_device *device);
 void output_frame(struct wl_listener *listener, void *data);
 void output_new(struct wl_listener *listener, void *data);
 
-struct border deco_max_extents(struct view *view);
+struct border deco_thickness(struct view *view);
+struct wlr_box deco_max_extents(struct view *view);
 struct wlr_box deco_box(struct view *view, enum deco_part deco_part);
 enum deco_part deco_at(struct view *view, double lx, double ly);
 
index 4b365c16661b12c26ecec72c1ab54f21e6ab4e0d..6974003bb1f1cb2e9cc9c1de5c56d95e45e4e750 100644 (file)
@@ -12,7 +12,7 @@
 
 #define BORDER_WIDTH (2)
 
-struct border deco_max_extents(struct view *view)
+struct border deco_thickness(struct view *view)
 {
        struct border border = {
                .top = rc.title_height + BORDER_WIDTH,
@@ -23,16 +23,24 @@ struct border deco_max_extents(struct view *view)
        return border;
 }
 
+struct wlr_box deco_max_extents(struct view *view)
+{
+       struct border border = deco_thickness(view);
+       struct wlr_box box = {
+               .x = view->x - border.left,
+               .y = view->y - border.top,
+               .width = view->w + border.left + border.right,
+               .height = view->h + border.top + border.bottom,
+       };
+       return box;
+}
+
 struct wlr_box deco_box(struct view *view, enum deco_part deco_part)
 {
        int margin;
 
        struct wlr_box box = { .x = 0, .y = 0, .width = 0, .height = 0 };
        BUG_ON(!view);
-       if ((view->w < 1) || (view->h < 1)) {
-               warn("view (%p) has no width/height", view);
-               return box;
-       }
        switch (deco_part) {
        case LAB_DECO_BUTTON_CLOSE:
                wlr_texture_get_size(theme.xbm_close_active_unpressed,
index 48117dfbc4077cc94c03f389e138d7a4786d9f7c..c5c761b224dce826fc831bb687f191c1d2dcb6b6 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -149,7 +149,7 @@ static void xdg_toplevel_view_map(struct view *view)
        if (!view->been_mapped) {
                view->server_side_deco = has_ssd(view);
                if (view->server_side_deco) {
-                       view->margin = deco_max_extents(view);
+                       view->margin = deco_thickness(view);
                } else {
                        view->margin = xdg_shell_border(view);
                        view->xdg_grab_offset = -view->margin.left;
index cdb842e49ef66bac3ded3bcdc21000fd3bad4105..006d137574181e83c965b5e108eba5c6b3a38f62 100644 (file)
@@ -61,6 +61,19 @@ static bool want_deco(struct view *view)
               WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
 }
 
+static void top_left_edge_boundary_check(struct view *view)
+{
+       struct wlr_box deco = deco_max_extents(view);
+       if (deco.x < 0)
+               view->x -= deco.x;
+       if (deco.y < 0)
+               view->y -= deco.y;
+       struct wlr_box box = {
+               .x = view->x, .y = view->y, .width = view->w, .height = view->h
+       };
+       view->impl->configure(view, box);
+}
+
 static void map(struct view *view)
 {
        view->mapped = true;
@@ -71,15 +84,9 @@ static void map(struct view *view)
        view->surface = view->xwayland_surface->surface;
        view->server_side_deco = want_deco(view);
 
-       view->margin = deco_max_extents(view);
+       view->margin = deco_thickness(view);
 
-       /* ensure we're inside screen */
-       view->x += view->margin.left;
-       view->y += view->margin.top;
-       struct wlr_box box = {
-               .x = view->x, .y = view->y, .width = view->w, .height = view->h
-       };
-       view->impl->configure(view, box);
+       top_left_edge_boundary_check(view);
 
        /* Add commit here, as xwayland map/unmap can change the wlr_surface */
        wl_signal_add(&view->xwayland_surface->surface->events.commit,