From abd08e487fce53227c8976ebb98acbbc2072a08b Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Mon, 4 Mar 2024 15:31:54 +0000 Subject: [PATCH] Seems we just need to remove min_keycode from press.detail --- src/backend/x11.zig | 42 ++++++++++++++++++++++-------------------- src/server.zig | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/backend/x11.zig b/src/backend/x11.zig index 9c75036..00a5728 100644 --- a/src/backend/x11.zig +++ b/src/backend/x11.zig @@ -8,7 +8,7 @@ const c = @cImport({ @cInclude("GLES3/gl3.h"); @cInclude("X11/Xlib-xcb.h"); @cInclude("xkbcommon/xkbcommon.h"); - @cInclude("xkbcommon/xkbcommon-x11.h"); + // @cInclude("xkbcommon/xkbcommon-x11.h"); }); const Event = @import("../subsystem.zig").Event; @@ -32,20 +32,20 @@ pub const X11 = struct { fd: i32, display: *c.Display, outputs: std.ArrayList(X11Output), - xkb_context: *c.xkb_context, - device_id: i32, - keymap: *c.xkb_keymap, - state: *c.xkb_state, + // xkb_context: *c.xkb_context, + // device_id: i32, + // keymap: *c.xkb_keymap, + // state: *c.xkb_state, min_keycode: u8, pub fn init(allocator: mem.Allocator) !X11 { const display: *c.Display = c.XOpenDisplay(null) orelse return error.FailedToOpenDisplay; const conn = c.XGetXCBConnection(display) orelse return error.FailedToGetXcbConnection; - const xkb_context = c.xkb_context_new(c.XKB_CONTEXT_NO_FLAGS) orelse return error.X11XkbContextFailed; - const device_id = c.xkb_x11_get_core_keyboard_device_id(conn); - const keymap = c.xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, c.XKB_KEYMAP_COMPILE_NO_FLAGS) orelse return error.X11XkbKeymapFailed; - const state = c.xkb_x11_state_new_from_device(keymap, conn, device_id) orelse return error.X11XkbStateFailed; + // const xkb_context = c.xkb_context_new(c.XKB_CONTEXT_NO_FLAGS) orelse return error.X11XkbContextFailed; + // const device_id = c.xkb_x11_get_core_keyboard_device_id(conn); + // const keymap = c.xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, c.XKB_KEYMAP_COMPILE_NO_FLAGS) orelse return error.X11XkbKeymapFailed; + // const state = c.xkb_x11_state_new_from_device(keymap, conn, device_id) orelse return error.X11XkbStateFailed; const setup = c.xcb_get_setup(conn); @@ -54,10 +54,10 @@ pub const X11 = struct { .fd = c.xcb_get_file_descriptor(conn), .display = display, .outputs = std.ArrayList(X11Output).init(allocator), - .xkb_context = xkb_context, - .device_id = device_id, - .keymap = keymap, - .state = state, + // .xkb_context = xkb_context, + // .device_id = device_id, + // .keymap = keymap, + // .state = state, .min_keycode = setup.*.min_keycode, }; } @@ -88,10 +88,11 @@ pub const X11 = struct { c.XCB_KEY_PRESS => { const press: *c.xcb_key_press_event_t = @ptrCast(ev); - _ = c.xkb_state_update_key(it.x11.state, press.detail, c.XKB_KEY_DOWN); - const keysym = c.xkb_state_key_get_one_sym(it.x11.state, press.detail); + const adjusted_keycode = press.detail - it.x11.min_keycode; + // _ = c.xkb_state_update_key(it.x11.state, adjusted_keycode, c.XKB_KEY_DOWN); + // const keysym = c.xkb_state_key_get_one_sym(it.x11.state, adjusted_keycode); - std.log.info("key press = {} keysym = {}", .{ press.detail, keysym }); + // std.log.info("key press = {} keysym = {}", .{ press.detail, keysym }); return .{ .backend = .{ @@ -100,7 +101,7 @@ pub const X11 = struct { .event = .{ .key_press = .{ .time = press.time, - .button = keysym - 8, + .button = adjusted_keycode, .state = 1, }, }, @@ -111,8 +112,9 @@ pub const X11 = struct { const press: *c.xcb_key_release_event_t = @ptrCast(ev); // std.log.info("button press = {}x{} 0x{x}", .{ press.event_x, press.event_y, press.state }); - _ = c.xkb_state_update_key(it.x11.state, press.detail, c.XKB_KEY_UP); - const keysym = c.xkb_state_key_get_one_sym(it.x11.state, press.detail); + const adjusted_keycode = press.detail - it.x11.min_keycode; + // _ = c.xkb_state_update_key(it.x11.state, adjusted_keycode, c.XKB_KEY_UP); + // const keysym = c.xkb_state_key_get_one_sym(it.x11.state, adjusted_keycode); return .{ .backend = .{ @@ -121,7 +123,7 @@ pub const X11 = struct { .event = .{ .key_press = .{ .time = press.time, - .button = keysym - 8, + .button = adjusted_keycode, .state = 0, }, }, diff --git a/src/server.zig b/src/server.zig index 8ab505f..dcb472f 100644 --- a/src/server.zig +++ b/src/server.zig @@ -233,7 +233,7 @@ pub const Server = struct { } pub fn keyboard(server: *Self, time: u32, button: u32, action: u32) !void { - if (button == 224 or button == 25) server.running = false; + if (button == 224) server.running = false; server.xkb.updateKey(button, action); server.mods_depressed = server.xkb.serializeDepressed();