Summary: | KWin changes focus when switching virtual desktop with an app that changes its WM_NAME and _NET_WM_NAME at runtime | ||
---|---|---|---|
Product: | [Plasma] kwin | Reporter: | Oscar Fuentes <bugs-kde> |
Component: | general | Assignee: | KWin default assignee <kwin-bugs-null> |
Status: | REPORTED --- | ||
Severity: | normal | CC: | nate |
Priority: | NOR | ||
Version: | 5.26.90 | ||
Target Milestone: | --- | ||
Platform: | Debian testing | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Oscar Fuentes
2023-02-10 04:53:19 UTC
Why does it do that, though? That's an odd thing for a window to do. (In reply to Nate Graham from comment #1) > Why does it do that, though? That's an odd thing for a window to do. I don't know for sure, but I think that's what Emacs does to set the title bar of the iconified window (it seems some window managers support this, including KDE.) Emacs can be configured to use different strings for the iconified and the non-iconified window. It doesn't need to do that; there are ways to change the window title without messing with those values. The nonstandard thing it's doing right now apparently proves confusing to KWin. :) (In reply to Nate Graham from comment #3) > It doesn't need to do that; there are ways to change the window title > without messing with those values. The nonstandard thing it's doing right > now apparently proves confusing to KWin. :) Would you like to give a general indication about what is the correct way of changing the window title? I'll rely your answer to the Emacs developer who implemented that feature. Thanks. it depends on the UI toolkit being used, but in Qt, we typically use QWidget::setWindowTitle(). I don't know what it does under the hood, sorry. (In reply to Nate Graham from comment #5) > it depends on the UI toolkit being used, but in Qt, we typically use > QWidget::setWindowTitle(). I don't know what it does under the hood, sorry. Emacs does not use a UI toolkit (optionally, it uses Gtk for some tasks.) I'll try looking at the sources of Qt then, thanks. (In reply to Nate Graham from comment #5) > it depends on the UI toolkit being used, but in Qt, we typically use > QWidget::setWindowTitle(). I don't know what it does under the hood, sorry. Nate, please allow me one more question: do you *know* that the method for changing the window title described on my bug report is wrong? Because I have the impression that you know about Qt, but not about the low level X API calls. Thanks. I don't know 100%, but I do know that changing WM_NAME and _NET_WM_NAME at runtime is considered to be always wrong by KWin and Plasma developers. (In reply to Nate Graham from comment #8) > I don't know 100%, but I do know that changing WM_NAME and _NET_WM_NAME at > runtime is considered to be always wrong by KWin and Plasma developers. Thanks. Sorry, but what you say would amount to not changing the window's title at runtime, so I think there is a misunderstanding here. BTW, Qt ends setting _NET_WM_NAME and, conditionally, also WM_NAME when QWidget::setWindowTitle is called: https://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/xcb/qxcbwindow.cpp?h=dev#n2543 What the Emacs developer thinks is happening is that KWin notices that a pseudo-iconified window (I say pseudo-iconified because the window is not on the current virtual desktop) changed its title, and somehow transfers focus to that window when its virtual desktop is shown. I hope a KWin developer will chime in for valuating this hypothesis. Until that happens, can we maintain the bug report status on a suitable state for requesting the attention of such developer? Thanks again. Oh, TIL! I'm unaware of code that could focus a window if its title changes. A shot in the dark: do you have window rules for emacs? If not, then I guess somebody would need to build a dev version of emacs and test for themselves (In reply to Vlad Zahorodnii from comment #11) > I'm unaware of code that could focus a window if its title changes. A shot > in the dark: do you have window rules for emacs? If not, then I guess > somebody would need to build a dev version of emacs and test for themselves Yes, I have these window rules for Emacs: [5] Description=Emacs Android shortcut=Ctrl+Alt+6 shortcutrule=2 strictgeometryrule=2 title=AndroEmacs: titlematch=2 types=1 wmclass=emacs wmclassmatch=1 [6] Description=Emacs shortcut=Ctrl+Alt+1 shortcutrule=2 strictgeometryrule=2 types=1 wmclass=emacs wmclassmatch=1 For the rule [5] I changed wmclass to "foo" (thus effectively disabling the rule) and the problem went away. So Kwin is giving focus to Emacs because of that rule. Please note that it has "title=" and "titlematch=" attributes, but the Emacs window that ends with focus do not match those criteria (in fact, in my experiment there is no window that matches that criteria.) To recap: Emacs changes its window's title when it is iconified and de-icononified, Kwin notices the change of title and the existence of that rule [5] causes to set the input focus on Emacs' window. This is a simple reproducer that does not require Emacs. Save this tcl script to foo.tcl: # foo.tcl begins here package require Tk proc ct { new_title } { puts "Changing title to $new_title" wm title . $new_title } bind . <Unmap> { ct "Unmapped" } bind . <Map> { ct "Mapped" } # foo.tcl ends here Run it from Konsole: $ tclsh foo.tcl Create this window rule for the window created by the script: [aa2e10a2-9656-4729-b55f-b3a84332de67] Description=Window settings for foo.tcl clientmachine=localhost strictgeometryrule=2 title=blah titlematch=2 types=1 wmclass=tile-foo.tcl wmclassmatch=1 It is important that wmclass matches, while titlematch must be defined, but it is not necessary that it matches. Set focus to Konsole. Switch to another virtual desktop and back to the original virtual desktop. Focus is now on the script's window. |