Fix xdg-shell popups, add wlr_xdg_surface_surface_at

master
emersion 7 years ago
parent c9d21106b4
commit 3ea425d4e2
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -215,19 +215,19 @@ uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface,
void wlr_xdg_surface_send_close(struct wlr_xdg_surface *surface); void wlr_xdg_surface_send_close(struct wlr_xdg_surface *surface);
/** /**
* Compute the popup position in surface-local coordinates. * Compute the popup position in its parent's surface-local coordinate system.
*/ */
void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface, void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
double *popup_sx, double *popup_sy); double *popup_sx, double *popup_sy);
/** /**
* Find a popup within this surface at the surface-local coordinates. Returns * Find a surface within this xdg-surface tree at the given surface-local
* the popup and coordinates in the topmost surface coordinate system or NULL if * coordinates. Returns the surface and coordinates in the leaf surface
* no popup is found at that location. * coordinate system or NULL if no surface is found at that location.
*/ */
struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_surface *wlr_xdg_surface_surface_at(
struct wlr_xdg_surface *surface, double sx, double sy, struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy); double *sub_x, double *sub_y);
bool wlr_surface_is_xdg_surface(struct wlr_surface *surface); bool wlr_surface_is_xdg_surface(struct wlr_surface *surface);

@ -584,12 +584,15 @@ static bool view_at(struct roots_view *view, double lx, double ly,
_surface = wlr_xdg_surface_v6_surface_at(view->xdg_surface_v6, _surface = wlr_xdg_surface_v6_surface_at(view->xdg_surface_v6,
view_sx, view_sy, &_sx, &_sy); view_sx, view_sy, &_sx, &_sy);
break; break;
case ROOTS_XDG_SHELL_VIEW:
_surface = wlr_xdg_surface_surface_at(view->xdg_surface,
view_sx, view_sy, &_sx, &_sy);
break;
case ROOTS_WL_SHELL_VIEW: case ROOTS_WL_SHELL_VIEW:
_surface = wlr_wl_shell_surface_surface_at(view->wl_shell_surface, _surface = wlr_wl_shell_surface_surface_at(view->wl_shell_surface,
view_sx, view_sy, &_sx, &_sy); view_sx, view_sy, &_sx, &_sy);
break; break;
case ROOTS_XWAYLAND_VIEW: case ROOTS_XWAYLAND_VIEW:
case ROOTS_XDG_SHELL_VIEW: // TODO
_surface = wlr_surface_surface_at(view->wlr_surface, _surface = wlr_surface_surface_at(view->wlr_surface,
view_sx, view_sy, &_sx, &_sy); view_sx, view_sy, &_sx, &_sy);
break; break;

@ -1638,45 +1638,24 @@ void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
surface->geometry.y; surface->geometry.y;
} }
struct wlr_xdg_surface *wlr_xdg_surface_popup_at( struct wlr_surface *wlr_xdg_surface_surface_at(
struct wlr_xdg_surface *surface, double sx, double sy, struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy) { double *sub_x, double *sub_y) {
// 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_popup *popup_state; struct wlr_xdg_popup *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) { wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface *popup = popup_state->base; struct wlr_xdg_surface *popup = popup_state->base;
double _popup_sx = double popup_sx, popup_sy;
surface->geometry.x + popup_state->geometry.x; wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
double _popup_sy =
surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
struct wlr_xdg_surface *_popup =
wlr_xdg_surface_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) && struct wlr_surface *sub = wlr_xdg_surface_surface_at(popup,
(sy > _popup_sy && sy < _popup_sy + popup_height)) { sx - popup_sx + popup->geometry.x,
if (pixman_region32_contains_point(&popup->surface->current->input, sy - popup_sy + popup->geometry.y,
sx - _popup_sx + popup->geometry.x, sub_x, sub_y);
sy - _popup_sy + popup->geometry.y, NULL)) { if (sub != NULL) {
*popup_sx = _popup_sx - popup->geometry.x; return sub;
*popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
} }
} }
return NULL; return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
} }

Loading…
Cancel
Save