From e81e99d16d31765b51fcca31d5ffffd5087febfa Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 11:13:18 -0400 Subject: Render XDG shell surfaces --- rootston/xdg_shell_v6.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 rootston/xdg_shell_v6.c (limited to 'rootston/xdg_shell_v6.c') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c new file mode 100644 index 00000000..6c2bff55 --- /dev/null +++ b/rootston/xdg_shell_v6.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include "rootston/desktop.h" +#include "rootston/server.h" + +static void handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, destroy); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->ping_timeout.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_show_window_menu.link); + wl_list_remove(&roots_xdg_surface->request_minimize.link); + view_destroy(roots_xdg_surface->view); + free(roots_xdg_surface); +} + +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = + wl_container_of(listener, desktop, xdg_shell_v6_surface); + + struct wlr_xdg_surface_v6 *surface = data; + wlr_log(L_DEBUG, "new xdg surface: title=%s, app_id=%s", + surface->title, surface->app_id); + wlr_xdg_surface_v6_ping(surface); + + struct roots_xdg_surface_v6 *roots_surface = + calloc(1, sizeof(struct roots_xdg_surface_v6)); + // TODO: all of the trimmings + wl_list_init(&roots_surface->destroy.link); + roots_surface->destroy.notify = handle_destroy; + wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + wl_list_init(&roots_surface->ping_timeout.link); + wl_list_init(&roots_surface->request_minimize.link); + wl_list_init(&roots_surface->request_move.link); + wl_list_init(&roots_surface->request_resize.link); + wl_list_init(&roots_surface->request_show_window_menu.link); + + struct roots_view *view = calloc(1, sizeof(struct roots_view)); + view->type = ROOTS_XDG_SHELL_V6_VIEW; + view->x = view->y = 200; + view->xdg_surface_v6 = surface; + view->roots_xdg_surface_v6 = roots_surface; + view->wlr_surface = surface->surface; + roots_surface->view = view; + wl_list_insert(&desktop->views, &view->link); +} -- cgit v1.2.3 From eaf6c0ccf4a8fc78580a49335adb1783dbebd9af Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 17:48:13 -0400 Subject: Implement pointer motion and buttons --- include/rootston/desktop.h | 2 ++ include/rootston/view.h | 12 ++++++- rootston/cursor.c | 78 ++++++++++++++++++++++++---------------------- rootston/desktop.c | 29 +++++++++++++++++ rootston/input.c | 2 ++ rootston/xdg_shell_v6.c | 21 ++++++++++++- types/wlr_seat.c | 1 + 7 files changed, 106 insertions(+), 39 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 8fb55219..62050972 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -48,6 +48,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); +void view_activate(struct roots_view *view, bool activate); void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); diff --git a/include/rootston/view.h b/include/rootston/view.h index 9535094b..9e7c4a01 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -1,8 +1,9 @@ #ifndef _ROOTSTON_VIEW_H #define _ROOTSTON_VIEW_H #include -#include +#include #include +#include struct roots_wl_shell_surface { // TODO @@ -41,6 +42,15 @@ struct roots_view { }; struct wlr_surface *wlr_surface; struct wl_list link; + // TODO: This would probably be better as a field that's updated on a + // configure event from the xdg_shell + // If not then this should follow the typical type/impl pattern we use + // elsewhere + void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box); + void (*activate)(struct roots_view *view, bool active); }; +void view_get_input_bounds(struct roots_view *view, struct wlr_box *box); +void view_activate(struct roots_view *view, bool active); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index d5507289..f06369f4 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "rootston/config.h" #include "rootston/input.h" #include "rootston/desktop.h" @@ -15,23 +16,34 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { surface->position.ly = sample->cursor->y - sample->motion_context.off_y; return; } - - struct wlr_xdg_surface_v6 *surface = example_xdg_surface_at(sample, - sample->cursor->x, sample->cursor->y); - - if (surface) { - struct example_xdg_surface_v6 *esurface = surface->data; - - double sx = sample->cursor->x - esurface->position.lx; - double sy = sample->cursor->y - esurface->position.ly; - - // TODO z-order - wlr_seat_pointer_enter(sample->wl_seat, surface->surface, sx, sy); - wlr_seat_pointer_send_motion(sample->wl_seat, time, sx, sy); + */ + struct roots_desktop *desktop = input->server->desktop; + struct roots_view *view = view_at( + desktop, input->cursor->x, input->cursor->y); + 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_log(L_DEBUG, "Moving cursor in view at %f, %f", sx, sy); + wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy); + wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy); } else { - wlr_seat_pointer_clear_focus(sample->wl_seat); + wlr_seat_pointer_clear_focus(input->wl_seat); } - */ +} + +static void set_view_focus(struct roots_input *input, + struct roots_desktop *desktop, struct roots_view *view) { + if (input->active_view == view) { + return; + } + struct roots_view *_view; + wl_list_for_each(_view, &desktop->views, link) { + view_activate(_view, _view == view); + } + input->active_view = view; + input->mode = ROOTS_CURSOR_PASSTHROUGH; } static void handle_cursor_motion(struct wl_listener *listener, void *data) { @@ -61,43 +73,35 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { } static void handle_cursor_button(struct wl_listener *listener, void *data) { - /* TODO - struct sample_state *sample = - wl_container_of(listener, sample, cursor_button); + struct roots_input *input = wl_container_of(listener, input, cursor_button); struct wlr_event_pointer_button *event = data; - struct wlr_xdg_surface_v6 *surface = - example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y); + struct roots_desktop *desktop = input->server->desktop; + struct roots_view *view = view_at( + desktop, input->cursor->x, input->cursor->y); - uint32_t serial = wlr_seat_pointer_send_button(sample->wl_seat, + uint32_t serial = wlr_seat_pointer_send_button(input->wl_seat, (uint32_t)event->time_usec, event->button, event->state); int i; switch (event->state) { case WLR_BUTTON_RELEASED: + /* if (sample->motion_context.surface) { sample->motion_context.surface = NULL; } + */ break; case WLR_BUTTON_PRESSED: - i = sample->input_cache_idx; - sample->input_cache[i].serial = serial; - sample->input_cache[i].cursor = sample->cursor; - sample->input_cache[i].device = event->device; - sample->input_cache_idx = (i + 1) - % (sizeof(sample->input_cache) / sizeof(sample->input_cache[0])); - example_set_focused_surface(sample, surface); - wlr_log(L_DEBUG, "Stored event %d at %d", serial, i); - if (sample->mod_down && event->button == BTN_LEFT) { - struct example_xdg_surface_v6 *esurface = surface->data; - sample->motion_context.surface = esurface; - sample->motion_context.off_x = sample->cursor->x - esurface->position.lx; - sample->motion_context.off_y = sample->cursor->y - esurface->position.ly; - wlr_seat_pointer_clear_focus(sample->wl_seat); - } + i = input->input_events_idx; + input->input_events[i].serial = serial; + input->input_events[i].cursor = input->cursor; + input->input_events[i].device = event->device; + input->input_events_idx = (i + 1) + % (sizeof(input->input_events) / sizeof(input->input_events[0])); + set_view_focus(input, desktop, view); break; } - */ } static void handle_tool_axis(struct wl_listener *listener, void *data) { diff --git a/rootston/desktop.c b/rootston/desktop.c index fbaf9cac..f0495fa1 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 199309L #include #include +#include #include #include #include @@ -16,6 +17,34 @@ void view_destroy(struct roots_view *view) { free(view); } +void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) { + if (view->get_input_bounds) { + view->get_input_bounds(view, box); + return; + } + box->x = box->y = 0; +} + +void view_activate(struct roots_view *view, bool activate) { + if (view->activate) { + view->activate(view, activate); + } +} + +struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) { + struct roots_view *view; + wl_list_for_each(view, &desktop->views, link) { + 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)) { + return view; + } + } + return NULL; +} + struct roots_desktop *desktop_create(struct roots_server *server, struct roots_config *config) { struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop)); diff --git a/rootston/input.c b/rootston/input.c index 9ad20b58..4925226a 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -82,6 +82,8 @@ struct roots_input *input_create(struct roots_server *server, assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr")); assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0")); + wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD + | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH); wl_list_init(&input->keyboards); wl_list_init(&input->pointers); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 6c2bff55..0c32bd97 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -1,11 +1,28 @@ +#include #include +#include #include -#include +#include #include +#include #include #include "rootston/desktop.h" #include "rootston/server.h" +static void get_input_bounds(struct roots_view *view, struct wlr_box *box) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; + memcpy(box, surf->geometry, sizeof(struct wlr_box)); +} + +static void activate(struct roots_view *view, bool active) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; + if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_set_activated(surf, active); + } +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -46,6 +63,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; view->wlr_surface = surface->surface; + view->get_input_bounds = get_input_bounds; + view->activate = activate; roots_surface->view = view; wl_list_insert(&desktop->views, &view->link); } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index cbf1abc7..24dbe19e 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -157,6 +157,7 @@ static void wl_seat_bind(struct wl_client *wl_client, void *_wlr_seat, wl_resource_set_implementation(handle->wl_resource, &wl_seat_impl, handle, wlr_seat_handle_resource_destroy); wl_list_insert(&wlr_seat->handles, &handle->link); + wl_seat_send_name(handle->wl_resource, wlr_seat->name); wl_seat_send_capabilities(handle->wl_resource, wlr_seat->capabilities); wl_signal_emit(&wlr_seat->events.client_bound, handle); } -- cgit v1.2.3 From 0ca7932c3f23dddd7e8375a89e727223d665c8d5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 18:18:19 -0400 Subject: Implement xdg surface request_move --- include/rootston/view.h | 1 + rootston/cursor.c | 58 +++++++++++++++++++++++-------------------------- rootston/xdg_shell_v6.c | 30 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 31 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index 9e7c4a01..b74d1075 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -28,6 +28,7 @@ enum roots_view_type { }; struct roots_view { + struct roots_desktop *desktop; double x, y; float rotation; // TODO: Something for roots-enforced width/height diff --git a/rootston/cursor.c b/rootston/cursor.c index 9c2ff8c3..0e9bf748 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -1,5 +1,7 @@ #include #include +// TODO: BSD et al +#include #include #include #include @@ -18,7 +20,6 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { view_get_input_bounds(view, &box); double sx = input->cursor->x - view->x; double sy = input->cursor->y - view->y; - wlr_log(L_DEBUG, "Moving cursor in view at %f, %f", sx, sy); wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy); wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy); } else { @@ -26,21 +27,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { } break; case ROOTS_CURSOR_MOVE: + if (input->active_view) { + input->active_view->x = input->cursor->x - input->offs_x; + input->active_view->y = input->cursor->y - input->offs_y; + } break; case ROOTS_CURSOR_RESIZE: break; case ROOTS_CURSOR_ROTATE: break; } - /* - if (input->motion_context.surface) { - struct example_xdg_surface_v6 *surface; - surface = sample->motion_context.surface; - surface->position.lx = sample->cursor->x - sample->motion_context.off_x; - surface->position.ly = sample->cursor->y - sample->motion_context.off_y; - return; - } - */ } static void set_view_focus(struct roots_input *input, @@ -82,27 +78,25 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { event->orientation, event->delta); } -static void handle_cursor_button(struct wl_listener *listener, void *data) { - struct roots_input *input = wl_container_of(listener, input, cursor_button); - struct wlr_event_pointer_button *event = data; - +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 roots_view *view = view_at( - desktop, input->cursor->x, input->cursor->y); - - uint32_t serial = wlr_seat_pointer_send_button(input->wl_seat, - (uint32_t)event->time_usec, event->button, event->state); - + struct roots_view *view = view_at(desktop, + input->cursor->x, input->cursor->y); + uint32_t serial = wlr_seat_pointer_send_button( + input->wl_seat, time, button, state); int i; - switch (event->state) { + switch (state) { case WLR_BUTTON_RELEASED: input->active_view = NULL; + input->mode = ROOTS_CURSOR_PASSTHROUGH; break; case WLR_BUTTON_PRESSED: i = input->input_events_idx; input->input_events[i].serial = serial; - input->input_events[i].cursor = input->cursor; - input->input_events[i].device = event->device; + input->input_events[i].cursor = cursor; + input->input_events[i].device = device; input->input_events_idx = (i + 1) % (sizeof(input->input_events) / sizeof(input->input_events[0])); set_view_focus(input, desktop, view); @@ -110,6 +104,13 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { } } +static void handle_cursor_button(struct wl_listener *listener, void *data) { + struct roots_input *input = wl_container_of(listener, input, cursor_button); + struct wlr_event_pointer_button *event = data; + do_cursor_button_press(input, input->cursor, event->device, + (uint32_t)event->time_usec, event->button, event->state); +} + static void handle_tool_axis(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis); struct wlr_event_tablet_tool_axis *event = data; @@ -122,15 +123,10 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { } static void handle_tool_tip(struct wl_listener *listener, void *data) { - struct roots_input *input = wl_container_of(listener, input, tool_tip); + struct roots_input *input = wl_container_of(listener, input, cursor_tool_tip); struct wlr_event_tablet_tool_tip *event = data; - - struct roots_desktop *desktop = input->server->desktop; - struct roots_view *view = view_at( - desktop, input->cursor->x, input->cursor->y); - set_view_focus(input, desktop, view); - wlr_seat_pointer_send_button(input->wl_seat, (uint32_t)event->time_usec, - BTN_LEFT, event->state); + do_cursor_button_press(input, input->cursor, event->device, + (uint32_t)event->time_usec, BTN_LEFT, event->state); } void cursor_initialize(struct roots_input *input) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0c32bd97..4a809930 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -8,6 +8,7 @@ #include #include "rootston/desktop.h" #include "rootston/server.h" +#include "rootston/input.h" static void get_input_bounds(struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); @@ -23,6 +24,32 @@ static void activate(struct roots_view *view, bool active) { } } +static void handle_request_move(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, request_move); + struct roots_view *view = roots_xdg_surface->view; + struct roots_input *input = view->desktop->server->input; + struct wlr_xdg_toplevel_v6_move_event *e = data; + + // TODO: Some of this might want to live in cursor.c I guess + struct roots_input_event *event = NULL; + size_t len = sizeof(input->input_events) / sizeof(*input->input_events); + for (size_t i = 0; i < len; ++i) { + if (input->input_events[i].cursor + && input->input_events[i].serial == e->serial) { + event = &input->input_events[i]; + break; + } + } + if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + return; + } + input->mode = ROOTS_CURSOR_MOVE; + input->offs_x = input->cursor->x - view->x; + input->offs_y = input->cursor->y - view->y; + wlr_seat_pointer_clear_focus(input->wl_seat); +} + static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); @@ -54,6 +81,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { wl_list_init(&roots_surface->ping_timeout.link); wl_list_init(&roots_surface->request_minimize.link); wl_list_init(&roots_surface->request_move.link); + roots_surface->request_move.notify = handle_request_move; + wl_signal_add(&surface->events.request_move, &roots_surface->request_move); wl_list_init(&roots_surface->request_resize.link); wl_list_init(&roots_surface->request_show_window_menu.link); @@ -65,6 +94,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->wlr_surface = surface->surface; view->get_input_bounds = get_input_bounds; view->activate = activate; + view->desktop = desktop; roots_surface->view = view; wl_list_insert(&desktop->views, &view->link); } -- cgit v1.2.3