From 550748681db7f75888beab41a1a85eb86876604c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 22 Sep 2017 20:24:32 -0400 Subject: Establish rootston headers & main --- include/rootston/server.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 include/rootston/server.h (limited to 'include/rootston/server.h') diff --git a/include/rootston/server.h b/include/rootston/server.h new file mode 100644 index 00000000..f4d1de95 --- /dev/null +++ b/include/rootston/server.h @@ -0,0 +1,31 @@ +#ifndef _ROOTSTON_SERVER_H +#define _ROOTSTON_SERVER_H +#include +#include +#include +#include +#include +#include "rootston/config.h" +#include "rootston/desktop.h" +#include "rootston/input.h" + +struct rootston { + /* Rootston resources */ + struct roots_config *config; + struct roots_desktop *desktop; + struct roots_input *input; + + /* Wayland resources */ + struct wl_display *wl_display; + struct wl_event_loop *wl_event_loop; + + /* WLR tools */ + struct wlr_backend *backend; + struct wlr_session *session; + struct wlr_renderer *renderer; + struct wlr_xwayland *xwayland; +}; + +extern struct rootston root; + +#endif -- cgit v1.2.3 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 --- backend/wayland/backend.c | 42 ++++++++++--------- backend/wayland/output.c | 2 +- include/backend/wayland.h | 2 + include/rootston/desktop.h | 27 +++++++++--- include/rootston/server.h | 9 ++-- rootston/desktop.c | 59 ++++++++++++++++++++++++++ rootston/main.c | 41 +++++++++++++++--- rootston/meson.build | 6 ++- rootston/output.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 253 insertions(+), 36 deletions(-) create mode 100644 rootston/desktop.c create mode 100644 rootston/output.c (limited to 'include/rootston/server.h') diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index d917c7e9..3ac2ea7d 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -35,26 +35,7 @@ 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"); - backend->remote_display = wl_display_connect(NULL); - if (!backend->remote_display) { - wlr_log_errno(L_ERROR, "Could not connect to remote display"); - return false; - } - - if (!(backend->registry = wl_display_get_registry(backend->remote_display))) { - wlr_log_errno(L_ERROR, "Could not obtain reference to remote registry"); - 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); - + backend->started = true; for (size_t i = 0; i < backend->requested_outputs; ++i) { wlr_wl_output_create(&backend->backend); } @@ -146,6 +127,27 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { } backend->local_display = display; + + backend->remote_display = wl_display_connect(NULL); + if (!backend->remote_display) { + wlr_log_errno(L_ERROR, "Could not connect to remote display"); + return false; + } + + if (!(backend->registry = wl_display_get_registry(backend->remote_display))) { + wlr_log_errno(L_ERROR, "Could not obtain reference to remote registry"); + 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); + return &backend->backend; error: diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 3e673bcc..ba04aede 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -209,7 +209,7 @@ static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { assert(wlr_backend_is_wl(_backend)); struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; - if (!backend->remote_display) { + if (!backend->started) { ++backend->requested_outputs; return NULL; } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 5e278dc9..42739c18 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -1,6 +1,7 @@ #ifndef _WLR_INTERNAL_BACKEND_WAYLAND_H #define _WLR_INTERNAL_BACKEND_WAYLAND_H +#include #include #include #include @@ -14,6 +15,7 @@ struct wlr_wl_backend { struct wlr_backend backend; /* local state */ + bool started; struct wl_display *local_display; list_t *devices; list_t *outputs; diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 7881e599..3d31059c 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -7,13 +7,13 @@ #include #include #include -#include #include #include "rootston/view.h" +#include "rootston/config.h" struct roots_output { struct roots_desktop *desktop; - struct wlr_output *output; + struct wlr_output *wlr_output; struct wl_listener frame; struct wl_listener resolution; struct timespec last_frame; @@ -22,12 +22,29 @@ struct roots_output { struct roots_desktop { struct wl_list outputs; + struct timespec last_frame; + struct roots_server *server; + struct roots_config *config; + struct wlr_output_layout *layout; - struct wlr_compositor *wlr_compositor; + + struct wlr_compositor *compositor; struct wlr_wl_shell *wl_shell; - struct wlr_xdg_shell_v6 *xdg_shell; - struct wlr_data_device_manager *data_device_manager; + struct wlr_xdg_shell_v6 *xdg_shell_v6; 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 roots_server; + +struct roots_desktop *desktop_create(struct roots_server *server, + struct roots_config *config); +void desktop_destroy(struct roots_desktop *desktop); + +void output_add_notify(struct wl_listener *listener, void *data); +void output_remove_notify(struct wl_listener *listener, void *data); + #endif diff --git a/include/rootston/server.h b/include/rootston/server.h index f4d1de95..d9fa8f9e 100644 --- a/include/rootston/server.h +++ b/include/rootston/server.h @@ -3,13 +3,14 @@ #include #include #include +#include #include #include #include "rootston/config.h" #include "rootston/desktop.h" #include "rootston/input.h" -struct rootston { +struct roots_server { /* Rootston resources */ struct roots_config *config; struct roots_desktop *desktop; @@ -21,11 +22,13 @@ struct rootston { /* WLR tools */ struct wlr_backend *backend; - struct wlr_session *session; struct wlr_renderer *renderer; struct wlr_xwayland *xwayland; + + /* Global resources */ + struct wlr_data_device_manager *data_device_manager; }; -extern struct rootston root; +extern struct roots_server server; #endif 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 +} diff --git a/rootston/main.c b/rootston/main.c index 9be2ff41..b95840a9 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -1,14 +1,45 @@ +#define _POSIX_C_SOURCE 200112L +#include +#include #include +#include +#include +#include #include #include "rootston/config.h" #include "rootston/server.h" -struct rootston root = { 0 }; +struct roots_server server = { 0 }; int main(int argc, char **argv) { - root.config = parse_args(argc, argv); - root.wl_display = wl_display_create(); - root.wl_event_loop = wl_display_get_event_loop(root.wl_display); - wl_display_init_shm(root.wl_display); + assert(server.config = parse_args(argc, argv)); + assert(server.wl_display = wl_display_create()); + assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display)); + + assert(server.backend = wlr_backend_autocreate(server.wl_display)); + + assert(server.renderer = wlr_gles2_renderer_create(server.backend)); + wl_display_init_shm(server.wl_display); + server.desktop = desktop_create(&server, server.config); + server.data_device_manager = wlr_data_device_manager_create( + server.wl_display); + + const char *socket = wl_display_add_socket_auto(server.wl_display); + if (!socket) { + wlr_log_errno(L_ERROR, "Unable to open wayland socket"); + wlr_backend_destroy(server.backend); + return 1; + } + + wlr_log(L_INFO, "Running compositor on wayland display '%s'", socket); + setenv("_WAYLAND_DISPLAY", socket, true); + + if (!wlr_backend_start(server.backend)) { + wlr_log(L_ERROR, "Failed to start backend"); + wlr_backend_destroy(server.backend); + return 1; + } + + wl_display_run(server.wl_display); return 0; } diff --git a/rootston/meson.build b/rootston/meson.build index 501fe17e..9342d19c 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -1,7 +1,9 @@ executable( - 'rooston', [ - 'main.c', + 'rootson', [ 'config.c', + 'desktop.c', 'ini.c', + 'main.c', + 'output.c', ], dependencies: wlroots ) diff --git a/rootston/output.c b/rootston/output.c new file mode 100644 index 00000000..39586e0e --- /dev/null +++ b/rootston/output.c @@ -0,0 +1,101 @@ +#define _POSIX_C_SOURCE 199309L +#include +#include +#include +#include +#include +#include +#include +#include "rootston/server.h" +#include "rootston/desktop.h" +#include "rootston/config.h" + +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); + struct roots_desktop *desktop = output->desktop; + struct roots_server *server = desktop->server; + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + wlr_output_make_current(wlr_output); + wlr_renderer_begin(server->renderer, wlr_output); + + // TODO: render views + + wlr_renderer_end(server->renderer); + wlr_output_swap_buffers(wlr_output); + + output->last_frame = desktop->last_frame = now; +} + +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_config *config = desktop->config; + + wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name); + wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", + wlr_output->make, wlr_output->model, + wlr_output->phys_width, wlr_output->phys_height); + if (wlr_output->modes->length > 0) { + wlr_output_set_mode(wlr_output, wlr_output->modes->items[0]); + } + + struct roots_output *output = calloc(1, sizeof(struct roots_output)); + clock_gettime(CLOCK_MONOTONIC, &output->last_frame); + output->desktop = desktop; + output->wlr_output = wlr_output; + output->frame.notify = output_frame_notify; + wl_list_init(&output->frame.link); + wl_signal_add(&wlr_output->events.frame, &output->frame); + wl_list_insert(&desktop->outputs, &output->link); + + struct output_config *output_config = config_get_output(config, wlr_output); + if (output_config) { + wlr_output_transform(wlr_output, output_config->transform); + wlr_output_layout_add(desktop->layout, + wlr_output, output_config->x, output_config->y); + } else { + wlr_output_layout_add_auto(desktop->layout, wlr_output); + } + + /* TODO: cursor + example_config_configure_cursor(sample->config, sample->cursor, + sample->compositor); + + // 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, + image->width, image->width, image->height)) { + wlr_log(L_DEBUG, "Failed to set hardware cursor"); + return; + } + + wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y); + */ +} + +void output_remove_notify(struct wl_listener *listener, void *data) { + struct wlr_output *wlr_output = data; + struct roots_desktop *desktop = wl_container_of(listener, desktop, output_remove); + struct roots_output *output = NULL, *_output; + wl_list_for_each(_output, &desktop->outputs, link) { + if (_output->wlr_output == wlr_output) { + output = _output; + break; + } + } + if (!output) { + return; // We are unfamiliar with this output + } + wlr_output_layout_remove(desktop->layout, output->wlr_output); + // TODO: cursor + //example_config_configure_cursor(sample->config, sample->cursor, + // sample->compositor); + wl_list_remove(&output->link); + wl_list_remove(&output->frame.link); + wl_list_remove(&output->resolution.link); + free(output); +} -- 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 'include/rootston/server.h') 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