8
8
#include < chrono>
9
9
#include < mach/mach.h>
10
10
11
+ #include " misc.h"
12
+
11
13
#include " src/logging.h"
12
14
#include " src/platform/common.h"
13
15
#include " src/utility.h"
@@ -226,6 +228,11 @@ const KeyCodeMap kKeyCodesMap[] = {
226
228
};
227
229
// clang-format on
228
230
231
+ /* *
232
+ * Used to avoid spamming permission requests when the user receives an input event
233
+ */
234
+ bool accessibility_permission_requested;
235
+
229
236
int
230
237
keysym (int keycode) {
231
238
KeyCodeMap key_map {};
@@ -242,12 +249,36 @@ const KeyCodeMap kKeyCodesMap[] = {
242
249
return temp_map->mac_keycode ;
243
250
}
244
251
252
+ std::string
253
+ default_accessibility_log_msg () {
254
+ return " Accessibility permission is not enabled,"
255
+ " please enable sunshine in "
256
+ " [System Settings > Privacy & Security > Privacy > Accessibility]"
257
+ " , then please restart Sunshine for it to take effect" ;
258
+ }
259
+
260
+ void
261
+ print_accessibility_status (const bool is_keyboard_event, const bool release) {
262
+ if (!release) return ;
263
+
264
+ if (!has_accessibility_permission ()) {
265
+ if (!accessibility_permission_requested) {
266
+ accessibility_permission_requested = true ;
267
+ request_accessibility_permission ();
268
+ }
269
+ BOOST_LOG (info) << " Received " << (is_keyboard_event ? " keyboard" : " mouse" ) << " event but "
270
+ << default_accessibility_log_msg ();
271
+ }
272
+ }
273
+
245
274
void
246
275
keyboard_update (input_t &input, uint16_t modcode, bool release, uint8_t flags) {
247
276
auto key = keysym (modcode);
248
277
249
278
BOOST_LOG (debug) << " got keycode: 0x" sv << std::hex << modcode << " , translated to: 0x" << std::hex << key << " , release:" << release;
250
279
280
+ print_accessibility_status (true , release);
281
+
251
282
if (key < 0 ) {
252
283
return ;
253
284
}
@@ -437,6 +468,8 @@ const KeyCodeMap kKeyCodesMap[] = {
437
468
BOOST_LOG (warning) << " Unsupported mouse button for MacOS: " sv << button;
438
469
return ;
439
470
}
471
+
472
+ print_accessibility_status (false , release);
440
473
441
474
macos_input->mouse_down [mac_button] = !release;
442
475
@@ -538,6 +571,11 @@ const KeyCodeMap kKeyCodesMap[] = {
538
571
539
572
const auto macos_input = static_cast <macos_input_t *>(result.get ());
540
573
574
+ accessibility_permission_requested = false ;
575
+ if (request_accessibility_permission ()) {
576
+ BOOST_LOG (info) << default_accessibility_log_msg () << " , to allow mouse clicks and keyboard inputs." ;
577
+ }
578
+
541
579
// Default to main display
542
580
macos_input->display = CGMainDisplayID ();
543
581
0 commit comments