History

wayland: handle arrow keys and key repeat

Jacob Moody committed 5 years ago

Commit dd03ed11 parent 4d482df1 file · +97 −9Browse files

Unified · Split

gui-wl/wl-cb.c+97−9
@@ -112,6 +112,58 @@ keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struc · 111 unmodified lines
112112 qunlock(&wl->clip.lk);
113113 }
114114
115+static struct {
116+ Rendez z;
117+ QLock lk;
118+ int active;
119+ int32_t key;
120+ int32_t rate;
121+ int32_t delay;
122+} repeatstate;
123+
124+static int
125+isactive(void *arg)
126+{
127+ return repeatstate.active;
128+}
129+
130+void
131+repeatproc(void*)
132+{
133+ int ms;
134+ int32_t key;
135+
136+ for(;;){
137+ ksleep(&repeatstate.z, isactive, 0);
138+ qlock(&repeatstate.lk);
139+ key = repeatstate.key;
140+ qunlock(&repeatstate.lk);
141+ osmsleep(repeatstate.delay);
142+
143+repeat:
144+ qlock(&repeatstate.lk);
145+ if(repeatstate.active == 0 || key != repeatstate.key){
146+ qunlock(&repeatstate.lk);
147+ continue;
148+ }
149+ ms = 1000/repeatstate.rate;
150+ kbdkey(repeatstate.key, 0);
151+ kbdkey(repeatstate.key, 1);
152+ qunlock(&repeatstate.lk);
153+ osmsleep(ms);
154+ goto repeat;
155+ }
156+}
157+
158+static void
159+keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay)
160+{
161+ qlock(&repeatstate.lk);
162+ repeatstate.rate = rate;
163+ repeatstate.delay = delay;
164+ qunlock(&repeatstate.lk);
165+}
166+
115167 static void
116168 keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
117169 {
@@ -132,16 +184,35 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t · 14 unmodified lines
132184 case XKB_KEY_Tab:
133185 utf32 = '\t';
134186 break;
187+ case XKB_KEY_Up:
188+ utf32 = Kup;
189+ break;
190+ case XKB_KEY_Down:
191+ utf32 = Kdown;
192+ break;
193+ case XKB_KEY_Left:
194+ utf32 = Kleft;
195+ break;
196+ case XKB_KEY_Right:
197+ utf32 = Kright;
198+ break;
135199 default:
136200 utf32 = xkb_keysym_to_utf32(keysym);
137201 break;
138202 }
203+ if(utf32 == 0)
204+ return;
205+
139206 if(xkb_state_mod_name_is_active(wl->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0)
140207 if(utf32 >= 'a' && utf32 <= 'z')
141208 utf32 -= ('a' - 1);
142− if(utf32){
143− kbdkey(utf32, state);
144− }
209+
210+ kbdkey(utf32, state);
211+ qlock(&repeatstate.lk);
212+ repeatstate.active = state;
213+ repeatstate.key = utf32;
214+ qunlock(&repeatstate.lk);
215+ wakeup(&repeatstate.z);
145216 }
146217
147218 static void
@@ -158,11 +229,12 @@ static const struct wl_callback_listener wl_surface_frame_listener = { · 10 unmodified lines
158229 };
159230
160231 static struct wl_keyboard_listener keyboard_listener = {
161− &keyboard_keymap,
162− &keyboard_enter,
163− &keyboard_leave,
164− &keyboard_key,
165− &keyboard_modifiers
232+ .keymap = keyboard_keymap,
233+ .enter = keyboard_enter,
234+ .leave = keyboard_leave,
235+ .key = keyboard_key,
236+ .modifiers = keyboard_modifiers,
237+ .repeat_info = keyboard_repeat_info,
166238 };
167239
168240 enum{
@@ -229,6 +301,8 @@ pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, · 60 unmodified lines
229301
230302 wl = data;
231303 wl->pointerserial = serial;
304+ if(wl->cursorsurface == nil)
305+ return;
232306 wl_pointer_set_cursor(wl->pointer, wl->pointerserial, wl->cursorsurface, 0, 0);
233307 }
234308
@@ -282,8 +356,15 @@ seat_handle_capabilities(void *data, struct wl_seat *seat, uint32_t capabilities · 47 unmodified lines
282356 }
283357 }
284358
359+static void
360+seat_handle_name(void *data, struct wl_seat *seat, const char *name)
361+{
362+
363+}
364+
285365 static const struct wl_seat_listener seat_listener = {
286366 .capabilities = seat_handle_capabilities,
367+ .name = seat_handle_name,
287368 };
288369
289370 static void
@@ -391,7 +472,7 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const cha · 101 unmodified lines
391472 if(strcmp(interface, wl_shm_interface.name) == 0) {
392473 wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
393474 } else if(strcmp(interface, wl_seat_interface.name) == 0) {
394− wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
475+ wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, 4);
395476 wl_seat_add_listener(wl->seat, &seat_listener, wl);
396477 } else if(strcmp(interface, wl_compositor_interface.name) == 0) {
397478 wl->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
@@ -423,6 +504,13 @@ wlsetcb(Wlwin *wl) · 25 unmodified lines
423504 struct wl_callback *cb;
424505 struct zxdg_toplevel_decoration_v1 *deco;
425506
507+ //Wayland doesn't do keyboard repeat, but also may
508+ //not tell us what the user would like, so we
509+ //pick some sane defaults.
510+ repeatstate.delay = 200;
511+ repeatstate.rate = 20;
512+ kproc("keyboard repeat", repeatproc, 0);
513+
426514 registry = wl_display_get_registry(wl->display);
427515 wl_registry_add_listener(registry, &registry_listener, wl);
428516 wl_display_roundtrip(wl->display);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t