mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-17 17:26:09 +03:00
Merge pull request #1278 from gpanders/x11-gtk-mods
gtk: use modifier state from GTK key event on X11
This commit is contained in:
@ -600,10 +600,3 @@ test "isValidAppId" {
|
|||||||
try testing.expect(!isValidAppId(""));
|
try testing.expect(!isValidAppId(""));
|
||||||
try testing.expect(!isValidAppId("foo" ** 86));
|
try testing.expect(!isValidAppId("foo" ** 86));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads keyboard state from Xkb if there is an event pending and Xkb is
|
|
||||||
/// loaded (X11 only). Returns null otherwise.
|
|
||||||
pub fn modifier_state_from_xkb(self: *App, display_: ?*c.GdkDisplay) ?input.Mods {
|
|
||||||
const x11_xkb = self.x11_xkb orelse return null;
|
|
||||||
return x11_xkb.modifier_state_from_notify(display_);
|
|
||||||
}
|
|
||||||
|
@ -1349,20 +1349,22 @@ fn keyEvent(
|
|||||||
if (entry.native == keycode) break :keycode entry.key;
|
if (entry.native == keycode) break :keycode entry.key;
|
||||||
} else .invalid;
|
} else .invalid;
|
||||||
|
|
||||||
// Get our modifiers. We have to use the GDK device because the mods
|
|
||||||
// sent to this event do not have the modifier key applied it if it
|
|
||||||
// was presssed (i.e. left control)
|
|
||||||
const mods = mods: {
|
const mods = mods: {
|
||||||
_ = gtk_mods;
|
|
||||||
const device = c.gdk_event_get_device(event);
|
const device = c.gdk_event_get_device(event);
|
||||||
|
|
||||||
// Add any modifier state events from Xkb if we have them (X11 only).
|
var mods = if (self.app.x11_xkb) |xkb|
|
||||||
// Null back from the Xkb call means there was no modifier
|
// Add any modifier state events from Xkb if we have them (X11
|
||||||
|
// only). Null back from the Xkb call means there was no modifier
|
||||||
// event to read. This likely means that the key event did not
|
// event to read. This likely means that the key event did not
|
||||||
// result in a modifier change and we can safely rely on the
|
// result in a modifier change and we can safely rely on the GDK
|
||||||
// GDK state.
|
// state.
|
||||||
var mods = self.app.modifier_state_from_xkb(display) orelse
|
xkb.modifier_state_from_notify(display) orelse translateMods(gtk_mods)
|
||||||
|
else
|
||||||
|
// On Wayland, we have to use the GDK device because the mods sent
|
||||||
|
// to this event do not have the modifier key applied if it was
|
||||||
|
// presssed (i.e. left control).
|
||||||
translateMods(c.gdk_device_get_modifier_state(device));
|
translateMods(c.gdk_device_get_modifier_state(device));
|
||||||
|
|
||||||
mods.num_lock = c.gdk_device_get_num_lock_state(device) == 1;
|
mods.num_lock = c.gdk_device_get_num_lock_state(device) == 1;
|
||||||
|
|
||||||
switch (physical_key) {
|
switch (physical_key) {
|
||||||
|
Reference in New Issue
Block a user