mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-21 22:52:20 +00:00
Forward-port xdg-shell-v6 positioner improvements
This commit is contained in:
parent
278aa84619
commit
2e3d901ac5
@ -165,14 +165,19 @@ static void create_popup() {
|
||||
}
|
||||
struct wl_surface *surface = wl_compositor_create_surface(compositor);
|
||||
assert(xdg_wm_base && surface);
|
||||
struct xdg_surface *xdg_surface = xdg_wm_base_get_xdg_surface(
|
||||
xdg_wm_base, surface);
|
||||
struct xdg_positioner *xdg_positioner = xdg_wm_base_create_positioner(
|
||||
xdg_wm_base);
|
||||
struct xdg_surface *xdg_surface =
|
||||
xdg_wm_base_get_xdg_surface(xdg_wm_base, surface);
|
||||
struct xdg_positioner *xdg_positioner =
|
||||
xdg_wm_base_create_positioner(xdg_wm_base);
|
||||
assert(xdg_surface && xdg_positioner);
|
||||
|
||||
xdg_positioner_set_size(xdg_positioner, 256, 256);
|
||||
xdg_positioner_set_anchor_rect(xdg_positioner, 0, 0, width, height);
|
||||
xdg_positioner_set_offset(xdg_positioner, 0, 0);
|
||||
xdg_positioner_set_anchor_rect(xdg_positioner, cur_x, cur_y, 1, 1);
|
||||
xdg_positioner_set_anchor(xdg_positioner, XDG_POSITIONER_ANCHOR_TOP_LEFT);
|
||||
xdg_positioner_set_gravity(xdg_positioner, XDG_POSITIONER_GRAVITY_TOP_LEFT);
|
||||
xdg_positioner_set_constraint_adjustment(xdg_positioner,
|
||||
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE);
|
||||
|
||||
popup = xdg_surface_get_popup(xdg_surface, NULL, xdg_positioner);
|
||||
assert(popup);
|
||||
@ -185,6 +190,8 @@ static void create_popup() {
|
||||
wl_surface_commit(surface);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
xdg_positioner_destroy(xdg_positioner);
|
||||
|
||||
struct wl_egl_window *egl_window;
|
||||
struct wlr_egl_surface *egl_surface;
|
||||
egl_window = wl_egl_window_create(surface, 256, 256);
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef WLR_TYPES_WLR_XDG_SHELL_H
|
||||
#define WLR_TYPES_WLR_XDG_SHELL_H
|
||||
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wayland-server.h>
|
||||
#include "xdg-shell-protocol.h"
|
||||
|
||||
struct wlr_xdg_shell {
|
||||
struct wl_global *wl_global;
|
||||
@ -32,7 +32,22 @@ struct wlr_xdg_client {
|
||||
struct wl_event_source *ping_timer;
|
||||
};
|
||||
|
||||
struct wlr_xdg_positioner;
|
||||
struct wlr_xdg_positioner {
|
||||
struct wl_resource *resource;
|
||||
|
||||
struct wlr_box anchor_rect;
|
||||
enum xdg_positioner_anchor anchor;
|
||||
enum xdg_positioner_gravity gravity;
|
||||
enum xdg_positioner_constraint_adjustment constraint_adjustment;
|
||||
|
||||
struct {
|
||||
int32_t width, height;
|
||||
} size;
|
||||
|
||||
struct {
|
||||
int32_t x, y;
|
||||
} offset;
|
||||
};
|
||||
|
||||
struct wlr_xdg_popup {
|
||||
struct wlr_xdg_surface *base;
|
||||
@ -43,11 +58,12 @@ struct wlr_xdg_popup {
|
||||
struct wlr_surface *parent;
|
||||
struct wlr_seat *seat;
|
||||
|
||||
struct wlr_xdg_positioner *positioner;
|
||||
// Position of the popup relative to the upper left corner of the window
|
||||
// geometry of the parent surface
|
||||
struct wlr_box geometry;
|
||||
|
||||
struct wlr_xdg_positioner positioner;
|
||||
|
||||
struct wl_list grab_link; // wlr_xdg_popup_grab::popups
|
||||
};
|
||||
|
||||
@ -186,7 +202,8 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_resource(
|
||||
struct wlr_xdg_surface *wlr_xdg_surface_from_popup_resource(
|
||||
struct wl_resource *resource);
|
||||
|
||||
struct wlr_box wlr_xdg_popup_get_geometry(struct wlr_xdg_popup *popup);
|
||||
struct wlr_box wlr_xdg_positioner_get_geometry(
|
||||
struct wlr_xdg_positioner *positioner);
|
||||
|
||||
/**
|
||||
* Send a ping to the surface. If the surface does not respond in a reasonable
|
||||
|
@ -142,7 +142,7 @@ static void layer_surface_handle_get_popup(struct wl_client *client,
|
||||
assert(popup_surface->role == WLR_XDG_SURFACE_ROLE_POPUP);
|
||||
struct wlr_xdg_popup *popup = popup_surface->popup;
|
||||
popup->parent = parent->surface;
|
||||
popup->geometry = wlr_xdg_popup_get_geometry(popup);
|
||||
popup->geometry = wlr_xdg_positioner_get_geometry(&popup->positioner);
|
||||
wl_list_insert(&parent->popups, &popup->link);
|
||||
wlr_signal_emit_safe(&parent->events.new_popup, popup);
|
||||
}
|
||||
|
@ -28,24 +28,11 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface(
|
||||
return (struct wlr_xdg_surface *)surface->role_data;
|
||||
}
|
||||
|
||||
struct wlr_xdg_positioner {
|
||||
struct wlr_xdg_positioner_resource {
|
||||
struct wl_resource *resource;
|
||||
|
||||
struct wlr_box anchor_rect;
|
||||
enum xdg_positioner_anchor anchor;
|
||||
enum xdg_positioner_gravity gravity;
|
||||
enum xdg_positioner_constraint_adjustment constraint_adjustment;
|
||||
|
||||
struct {
|
||||
int32_t width, height;
|
||||
} size;
|
||||
|
||||
struct {
|
||||
int32_t x, y;
|
||||
} offset;
|
||||
struct wlr_xdg_positioner attrs;
|
||||
};
|
||||
|
||||
|
||||
static void resource_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
@ -301,7 +288,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface *surface) {
|
||||
|
||||
static const struct xdg_positioner_interface xdg_positioner_implementation;
|
||||
|
||||
static struct wlr_xdg_positioner *xdg_positioner_from_resource(
|
||||
static struct wlr_xdg_positioner_resource *xdg_positioner_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &xdg_positioner_interface,
|
||||
&xdg_positioner_implementation));
|
||||
@ -309,14 +296,14 @@ static struct wlr_xdg_positioner *xdg_positioner_from_resource(
|
||||
}
|
||||
|
||||
static void xdg_positioner_destroy(struct wl_resource *resource) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
free(positioner);
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_size(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t width, int32_t height) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
if (width < 1 || height < 1) {
|
||||
@ -326,14 +313,14 @@ static void xdg_positioner_handle_set_size(struct wl_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->size.width = width;
|
||||
positioner->size.height = height;
|
||||
positioner->attrs.size.width = width;
|
||||
positioner->attrs.size.height = height;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
|
||||
int32_t height) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
if (width < 0 || height < 0) {
|
||||
@ -343,15 +330,15 @@ static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->anchor_rect.x = x;
|
||||
positioner->anchor_rect.y = y;
|
||||
positioner->anchor_rect.width = width;
|
||||
positioner->anchor_rect.height = height;
|
||||
positioner->attrs.anchor_rect.x = x;
|
||||
positioner->attrs.anchor_rect.y = y;
|
||||
positioner->attrs.anchor_rect.width = width;
|
||||
positioner->attrs.anchor_rect.height = height;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_anchor(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t anchor) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
if (anchor > XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT) {
|
||||
@ -361,12 +348,12 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->anchor = anchor;
|
||||
positioner->attrs.anchor = anchor;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_gravity(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t gravity) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
if (gravity > XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT) {
|
||||
@ -376,25 +363,25 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->gravity = gravity;
|
||||
positioner->attrs.gravity = gravity;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_constraint_adjustment(
|
||||
struct wl_client *client, struct wl_resource *resource,
|
||||
uint32_t constraint_adjustment) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
positioner->constraint_adjustment = constraint_adjustment;
|
||||
positioner->attrs.constraint_adjustment = constraint_adjustment;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_offset(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t x, int32_t y) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(resource);
|
||||
|
||||
positioner->offset.x = x;
|
||||
positioner->offset.y = y;
|
||||
positioner->attrs.offset.x = x;
|
||||
positioner->attrs.offset.y = y;
|
||||
}
|
||||
|
||||
static const struct xdg_positioner_interface
|
||||
@ -412,16 +399,12 @@ static const struct xdg_positioner_interface
|
||||
static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
|
||||
struct wl_resource *resource, uint32_t id) {
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
calloc(1, sizeof(struct wlr_xdg_positioner));
|
||||
calloc(1, sizeof(struct wlr_xdg_positioner_resource));
|
||||
if (positioner == NULL) {
|
||||
wl_client_post_no_memory(wl_client);
|
||||
return;
|
||||
}
|
||||
|
||||
/* set widths to detect improper usages of get_popup */
|
||||
positioner->size.width = -1;
|
||||
positioner->anchor_rect.width = -1;
|
||||
|
||||
positioner->resource = wl_resource_create(wl_client,
|
||||
&xdg_positioner_interface,
|
||||
wl_resource_get_version(resource),
|
||||
@ -437,9 +420,8 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
|
||||
positioner, xdg_positioner_destroy);
|
||||
}
|
||||
|
||||
struct wlr_box wlr_xdg_popup_get_geometry(struct wlr_xdg_popup *popup) {
|
||||
assert(popup && popup->positioner);
|
||||
struct wlr_xdg_positioner *positioner = popup->positioner;
|
||||
struct wlr_box wlr_xdg_positioner_get_geometry(
|
||||
struct wlr_xdg_positioner *positioner) {
|
||||
struct wlr_box geometry = {
|
||||
.x = positioner->offset.x,
|
||||
.y = positioner->offset.y,
|
||||
@ -447,71 +429,39 @@ struct wlr_box wlr_xdg_popup_get_geometry(struct wlr_xdg_popup *popup) {
|
||||
.height = positioner->size.height,
|
||||
};
|
||||
|
||||
switch (positioner->anchor) {
|
||||
case XDG_POSITIONER_ANCHOR_TOP:
|
||||
case XDG_POSITIONER_ANCHOR_TOP_LEFT:
|
||||
case XDG_POSITIONER_ANCHOR_TOP_RIGHT:
|
||||
if (positioner->anchor & XDG_POSITIONER_ANCHOR_TOP) {
|
||||
geometry.y += positioner->anchor_rect.y;
|
||||
break;
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM:
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_LEFT:
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT:
|
||||
} else if (positioner->anchor & XDG_POSITIONER_ANCHOR_BOTTOM) {
|
||||
geometry.y +=
|
||||
positioner->anchor_rect.y + positioner->anchor_rect.height;
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
geometry.y +=
|
||||
positioner->anchor_rect.y + positioner->anchor_rect.height / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (positioner->anchor) {
|
||||
case XDG_POSITIONER_ANCHOR_LEFT:
|
||||
case XDG_POSITIONER_ANCHOR_TOP_LEFT:
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_LEFT:
|
||||
if (positioner->anchor & XDG_POSITIONER_ANCHOR_LEFT) {
|
||||
geometry.x += positioner->anchor_rect.x;
|
||||
break;
|
||||
case XDG_POSITIONER_ANCHOR_RIGHT:
|
||||
case XDG_POSITIONER_ANCHOR_TOP_RIGHT:
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT:
|
||||
} else if (positioner->anchor & XDG_POSITIONER_ANCHOR_RIGHT) {
|
||||
geometry.x += positioner->anchor_rect.x + positioner->anchor_rect.width;
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
geometry.x +=
|
||||
positioner->anchor_rect.x + positioner->anchor_rect.width / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (positioner->gravity) {
|
||||
case XDG_POSITIONER_GRAVITY_TOP:
|
||||
case XDG_POSITIONER_GRAVITY_TOP_LEFT:
|
||||
case XDG_POSITIONER_GRAVITY_TOP_RIGHT:
|
||||
if (positioner->gravity & XDG_POSITIONER_GRAVITY_TOP) {
|
||||
geometry.y -= geometry.height;
|
||||
break;
|
||||
case XDG_POSITIONER_GRAVITY_BOTTOM:
|
||||
case XDG_POSITIONER_GRAVITY_BOTTOM_LEFT:
|
||||
case XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT:
|
||||
} else if (positioner->gravity & XDG_POSITIONER_GRAVITY_BOTTOM) {
|
||||
geometry.y = geometry.y;
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
geometry.y -= geometry.height / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (positioner->gravity) {
|
||||
case XDG_POSITIONER_GRAVITY_LEFT:
|
||||
case XDG_POSITIONER_GRAVITY_TOP_LEFT:
|
||||
case XDG_POSITIONER_GRAVITY_BOTTOM_LEFT:
|
||||
if (positioner->gravity & XDG_POSITIONER_GRAVITY_LEFT) {
|
||||
geometry.x -= geometry.width;
|
||||
break;
|
||||
case XDG_POSITIONER_GRAVITY_RIGHT:
|
||||
case XDG_POSITIONER_GRAVITY_TOP_RIGHT:
|
||||
case XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT:
|
||||
} else if (positioner->gravity & XDG_POSITIONER_GRAVITY_RIGHT) {
|
||||
geometry.x = geometry.x;
|
||||
break;
|
||||
default:
|
||||
} else {
|
||||
geometry.x -= geometry.width / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (positioner->constraint_adjustment ==
|
||||
@ -519,8 +469,6 @@ struct wlr_box wlr_xdg_popup_get_geometry(struct wlr_xdg_popup *popup) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
// TODO: add compositor policy configuration and the code here
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@ -620,10 +568,11 @@ static void xdg_surface_handle_get_popup(struct wl_client *client,
|
||||
wlr_xdg_surface_from_resource(resource);
|
||||
struct wlr_xdg_surface *parent =
|
||||
wlr_xdg_surface_from_resource(parent_resource);
|
||||
struct wlr_xdg_positioner *positioner =
|
||||
struct wlr_xdg_positioner_resource *positioner =
|
||||
xdg_positioner_from_resource(positioner_resource);
|
||||
|
||||
if (positioner->size.width == -1 || positioner->anchor_rect.width == -1) {
|
||||
if (positioner->attrs.size.width == 0 ||
|
||||
positioner->attrs.anchor_rect.width == 0) {
|
||||
wl_resource_post_error(resource,
|
||||
XDG_WM_BASE_ERROR_INVALID_POSITIONER,
|
||||
"positioner object is not complete");
|
||||
@ -652,7 +601,10 @@ static void xdg_surface_handle_get_popup(struct wl_client *client,
|
||||
|
||||
surface->role = WLR_XDG_SURFACE_ROLE_POPUP;
|
||||
surface->popup->base = surface;
|
||||
surface->popup->positioner = positioner;
|
||||
|
||||
// positioner properties
|
||||
memcpy(&surface->popup->positioner, &positioner->attrs,
|
||||
sizeof(struct wlr_xdg_positioner));
|
||||
|
||||
wl_resource_set_implementation(surface->popup->resource,
|
||||
&xdg_popup_implementation, surface,
|
||||
@ -660,7 +612,8 @@ static void xdg_surface_handle_get_popup(struct wl_client *client,
|
||||
|
||||
if (parent) {
|
||||
surface->popup->parent = parent->surface;
|
||||
surface->popup->geometry = wlr_xdg_popup_get_geometry(surface->popup);
|
||||
surface->popup->geometry =
|
||||
wlr_xdg_positioner_get_geometry(&positioner->attrs);
|
||||
wl_list_insert(&parent->popups, &surface->popup->link);
|
||||
wlr_signal_emit_safe(&parent->events.new_popup, surface->popup);
|
||||
}
|
||||
|
@ -486,8 +486,6 @@ struct wlr_box wlr_xdg_positioner_v6_get_geometry(
|
||||
return geometry;
|
||||
}
|
||||
|
||||
// TODO: add compositor policy configuration and the code here
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user