nclarius / kwin-application-switcher

KWin script to raise all windows of an application as a group
https://store.kde.org/p/1805105
GNU General Public License v3.0
15 stars 1 forks source link

Interference with other keyboard shortcuts #1

Closed RedBearAK closed 2 years ago

RedBearAK commented 2 years ago

@nclarius

Alright, I'm seeing the same effect of interference with other keyboard shortcuts on a physical machine as well as the (Boxes/qemu) VM that I was using to test.

The VM was running KDE Neon User Edition, installed just a couple of days ago.

The physical machine is a 2007 white MacBook with Fedora 36 KDE spin freshly installed.

Both machines have Kinto.sh installed to remap the keyboard to act like a Mac, but even with that completely disabled the interference is happening. So I don't think it has anything to do with Kinto or xkeysnail, the Python app it uses to remap the keyboard input.

What I'm seeing:

With the Kwin script disabled, I can reliably trigger things like krunner, the main application launcher menu, and a "search" dropdown that mimics Spotlight from macOS. The shortcuts are:

Ctrl+Shift+Space (KDE app launcher menu) Alt+Space (krunner) Alt+F1 (Spotlight search clone widget)

These are the actual shortcuts the widgets are set to use, but with Kinto active they remap to different physical keys on the keyboard.

When I have the Kwin script activated, the success rate for triggering any of these shortcuts falls to around 30-50%. In other words, with the script deactivated I can sit here and hold down Cmd+Shift (on the real MacBook) and hit Space over and over, and the KDE app launcher menu will appear and disappear with 100% reliability. Cmd+Space will activate the Spotlight clone, and hide it. Option(Alt)+Space will reveal krunner.

But once I activate the Kwin script these things will either not activate at all, or I'll see a flash as if it was about to activate, but then it goes away without fully opening.

There doesn't seem to be any corresponding effect on the speed or responsiveness of Alt+Tabbing, even with Kinto remapping physical Cmd+Tab to the Alt+Tab logical shortcut.

I can also go crazy doing shortcuts like Cmd+T (new tabs) and Cmd+N (new window), Cmd+W (close tab/window), and there seems to be no issue with such things.

Working theory: This has something to do with the described shortcuts somehow taking focus away from the current window. In other words, maybe triggering these things that are appearing from the top panel (Whitesur Dark global theme applied) is generating some kind of window activation event.

Yeah, seems to be some sort of window focus problem, because when I use the mouse to access the KDE app launcher menu or the Spotlight clone from their icons on the top bar, I also see an unreliable response to the mouse clicks. As I type in this browser window there is a highlighted border around the text box I'm typing in, and when I click on the icons on the top bar that will flash, and more often than not the focus will immediately return to the browser window rather than opening the item in the top bar.

Other icons in the top bar like clipboard indicator, volume and WiFi icons are exhibiting the same behavior. Seems to be a general problem with the Kwin script not wanting to let windows lose focus to these objects living in the top panel. (If you're using the typical default KDE setup these things will mostly be in your "bottom" panel.)

I haven't even taken a look at the code yet, so I can't offer any specific ideas at the moment as to why this is happening or how to fix it.

nclarius commented 2 years ago

Your hypothesis is correct; panel popouts and the like are windows which trigger an activation event, and trying to pull other special windows of the same class to the front causes problems.

Since it is not possible to adequately distinguish the wanted and unwanted windows by window type, the best I can do is hardcode a list of applications (such as "plasmashell" and "krunner") to be ignored.

Please update to the most recent version and confirm that it fixes the problem for KRunner and the launcher menu.

For your Spotlight widget I need the window class; you can retrieve it by running in a terminal

journalctl -g "applicationswitcher:" -f

then activating the window, and the journal should print something like

activated Spotlight Search Clone Widget
app spotlight

and what appears in place of spotlight is what I need.

RedBearAK commented 2 years ago

@nclarius

Hmm. I am actually not seeing anything at all show up in the terminal when I activate the Spotlight clone search widget or the KDE application launcher menu. Of course you know how to identify krunner.

Would this be something that you could pull from a text config file each time the Kwin script is enabled in settings? This is similar to how xkeysnail watches for a specific application name and is able to overlay a specific set of shortcut remaps onto that individual application. But that relies on the X11 WM_CLASS attribute, which is why I can't use Wayland until a solution is found for that. Nothing to do with your script, of course, which is relying on Kwin to identify the window (I assume).

Even with this more general command, I can't see any specific events for the KDE app launcher menu or the search widget.

journalctl -f

The Spotlight clone widget is called "Search 0.1", "Search and Launch", by Vishesh Handa. It appeared as part of the Whitesur Dark global theme that I applied.

If the settings for what to ignore could be pulled from an external source, the user could adapt the script to ignore other widgets they have installed.

Forgot I had the script disabled, but after enabling it I still don't see anything when switching apps or clicking on anything. But with journalctl -f I see a bunch of errors. I don't know if these are even relevant to the discussion:

[kris@fedora ~]$ journalctl -f
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26418, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26419, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26420, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26421, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26422, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26423, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26424, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:34 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 26425, resource id: 16785181, major code: 20 (GetProperty), minor code: 0
May 24 16:36:47 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 28037, resource id: 16785031, major code: 3 (GetWindowAttributes), minor code: 0
May 24 16:36:47 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 28038, resource id: 16785031, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35730, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35731, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35732, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35733, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35734, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35735, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35736, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:37 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 35737, resource id: 16785655, major code: 20 (GetProperty), minor code: 0
May 24 16:37:47 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 36135, resource id: 16785440, major code: 3 (GetWindowAttributes), minor code: 0
May 24 16:37:47 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 36136, resource id: 16785440, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:54 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 40463, resource id: 23069323, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:54 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 40464, resource id: 23069323, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:54 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 40465, resource id: 23069323, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:54 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 40466, resource id: 23069323, major code: 14 (GetGeometry), minor code: 0
May 24 16:37:54 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 40470, resource id: 23069323, major code: 14 (GetGeometry), minor code: 0
May 24 16:38:00 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 42377, resource id: 23069345, major code: 73 (GetImage), minor code: 0
May 24 16:38:00 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 42378, resource id: 23069345, major code: 73 (GetImage), minor code: 0
May 24 16:38:00 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 42379, resource id: 23069345, major code: 73 (GetImage), minor code: 0
May 24 16:38:00 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 42380, resource id: 23069345, major code: 73 (GetImage), minor code: 0
May 24 16:38:00 fedora kwin_x11[1423]: qt.qpa.xcb: QXcbConnection: XCB error: 9 (BadDrawable), sequence: 42384, resource id: 23069345, major code: 73 (GetImage), minor code: 0
nclarius commented 2 years ago

A configuration menu with a list of applications to be ignored is possible and will work for both X11 and Wayland, but takes some work to set up.

nclarius commented 2 years ago

If you're not getting any debug output for the KWin script, open kdebugsettings and make sure that "KWin Scripting" is set to "Full Debug". If that doesn't help, it's probably the same issue as this one for which no solution has been found yet.

The other stuff you're seeing is not relevant.

KWin script print output will be useful if you want to work on the script yourself, but for getting the window class there are other ways if you're on X11, e.g.

watch -n1 wmctrl -lx

(requires wmctrl to be installed) will print a list of open windows every second, the window class is the part after the dot in the third column.

Can't find that Spotlight extension, but if it's a Plasma widget, its window class is likely plasmashell which is taken care of by the update.

RedBearAK commented 2 years ago

@nclarius

Sorry for not getting back sooner. Had a major issue with my network for quite a while that required troubleshooting.

Upgraded to the new version of the script and things seem to work much better. I can reliably activate/toggle all the widgets/objects I was describing earlier. The script no longer seems to be interfering.

Installed the kdebugsettings package and opened the app, set "KWin Scripting" to "Full Debug" and also got rid of a generic "debug=false" that the app was warning about.

Still see nothing at all in the terminal for switching windows or clicking on anything on the screen.

So, at this point I'm not sure how to identify other window classes that might have a problem with the script. Maybe anything similar involving panel widgets will just be covered by plasmashell? Hope so. Clicking on all the tray indicator icons also does not seem to be a problem anymore.

Will let you know if I manage to run into any other issue. Thanks for tweaking it. Looks good for now.

Edit: The wmctrl command just shows a line with plasmashell.plasmashell and a slightly different hex number sequence in front for different objects on the panel, which disappears as soon as I close the drop-down for the item on the panel. I assume that means plasmashell will cover anything on the panel.

nclarius commented 2 years ago

To get debug output: Try

export QT_LOGGING_RULES='kwin_*=true; js=true'

before running journalctl.

nclarius commented 2 years ago

So, at this point I'm not sure how to identify other window classes that might have a problem with the script.

Well if you're not noticing any problems, then hopefully it's because there aren't any :) And yes, what you're getting confirms that everything widgety should be covered by plasmashell.

nclarius commented 2 years ago

So this issue appears to be resolved; if you're noticing strange behavior with other things, please open a new issue for it.

RedBearAK commented 2 years ago

To get debug output: Try

export QT_LOGGING_RULES='kwin_*=true; js=true'

before running journalctl.

@nclarius

FYI, I did that and double-checked that this was the machine where I had installed and configured kdebugsettings. Still see no output for the filtered version of the command for any kind of window event or clicking on panel widgets.

I'll have to rely on wmctrl if something else comes up.

nclarius commented 2 years ago

Still see no output

Then I don't know what else you could do., and the KWin Development chatroom doesn't either. Let's just hope there is no need for any more debugging at all :)