From 721087be7624ce2fd0def7ff3fba91905072c29e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 14 Aug 2023 12:40:48 -0700 Subject: [PATCH] macos: send the left/right status of modifier keys --- include/ghostty.h | 4 ++++ macos/Sources/Ghostty/SurfaceView.swift | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index d2d74ea6c..af3aa1fa7 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -83,6 +83,10 @@ typedef enum { GHOSTTY_MODS_SUPER = 1 << 3, GHOSTTY_MODS_CAPS = 1 << 4, GHOSTTY_MODS_NUM = 1 << 5, + GHOSTTY_MODS_SHIFT_RIGHT = 1 << 6, + GHOSTTY_MODS_CTRL_RIGHT = 1 << 7, + GHOSTTY_MODS_ALT_RIGHT = 1 << 8, + GHOSTTY_MODS_SUPER_RIGHT = 1 << 9, } ghostty_input_mods_e; typedef enum { diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 178885976..cad0fdbd5 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -480,12 +480,21 @@ extension Ghostty { private static func translateFlags(_ flags: NSEvent.ModifierFlags) -> ghostty_input_mods_e { var mods: UInt32 = GHOSTTY_MODS_NONE.rawValue + if (flags.contains(.shift)) { mods |= GHOSTTY_MODS_SHIFT.rawValue } if (flags.contains(.control)) { mods |= GHOSTTY_MODS_CTRL.rawValue } if (flags.contains(.option)) { mods |= GHOSTTY_MODS_ALT.rawValue } if (flags.contains(.command)) { mods |= GHOSTTY_MODS_SUPER.rawValue } if (flags.contains(.capsLock)) { mods |= GHOSTTY_MODS_CAPS.rawValue } + // Handle sided input. We can't tell that both are pressed in the + // Ghostty structure but thats okay -- we don't use that information. + let rawFlags = flags.rawValue + if (rawFlags & UInt(NX_DEVICERSHIFTKEYMASK) != 0) { mods |= GHOSTTY_MODS_SHIFT_RIGHT.rawValue } + if (rawFlags & UInt(NX_DEVICERCTLKEYMASK) != 0) { mods |= GHOSTTY_MODS_CTRL_RIGHT.rawValue } + if (rawFlags & UInt(NX_DEVICERALTKEYMASK) != 0) { mods |= GHOSTTY_MODS_ALT_RIGHT.rawValue } + if (rawFlags & UInt(NX_DEVICERCMDKEYMASK) != 0) { mods |= GHOSTTY_MODS_SUPER_RIGHT.rawValue } + return ghostty_input_mods_e(mods) }