From 24d433333b5a28f5e484dfdc724262992eb67e91 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 May 2025 10:44:49 -0700 Subject: [PATCH] apprt/glfw: builds --- src/Surface.zig | 17 +++-- src/apprt/glfw.zig | 142 +++++++++++++++++++------------------- src/cli/list_keybinds.zig | 8 +-- src/input/key.zig | 16 ++--- 4 files changed, 93 insertions(+), 90 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 0d4c9d984..e173d2d8b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -1895,12 +1895,12 @@ pub fn keyCallback( // if we didn't have a previous event and this is a release // event then we just want to set it to null. const prev = self.pressed_key orelse break :event null; - if (prev.key == copy.key) copy.key = .invalid; + if (prev.key == copy.key) copy.key = .unidentified; } // If our key is invalid and we have no mods, then we're done! // This helps catch the state that we naturally released all keys. - if (copy.key == .invalid and copy.mods.empty()) break :event null; + if (copy.key == .unidentified and copy.mods.empty()) break :event null; break :event copy; }; @@ -2295,7 +2295,7 @@ pub fn focusCallback(self: *Surface, focused: bool) !void { pressed_key.action = .release; // Release the full key first - if (pressed_key.key != .invalid) { + if (pressed_key.key != .unidentified) { assert(self.keyCallback(pressed_key) catch |err| err: { log.warn("error releasing key on focus loss err={}", .{err}); break :err .ignored; @@ -2315,8 +2315,15 @@ pub fn focusCallback(self: *Surface, focused: bool) !void { if (@field(pressed_key.mods, key)) { @field(pressed_key.mods, key) = false; inline for (&.{ "right", "left" }) |side| { - const keyname = if (comptime std.mem.eql(u8, key, "ctrl")) "control" else key; - pressed_key.key = @field(input.Key, side ++ "_" ++ keyname); + const keyname = comptime keyname: { + break :keyname if (std.mem.eql(u8, key, "ctrl")) + "control" + else if (std.mem.eql(u8, key, "super")) + "meta" + else + key; + }; + pressed_key.key = @field(input.Key, keyname ++ "_" ++ side); if (pressed_key.key != original_key) { assert(self.keyCallback(pressed_key) catch |err| err: { log.warn("error releasing key on focus loss err={}", .{err}); diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 9d1c8a6b5..763933b91 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -966,46 +966,46 @@ pub const Surface = struct { .repeat => .repeat, }; const key: input.Key = switch (glfw_key) { - .a => .a, - .b => .b, - .c => .c, - .d => .d, - .e => .e, - .f => .f, - .g => .g, - .h => .h, - .i => .i, - .j => .j, - .k => .k, - .l => .l, - .m => .m, - .n => .n, - .o => .o, - .p => .p, - .q => .q, - .r => .r, - .s => .s, - .t => .t, - .u => .u, - .v => .v, - .w => .w, - .x => .x, - .y => .y, - .z => .z, - .zero => .zero, - .one => .one, - .two => .two, - .three => .three, - .four => .four, - .five => .five, - .six => .six, - .seven => .seven, - .eight => .eight, - .nine => .nine, - .up => .up, - .down => .down, - .right => .right, - .left => .left, + .a => .key_a, + .b => .key_b, + .c => .key_c, + .d => .key_d, + .e => .key_e, + .f => .key_f, + .g => .key_g, + .h => .key_h, + .i => .key_i, + .j => .key_j, + .k => .key_k, + .l => .key_l, + .m => .key_m, + .n => .key_n, + .o => .key_o, + .p => .key_p, + .q => .key_q, + .r => .key_r, + .s => .key_s, + .t => .key_t, + .u => .key_u, + .v => .key_v, + .w => .key_w, + .x => .key_x, + .y => .key_y, + .z => .key_z, + .zero => .digit_0, + .one => .digit_1, + .two => .digit_2, + .three => .digit_3, + .four => .digit_4, + .five => .digit_5, + .six => .digit_6, + .seven => .digit_7, + .eight => .digit_8, + .nine => .digit_9, + .up => .arrow_up, + .down => .arrow_down, + .right => .arrow_right, + .left => .arrow_left, .home => .home, .end => .end, .page_up => .page_up, @@ -1036,34 +1036,34 @@ pub const Surface = struct { .F23 => .f23, .F24 => .f24, .F25 => .f25, - .kp_0 => .kp_0, - .kp_1 => .kp_1, - .kp_2 => .kp_2, - .kp_3 => .kp_3, - .kp_4 => .kp_4, - .kp_5 => .kp_5, - .kp_6 => .kp_6, - .kp_7 => .kp_7, - .kp_8 => .kp_8, - .kp_9 => .kp_9, - .kp_decimal => .kp_decimal, - .kp_divide => .kp_divide, - .kp_multiply => .kp_multiply, - .kp_subtract => .kp_subtract, - .kp_add => .kp_add, - .kp_enter => .kp_enter, - .kp_equal => .kp_equal, - .grave_accent => .grave_accent, + .kp_0 => .numpad_0, + .kp_1 => .numpad_1, + .kp_2 => .numpad_2, + .kp_3 => .numpad_3, + .kp_4 => .numpad_4, + .kp_5 => .numpad_5, + .kp_6 => .numpad_6, + .kp_7 => .numpad_7, + .kp_8 => .numpad_8, + .kp_9 => .numpad_9, + .kp_decimal => .numpad_decimal, + .kp_divide => .numpad_divide, + .kp_multiply => .numpad_multiply, + .kp_subtract => .numpad_subtract, + .kp_add => .numpad_add, + .kp_enter => .numpad_enter, + .kp_equal => .numpad_equal, + .grave_accent => .backquote, .minus => .minus, .equal => .equal, .space => .space, .semicolon => .semicolon, - .apostrophe => .apostrophe, + .apostrophe => .quote, .comma => .comma, .period => .period, .slash => .slash, - .left_bracket => .left_bracket, - .right_bracket => .right_bracket, + .left_bracket => .bracket_left, + .right_bracket => .bracket_right, .backslash => .backslash, .enter => .enter, .tab => .tab, @@ -1075,20 +1075,20 @@ pub const Surface = struct { .num_lock => .num_lock, .print_screen => .print_screen, .pause => .pause, - .left_shift => .left_shift, - .left_control => .left_control, - .left_alt => .left_alt, - .left_super => .left_super, - .right_shift => .right_shift, - .right_control => .right_control, - .right_alt => .right_alt, - .right_super => .right_super, + .left_shift => .shift_left, + .left_control => .control_left, + .left_alt => .alt_left, + .left_super => .meta_left, + .right_shift => .shift_right, + .right_control => .control_right, + .right_alt => .alt_right, + .right_super => .meta_right, + .menu => .context_menu, - .menu, .world_1, .world_2, .unknown, - => .invalid, + => .unidentified, }; // This is a hack for GLFW. We require our apprts to send both diff --git a/src/cli/list_keybinds.zig b/src/cli/list_keybinds.zig index 6cd989201..f84d540c3 100644 --- a/src/cli/list_keybinds.zig +++ b/src/cli/list_keybinds.zig @@ -155,14 +155,12 @@ const ChordBinding = struct { while (l_trigger != null and r_trigger != null) { const lhs_key: c_int = blk: { switch (l_trigger.?.data.key) { - .translated => |key| break :blk @intFromEnum(key), .physical => |key| break :blk @intFromEnum(key), .unicode => |key| break :blk @intCast(key), } }; const rhs_key: c_int = blk: { switch (r_trigger.?.data.key) { - .translated => |key| break :blk @intFromEnum(key), .physical => |key| break :blk @intFromEnum(key), .unicode => |key| break :blk @intCast(key), } @@ -254,8 +252,7 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 { result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); } const key = switch (trigger.data.key) { - .translated => |k| try std.fmt.allocPrint(alloc, "{s}", .{@tagName(k)}), - .physical => |k| try std.fmt.allocPrint(alloc, "physical:{s}", .{@tagName(k)}), + .physical => |k| try std.fmt.allocPrint(alloc, "{s}", .{@tagName(k)}), .unicode => |c| try std.fmt.allocPrint(alloc, "{u}", .{c}), }; result = win.printSegment(.{ .text = key }, .{ .col_offset = result.col }); @@ -297,8 +294,7 @@ fn iterateBindings(alloc: Allocator, iter: anytype, win: *const vaxis.Window) !s if (t.mods.shift) try std.fmt.format(buf.writer(), "shift + ", .{}); switch (t.key) { - .translated => |k| try std.fmt.format(buf.writer(), "{s}", .{@tagName(k)}), - .physical => |k| try std.fmt.format(buf.writer(), "physical:{s}", .{@tagName(k)}), + .physical => |k| try std.fmt.format(buf.writer(), "{s}", .{@tagName(k)}), .unicode => |c| try std.fmt.format(buf.writer(), "{u}", .{c}), } diff --git a/src/input/key.zig b/src/input/key.zig index 0609108a1..b39c5e5d3 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -573,14 +573,14 @@ pub const Key = enum(c_int) { /// True if this key is a modifier. pub fn modifier(self: Key) bool { return switch (self) { - .left_shift, - .left_control, - .left_alt, - .left_super, - .right_shift, - .right_control, - .right_alt, - .right_super, + .shift_left, + .control_left, + .alt_left, + .meta_left, + .shift_right, + .control_right, + .alt_right, + .meta_right, => true, else => false,