Bug 458748

Summary: Rules don't apply screen & pos restriction for Thunderbird (wayland native)
Product: [Plasma] kwin Reporter: gudvinr+kde
Component: rulesAssignee: KWin default assignee <kwin-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: isma.af, nate
Priority: NOR    
Version: 5.25.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: rules

Description gudvinr+kde 2022-09-05 14:16:44 UTC
Created attachment 151839 [details]
rules

SUMMARY

Position and Screen rules for Thunderbird (102) under wayland.

Thunderbird is running under wayland natively. I confirmed that by looking at kwin debug console.
Same thing happens with firefox. That is probably important since they both use same base.

Also I noticed similar behaviour in Discord native app (electron based) as I mentioned in bug #453374

STEPS TO REPRODUCE
1. Create window rule to match thunderbird
2. Add Position and/or Screen rule
3. Close (if necessary) and open thunderbird

OBSERVED RESULT

Thunderbird opens on active screen (where cursor is) ignoring requested position.

EXPECTED RESULT

Thunderbird appearing where it should according to requested rules.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.25.4
KDE Frameworks Version: 5.97.0
Qt Version: 5.15.5
Graphics Platform: Wayland
Comment 1 Nate Graham 2022-09-09 04:06:59 UTC
Can reproduce.
Comment 2 Vlad Zahorodnii 2022-09-12 09:43:04 UTC
[2681654.605]  -> wl_compositor@4.create_surface(new id wl_surface@59)
[2681818.370]  -> xdg_wm_base@30.get_xdg_surface(new id xdg_surface@60, wl_surface@51)
[2681818.387]  -> xdg_surface@60.get_toplevel(new id xdg_toplevel@61)
[2681818.390]  -> xdg_toplevel@61.set_parent(nil)
[2681818.392]  -> xdg_toplevel@61.set_title("Mozilla Thunderbird")
[2681818.394]  -> xdg_toplevel@61.set_app_id("thunderbird")
[2681818.396]  -> wl_surface@51.commit()
[2681818.398]  -> org_kde_kwin_server_decoration_manager@11.create(new id org_kde_kwin_server_decoration@62, wl_surface@51)
[2681818.401]  -> org_kde_kwin_server_decoration@62.request_mode(1)
[2681819.350]  -> xdg_toplevel@61.set_title("Home - Mozilla Thunderbird")

kwin expects that the application sets all initial properties and then commits the surface. This is not the case with Thunderbird. According to the wayland debug log, Thunderbird sets "Mozilla Thunderbird" title, then tells kwin that it has done initializing the window and it can proceed doing its own thing, kwin applies window rules, then Thunderbird changes the title to "Home - Mozilla Thunderbird", and afterwards one more time.

Ideally, Thunderbird should initialize in the following order

[2681654.605]  -> wl_compositor@4.create_surface(new id wl_surface@59)
[2681818.370]  -> xdg_wm_base@30.get_xdg_surface(new id xdg_surface@60, wl_surface@51)
[2681818.387]  -> xdg_surface@60.get_toplevel(new id xdg_toplevel@61)
[2681818.390]  -> xdg_toplevel@61.set_parent(nil)
[2681818.392]  -> xdg_toplevel@61.set_title("Home - Mozilla Thunderbird")
[2681818.394]  -> xdg_toplevel@61.set_app_id("thunderbird")
[2681818.398]  -> org_kde_kwin_server_decoration_manager@11.create(new id org_kde_kwin_server_decoration@62, wl_surface@51)
[2681818.401]  -> org_kde_kwin_server_decoration@62.request_mode(1)
[2681818.396]  -> wl_surface@51.commit()

As a workaround, change the title match in your window rule, or remove it completely. Also, can you report this issue to Thunderbird developers? If not, I can do that, but it can a bit later.
Comment 3 gudvinr+kde 2022-09-12 12:38:35 UTC
Thanks for investigating this, Vlad.

Did you test it with added account? In my case title is changed when you switch through accounts and when app is launched it shows "Index xxx@yyy - Mozilla Thunderbird".

I tried to change title to both "Home - Mozilla Thunderbird" and "Mozilla Thunderbird" and it didn't work.

Removing title match works, however I added it specifically because without that kwin applies rules to sub-windows (like new message window) which I don't want.
Comment 4 Vlad Zahorodnii 2022-09-12 12:53:10 UTC
.*Mozilla Thunderbird$

seems to work on my machine
Comment 5 gudvinr+kde 2022-09-13 11:03:28 UTC
(In reply to Vlad Zahorodnii from comment #4)
> .*Mozilla Thunderbird$
> 
> seems to work on my machine

Yep, this one works too. Since it solves my issue I guess there's not much point on leaving it open.

I don't know if what you say is the bug so I don't feel too confident to create bug report myself, but if you think that's issue with Thunderbird (and probably with Firefox too) I don't mind that not being reported ASAP since it is fine-ish now.

Also I feel like Firefox/Thunderbird don't remember their position which is why I created this rule but I am not sure if that is the bug of the Firefox or there's something shady going on between compositor and windows. So I am not sure how to proceed here.
Comment 6 gudvinr+kde 2022-10-18 00:06:06 UTC
Vlad, what do you use to debug window creation process? Is it possible to do that without recompiling kwin?
I'd like to give more information for bug 458956 and it seems like what you did here can help there too.