fix(gtk): detect modifier keys without cursor movement

This commit is contained in:
nnyyxxxx
2025-01-25 02:26:45 -05:00
parent 71e62f96fa
commit cc154404d3
2 changed files with 25 additions and 4 deletions

View File

@ -76,10 +76,21 @@ pub const App = struct {
}
pub fn eventMods(
_: *App,
_: ?*c.GdkDevice,
_: App,
device: ?*c.GdkDevice,
_: c.GdkModifierType,
) ?input.Mods {
if (device) |dev| {
const device_mods = c.gdk_device_get_modifier_state(dev);
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;
}

View File

@ -122,8 +122,18 @@ pub const App = struct {
device: ?*c.GdkDevice,
gtk_mods: c.GdkModifierType,
) ?input.Mods {
_ = device;
_ = gtk_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,
};
}
}
// Shoutout to Mozilla for figuring out a clean way to do this, this is
// paraphrased from Firefox/Gecko in widget/gtk/nsGtkKeyUtils.cpp.