Remove superfluous .*.

I may be be slowly getting the hang of this language.
This commit is contained in:
Isaac Freund
2020-03-24 20:03:48 +01:00
parent e01a150f6d
commit 4872a68378
6 changed files with 60 additions and 56 deletions

View File

@ -6,6 +6,7 @@ const Seat = @import("seat.zig").Seat;
pub const Keyboard = struct {
seat: *Seat,
device: *c.wlr_input_device,
wlr_keyboard: *c.wlr_keyboard,
listen_modifiers: c.wl_listener,
listen_key: c.wl_listener,
@ -13,6 +14,7 @@ pub const Keyboard = struct {
pub fn init(self: *@This(), seat: *Seat, device: *c.wlr_input_device) !void {
self.seat = seat;
self.device = device;
self.wlr_keyboard = device.unnamed_37.keyboard;
// We need to prepare an XKB keymap and assign it to the keyboard. This
// assumes the defaults (e.g. layout = "us").
@ -35,17 +37,16 @@ pub const Keyboard = struct {
return error.CantCreateXkbKeymap;
defer c.xkb_keymap_unref(keymap);
var keyboard_device = self.device.unnamed_37.keyboard;
// TODO: handle failure after https://github.com/swaywm/wlroots/pull/2081
c.wlr_keyboard_set_keymap(keyboard_device, keymap);
c.wlr_keyboard_set_repeat_info(keyboard_device, 25, 600);
c.wlr_keyboard_set_keymap(self.wlr_keyboard, keymap);
c.wlr_keyboard_set_repeat_info(self.wlr_keyboard, 25, 600);
// Setup listeners for keyboard events
self.listen_modifiers.notify = handle_modifiers;
c.wl_signal_add(&keyboard_device.*.events.modifiers, &self.listen_modifiers);
c.wl_signal_add(&self.wlr_keyboard.events.modifiers, &self.listen_modifiers);
self.listen_key.notify = handle_key;
c.wl_signal_add(&keyboard_device.*.events.key, &self.listen_key);
c.wl_signal_add(&self.wlr_keyboard.events.key, &self.listen_key);
}
fn handle_modifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@ -57,10 +58,13 @@ pub 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.seat.wlr_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.seat.wlr_seat, &keyboard.*.device.*.unnamed_37.keyboard.*.modifiers);
c.wlr_seat_keyboard_notify_modifiers(
keyboard.seat.wlr_seat,
&keyboard.wlr_keyboard.modifiers,
);
}
fn handle_key(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@ -71,16 +75,16 @@ pub const Keyboard = struct {
@alignCast(@alignOf(*c.wlr_event_keyboard_key), data),
);
const keyboard_device = keyboard.device.unnamed_37.keyboard;
const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_37.keyboard;
// Translate libinput keycode -> xkbcommon
const keycode = event.keycode + 8;
// Get a list of keysyms based on the keymap for this keyboard
var syms: ?[*]c.xkb_keysym_t = undefined;
const nsyms = c.xkb_state_key_get_syms(keyboard_device.*.xkb_state, keycode, &syms);
const nsyms = c.xkb_state_key_get_syms(wlr_keyboard.xkb_state, keycode, &syms);
var handled = false;
const modifiers = c.wlr_keyboard_get_modifiers(keyboard_device);
const modifiers = c.wlr_keyboard_get_modifiers(wlr_keyboard);
if (modifiers & @intCast(u32, c.WLR_MODIFIER_LOGO) != 0 and
event.state == c.enum_wlr_key_state.WLR_KEY_PRESSED)
{