Skip to content

Commit dbe6fcc

Browse files
committed
fix key rebindings
Hotkey + Send works together great now. ref jordansissel/xdotool#210 (comment), jordansissel/xdotool#406 (comment)
1 parent 44fc26a commit dbe6fcc

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

src/run/display/hotkeys.cr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ module Run
7474
(! @runner.display.suspended || hotkey.exempt_from_suspension)
7575
end
7676
if hotkey
77-
# TODO: auto test for this
78-
if ! hotkey.up && ! hotkey.no_grab && (hotkey.cmd.is_a?(Cmd::X11::Keyboard::Send) || hotkey.cmd.is_a?(Cmd::X11::Keyboard::SendRaw))
79-
# Fix https://github.com/jordansissel/xdotool/pull/406#issuecomment-1280013095
80-
key_map = XDo::LibXDo::Charcodemap.new
81-
key_map.code = hotkey.keycode
82-
@runner.display.x_do.keys_raw [key_map], pressed: false, delay: 0
77+
if ! hotkey.up && ! hotkey.no_grab
78+
# Fixing https://github.com/jordansissel/xdotool/issues/210:
79+
# Doing a `hotkey.keycode` UP event works great but breaks key remaps.
80+
# Instead, the following magic seems to work reliably.
81+
# Note that both grab and ungrab may fail / not work as expected but that's fine.
82+
# This would better be placed at the *first* `Send`/`SendRaw` command on a per-hotkey
83+
# basis, but since the performance penalty is negligible and it has no negative
84+
# side effects, we just put it at the start of any grabbing hotkey trigger:
85+
@runner.display.adapter.as(X11).grab_keyboard
86+
@runner.display.adapter.as(X11).ungrab_keyboard
8387
end
8488
hotkey.trigger(@runner)
8589
end

tests.ahk

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; Right now, only commands that can be easily tested in 1-2 lines are tested.
44
;;;;;;;;;;;;;;;;;;;;;;
55

6-
N_TESTS = 50
6+
N_TESTS = 52
77

88
GoSub, run_tests
99
if tests_run != %N_TESTS%
@@ -120,6 +120,9 @@ goto l_after_gui
120120
return
121121
l_after_gui:
122122
sleep 10
123+
124+
;;;;;;;;;;;;;;;;;;; TESTS ;;;;;;;;;;;;;;;;;;;
125+
123126
ifwinnotexist, ahk_x11_test_gui
124127
{
125128
fail_reason = gui win not exist
@@ -518,7 +521,7 @@ gosub assert
518521

519522
; ### SEND/HOTKEY/HOTSTRING TESTS ###
520523

521-
send {tab}{tab}^a{del} ; focus and reset
524+
send {tab}^a{del} ; focus and reset
522525
sleep 20
523526
send 123
524527
sleep 20
@@ -566,7 +569,7 @@ goto l_hotstring_tests
566569
if a_index > 50
567570
break
568571
}
569-
expect = hotstring testhotstringbtw,gui_edit,%hotstring_output%
572+
expect = hotstring %hotstring_input%,gui_edit,%hotstring_output%
570573
gosub assert
571574
return
572575
l_hotstring_tests:
@@ -600,6 +603,9 @@ hotstring_input = .testhotstringnoendchar
600603
hotstring_output = .immediate
601604
gosub test_hotstring
602605

606+
send ^a{del}
607+
sleep 10
608+
603609
goto l_after_f2_hotkey
604610
hotkey_f2:
605611
hotkey_f2_success = 1
@@ -655,6 +661,34 @@ expect = hotkey xbutton2,hotkey_xbutton2_success,1
655661
gosub assert
656662
hotkey, xbutton2, off
657663

664+
goto l_after_hotkey_with_send_hotkey
665+
hotkey_hotkey_with_send:
666+
send, bcd
667+
return
668+
l_after_hotkey_with_send_hotkey:
669+
hotkey, a, hotkey_hotkey_with_send
670+
runwait, xdotool key a
671+
sleep 20
672+
gui submit, nohide
673+
expect = hotkey with send,gui_edit,bcd
674+
gosub assert
675+
hotkey, a, off
676+
send ^a{del}
677+
sleep 10
678+
goto l_after_hotkey_with_send_not_first_cmd_hotkey
679+
hotkey_hotkey_with_send_not_first_cmd:
680+
sleep 1
681+
send, efg
682+
return
683+
l_after_hotkey_with_send_not_first_cmd_hotkey:
684+
hotkey, a, hotkey_hotkey_with_send_not_first_cmd
685+
runwait, xdotool key a
686+
sleep 20
687+
gui submit, nohide
688+
expect = hotkey with send,gui_edit,efg
689+
gosub assert
690+
hotkey, a, off
691+
658692
Send, {LButton}
659693
sleep 20
660694
expect = send {lbutton},gui_button_clicked_success,1

0 commit comments

Comments
 (0)