From 03b5c4298323ccee42b94ab55f1732997b24ca9f Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Jul 2018 23:06:44 +0100 Subject: [PATCH 1/3] Add view_get_geometry --- include/sway/tree/view.h | 5 +---- sway/desktop/xdg_shell.c | 14 +++++++++++++- sway/tree/view.c | 42 ++++++++++++++-------------------------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 7dc8ac461..bdae51f42 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -29,6 +29,7 @@ struct sway_view_impl { const char *(*get_string_prop)(struct sway_view *view, enum sway_view_prop prop); uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); + void (*get_geometry)(struct sway_view *view, struct wlr_box *box); uint32_t (*configure)(struct sway_view *view, double lx, double ly, int width, int height); void (*set_activated)(struct sway_view *view, bool activated); @@ -250,10 +251,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); void view_unmap(struct sway_view *view); -void view_update_position(struct sway_view *view, double lx, double ly); - -void view_update_size(struct sway_view *view, int width, int height); - void view_child_init(struct sway_view_child *child, const struct sway_view_child_impl *impl, struct sway_view *view, struct wlr_surface *surface); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 2b634749f..c6995ec1c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -74,7 +74,8 @@ static struct sway_xdg_shell_view *xdg_shell_view_from_view( return (struct sway_xdg_shell_view *)view; } -static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { +static const char *get_string_prop(struct sway_view *view, + enum sway_view_prop prop) { if (xdg_shell_view_from_view(view) == NULL) { return NULL; } @@ -88,6 +89,16 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p } } +static void get_geometry(struct sway_view *view, struct wlr_box *box) { + struct sway_xdg_shell_view *xdg_shell_view = + xdg_shell_view_from_view(view); + if (xdg_shell_view == NULL) { + return; + } + struct wlr_xdg_surface *surface = view->wlr_xdg_surface; + wlr_xdg_surface_get_geometry(surface, box); +} + static uint32_t configure(struct sway_view *view, double lx, double ly, int width, int height) { struct sway_xdg_shell_view *xdg_shell_view = @@ -168,6 +179,7 @@ static void destroy(struct sway_view *view) { static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, + .get_geometry = get_geometry, .configure = configure, .set_activated = set_activated, .set_tiled = set_tiled, diff --git a/sway/tree/view.c b/sway/tree/view.c index 06e9edc50..67edb96e3 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -129,7 +129,7 @@ uint32_t view_get_window_type(struct sway_view *view) { } const char *view_get_shell(struct sway_view *view) { - switch(view->type) { + switch (view->type) { case SWAY_VIEW_XDG_SHELL_V6: return "xdg_shell_v6"; case SWAY_VIEW_XDG_SHELL: @@ -140,6 +140,20 @@ const char *view_get_shell(struct sway_view *view) { return "unknown"; } +void view_get_geometry(struct sway_view *view, struct wlr_box *box) { + if (view->surface == NULL) { + box->x = box->y = box->width = box->height = 0; + return; + } + if (view->impl->get_geometry) { + view->impl->get_geometry(view, box); + return; + } + box->x = box->y = 0; + box->width = view->surface->current->width; + box->height = view->surface->current->height; +} + uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, int height) { if (view->impl->configure) { @@ -569,32 +583,6 @@ void view_unmap(struct sway_view *view) { view->surface = NULL; } -void view_update_position(struct sway_view *view, double lx, double ly) { - if (view->x == lx && view->y == ly) { - return; - } - container_damage_whole(view->swayc); - view->x = lx; - view->y = ly; - if (container_is_floating(view->swayc)) { - container_set_geometry_from_floating_view(view->swayc); - } - container_damage_whole(view->swayc); -} - -void view_update_size(struct sway_view *view, int width, int height) { - if (view->width == width && view->height == height) { - return; - } - container_damage_whole(view->swayc); - view->width = width; - view->height = height; - if (container_is_floating(view->swayc)) { - container_set_geometry_from_floating_view(view->swayc); - } - container_damage_whole(view->swayc); -} - static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); From db4e900789d8c9de2ef2df0e2d42979c45b8fd04 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Jul 2018 23:07:42 +0100 Subject: [PATCH 2/3] [REMOVE ME] Don't tile views to get nontrivial window geometry --- sway/desktop/xdg_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index c6995ec1c..92bdc8fc5 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -126,8 +126,8 @@ static void set_tiled(struct sway_view *view, bool tiled) { struct wlr_xdg_surface *surface = view->wlr_xdg_surface; enum wlr_edges edges = WLR_EDGE_NONE; if (tiled) { - edges = WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP | - WLR_EDGE_BOTTOM; + // edges = WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP | + // WLR_EDGE_BOTTOM; } wlr_xdg_toplevel_set_tiled(surface, edges); } From 75a99c1b99e7032437b15e1e1ca1484f0673091c Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Jul 2018 23:08:58 +0100 Subject: [PATCH 3/3] [FIX ME] Adjust view position with window geometry --- sway/tree/view.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/tree/view.c b/sway/tree/view.c index 67edb96e3..b82f1093e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -288,6 +288,11 @@ void view_autoconfigure(struct sway_view *view) { break; } + struct wlr_box geo; + view_get_geometry(view, &geo); + x -= geo.x; + y -= geo.y; + view->x = x; view->y = y; view->width = width;