diff options
Diffstat (limited to 'src/keyboard.zig')
| -rw-r--r-- | src/keyboard.zig | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/keyboard.zig b/src/keyboard.zig index e769ac0..7e201b4 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -1,7 +1,9 @@ const std = @import("std"); const c = @import("c.zig").c; -const Keyboard = struct { +const Seat = @import("seat.zig").Seat; + +pub const Keyboard = struct { seat: *Seat, device: *c.wlr_input_device, @@ -35,7 +37,7 @@ const Keyboard = struct { const context = c.xkb_context_new(c.enum_xkb_context_flags.XKB_CONTEXT_NO_FLAGS); defer c.xkb_context_unref(context); - const keymap = man_c.xkb_map_new_from_names( + const keymap = c.xkb_keymap_new_from_names( context, &rules, c.enum_xkb_keymap_compile_flags.XKB_KEYMAP_COMPILE_NO_FLAGS, @@ -47,8 +49,8 @@ const Keyboard = struct { c.wlr_keyboard_set_repeat_info(keyboard_device, 25, 600); // Setup listeners for keyboard events - c.wl_signal_add(&keyboard_device.*.events.modifiers, &keyboard.*.listen_modifiers); - c.wl_signal_add(&keyboard_device.*.events.key, &keyboard.*.listen_key); + c.wl_signal_add(&keyboard_device.*.events.modifiers, &keyboard.listen_modifiers); + c.wl_signal_add(&keyboard_device.*.events.key, &keyboard.listen_key); return keyboard; } @@ -62,10 +64,10 @@ const Keyboard = struct { // Wayland protocol - not wlroots. We assign all connected keyboards to the // same seat. You can swap out the underlying wlr_keyboard like this and // wlr_seat handles this transparently. - c.wlr_seat_set_keyboard(keyboard.*.server.*.seat, keyboard.*.device); + c.wlr_seat_set_keyboard(keyboard.seat.wlr_seat, keyboard.*.device); // Send modifiers to the client. - c.wlr_seat_keyboard_notify_modifiers(keyboard.*.server.*.seat, &keyboard.*.device.*.unnamed_37.keyboard.*.modifiers); + c.wlr_seat_keyboard_notify_modifiers(keyboard.seat.wlr_seat, &keyboard.*.device.*.unnamed_37.keyboard.*.modifiers); } fn handle_key(listener: [*c]c.wl_listener, data: ?*c_void) callconv(.C) void { @@ -76,26 +78,24 @@ const Keyboard = struct { @alignCast(@alignOf(*c.wlr_event_keyboard_key), data), ); - const server = keyboard.*.server; - const seat = server.*.seat; - const keyboard_device = keyboard.*.device.*.unnamed_37.keyboard; + const keyboard_device = keyboard.device.unnamed_37.keyboard; // Translate libinput keycode -> xkbcommon - const keycode = event.*.keycode + 8; + const keycode = event.keycode + 8; // Get a list of keysyms based on the keymap for this keyboard - var syms: *c.xkb_keysym_t = undefined; + var syms: ?[*]c.xkb_keysym_t = undefined; const nsyms = c.xkb_state_key_get_syms(keyboard_device.*.xkb_state, keycode, &syms); var handled = false; const modifiers = c.wlr_keyboard_get_modifiers(keyboard_device); if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and - event.*.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) + event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED) { // If mod is held down and this button was _pressed_, we attempt to // process it as a compositor keybinding. var i: usize = 0; while (i < nsyms) { - handled = keyboard.seat.server.handle_keybinding(syms[i]); + handled = keyboard.seat.server.handle_keybinding(syms.?[i]); if (handled) { break; } @@ -105,12 +105,13 @@ const Keyboard = struct { if (!handled) { // Otherwise, we pass it along to the client. - c.wlr_seat_set_keyboard(seat, keyboard.*.device); + const wlr_seat = keyboard.seat.wlr_seat; + c.wlr_seat_set_keyboard(wlr_seat, keyboard.device); c.wlr_seat_keyboard_notify_key( - seat, - event.*.time_msec, - event.*.keycode, - @intCast(u32, @enumToInt(event.*.state)), + wlr_seat, + event.time_msec, + event.keycode, + @intCast(u32, @enumToInt(event.state)), ); } } |
