diff --git a/src/cmd/x11/keyboard/send-raw.cr b/src/cmd/x11/keyboard/send-raw.cr index 4efb720..0b6dfe5 100644 --- a/src/cmd/x11/keyboard/send-raw.cr +++ b/src/cmd/x11/keyboard/send-raw.cr @@ -5,7 +5,8 @@ class Cmd::X11::Keyboard::SendRaw < Cmd::Base def run(thread, args) txt = args[0] thread.runner.display.pause do # to prevent hotkey from triggering other hotkey or itself - thread.runner.display.x_do.clear_active_modifiers thread.runner.display.x_do.active_modifiers + active_modifiers = thread.runner.display.x_do.active_modifiers + thread.runner.display.x_do.clear_active_modifiers active_modifiers if (hotkey = thread.hotkey) && hotkey.key_name.size == 1 && txt.includes?(hotkey.key_name) # TODO: duplicate code as in send.cr key_map_hotkey_up = XDo::LibXDo::Charcodemap.new @@ -13,6 +14,7 @@ class Cmd::X11::Keyboard::SendRaw < Cmd::Base thread.runner.display.x_do.keys_raw [key_map_hotkey_up], pressed: false, delay: 0 end thread.runner.display.x_do.type txt + thread.runner.display.x_do.set_active_modifiers active_modifiers end end end \ No newline at end of file diff --git a/src/cmd/x11/keyboard/send.cr b/src/cmd/x11/keyboard/send.cr index c3d06f7..54e2e38 100644 --- a/src/cmd/x11/keyboard/send.cr +++ b/src/cmd/x11/keyboard/send.cr @@ -4,7 +4,8 @@ class Cmd::X11::Keyboard::Send < Cmd::Base def self.max_args; 1 end def run(thread, args) thread.runner.display.pause do # to prevent hotkey from triggering other hotkey or itself - thread.runner.display.x_do.clear_active_modifiers thread.runner.display.x_do.active_modifiers + active_modifiers = thread.runner.display.x_do.active_modifiers + thread.runner.display.x_do.clear_active_modifiers active_modifiers thread.parse_key_combinations_to_charcodemap(args[0]) do |key_map, pressed, mouse_button, combo| if mouse_button if pressed @@ -17,13 +18,19 @@ class Cmd::X11::Keyboard::Send < Cmd::Base # https://github.com/jordansissel/xdotool/issues/210 (see also hotkeys.cr) # Not a super great solution because for every key up/down combo of the hotkey, this will # *always* send a second key up event now, but oh well it works - key_map_hotkey_up = XDo::LibXDo::Charcodemap.new - key_map_hotkey_up.code = hotkey.keycode - thread.runner.display.x_do.keys_raw [key_map_hotkey_up], pressed: false, delay: 0 + hotkey_key_up = XDo::LibXDo::Charcodemap.new + hotkey_key_up.code = hotkey.keycode + thread.runner.display.x_do.keys_raw [hotkey_key_up], pressed: false, delay: 0 end thread.runner.display.x_do.keys_raw key_map, pressed: pressed, delay: 0 end end + # We can't use `x_do.set_active_modifiers active_modifiers` here because while it would be + # the preferred method, it also does some `xdo_mouse_down()` internally, based on current input state. + # And when we've sent an `{LButton}` down+up event in the keys, the x11 server might still report for the button + # to be pressed down when the up event hasn't been processed yet by it, resulting in wrong input state and + # effectively a wrong button pressed again by libxdo. + thread.runner.display.x_do.keys_raw active_modifiers, pressed: false, delay: 0 end end end \ No newline at end of file