Commit f313955
committed
Fix macOS global shortcuts never firing
The macOS backend pumped Carbon events from a private background thread
via ReceiveNextEvent(). That call drains the *calling* thread's event
queue, and hotkey events are only ever posted to the main thread's queue,
so the poller drained an always-empty queue and no shortcut ever fired.
Registration still succeeded and IsSupported() still returned true, so the
failure was completely silent: examples/shortcut_example could not respond
to a keypress at all.
Rework the backend along the lines of soffes/HotKey: one process-wide
Carbon handler, one RegisterEventHotKey per shortcut, and an EventHotKeyID
signature so the handler passes hotkeys owned by the host application
through instead of swallowing them. The background thread is gone.
InstallEventHandler/RegisterEventHotKey target GetApplicationEventTarget()
rather than the reference's GetEventDispatcherTarget(), because the
dispatcher target is per-thread while Register() is documented as callable
from any thread. The main thread's dispatcher propagates to the
application target, so delivery works either way.
Something still has to pump the main-thread queue. A Cocoa app gets that
from [NSApp run]; PlatformRunMainThreadLoopFor() now performs the same
routing for programs without one, and continues to drain the GCD main
queue that RunOnMainThread()/EmitAsync() depend on.
Also widen the accelerator vocabulary to match the reference's Key enum.
Punctuation, the keypad, and the Control/Option/Command modifier spellings
were understood by every platform parser but rejected by
IsValidAccelerator(), which gates Register() -- so Cmd+Comma and similar
were unreachable regardless of backend support. Windows and Linux gain the
same token tables so one accelerator string means the same key everywhere,
and their F-key paths no longer hand unvalidated input to std::stoi.
Covered by the new shortcut_accelerator_test.1 parent 5f5e643 commit f313955
7 files changed
Lines changed: 517 additions & 294 deletions
File tree
- src
- platform
- linux
- macos
- windows
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
71 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
72 | 129 | | |
73 | 130 | | |
74 | 131 | | |
| |||
79 | 136 | | |
80 | 137 | | |
81 | 138 | | |
82 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
83 | 142 | | |
84 | 143 | | |
85 | 144 | | |
86 | 145 | | |
| 146 | + | |
87 | 147 | | |
88 | 148 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 149 | + | |
| 150 | + | |
109 | 151 | | |
110 | 152 | | |
111 | 153 | | |
| |||
122 | 164 | | |
123 | 165 | | |
124 | 166 | | |
125 | | - | |
| 167 | + | |
| 168 | + | |
126 | 169 | | |
127 | | - | |
| 170 | + | |
128 | 171 | | |
129 | 172 | | |
130 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
43 | 69 | | |
44 | 70 | | |
45 | 71 | | |
| |||
0 commit comments