Skip to content

Commit

Permalink
fix key rebindings
Browse files Browse the repository at this point in the history
Hotkey + Send works together great now.

ref jordansissel/xdotool#210 (comment), jordansissel/xdotool#406 (comment)
  • Loading branch information
phil294 committed Jul 9, 2023
1 parent 44fc26a commit dbe6fcc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/run/display/hotkeys.cr
Expand Up @@ -74,12 +74,16 @@ module Run
(! @runner.display.suspended || hotkey.exempt_from_suspension)
end
if hotkey
# TODO: auto test for this
if ! hotkey.up && ! hotkey.no_grab && (hotkey.cmd.is_a?(Cmd::X11::Keyboard::Send) || hotkey.cmd.is_a?(Cmd::X11::Keyboard::SendRaw))
# Fix https://github.com/jordansissel/xdotool/pull/406#issuecomment-1280013095
key_map = XDo::LibXDo::Charcodemap.new
key_map.code = hotkey.keycode
@runner.display.x_do.keys_raw [key_map], pressed: false, delay: 0
if ! hotkey.up && ! hotkey.no_grab
# Fixing https://github.com/jordansissel/xdotool/issues/210:
# Doing a `hotkey.keycode` UP event works great but breaks key remaps.
# Instead, the following magic seems to work reliably.
# Note that both grab and ungrab may fail / not work as expected but that's fine.
# This would better be placed at the *first* `Send`/`SendRaw` command on a per-hotkey
# basis, but since the performance penalty is negligible and it has no negative
# side effects, we just put it at the start of any grabbing hotkey trigger:
@runner.display.adapter.as(X11).grab_keyboard
@runner.display.adapter.as(X11).ungrab_keyboard
end
hotkey.trigger(@runner)
end
Expand Down
40 changes: 37 additions & 3 deletions tests.ahk
Expand Up @@ -3,7 +3,7 @@
; Right now, only commands that can be easily tested in 1-2 lines are tested.
;;;;;;;;;;;;;;;;;;;;;;

N_TESTS = 50
N_TESTS = 52

GoSub, run_tests
if tests_run != %N_TESTS%
Expand Down Expand Up @@ -120,6 +120,9 @@ goto l_after_gui
return
l_after_gui:
sleep 10

;;;;;;;;;;;;;;;;;;; TESTS ;;;;;;;;;;;;;;;;;;;

ifwinnotexist, ahk_x11_test_gui
{
fail_reason = gui win not exist
Expand Down Expand Up @@ -518,7 +521,7 @@ gosub assert

; ### SEND/HOTKEY/HOTSTRING TESTS ###

send {tab}{tab}^a{del} ; focus and reset
send {tab}^a{del} ; focus and reset
sleep 20
send 123
sleep 20
Expand Down Expand Up @@ -566,7 +569,7 @@ goto l_hotstring_tests
if a_index > 50
break
}
expect = hotstring testhotstringbtw,gui_edit,%hotstring_output%
expect = hotstring %hotstring_input%,gui_edit,%hotstring_output%
gosub assert
return
l_hotstring_tests:
Expand Down Expand Up @@ -600,6 +603,9 @@ hotstring_input = .testhotstringnoendchar
hotstring_output = .immediate
gosub test_hotstring

send ^a{del}
sleep 10

goto l_after_f2_hotkey
hotkey_f2:
hotkey_f2_success = 1
Expand Down Expand Up @@ -655,6 +661,34 @@ expect = hotkey xbutton2,hotkey_xbutton2_success,1
gosub assert
hotkey, xbutton2, off

goto l_after_hotkey_with_send_hotkey
hotkey_hotkey_with_send:
send, bcd
return
l_after_hotkey_with_send_hotkey:
hotkey, a, hotkey_hotkey_with_send
runwait, xdotool key a
sleep 20
gui submit, nohide
expect = hotkey with send,gui_edit,bcd
gosub assert
hotkey, a, off
send ^a{del}
sleep 10
goto l_after_hotkey_with_send_not_first_cmd_hotkey
hotkey_hotkey_with_send_not_first_cmd:
sleep 1
send, efg
return
l_after_hotkey_with_send_not_first_cmd_hotkey:
hotkey, a, hotkey_hotkey_with_send_not_first_cmd
runwait, xdotool key a
sleep 20
gui submit, nohide
expect = hotkey with send,gui_edit,efg
gosub assert
hotkey, a, off

Send, {LButton}
sleep 20
expect = send {lbutton},gui_button_clicked_success,1
Expand Down

0 comments on commit dbe6fcc

Please sign in to comment.