mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-07 14:06:00 +01:00
Merge branch 'master' into feature/multiseat
This commit is contained in:
commit
79f5bd6ef8
8 changed files with 154 additions and 68 deletions
|
@ -28,6 +28,8 @@ enum wlr_keyboard_modifier {
|
|||
WLR_MODIFIER_MOD5 = 128,
|
||||
};
|
||||
|
||||
#define WLR_KEYBOARD_KEYS_CAP 32
|
||||
|
||||
struct wlr_keyboard_impl;
|
||||
|
||||
struct wlr_keyboard {
|
||||
|
@ -41,6 +43,7 @@ struct wlr_keyboard {
|
|||
xkb_led_index_t led_indexes[WLR_LED_COUNT];
|
||||
xkb_mod_index_t mod_indexes[WLR_MODIFIER_COUNT];
|
||||
|
||||
uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP];
|
||||
struct {
|
||||
xkb_mod_mask_t depressed;
|
||||
xkb_mod_mask_t latched;
|
||||
|
|
|
@ -45,9 +45,7 @@ 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group);
|
||||
void (*modifiers)(struct wlr_seat_keyboard_grab *grab);
|
||||
void (*cancel)(struct wlr_seat_keyboard_grab *grab);
|
||||
};
|
||||
|
||||
|
@ -296,17 +294,13 @@ 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group);
|
||||
void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat);
|
||||
|
||||
/**
|
||||
* 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group);
|
||||
void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat);
|
||||
|
||||
/**
|
||||
* Notify the seat that the keyboard focus has changed and request it to be the
|
||||
|
|
|
@ -128,6 +128,16 @@ void view_setup(struct roots_view *view) {
|
|||
|
||||
void view_teardown(struct roots_view *view) {
|
||||
// TODO replace me with a signal
|
||||
/*
|
||||
struct wlr_list *views = view->desktop->views;
|
||||
if (views->length < 2 || views->items[views->length-1] != view) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct roots_view *prev_view = views->items[views->length-2];
|
||||
struct roots_input *input = prev_view->desktop->server->input;
|
||||
set_view_focus(input, prev_view->desktop, prev_view);
|
||||
*/
|
||||
}
|
||||
|
||||
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
|
||||
|
|
|
@ -123,17 +123,58 @@ static void keyboard_keysym_release(struct roots_keyboard *keyboard,
|
|||
keyboard->pressed_keysyms[i] = XKB_KEY_NoSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_key *event) {
|
||||
uint32_t keycode = event->keycode + 8;
|
||||
/*
|
||||
* Process keypresses from the keyboard as xkb sees them.
|
||||
*
|
||||
* This uses the xkb keysyms translation based on pressed modifiers and clears
|
||||
* the consumed modifiers from the list of modifiers passed to keybind
|
||||
* detection.
|
||||
*
|
||||
* (On US layout) this will trigger: [Alt]+[at]
|
||||
*/
|
||||
static bool keyboard_keysyms_xkb(struct roots_keyboard *keyboard,
|
||||
uint32_t keycode, enum wlr_key_state state) {
|
||||
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
|
||||
const xkb_keysym_t *syms;
|
||||
int syms_len = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
|
||||
keycode, &syms);
|
||||
uint32_t consumed = xkb_state_key_get_consumed_mods2(
|
||||
keyboard->device->keyboard->xkb_state, keycode, XKB_CONSUMED_MODE_XKB);
|
||||
|
||||
modifiers = modifiers & ~consumed;
|
||||
|
||||
bool handled = false;
|
||||
for (int i = 0; i < syms_len; i++) {
|
||||
if (event->state == WLR_KEY_PRESSED) {
|
||||
if (state) {
|
||||
bool keysym_handled =
|
||||
keyboard_keysym_press(keyboard, syms[i]);
|
||||
handled = handled || keysym_handled;
|
||||
} else { // WLR_KEY_RELEASED
|
||||
keyboard_keysym_release(keyboard, syms[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
/*
|
||||
* Process keypresses from the keyboard as if modifiers didn't change keysyms.
|
||||
*
|
||||
* This avoids the xkb keysym translation based on modifiers considered pressed
|
||||
* in the state and uses the list of modifiers saved on the rootston side.
|
||||
*
|
||||
* This will trigger the keybind: [Alt]+[Shift]+2
|
||||
*/
|
||||
static bool keyboard_keysyms_simple(struct roots_keyboard *keyboard,
|
||||
uint32_t keycode, enum wlr_key_state state) {
|
||||
const xkb_keysym_t *syms;
|
||||
xkb_layout_index_t layout_index = xkb_state_key_get_layout(
|
||||
keyboard->device->keyboard->xkb_state, keycode);
|
||||
int syms_len = xkb_keymap_key_get_syms_by_level(
|
||||
keyboard->device->keyboard->keymap, keycode, layout_index, 0, &syms);
|
||||
|
||||
bool handled = false;
|
||||
for (int i = 0; i < syms_len; i++) {
|
||||
if (state) {
|
||||
bool keysym_handled = keyboard_keysym_press(keyboard, syms[i]);
|
||||
handled = handled || keysym_handled;
|
||||
} else { // WLR_KEY_RELEASED
|
||||
|
@ -141,6 +182,21 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
|||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_key *event) {
|
||||
uint32_t keycode = event->keycode + 8;
|
||||
|
||||
bool handled = keyboard_keysyms_xkb(keyboard, keycode, event->state);
|
||||
|
||||
if (!handled) {
|
||||
bool key_handled = keyboard_keysyms_simple(keyboard, keycode,
|
||||
event->state);
|
||||
handled = handled || key_handled;
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
|
||||
wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
|
||||
|
@ -151,13 +207,8 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
|||
void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard,
|
||||
struct wlr_event_keyboard_modifiers *event) {
|
||||
struct wlr_seat *seat = r_keyboard->seat->seat;
|
||||
struct wlr_keyboard *keyboard = r_keyboard->device->keyboard;
|
||||
wlr_seat_set_keyboard(seat, r_keyboard->device);
|
||||
wlr_seat_keyboard_notify_modifiers(seat,
|
||||
keyboard->modifiers.depressed,
|
||||
keyboard->modifiers.latched,
|
||||
keyboard->modifiers.locked,
|
||||
keyboard->modifiers.group);
|
||||
wlr_seat_keyboard_notify_modifiers(seat);
|
||||
}
|
||||
|
||||
static void keyboard_config_merge(struct keyboard_config *config,
|
||||
|
|
|
@ -531,9 +531,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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group) {
|
||||
static void keyboard_drag_modifiers(struct wlr_seat_keyboard_grab *grab) {
|
||||
//struct wlr_keyboard *keyboard = grab->seat->keyboard_state.keyboard;
|
||||
// TODO change the dnd action based on what modifier is pressed on the
|
||||
// keyboard
|
||||
}
|
||||
|
|
|
@ -43,6 +43,30 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) {
|
|||
keyboard->modifiers.group = group;
|
||||
}
|
||||
|
||||
static void keyboard_key_update(struct wlr_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_key *event) {
|
||||
bool found = false;
|
||||
size_t i = 0;
|
||||
for (; i < WLR_KEYBOARD_KEYS_CAP; ++i) {
|
||||
if (keyboard->keycodes[i] == event->keycode) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event->state == WLR_KEY_PRESSED && !found) {
|
||||
for (size_t i = 0; i < WLR_KEYBOARD_KEYS_CAP; ++i) {
|
||||
if (keyboard->keycodes[i] == 0) {
|
||||
keyboard->keycodes[i] = event->keycode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event->state == WLR_KEY_RELEASED && found) {
|
||||
keyboard->keycodes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_modifiers *event) {
|
||||
if (!keyboard->xkb_state) {
|
||||
|
@ -67,6 +91,7 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,
|
|||
}
|
||||
keyboard_led_update(keyboard);
|
||||
keyboard_modifier_update(keyboard);
|
||||
keyboard_key_update(keyboard, event);
|
||||
wl_signal_emit(&keyboard->events.key, event);
|
||||
}
|
||||
|
||||
|
|
|
@ -284,11 +284,8 @@ 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group) {
|
||||
wlr_seat_keyboard_send_modifiers(grab->seat, mods_depressed,
|
||||
mods_latched, mods_locked, group);
|
||||
static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab) {
|
||||
wlr_seat_keyboard_send_modifiers(grab->seat);
|
||||
}
|
||||
|
||||
static void default_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) {
|
||||
|
@ -708,24 +705,26 @@ 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group) {
|
||||
void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat) {
|
||||
struct wlr_seat_client *client = seat->keyboard_state.focused_client;
|
||||
if (!client || !client->keyboard) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t serial = wl_display_next_serial(seat->display);
|
||||
struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard;
|
||||
if (!keyboard) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t serial = wl_display_next_serial(seat->display);
|
||||
wl_keyboard_send_modifiers(client->keyboard, serial,
|
||||
mods_depressed, mods_latched,
|
||||
mods_locked, group);
|
||||
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
||||
keyboard->modifiers.locked, keyboard->modifiers.group);
|
||||
}
|
||||
|
||||
void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
|
||||
void wlr_seat_keyboard_enter(struct wlr_seat *seat,
|
||||
struct wlr_surface *surface) {
|
||||
if (wlr_seat->keyboard_state.focused_surface == surface) {
|
||||
if (seat->keyboard_state.focused_surface == surface) {
|
||||
// this surface already got an enter notify
|
||||
return;
|
||||
}
|
||||
|
@ -734,71 +733,79 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
|
|||
|
||||
if (surface) {
|
||||
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
|
||||
client = wlr_seat_client_for_wl_client(wlr_seat, wl_client);
|
||||
client = wlr_seat_client_for_wl_client(seat, wl_client);
|
||||
}
|
||||
|
||||
struct wlr_seat_client *focused_client =
|
||||
wlr_seat->keyboard_state.focused_client;
|
||||
seat->keyboard_state.focused_client;
|
||||
struct wlr_surface *focused_surface =
|
||||
wlr_seat->keyboard_state.focused_surface;
|
||||
seat->keyboard_state.focused_surface;
|
||||
|
||||
// leave the previously entered surface
|
||||
if (focused_client && focused_client->keyboard && focused_surface) {
|
||||
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
||||
uint32_t serial = wl_display_next_serial(seat->display);
|
||||
wl_keyboard_send_leave(focused_client->keyboard, serial,
|
||||
focused_surface->resource);
|
||||
}
|
||||
|
||||
// enter the current surface
|
||||
if (client && client->keyboard) {
|
||||
// TODO: read the currently pressed keys out of the active keyboard and
|
||||
// put them in this array
|
||||
if (client && client->keyboard && seat->keyboard_state.keyboard) {
|
||||
struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard;
|
||||
|
||||
struct wl_array keys;
|
||||
wl_array_init(&keys);
|
||||
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
||||
size_t n = 0;
|
||||
for (size_t i = 0; i < WLR_KEYBOARD_KEYS_CAP; ++i) {
|
||||
if (keyboard->keycodes[i] != 0) {
|
||||
wl_array_add(&keys, sizeof(uint32_t));
|
||||
((uint32_t *)keys.data)[n] = keyboard->keycodes[i];
|
||||
n++;
|
||||
}
|
||||
}
|
||||
uint32_t serial = wl_display_next_serial(seat->display);
|
||||
wl_keyboard_send_enter(client->keyboard, serial,
|
||||
surface->resource, &keys);
|
||||
wl_array_release(&keys);
|
||||
|
||||
wlr_seat_keyboard_send_modifiers(seat);
|
||||
wlr_seat_client_send_selection(client);
|
||||
}
|
||||
|
||||
// reinitialize the focus destroy events
|
||||
wl_list_remove(&wlr_seat->keyboard_state.surface_destroy.link);
|
||||
wl_list_init(&wlr_seat->keyboard_state.surface_destroy.link);
|
||||
wl_list_remove(&wlr_seat->keyboard_state.resource_destroy.link);
|
||||
wl_list_init(&wlr_seat->keyboard_state.resource_destroy.link);
|
||||
wl_list_remove(&seat->keyboard_state.surface_destroy.link);
|
||||
wl_list_init(&seat->keyboard_state.surface_destroy.link);
|
||||
wl_list_remove(&seat->keyboard_state.resource_destroy.link);
|
||||
wl_list_init(&seat->keyboard_state.resource_destroy.link);
|
||||
if (surface) {
|
||||
wl_signal_add(&surface->events.destroy,
|
||||
&wlr_seat->keyboard_state.surface_destroy);
|
||||
&seat->keyboard_state.surface_destroy);
|
||||
wl_resource_add_destroy_listener(surface->resource,
|
||||
&wlr_seat->keyboard_state.resource_destroy);
|
||||
wlr_seat->keyboard_state.resource_destroy.notify =
|
||||
&seat->keyboard_state.resource_destroy);
|
||||
seat->keyboard_state.resource_destroy.notify =
|
||||
keyboard_resource_destroy_notify;
|
||||
wlr_seat->keyboard_state.surface_destroy.notify =
|
||||
seat->keyboard_state.surface_destroy.notify =
|
||||
keyboard_surface_destroy_notify;
|
||||
}
|
||||
|
||||
wlr_seat->keyboard_state.focused_client = client;
|
||||
wlr_seat->keyboard_state.focused_surface = surface;
|
||||
seat->keyboard_state.focused_client = client;
|
||||
seat->keyboard_state.focused_surface = surface;
|
||||
}
|
||||
|
||||
void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, struct
|
||||
void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, struct
|
||||
wlr_surface *surface) {
|
||||
struct wlr_seat_keyboard_grab *grab = wlr_seat->keyboard_state.grab;
|
||||
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
||||
grab->interface->enter(grab, surface);
|
||||
}
|
||||
|
||||
void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat) {
|
||||
void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) {
|
||||
struct wl_array keys;
|
||||
wl_array_init(&keys);
|
||||
wlr_seat_keyboard_enter(wlr_seat, NULL);
|
||||
wlr_seat_keyboard_enter(seat, NULL);
|
||||
}
|
||||
|
||||
void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group) {
|
||||
void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) {
|
||||
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
||||
grab->interface->modifiers(grab,
|
||||
mods_depressed, mods_latched, mods_locked, group);
|
||||
grab->interface->modifiers(grab);
|
||||
}
|
||||
|
||||
void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time,
|
||||
|
|
|
@ -111,11 +111,8 @@ 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,
|
||||
uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group) {
|
||||
wlr_seat_keyboard_send_modifiers(grab->seat, mods_depressed, mods_latched,
|
||||
mods_locked, group);
|
||||
static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab) {
|
||||
wlr_seat_keyboard_send_modifiers(grab->seat);
|
||||
}
|
||||
|
||||
static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) {
|
||||
|
|
Loading…
Reference in a new issue