From 761758b1365317bece61a87cfb401062f54f96dd Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 18 Apr 2020 18:19:20 +0200 Subject: [PATCH] Speed up release of keys in fast inject mode --- native/liblinuxbridge/bridge.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/native/liblinuxbridge/bridge.cpp b/native/liblinuxbridge/bridge.cpp index 417b8b6..df5c236 100644 --- a/native/liblinuxbridge/bridge.cpp +++ b/native/liblinuxbridge/bridge.cpp @@ -303,13 +303,35 @@ void send_enter() { xdo_send_keysequence_window(xdo_context, CURRENTWINDOW, "Return", 1000); } +void fast_release_all_keys() { + Window focused; + int revert_to; + XGetInputFocus(xdo_context->xdpy, &focused, &revert_to); + + char keys[32]; + XQueryKeymap(xdo_context->xdpy, keys); // Get the current status of the keyboard + for (int i = 0; i<32; i++) { + // Only those that show a keypress should be changed + if (keys[i] != 0) { + for (int k = 0; k<8; k++) { + if ((keys[i] & (1 << k)) != 0) { // Bit by bit check + int key_code = i*8 + k; + fast_send_event(xdo_context, focused, keycode, 0); + } + } + } + } + + XFlush(xdo_context->xdpy); +} + void fast_send_string(const char * string) { // It may happen that when an expansion is triggered, some keys are still pressed. // This causes a problem if the expanded match contains that character, as the injection // will not be able to register that keypress (as it is already pressed). // To solve the problem, before an expansion we get which keys are currently pressed // and inject a key_release event so that they can be further registered. - release_all_keys(); + fast_release_all_keys(); Window focused; int revert_to;