diff --git a/src/casilda-compositor.c b/src/casilda-compositor.c index fa2db33..428f028 100644 --- a/src/casilda-compositor.c +++ b/src/casilda-compositor.c @@ -2625,15 +2625,35 @@ server_new_xdg_toplevel (struct wl_listener *listener, void *data) surface_notify_scale (xdg_toplevel->base->surface, priv->scale); } +/* Leave a margin so that popups are not right next to the compositor border */ +#define POSITIONER_MARGIN 4 + static void xdg_popup_commit (struct wl_listener *listener, G_GNUC_UNUSED void *data) { CasildaCompositorPopup *popup = wl_container_of (listener, popup, commit); + CasildaCompositorPrivate *priv = popup->priv; if (popup->xdg_popup->base->initial_commit) - wlr_xdg_surface_schedule_configure (popup->xdg_popup->base); + { + CasildaCompositorToplevel *toplevel = popup->toplevel; + struct wlr_box *geo = &toplevel->xdg_toplevel->base->geometry; + gint offset_x, offset_y; - casilda_compositor_queue_draw (popup->priv); + casilda_compositor_get_scroll_offset (priv, &offset_x, &offset_y); + + struct wlr_box box = { + .x = offset_x + ((toplevel->x - geo->x) * -1) + POSITIONER_MARGIN, + .y = offset_y + ((toplevel->y - geo->y) * -1) + POSITIONER_MARGIN, + .width = gtk_widget_get_width (priv->self) - POSITIONER_MARGIN * 2, + .height = gtk_widget_get_height (priv->self) - POSITIONER_MARGIN * 2, + }; + + /* Define popup position box in parent toplevel coordinates */ + wlr_xdg_popup_unconstrain_from_box (popup->xdg_popup, &box); + } + + casilda_compositor_queue_draw (priv); } static void