Hello community, here is the log from the commit of package khotkeys5 for openSUSE:Factory checked in at 2020-07-14 07:44:30 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/khotkeys5 (Old) and /work/SRC/openSUSE:Factory/.khotkeys5.new.3060 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "khotkeys5" Tue Jul 14 07:44:30 2020 rev:103 rq:820097 version:5.19.3 Changes: -------- --- /work/SRC/openSUSE:Factory/khotkeys5/khotkeys5.changes 2020-07-10 14:11:27.835250111 +0200 +++ /work/SRC/openSUSE:Factory/.khotkeys5.new.3060/khotkeys5.changes 2020-07-14 07:45:11.151052762 +0200 @@ -1,0 +2,7 @@ +Fri Jul 10 13:20:23 UTC 2020 - Fabian Vogt <[email protected]> + +- Add patches to improve XTest and use it more (boo#1173968): + * 0001-Handle-modifier-keys-with-xtest-in-ShortcutsHandler-.patch + * 0002-Use-xtest-also-for-sending-input-to-the-active-windo.patch + +------------------------------------------------------------------- New: ---- 0001-Handle-modifier-keys-with-xtest-in-ShortcutsHandler-.patch 0002-Use-xtest-also-for-sending-input-to-the-active-windo.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ khotkeys5.spec ++++++ --- /var/tmp/diff_new_pack.5d6QGk/_old 2020-07-14 07:45:12.827058173 +0200 +++ /var/tmp/diff_new_pack.5d6QGk/_new 2020-07-14 07:45:12.831058186 +0200 @@ -33,8 +33,11 @@ Source1: https://download.kde.org/stable/plasma/%{version}/khotkeys-%{version}.tar.xz.sig Source2: plasma.keyring %endif +# PATCH-FIX-UPSTREAM https://invent.kde.org/plasma/khotkeys/-/merge_requests/3 +Patch1: 0001-Handle-modifier-keys-with-xtest-in-ShortcutsHandler-.patch +Patch2: 0002-Use-xtest-also-for-sending-input-to-the-active-windo.patch # PATCH-FIX-OPENSUSE -Patch: 0001-Use-qdbus-qt5-and-qdbusviewer-qt5.patch +Patch100: 0001-Use-qdbus-qt5-and-qdbusviewer-qt5.patch BuildRequires: extra-cmake-modules >= 1.1.0 BuildRequires: kf5-filesystem BuildRequires: xz ++++++ 0001-Handle-modifier-keys-with-xtest-in-ShortcutsHandler-.patch ++++++ >From f30e5782d56d844cd4a443be9bf43536a3796e41 Mon Sep 17 00:00:00 2001 From: Fabian Vogt <[email protected]> Date: Fri, 10 Jul 2020 14:27:41 +0200 Subject: [PATCH 1/2] Handle modifier keys with xtest in ShortcutsHandler::send_macro_key Otherwise the currently pressed modifiers are used. This is especially an issue for global shortcuts, as those are most likely activated with pressed modifiers. --- libkhotkeysprivate/shortcuts_handler.cpp | 47 +++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/libkhotkeysprivate/shortcuts_handler.cpp b/libkhotkeysprivate/shortcuts_handler.cpp index b7876c2..561dc57 100644 --- a/libkhotkeysprivate/shortcuts_handler.cpp +++ b/libkhotkeysprivate/shortcuts_handler.cpp @@ -146,6 +146,36 @@ static bool xtest() ( XTestQueryExtension( QX11Info::display(), &dummy1, &dummy2, &dummy3, &dummy4 ) == True ); return xtest_available; } + +static void get_modifier_change(int x_mod_needed, QVector<int> &to_press, QVector<int> &to_release) +{ + // Get state of all keys + char keymap[32]; + XQueryKeymap(QX11Info::display(), keymap); + + // From KKeyServer's initializeMods() + XModifierKeymap *xmk = XGetModifierMapping( QX11Info::display() ); + + for (int modidx = 0; modidx < 8; ++modidx) { + bool mod_needed = x_mod_needed & (1 << modidx); + for (int kcidx = 0; kcidx < xmk->max_keypermod; ++kcidx) { + int keycode = xmk->modifiermap[modidx * xmk->max_keypermod + kcidx]; + if(!keycode) + continue; + + bool mod_pressed = keymap[keycode / 8] & (1 << (keycode % 8)); + if(mod_needed) { + mod_needed = false; + if(!mod_pressed) + to_press.push_back(keycode); + } else if(mod_pressed) + to_release.push_back(keycode); + } + } + + XFreeModifiermap(xmk); +} + #endif bool ShortcutsHandler::send_macro_key( const QKeySequence &key, Window window_P ) @@ -164,9 +194,24 @@ bool ShortcutsHandler::send_macro_key( const QKeySequence &key, Window window_P #ifdef HAVE_XTEST if( xtest() && window_P == None ) { - // CHECKME tohle jeste potrebuje modifikatory + QVector<int> keycodes_to_press, keycodes_to_release; + get_modifier_change(x_mod, keycodes_to_press, keycodes_to_release); + + for(int kc : keycodes_to_release) + XTestFakeKeyEvent( QX11Info::display(), kc, False, CurrentTime ); + + for(int kc : keycodes_to_press) + XTestFakeKeyEvent( QX11Info::display(), kc, True, CurrentTime ); + bool ret = XTestFakeKeyEvent( QX11Info::display(), x_keycode, True, CurrentTime ); ret = ret && XTestFakeKeyEvent( QX11Info::display(), x_keycode, False, CurrentTime ); + + for(int kc : keycodes_to_press) + XTestFakeKeyEvent( QX11Info::display(), kc, False, CurrentTime ); + + for(int kc : keycodes_to_release) + XTestFakeKeyEvent( QX11Info::display(), kc, True, CurrentTime ); + return ret; } #endif -- 2.25.1 ++++++ 0002-Use-xtest-also-for-sending-input-to-the-active-windo.patch ++++++ >From fd301faa7ab00f5858741da2697c5f8977c2290c Mon Sep 17 00:00:00 2001 From: Fabian Vogt <[email protected]> Date: Fri, 10 Jul 2020 14:29:20 +0200 Subject: [PATCH 2/2] Use xtest also for sending input to the active window This is possible with xtest as well and necessary to work with applications which don't accept synthetic events, like those using XInput2 (GTK3, Firefox) --- libkhotkeysprivate/shortcuts_handler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libkhotkeysprivate/shortcuts_handler.cpp b/libkhotkeysprivate/shortcuts_handler.cpp index 561dc57..631348d 100644 --- a/libkhotkeysprivate/shortcuts_handler.cpp +++ b/libkhotkeysprivate/shortcuts_handler.cpp @@ -186,13 +186,14 @@ bool ShortcutsHandler::send_macro_key( const QKeySequence &key, Window window_P unsigned int keysym = key[0]; int x_keycode; KKeyServer::keyQtToCodeX(keysym, &x_keycode); + if( x_keycode == NoSymbol ) return false; unsigned int x_mod; KKeyServer::keyQtToModX(keysym, &x_mod ); #ifdef HAVE_XTEST - if( xtest() && window_P == None ) + if( xtest() && (window_P == None || window_P == InputFocus) ) { QVector<int> keycodes_to_press, keycodes_to_release; get_modifier_change(x_mod, keycodes_to_press, keycodes_to_release); -- 2.25.1
