From a3c0f9781073a29c020d8f5c992b8019264dc219 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 17:03:05 +0100 Subject: [PATCH 01/10] Make keyboard repeat info configurable --- include/rootston/config.h | 1 + include/wlr/types/wlr_keyboard.h | 8 ++++++++ include/wlr/types/wlr_seat.h | 1 + rootston/config.c | 4 ++++ rootston/keyboard.c | 13 +++++++++++-- types/wlr_keyboard.c | 15 +++++++++++++++ types/wlr_seat.c | 33 ++++++++++++++++++++++++++++---- 7 files changed, 69 insertions(+), 6 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index de20fb8e..233692dc 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -42,6 +42,7 @@ struct roots_keyboard_config { char *layout; char *variant; char *options; + int repeat_rate, repeat_delay; struct wl_list link; }; diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index e2d50b03..c259189d 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -51,10 +51,16 @@ struct wlr_keyboard { xkb_mod_mask_t group; } modifiers; + struct { + int32_t rate; + int32_t delay; + } repeat_info; + struct { struct wl_signal key; struct wl_signal modifiers; struct wl_signal keymap; + struct wl_signal repeat_info; } events; void *data; @@ -74,6 +80,8 @@ struct wlr_event_keyboard_key { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); +void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, + int32_t delay); void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6d59315b..6c04380e 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -146,6 +146,7 @@ struct wlr_seat_keyboard_state { struct wl_listener keyboard_destroy; struct wl_listener keyboard_keymap; + struct wl_listener keyboard_repeat_info; struct wl_listener surface_destroy; struct wl_listener resource_destroy; diff --git a/rootston/config.c b/rootston/config.c index 59adf13c..6e596852 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -213,6 +213,10 @@ static void config_handle_keyboard(struct roots_config *config, kc->variant = strdup(value); } else if (strcmp(name, "options") == 0) { kc->options = strdup(value); + } else if (strcmp(name, "repeat-rate") == 0) { + kc->repeat_rate = strtol(value, NULL, 10); + } else if (strcmp(name, "repeat-delay") == 0) { + kc->repeat_delay = strtol(value, NULL, 10); } else { wlr_log(L_ERROR, "got unknown keyboard config: %s", name); } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 85033613..4aaf2d48 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -306,6 +306,12 @@ static void keyboard_config_merge(struct roots_keyboard_config *config, if (config->name == NULL) { config->name = fallback->name; } + if (config->repeat_rate <= 0) { + config->repeat_rate = fallback->repeat_rate; + } + if (config->repeat_delay <= 0) { + config->repeat_delay = fallback->repeat_delay; + } } struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, @@ -337,8 +343,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, keyboard_config_merge(config, &env_config); keyboard->config = config; - struct xkb_rule_names rules; - memset(&rules, 0, sizeof(rules)); + struct xkb_rule_names rules = { 0 }; rules.rules = config->rules; rules.model = config->model; rules.layout = config->layout; @@ -353,6 +358,10 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); xkb_context_unref(context); + int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25; + int repeat_delay = (config->repeat_delay > 0) ? config->repeat_delay : 600; + wlr_keyboard_set_repeat_info(device->keyboard, repeat_rate, repeat_delay); + return keyboard; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index c4f2ed52..c494b45d 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -102,6 +102,11 @@ void wlr_keyboard_init(struct wlr_keyboard *kb, wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); + wl_signal_init(&kb->events.repeat_info); + + // Sane defaults + kb->repeat_info.rate = 25; + kb->repeat_info.delay = 600; } void wlr_keyboard_destroy(struct wlr_keyboard *kb) { @@ -167,6 +172,16 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, wl_signal_emit(&kb->events.keymap, kb); } +void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, + int32_t delay) { + if (kb->repeat_info.rate == rate && kb->repeat_info.delay == delay) { + return; + } + kb->repeat_info.rate = rate; + kb->repeat_info.delay = delay; + wl_signal_emit(&kb->events.repeat_info, kb); +} + uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; uint32_t modifiers = 0; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ff1cbf7f..ab3e990d 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -109,10 +109,18 @@ static void seat_client_send_keymap(struct wlr_seat_client *client, wl_keyboard_send_keymap(client->keyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd, keyboard->keymap_size); +} + +static void seat_client_send_repeat_info(struct wlr_seat_client *client, + struct wlr_keyboard *keyboard) { + if (!keyboard || !client->keyboard) { + return; + } if (wl_resource_get_version(client->keyboard) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { - wl_keyboard_send_repeat_info(client->keyboard, 25, 600); + wl_keyboard_send_repeat_info(client->keyboard, + keyboard->repeat_info.rate, keyboard->repeat_info.delay); } } @@ -138,8 +146,9 @@ static void wl_seat_get_keyboard(struct wl_client *client, wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl, seat_client, &wl_keyboard_destroy); - seat_client_send_keymap(seat_client, - seat_client->seat->keyboard_state.keyboard); + struct wlr_keyboard *keyboard = seat_client->seat->keyboard_state.keyboard; + seat_client_send_keymap(seat_client, keyboard); + seat_client_send_repeat_info(seat_client, keyboard); // TODO possibly handle the case where this keyboard needs an enter // right away @@ -695,6 +704,16 @@ static void handle_keyboard_keymap(struct wl_listener *listener, void *data) { } } +static void handle_keyboard_repeat_info(struct wl_listener *listener, + void *data) { + struct wlr_seat_keyboard_state *state = + wl_container_of(listener, state, keyboard_repeat_info); + struct wlr_seat_client *client; + wl_list_for_each(client, &state->seat->clients, link) { + seat_client_send_repeat_info(client, state->keyboard); + } +} + static void handle_keyboard_destroy(struct wl_listener *listener, void *data) { struct wlr_seat_keyboard_state *state = wl_container_of(listener, state, keyboard_destroy); @@ -713,22 +732,28 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, if (seat->keyboard_state.keyboard) { wl_list_remove(&seat->keyboard_state.keyboard_destroy.link); wl_list_remove(&seat->keyboard_state.keyboard_keymap.link); + wl_list_remove(&seat->keyboard_state.keyboard_repeat_info.link); seat->keyboard_state.keyboard = NULL; } if (device) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); + wl_signal_add(&device->events.destroy, &seat->keyboard_state.keyboard_destroy); seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy; - wl_signal_add(&device->keyboard->events.keymap, &seat->keyboard_state.keyboard_keymap); seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap; + wl_signal_add(&device->keyboard->events.repeat_info, + &seat->keyboard_state.keyboard_repeat_info); + seat->keyboard_state.keyboard_repeat_info.notify = + handle_keyboard_repeat_info; struct wlr_seat_client *client; wl_list_for_each(client, &seat->clients, link) { seat_client_send_keymap(client, device->keyboard); + seat_client_send_repeat_info(client, device->keyboard); } seat->keyboard_state.keyboard = device->keyboard; From 2c6e52c164cfd19bac642d3507fb8584a0201845 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 17:06:31 +0100 Subject: [PATCH 02/10] Add docs for wlr_keyboard_set_repeat_info --- include/wlr/types/wlr_keyboard.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index c259189d..450cd473 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -80,6 +80,10 @@ struct wlr_event_keyboard_key { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); +/** + * Sets the keyboard repeat info. `rate` is in key repeats/second and delay is + * in milliseconds. + */ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, int32_t delay); void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); From b275d44bc3226fdd38ee1f983769697751af5740 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 9 Dec 2017 12:10:09 -0500 Subject: [PATCH 03/10] rootston xcursor fixes --- rootston/output.c | 7 ------- rootston/seat.c | 14 ++++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/rootston/output.c b/rootston/output.c index aace1991..cf2ffdc3 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -324,12 +323,6 @@ void output_add_notify(struct wl_listener *listener, void *data) { struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { - if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager, - wlr_output->scale)) { - wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' " - "with scale %d", wlr_output->name, wlr_output->scale); - } - roots_seat_configure_cursor(seat); roots_seat_configure_xcursor(seat); } diff --git a/rootston/seat.c b/rootston/seat.c index 1fa09ad6..cb245ca8 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -444,12 +444,14 @@ void roots_seat_configure_xcursor(struct roots_seat *seat) { cursor_theme = cc->theme; } - seat->cursor->xcursor_manager = - wlr_xcursor_manager_create(cursor_theme, ROOTS_XCURSOR_SIZE); - if (seat->cursor->xcursor_manager == NULL) { - wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s", - cursor_theme); - return; + if (!seat->cursor->xcursor_manager) { + seat->cursor->xcursor_manager = + wlr_xcursor_manager_create(cursor_theme, ROOTS_XCURSOR_SIZE); + if (seat->cursor->xcursor_manager == NULL) { + wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s", + cursor_theme); + return; + } } struct roots_output *output; From 542d886984c8c94b4ab57e657d334c5d0e136d7c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 10 Dec 2017 08:06:43 +0100 Subject: [PATCH 04/10] wlr_seat: send keyboard modifiers to the right client on enter We were previously sending modifiers to the leaving client instead. Fixes #476. --- types/wlr_seat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ab3e990d..05ea4745 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -860,7 +860,6 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, surface->resource, &keys); wl_array_release(&keys); - wlr_seat_keyboard_send_modifiers(seat); wlr_seat_client_send_selection(client); } @@ -882,6 +881,12 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, seat->keyboard_state.focused_client = client; seat->keyboard_state.focused_surface = surface; + + if (client && client->keyboard && seat->keyboard_state.keyboard) { + // tell new client about any modifier change last, + // as it targets seat->keyboard_state.focused_client + wlr_seat_keyboard_send_modifiers(seat); + } } void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, struct From 925497fbeaed9a2eb8420490e6cdfa4fd162e79e Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 11 Dec 2017 10:36:22 +0100 Subject: [PATCH 05/10] Set default cursor image in rootston --- include/rootston/config.h | 1 + include/rootston/cursor.h | 2 ++ rootston/config.c | 4 ++++ rootston/cursor.c | 3 ++- rootston/desktop.c | 6 +++++- rootston/seat.c | 5 ++++- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index 233692dc..1d54314e 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -51,6 +51,7 @@ struct roots_cursor_config { char *mapped_output; struct wlr_box *mapped_box; char *theme; + char *default_image; struct wl_list link; }; diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 2d9a9215..de6b7b92 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -20,6 +20,8 @@ struct roots_cursor { struct roots_seat *seat; struct wlr_cursor *cursor; + const char *default_xcursor; + enum roots_cursor_mode mode; // state from input (review if this is necessary) diff --git a/rootston/config.c b/rootston/config.c index 6e596852..db77506f 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -176,6 +176,9 @@ static void config_handle_cursor(struct roots_config *config, } else if (strcmp(name, "theme") == 0) { free(cc->theme); cc->theme = strdup(value); + } else if (strcmp(name, "default-image") == 0) { + free(cc->default_image); + cc->default_image = strdup(value); } else { wlr_log(L_ERROR, "got unknown cursor config: %s", name); } @@ -454,6 +457,7 @@ void roots_config_destroy(struct roots_config *config) { free(cc->mapped_output); free(cc->mapped_box); free(cc->theme); + free(cc->default_image); free(cc); } diff --git a/rootston/cursor.c b/rootston/cursor.c index d38e40a1..95e8ce2a 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -22,6 +22,7 @@ struct roots_cursor *roots_cursor_create(struct roots_seat *seat) { free(cursor); return NULL; } + cursor->default_xcursor = ROOTS_XCURSOR_DEFAULT; return cursor; } @@ -48,7 +49,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } if (set_compositor_cursor) { wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, - ROOTS_XCURSOR_DEFAULT, cursor->cursor); + cursor->default_xcursor, cursor->cursor); cursor->cursor_client = NULL; } if (view) { diff --git a/rootston/desktop.c b/rootston/desktop.c index 244f7c94..ef459e69 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -408,10 +408,14 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->config = config; const char *cursor_theme = NULL; + const char *cursor_default = ROOTS_XCURSOR_DEFAULT; struct roots_cursor_config *cc = roots_config_get_cursor(config, ROOTS_CONFIG_DEFAULT_SEAT_NAME); if (cc != NULL) { cursor_theme = cc->theme; + if (cc->default_image != NULL) { + cursor_default = cc->default_image; + } } desktop->xcursor_manager = wlr_xcursor_manager_create(cursor_theme, @@ -449,7 +453,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, wlr_log(L_ERROR, "Cannot load XWayland XCursor theme"); } struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( - desktop->xcursor_manager, ROOTS_XCURSOR_DEFAULT, 1); + desktop->xcursor_manager, cursor_default, 1); if (xcursor != NULL) { struct wlr_xcursor_image *image = xcursor->images[0]; wlr_xwayland_set_cursor(desktop->xwayland, image->buffer, diff --git a/rootston/seat.c b/rootston/seat.c index cb245ca8..8a581157 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -442,6 +442,9 @@ void roots_seat_configure_xcursor(struct roots_seat *seat) { roots_config_get_cursor(seat->input->config, seat->seat->name); if (cc != NULL) { cursor_theme = cc->theme; + if (cc->default_image != NULL) { + seat->cursor->default_xcursor = cc->default_image; + } } if (!seat->cursor->xcursor_manager) { @@ -465,7 +468,7 @@ void roots_seat_configure_xcursor(struct roots_seat *seat) { } wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, - ROOTS_XCURSOR_DEFAULT, seat->cursor->cursor); + seat->cursor->default_xcursor, seat->cursor->cursor); wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); } From 529675b7b04a2598f7701d2e05567d8249ea1cfb Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 11 Dec 2017 12:14:23 +0100 Subject: [PATCH 06/10] Add wlr_output_set_custom_mode --- backend/wayland/output.c | 10 ++++++++++ backend/x11/backend.c | 16 ++++++++++++++-- include/wlr/interfaces/wlr_output.h | 2 ++ include/wlr/types/wlr_output.h | 2 ++ rootston/output.c | 9 ++++++++- types/wlr_output.c | 17 +++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index c4301617..f6182dcd 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -28,6 +28,15 @@ static struct wl_callback_listener frame_listener = { .done = surface_frame_callback }; +static bool wlr_wl_output_set_custom_mode(struct wlr_output *_output, + int32_t width, int32_t height, int32_t refresh) { + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; + wl_egl_window_resize(output->egl_window, width, height, 0, 0); + wlr_output_update_size(&output->wlr_output, width, height); + wl_signal_emit(&output->wlr_output.events.resolution, output); + return true; +} + static void wlr_wl_output_make_current(struct wlr_output *_output) { struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; if (!eglMakeCurrent(output->backend->egl.display, @@ -185,6 +194,7 @@ bool wlr_wl_output_move_cursor(struct wlr_output *_output, int x, int y) { } static struct wlr_output_impl output_impl = { + .set_custom_mode = wlr_wl_output_set_custom_mode, .transform = wlr_wl_output_transform, .destroy = wlr_wl_output_destroy, .make_current = wlr_wl_output_make_current, diff --git a/backend/x11/backend.c b/backend/x11/backend.c index b798daf6..5fb54ffd 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -267,8 +267,8 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); output->win = xcb_generate_id(x11->xcb_conn); - xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, x11->screen->root, - 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, + xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, + x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, x11->screen->root_visual, mask, values); output->surf = wlr_egl_create_surface(&x11->egl, &output->win); @@ -329,6 +329,17 @@ static struct wlr_backend_impl backend_impl = { .get_egl = wlr_x11_backend_get_egl, }; +static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, + int32_t height, int32_t refresh) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + const uint32_t values[] = { width, height }; + xcb_configure_window(x11->xcb_conn, output->win, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); + return true; +} + static void output_transform(struct wlr_output *wlr_output, enum wl_output_transform transform) { struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; output->wlr_output.transform = transform; @@ -362,6 +373,7 @@ static void output_swap_buffers(struct wlr_output *wlr_output) { } static struct wlr_output_impl output_impl = { + .set_custom_mode = output_set_custom_mode, .transform = output_transform, .destroy = output_destroy, .make_current = output_make_current, diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index b4f39d35..dc2a867b 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -9,6 +9,8 @@ struct wlr_output_impl { void (*enable)(struct wlr_output *output, bool enable); bool (*set_mode)(struct wlr_output *output, struct wlr_output_mode *mode); + bool (*set_custom_mode)(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh); void (*transform)(struct wlr_output *output, enum wl_output_transform transform); bool (*set_cursor)(struct wlr_output *output, const uint8_t *buf, diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 895536e1..7f681ab7 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -83,6 +83,8 @@ struct wlr_surface; void wlr_output_enable(struct wlr_output *output, bool enable); bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode); +bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh); void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); diff --git a/rootston/output.c b/rootston/output.c index cf2ffdc3..b2d6554d 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -263,8 +263,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { static void set_mode(struct wlr_output *output, struct roots_output_config *oc) { - struct wlr_output_mode *mode, *best = NULL; int mhz = (int)(oc->mode.refresh_rate * 1000); + + if (wl_list_empty(&output->modes)) { + // Output has no mode, try setting a custom one + wlr_output_set_custom_mode(output, oc->mode.width, oc->mode.height, mhz); + return; + } + + struct wlr_output_mode *mode, *best = NULL; wl_list_for_each(mode, &output->modes, link) { if (mode->width == oc->mode.width && mode->height == oc->mode.height) { if (mode->refresh == mhz) { diff --git a/types/wlr_output.c b/types/wlr_output.c index f4ae7aaa..adade238 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -164,6 +164,23 @@ bool wlr_output_set_mode(struct wlr_output *output, return result; } +bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, + int32_t height, int32_t refresh) { + if (!output->impl || !output->impl->set_custom_mode) { + return false; + } + bool result = output->impl->set_custom_mode(output, width, height, refresh); + if (result) { + wlr_output_update_matrix(output); + + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + wlr_output_send_current_mode_to_resource(resource); + } + } + return result; +} + void wlr_output_update_size(struct wlr_output *output, int32_t width, int32_t height) { if (output->width == width && output->height == height) { From 3b4b8953d96194e8b168149f46c731443239accd Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 12 Dec 2017 21:58:00 +0100 Subject: [PATCH 07/10] Update output layout when scale or transform changes --- backend/drm/drm.c | 6 +----- backend/wayland/output.c | 2 -- backend/x11/backend.c | 1 - examples/multi-pointer.c | 2 +- examples/output-layout.c | 2 +- examples/pointer.c | 2 +- examples/rotation.c | 2 +- include/wlr/types/wlr_output.h | 4 +++- rootston/output.c | 2 +- types/wlr_output.c | 10 +++++++++- types/wlr_output_layout.c | 20 ++++++++++++++++++++ 11 files changed, 38 insertions(+), 15 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 9fcf2ad7..ba203791 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -453,11 +453,7 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, conn->state = WLR_DRM_CONN_CONNECTED; conn->output.current_mode = mode; - if (conn->output.width != mode->width || conn->output.height != mode->height) { - conn->output.width = mode->width; - conn->output.height = mode->height; - wl_signal_emit(&conn->output.events.resolution, &conn->output); - } + wlr_output_update_size(&conn->output, mode->width, mode->height); // Since realloc_crtcs can deallocate planes on OTHER outputs, // we actually need to reinitalise any than has changed diff --git a/backend/wayland/output.c b/backend/wayland/output.c index f6182dcd..f940299e 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -33,7 +33,6 @@ static bool wlr_wl_output_set_custom_mode(struct wlr_output *_output, struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; wl_egl_window_resize(output->egl_window, width, height, 0, 0); wlr_output_update_size(&output->wlr_output, width, height); - wl_signal_emit(&output->wlr_output.events.resolution, output); return true; } @@ -228,7 +227,6 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x // loop over states for maximized etc? wl_egl_window_resize(output->egl_window, width, height, 0, 0); wlr_output_update_size(&output->wlr_output, width, height); - wl_signal_emit(&output->wlr_output.events.resolution, output); } static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) { diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 5fb54ffd..5a6e90b5 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -118,7 +118,6 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e xcb_configure_notify_event_t *ev = (xcb_configure_notify_event_t *)event; wlr_output_update_size(&output->wlr_output, ev->width, ev->height); - wl_signal_emit(&output->wlr_output.events.resolution, output); // Move the pointer to its new location xcb_query_pointer_cookie_t cookie = diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index f1bcebc7..3f8b2415 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -72,7 +72,7 @@ static void handle_output_add(struct output_state *ostate) { example_config_get_output(sample->config, ostate->output); if (o_config) { - wlr_output_transform(ostate->output, o_config->transform); + wlr_output_set_transform(ostate->output, o_config->transform); wlr_output_layout_add(sample->layout, ostate->output, o_config->x, o_config->y); } else { diff --git a/examples/output-layout.c b/examples/output-layout.c index 084bd7df..b9228692 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -136,7 +136,7 @@ static void handle_output_add(struct output_state *ostate) { example_config_get_output(sample->config, ostate->output); if (o_config) { - wlr_output_transform(ostate->output, o_config->transform); + wlr_output_set_transform(ostate->output, o_config->transform); wlr_output_layout_add(sample->layout, ostate->output, o_config->x, o_config->y); } else { diff --git a/examples/pointer.c b/examples/pointer.c index f75e1bce..280372e0 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -101,7 +101,7 @@ static void handle_output_add(struct output_state *ostate) { example_config_get_output(sample->config, ostate->output); if (o_config) { - wlr_output_transform(ostate->output, o_config->transform); + wlr_output_set_transform(ostate->output, o_config->transform); wlr_output_layout_add(sample->layout, ostate->output, o_config->x, o_config->y); } else { diff --git a/examples/rotation.c b/examples/rotation.c index 276b6255..f9307ed3 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -78,7 +78,7 @@ static void handle_output_add(struct output_state *output) { struct output_config *conf; wl_list_for_each(conf, &state->config->outputs, link) { if (strcmp(conf->name, output->output->name) == 0) { - wlr_output_transform(output->output, conf->transform); + wlr_output_set_transform(output->output, conf->transform); break; } } diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 7f681ab7..99737c48 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -62,6 +62,8 @@ struct wlr_output { struct wl_signal frame; struct wl_signal swap_buffers; struct wl_signal resolution; + struct wl_signal scale; + struct wl_signal transform; struct wl_signal destroy; } events; @@ -85,7 +87,7 @@ bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode); bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, int32_t height, int32_t refresh); -void wlr_output_transform(struct wlr_output *output, +void wlr_output_set_transform(struct wlr_output *output, enum wl_output_transform transform); void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly); void wlr_output_set_scale(struct wlr_output *output, uint32_t scale); diff --git a/rootston/output.c b/rootston/output.c index b2d6554d..560e5eeb 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -321,7 +321,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { set_mode(wlr_output, output_config); } wlr_output_set_scale(wlr_output, output_config->scale); - wlr_output_transform(wlr_output, output_config->transform); + wlr_output_set_transform(wlr_output, output_config->transform); wlr_output_layout_add(desktop->layout, wlr_output, output_config->x, output_config->y); } else { diff --git a/types/wlr_output.c b/types/wlr_output.c index adade238..a922b6f3 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -195,9 +195,11 @@ void wlr_output_update_size(struct wlr_output *output, int32_t width, wl_resource_for_each(resource, &output->wl_resources) { wlr_output_send_current_mode_to_resource(resource); } + + wl_signal_emit(&output->events.resolution, output); } -void wlr_output_transform(struct wlr_output *output, +void wlr_output_set_transform(struct wlr_output *output, enum wl_output_transform transform) { output->impl->transform(output, transform); wlr_output_update_matrix(output); @@ -207,6 +209,8 @@ void wlr_output_transform(struct wlr_output *output, wl_resource_for_each(resource, &output->wl_resources) { wl_output_send_to_resource(resource); } + + wl_signal_emit(&output->events.transform, output); } void wlr_output_set_position(struct wlr_output *output, int32_t lx, @@ -237,6 +241,8 @@ void wlr_output_set_scale(struct wlr_output *output, uint32_t scale) { wl_resource_for_each(resource, &output->wl_resources) { wl_output_send_to_resource(resource); } + + wl_signal_emit(&output->events.scale, output); } void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, @@ -252,6 +258,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, wl_signal_init(&output->events.frame); wl_signal_init(&output->events.swap_buffers); wl_signal_init(&output->events.resolution); + wl_signal_init(&output->events.scale); + wl_signal_init(&output->events.transform); wl_signal_init(&output->events.destroy); } diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index b2bcb113..a6942655 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -19,6 +19,8 @@ struct wlr_output_layout_output_state { bool auto_configured; struct wl_listener resolution; + struct wl_listener scale; + struct wl_listener transform; struct wl_listener output_destroy; }; @@ -46,6 +48,8 @@ static void wlr_output_layout_output_destroy( struct wlr_output_layout_output *l_output) { wl_signal_emit(&l_output->events.destroy, l_output); wl_list_remove(&l_output->state->resolution.link); + wl_list_remove(&l_output->state->scale.link); + wl_list_remove(&l_output->state->transform.link); wl_list_remove(&l_output->state->output_destroy.link); wl_list_remove(&l_output->link); free(l_output->state); @@ -134,6 +138,18 @@ static void handle_output_resolution(struct wl_listener *listener, void *data) { wlr_output_layout_reconfigure(state->layout); } +static void handle_output_scale(struct wl_listener *listener, void *data) { + struct wlr_output_layout_output_state *state = + wl_container_of(listener, state, scale); + wlr_output_layout_reconfigure(state->layout); +} + +static void handle_output_transform(struct wl_listener *listener, void *data) { + struct wlr_output_layout_output_state *state = + wl_container_of(listener, state, transform); + wlr_output_layout_reconfigure(state->layout); +} + static void handle_output_destroy(struct wl_listener *listener, void *data) { struct wlr_output_layout_output_state *state = wl_container_of(listener, state, output_destroy); @@ -162,6 +178,10 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( wl_signal_add(&output->events.resolution, &l_output->state->resolution); l_output->state->resolution.notify = handle_output_resolution; + wl_signal_add(&output->events.scale, &l_output->state->scale); + l_output->state->scale.notify = handle_output_scale; + wl_signal_add(&output->events.transform, &l_output->state->transform); + l_output->state->transform.notify = handle_output_transform; wl_signal_add(&output->events.destroy, &l_output->state->output_destroy); l_output->state->output_destroy.notify = handle_output_destroy; From 257559d890d294cbbc1c036ec9a1855d81d0db8b Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 13 Dec 2017 21:48:59 +0100 Subject: [PATCH 08/10] Remove output instead of terminating display when a wayland backend view closed --- backend/wayland/output.c | 5 ++++- backend/wayland/wl_seat.c | 5 ++++- types/wlr_output.c | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index f940299e..fc09903e 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -154,6 +154,8 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { wl_signal_emit(&output->backend->backend.events.output_remove, &output->wlr_output); + wl_list_remove(&output->link); + if (output->cursor.buf_size != 0) { assert(output->cursor.data); assert(output->cursor.buffer); @@ -171,6 +173,7 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) { if (output->frame_callback) { wl_callback_destroy(output->frame_callback); } + eglDestroySurface(output->backend->egl.display, output->surface); wl_egl_window_destroy(output->egl_window); zxdg_toplevel_v6_destroy(output->xdg_toplevel); @@ -233,7 +236,7 @@ static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_t struct wlr_wl_backend_output *output = data; assert(output && output->xdg_toplevel == xdg_toplevel); - wl_display_terminate(output->backend->local_display); + wlr_output_destroy((struct wlr_output *)output); } static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index a2da8df5..3c20e6ca 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -21,7 +21,10 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer; struct wlr_wl_backend_output *output = wlr_wl_output_for_surface(wlr_wl_dev->backend, surface); - assert(output); + if (!output) { + // GNOME sends a pointer enter when the surface is being destroyed + return; + } wlr_wl_pointer->current_output = output; output->enter_serial = serial; wlr_wl_output_update_cursor(output); diff --git a/types/wlr_output.c b/types/wlr_output.c index a922b6f3..cb604021 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -272,9 +272,9 @@ void wlr_output_destroy(struct wlr_output *output) { struct wlr_output_mode *mode, *tmp_mode; wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { + wl_list_remove(&mode->link); free(mode); } - wl_list_remove(&output->modes); if (output->impl && output->impl->destroy) { output->impl->destroy(output); } else { From a1302cc4a517b2a2851b0b41848cf2f001b954f3 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 13 Dec 2017 22:32:22 +0100 Subject: [PATCH 09/10] Fix pointer events with multiple outputs in wayland backend --- backend/wayland/backend.c | 33 +++++++++++++++++++++++++++++++++ backend/wayland/wl_seat.c | 19 ++++++++++++------- include/backend/wayland.h | 3 +++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 1801f3e0..39ecc10f 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,38 @@ struct wlr_wl_backend_output *wlr_wl_output_for_surface( return NULL; } +void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend, + struct wlr_box *box) { + int min_x = INT_MAX, min_y = INT_MAX; + int max_x = INT_MIN, max_y = INT_MIN; + + struct wlr_wl_backend_output *output; + wl_list_for_each(output, &backend->outputs, link) { + struct wlr_output *wlr_output = &output->wlr_output; + + int width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + + if (wlr_output->lx < min_x) { + min_x = wlr_output->lx; + } + if (wlr_output->ly < min_y) { + min_y = wlr_output->ly; + } + if (wlr_output->lx + width > max_x) { + max_x = wlr_output->lx + width; + } + if (wlr_output->ly + height > max_y) { + max_y = wlr_output->ly + height; + } + } + + box->x = min_x; + box->y = min_y; + box->width = max_x - min_x; + box->height = max_y - min_y; +} + struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { wlr_log(L_INFO, "Creating wayland backend"); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 3c20e6ca..7bfbf302 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -52,23 +52,28 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, return; } + struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output; + struct wlr_box box; wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, &box.width, &box.height); box.x = wl_fixed_to_int(surface_x); box.y = wl_fixed_to_int(surface_y); struct wlr_box transformed; - wlr_output_transform_apply_to_box( - wlr_wl_pointer->current_output->wlr_output.transform, &box, - &transformed); + wlr_output_transform_apply_to_box(wlr_output->transform, &box, &transformed); + box.x /= wlr_output->scale; + box.y /= wlr_output->scale; + + struct wlr_box layout_box; + wlr_wl_output_layout_get_box(wlr_wl_pointer->current_output->backend, &layout_box); struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.device = dev; wlr_event.time_msec = time; - wlr_event.width_mm = transformed.width; - wlr_event.height_mm = transformed.height; - wlr_event.x_mm = transformed.x; - wlr_event.y_mm = transformed.y; + wlr_event.width_mm = layout_box.width; + wlr_event.height_mm = layout_box.height; + wlr_event.x_mm = transformed.x + wlr_output->lx + layout_box.x; + wlr_event.y_mm = transformed.y + wlr_output->ly + layout_box.y; wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 1e8a55d2..7e2ec0d6 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,8 @@ void wlr_wl_registry_poll(struct wlr_wl_backend *backend); void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output); struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend *backend, struct wl_surface *surface); +void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend, + struct wlr_box *box); extern const struct wl_seat_listener seat_listener; From ea4b871e16ae63db67f2bf89c00e814b3dde6c78 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 13 Dec 2017 17:54:19 -0500 Subject: [PATCH 10/10] xwm: user custom event handler --- include/wlr/xwayland.h | 7 +++++++ {xwayland => include/wlr}/xwm.h | 0 meson.build | 2 +- xwayland/xwayland.c | 2 +- xwayland/xwm.c | 8 +++++++- 5 files changed, 16 insertions(+), 3 deletions(-) rename {xwayland => include/wlr}/xwm.h (100%) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 792d2b88..9a89661b 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -32,6 +32,13 @@ struct wlr_xwayland { struct wl_signal new_surface; } events; + /** + * Add a custom event handler to xwayland. Return 1 if the event was + * handled or 0 to use the default wlr-xwayland handler. wlr-xwayland will + * free the event. + */ + int (*user_event_handler)(struct wlr_xwm *xwm, xcb_generic_event_t *event); + void *data; }; diff --git a/xwayland/xwm.h b/include/wlr/xwm.h similarity index 100% rename from xwayland/xwm.h rename to include/wlr/xwm.h diff --git a/meson.build b/meson.build index addea930..a3f5e7f9 100644 --- a/meson.build +++ b/meson.build @@ -87,7 +87,7 @@ if get_option('enable_xwayland') wlr_parts += [lib_wlr_xwayland] conf_data.set('WLR_HAS_XWAYLAND', true) else - exclude_files += ['xwayland.h'] + exclude_files += ['xwayland.h', 'xwm.h'] endif configure_file(output: 'config.h', install_dir: 'include/wlr', configuration: conf_data) install_subdir('include/wlr', install_dir: 'include', exclude_files: exclude_files) diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index ecec785c..eb06bd57 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -19,7 +19,7 @@ #include "wlr/util/log.h" #include "wlr/xwayland.h" #include "sockets.h" -#include "xwm.h" +#include "wlr/xwm.h" #ifdef __FreeBSD__ static inline int clearenv(void) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index a86fbd0e..54092cda 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -12,7 +12,7 @@ #include "wlr/types/wlr_surface.h" #include "wlr/xwayland.h" #include "wlr/xcursor.h" -#include "xwm.h" +#include "wlr/xwm.h" #ifdef HAS_XCB_ICCCM #include @@ -938,6 +938,12 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { while ((event = xcb_poll_for_event(xwm->xcb_conn))) { count++; + + if (xwm->xwayland->user_event_handler && + xwm->xwayland->user_event_handler(xwm, event)) { + break; + } + switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) { case XCB_CREATE_NOTIFY: xwm_handle_create_notify(xwm, (xcb_create_notify_event_t *)event);