Skip to content

Commit

Permalink
create a wlr_keyboard_group for virtual keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
sevz17 committed Dec 26, 2023
1 parent 23fd312 commit 1f0afcf
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions dwl.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ static struct wlr_session_lock_v1 *cur_lock;
static struct wl_listener lock_listener = {.notify = locksession};

static struct wlr_seat *seat;
static KeyboardGroup kb_group;
static KeyboardGroup kb_group = {0};
static KeyboardGroup vkb_group = {0};
static struct wlr_surface *held_grab;
static unsigned int cursor_mode;
static Client *grabc;
Expand Down Expand Up @@ -643,6 +644,7 @@ cleanup(void)

/* Remove event source that use the dpy event loop before destroying dpy */
wl_event_source_remove(kb_group.key_repeat_source);
wl_event_source_remove(vkb_group.key_repeat_source);

wl_display_destroy(dpy);
/* Destroy after the wayland display (when the monitors are already destroyed)
Expand Down Expand Up @@ -1409,6 +1411,7 @@ keypress(struct wl_listener *listener, void *data)
if (handled)
return;

wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Pass unhandled keycodes along to the client. */
wlr_seat_keyboard_notify_key(seat, event->time_msec,
event->keycode, event->state);
Expand All @@ -1421,6 +1424,7 @@ keypressmod(struct wl_listener *listener, void *data)
* pressed. We simply communicate this to the client. */
KeyboardGroup *group = wl_container_of(listener, group, modifiers);

wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Send modifiers to the client. */
wlr_seat_keyboard_notify_modifiers(seat,
&group->wlr_group->keyboard.modifiers);
Expand Down Expand Up @@ -2338,24 +2342,37 @@ setup(void)
kb_group.wlr_group = wlr_keyboard_group_create();
kb_group.wlr_group->data = &kb_group;

/*
* Virtual keyboards need to be in a different group
* https://codeberg.org/dwl/dwl/issues/554
*/
vkb_group.wlr_group = wlr_keyboard_group_create();
vkb_group.wlr_group->data = &vkb_group;

/* Prepare an XKB keymap and assign it to the keyboard group. */
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!(keymap = xkb_keymap_new_from_names(context, &xkb_rules,
XKB_KEYMAP_COMPILE_NO_FLAGS)))
die("failed to compile keymap");

wlr_keyboard_set_keymap(&kb_group.wlr_group->keyboard, keymap);
wlr_keyboard_set_keymap(&vkb_group.wlr_group->keyboard, keymap);
xkb_keymap_unref(keymap);
xkb_context_unref(context);

wlr_keyboard_set_repeat_info(&kb_group.wlr_group->keyboard, repeat_rate, repeat_delay);
wlr_keyboard_set_repeat_info(&vkb_group.wlr_group->keyboard, repeat_rate, repeat_delay);

/* Set up listeners for keyboard events */
LISTEN(&kb_group.wlr_group->keyboard.events.key, &kb_group.key, keypress);
LISTEN(&kb_group.wlr_group->keyboard.events.modifiers, &kb_group.modifiers, keypressmod);
LISTEN(&vkb_group.wlr_group->keyboard.events.key, &vkb_group.key, keypress);
LISTEN(&vkb_group.wlr_group->keyboard.events.modifiers, &vkb_group.modifiers, keypressmod);

kb_group.key_repeat_source = wl_event_loop_add_timer(
wl_display_get_event_loop(dpy), keyrepeat, &kb_group);
vkb_group.key_repeat_source = wl_event_loop_add_timer(
wl_display_get_event_loop(dpy), keyrepeat, &vkb_group);

/* A seat can only have one keyboard, but this is a limitation of the
* Wayland protocol - not wlroots. We assign all connected keyboards to the
Expand Down Expand Up @@ -2697,7 +2714,12 @@ void
virtualkeyboard(struct wl_listener *listener, void *data)
{
struct wlr_virtual_keyboard_v1 *keyboard = data;
createkeyboard(&keyboard->keyboard);
/* Set the keymap to match the group keymap */
wlr_keyboard_set_keymap(&keyboard->keyboard, vkb_group.wlr_group->keyboard.keymap);
wlr_keyboard_set_repeat_info(&keyboard->keyboard, repeat_rate, repeat_delay);

/* Add the new keyboard to the group */
wlr_keyboard_group_add_keyboard(vkb_group.wlr_group, &keyboard->keyboard);
}

Monitor *
Expand Down

0 comments on commit 1f0afcf

Please sign in to comment.