mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
refactor(gtk): move device modifier state handling to key.zig
This commit is contained in:
@ -49,6 +49,22 @@ pub fn translateMods(state: c.GdkModifierType) input.Mods {
|
|||||||
return 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
|
// Get the unshifted unicode value of the keyval. This is used
|
||||||
// by the Kitty keyboard protocol.
|
// by the Kitty keyboard protocol.
|
||||||
pub fn keyvalUnicodeUnshifted(
|
pub fn keyvalUnicodeUnshifted(
|
||||||
|
@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator;
|
|||||||
const c = @import("../c.zig").c;
|
const c = @import("../c.zig").c;
|
||||||
const Config = @import("../../../config.zig").Config;
|
const Config = @import("../../../config.zig").Config;
|
||||||
const input = @import("../../../input.zig");
|
const input = @import("../../../input.zig");
|
||||||
|
const key = @import("../key.zig");
|
||||||
|
|
||||||
const wl = wayland.client.wl;
|
const wl = wayland.client.wl;
|
||||||
const org = wayland.client.org;
|
const org = wayland.client.org;
|
||||||
@ -78,20 +79,9 @@ pub const App = struct {
|
|||||||
pub fn eventMods(
|
pub fn eventMods(
|
||||||
_: App,
|
_: App,
|
||||||
device: ?*c.GdkDevice,
|
device: ?*c.GdkDevice,
|
||||||
_: c.GdkModifierType,
|
gtk_mods: c.GdkModifierType,
|
||||||
) ?input.Mods {
|
) ?input.Mods {
|
||||||
if (device) |dev| {
|
return key.deviceMods(device, gtk_mods);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn registryListener(
|
fn registryListener(
|
||||||
|
@ -7,6 +7,7 @@ const c = @import("../c.zig").c;
|
|||||||
const input = @import("../../../input.zig");
|
const input = @import("../../../input.zig");
|
||||||
const Config = @import("../../../config.zig").Config;
|
const Config = @import("../../../config.zig").Config;
|
||||||
const adwaita = @import("../adwaita.zig");
|
const adwaita = @import("../adwaita.zig");
|
||||||
|
const key = @import("../key.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.gtk_x11);
|
const log = std.log.scoped(.gtk_x11);
|
||||||
|
|
||||||
@ -122,17 +123,8 @@ pub const App = struct {
|
|||||||
device: ?*c.GdkDevice,
|
device: ?*c.GdkDevice,
|
||||||
gtk_mods: c.GdkModifierType,
|
gtk_mods: c.GdkModifierType,
|
||||||
) ?input.Mods {
|
) ?input.Mods {
|
||||||
if (device) |dev| {
|
if (key.deviceMods(device, gtk_mods)) |mods| {
|
||||||
const device_mods = c.gdk_device_get_modifier_state(dev);
|
return mods;
|
||||||
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
|
// Shoutout to Mozilla for figuring out a clean way to do this, this is
|
||||||
|
Reference in New Issue
Block a user