wayland: popup positioning

This commit is contained in:
IoIxD
2026-01-04 13:01:44 -07:00
parent 12f279e83a
commit d784770ca9
3 changed files with 20 additions and 10 deletions

View File

@@ -74,7 +74,7 @@ struct _MwLLWaylandPopup {
struct xdg_positioner* xdg_positioner;
struct xdg_surface_listener xdg_surface_listener;
struct xdg_wm_base* xdg_wm_base;
MwLL parent;
MwLL topmost_parent;
};
/* Shared set of anything needed for a shm buffer. */

View File

@@ -1263,12 +1263,14 @@ struct xdg_popup_listener popup_listener = {
};
/* Popup setup function */
static void setup_popup(MwLL r) {
static void setup_popup(MwLL r, int x, int y) {
int i;
struct xdg_surface* xdg_surface;
MwLL topmost_parent = r->wayland.parent;
r->wayland.type = MWLL_WAYLAND_POPUP;
r->wayland.x = x;
r->wayland.y = y;
while(topmost_parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) {
topmost_parent = topmost_parent->wayland.parent;
@@ -1276,6 +1278,7 @@ static void setup_popup(MwLL r) {
r->wayland.popup = malloc(sizeof(struct _MwLLWaylandPopup));
memset(r->wayland.popup, 0, sizeof(struct _MwLLWaylandPopup));
r->wayland.popup->topmost_parent = topmost_parent;
setup_callbacks(&r->wayland);
@@ -1288,14 +1291,16 @@ static void setup_popup(MwLL r) {
return;
}
r->wayland.popup->xdg_wm_base = WAYLAND_GET_INTERFACE(r->wayland, xdg_wm_base)->context;
r->wayland.popup->xdg_wm_base = WAYLAND_GET_INTERFACE(topmost_parent->wayland, xdg_wm_base)->context;
r->wayland.popup->xdg_positioner = xdg_wm_base_create_positioner(r->wayland.popup->xdg_wm_base);
xdg_positioner_set_size(r->wayland.popup->xdg_positioner, r->wayland.ww, r->wayland.wh);
xdg_positioner_set_anchor(r->wayland.popup->xdg_positioner, XDG_POSITIONER_ANCHOR_NONE);
xdg_positioner_set_anchor_rect(
r->wayland.popup->xdg_positioner, 0, 0,
1, 1);
r->wayland.popup->xdg_positioner, 0, 0, 1, 1);
printf("%d, %d\n", x, y);
xdg_positioner_set_offset(r->wayland.popup->xdg_positioner, x, y);
xdg_surface = topmost_parent->wayland.toplevel->xdg_surface;
@@ -1450,13 +1455,17 @@ static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsign
}
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
if(handle->wayland.type == MWLL_WAYLAND_SUBLEVEL) {
region_invalidate(handle);
handle->wayland.x = x;
handle->wayland.y = y;
if(handle->wayland.type == MWLL_WAYLAND_SUBLEVEL) {
wl_subsurface_set_position(handle->wayland.sublevel->subsurface, x, y);
region_setup(handle);
}
if(handle->wayland.type == MWLL_WAYLAND_POPUP) {
destroy_popup(handle);
setup_popup(handle, x, y);
}
region_setup(handle);
MwLLDispatch(handle, draw, NULL);
}
@@ -1761,7 +1770,7 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
switch(handle->wayland.type_to_be) {
case MWLL_WAYLAND_POPUP:
setup_popup(handle);
setup_popup(handle, point->x, point->y);
return;
default:
setup_toplevel(handle, point->x, point->y);

View File

@@ -188,6 +188,7 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, in
MwNy, rc.height - sz.height,
NULL);
}
MwLLEndStateChange(handle->lowlevel);
MwVaApply(handle,