mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-04-04 07:15:44 -04:00
Refactor desktop_view_at
This commit is contained in:
parent
58a9f09617
commit
429392ac63
1 changed files with 20 additions and 14 deletions
34
cage.c
34
cage.c
|
|
@ -287,18 +287,18 @@ seat_request_cursor(struct wl_listener *listener, void *data)
|
||||||
* coordinates lx and ly (in output Layout Coordinates). If so, it sets the
|
* coordinates lx and ly (in output Layout Coordinates). If so, it sets the
|
||||||
* surface pointer to that wlr_surface and the sx and sy coordinates to the
|
* surface pointer to that wlr_surface and the sx and sy coordinates to the
|
||||||
* coordinates relative to that surface's top-left corner. */
|
* coordinates relative to that surface's top-left corner. */
|
||||||
static bool view_at(struct cg_view *view,
|
static bool
|
||||||
double lx, double ly,
|
view_at(struct cg_view *view, double lx, double ly,
|
||||||
struct wlr_surface **surface,
|
struct wlr_surface **surface, double *sx, double *sy)
|
||||||
double *sx, double *sy)
|
|
||||||
{
|
{
|
||||||
double view_sx = lx - view->x;
|
double view_sx = lx - view->x;
|
||||||
double view_sy = ly - view->y;
|
double view_sy = ly - view->y;
|
||||||
|
|
||||||
double _sx, _sy;
|
double _sx, _sy;
|
||||||
struct wlr_surface *_surface = NULL;
|
struct wlr_surface *_surface = NULL;
|
||||||
_surface = wlr_xdg_surface_surface_at(
|
_surface = wlr_xdg_surface_surface_at(view->xdg_surface,
|
||||||
view->xdg_surface, view_sx, view_sy, &_sx, &_sy);
|
view_sx, view_sy,
|
||||||
|
&_sx, &_sy);
|
||||||
|
|
||||||
if (_surface != NULL) {
|
if (_surface != NULL) {
|
||||||
*sx = _sx;
|
*sx = _sx;
|
||||||
|
|
@ -312,15 +312,18 @@ static bool view_at(struct cg_view *view,
|
||||||
|
|
||||||
/* This iterates over all of our surfaces and attempts to find one under the
|
/* This iterates over all of our surfaces and attempts to find one under the
|
||||||
* cursor. This relies on server->views being ordered from top-to-bottom. */
|
* cursor. This relies on server->views being ordered from top-to-bottom. */
|
||||||
static struct cg_view *desktop_view_at(
|
static struct cg_view *
|
||||||
struct cg_server *server, double lx, double ly,
|
desktop_view_at(struct cg_server *server, double lx, double ly,
|
||||||
struct wlr_surface **surface, double *sx, double *sy) {
|
struct wlr_surface **surface, double *sx, double *sy)
|
||||||
|
{
|
||||||
struct cg_view *view;
|
struct cg_view *view;
|
||||||
|
|
||||||
wl_list_for_each(view, &server->views, link) {
|
wl_list_for_each(view, &server->views, link) {
|
||||||
if (view_at(view, lx, ly, surface, sx, sy)) {
|
if (view_at(view, lx, ly, surface, sx, sy)) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,18 +339,19 @@ process_cursor_motion(struct cg_server *server, uint32_t time)
|
||||||
server->cursor->x, server->cursor->y,
|
server->cursor->x, server->cursor->y,
|
||||||
&surface, &sx, &sy);
|
&surface, &sx, &sy);
|
||||||
|
|
||||||
|
/* If desktop_view_at returns a view, there is also a
|
||||||
|
surface. There cannot be a surface without a view,
|
||||||
|
either. It's both or nothing. */
|
||||||
if (!view) {
|
if (!view) {
|
||||||
wlr_xcursor_manager_set_cursor_image(server->cursor_mgr, "left_ptr", server->cursor);
|
wlr_xcursor_manager_set_cursor_image(server->cursor_mgr, "left_ptr", server->cursor);
|
||||||
}
|
wlr_seat_pointer_clear_focus(seat);
|
||||||
if (surface) {
|
} else {
|
||||||
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
||||||
|
|
||||||
bool focus_changed = seat->pointer_state.focused_surface != surface;
|
bool focus_changed = seat->pointer_state.focused_surface != surface;
|
||||||
if (!focus_changed) {
|
if (!focus_changed) {
|
||||||
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
wlr_seat_pointer_clear_focus(seat);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +394,9 @@ server_cursor_button(struct wl_listener *listener, void *data)
|
||||||
double sx, sy;
|
double sx, sy;
|
||||||
struct wlr_surface *surface;
|
struct wlr_surface *surface;
|
||||||
struct cg_view *view = desktop_view_at(server,
|
struct cg_view *view = desktop_view_at(server,
|
||||||
server->cursor->x, server->cursor->y, &surface, &sx, &sy);
|
server->cursor->x,
|
||||||
|
server->cursor->y,
|
||||||
|
&surface, &sx, &sy);
|
||||||
if (view) {
|
if (view) {
|
||||||
focus_view(view);
|
focus_view(view);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue