]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Adjust xdg-shell view position on first map
authorJohan Malm <jgm323@gmail.com>
Mon, 1 Jun 2020 18:42:15 +0000 (19:42 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 1 Jun 2020 18:42:15 +0000 (19:42 +0100)
include/labwc.h
src/deco.c
src/view.c
src/xdg.c
src/xwl.c

index 61a21bcc29ae527e0973f112d9a43d20ea1798f3..d3f44e2f659719dde16fa2dfc0402bdeb03fb679 100644 (file)
@@ -34,7 +34,7 @@
 #define XCURSOR_MOVE "grabbing"
 #define XWL_TITLEBAR_HEIGHT (10)
 #define XWL_WINDOW_BORDER (3)
-#define LAB_DISABLE_CSD (1)
+#define LAB_DISABLE_CSD (0)
 
 enum cursor_mode {
        LAB_CURSOR_PASSTHROUGH,
@@ -137,6 +137,7 @@ void xdg_surface_new(struct wl_listener *listener, void *data);
 int xwl_nr_parents(struct view *view);
 void xwl_surface_new(struct wl_listener *listener, void *data);
 
+void view_init_position(struct view *view);
 /**
  * view_get_surface_geometry - geometry relative to view
  * @view: toplevel containing the surface to process
index 485f6e98e92c55b5dd63e03c3fa9df4ea1fedec1..56235faf33432fd312ec791fcfa5daccff4100dd 100644 (file)
@@ -29,26 +29,28 @@ struct wlr_box deco_box(struct view *view, enum deco_part deco_part)
                box.y = view->y - XWL_TITLEBAR_HEIGHT - XWL_WINDOW_BORDER;
                box.width =
                        view->surface->current.width + 2 * XWL_WINDOW_BORDER;
-               box.height = XWL_WINDOW_BORDER;
+               box.height = XWL_WINDOW_BORDER;
                break;
        case LAB_DECO_PART_RIGHT:
                box.x = view->x + view->surface->current.width;
                box.y = view->y - XWL_TITLEBAR_HEIGHT;
                box.width = XWL_WINDOW_BORDER;
-               box.height = view->surface->current.height + XWL_TITLEBAR_HEIGHT;
+               box.height =
+                       view->surface->current.height + XWL_TITLEBAR_HEIGHT;
                break;
        case LAB_DECO_PART_BOTTOM:
                box.x = view->x - XWL_WINDOW_BORDER;
                box.y = view->y + view->surface->current.height;
                box.width =
                        view->surface->current.width + 2 * XWL_WINDOW_BORDER;
-               box.height = + XWL_WINDOW_BORDER;
+               box.height = +XWL_WINDOW_BORDER;
                break;
        case LAB_DECO_PART_LEFT:
                box.x = view->x - XWL_WINDOW_BORDER;
                box.y = view->y - XWL_TITLEBAR_HEIGHT;
                box.width = XWL_WINDOW_BORDER;
-               box.height = view->surface->current.height + XWL_TITLEBAR_HEIGHT;
+               box.height =
+                       view->surface->current.height + XWL_TITLEBAR_HEIGHT;
                break;
        default:
                break;
index d11cb204164c24288a192f2767cd10a55571056d..1107724c1e8ac800e508053c332ba25f0ea52d4a 100644 (file)
@@ -1,5 +1,42 @@
 #include "labwc.h"
 
+static bool is_toplevel(struct view *view)
+{
+       switch (view->type) {
+       case LAB_XDG_SHELL_VIEW:
+               return view->xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL;
+       case LAB_XWAYLAND_VIEW:
+               return xwl_nr_parents(view) > 0 ? false : true;
+       }
+       return false;
+}
+
+void view_init_position(struct view *view)
+{
+       /* If surface already has a 'desired' position, don't touch it */
+       if (view->x || view->y)
+               return;
+       if (!is_toplevel(view))
+               return;
+       struct wlr_box box;
+       if (view->type == LAB_XDG_SHELL_VIEW && !LAB_DISABLE_CSD) {
+               /* CSD */
+               wlr_xdg_surface_get_geometry(view->xdg_surface, &box);
+       } else if (!view_want_deco(view)) {
+               return;
+       } else {
+               /* SSD */
+               box = deco_max_extents(view);
+       }
+       view->x -= box.x;
+       view->y -= box.y;
+       if (view->type != LAB_XWAYLAND_VIEW)
+               return;
+       wlr_xwayland_surface_configure(view->xwayland_surface, view->x, view->y,
+                                      view->xwayland_surface->width,
+                                      view->xwayland_surface->height);
+}
+
 struct wlr_box view_get_surface_geometry(struct view *view)
 {
        struct wlr_box box = { 0 };
@@ -46,17 +83,7 @@ void view_resize(struct view *view, struct wlr_box geo)
        }
 }
 
-static bool is_toplevel(struct view *view)
-{
-       switch (view->type) {
-       case LAB_XDG_SHELL_VIEW:
-               return view->xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL;
-       case LAB_XWAYLAND_VIEW:
-               return xwl_nr_parents(view) > 0 ? false : true;
-       }
-       return false;
-}
-
+/* Do we want _server_ side decoration? */
 bool view_want_deco(struct view *view)
 {
        if (!is_toplevel(view))
index 6b2a153a9708d4a3b4580f26193da3f536322995..526493296f29e3676e9f692e1842f347904d1eec 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -49,11 +49,12 @@ void xdg_toplevel_decoration(struct wl_listener *listener, void *data)
 
 void xdg_surface_map(struct wl_listener *listener, void *data)
 {
-       /* Called when the surface is mapped, or ready to display on-screen. */
        struct view *view = wl_container_of(listener, view, map);
        view->mapped = true;
-       view->been_mapped = true;
        view->surface = view->xdg_surface->surface;
+       if (!view->been_mapped)
+               view_init_position(view);
+       view->been_mapped = true;
        view_focus(view);
 }
 
index 459953526a37fcd576889867430889916633808f..4eaa17d578fcef49063a12e3e952e668714460c6 100644 (file)
--- a/src/xwl.c
+++ b/src/xwl.c
@@ -16,22 +16,6 @@ int xwl_nr_parents(struct view *view)
        return i;
 }
 
-static void position(struct view *view)
-{
-       struct wlr_box box;
-       if (!view_want_deco(view))
-               return;
-       if (view->x || view->y)
-               return;
-       box = deco_box(view, LAB_DECO_PART_TITLE);
-       view->y = box.height;
-       box = deco_box(view, LAB_DECO_PART_LEFT);
-       view->x = box.width;
-       wlr_xwayland_surface_configure(view->xwayland_surface, view->x, view->y,
-                                      view->xwayland_surface->width,
-                                      view->xwayland_surface->height);
-}
-
 void xwl_surface_map(struct wl_listener *listener, void *data)
 {
        struct view *view = wl_container_of(listener, view, map);
@@ -40,7 +24,7 @@ void xwl_surface_map(struct wl_listener *listener, void *data)
        view->y = view->xwayland_surface->y;
        view->surface = view->xwayland_surface->surface;
        if (!view->been_mapped)
-               position(view);
+               view_init_position(view);
        view->been_mapped = true;
        view_focus(view);
 }