diff options
Diffstat (limited to 'src/wayland/popup.c')
| -rw-r--r-- | src/wayland/popup.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/wayland/popup.c b/src/wayland/popup.c index f0ef305..63bcba6 100644 --- a/src/wayland/popup.c +++ b/src/wayland/popup.c @@ -23,13 +23,18 @@ static const struct xdg_popup_listener popup_listener = { .repositioned = popup_repositioned, }; -static bool popup_spec_valid(const struct yasl_popup_spec *spec) +static bool popup_spec_valid(const struct wayland_surface *parent, + const struct yasl_popup_spec *spec) { - return spec && spec->size.x > 0 && spec->size.y > 0 && + if (!parent || !spec) return false; + int64_t x = (int64_t)spec->anchor.x - parent->content.x; + int64_t y = (int64_t)spec->anchor.y - parent->content.y; + return x >= INT_MIN && x <= INT_MAX && y >= INT_MIN && y <= INT_MAX && + spec->size.x > 0 && spec->size.y > 0 && spec->content_offset.x >= 0 && spec->content_offset.y >= 0 && spec->content_size.x >= 0 && spec->content_size.y >= 0 && - spec->content_offset.x + spec->content_size.x <= spec->size.x && - spec->content_offset.y + spec->content_size.y <= spec->size.y; + (int64_t)spec->content_offset.x + spec->content_size.x <= spec->size.x && + (int64_t)spec->content_offset.y + spec->content_size.y <= spec->size.y; } static bool popup_apply_spec(struct wayland_surface *w, const struct yasl_popup_spec *spec) @@ -125,7 +130,7 @@ struct wayland_surface *wayland_surface_create_popup(struct wayland_surface *par struct wayland_display *c = parent ? parent->conn : NULL; struct seat *seat = c ? conn_active_seat(c) : NULL; if (!c || c->lost || parent->closed || !parent->xdg_surface || !seat || - !seat->input_serial || !popup_spec_valid(spec)) + !seat->input_serial || !popup_spec_valid(parent, spec)) return NULL; struct wayland_surface *w = calloc(1, sizeof(*w)); @@ -170,7 +175,7 @@ err: bool wayland_surface_popup_reposition(struct wayland_surface *w, const struct yasl_popup_spec *spec) { if (!w || !w->popup || w->closed || !w->conn || w->conn->lost || - !popup_spec_valid(spec) || + !popup_spec_valid(w->parent, spec) || xdg_popup_get_version(w->popup) < XDG_POPUP_REPOSITION_SINCE_VERSION) return false; struct yasl_popup_spec old = { |
