From 4c1bd9bde8e56814ca9c73b138bd8c9dc0469062 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 30 Sep 2017 12:33:39 -0400 Subject: input events for subsurfaces --- include/rootston/desktop.h | 3 ++- rootston/cursor.c | 17 ++++++++-------- rootston/desktop.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 392b0271..91ac87b7 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -52,7 +52,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, void desktop_destroy(struct roots_desktop *desktop); void view_destroy(struct roots_view *view); -struct roots_view *view_at(struct roots_desktop *desktop, int x, int y); +struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy); void view_activate(struct roots_view *view, bool activate); void output_add_notify(struct wl_listener *listener, void *data); diff --git a/rootston/cursor.c b/rootston/cursor.c index 2742e7cd..8839e9d7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -32,15 +32,14 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, void cursor_update_position(struct roots_input *input, uint32_t time) { struct roots_desktop *desktop = input->server->desktop; struct roots_view *view; + struct wlr_surface *surface; + double sx, sy; switch (input->mode) { case ROOTS_CURSOR_PASSTHROUGH: - view = view_at(desktop, input->cursor->x, input->cursor->y); + view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, + &sx, &sy); if (view) { - struct wlr_box box; - view_get_input_bounds(view, &box); - double sx = input->cursor->x - view->x; - double sy = input->cursor->y - view->y; - wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy); + wlr_seat_pointer_enter(input->wl_seat, surface, sx, sy); wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy); } else { wlr_seat_pointer_clear_focus(input->wl_seat); @@ -109,8 +108,10 @@ static void do_cursor_button_press(struct roots_input *input, struct wlr_cursor *cursor, struct wlr_input_device *device, uint32_t time, uint32_t button, uint32_t state) { struct roots_desktop *desktop = input->server->desktop; + struct wlr_surface *surface; + double sx, sy; struct roots_view *view = view_at(desktop, - input->cursor->x, input->cursor->y); + input->cursor->x, input->cursor->y, &surface, &sx, &sy); uint32_t serial = wlr_seat_pointer_send_button( input->wl_seat, time, button, state); int i; @@ -128,7 +129,7 @@ static void do_cursor_button_press(struct roots_input *input, % (sizeof(input->input_events) / sizeof(input->input_events[0])); set_view_focus(input, desktop, view); if (view) { - wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface); + wlr_seat_keyboard_enter(input->wl_seat, surface); } break; } diff --git a/rootston/desktop.c b/rootston/desktop.c index 4d1cb199..3233f25a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -41,14 +41,60 @@ void view_activate(struct roots_view *view, bool activate) { } } -struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) { +static struct wlr_subsurface *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 = + subsurface_at(subsurface->surface, _sub_x + sx, _sub_y + sy, + sub_x, sub_y); + if (sub) { + // TODO: 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 && sub_y < sub_y + sub_height)) { + *sub_x = _sub_x; + *sub_y = _sub_y; + return subsurface; + } + } + + return NULL; +} + +struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy) { for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *view = desktop->views->items[i]; + + double view_sx = lx - view->x; + double view_sy = ly - view->y; + + double sub_x, sub_y; + struct wlr_subsurface *subsurface = + subsurface_at(view->wlr_surface, view_sx, view_sy, &sub_x, &sub_y); + + if (subsurface) { + *sx = view_sx - sub_x; + *sy = view_sy - sub_y; + *surface = subsurface->surface; + return view; + } + struct wlr_box box; view_get_input_bounds(view, &box); box.x += view->x; box.y += view->y; - if (wlr_box_contains_point(&box, x, y)) { + if (wlr_box_contains_point(&box, lx, ly)) { + *sx = view_sx; + *sy = view_sy; + *surface = view->wlr_surface; return view; } } -- cgit v1.2.3