From b6d7c3ed8ec6ae29af5d585db5417394ff49f3c7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 00:29:53 -0400 Subject: Initialize display, backend; add frame handling --- rootston/desktop.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rootston/desktop.c (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c new file mode 100644 index 00000000..551d289a --- /dev/null +++ b/rootston/desktop.c @@ -0,0 +1,59 @@ +#define _POSIX_C_SOURCE 199309L +#include +#include +#include +#include +#include +#include +#include +#include +#include "rootston/desktop.h" +#include "rootston/server.h" + +static 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_desktop *desktop_create(struct roots_server *server, + struct roots_config *config) { + struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop)); + wlr_log(L_DEBUG, "Initializing roots desktop"); + + wl_list_init(&desktop->outputs); + wl_list_init(&desktop->output_add.link); + desktop->output_add.notify = output_add_notify; + wl_list_init(&desktop->output_remove.link); + desktop->output_remove.notify = output_remove_notify; + + wl_signal_add(&server->backend->events.output_add, + &desktop->output_add); + wl_signal_add(&server->backend->events.output_remove, + &desktop->output_remove); + + desktop->server = server; + desktop->config = config; + desktop->layout = wlr_output_layout_create(); + desktop->compositor = wlr_compositor_create( + server->wl_display, server->renderer); + desktop->wl_shell = wlr_wl_shell_create(server->wl_display); + + desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display); + wl_signal_add(&desktop->xdg_shell_v6->events.new_surface, + &desktop->xdg_shell_v6_surface); + desktop->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; + + desktop->gamma_control_manager = wlr_gamma_control_manager_create( + server->wl_display); + + return desktop; +} + +void desktop_destroy(struct roots_desktop *desktop) { + // TODO +} -- cgit v1.2.3 From 0699aa62d805fe61151189ab9989178fbbb456f2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 10:13:05 -0400 Subject: Initial pass on roots_input --- backend/wayland/backend.c | 12 +++--- include/rootston/input.h | 24 +++++++---- rootston/desktop.c | 8 +++- rootston/input.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ rootston/main.c | 1 + rootston/meson.build | 1 + 6 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 rootston/input.c (limited to 'rootston/desktop.c') diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 3ac2ea7d..264ce338 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -35,6 +35,12 @@ static bool wlr_wl_backend_start(struct wlr_backend *_backend) { struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; wlr_log(L_INFO, "Initializating wayland backend"); + wlr_wl_registry_poll(backend); + if (!(backend->compositor) || (!(backend->shell))) { + wlr_log_errno(L_ERROR, "Could not obtain retrieve required globals"); + return false; + } + backend->started = true; for (size_t i = 0; i < backend->requested_outputs; ++i) { wlr_wl_output_create(&backend->backend); @@ -139,12 +145,6 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { return false; } - wlr_wl_registry_poll(backend); - if (!(backend->compositor) || (!(backend->shell))) { - wlr_log_errno(L_ERROR, "Could not obtain retrieve required globals"); - return false; - } - wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT, backend->remote_display); wlr_egl_bind_display(&backend->egl, backend->local_display); diff --git a/include/rootston/input.h b/include/rootston/input.h index 88505201..b60eccbd 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -6,6 +6,7 @@ #include #include #include +#include "rootston/config.h" #include "rootston/view.h" struct roots_keyboard { @@ -52,10 +53,10 @@ struct roots_tablet_tool { }; enum roots_cursor_mode { - ROOTS_CURSOR_PASSTHROUGH, - ROOTS_CURSOR_MOVE, - ROOTS_CURSOR_RESIZE, - ROOTS_CURSOR_ROTATE, + ROOTS_CURSOR_PASSTHROUGH = 0, + ROOTS_CURSOR_MOVE = 1, + ROOTS_CURSOR_RESIZE = 2, + ROOTS_CURSOR_ROTATE = 3, }; struct roots_input_event { @@ -65,16 +66,15 @@ struct roots_input_event { }; struct roots_input { + struct roots_config *config; + // TODO: multiseat, multicursor struct wlr_cursor *cursor; struct wlr_xcursor *xcursor; struct wlr_seat *wl_seat; enum roots_cursor_mode mode; - struct roots_view *focused_view; - struct roots_view *moving_view; - struct roots_view *resizing_view; - struct roots_view *rotating_view; + struct roots_view *active_view; int offs_x, offs_y; // Ring buffer of input events that could trigger move/resize/rotate @@ -85,7 +85,13 @@ struct roots_input { struct wl_list pointers; struct wl_list touch; struct wl_list tablet_tools; - struct wl_list tablet_pads; + + struct wl_listener input_add; + struct wl_listener input_remove; }; +struct roots_input *input_create(struct roots_server *server, + struct roots_config *config); +void input_destroy(struct roots_input *input); + #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 551d289a..86d128ef 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -1,11 +1,12 @@ #define _POSIX_C_SOURCE 199309L #include #include -#include #include +#include +#include +#include #include #include -#include #include #include "rootston/desktop.h" #include "rootston/server.h" @@ -43,6 +44,9 @@ struct roots_desktop *desktop_create(struct roots_server *server, server->wl_display, server->renderer); desktop->wl_shell = wlr_wl_shell_create(server->wl_display); + wlr_cursor_attach_output_layout(server->input->cursor, desktop->layout); + wlr_cursor_map_to_region(server->input->cursor, config->cursor.mapped_box); + desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display); wl_signal_add(&desktop->xdg_shell_v6->events.new_surface, &desktop->xdg_shell_v6_surface); diff --git a/rootston/input.c b/rootston/input.c new file mode 100644 index 00000000..8764e9b0 --- /dev/null +++ b/rootston/input.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include "rootston/server.h" +#include "rootston/config.h" +#include "rootston/input.h" + +static const char *device_type(enum wlr_input_device_type type) { + switch (type) { + case WLR_INPUT_DEVICE_KEYBOARD: + return "keyboard"; + case WLR_INPUT_DEVICE_POINTER: + return "pointer"; + case WLR_INPUT_DEVICE_TOUCH: + return "touch"; + case WLR_INPUT_DEVICE_TABLET_TOOL: + return "tablet tool"; + case WLR_INPUT_DEVICE_TABLET_PAD: + return "tablet pad"; + } + return NULL; +} + +static void input_add_notify(struct wl_listener *listener, void *data) { + struct wlr_input_device *device = data; + struct roots_input *input = wl_container_of(listener, input, input_add); + wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name, + device->vendor, device->product, device_type(device->type)); + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + //keyboard_add(device, state); + break; + case WLR_INPUT_DEVICE_POINTER: + //pointer_add(device, state); + break; + case WLR_INPUT_DEVICE_TOUCH: + //touch_add(device, state); + break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + //tablet_tool_add(device, state); + break; + default: + break; + } +} + +static void input_remove_notify(struct wl_listener *listener, void *data) { + struct wlr_input_device *device = data; + struct roots_input *input = wl_container_of(listener, input, input_remove); + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + //keyboard_remove(device, state); + break; + case WLR_INPUT_DEVICE_POINTER: + //pointer_remove(device, state); + break; + case WLR_INPUT_DEVICE_TOUCH: + //touch_remove(device, state); + break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + //tablet_tool_remove(device, state); + break; + default: + break; + } +} + +struct roots_input *input_create(struct roots_server *server, + struct roots_config *config) { + wlr_log(L_DEBUG, "Initializing roots input"); + struct roots_input *input = calloc(1, sizeof(struct roots_input)); + assert(input); + + input->config = config; + input->cursor = wlr_cursor_create(); + + struct wlr_xcursor_theme *theme; + assert(theme = wlr_xcursor_theme_load("default", 16)); + assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr")); + wlr_cursor_set_xcursor(input->cursor, input->xcursor); + assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0")); + + wl_list_init(&input->keyboards); + wl_list_init(&input->pointers); + wl_list_init(&input->touch); + wl_list_init(&input->tablet_tools); + + wl_list_init(&input->input_add.link); + input->input_add.notify = input_add_notify; + wl_list_init(&input->input_remove.link); + input->input_remove.notify = input_remove_notify; + + wl_signal_add(&server->backend->events.input_add, + &input->input_add); + wl_signal_add(&server->backend->events.input_remove, + &input->input_remove); + + return input; +} + +void input_destroy(struct roots_input *input) { + // TODO +} diff --git a/rootston/main.c b/rootston/main.c index b95840a9..c8ec1249 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -20,6 +20,7 @@ int main(int argc, char **argv) { assert(server.renderer = wlr_gles2_renderer_create(server.backend)); wl_display_init_shm(server.wl_display); + server.input = input_create(&server, server.config); server.desktop = desktop_create(&server, server.config); server.data_device_manager = wlr_data_device_manager_create( server.wl_display); diff --git a/rootston/meson.build b/rootston/meson.build index 9342d19c..ba1fb1c0 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -3,6 +3,7 @@ executable( 'config.c', 'desktop.c', 'ini.c', + 'input.c', 'main.c', 'output.c', ], dependencies: wlroots -- cgit v1.2.3 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 --- include/rootston/desktop.h | 7 +++++++ include/rootston/view.h | 21 +++++++++++-------- rootston/desktop.c | 12 ++++------- rootston/meson.build | 3 ++- rootston/output.c | 42 +++++++++++++++++++++++++++++++++++++- rootston/xdg_shell_v6.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 rootston/xdg_shell_v6.c (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 3d31059c..8fb55219 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -21,8 +21,11 @@ struct roots_output { }; struct roots_desktop { + struct wl_list views; + struct wl_list outputs; struct timespec last_frame; + struct roots_server *server; struct roots_config *config; @@ -44,7 +47,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, struct roots_config *config); void desktop_destroy(struct roots_desktop *desktop); +void view_destroy(struct roots_view *view); + void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); + #endif diff --git a/include/rootston/view.h b/include/rootston/view.h index d33e6bfb..9535094b 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -1,5 +1,8 @@ #ifndef _ROOTSTON_VIEW_H #define _ROOTSTON_VIEW_H +#include +#include +#include struct roots_wl_shell_surface { // TODO @@ -7,13 +10,14 @@ struct roots_wl_shell_surface { }; struct roots_xdg_surface_v6 { + struct roots_view *view; // TODO: Maybe destroy listener should go in roots_view - struct wl_listener destroy_listener; - struct wl_listener ping_timeout_listener; - struct wl_listener request_minimize_listener; - struct wl_listener request_move_listener; - struct wl_listener request_resize_listener; - struct wl_listener request_show_window_menu_listener; + struct wl_listener destroy; + struct wl_listener ping_timeout; + struct wl_listener request_minimize; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_show_window_menu; }; enum roots_view_type { @@ -29,12 +33,13 @@ struct roots_view { enum roots_view_type type; union { struct wlr_shell_surface *wl_shell_surface; - struct xdg_shell_v6_surface *xdg_shell_v6_surface; + struct wlr_xdg_surface_v6 *xdg_surface_v6; }; union { struct roots_wl_shell_surface *roots_wl_shell_surface; - struct xdg_shell_v6_surface *roots_xdg_surface_v6; + struct roots_xdg_surface_v6 *roots_xdg_surface_v6; }; + struct wlr_surface *wlr_surface; struct wl_list link; }; diff --git a/rootston/desktop.c b/rootston/desktop.c index 86d128ef..fc341a23 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -11,14 +11,9 @@ #include "rootston/desktop.h" #include "rootston/server.h" -static 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); +void view_destroy(struct roots_view *view) { + wl_list_remove(&view->link); + free(view); } struct roots_desktop *desktop_create(struct roots_server *server, @@ -26,6 +21,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop)); wlr_log(L_DEBUG, "Initializing roots desktop"); + wl_list_init(&desktop->views); wl_list_init(&desktop->outputs); wl_list_init(&desktop->output_add.link); desktop->output_add.notify = output_add_notify; diff --git a/rootston/meson.build b/rootston/meson.build index 6fc4452f..03ca837a 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -6,6 +6,7 @@ executable( 'input.c', 'main.c', 'output.c', - 'pointer.c' + 'pointer.c', + 'xdg_shell_v6.c' ], dependencies: wlroots ) diff --git a/rootston/output.c b/rootston/output.c index 39586e0e..481832cf 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -1,15 +1,43 @@ #define _POSIX_C_SOURCE 199309L #include #include +#include #include #include #include #include +#include #include #include "rootston/server.h" #include "rootston/desktop.h" #include "rootston/config.h" +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + +static void render_view(struct roots_desktop *desktop, + struct wlr_output *wlr_output, struct timespec *when, + struct roots_view *view, double ox, double oy) { + struct wlr_surface *surface = view->wlr_surface; + float matrix[16]; + float transform[16]; + wlr_surface_flush_damage(surface); + if (surface->texture->valid) { + wlr_matrix_translate(&transform, ox, oy, 0); + wlr_surface_get_matrix(surface, &matrix, + &wlr_output->transform_matrix, &transform); + wlr_render_with_matrix(desktop->server->renderer, + surface->texture, &matrix); + + struct wlr_frame_callback *cb, *cnext; + wl_list_for_each_safe(cb, cnext, &surface->frame_callback_list, link) { + wl_callback_send_done(cb->resource, timespec_to_msec(when)); + wl_resource_destroy(cb->resource); + } + } +} + static void output_frame_notify(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; struct roots_output *output = wl_container_of(listener, output, frame); @@ -22,7 +50,19 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); - // TODO: render views + struct roots_view *view; + wl_list_for_each(view, &desktop->views, link) { + int width = view->wlr_surface->current.buffer_width; + int height = view->wlr_surface->current.buffer_height; + + if (wlr_output_layout_intersects(desktop->layout, wlr_output, + view->x, view->y, view->x + width, view->y + height)) { + double ox = view->x, oy = view->y; + wlr_output_layout_output_coords( + desktop->layout, wlr_output, &ox, &oy); + render_view(desktop, wlr_output, &now, view, ox, oy); + } + } wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); 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 57c50c78f05c25dfb82d0ef69264fca00e4b3e04 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 23 Sep 2017 14:53:15 -0400 Subject: Implement wlr_cursor in rootston --- include/rootston/input.h | 14 ++++ rootston/cursor.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++- rootston/desktop.c | 2 + rootston/input.c | 8 +- rootston/meson.build | 1 + rootston/output.c | 9 +-- rootston/pointer.c | 29 +------ 7 files changed, 220 insertions(+), 35 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/input.h b/include/rootston/input.h index 4177ffa8..4ac11959 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -68,6 +68,7 @@ struct roots_input_event { struct roots_input { struct roots_config *config; + struct roots_server *server; // TODO: multiseat, multicursor struct wlr_cursor *cursor; @@ -89,6 +90,13 @@ struct roots_input { struct wl_listener input_add; struct wl_listener input_remove; + + struct wl_listener cursor_motion; + struct wl_listener cursor_motion_absolute; + struct wl_listener cursor_button; + struct wl_listener cursor_axis; + struct wl_listener cursor_tool_axis; + struct wl_listener cursor_tool_tip; }; struct roots_input *input_create(struct roots_server *server, @@ -97,4 +105,10 @@ void input_destroy(struct roots_input *input); void pointer_add(struct wlr_input_device *device, struct roots_input *input); +void cursor_initialize(struct roots_input *input); +void cursor_load_config(struct roots_config *config, + struct wlr_cursor *cursor, + struct roots_input *input, + struct roots_desktop *desktop); + #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 100e4b32..d5507289 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -1,3 +1,10 @@ +#include +#include +#include +#include +#include "rootston/config.h" +#include "rootston/input.h" +#include "rootston/desktop.h" void cursor_update_position(struct roots_input *input, uint32_t time) { /* @@ -8,7 +15,6 @@ 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); @@ -25,4 +31,188 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { } else { wlr_seat_pointer_clear_focus(sample->wl_seat); } + */ +} + +static void handle_cursor_motion(struct wl_listener *listener, void *data) { + struct roots_input *input = wl_container_of(listener, input, cursor_motion); + struct wlr_event_pointer_motion *event = data; + wlr_cursor_move(input->cursor, event->device, + event->delta_x, event->delta_y); + cursor_update_position(input, (uint32_t)event->time_usec); +} + +static void handle_cursor_motion_absolute(struct wl_listener *listener, + void *data) { + struct roots_input *input = wl_container_of(listener, + input, cursor_motion_absolute); + struct wlr_event_pointer_motion_absolute *event = data; + wlr_cursor_warp_absolute(input->cursor, event->device, + event->x_mm / event->width_mm, event->y_mm / event->height_mm); + cursor_update_position(input, (uint32_t)event->time_usec); +} + +static void handle_cursor_axis(struct wl_listener *listener, void *data) { + struct roots_input *input = + wl_container_of(listener, input, cursor_axis); + struct wlr_event_pointer_axis *event = data; + wlr_seat_pointer_send_axis(input->wl_seat, event->time_sec, + event->orientation, event->delta); +} + +static void handle_cursor_button(struct wl_listener *listener, void *data) { + /* TODO + struct sample_state *sample = + wl_container_of(listener, sample, 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); + + uint32_t serial = wlr_seat_pointer_send_button(sample->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); + } + break; + } + */ +} + +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; + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && + (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(input->cursor, event->device, + event->x_mm / event->width_mm, event->y_mm / event->height_mm); + cursor_update_position(input, (uint32_t)event->time_usec); + } +} + +static void handle_tool_tip(struct wl_listener *listener, void *data) { + /* TODO + struct roots_input *input = wl_container_of(listener, input, tool_tip); + struct wlr_event_tablet_tool_tip *event = data; + + struct wlr_xdg_surface_v6 *surface = + example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y); + example_set_focused_surface(sample, surface); + + wlr_seat_pointer_send_button(sample->wl_seat, (uint32_t)event->time_usec, + BTN_LEFT, event->state); + */ +} + +void cursor_initialize(struct roots_input *input) { + struct wlr_cursor *cursor = input->cursor; + + wl_list_init(&input->cursor_motion.link); + wl_signal_add(&cursor->events.motion, &input->cursor_motion); + input->cursor_motion.notify = handle_cursor_motion; + + wl_list_init(&input->cursor_motion_absolute.link); + wl_signal_add(&cursor->events.motion_absolute, + &input->cursor_motion_absolute); + input->cursor_motion_absolute.notify = handle_cursor_motion_absolute; + + wl_list_init(&input->cursor_button.link); + wl_signal_add(&cursor->events.button, &input->cursor_button); + input->cursor_button.notify = handle_cursor_button; + + wl_list_init(&input->cursor_axis.link); + wl_signal_add(&cursor->events.axis, &input->cursor_axis); + input->cursor_axis.notify = handle_cursor_axis; + + wl_list_init(&input->cursor_tool_axis.link); + wl_signal_add(&cursor->events.tablet_tool_axis, &input->cursor_tool_axis); + input->cursor_tool_axis.notify = handle_tool_axis; + + wl_list_init(&input->cursor_tool_tip.link); + wl_signal_add(&cursor->events.tablet_tool_tip, &input->cursor_tool_tip); + input->cursor_tool_tip.notify = handle_tool_tip; +} + +static void reset_device_mappings(struct roots_config *config, + struct wlr_cursor *cursor, struct wlr_input_device *device) { + wlr_cursor_map_input_to_output(cursor, device, NULL); + struct device_config *dconfig; + if ((dconfig = config_get_device(config, device))) { + wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box); + } +} + +static void set_device_output_mappings(struct roots_config *config, + struct wlr_cursor *cursor, struct wlr_output *output, + struct wlr_input_device *device) { + struct device_config *dconfig; + dconfig = config_get_device(config, device); + if (dconfig && dconfig->mapped_output && + strcmp(dconfig->mapped_output, output->name) == 0) { + wlr_cursor_map_input_to_output(cursor, device, output); + } +} + +void cursor_load_config(struct roots_config *config, + struct wlr_cursor *cursor, + struct roots_input *input, + struct roots_desktop *desktop) { + struct roots_pointer *pointer; + struct roots_touch *touch; + struct roots_tablet_tool *tablet_tool; + struct roots_output *output; + + // reset mappings + wlr_cursor_map_to_output(cursor, NULL); + wl_list_for_each(pointer, &input->pointers, link) { + reset_device_mappings(config, cursor, pointer->device); + } + wl_list_for_each(touch, &input->touch, link) { + reset_device_mappings(config, cursor, touch->device); + } + wl_list_for_each(tablet_tool, &input->tablet_tools, link) { + reset_device_mappings(config, cursor, tablet_tool->device); + } + + // configure device to output mappings + const char *mapped_output = config->cursor.mapped_output; + wl_list_for_each(output, &desktop->outputs, link) { + if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) { + wlr_cursor_map_to_output(cursor, output->wlr_output); + } + + wl_list_for_each(pointer, &input->pointers, link) { + set_device_output_mappings(config, cursor, output->wlr_output, + pointer->device); + } + wl_list_for_each(tablet_tool, &input->tablet_tools, link) { + set_device_output_mappings(config, cursor, output->wlr_output, + tablet_tool->device); + } + wl_list_for_each(touch, &input->touch, link) { + set_device_output_mappings(config, cursor, output->wlr_output, + touch->device); + } + } } diff --git a/rootston/desktop.c b/rootston/desktop.c index fc341a23..fbaf9cac 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -42,6 +42,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, wlr_cursor_attach_output_layout(server->input->cursor, desktop->layout); wlr_cursor_map_to_region(server->input->cursor, config->cursor.mapped_box); + cursor_load_config(config, server->input->cursor, + server->input, desktop); desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display); wl_signal_add(&desktop->xdg_shell_v6->events.new_surface, diff --git a/rootston/input.c b/rootston/input.c index d551715b..9ad20b58 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -75,12 +75,12 @@ struct roots_input *input_create(struct roots_server *server, assert(input); input->config = config; - input->cursor = wlr_cursor_create(); + input->server = server; struct wlr_xcursor_theme *theme; assert(theme = wlr_xcursor_theme_load("default", 16)); assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr")); - wlr_cursor_set_xcursor(input->cursor, input->xcursor); + assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0")); wl_list_init(&input->keyboards); @@ -98,6 +98,10 @@ struct roots_input *input_create(struct roots_server *server, wl_signal_add(&server->backend->events.input_remove, &input->input_remove); + input->cursor = wlr_cursor_create(); + cursor_initialize(input); + wlr_cursor_set_xcursor(input->cursor, input->xcursor); + return input; } diff --git a/rootston/meson.build b/rootston/meson.build index 03ca837a..787d0cf1 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -1,6 +1,7 @@ executable( 'rootson', [ 'config.c', + 'cursor.c', 'desktop.c', 'ini.c', 'input.c', diff --git a/rootston/output.c b/rootston/output.c index 481832cf..0f015fb6 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -73,6 +73,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { void output_add_notify(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; struct roots_desktop *desktop = wl_container_of(listener, desktop, output_add); + struct roots_input *input = desktop->server->input; struct roots_config *config = desktop->config; wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name); @@ -101,10 +102,9 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_output_layout_add_auto(desktop->layout, wlr_output); } - /* TODO: cursor - example_config_configure_cursor(sample->config, sample->cursor, - sample->compositor); + cursor_load_config(config, input->cursor, input, desktop); + struct wlr_xcursor_image *image = input->xcursor->images[0]; // TODO the cursor must be set depending on which surface it is displayed // over which should happen in the compositor. if (!wlr_output_set_cursor(wlr_output, image->buffer, @@ -113,8 +113,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { return; } - wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y); - */ + wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y); } void output_remove_notify(struct wl_listener *listener, void *data) { diff --git a/rootston/pointer.c b/rootston/pointer.c index 84c23d39..1693893e 100644 --- a/rootston/pointer.c +++ b/rootston/pointer.c @@ -2,39 +2,14 @@ #include #include #include -#include #include "rootston/input.h" -static void pointer_motion_notify(struct wl_listener *listener, void *data) { - //struct wlr_event_pointer_motion *event = data; - struct roots_pointer *pointer = wl_container_of(listener, pointer, motion); -} - -static void pointer_motion_absolute_notify(struct wl_listener *listener, void *data) { - //struct wlr_event_pointer_motion *event = data; - struct roots_pointer *pointer = wl_container_of(listener, pointer, motion_absolute); -} - void pointer_add(struct wlr_input_device *device, struct roots_input *input) { struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); pointer->device = device; pointer->input = input; - wl_list_init(&pointer->motion.link); - wl_list_init(&pointer->motion_absolute.link); - wl_list_init(&pointer->button.link); - wl_list_init(&pointer->axis.link); - pointer->motion.notify = pointer_motion_notify; - pointer->motion_absolute.notify = pointer_motion_absolute_notify; - //pointer->button.notify = pointer_button_notify; - //pointer->axis.notify = pointer_axis_notify; - wl_signal_add(&device->pointer->events.motion, &pointer->motion); - wl_signal_add(&device->pointer->events.motion_absolute, &pointer->motion_absolute); - wl_signal_add(&device->pointer->events.button, &pointer->button); - wl_signal_add(&device->pointer->events.axis, &pointer->axis); wl_list_insert(&input->pointers, &pointer->link); - wlr_cursor_attach_input_device(input->cursor, device); - // TODO: rootston/cursor.c - //example_config_configure_cursor(sample->config, sample->cursor, - // sample->compositor); + cursor_load_config(input->server->config, input->cursor, + input, input->server->desktop); } -- 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/desktop.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 ed9a43c2134f19ddaa4d8e7c9f680d8a3d8329a6 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 26 Sep 2017 23:59:25 +0200 Subject: Add first try to add wl_shell to rootston --- include/rootston/desktop.h | 2 ++ include/wlr/types/wlr_wl_shell.h | 17 ++++++++++++- rootston/desktop.c | 6 ++++- rootston/meson.build | 3 ++- rootston/wl_shell.c | 20 ++++++++++++++++ types/wlr_wl_shell.c | 52 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 rootston/wl_shell.c (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 62050972..ef361d87 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -39,6 +39,7 @@ struct roots_desktop { struct wl_listener output_add; struct wl_listener output_remove; struct wl_listener xdg_shell_v6_surface; + struct wl_listener wl_shell_surface; }; struct roots_server; @@ -55,5 +56,6 @@ void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); +void handle_wl_shell_surface(struct wl_listener *listener, void *data); #endif diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 1443bbf0..614d785b 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -7,20 +7,35 @@ struct wlr_wl_shell { struct wl_global *wl_global; struct wl_list wl_resources; struct wl_list surfaces; + uint32_t ping_timeout; + + struct { + struct wl_signal new_surface; + } events; void *data; }; struct wlr_wl_shell_surface { + struct wlr_wl_shell *shell; + struct wl_client *client; struct wl_resource *surface; struct wlr_texture *wlr_texture; struct wl_list link; + uint32_t ping_serial; + struct wl_event_source *ping_timer; + + struct { + struct wl_signal ping_timeout; + } events; + void *data; }; - struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display); void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell); +void wlr_wl_shell_surface_ping(struct wlr_wl_shell_surface *surface); + #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index f0495fa1..f9af3b8e 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -67,7 +67,6 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->layout = wlr_output_layout_create(); desktop->compositor = wlr_compositor_create( server->wl_display, server->renderer); - desktop->wl_shell = wlr_wl_shell_create(server->wl_display); wlr_cursor_attach_output_layout(server->input->cursor, desktop->layout); wlr_cursor_map_to_region(server->input->cursor, config->cursor.mapped_box); @@ -79,6 +78,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->xdg_shell_v6_surface); desktop->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; + desktop->wl_shell = wlr_wl_shell_create(server->wl_display); + wl_signal_add(&desktop->wl_shell->events.new_surface, + &desktop->wl_shell_surface); + desktop->wl_shell_surface.notify = handle_wl_shell_surface; + desktop->gamma_control_manager = wlr_gamma_control_manager_create( server->wl_display); diff --git a/rootston/meson.build b/rootston/meson.build index 30ae1548..de2d04de 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -9,6 +9,7 @@ executable( 'main.c', 'output.c', 'pointer.c', - 'xdg_shell_v6.c' + 'xdg_shell_v6.c', + 'wl_shell.c' ], dependencies: wlroots ) diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c new file mode 100644 index 00000000..0dcc0565 --- /dev/null +++ b/rootston/wl_shell.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "rootston/desktop.h" +#include "rootston/server.h" +#include "rootston/input.h" + +void handle_wl_shell_surface(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = + wl_container_of(listener, desktop, wl_shell_surface); + + struct wlr_wl_shell_surface *surface = data; + wlr_log(L_DEBUG, "new wl_shell surface"); + wlr_wl_shell_surface_ping(surface); +} diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index 84b40fc3..745299bf 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -3,10 +3,19 @@ #include #include #include +#include static void shell_surface_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { wlr_log(L_DEBUG, "TODO: implement shell surface pong"); + struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); + + if (surface->ping_serial != serial) { + return; + } + + wl_event_source_timer_update(surface->ping_timer, 0); + surface->ping_serial = 0; } static void shell_surface_move(struct wl_client *client, struct wl_resource @@ -77,6 +86,14 @@ static void destroy_shell_surface(struct wl_resource *resource) { free(state); } +static int wlr_wl_shell_surface_ping_timeout(void *user_data) { + struct wlr_wl_shell_surface *surface = user_data; + wl_signal_emit(&surface->events.ping_timeout, surface); + + surface->ping_serial = 0; + return 1; +} + static void wl_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface) { @@ -84,14 +101,33 @@ static void wl_shell_get_shell_surface(struct wl_client *client, struct wlr_wl_shell *wlr_wl_shell = wl_resource_get_user_data(resource); struct wlr_wl_shell_surface *state = calloc(1, sizeof(struct wlr_wl_shell_surface)); + if (state == NULL) { + wl_client_post_no_memory(client); + return; + } + + state->shell = wlr_wl_shell; + state->client = client; state->wlr_texture = wlr_texture; state->surface = surface; + struct wl_resource *shell_surface_resource = wl_resource_create(client, &wl_shell_surface_interface, wl_resource_get_version(resource), id); wlr_log(L_DEBUG, "New wl_shell %p (res %p)", state, shell_surface_resource); wl_resource_set_implementation(shell_surface_resource, &shell_surface_interface, state, destroy_shell_surface); wl_list_insert(&wlr_wl_shell->surfaces, &state->link); + wl_signal_emit(&wlr_wl_shell->events.new_surface, state); + + wl_signal_init(&state->events.ping_timeout); + + struct wl_display *display = wl_client_get_display(client); + struct wl_event_loop *loop = wl_display_get_event_loop(display); + state->ping_timer = wl_event_loop_add_timer(loop, + wlr_wl_shell_surface_ping_timeout, state); + if (state->ping_timer == NULL) { + wl_client_post_no_memory(client); + } } static struct wl_shell_interface wl_shell_impl = { @@ -124,6 +160,7 @@ struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { if (!wlr_wl_shell) { return NULL; } + wlr_wl_shell->ping_timeout = 10000; struct wl_global *wl_global = wl_global_create(display, &wl_shell_interface, 1, wlr_wl_shell, wl_shell_bind); if (!wl_global) { @@ -133,6 +170,7 @@ struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { wlr_wl_shell->wl_global = wl_global; wl_list_init(&wlr_wl_shell->wl_resources); wl_list_init(&wlr_wl_shell->surfaces); + wl_signal_init(&wlr_wl_shell->events.new_surface); return wlr_wl_shell; } @@ -150,3 +188,17 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) { // wl_global_destroy(wlr_wl_shell->wl_global); free(wlr_wl_shell); } + +void wlr_wl_shell_surface_ping(struct wlr_wl_shell_surface *surface) { + if (surface->ping_serial != 0) { + // already pinged + return; + } + + surface->ping_serial = + wl_display_next_serial(wl_client_get_display(surface->client)); + wl_event_source_timer_update(surface->ping_timer, + surface->shell->ping_timeout); + wl_shell_surface_send_ping(surface->surface, + surface->ping_serial); +} -- cgit v1.2.3 From 906a816abf812445ec9e514e6115872632fb3ee1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 28 Sep 2017 08:54:57 -0400 Subject: Fix rootston keyboard, add Xwayland --- examples/compositor.c | 2 +- include/rootston/desktop.h | 3 +++ include/rootston/input.h | 5 ----- include/rootston/server.h | 1 - include/rootston/view.h | 8 ++++++++ include/wlr/xwayland.h | 14 +++++++++++++- rootston/cursor.c | 1 + rootston/desktop.c | 6 ++++++ rootston/keyboard.c | 40 +++++++--------------------------------- rootston/meson.build | 1 + rootston/xwayland.c | 43 +++++++++++++++++++++++++++++++++++++++++++ types/wlr_keyboard.c | 1 + types/wlr_seat.c | 1 + xwayland/xwayland.c | 1 + xwayland/xwm.c | 6 +++++- 15 files changed, 91 insertions(+), 42 deletions(-) create mode 100644 rootston/xwayland.c (limited to 'rootston/desktop.c') diff --git a/examples/compositor.c b/examples/compositor.c index ae21697a..7d6efdb6 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -323,7 +323,7 @@ static void handle_output_frame(struct output_state *output, struct wlr_x11_window *x11_window; wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) { output_frame_handle_surface(sample, wlr_output, ts, - x11_window->surface, 200, 200); + x11_window->surface->resource, 200, 200); } wlr_renderer_end(sample->renderer); diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index ef361d87..5e138c11 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -34,11 +34,13 @@ struct roots_desktop { struct wlr_compositor *compositor; struct wlr_wl_shell *wl_shell; struct wlr_xdg_shell_v6 *xdg_shell_v6; + struct wlr_xwayland *xwayland; struct wlr_gamma_control_manager *gamma_control_manager; struct wl_listener output_add; struct wl_listener output_remove; struct wl_listener xdg_shell_v6_surface; + struct wl_listener xwayland_surface; struct wl_listener wl_shell_surface; }; @@ -57,5 +59,6 @@ void output_remove_notify(struct wl_listener *listener, void *data); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); +void handle_xwayland_surface(struct wl_listener *listener, void *data); #endif diff --git a/include/rootston/input.h b/include/rootston/input.h index ec1cd32d..b3ce84d7 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -15,11 +15,6 @@ struct roots_keyboard { struct wlr_input_device *device; struct wl_listener key; struct wl_list link; - struct xkb_keymap *keymap; - struct xkb_state *xkb_state; - xkb_led_index_t leds[WLR_LED_LAST]; - int keymap_fd; - size_t keymap_size; }; struct roots_pointer { diff --git a/include/rootston/server.h b/include/rootston/server.h index d9fa8f9e..15e3a4ee 100644 --- a/include/rootston/server.h +++ b/include/rootston/server.h @@ -23,7 +23,6 @@ struct roots_server { /* WLR tools */ struct wlr_backend *backend; struct wlr_renderer *renderer; - struct wlr_xwayland *xwayland; /* Global resources */ struct wlr_data_device_manager *data_device_manager; diff --git a/include/rootston/view.h b/include/rootston/view.h index 1010566a..8d4d69c5 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -27,6 +27,12 @@ struct roots_xdg_surface_v6 { struct wl_listener request_show_window_menu; }; +struct roots_x11_surface { + struct roots_view *view; + // TODO: Maybe destroy listener should go in roots_view + struct wl_listener destroy; +}; + enum roots_view_type { ROOTS_WL_SHELL_VIEW, ROOTS_XDG_SHELL_V6_VIEW, @@ -42,10 +48,12 @@ struct roots_view { union { struct wlr_wl_shell_surface *wl_shell_surface; struct wlr_xdg_surface_v6 *xdg_surface_v6; + struct wlr_x11_window *x11_window; }; union { struct roots_wl_shell_surface *roots_wl_shell_surface; struct roots_xdg_surface_v6 *roots_xdg_surface_v6; + struct roots_x11_surface *roots_x11_surface; }; struct wlr_surface *wlr_surface; struct wl_list link; diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 41b8042f..e3eadc2d 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -21,6 +21,12 @@ struct wlr_xwayland { struct wl_listener destroy_listener; struct wlr_xwm *xwm; struct wl_list displayable_windows; + + struct { + struct wl_signal new_surface; + } events; + + void *data; }; struct wlr_x11_window { @@ -28,11 +34,17 @@ struct wlr_x11_window { uint32_t surface_id; struct wl_list link; - struct wl_resource *surface; + struct wlr_surface *surface; struct wl_listener surface_destroy_listener; int16_t x, y; uint16_t width, height; bool override_redirect; + + struct { + struct wl_signal destroy; + } events; + + void *data; }; void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); diff --git a/rootston/cursor.c b/rootston/cursor.c index 0e9bf748..226fe412 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -100,6 +100,7 @@ static void do_cursor_button_press(struct roots_input *input, input->input_events_idx = (i + 1) % (sizeof(input->input_events) / sizeof(input->input_events[0])); set_view_focus(input, desktop, view); + wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface); break; } } diff --git a/rootston/desktop.c b/rootston/desktop.c index f9af3b8e..0224dd19 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -83,6 +83,12 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->wl_shell_surface); desktop->wl_shell_surface.notify = handle_wl_shell_surface; + desktop->xwayland = wlr_xwayland_create(server->wl_display, + desktop->compositor); + wl_signal_add(&desktop->xwayland->events.new_surface, + &desktop->xwayland_surface); + desktop->xwayland_surface.notify = handle_xwayland_surface; + desktop->gamma_control_manager = wlr_gamma_control_manager_create( server->wl_display); diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 54ae3f8f..57e0d14e 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -10,38 +10,19 @@ #include #include "rootston/input.h" -static void keyboard_led_update(struct roots_keyboard *keyboard) { - uint32_t leds = 0; - for (uint32_t i = 0; i < WLR_LED_LAST; ++i) { - if (xkb_state_led_index_is_active( - keyboard->xkb_state, keyboard->leds[i])) { - leds |= (1 << i); - } - } - wlr_keyboard_led_update(keyboard->device->keyboard, leds); -} - static void keyboard_key_notify(struct wl_listener *listener, void *data) { struct wlr_event_keyboard_key *event = data; struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, key); struct roots_input *input = keyboard->input; struct roots_server *server = input->server; - uint32_t keycode = event->keycode + 8; + enum wlr_key_state key_state = event->state; + uint32_t keycode = event->keycode + 8; const xkb_keysym_t *syms; - int nsyms = xkb_state_key_get_syms(keyboard->xkb_state, keycode, &syms); - xkb_state_update_key(keyboard->xkb_state, keycode, - event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); - keyboard_led_update(keyboard); + int nsyms = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state, + keycode, &syms); for (int i = 0; i < nsyms; ++i) { xkb_keysym_t sym = syms[i]; - char name[64]; - int l = xkb_keysym_get_name(sym, name, sizeof(name)); - if (l != -1 && l != sizeof(name)) { - wlr_log(L_DEBUG, "Key event: %s %s", name, - key_state == WLR_KEY_PRESSED ? "pressed" : "released"); - } - // TODO: pass key to clients if (sym == XKB_KEY_Escape) { // TEMPORARY, probably wl_display_terminate(server->wl_display); @@ -77,16 +58,9 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { rules.options = getenv("XKB_DEFAULT_OPTIONS"); struct xkb_context *context; assert(context = xkb_context_new(XKB_CONTEXT_NO_FLAGS)); - assert(keyboard->keymap = xkb_map_new_from_names(context, &rules, + wlr_keyboard_set_keymap(device->keyboard, + xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); xkb_context_unref(context); - assert(keyboard->xkb_state = xkb_state_new(keyboard->keymap)); - const char *led_names[3] = { - XKB_LED_NAME_NUM, - XKB_LED_NAME_CAPS, - XKB_LED_NAME_SCROLL - }; - for (uint32_t i = 0; i < 3; ++i) { - keyboard->leds[i] = xkb_map_led_get_index(keyboard->keymap, led_names[i]); - } + wlr_seat_attach_keyboard(input->wl_seat, device); } diff --git a/rootston/meson.build b/rootston/meson.build index 6e9e0041..59f73e96 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -10,6 +10,7 @@ executable( 'output.c', 'pointer.c', 'xdg_shell_v6.c', + 'xwayland.c', 'wl_shell.c', ], dependencies: wlroots ) diff --git a/rootston/xwayland.c b/rootston/xwayland.c new file mode 100644 index 00000000..e68af907 --- /dev/null +++ b/rootston/xwayland.c @@ -0,0 +1,43 @@ +#include +#include +#include +#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_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, destroy); + wl_list_remove(&roots_surface->destroy.link); + view_destroy(roots_surface->view); + free(roots_surface); +} + +void handle_xwayland_surface(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = + wl_container_of(listener, desktop, xwayland_surface); + + struct wlr_x11_window *surface = data; + // TODO: get and log title, class, etc + wlr_log(L_DEBUG, "new xwayland surface"); + + struct roots_x11_surface *roots_surface = + calloc(1, sizeof(struct roots_wl_shell_surface)); + wl_list_init(&roots_surface->destroy.link); + roots_surface->destroy.notify = handle_destroy; + wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + + struct roots_view *view = calloc(1, sizeof(struct roots_view)); + view->type = ROOTS_XWAYLAND_VIEW; + view->x = view->y = 200; + view->x11_window = surface; + view->roots_x11_surface = roots_surface; + view->wlr_surface = surface->surface; + view->desktop = desktop; + roots_surface->view = view; + wl_list_insert(&desktop->views, &view->link); +} diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 057f4ce3..dd90b38f 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -54,6 +54,7 @@ void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap) { + wlr_log(L_DEBUG, "Keymap set"); kb->keymap = keymap; assert(kb->xkb_state = xkb_state_new(kb->keymap)); const char *led_names[3] = { diff --git a/types/wlr_seat.c b/types/wlr_seat.c index aaff6005..e473064a 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -377,6 +377,7 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, } static void keyboard_key_notify(struct wl_listener *listener, void *data) { + wlr_log(L_DEBUG, "Updating keyboard"); struct wlr_seat_keyboard *seat_kb = wl_container_of( listener, seat_kb, key); struct wlr_seat *seat = seat_kb->seat; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index bed2e00e..6a521393 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -194,6 +194,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1; wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1; wl_list_init(&wlr_xwayland->displayable_windows); + wl_signal_init(&wlr_xwayland->events.new_surface); wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); if (wlr_xwayland->display < 0) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index be8fe123..88be0d99 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -16,6 +16,7 @@ static struct wlr_x11_window *lookup_window(struct wl_list *list, xcb_window_t w } return NULL; } + static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) { struct wlr_x11_window *window; if ((window = lookup_window(&xwm->xwayland->displayable_windows, window_id)) || @@ -43,10 +44,12 @@ static struct wlr_x11_window *wlr_x11_window_create(struct wlr_xwm *xwm, window->height = height; window->override_redirect = override_redirect; wl_list_insert(&xwm->new_windows, &window->link); + wl_signal_init(&window->events.destroy); return window; } static void wlr_x11_window_destroy(struct wlr_x11_window *window) { + wl_signal_emit(&window->events.destroy, window); wl_list_remove(&window->link); free(window); } @@ -69,10 +72,11 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line, static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window, struct wlr_surface *surface) { // get xcb geometry for depth = alpha channel - window->surface = surface->resource; + window->surface = surface; wl_list_remove(&window->link); wl_list_insert(&xwm->xwayland->displayable_windows, &window->link); + wl_signal_emit(&xwm->xwayland->events.new_surface, window); } /* xcb event handlers */ -- cgit v1.2.3 From 220a6e9bf637471f3f5e392d3c3fb76ae9b7e138 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 28 Sep 2017 09:11:16 -0400 Subject: Add xwayland activate and fix EGL bug --- include/wlr/xwayland.h | 2 ++ render/gles2/texture.c | 4 ++-- rootston/cursor.c | 4 +++- rootston/desktop.c | 2 ++ rootston/xwayland.c | 5 +++++ types/wlr_surface.c | 1 + xwayland/xwm.c | 19 +++++++++++++++++++ xwayland/xwm.h | 3 ++- 8 files changed, 36 insertions(+), 4 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index e3eadc2d..3c893c72 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -50,5 +50,7 @@ struct wlr_x11_window { void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_compositor *compositor); +void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland, + struct wlr_x11_window *window); #endif diff --git a/render/gles2/texture.c b/render/gles2/texture.c index f6a9d7eb..98d1a112 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -227,13 +227,13 @@ static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct return; } if (!wlr_egl_query_buffer(tex->egl, resource, EGL_WIDTH, - (EGLint*)&width)) { + (EGLint*)width)) { wlr_log(L_ERROR, "could not get size of the buffer " "(no buffer found)"); return; }; wlr_egl_query_buffer(tex->egl, resource, EGL_HEIGHT, - (EGLint*)&height); + (EGLint*)height); return; } diff --git a/rootston/cursor.c b/rootston/cursor.c index 226fe412..89f5874e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -100,7 +100,9 @@ static void do_cursor_button_press(struct roots_input *input, input->input_events_idx = (i + 1) % (sizeof(input->input_events) / sizeof(input->input_events[0])); set_view_focus(input, desktop, view); - wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface); + if (view) { + wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface); + } break; } } diff --git a/rootston/desktop.c b/rootston/desktop.c index 0224dd19..697c83df 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -23,6 +23,8 @@ void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) { return; } box->x = box->y = 0; + box->width = view->wlr_surface->current.width; + box->height = view->wlr_surface->current.height; } void view_activate(struct roots_view *view, bool activate) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index e68af907..f9ad2a22 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -17,6 +17,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { free(roots_surface); } +static void x11_activate(struct roots_view *view, bool active) { + wlr_x11_window_activate(view->desktop->xwayland, view->x11_window); +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, xwayland_surface); @@ -38,6 +42,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->roots_x11_surface = roots_surface; view->wlr_surface = surface->surface; view->desktop = desktop; + view->activate = x11_activate; roots_surface->view = view; wl_list_insert(&desktop->views, &view->link); } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index a9a54abe..09002d2d 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -117,6 +117,7 @@ static void wlr_surface_update_size(struct wlr_surface *surface) { surface->current.width = _width; surface->current.height = _height; + wlr_log(L_DEBUG, "%dx%d", _width, _height); } static void wlr_surface_to_buffer_region(struct wlr_surface *surface, diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 88be0d99..bda9f882 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -308,6 +308,25 @@ static void xcb_init_wm(struct wlr_xwm *xwm) { xcb_flush(xwm->xcb_conn); } +void wlr_x11_window_activate(struct wlr_xwayland *wlr_xwayland, + struct wlr_x11_window *window) { + struct wlr_xwm *xwm = wlr_xwayland->xwm; + xcb_client_message_event_t m = {0}; + m.response_type = XCB_CLIENT_MESSAGE; + m.format = 32; + m.window = window->window_id; + m.type = xwm->atoms[WM_PROTOCOLS]; + m.data.data32[0] = xwm->atoms[WM_TAKE_FOCUS]; + m.data.data32[1] = XCB_TIME_CURRENT_TIME; + xcb_send_event_checked(xwm->xcb_conn, 0, window->window_id, + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char*)&m); + xcb_set_input_focus_checked(xwm->xcb_conn, XCB_INPUT_FOCUS_POINTER_ROOT, + window->window_id, XCB_CURRENT_TIME); + xcb_configure_window_checked(xwm->xcb_conn, window->window_id, + XCB_CONFIG_WINDOW_STACK_MODE, (uint32_t[]){XCB_STACK_MODE_ABOVE}); + xcb_flush(xwm->xcb_conn); +} + void xwm_destroy(struct wlr_xwm *xwm) { if (!xwm) { return; diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 235145b9..679ff128 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -52,7 +52,8 @@ enum atom_name { NET_SUPPORTED, NET_WM_S0, NET_WM_STATE, - ATOM_LAST + ATOM_LAST, + WM_TAKE_FOCUS, }; static const char * const atom_map[ATOM_LAST] = { -- cgit v1.2.3