Skip to content

Commit

Permalink
apprt/gtk: set key modifier flag if physical modifier key is pressed (#…
Browse files Browse the repository at this point in the history
…5420)

Fixes #5191
  • Loading branch information
mitchellh authored Jan 29, 2025
2 parents e536439 + 27b254d commit 09ccda4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/apprt/gtk/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@ pub fn keyEvent(
event,
physical_key,
gtk_mods,
action,
&self.app.winproto,
);

Expand Down
57 changes: 49 additions & 8 deletions src/apprt/gtk/key.zig
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,63 @@ pub fn eventMods(
event: *c.GdkEvent,
physical_key: input.Key,
gtk_mods: c.GdkModifierType,
action: input.Action,
app_winproto: *winproto.App,
) input.Mods {
const device = c.gdk_event_get_device(event);

var mods = app_winproto.eventMods(device, gtk_mods);
mods.num_lock = c.gdk_device_get_num_lock_state(device) == 1;

// We use the physical key to determine sided modifiers. As
// far as I can tell there's no other way to reliably determine
// this.
//
// We also set the main modifier to true if either side is true,
// since on both X11/Wayland, GTK doesn't set the main modifier
// if only the modifier key is pressed, but our core logic
// relies on it.
switch (physical_key) {
.left_shift => mods.sides.shift = .left,
.right_shift => mods.sides.shift = .right,
.left_control => mods.sides.ctrl = .left,
.right_control => mods.sides.ctrl = .right,
.left_alt => mods.sides.alt = .left,
.right_alt => mods.sides.alt = .right,
.left_super => mods.sides.super = .left,
.right_super => mods.sides.super = .right,
.left_shift => {
mods.shift = action != .release;
mods.sides.shift = .left;
},

.right_shift => {
mods.shift = action != .release;
mods.sides.shift = .right;
},

.left_control => {
mods.ctrl = action != .release;
mods.sides.ctrl = .left;
},

.right_control => {
mods.ctrl = action != .release;
mods.sides.ctrl = .right;
},

.left_alt => {
mods.alt = action != .release;
mods.sides.alt = .left;
},

.right_alt => {
mods.alt = action != .release;
mods.sides.alt = .right;
},

.left_super => {
mods.super = action != .release;
mods.sides.super = .left;
},

.right_super => {
mods.super = action != .release;
mods.sides.super = .right;
},

else => {},
}

Expand Down

0 comments on commit 09ccda4

Please sign in to comment.