@@ -466,6 +466,39 @@ static void handle_key_event(struct sway_keyboard *keyboard,
466
466
}
467
467
468
468
if (!handled || event -> state == WLR_KEY_RELEASED ) {
469
+ if (seat -> im_relay .input_method ) {
470
+ struct wlr_input_method_keyboard_grab_v2 * kb_grab =
471
+ seat -> im_relay .input_method -> im_keyboard_grab ;
472
+ struct wlr_virtual_keyboard_v1 * virtual_keyboard =
473
+ wlr_device -> keyboard -> virtual_keyboard ;
474
+
475
+ // If event is from virtual keyboard of the same client as grab,
476
+ // do not send it back
477
+ if (kb_grab && !(virtual_keyboard &&
478
+ wl_resource_get_client (virtual_keyboard -> resource ) ==
479
+ wl_resource_get_client (kb_grab -> resource ))) {
480
+ // Do not grab the release event if the press event was not
481
+ // sent to grab.
482
+ if (event -> state == WLR_KEY_RELEASED ) {
483
+ bool pressed_sent = update_shortcut_state (
484
+ & keyboard -> state_pressed_sent , event , (uint32_t )keycode , 0 );
485
+ if (pressed_sent ) {
486
+ wlr_seat_set_keyboard (wlr_seat , wlr_device );
487
+ wlr_seat_keyboard_notify_key (wlr_seat , event -> time_msec ,
488
+ event -> keycode , event -> state );
489
+ goto end ;
490
+ }
491
+
492
+ }
493
+
494
+ wlr_input_method_keyboard_grab_v2_set_keyboard (kb_grab ,
495
+ wlr_device -> keyboard );
496
+ wlr_input_method_keyboard_grab_v2_send_key (kb_grab ,
497
+ event -> time_msec , event -> keycode , event -> state );
498
+ goto end ;
499
+ }
500
+ }
501
+
469
502
bool pressed_sent = update_shortcut_state (
470
503
& keyboard -> state_pressed_sent , event , (uint32_t )keycode , 0 );
471
504
if (pressed_sent || event -> state == WLR_KEY_PRESSED ) {
@@ -475,6 +508,7 @@ static void handle_key_event(struct sway_keyboard *keyboard,
475
508
}
476
509
}
477
510
511
+ end :
478
512
transaction_commit_dirty ();
479
513
480
514
free (device_identifier );
@@ -538,10 +572,32 @@ static void handle_modifier_event(struct sway_keyboard *keyboard) {
538
572
struct wlr_input_device * wlr_device =
539
573
keyboard -> seat_device -> input_device -> wlr_device ;
540
574
if (!wlr_device -> keyboard -> group ) {
541
- struct wlr_seat * wlr_seat = keyboard -> seat_device -> sway_seat -> wlr_seat ;
542
- wlr_seat_set_keyboard (wlr_seat , wlr_device );
543
- wlr_seat_keyboard_notify_modifiers (wlr_seat ,
544
- & wlr_device -> keyboard -> modifiers );
575
+ struct sway_seat * seat = keyboard -> seat_device -> sway_seat ;
576
+ bool kb_grab_sent = false;
577
+ if (seat -> im_relay .input_method ) {
578
+ struct wlr_input_method_keyboard_grab_v2 * kb_grab =
579
+ seat -> im_relay .input_method -> im_keyboard_grab ;
580
+ struct wlr_virtual_keyboard_v1 * virtual_keyboard =
581
+ wlr_device -> keyboard -> virtual_keyboard ;
582
+
583
+ // If event is from virtual keyboard of the same client as grab,
584
+ // do not send it back
585
+ if (kb_grab && !(virtual_keyboard &&
586
+ wl_resource_get_client (virtual_keyboard -> resource ) ==
587
+ wl_resource_get_client (kb_grab -> resource ))) {
588
+ wlr_input_method_keyboard_grab_v2_set_keyboard (kb_grab ,
589
+ wlr_device -> keyboard );
590
+ wlr_input_method_keyboard_grab_v2_send_modifiers (kb_grab ,
591
+ & wlr_device -> keyboard -> modifiers );
592
+ kb_grab_sent = true;
593
+ }
594
+ }
595
+ if (!kb_grab_sent ) {
596
+ struct wlr_seat * wlr_seat = keyboard -> seat_device -> sway_seat -> wlr_seat ;
597
+ wlr_seat_set_keyboard (wlr_seat , wlr_device );
598
+ wlr_seat_keyboard_notify_modifiers (wlr_seat ,
599
+ & wlr_device -> keyboard -> modifiers );
600
+ }
545
601
546
602
uint32_t modifiers = wlr_keyboard_get_modifiers (wlr_device -> keyboard );
547
603
determine_bar_visibility (modifiers );
0 commit comments