Skip to content

Commit e8c038c

Browse files
committed
view: adjust position according to declared top left corner
The XDG surface geometry includes an (x,y) coordinate indicating the top left corner of the window. Use this information to correctly set the view position.
1 parent 6f20285 commit e8c038c

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

view.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ view_activate(struct cg_view *view, bool activate)
5555
static bool
5656
view_extends_output_layout(struct cg_view *view, struct wlr_box *layout_box)
5757
{
58-
int width, height;
59-
view->impl->get_geometry(view, &width, &height);
58+
struct wlr_box view_box;
59+
view->impl->get_geometry(view, &view_box);
6060

61-
return (layout_box->height < height || layout_box->width < width);
61+
return (layout_box->height < view_box.height || layout_box->width < view_box.width);
6262
}
6363

6464
static void
6565
view_maximize(struct cg_view *view, struct wlr_box *layout_box)
6666
{
67-
view->lx = layout_box->x;
68-
view->ly = layout_box->y;
67+
struct wlr_box view_box;
68+
view->impl->get_geometry(view, &view_box);
69+
70+
// Do not forget to adjust position according to top left corner declared in view geometry
71+
view->lx = layout_box->x - view_box.x;
72+
view->ly = layout_box->y - view_box.y;
6973

7074
if (view->scene_tree) {
7175
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
@@ -77,11 +81,12 @@ view_maximize(struct cg_view *view, struct wlr_box *layout_box)
7781
static void
7882
view_center(struct cg_view *view, struct wlr_box *layout_box)
7983
{
80-
int width, height;
81-
view->impl->get_geometry(view, &width, &height);
84+
struct wlr_box view_box;
85+
view->impl->get_geometry(view, &view_box);
8286

83-
view->lx = (layout_box->width - width) / 2;
84-
view->ly = (layout_box->height - height) / 2;
87+
// Do not forget to adjust position according to top left corner declared in view geometry
88+
view->lx = (layout_box->width - view_box.width) / 2 - view_box.x;
89+
view->ly = (layout_box->height - view_box.height) / 2 - view_box.y;
8590

8691
if (view->scene_tree) {
8792
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);

view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct cg_view {
3636

3737
struct cg_view_impl {
3838
char *(*get_title)(struct cg_view *view);
39-
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
39+
void (*get_geometry)(struct cg_view *view, struct wlr_box *view_box);
4040
bool (*is_primary)(struct cg_view *view);
4141
bool (*is_transient_for)(struct cg_view *child, struct cg_view *parent);
4242
void (*activate)(struct cg_view *view, bool activate);

xdg_shell.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,12 @@ get_title(struct cg_view *view)
125125
}
126126

127127
static void
128-
get_geometry(struct cg_view *view, int *width_out, int *height_out)
128+
get_geometry(struct cg_view *view, struct wlr_box *view_box)
129129
{
130130
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
131131
struct wlr_xdg_surface *xdg_surface = xdg_shell_view->xdg_toplevel->base;
132132

133-
*width_out = xdg_surface->geometry.width;
134-
*height_out = xdg_surface->geometry.height;
133+
memcpy(view_box, &xdg_surface->geometry, sizeof(*view_box));
135134
}
136135

137136
static bool

xwayland.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@ get_title(struct cg_view *view)
3838
}
3939

4040
static void
41-
get_geometry(struct cg_view *view, int *width_out, int *height_out)
41+
get_geometry(struct cg_view *view, struct wlr_box *view_box)
4242
{
4343
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
4444
struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface;
45+
46+
view_box->x = 0;
47+
view_box->y = 0;
48+
4549
if (xsurface->surface == NULL) {
46-
*width_out = 0;
47-
*height_out = 0;
50+
view_box->width = 0;
51+
view_box->height = 0;
4852
return;
4953
}
5054

51-
*width_out = xsurface->surface->current.width;
52-
*height_out = xsurface->surface->current.height;
55+
view_box->width = xsurface->surface->current.width;
56+
view_box->height = xsurface->surface->current.height;
5357
}
5458

5559
static bool

0 commit comments

Comments
 (0)