mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-19 06:59:48 -05:00
Merge pull request #250 from acrisci/feature/surface-finder-to-wlr
move surface finder functions to wlroots
This commit is contained in:
commit
1c3c2ff90a
5 changed files with 92 additions and 72 deletions
|
|
@ -844,3 +844,35 @@ struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface) {
|
|||
|
||||
return surface;
|
||||
}
|
||||
|
||||
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface,
|
||||
double sx, double sy, double *sub_x, double *sub_y) {
|
||||
struct wlr_subsurface *subsurface;
|
||||
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
|
||||
double _sub_x = subsurface->surface->current->subsurface_position.x;
|
||||
double _sub_y = subsurface->surface->current->subsurface_position.y;
|
||||
struct wlr_subsurface *sub =
|
||||
wlr_surface_subsurface_at(subsurface->surface, _sub_x + sx,
|
||||
_sub_y + sy, sub_x, sub_y);
|
||||
if (sub) {
|
||||
// TODO: This won't work for nested subsurfaces. Convert sub_x and
|
||||
// sub_y to the parent coordinate system
|
||||
return sub;
|
||||
}
|
||||
|
||||
int sub_width = subsurface->surface->current->buffer_width;
|
||||
int sub_height = subsurface->surface->current->buffer_height;
|
||||
if ((sx > _sub_x && sx < _sub_x + sub_width) &&
|
||||
(sy > _sub_y && sy < _sub_y + sub_height)) {
|
||||
if (pixman_region32_contains_point(
|
||||
&subsurface->surface->current->input,
|
||||
sx - _sub_x, sy - _sub_y, NULL)) {
|
||||
*sub_x = _sub_x;
|
||||
*sub_y = _sub_y;
|
||||
return subsurface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1301,3 +1301,44 @@ void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {
|
|||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
zxdg_toplevel_v6_send_close(surface->toplevel_state->resource);
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
|
||||
struct wlr_xdg_surface_v6 *surface, double sx, double sy,
|
||||
double *popup_sx, double *popup_sy) {
|
||||
// XXX: I think this is so complicated because we're mixing geometry
|
||||
// coordinates with surface coordinates. Input handling should only deal
|
||||
// with surface coordinates.
|
||||
struct wlr_xdg_surface_v6 *popup;
|
||||
wl_list_for_each(popup, &surface->popups, popup_link) {
|
||||
double _popup_sx =
|
||||
surface->geometry->x + popup->popup_state->geometry.x;
|
||||
double _popup_sy =
|
||||
surface->geometry->y + popup->popup_state->geometry.y;
|
||||
int popup_width = popup->popup_state->geometry.width;
|
||||
int popup_height = popup->popup_state->geometry.height;
|
||||
|
||||
struct wlr_xdg_surface_v6 *_popup =
|
||||
wlr_xdg_surface_v6_popup_at(popup,
|
||||
sx - _popup_sx + popup->geometry->x,
|
||||
sy - _popup_sy + popup->geometry->y,
|
||||
popup_sx, popup_sy);
|
||||
if (_popup) {
|
||||
*popup_sx = *popup_sx + _popup_sx - popup->geometry->x;
|
||||
*popup_sy = *popup_sy + _popup_sy - popup->geometry->y;
|
||||
return _popup;
|
||||
}
|
||||
|
||||
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
|
||||
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
|
||||
if (pixman_region32_contains_point(&popup->surface->current->input,
|
||||
sx - _popup_sx + popup->geometry->x,
|
||||
sy - _popup_sy + popup->geometry->y, NULL)) {
|
||||
*popup_sx = _popup_sx - popup->geometry->x;
|
||||
*popup_sy = _popup_sy - popup->geometry->y;
|
||||
return popup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue