From 6e0d11bff5abf26c3e84b071afaf5a73efea9509 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 1 Jun 2020 19:42:15 +0100 Subject: [PATCH] Adjust xdg-shell view position on first map --- include/labwc.h | 3 ++- src/deco.c | 10 ++++++---- src/view.c | 49 ++++++++++++++++++++++++++++++++++++++----------- src/xdg.c | 5 +++-- src/xwl.c | 18 +----------------- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index 61a21bcc..d3f44e2f 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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 diff --git a/src/deco.c b/src/deco.c index 485f6e98..56235faf 100644 --- a/src/deco.c +++ b/src/deco.c @@ -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; diff --git a/src/view.c b/src/view.c index d11cb204..1107724c 100644 --- a/src/view.c +++ b/src/view.c @@ -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)) diff --git a/src/xdg.c b/src/xdg.c index 6b2a153a..52649329 100644 --- 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); } diff --git a/src/xwl.c b/src/xwl.c index 45995352..4eaa17d5 100644 --- 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); }