Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): stop the picker's Escape hotkey from swallowing app shortcuts

Aatman Jain (AJ)e964d86fc0d3
diff --git a/apps/desktop-gpui/src/platform.rs b/apps/desktop-gpui/src/platform.rs
index 0ee7f4e0b..4994cc574 100644
--- a/apps/desktop-gpui/src/platform.rs
+++ b/apps/desktop-gpui/src/platform.rs
@@ -1439,10 +1439,24 @@ mod mac {
const K_EVENT_HOT_KEY_PRESSED: u32 = 5;
const KVK_ESCAPE: u32 = 53;
const SIGNATURE: u32 = 0x4361_7047;
+ /// `kEventParamDirectObject` (`'----'`) / `typeEventHotKeyID` (`'hkid'`) /
+ /// `eventNotHandledErr`.
+ const K_EVENT_PARAM_DIRECT_OBJECT: u32 = 0x2d2d_2d2d;
+ const TYPE_EVENT_HOT_KEY_ID: u32 = 0x686b_6964;
+ const EVENT_NOT_HANDLED_ERR: OsStatus = -9874;
#[link(name = "Carbon", kind = "framework")]
unsafe extern "C" {
fn GetEventDispatcherTarget() -> *mut c_void;
+ fn GetEventParameter(
+ event: *mut c_void,
+ name: u32,
+ desired_type: u32,
+ actual_type: *mut u32,
+ buffer_size: usize,
+ actual_size: *mut usize,
+ data: *mut c_void,
+ ) -> OsStatus;
fn InstallEventHandler(
target: *mut c_void,
handler: extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> OsStatus,
@@ -1470,9 +1484,32 @@ mod mac {
extern "C" fn escape_pressed(
_call_ref: *mut c_void,
- _event: *mut c_void,
+ event: *mut c_void,
_user_data: *mut c_void,
) -> OsStatus {
+ // The dispatcher target sees every hot key in the process before
+ // its own target does, including global-hotkey's app shortcuts on
+ // the application target. Claiming those swallowed every shortcut
+ // once the first picker had installed this handler, so anything
+ // that is not this Escape goes on to its own handler.
+ let mut pressed = EventHotKeyId {
+ signature: 0,
+ id: 0,
+ };
+ let status = unsafe {
+ GetEventParameter(
+ event,
+ K_EVENT_PARAM_DIRECT_OBJECT,
+ TYPE_EVENT_HOT_KEY_ID,
+ std::ptr::null_mut(),
+ std::mem::size_of::<EventHotKeyId>(),
+ std::ptr::null_mut(),
+ (&raw mut pressed).cast(),
+ )
+ };
+ if status != 0 || pressed.signature != SIGNATURE {
+ return EVENT_NOT_HANDLED_ERR;
+ }
ESCAPE_TX.with(|tx| {
if let Some(sender) = tx.borrow().as_ref() {
let _ = sender.send(());