diff --git a/src/apprt/gtk/key.zig b/src/apprt/gtk/key.zig index 40c9ca9a4b..a62b0a16ab 100644 --- a/src/apprt/gtk/key.zig +++ b/src/apprt/gtk/key.zig @@ -49,6 +49,22 @@ pub fn translateMods(state: c.GdkModifierType) input.Mods { return mods; } +pub fn deviceMods(device: ?*c.GdkDevice, gtk_mods: c.GdkModifierType) ?input.Mods { + if (device) |dev| { + const device_mods = c.gdk_device_get_modifier_state(dev); + if (device_mods != gtk_mods) { + return input.Mods{ + .shift = (device_mods & c.GDK_SHIFT_MASK) != 0, + .ctrl = (device_mods & c.GDK_CONTROL_MASK) != 0, + .alt = (device_mods & c.GDK_ALT_MASK) != 0, + .super = (device_mods & c.GDK_SUPER_MASK) != 0, + .caps_lock = (device_mods & c.GDK_LOCK_MASK) != 0, + }; + } + } + return null; +} + // Get the unshifted unicode value of the keyval. This is used // by the Kitty keyboard protocol. pub fn keyvalUnicodeUnshifted( diff --git a/src/apprt/gtk/winproto/wayland.zig b/src/apprt/gtk/winproto/wayland.zig index 8df3e57b32..c50409a592 100644 --- a/src/apprt/gtk/winproto/wayland.zig +++ b/src/apprt/gtk/winproto/wayland.zig @@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator; const c = @import("../c.zig").c; const Config = @import("../../../config.zig").Config; const input = @import("../../../input.zig"); +const key = @import("../key.zig"); const wl = wayland.client.wl; const org = wayland.client.org; @@ -76,11 +77,11 @@ pub const App = struct { } pub fn eventMods( - _: *App, - _: ?*c.GdkDevice, - _: c.GdkModifierType, + _: App, + device: ?*c.GdkDevice, + gtk_mods: c.GdkModifierType, ) ?input.Mods { - return null; + return key.deviceMods(device, gtk_mods); } fn registryListener( diff --git a/src/apprt/gtk/winproto/x11.zig b/src/apprt/gtk/winproto/x11.zig index 7a6b8b4c78..9afd3ff110 100644 --- a/src/apprt/gtk/winproto/x11.zig +++ b/src/apprt/gtk/winproto/x11.zig @@ -7,6 +7,7 @@ const c = @import("../c.zig").c; const input = @import("../../../input.zig"); const Config = @import("../../../config.zig").Config; const adwaita = @import("../adwaita.zig"); +const key = @import("../key.zig"); const log = std.log.scoped(.gtk_x11); @@ -122,8 +123,9 @@ pub const App = struct { device: ?*c.GdkDevice, gtk_mods: c.GdkModifierType, ) ?input.Mods { - _ = device; - _ = gtk_mods; + if (key.deviceMods(device, gtk_mods)) |mods| { + return mods; + } // Shoutout to Mozilla for figuring out a clean way to do this, this is // paraphrased from Firefox/Gecko in widget/gtk/nsGtkKeyUtils.cpp.