Bug 495741 - Focus not properly given to the destination window after Alt+Tab under Wayland
Summary: Focus not properly given to the destination window after Alt+Tab under Wayland
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: general (show other bugs)
Version: 6.2.4
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: usability
: 494856 496535 496716 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-11-03 09:14 UTC by Huanyu Liu
Modified: 2025-02-14 11:23 UTC (History)
11 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Screencast of the bug when using Kate with an IME (1.99 MB, video/x-matroska)
2024-11-03 09:14 UTC, Huanyu Liu
Details
dolphin issue (2.80 MB, video/mp4)
2024-11-26 19:25 UTC, Filip
Details
kwinrc-01 (2.45 KB, text/plain)
2024-11-26 19:27 UTC, Filip
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Huanyu Liu 2024-11-03 09:14:51 UTC
Created attachment 175481 [details]
Screencast of the bug when using Kate with an IME

SUMMARY
When using Alt+Tab to switch windows under Wayland, the focus is not properly given to the destination window. An additional keystroke is required to gain the focus properly. The additional keystroke may or may not be sent to the destination window, depending on the situation. This bug is not reproducible under X11. The bug is not reproducible when switching windows using taskbar.

STEPS TO REPRODUCE & OBSERVED RESULT
Case 1 (System Settings)
1. Launch System Settings
2. Click on the search bar
3. Switch windows using Alt+Tab to System Settings again
-- Now you can observe that everything in the System Settings window is displayed in unfocused style
4a. Press any key on the keyboard, be it A, Caps Lock, Alt or Esc
-- Now the window regains the focus, while the pressed key is not sent to it
4b. Alternatively, click on the search bar with a mouse
-- Now only the search bar regains the focus, while everything else in the window remains unfocused, *even if you click anything with a mouse*, before you press a key

Case 2 (Kate)
1. Launch Kate and create a new file
2. Switch windows using Alt+Tab to Kate again
-- Now you can observe the same unfocused display, especially, the cursor not blinking, *even though you can move the cursor position with a mouse*
3. Press any key on the keyboard
-- Now the window regains the focus, while the pressed key is sent to it (e.g. if you press A, then an "a" will be typed)

EXPECTED RESULT
The destination window should be given the focus immediately after switching to it.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.2.2
KDE Frameworks Version: 6.7.0
Qt Version: 6.8.0
Kernel Version: 6.11.5-arch1-1 (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION
This bug is especially annoying if you are using an IME, since the first keystroke after Alt+Tab will bypass the IME. See the attached screencast for a demonstration of the bug when using Kate with an IME.
Comment 1 David Edmundson 2024-11-04 17:32:14 UTC
I cannot reproduce even with fcitx enabled. Can you share your ~/.config/kwinrc?
Comment 2 Huanyu Liu 2024-11-09 03:31:57 UTC
I updated to KDE Plasma 6.2.3 and Linux Kernel 6.11.6-arch1-1 and the bug persists.

(In reply to David Edmundson from comment #1)
> I cannot reproduce even with fcitx enabled. Can you share your
> ~/.config/kwinrc?

I created a new account with minimal KWin settings, fcitx disabled and system language set to English (as I encountered a language-dependent crash in LabPlot previously). The bug can still be reproduced. Here is the contents of the auto-generated minimal kwinrc file:

[Desktops]
Id_1=610b991e-7f67-42d3-9531-d707b5bc4e9a
Number=1
Rows=1

[Tiling]
padding=4

[Tiling][052f5458-d764-5f16-9bfc-557564c1e991]
tiles={"layoutDirection":"horizontal","tiles":[{"width":0.25},{"width":0.5},{"width":0.25}]}

[Tiling][292aea65-7de9-5e3b-b0a0-35d5d648c8c2]
tiles={"layoutDirection":"horizontal","tiles":[{"width":0.25},{"width":0.5},{"width":0.25}]}

[Tiling][afb210b1-e2f2-52db-a504-666041e512b9]
tiles={"layoutDirection":"horizontal","tiles":[{"width":0.25},{"width":0.5},{"width":0.25}]}

[Xwayland]
Scale=1
Comment 3 Filip 2024-11-26 19:22:42 UTC
*** Bug 496535 has been marked as a duplicate of this bug. ***
Comment 4 Filip 2024-11-26 19:22:47 UTC
*** Bug 496716 has been marked as a duplicate of this bug. ***
Comment 5 Filip 2024-11-26 19:25:04 UTC
Created attachment 176147 [details]
dolphin issue
Comment 6 Filip 2024-11-26 19:27:52 UTC
Created attachment 176148 [details]
kwinrc-01
Comment 7 Filip 2024-11-26 19:31:55 UTC
I can also reproduce this issue on Dolphin (uploaded a video) and in terminals like in https://bugs.kde.org/show_bug.cgi?id=496716 on multiple devices (PC and laptop)

I also uploaded my kwinrc from PC.

Both devices run Arch Linux, PC has Nvidia proprietary driver, laptop has nvidia gpu, but running nouveau. Both on Wayland.
Operating System: Arch Linux 
KDE Plasma Version: 6.2.3
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0
Kernel Version: 6.11.9-arch1-1 (64-bit)
Graphics Platform: Wayland
Comment 8 ozziem 2024-12-02 22:20:15 UTC
Possible further confirmation of an issue related to window focus using Alt-Tab under Wayland:
https://forum.manjaro.org/t/plasma-window-focus-when-using-task-switcher-across-desktops-behaviour-changed-after-latest-stable-update/171317

In my case the focus issues occur specifically when "Alt-Tabbing" to a window which is on a different virtual desktop.

Operating System: Manjaro Linux rolling
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0
Kernel Version: 6.12.1-4-MANJARO (64-bit)
Graphics Platform: Wayland
Comment 9 nttkde 2024-12-09 17:23:14 UTC
I too noticed that when I Alt-Tab to eg. Kwrite(Kate) its text area stays in this weird unfocused state (but titlebar gets focused color).
In Kwin debug console, the window's parameter 'active' seems to change normally to true.
A key press brings the app to proper focus again.
Also, in Kwrite the first keypress of regular letter keys or Enter get passed to its text area, but first press of at least Backspace, Insert, Delete, PgUp, PGDown and arrow keys is discarded.
System setting's search field seems to discard any first keypress.

Operating System: KDE neon 6.2
KDE Plasma Version: 6.2.3
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0
Kernel Version: 6.8.0-49-generic (64-bit)
Graphics Platform: Wayland
single monitor, no virtual desktops in use
Comment 10 benjamin melançon 2024-12-17 03:40:37 UTC
Confirming this as still a problem with the Task Switcher in Plasma 6.2.4 also in NixOS, not only Arch.  (Posted here before being pointed to this issue: https://discuss.kde.org/t/task-switcher-gives-a-konsole-window-sufficient-focus-to-type-but-not-to-middle-click-paste/27029 )

Perhaps this will make it easier to fix: This is NOT a problem when the Icons-Only Task Manager set so that "Clicking grouped task" "Shows large window previews" and windows are selected and filtered that way.  (Indeed, if the Task Switcher could borrow more from the Icons-Only Task Manager here— correctly getting icons, above all allowing filtering, and "fully" selecting so that middle-click etc works as well as typing, KDE would be in fantastic shape as the most usable desktop for heavy task switchers.)
Comment 11 Maxim Egorushkin 2024-12-25 06:33:21 UTC
Came here to report exactly this same problem. 

Konsole doesn't get focus/blinking-cursor when alt-tab'ing into it. 

Emacs windows (frames in emacs parlance), on the other hand, do, and start blinking the cursor, as expected.

But when switching to Konsole windows using kwin «Switch to Window Left/Right/Up/Down» keyboard shortcuts Konsole does get focus and start blinking the cursor, as expected.

Info Center:
Operating System: KDE neon 6.2
KDE Plasma Version: 6.2.4
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.1
Kernel Version: 6.8.0-50-generic (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5825U with Radeon Graphics
Memory: 62.2 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: Dell Inc.
Product Name: Inspiron 14 7425 2-in-1
System Version: 1.16.0
Comment 12 ozziem 2025-01-11 22:45:04 UTC
(In reply to ozziem from comment #8)
> Possible further confirmation of an issue related to window focus using
> Alt-Tab under Wayland:
> https://forum.manjaro.org/t/plasma-window-focus-when-using-task-switcher-
> across-desktops-behaviour-changed-after-latest-stable-update/171317
> 
> In my case the focus issues occur specifically when "Alt-Tabbing" to a
> window which is on a different virtual desktop.
> 
> Operating System: Manjaro Linux rolling
> KDE Plasma Version: 6.2.4
> KDE Frameworks Version: 6.8.0
> Qt Version: 6.8.0
> Kernel Version: 6.12.1-4-MANJARO (64-bit)
> Graphics Platform: Wayland

I can no longer reproduce this on Plasma 6.2.5 in Endeavour OS. Potentially fixed indirectly?
Comment 13 Krut Patel 2025-02-04 22:18:51 UTC
Definitely still seeing this on 6.2.5 with dolphin at least.

I put some comments on https://bugs.kde.org/show_bug.cgi?id=494856 but looks like this bug covers everything I wrote there.

Info-
Operating System: Arch Linux 
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.2
Kernel Version: 6.13.0-1-mainline-um5606 (64-bit)
Graphics Platform: Wayland
Processors: 20 × AMD Ryzen AI 9 365 w/ Radeon 880M
Memory: 22.6 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ASUS Vivobook S 14 M5406WA_M5406WA
System Version: 1.0
Comment 14 ozziem 2025-02-04 22:32:35 UTC
(In reply to Krut Patel from comment #13)
> Definitely still seeing this on 6.2.5 with dolphin at least.

Manjaro just got 6.2.5 in stable and the issue is definitely still present, even with a clean/default user account. For me it's only an issue when Alt-Tab switching between windows on different virtual desktops.

However, I still cannot reproduce on Endeavour with 6.2.5.
Comment 15 TraceyC 2025-02-04 22:44:22 UTC
*** Bug 494856 has been marked as a duplicate of this bug. ***
Comment 16 TraceyC 2025-02-04 22:59:50 UTC
I'm not able to reproduce the original issue either on Plasma 6.2.5 or with git-master

I *am* able to reproduce the issue with Dolphin, as shown in the screen recording "dolphin issue" on Plasma 6.2.5
I am *not* able to reproduce it on git-master, so it looks like that fix will be available in 6.3.0

I'll leave this open until some folks are able to confirm this on their systems
Comment 17 ozziem 2025-02-05 05:35:02 UTC
Please disregard my comment above regarding EndeavourOS - I forgot that I was running an X11 session.

In my setups, I can resolve the focus issue when switching between windows on different virtual desktops using Alt-Tab by disabling the Plasma setting: “Apps & Windows” - “Window Management” - “Virtual Desktops” - “Show on-screen display when switching”. 

I still think it is a regression introduced in 6.2.4 since I always had this setting enabled previously. Perhaps the root cause relates to that on-screen desktop switching display not releasing focus correctly. Hopefully this helps others reproduce.

Current setup on which the above works around the issue:
Operating System: Manjaro Linux 
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.1
Kernel Version: 6.12.11-1-MANJARO (64-bit)
Graphics Platform: Wayland
Processors: 8 × Intel® Core™ i7-8550U CPU @ 1.80GHz
Memory: 15.4 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics 620
Comment 18 Ilan 2025-02-08 19:12:04 UTC
I'm able to reproduce this with the Thumbnail Grid task switcher on 6.2.5 (wayland). Any other task switcher does not exhibit this behavior.
Comment 19 Filip 2025-02-09 06:34:31 UTC
(In reply to Ilan from comment #18)
> I'm able to reproduce this with the Thumbnail Grid task switcher on 6.2.5 (wayland). Any other task switcher does not exhibit this behavior.

Can confirm this.
Comment 20 Filip 2025-02-14 07:54:04 UTC
Can't reproduce the issue anymore. Is it resolved for anyone else?
Comment 21 Vlad Zahorodnii 2025-02-14 10:54:55 UTC
(In reply to Filip from comment #20)
> Can't reproduce the issue anymore. Is it resolved for anyone else?

If you run 6.3.0, yes
Comment 22 Filip 2025-02-14 11:13:17 UTC
(In reply to Vlad Zahorodnii from comment #21)
> (In reply to Filip from comment #20)
> > Can't reproduce the issue anymore. Is it resolved for anyone else?
> 
> If you run 6.3.0, yes

Yeah, in 6.3.0. Forgot to mention, mb.
Comment 23 Vlad Zahorodnii 2025-02-14 11:23:09 UTC
Okay, let's mark it as resolved then.