Make Keyboard a toplevel struct

This commit is contained in:
Isaac Freund 2020-05-02 16:48:09 +02:00
parent 97d395dbfc
commit ed98e8fe1a
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
2 changed files with 138 additions and 139 deletions

View file

@ -1,20 +1,20 @@
const Self = @This();
const std = @import("std");
const c = @import("c.zig");
const Log = @import("log.zig").Log;
const Seat = @import("seat.zig");
pub const Keyboard = struct {
const Self = @This();
seat: *Seat,
wlr_input_device: *c.wlr_input_device,
wlr_keyboard: *c.wlr_keyboard,
seat: *Seat,
wlr_input_device: *c.wlr_input_device,
wlr_keyboard: *c.wlr_keyboard,
listen_key: c.wl_listener,
listen_modifiers: c.wl_listener,
listen_key: c.wl_listener,
listen_modifiers: c.wl_listener,
pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !void {
pub fn init(self: *Self, seat: *Seat, wlr_input_device: *c.wlr_input_device) !void {
self.seat = seat;
self.wlr_input_device = wlr_input_device;
self.wlr_keyboard = @field(wlr_input_device, c.wlr_input_device_union).keyboard;
@ -50,9 +50,9 @@ pub const Keyboard = struct {
self.listen_modifiers.notify = handleModifiers;
c.wl_signal_add(&self.wlr_keyboard.events.modifiers, &self.listen_modifiers);
}
}
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
fn handleKey(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is raised when a key is pressed or released.
const self = @fieldParentPtr(Self, "listen_key", listener.?);
const event = @ptrCast(
@ -124,9 +124,9 @@ pub const Keyboard = struct {
@intCast(u32, @enumToInt(event.state)),
);
}
}
}
fn handleModifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
fn handleModifiers(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is raised when a modifier key, such as shift or alt, is
// pressed. We simply communicate this to the client. */
const self = @fieldParentPtr(Self, "listen_modifiers", listener.?);
@ -142,11 +142,11 @@ pub const Keyboard = struct {
self.seat.wlr_seat,
&self.wlr_keyboard.modifiers,
);
}
}
/// Handle any builtin, harcoded compsitor bindings such as VT switching.
/// Returns true if the keysym was handled.
fn handleBuiltinKeybind(self: Self, keysym: c.xkb_keysym_t) bool {
/// Handle any builtin, harcoded compsitor bindings such as VT switching.
/// Returns true if the keysym was handled.
fn handleBuiltinKeybind(self: Self, keysym: c.xkb_keysym_t) bool {
if (keysym >= c.XKB_KEY_XF86Switch_VT_1 and keysym <= c.XKB_KEY_XF86Switch_VT_12) {
Log.Debug.log("Switch VT keysym received", .{});
const wlr_backend = self.seat.input_manager.server.wlr_backend;
@ -160,5 +160,4 @@ pub const Keyboard = struct {
return true;
}
return false;
}
};
}

View file

@ -5,7 +5,7 @@ const std = @import("std");
const Cursor = @import("cursor.zig");
const InputManager = @import("input_manager.zig");
const Keyboard = @import("keyboard.zig").Keyboard;
const Keyboard = @import("keyboard.zig");
const LayerSurface = @import("layer_surface.zig");
const Output = @import("output.zig");
const View = @import("view.zig");