From 0ef2df21f2943c3985fcc86f5f6c3289036be491 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 5 Jan 2018 07:00:50 -0500 Subject: compositor modifier hook --- include/wlr/types/wlr_keyboard.h | 14 ++++++++------ include/wlr/types/wlr_seat.h | 14 +++++++++++--- rootston/keyboard.c | 3 ++- types/wlr_keyboard.c | 20 +++++++++++--------- types/wlr_seat.c | 29 ++++++++++++++++------------- types/wlr_xdg_shell_v6.c | 5 +++-- 6 files changed, 51 insertions(+), 34 deletions(-) diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index d32d6e96..b37797c8 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -32,6 +32,13 @@ enum wlr_keyboard_modifier { struct wlr_keyboard_impl; +struct wlr_keyboard_modifiers { + xkb_mod_mask_t depressed; + xkb_mod_mask_t latched; + xkb_mod_mask_t locked; + xkb_mod_mask_t group; +}; + struct wlr_keyboard { struct wlr_keyboard_impl *impl; // TODO: Should this store key repeat info too? @@ -45,12 +52,7 @@ struct wlr_keyboard { uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP]; size_t num_keycodes; - struct { - xkb_mod_mask_t depressed; - xkb_mod_mask_t latched; - xkb_mod_mask_t locked; - xkb_mod_mask_t group; - } modifiers; + struct wlr_keyboard_modifiers *modifiers; struct { int32_t rate; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 432e5dc3..f5b4afde 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -71,7 +71,8 @@ struct wlr_keyboard_grab_interface { struct wlr_surface *surface); void (*key)(struct wlr_seat_keyboard_grab *grab, uint32_t time, uint32_t key, uint32_t state); - void (*modifiers)(struct wlr_seat_keyboard_grab *grab); + void (*modifiers)(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers); void (*cancel)(struct wlr_seat_keyboard_grab *grab); }; @@ -344,6 +345,11 @@ bool wlr_seat_pointer_has_grab(struct wlr_seat *seat); */ void wlr_seat_set_keyboard(struct wlr_seat *seat, struct wlr_input_device *dev); +/** + * Get the active keyboard for the seat. + */ +struct wlr_keyboard *wlr_seat_get_keyboard(struct wlr_seat *seat); + /** * Start a grab of the keyboard of this seat. The grabber is responsible for * handling all keyboard events until the grab ends. @@ -375,13 +381,15 @@ void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, * Send the modifier state to focused keyboard resources. Compositors should use * `wlr_seat_keyboard_notify_modifiers()` to respect any keyboard grabs. */ -void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat); +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers); /** * Notify the seat that the modifiers for the keyboard have changed. Defers to * any keyboard grabs. */ -void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat); +void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers); /** * Notify the seat that the keyboard focus has changed and request it to be the diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 7b281308..29409dd7 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -279,7 +279,8 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard, void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) { struct wlr_seat *seat = r_keyboard->seat->seat; wlr_seat_set_keyboard(seat, r_keyboard->device); - wlr_seat_keyboard_notify_modifiers(seat); + wlr_seat_keyboard_notify_modifiers(seat, + r_keyboard->device->keyboard->modifiers); } static void keyboard_config_merge(struct roots_keyboard_config *config, diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 6caf27f5..53ea3a59 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -30,17 +30,17 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { XKB_STATE_MODS_LOCKED); xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, XKB_STATE_LAYOUT_EFFECTIVE); - if (depressed == keyboard->modifiers.depressed && - latched == keyboard->modifiers.latched && - locked == keyboard->modifiers.locked && - group == keyboard->modifiers.group) { + if (depressed == keyboard->modifiers->depressed && + latched == keyboard->modifiers->latched && + locked == keyboard->modifiers->locked && + group == keyboard->modifiers->group) { return; } - keyboard->modifiers.depressed = depressed; - keyboard->modifiers.latched = latched; - keyboard->modifiers.locked = locked; - keyboard->modifiers.group = group; + keyboard->modifiers->depressed = depressed; + keyboard->modifiers->latched = latched; + keyboard->modifiers->locked = locked; + keyboard->modifiers->group = group; wl_signal_emit(&keyboard->events.modifiers, keyboard); } @@ -117,6 +117,7 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, void wlr_keyboard_init(struct wlr_keyboard *kb, struct wlr_keyboard_impl *impl) { kb->impl = impl; + kb->modifiers = calloc(1, sizeof(struct wlr_keyboard_modifiers)); wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); @@ -139,6 +140,7 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) { xkb_state_unref(kb->xkb_state); xkb_keymap_unref(kb->keymap); close(kb->keymap_fd); + free(kb->modifiers); free(kb); } @@ -222,7 +224,7 @@ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, } uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { - xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; + xkb_mod_mask_t mask = kb->modifiers->depressed | kb->modifiers->latched; uint32_t modifiers = 0; for (size_t i = 0; i < WLR_MODIFIER_COUNT; ++i) { if (kb->mod_indexes[i] != XKB_MOD_INVALID && diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 79638822..8c5519b6 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -291,8 +291,9 @@ static void default_keyboard_key(struct wlr_seat_keyboard_grab *grab, wlr_seat_keyboard_send_key(grab->seat, time, key, state); } -static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab) { - wlr_seat_keyboard_send_modifiers(grab->seat); +static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_send_modifiers(grab->seat, modifiers); } static void default_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) { @@ -796,6 +797,10 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat->keyboard_state.keyboard = keyboard; } +struct wlr_keyboard *wlr_seat_get_keyboard(struct wlr_seat *seat) { + return seat->keyboard_state.keyboard; +} + void wlr_seat_keyboard_start_grab(struct wlr_seat *wlr_seat, struct wlr_seat_keyboard_grab *grab) { grab->seat = wlr_seat; @@ -834,23 +839,19 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener, wlr_seat_keyboard_clear_focus(state->seat); } -void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat) { +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers) { struct wlr_seat_client *client = seat->keyboard_state.focused_client; if (client == NULL) { return; } - struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard; - if (keyboard == NULL) { - return; - } - uint32_t serial = wl_display_next_serial(seat->display); struct wl_resource *resource; wl_resource_for_each(resource, &client->keyboards) { wl_keyboard_send_modifiers(resource, serial, - keyboard->modifiers.depressed, keyboard->modifiers.latched, - keyboard->modifiers.locked, keyboard->modifiers.group); + modifiers->depressed, modifiers->latched, + modifiers->locked, modifiers->group); } } @@ -930,7 +931,8 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, if (client != NULL && seat->keyboard_state.keyboard != NULL) { // tell new client about any modifier change last, // as it targets seat->keyboard_state.focused_client - wlr_seat_keyboard_send_modifiers(seat); + wlr_seat_keyboard_send_modifiers(seat, + seat->keyboard_state.keyboard->modifiers); } } @@ -950,10 +952,11 @@ bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) { return seat->keyboard_state.grab->interface != &default_keyboard_grab_impl; } -void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) { +void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers) { clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; - grab->interface->modifiers(grab); + grab->interface->modifiers(grab, modifiers); } void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 1c46197e..fd09b467 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -112,8 +112,9 @@ static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, uint32_t wlr_seat_keyboard_send_key(grab->seat, time, key, state); } -static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab) { - wlr_seat_keyboard_send_modifiers(grab->seat); +static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_send_modifiers(grab->seat, modifiers); } static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) { -- cgit v1.2.3 From fcab1e87ed884777d91858a766f5330697977851 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 08:32:44 -0500 Subject: fix data-device keyboard grab signature --- types/wlr_data_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index a4eb233b..3c48119a 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -594,7 +594,8 @@ static void keyboard_drag_key(struct wlr_seat_keyboard_grab *grab, // no keyboard input during drags } -static void keyboard_drag_modifiers(struct wlr_seat_keyboard_grab *grab) { +static void keyboard_drag_modifiers(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers) { //struct wlr_keyboard *keyboard = grab->seat->keyboard_state.keyboard; // TODO change the dnd action based on what modifier is pressed on the // keyboard -- cgit v1.2.3 From ca0f456d6c267523615afaed421f28affeaccf6c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 09:06:19 -0500 Subject: wlr-keyboard set layout error handling --- types/wlr_keyboard.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 53ea3a59..550ea67f 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -11,6 +11,10 @@ int os_create_anonymous_file(off_t size); static void keyboard_led_update(struct wlr_keyboard *keyboard) { + if (keyboard->xkb_state == NULL) { + return; + } + uint32_t leds = 0; for (uint32_t i = 0; i < WLR_LED_COUNT; ++i) { if (xkb_state_led_index_is_active(keyboard->xkb_state, @@ -22,6 +26,10 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) { } static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { + if (keyboard->xkb_state == NULL) { + return; + } + xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, XKB_STATE_MODS_DEPRESSED); xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state, @@ -90,7 +98,7 @@ static void keyboard_key_update(struct wlr_keyboard *keyboard, void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { - if (!keyboard->xkb_state) { + if (keyboard->xkb_state == NULL) { return; } xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched, @@ -100,7 +108,7 @@ void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event) { - if (!keyboard->xkb_state) { + if (keyboard->xkb_state == NULL) { return; } if (event->update_state) { @@ -152,20 +160,16 @@ 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) { - if (kb->keymap) { - xkb_keymap_unref(kb->keymap); - } - xkb_keymap_ref(keymap); - kb->keymap = keymap; + char *keymap_str = NULL; - if (kb->xkb_state) { - xkb_state_unref(kb->xkb_state); - } + xkb_keymap_unref(kb->keymap); + kb->keymap = xkb_keymap_ref(keymap); + xkb_state_unref(kb->xkb_state); kb->xkb_state = xkb_state_new(kb->keymap); if (kb->xkb_state == NULL) { wlr_log(L_ERROR, "Failed to create XKB state"); - return; + goto err; } const char *led_names[WLR_LED_COUNT] = { @@ -192,7 +196,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, kb->mod_indexes[i] = xkb_map_mod_get_index(kb->keymap, mod_names[i]); } - char *keymap_str = xkb_keymap_get_as_string(kb->keymap, + keymap_str = xkb_keymap_get_as_string(kb->keymap, XKB_KEYMAP_FORMAT_TEXT_V1); kb->keymap_size = strlen(keymap_str) + 1; if (kb->keymap_fd) { @@ -201,16 +205,29 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, kb->keymap_fd = os_create_anonymous_file(kb->keymap_size); if (kb->keymap_fd < 0) { wlr_log(L_ERROR, "creating a keymap file for %lu bytes failed", kb->keymap_size); + goto err; } void *ptr = mmap(NULL, kb->keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, kb->keymap_fd, 0); if (ptr == (void*)-1) { wlr_log(L_ERROR, "failed to mmap() %lu bytes", kb->keymap_size); + goto err; } strcpy(ptr, keymap_str); free(keymap_str); + // TODO need to update the state with the currently pressed keys + wl_signal_emit(&kb->events.keymap, kb); + return; + +err: + xkb_state_unref(kb->xkb_state); + kb->xkb_state = NULL; + xkb_keymap_unref(keymap); + kb->keymap = NULL; + close(kb->keymap_fd); + free(keymap_str); } void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, -- cgit v1.2.3 From 97652320965bd24fb1f823dabbf71cb789b2e254 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 09:36:57 -0500 Subject: update xkb state on layout change --- types/wlr_keyboard.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 550ea67f..5a90e6b2 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -25,9 +25,13 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) { wlr_keyboard_led_update(keyboard, leds); } -static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { +/** + * Update the modifier state of the wlr-keyboard. Returns true if the modifier + * state changed. + */ +static bool keyboard_modifier_update(struct wlr_keyboard *keyboard) { if (keyboard->xkb_state == NULL) { - return; + return false; } xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, @@ -42,7 +46,7 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { latched == keyboard->modifiers->latched && locked == keyboard->modifiers->locked && group == keyboard->modifiers->group) { - return; + return false; } keyboard->modifiers->depressed = depressed; @@ -50,7 +54,7 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { keyboard->modifiers->locked = locked; keyboard->modifiers->group = group; - wl_signal_emit(&keyboard->events.modifiers, keyboard); + return true; } // https://www.geeksforgeeks.org/move-zeroes-end-array/ @@ -103,7 +107,11 @@ void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, } xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); - keyboard_modifier_update(keyboard); + + bool updated = keyboard_modifier_update(keyboard); + if (updated) { + wl_signal_emit(&keyboard->events.modifiers, keyboard); + } } void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, @@ -117,7 +125,12 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); } keyboard_led_update(keyboard); - keyboard_modifier_update(keyboard); + + bool updated = keyboard_modifier_update(keyboard); + if (updated) { + wl_signal_emit(&keyboard->events.modifiers, keyboard); + } + keyboard_key_update(keyboard, event); wl_signal_emit(&keyboard->events.key, event); } @@ -216,7 +229,12 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, strcpy(ptr, keymap_str); free(keymap_str); - // TODO need to update the state with the currently pressed keys + for (size_t i = 0; i < kb->num_keycodes; ++i) { + xkb_keycode_t keycode = kb->keycodes[i] + 8; + xkb_state_update_key(kb->xkb_state, keycode, XKB_KEY_DOWN); + } + + keyboard_modifier_update(kb); wl_signal_emit(&kb->events.keymap, kb); return; -- cgit v1.2.3 From 2bd3a75f809dc0407d99a84997774c830f63ccd2 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 10:31:32 -0500 Subject: fix send modifiers in wlr-seat set keyboard --- types/wlr_seat.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 91a7a681..6ed92493 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -774,6 +774,7 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, if (keyboard) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); + seat->keyboard_state.keyboard = keyboard; wl_signal_add(&device->events.destroy, &seat->keyboard_state.keyboard_destroy); @@ -788,14 +789,14 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, 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_client_send_keymap(client, keyboard); + seat_client_send_repeat_info(client, keyboard); } + wlr_seat_keyboard_send_modifiers(seat, keyboard->modifiers); + } else { + seat->keyboard_state.keyboard = NULL; } - - seat->keyboard_state.keyboard = keyboard; - wlr_seat_keyboard_send_modifiers(seat); } struct wlr_keyboard *wlr_seat_get_keyboard(struct wlr_seat *seat) { -- cgit v1.2.3 From b40a5f084abeb5530b3a0097c946ba720c897262 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 11:06:09 -0500 Subject: keyboard grab enter with modifiers --- include/wlr/types/wlr_seat.h | 13 ++++++++----- rootston/seat.c | 11 ++++++++++- types/wlr_data_device.c | 3 ++- types/wlr_seat.c | 45 +++++++++++++++++++++++--------------------- types/wlr_xdg_shell_v6.c | 4 +++- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index f5b4afde..c2a89f33 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -68,7 +68,8 @@ struct wlr_seat_keyboard_grab; struct wlr_keyboard_grab_interface { void (*enter)(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface); + struct wlr_surface *surface, uint32_t keycodes[], + size_t num_keycodes, struct wlr_keyboard_modifiers *modifiers); void (*key)(struct wlr_seat_keyboard_grab *grab, uint32_t time, uint32_t key, uint32_t state); void (*modifiers)(struct wlr_seat_keyboard_grab *grab, @@ -396,8 +397,9 @@ void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, * focused surface for this keyboard. Defers to any current grab of the seat's * keyboard. */ -void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface); +void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers); /** * Send a keyboard enter event to the given surface and consider it to be the @@ -406,8 +408,9 @@ void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, * `wlr_seat_keyboard_notify_enter()` to change keyboard focus to respect * keyboard grabs. */ -void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface); +void wlr_seat_keyboard_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers); /** * Clear the focused surface for the keyboard and leave all entered surfaces. diff --git a/rootston/seat.c b/rootston/seat.c index 2728ca96..0972fce2 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -616,7 +616,16 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { seat->has_focus = true; wl_list_remove(&seat_view->link); wl_list_insert(&seat->views, &seat_view->link); - wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface); + + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); + if (keyboard != NULL) { + wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, + keyboard->keycodes, keyboard->num_keycodes, + keyboard->modifiers); + } else { + wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, + NULL, 0, NULL); + } } void roots_seat_cycle_focus(struct roots_seat *seat) { diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 3c48119a..5a6bc198 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -585,7 +585,8 @@ const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = { }; static void keyboard_drag_enter(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface) { + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { // nothing has keyboard focus during drags } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 6ed92493..4378675c 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -282,8 +282,9 @@ static const struct wlr_pointer_grab_interface default_pointer_grab_impl = { }; static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface) { - wlr_seat_keyboard_enter(grab->seat, surface); + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_enter(grab->seat, surface, keycodes, num_keycodes, modifiers); } static void default_keyboard_key(struct wlr_seat_keyboard_grab *grab, @@ -851,14 +852,19 @@ void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, uint32_t serial = wl_display_next_serial(seat->display); struct wl_resource *resource; wl_resource_for_each(resource, &client->keyboards) { - wl_keyboard_send_modifiers(resource, serial, - modifiers->depressed, modifiers->latched, - modifiers->locked, modifiers->group); + if (modifiers == NULL) { + wl_keyboard_send_modifiers(resource, serial, 0, 0, 0, 0); + } else { + wl_keyboard_send_modifiers(resource, serial, + modifiers->depressed, modifiers->latched, + modifiers->locked, modifiers->group); + } } } void wlr_seat_keyboard_enter(struct wlr_seat *seat, - struct wlr_surface *surface) { + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { if (seat->keyboard_state.focused_surface == surface) { // this surface already got an enter notify return; @@ -886,19 +892,17 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, } // enter the current surface - if (client != NULL && seat->keyboard_state.keyboard != NULL) { - struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard; - + if (client != NULL) { struct wl_array keys; wl_array_init(&keys); - for (size_t i = 0; i < keyboard->num_keycodes; ++i) { + for (size_t i = 0; i < num_keycodes; ++i) { uint32_t *p = wl_array_add(&keys, sizeof(uint32_t)); if (!p) { wlr_log(L_ERROR, "Cannot allocate memory, skipping keycode: %d\n", - keyboard->keycodes[i]); + keycodes[i]); continue; } - *p = keyboard->keycodes[i]; + *p = keycodes[i]; } uint32_t serial = wl_display_next_serial(seat->display); struct wl_resource *resource; @@ -930,24 +934,23 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, seat->keyboard_state.focused_client = client; seat->keyboard_state.focused_surface = surface; - if (client != NULL && seat->keyboard_state.keyboard != NULL) { + if (client != NULL) { // tell new client about any modifier change last, // as it targets seat->keyboard_state.focused_client - wlr_seat_keyboard_send_modifiers(seat, - seat->keyboard_state.keyboard->modifiers); + wlr_seat_keyboard_send_modifiers(seat, modifiers); } } -void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, struct - wlr_surface *surface) { +void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; - grab->interface->enter(grab, surface); + grab->interface->enter(grab, surface, keycodes, num_keycodes, modifiers); } void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) { - struct wl_array keys; - wl_array_init(&keys); - wlr_seat_keyboard_enter(seat, NULL); + // TODO respect grabs here? + wlr_seat_keyboard_enter(seat, NULL, NULL, 0, NULL); } bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) { diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index fd09b467..59b152bd 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -103,7 +103,9 @@ static const struct wlr_pointer_grab_interface xdg_pointer_grab_impl = { .axis = xdg_pointer_grab_axis, }; -static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, struct wlr_surface *surface) { +static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { // keyboard focus should remain on the popup } -- cgit v1.2.3 From 7f56ccd71395d2280ec463d8847b27d62c2855a6 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 16 Jan 2018 20:33:55 +0100 Subject: rootston: set real seat capabilities --- rootston/seat.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/rootston/seat.c b/rootston/seat.c index 130c7b27..c0cda3b0 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -293,11 +293,6 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { return NULL; } - wlr_seat_set_capabilities(seat->seat, - WL_SEAT_CAPABILITY_KEYBOARD | - WL_SEAT_CAPABILITY_POINTER | - WL_SEAT_CAPABILITY_TOUCH); - wl_list_insert(&input->seats, &seat->link); seat->seat_destroy.notify = roots_seat_handle_seat_destroy; @@ -306,6 +301,20 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { return seat; } +static void seat_update_capabilities(struct roots_seat *seat) { + uint32_t caps = 0; + if (!wl_list_empty(&seat->keyboards)) { + caps |= WL_SEAT_CAPABILITY_KEYBOARD; + } + if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablet_tools)) { + caps |= WL_SEAT_CAPABILITY_POINTER; + } + if (!wl_list_empty(&seat->touch)) { + caps |= WL_SEAT_CAPABILITY_TOUCH; + } + wlr_seat_set_capabilities(seat->seat, caps); +} + static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); @@ -404,6 +413,8 @@ void roots_seat_add_device(struct roots_seat *seat, seat_add_tablet_tool(seat, device); break; } + + seat_update_capabilities(seat); } static void seat_remove_keyboard(struct roots_seat *seat, @@ -480,6 +491,8 @@ void roots_seat_remove_device(struct roots_seat *seat, seat_remove_tablet_tool(seat, device); break; } + + seat_update_capabilities(seat); } void roots_seat_configure_xcursor(struct roots_seat *seat) { -- cgit v1.2.3 From 6e9c652fc4c3dc65d313f4cb8823995a98d65964 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 16 Jan 2018 20:37:32 +0100 Subject: rootston: hide cursor if seat has no pointer --- rootston/seat.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rootston/seat.c b/rootston/seat.c index c0cda3b0..a61057bd 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -313,6 +313,14 @@ static void seat_update_capabilities(struct roots_seat *seat) { caps |= WL_SEAT_CAPABILITY_TOUCH; } wlr_seat_set_capabilities(seat->seat, caps); + + // Hide cursor if seat doesn't have pointer capability + if ((caps & WL_SEAT_CAPABILITY_POINTER) == 0) { + wlr_cursor_set_image(seat->cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); + } else { + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + seat->cursor->default_xcursor, seat->cursor->cursor); + } } static void seat_add_keyboard(struct roots_seat *seat, -- cgit v1.2.3 From b6f29e87e85b599170a0ffd1f4c94c46c216d51a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 17 Jan 2018 08:31:15 -0500 Subject: dont use pointer for modifiers --- include/wlr/types/wlr_keyboard.h | 2 +- rootston/keyboard.c | 2 +- rootston/seat.c | 2 +- types/wlr_keyboard.c | 20 +++++++++----------- types/wlr_seat.c | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index b37797c8..c67cc4c2 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -52,7 +52,7 @@ struct wlr_keyboard { uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP]; size_t num_keycodes; - struct wlr_keyboard_modifiers *modifiers; + struct wlr_keyboard_modifiers modifiers; struct { int32_t rate; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 09adea5a..f1123599 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -289,7 +289,7 @@ void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) { struct wlr_seat *seat = r_keyboard->seat->seat; wlr_seat_set_keyboard(seat, r_keyboard->device); wlr_seat_keyboard_notify_modifiers(seat, - r_keyboard->device->keyboard->modifiers); + &r_keyboard->device->keyboard->modifiers); } static void keyboard_config_merge(struct roots_keyboard_config *config, diff --git a/rootston/seat.c b/rootston/seat.c index ed58e294..1a0e6253 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -667,7 +667,7 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { if (keyboard != NULL) { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, keyboard->keycodes, keyboard->num_keycodes, - keyboard->modifiers); + &keyboard->modifiers); } else { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, NULL, 0, NULL); diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 5a90e6b2..b0dc97aa 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -42,17 +42,17 @@ static bool keyboard_modifier_update(struct wlr_keyboard *keyboard) { XKB_STATE_MODS_LOCKED); xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, XKB_STATE_LAYOUT_EFFECTIVE); - if (depressed == keyboard->modifiers->depressed && - latched == keyboard->modifiers->latched && - locked == keyboard->modifiers->locked && - group == keyboard->modifiers->group) { + if (depressed == keyboard->modifiers.depressed && + latched == keyboard->modifiers.latched && + locked == keyboard->modifiers.locked && + group == keyboard->modifiers.group) { return false; } - keyboard->modifiers->depressed = depressed; - keyboard->modifiers->latched = latched; - keyboard->modifiers->locked = locked; - keyboard->modifiers->group = group; + keyboard->modifiers.depressed = depressed; + keyboard->modifiers.latched = latched; + keyboard->modifiers.locked = locked; + keyboard->modifiers.group = group; return true; } @@ -138,7 +138,6 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, void wlr_keyboard_init(struct wlr_keyboard *kb, struct wlr_keyboard_impl *impl) { kb->impl = impl; - kb->modifiers = calloc(1, sizeof(struct wlr_keyboard_modifiers)); wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); @@ -161,7 +160,6 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) { xkb_state_unref(kb->xkb_state); xkb_keymap_unref(kb->keymap); close(kb->keymap_fd); - free(kb->modifiers); free(kb); } @@ -259,7 +257,7 @@ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, } uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { - xkb_mod_mask_t mask = kb->modifiers->depressed | kb->modifiers->latched; + xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; uint32_t modifiers = 0; for (size_t i = 0; i < WLR_MODIFIER_COUNT; ++i) { if (kb->mod_indexes[i] != XKB_MOD_INVALID && diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 4378675c..019cb567 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -794,7 +794,7 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat_client_send_repeat_info(client, keyboard); } - wlr_seat_keyboard_send_modifiers(seat, keyboard->modifiers); + wlr_seat_keyboard_send_modifiers(seat, &keyboard->modifiers); } else { seat->keyboard_state.keyboard = NULL; } -- cgit v1.2.3 From dcc743047b903af8ba409ed25745f891234dc323 Mon Sep 17 00:00:00 2001 From: Johannes Schramm Date: Sun, 21 Jan 2018 16:28:21 +0100 Subject: style: include brackets for if/while/for, even if it's a single statement --- backend/session/logind.c | 4 +++- backend/session/session.c | 3 ++- backend/wayland/backend.c | 24 ++++++++++++++++++------ examples/rotation.c | 8 ++++++-- examples/screenshot.c | 3 ++- types/wlr_surface.c | 3 ++- xwayland/xwm.c | 9 ++++++--- 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/backend/session/logind.c b/backend/session/logind.c index 0b5b2a63..aa38b46c 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -330,7 +330,9 @@ static bool add_signal_matches(struct logind_session *session) { static int dbus_event(int fd, uint32_t mask, void *data) { sd_bus *bus = data; - while (sd_bus_process(bus, NULL) > 0); + while (sd_bus_process(bus, NULL) > 0) { + ; + } return 1; } diff --git a/backend/session/session.c b/backend/session/session.c index a5f17b8d..2bbbd4ef 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -307,8 +307,9 @@ size_t wlr_session_find_gpus(struct wlr_session *session, } const char *seat = udev_device_get_property_value(dev, "ID_SEAT"); - if (!seat) + if (!seat) { seat = "seat0"; + } if (session->seat[0] && strcmp(session->seat, seat) != 0) { udev_device_unref(dev); continue; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 32fdc2b6..f85498eb 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -85,12 +85,24 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) { wl_event_source_remove(backend->remote_display_src); wlr_egl_finish(&backend->egl); - if (backend->seat) wl_seat_destroy(backend->seat); - if (backend->shm) wl_shm_destroy(backend->shm); - if (backend->shell) zxdg_shell_v6_destroy(backend->shell); - if (backend->compositor) wl_compositor_destroy(backend->compositor); - if (backend->registry) wl_registry_destroy(backend->registry); - if (backend->remote_display) wl_display_disconnect(backend->remote_display); + if (backend->seat) { + wl_seat_destroy(backend->seat); + } + if (backend->shm) { + wl_shm_destroy(backend->shm); + } + if (backend->shell) { + zxdg_shell_v6_destroy(backend->shell); + } + if (backend->compositor) { + wl_compositor_destroy(backend->compositor); + } + if (backend->registry) { + wl_registry_destroy(backend->registry); + } + if (backend->remote_display) { + wl_display_disconnect(backend->remote_display); + } free(backend); } diff --git a/examples/rotation.c b/examples/rotation.c index 1d974025..6ec6b439 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -64,8 +64,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts odata->x_offs += odata->x_vel * seconds; odata->y_offs += odata->y_vel * seconds; - if (odata->x_offs > 128) odata->x_offs = 0; - if (odata->y_offs > 128) odata->y_offs = 0; + if (odata->x_offs > 128) { + odata->x_offs = 0; + } + if (odata->y_offs > 128) { + odata->y_offs = 0; + } } static void handle_output_add(struct output_state *output) { diff --git a/examples/screenshot.c b/examples/screenshot.c index 441d8684..529af38f 100644 --- a/examples/screenshot.c +++ b/examples/screenshot.c @@ -277,8 +277,9 @@ int main(int argc, char *argv[]) { screenshooter, output->output, output->buffer); orbital_screenshot_add_listener(screenshot, &screenshot_listener, screenshot); buffer_copy_done = 0; - while (!buffer_copy_done) + while (!buffer_copy_done) { wl_display_roundtrip(display); + } } write_image("wayland-screenshot.png", width, height); diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 8e024177..b9df8f7d 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -720,8 +720,9 @@ static struct wlr_subsurface *subsurface_find_sibling( struct wlr_subsurface *sibling; wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { - if (sibling->surface == surface && sibling != subsurface) + if (sibling->surface == surface && sibling != subsurface) { return sibling; + } } return NULL; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index dc349ab2..13e99040 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -480,12 +480,15 @@ static void read_surface_net_wm_state(struct wlr_xwm *xwm, xsurface->fullscreen = 0; xcb_atom_t *atom = xcb_get_property_value(reply); for (uint32_t i = 0; i < reply->value_len; i++) { - if (atom[i] == xwm->atoms[_NET_WM_STATE_FULLSCREEN]) + if (atom[i] == xwm->atoms[_NET_WM_STATE_FULLSCREEN]) { xsurface->fullscreen = true; - if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]) + } + if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]) { xsurface->maximized_vert = true; - if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]) + } + if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]) { xsurface->maximized_horz = true; + } } } -- cgit v1.2.3 From e37ebf6869b653c91c27af706404d60b78ad0168 Mon Sep 17 00:00:00 2001 From: Johannes Schramm Date: Sun, 21 Jan 2018 17:00:15 +0100 Subject: style: add comment to empty while loop in logind.c --- backend/session/logind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/session/logind.c b/backend/session/logind.c index aa38b46c..1ece051f 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -331,7 +331,7 @@ static bool add_signal_matches(struct logind_session *session) { static int dbus_event(int fd, uint32_t mask, void *data) { sd_bus *bus = data; while (sd_bus_process(bus, NULL) > 0) { - ; + // Do nothing. } return 1; } -- cgit v1.2.3 From 47eb478c35b109f520323af5013d47ad7ddc0824 Mon Sep 17 00:00:00 2001 From: Johannes Schramm Date: Sun, 21 Jan 2018 17:04:23 +0100 Subject: style: add else keywords in xwm.c --- xwayland/xwm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 13e99040..aada6501 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -482,11 +482,9 @@ static void read_surface_net_wm_state(struct wlr_xwm *xwm, for (uint32_t i = 0; i < reply->value_len; i++) { if (atom[i] == xwm->atoms[_NET_WM_STATE_FULLSCREEN]) { xsurface->fullscreen = true; - } - if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]) { + } else if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_VERT]) { xsurface->maximized_vert = true; - } - if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]) { + } else if (atom[i] == xwm->atoms[_NET_WM_STATE_MAXIMIZED_HORZ]) { xsurface->maximized_horz = true; } } -- cgit v1.2.3 From 4478cf1ddc9109dd39ed447bdab854838a423e2a Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 21 Jan 2018 14:57:24 -0500 Subject: Fixes #575 --- backend/drm/drm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 0d32605a..30eb1256 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -501,6 +501,9 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, struct wlr_drm_renderer *renderer = &drm->renderer; struct wlr_drm_crtc *crtc = conn->crtc; + if (!crtc) { + return false; + } struct wlr_drm_plane *plane = crtc->cursor; // We don't have a real cursor plane, so we make a fake one -- cgit v1.2.3 From 9d4ea146b66282e4cee6aedc8e0f27db3561d9a3 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 21 Jan 2018 15:37:23 -0500 Subject: Added crtc null check for other drm funcs --- backend/drm/drm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 30eb1256..c3cdd9f8 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -193,6 +193,9 @@ static void wlr_drm_connector_swap_buffers(struct wlr_output *output) { struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_crtc *crtc = conn->crtc; + if (!crtc) { + return; + } struct wlr_drm_plane *plane = crtc->primary; struct gbm_bo *bo = wlr_drm_surface_swap_buffers(&plane->surf); @@ -230,6 +233,9 @@ void wlr_drm_connector_start_renderer(struct wlr_drm_connector *conn) { struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; struct wlr_drm_crtc *crtc = conn->crtc; + if (!crtc) { + return; + } struct wlr_drm_plane *plane = crtc->primary; struct gbm_bo *bo = wlr_drm_surface_get_front( @@ -450,6 +456,9 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output, } struct wlr_drm_crtc *crtc = conn->crtc; + if (!crtc) { + return false; + } wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", conn->output.name, crtc - drm->crtcs, crtc->overlay ? crtc->overlay - drm->overlay_planes : -1, -- cgit v1.2.3 From f8b9f44ff53c25ad8feef1f2239b82c5e725c082 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 21 Jan 2018 15:47:02 -0500 Subject: Add con/crtc null check to move_cursor in drm --- backend/drm/drm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index c3cdd9f8..47bd4e3a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -634,6 +634,9 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, int x, int y) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + if (!conn || !conn->crtc) { + return false; + } struct wlr_drm_plane *plane = conn->crtc->cursor; struct wlr_box box; -- cgit v1.2.3