mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-11-16 06:59:49 -05:00
view: adjust position according to declared top left corner
This commit is contained in:
parent
560e9ff3ef
commit
44fb937f8e
4 changed files with 22 additions and 18 deletions
10
view.c
10
view.c
|
|
@ -65,11 +65,15 @@ view_position(struct cg_view *view)
|
||||||
struct wlr_box layout_box;
|
struct wlr_box layout_box;
|
||||||
wlr_output_layout_get_box(view->server->output_layout, NULL, &layout_box);
|
wlr_output_layout_get_box(view->server->output_layout, NULL, &layout_box);
|
||||||
|
|
||||||
view->impl->get_geometry(view, &view->width, &view->height);
|
struct wlr_box view_box;
|
||||||
|
view->impl->get_geometry(view, &view_box);
|
||||||
|
|
||||||
// If view dimensions are not the same as output layout ones, it will be centered first
|
// If view dimensions are not the same as output layout ones, it will be centered first
|
||||||
view->lx = layout_box.x + (layout_box.width - view->width) / 2;
|
// Do not forget to adjust position according to top left corner declared in view geometry
|
||||||
view->ly = layout_box.y + (layout_box.height - view->height) / 2;
|
view->lx = layout_box.x + (layout_box.width - view_box.width) / 2 - view_box.x;
|
||||||
|
view->ly = layout_box.y + (layout_box.height - view_box.height) / 2 - view_box.y;
|
||||||
|
view->width = view_box.width;
|
||||||
|
view->height = view_box.height;
|
||||||
|
|
||||||
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
|
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
|
||||||
|
|
||||||
|
|
|
||||||
2
view.h
2
view.h
|
|
@ -37,7 +37,7 @@ struct cg_view {
|
||||||
|
|
||||||
struct cg_view_impl {
|
struct cg_view_impl {
|
||||||
char *(*get_title)(struct cg_view *view);
|
char *(*get_title)(struct cg_view *view);
|
||||||
void (*get_geometry)(struct cg_view *view, int *width_out, int *height_out);
|
void (*get_geometry)(struct cg_view *view, struct wlr_box *view_box);
|
||||||
bool (*is_primary)(struct cg_view *view);
|
bool (*is_primary)(struct cg_view *view);
|
||||||
bool (*is_transient_for)(struct cg_view *child, struct cg_view *parent);
|
bool (*is_transient_for)(struct cg_view *child, struct cg_view *parent);
|
||||||
void (*activate)(struct cg_view *view, bool activate);
|
void (*activate)(struct cg_view *view, bool activate);
|
||||||
|
|
|
||||||
14
xdg_shell.c
14
xdg_shell.c
|
|
@ -101,14 +101,10 @@ get_title(struct cg_view *view)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
get_geometry(struct cg_view *view, struct wlr_box *view_box)
|
||||||
{
|
{
|
||||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||||
struct wlr_box geom;
|
wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_toplevel->base, view_box);
|
||||||
|
|
||||||
wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_toplevel->base, &geom);
|
|
||||||
*width_out = geom.width;
|
|
||||||
*height_out = geom.height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
@ -195,9 +191,9 @@ handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data)
|
||||||
struct cg_view *view = &xdg_shell_view->view;
|
struct cg_view *view = &xdg_shell_view->view;
|
||||||
|
|
||||||
// Check if view dimensions have changed
|
// Check if view dimensions have changed
|
||||||
int width, height;
|
struct wlr_box view_box;
|
||||||
get_geometry(view, &width, &height);
|
get_geometry(view, &view_box);
|
||||||
if (width != view->width || height != view->height) {
|
if (view_box.width != view->width || view_box.height != view->height) {
|
||||||
view_position(view);
|
view_position(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
xwayland.c
14
xwayland.c
|
|
@ -38,18 +38,22 @@ get_title(struct cg_view *view)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
get_geometry(struct cg_view *view, struct wlr_box *view_box)
|
||||||
{
|
{
|
||||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||||
struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface;
|
struct wlr_xwayland_surface *xsurface = xwayland_view->xwayland_surface;
|
||||||
|
|
||||||
|
view_box->x = 0;
|
||||||
|
view_box->y = 0;
|
||||||
|
|
||||||
if (xsurface->surface == NULL) {
|
if (xsurface->surface == NULL) {
|
||||||
*width_out = 0;
|
view_box->width = 0;
|
||||||
*height_out = 0;
|
view_box->height = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*width_out = xsurface->surface->current.width;
|
view_box->width = xwayland_view->xwayland_surface->surface->current.width;
|
||||||
*height_out = xsurface->surface->current.height;
|
view_box->height = xwayland_view->xwayland_surface->surface->current.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue