diff --git a/src/core/linux/Wayland.zig b/src/core/linux/Wayland.zig index c3db2829..5305b9fb 100644 --- a/src/core/linux/Wayland.zig +++ b/src/core/linux/Wayland.zig @@ -4,6 +4,7 @@ const gpu = mach.gpu; const Linux = @import("../Linux.zig"); const Core = @import("../../Core.zig"); const InitOptions = Core.InitOptions; +const KeyEvent = Core.KeyEvent; const log = std.log.scoped(.mach); pub const Wayland = @This(); @@ -58,7 +59,6 @@ libwaylandclient: LibWaylandClient, // input stuff keyboard: ?*c.wl_keyboard = null, pointer: ?*c.wl_pointer = null, -input_state: Core.InputState, // keyboard stuff xkb_context: ?*c.xkb_context = null, @@ -91,7 +91,6 @@ pub fn init( .shift = false, .super = false, }, - .input_state = .{}, .modifier_indices = .{ // TODO: make sure these are always getting initialized, we don't want undefined behavior .control_index = undefined, .alt_index = undefined, @@ -481,16 +480,12 @@ const keyboard_listener = struct { _ = time; var wl = &linux.backend.wayland; - const key = toMachKey(scancode); const pressed = state == 1; - wl.input_state.keys.setValue(@intFromEnum(key), pressed); + const key_event = KeyEvent{ .key = toMachKey(scancode), .mods = wl.modifiers }; if (pressed) { - wl.state.pushEvent(Core.Event{ .key_press = .{ - .key = key, - .mods = wl.modifiers, - } }); + wl.state.pushEvent(.{ .key_press = key_event }); var keysyms: ?[*]c.xkb_keysym_t = undefined; //Get the keysym from the keycode (scancode + 8) @@ -505,10 +500,7 @@ const keyboard_listener = struct { } } } else { - wl.state.pushEvent(Core.Event{ .key_release = .{ - .key = key, - .mods = wl.modifiers, - } }); + wl.state.pushEvent(.{ .key_release = key_event }); } } @@ -638,7 +630,6 @@ const pointer_listener = struct { const y = c.wl_fixed_to_double(fixed_y); wl.state.pushEvent(.{ .mouse_motion = .{ .pos = .{ .x = x, .y = y } } }); - wl.input_state.mouse_position = .{ .x = x, .y = y }; } fn handlePointerButton(linux: *Linux, pointer: ?*c.struct_wl_pointer, serial: u32, time: u32, button: u32, state: u32) callconv(.C) void { @@ -649,20 +640,20 @@ const pointer_listener = struct { const mouse_button: Core.MouseButton = @enumFromInt(button - c.BTN_LEFT); const pressed = state == c.WL_POINTER_BUTTON_STATE_PRESSED; - - wl.input_state.mouse_buttons.setValue(@intFromEnum(mouse_button), pressed); + const x = wl.state.input_state.mouse_position.x; + const y = wl.state.input_state.mouse_position.y; if (pressed) { wl.state.pushEvent(Core.Event{ .mouse_press = .{ .button = mouse_button, .mods = wl.modifiers, - .pos = wl.input_state.mouse_position, + .pos = .{ .x = x, .y = y }, } }); } else { wl.state.pushEvent(Core.Event{ .mouse_release = .{ .button = mouse_button, .mods = wl.modifiers, - .pos = wl.input_state.mouse_position, + .pos = .{ .x = x, .y = y }, } }); } } diff --git a/src/core/linux/X11.zig b/src/core/linux/X11.zig index 4e686a0e..cd0da7a6 100644 --- a/src/core/linux/X11.zig +++ b/src/core/linux/X11.zig @@ -501,7 +501,6 @@ fn processEvent(x11: *X11, linux: *Linux, event: *c.XEvent) void { switch (event.type) { c.KeyPress => { - x11.state.input_state.keys.set(@intFromEnum(key_event.key)); x11.state.pushEvent(.{ .key_press = key_event }); const codepoint = x11.libxkbcommon.xkb_keysym_to_utf32(@truncate(keysym)); @@ -510,7 +509,6 @@ fn processEvent(x11: *X11, linux: *Linux, event: *c.XEvent) void { } }, c.KeyRelease => { - x11.state.input_state.keys.unset(@intFromEnum(key_event.key)); x11.state.pushEvent(.{ .key_release = key_event }); }, else => unreachable, @@ -536,7 +534,6 @@ fn processEvent(x11: *X11, linux: *Linux, event: *c.XEvent) void { .mods = toMachMods(event.xbutton.state), }; - x11.state.input_state.mouse_buttons.set(@intFromEnum(mouse_button.button)); x11.state.pushEvent(.{ .mouse_press = mouse_button }); }, c.ButtonRelease => { @@ -548,7 +545,6 @@ fn processEvent(x11: *X11, linux: *Linux, event: *c.XEvent) void { .mods = toMachMods(event.xbutton.state), }; - x11.state.input_state.mouse_buttons.unset(@intFromEnum(mouse_button.button)); x11.state.pushEvent(.{ .mouse_release = mouse_button }); }, c.ClientMessage => { @@ -578,13 +574,11 @@ fn processEvent(x11: *X11, linux: *Linux, event: *c.XEvent) void { c.EnterNotify => { const x: f32 = @floatFromInt(event.xcrossing.x); const y: f32 = @floatFromInt(event.xcrossing.y); - x11.state.input_state.mouse_position = .{ .x = x, .y = y }; x11.state.pushEvent(.{ .mouse_motion = .{ .pos = .{ .x = x, .y = y } } }); }, c.MotionNotify => { const x: f32 = @floatFromInt(event.xmotion.x); const y: f32 = @floatFromInt(event.xmotion.y); - x11.state.input_state.mouse_position = .{ .x = x, .y = y }; x11.state.pushEvent(.{ .mouse_motion = .{ .pos = .{ .x = x, .y = y } } }); }, c.ConfigureNotify => {