Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gtk): detect modifier keys without cursor movement #5367

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/apprt/gtk/key.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 5 additions & 4 deletions src/apprt/gtk/winproto/wayland.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/apprt/gtk/winproto/x11.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down