Unified · Split
| @@ -112,6 +112,58 @@ keyboard_enter (void *data, struct wl_keyboard *keyboard, uint32_t serial, struc · 111 unmodified lines | |||
| 112 | qunlock(&wl->clip.lk); | 112 | qunlock(&wl->clip.lk); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 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 | |||
| 115 | static void | 167 | static void |
| 116 | keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) | 168 | keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) |
| 117 | { | 169 | { |
| @@ -132,16 +184,35 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t · 14 unmodified lines | |||
| 132 | case XKB_KEY_Tab: | 184 | case XKB_KEY_Tab: |
| 133 | utf32 = '\t'; | 185 | utf32 = '\t'; |
| 134 | break; | 186 | 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; | ||
| 135 | default: | 199 | default: |
| 136 | utf32 = xkb_keysym_to_utf32(keysym); | 200 | utf32 = xkb_keysym_to_utf32(keysym); |
| 137 | break; | 201 | break; |
| 138 | } | 202 | } |
| 203 | if(utf32 == 0) | ||
| 204 | return; | ||
| 205 | |||
| 139 | if(xkb_state_mod_name_is_active(wl->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) | 206 | if(xkb_state_mod_name_is_active(wl->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) |
| 140 | if(utf32 >= 'a' && utf32 <= 'z') | 207 | if(utf32 >= 'a' && utf32 <= 'z') |
| 141 | utf32 -= ('a' - 1); | 208 | utf32 -= ('a' - 1); |
| 142 | if(utf32){ | 209 | |
| 143 | kbdkey(utf32, state); | 210 | kbdkey(utf32, state); |
| 144 | } | 211 | qlock(&repeatstate.lk); |
| 212 | repeatstate.active = state; | ||
| 213 | repeatstate.key = utf32; | ||
| 214 | qunlock(&repeatstate.lk); | ||
| 215 | wakeup(&repeatstate.z); | ||
| 145 | } | 216 | } |
| 146 | 217 | ||
| 147 | static void | 218 | static void |
| @@ -158,11 +229,12 @@ static const struct wl_callback_listener wl_surface_frame_listener = { · 10 unmodified lines | |||
| 158 | }; | 229 | }; |
| 159 | 230 | ||
| 160 | static struct wl_keyboard_listener keyboard_listener = { | 231 | static struct wl_keyboard_listener keyboard_listener = { |
| 161 | &keyboard_keymap, | 232 | .keymap = keyboard_keymap, |
| 162 | &keyboard_enter, | 233 | .enter = keyboard_enter, |
| 163 | &keyboard_leave, | 234 | .leave = keyboard_leave, |
| 164 | &keyboard_key, | 235 | .key = keyboard_key, |
| 165 | &keyboard_modifiers | 236 | .modifiers = keyboard_modifiers, |
| 237 | .repeat_info = keyboard_repeat_info, | ||
| 166 | }; | 238 | }; |
| 167 | 239 | ||
| 168 | enum{ | 240 | enum{ |
| @@ -229,6 +301,8 @@ pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, · 60 unmodified lines | |||
| 229 | 301 | ||
| 230 | wl = data; | 302 | wl = data; |
| 231 | wl->pointerserial = serial; | 303 | wl->pointerserial = serial; |
| 304 | if(wl->cursorsurface == nil) | ||
| 305 | return; | ||
| 232 | wl_pointer_set_cursor(wl->pointer, wl->pointerserial, wl->cursorsurface, 0, 0); | 306 | wl_pointer_set_cursor(wl->pointer, wl->pointerserial, wl->cursorsurface, 0, 0); |
| 233 | } | 307 | } |
| 234 | 308 | ||
| @@ -282,8 +356,15 @@ seat_handle_capabilities(void *data, struct wl_seat *seat, uint32_t capabilities · 47 unmodified lines | |||
| 282 | } | 356 | } |
| 283 | } | 357 | } |
| 284 | 358 | ||
| 359 | static void | ||
| 360 | seat_handle_name(void *data, struct wl_seat *seat, const char *name) | ||
| 361 | { | ||
| 362 | |||
| 363 | } | ||
| 364 | |||
| 285 | static const struct wl_seat_listener seat_listener = { | 365 | static const struct wl_seat_listener seat_listener = { |
| 286 | .capabilities = seat_handle_capabilities, | 366 | .capabilities = seat_handle_capabilities, |
| 367 | .name = seat_handle_name, | ||
| 287 | }; | 368 | }; |
| 288 | 369 | ||
| 289 | static void | 370 | static void |
| @@ -391,7 +472,7 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const cha · 101 unmodified lines | |||
| 391 | if(strcmp(interface, wl_shm_interface.name) == 0) { | 472 | if(strcmp(interface, wl_shm_interface.name) == 0) { |
| 392 | wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); | 473 | wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); |
| 393 | } else if(strcmp(interface, wl_seat_interface.name) == 0) { | 474 | } 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); |
| 395 | wl_seat_add_listener(wl->seat, &seat_listener, wl); | 476 | wl_seat_add_listener(wl->seat, &seat_listener, wl); |
| 396 | } else if(strcmp(interface, wl_compositor_interface.name) == 0) { | 477 | } else if(strcmp(interface, wl_compositor_interface.name) == 0) { |
| 397 | wl->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1); | 478 | wl->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1); |
| @@ -423,6 +504,13 @@ wlsetcb(Wlwin *wl) · 25 unmodified lines | |||
| 423 | struct wl_callback *cb; | 504 | struct wl_callback *cb; |
| 424 | struct zxdg_toplevel_decoration_v1 *deco; | 505 | struct zxdg_toplevel_decoration_v1 *deco; |
| 425 | 506 | ||
| 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 | |||
| 426 | registry = wl_display_get_registry(wl->display); | 514 | registry = wl_display_get_registry(wl->display); |
| 427 | wl_registry_add_listener(registry, ®istry_listener, wl); | 515 | wl_registry_add_listener(registry, ®istry_listener, wl); |
| 428 | wl_display_roundtrip(wl->display); | 516 | wl_display_roundtrip(wl->display); |