Bug 389117

Summary: GTK3 apps started with GDK_BACKEND=wayland have incorrect or inconsistent decorations
Product: [Plasma] kwin Reporter: Kyle Devir <kyle.devir>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: bugseforuns, kyle.devir, nate, northivanastan, rainer
Priority: HI Flags: mgraesslin: Wayland+
mgraesslin: X11-
mgraesslin: ReviewRequest+
Version: 5.11.95   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
URL: https://phabricator.kde.org/D9967
Latest Commit: Version Fixed In: 5.12.0
Sentry Crash Report:
Attachments: Screenshot demonstrating issue
Official Gnome GTK3 application CSDs with patch
Other non-Gnome GTK3 applications with patch
Dirty hack to make GTK3 Wayland windows request SSD instead of CSD
Image demonstrating results after my new patch

Description Kyle Devir 2018-01-17 16:11:00 UTC
Created attachment 109941 [details]
Screenshot demonstrating issue

On KWin on Wayland, whenever I start GTK3 applications using GDK_BACKEND=wayland, decorations either don't appear or they appear oddly.

With the former, mouse clicks sometimes cause the application to vanish into the background. With the latter, clicking on the decoration can cause the same.

With GDK_BACKEND=x11, applications behave normally, with proper decorations.
Comment 1 Martin Flöser 2018-01-18 05:22:02 UTC
I have also experienced it. Haven't investigated yet.
Comment 2 Martin Flöser 2018-01-18 16:13:10 UTC
*** Bug 389167 has been marked as a duplicate of this bug. ***
Comment 3 Martin Flöser 2018-01-18 19:47:14 UTC
I'm currently investigating the issue. GTK seems to use our server side decoration API slightly different than plasma-integration. I'm trying to understand where the differences are.

What I already noticed is that we allow popup menus to be decorated. That's clearly a bug I already have a patch for.
Comment 4 Martin Flöser 2018-01-18 19:55:16 UTC
I think I found the issue. GTK creates the decoration manager, then directly sends a mode change request to client. At that time the xdg_shell_surface is not yet created so KWin doesn't have a ShellClient yet. The logic for connecting to mode change requests is in ShellClient, though. So we simply lose the request.
Comment 5 Martin Flöser 2018-01-18 20:23:23 UTC
Patch at: https://phabricator.kde.org/D9967
Comment 6 Kyle Devir 2018-01-19 05:21:16 UTC
Created attachment 109979 [details]
Official Gnome GTK3 application CSDs with patch

The official Gnome GTK3 application CSDs now work as expected, however...
Comment 7 Kyle Devir 2018-01-19 05:23:36 UTC
Created attachment 109980 [details]
Other non-Gnome GTK3 applications with patch

Unfortunately, non-Gnome GTK3 applications like Libreoffice and Darktable still have missing decorations.
Comment 8 Martin Flöser 2018-01-21 20:09:46 UTC
*** Bug 388836 has been marked as a duplicate of this bug. ***
Comment 9 Martin Flöser 2018-01-23 15:59:01 UTC
Git commit 339a08de3883cc796a263183a336a9e9cfaf4106 by Martin Flöser.
Committed on 23/01/2018 at 15:58.
Pushed by graesslin into branch 'Plasma/5.12'.

Acknowledge the server side deco mode in WaylandServer not ShellClient

Summary:
With GTK applications our code showed issues. With GTK the sequence for
a menu or dialog window is:
 1. create surface
 2. create server side decoration
 3. request csd
 4. create xdg_shell_surface

Which result in KWin to have the ServerSideDecoration object being
created before the ShellClient is created. The connect for mode changed
happens in ShellClient, which is too late to catch that the window
requested client side decoration. Thus KWin created a decoration about
things such as a menu.

This change moves the acknowledge of the mode to WaylandServer. As we
anyway always acknowledge the requested mode we can also do it there and
don't require ShellClient to be present. Thus when the ShellClient is
created the mode is properly reflected and no decoration is created.
FIXED-IN: 5.12.0

Test Plan: Played a lot with evince

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9967

M  +0    -2    shell_client.cpp
M  +6    -0    wayland_server.cpp

https://commits.kde.org/kwin/339a08de3883cc796a263183a336a9e9cfaf4106
Comment 10 Kyle Devir 2018-01-24 03:27:48 UTC
Martin, can this be reopened, as the submitted fix doesn't solve the sheer lack of decorations for applications like Libreoffice (using the GTK3 VCL backend), Darktable, RawTherapee, MyPaint, and the like.

They seem to use GTK3 differently to the official Gnome apps, in some manner.
Comment 11 Martin Flöser 2018-01-24 05:14:14 UTC
We only track one issue with each bug report. I fixed the issue with decorations around menus which was what I understood.

If there are further issues: please report a new bug report.
Comment 12 Kyle Devir 2018-01-24 06:50:15 UTC
Ah, now I understand.

Sorry for the confusion. New bug report time! :)
Comment 13 Martin Flöser 2018-01-24 19:29:06 UTC
*** Bug 389167 has been marked as a duplicate of this bug. ***
Comment 14 Kyle Devir 2018-01-26 11:35:13 UTC
Created attachment 110129 [details]
Dirty hack to make GTK3 Wayland windows request SSD instead of CSD

Okay... with this patch, it would seem like forcing GTK3 windows to request server-side decorations instead of client-side decorations makes this problem come back again.

I tried doing the patch more cleanly, but the GTK3 build would always scream at me for some reason. So, I went with a dirty hack, instead, for now.
Comment 15 Kyle Devir 2018-01-26 11:41:49 UTC
Created attachment 110130 [details]
Image demonstrating results after my new patch

Martin,

with being able to force SSD instead of CSD now, your old fix's assumptions no longer hold.

I've been really annoyed about this whole issue. :/
Comment 16 Christoph Feck 2018-01-27 01:33:41 UTC
Kyle, could you please clarify if additional patches are needed to fix this issue? If yes, please reopen the bug.

If the patches you added are ment to solve a different issue, please create a new ticket.
Comment 17 Kyle Devir 2018-01-27 02:54:25 UTC
Leave this issue closed for now, because this particular issue has been solved.

The non-request for server-side decorations is a GTK3 bug, but with the request being forced, it exposes a bug somewhere on the KWin side.

It could one or the other, or both. I don't know at this stage. So, I'll just open a new bug if necessary.

Sorry, but this bug leaves me frustrated and confused.
Comment 18 Martin Flöser 2018-01-27 08:43:15 UTC
From the image it looks like it is requesting ssd for csd windows again. You can try to use WAYLAND_DEBUG=1 to see the actual requests. That would answer the question whether can has another bug.

And trust me: I'm also frustrated by this bug. It's really disappointing to see how little testing that got in gtk.
Comment 19 Rainer Finke 2018-01-27 10:18:29 UTC
This is the output with kwin-git (compiled today):
$ WAYLAND_DEBUG=1 virt-manager 
[rainer@gd1 ~]$ [1258872,445]  -> wl_display@1.get_registry(new id wl_registry@2)
[1258872,490]  -> wl_display@1.sync(new id wl_callback@3)
[1258872,658] wl_display@1.delete_id(3)
[1258872,671] wl_registry@2.global(1, "wl_compositor", 3)
[1258872,701]  -> wl_registry@2.bind(1, "wl_compositor", 3, new id [unknown]@4)
[1258872,736] wl_registry@2.global(2, "wl_shell", 1)
[1258872,761] wl_registry@2.global(3, "xdg_shell", 1)
[1258872,782] wl_registry@2.global(4, "zxdg_shell_v6", 1)
[1258872,808]  -> wl_registry@2.bind(4, "zxdg_shell_v6", 1, new id [unknown]@5)
[1258872,843] wl_registry@2.global(5, "wl_shm", 1)
[1258872,868]  -> wl_registry@2.bind(5, "wl_shm", 1, new id [unknown]@6)
[1258872,988]  -> wl_shm@6.create_pool(new id wl_shm_pool@7, fd 13, 2304)
[1258874,053]  -> wl_shm_pool@7.resize(6912)
[1258875,218]  -> wl_shm_pool@7.resize(16128)
[1258876,798]  -> wl_shm_pool@7.resize(34560)
[1258879,367]  -> wl_shm_pool@7.resize(71424)
[1258883,316]  -> wl_shm_pool@7.resize(145152)
[1258883,416]  -> wl_shm_pool@7.resize(292608)
[1258885,937]  -> wl_shm_pool@7.resize(587520)
[1258891,096]  -> wl_shm_pool@7.resize(1177344)
[1258908,192] wl_registry@2.global(6, "wl_seat", 4)
[1258908,215] wl_registry@2.global(7, "zwp_pointer_gestures_v1", 1)
[1258908,222]  -> wl_registry@2.bind(7, "zwp_pointer_gestures_v1", 1, new id [unknown]@8)
[1258908,230] wl_registry@2.global(8, "zwp_pointer_constraints_v1", 1)
[1258908,236] wl_registry@2.global(9, "wl_data_device_manager", 3)
[1258908,242]  -> wl_registry@2.bind(9, "wl_data_device_manager", 3, new id [unknown]@9)
[1258908,249]  -> wl_registry@2.bind(6, "wl_seat", 4, new id [unknown]@10)
[1258911,209]  -> wl_compositor@4.create_surface(new id wl_surface@11)
[1258911,230]  -> wl_data_device_manager@9.get_data_device(new id wl_data_device@12, wl_seat@10)
[1258911,253]  -> wl_compositor@4.create_surface(new id wl_surface@13)
[1258911,371]  -> wl_display@1.sync(new id wl_callback@14)
[1258911,379] wl_registry@2.global(10, "org_kde_kwin_idle", 1)
[1258911,387] wl_registry@2.global(11, "zwp_idle_inhibit_manager_v1", 1)
[1258911,395] wl_registry@2.global(12, "org_kde_plasma_shell", 4)
[1258911,402] wl_registry@2.global(13, "qt_surface_extension", 1)
[1258911,410] wl_registry@2.global(14, "org_kde_kwin_appmenu_manager", 1)
[1258911,419] wl_registry@2.global(15, "org_kde_kwin_server_decoration_palette_manager", 1)
[1258911,431] wl_registry@2.global(16, "org_kde_plasma_window_management", 7)
[1258911,441] wl_registry@2.global(17, "org_kde_kwin_shadow_manager", 2)
[1258911,454] wl_registry@2.global(18, "org_kde_kwin_dpms_manager", 1)
[1258911,463] wl_registry@2.global(19, "org_kde_kwin_server_decoration_manager", 1)
[1258911,475]  -> wl_registry@2.bind(19, "org_kde_kwin_server_decoration_manager", 1, new id [unknown]@15)
[1258911,489] wl_registry@2.global(20, "org_kde_kwin_outputmanagement", 1)
[1258911,498] wl_registry@2.global(21, "wl_subcompositor", 1)
[1258911,513]  -> wl_registry@2.bind(21, "wl_subcompositor", 1, new id [unknown]@16)
[1258911,526] wl_registry@2.global(22, "zxdg_exporter_v2", 1)
[1258911,535] wl_registry@2.global(23, "zxdg_importer_v2", 1)
[1258911,544] wl_registry@2.global(24, "zwp_relative_pointer_manager_v1", 1)
[1258911,554] wl_registry@2.global(25, "org_kde_kwin_outputdevice", 1)
[1258911,566] wl_registry@2.global(26, "wl_output", 2)
[1258911,575]  -> wl_registry@2.bind(26, "wl_output", 2, new id [unknown]@17)
[1258911,611]  -> wl_display@1.sync(new id wl_callback@18)
[1258911,618] wl_registry@2.global(27, "wl_drm", 2)
[1258911,630] wl_registry@2.global(28, "org_kde_kwin_fake_input", 2)
[1258911,641] wl_registry@2.global(29, "wl_text_input_manager", 1)
[1258911,652] wl_registry@2.global(30, "zwp_text_input_manager_v2", 1)
[1258911,666] wl_registry@2.global(31, "org_kde_kwin_blur_manager", 1)
[1258911,675] wl_registry@2.global(32, "org_kde_kwin_contrast_manager", 1)
[1258911,687] wl_registry@2.global(33, "org_kde_kwin_slide_manager", 1)
[1258911,697] wl_callback@3.done(289)
[1258911,976] wl_display@1.delete_id(14)
[1258911,981] wl_shm@6.format(0)
[1258911,986] wl_shm@6.format(1)
[1258911,991] wl_seat@10.capabilities(3)
[1258911,995]  -> wl_seat@10.get_pointer(new id wl_pointer@3)
[1258912,015]  -> zwp_pointer_gestures_v1@8.get_swipe_gesture(new id zwp_pointer_gesture_swipe_v1@19, wl_pointer@3)
[1258912,024]  -> zwp_pointer_gestures_v1@8.get_pinch_gesture(new id zwp_pointer_gesture_pinch_v1@20, wl_pointer@3)
[1258912,033]  -> wl_seat@10.get_keyboard(new id wl_keyboard@21)
[1258912,050] wl_seat@10.name("")
[1258912,054] wl_callback@14.done(289)
[1258912,059] org_kde_kwin_server_decoration_manager@15.default_mode(2)
[1258912,080] wl_display@1.delete_id(18)
[1258912,084] wl_output@17.geometry(0, 0, 610, 350, 0, "SAM", "DP-3-U28D590", 0)
[1258912,110] wl_output@17.scale(1)
[1258912,116] wl_output@17.mode(0, 2560, 1440, 59951)
[1258912,128] wl_output@17.mode(0, 1920, 1200, 59997)
[1258912,139] wl_output@17.mode(0, 1920, 1080, 60000)
[1258912,152] wl_output@17.mode(0, 1920, 1080, 59940)
[1258912,161] wl_output@17.mode(0, 1600, 1200, 59997)
[1258912,170] wl_output@17.mode(0, 1680, 1050, 59954)
[1258912,185] wl_output@17.mode(0, 1600, 900, 60000)
[1258912,195] wl_output@17.mode(0, 1280, 1024, 75025)
[1258912,204] wl_output@17.mode(0, 1280, 1024, 60020)
[1258912,214] wl_output@17.mode(0, 1440, 900, 59887)
[1258912,225] wl_output@17.mode(0, 1280, 800, 59810)
[1258912,234] wl_output@17.mode(0, 1152, 864, 75000)
[1258912,244] wl_output@17.mode(0, 1280, 720, 60000)
[1258912,252] wl_output@17.mode(0, 1280, 720, 59940)
[1258912,262] wl_output@17.mode(0, 1024, 768, 75029)
[1258912,276] wl_output@17.mode(0, 1024, 768, 70069)
[1258912,286] wl_output@17.mode(0, 1024, 768, 60004)
[1258912,297] wl_output@17.mode(0, 832, 624, 74551)
[1258912,307] wl_output@17.mode(0, 800, 600, 75000)
[1258912,317] wl_output@17.mode(0, 800, 600, 72188)
[1258912,333] wl_output@17.mode(0, 800, 600, 60317)
[1258912,341] wl_output@17.mode(0, 800, 600, 56250)
[1258912,352] wl_output@17.mode(0, 640, 480, 75000)
[1258912,361] wl_output@17.mode(0, 640, 480, 72809)
[1258912,371] wl_output@17.mode(0, 640, 480, 66667)
[1258912,381] wl_output@17.mode(0, 640, 480, 60000)
[1258912,391] wl_output@17.mode(0, 640, 480, 59940)
[1258912,400] wl_output@17.mode(0, 720, 400, 70082)
[1258912,410] wl_output@17.mode(3, 3840, 2160, 59997)
[1258912,423] wl_output@17.done()
[1258912,431] wl_callback@18.done(289)