From 906a816abf812445ec9e514e6115872632fb3ee1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 28 Sep 2017 08:54:57 -0400 Subject: [PATCH] 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 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 */