Sway: [firefox] GTK popups such as tooltips/context menus flicker on surface commit

Created on 27 May 2019  路  6Comments  路  Source: swaywm/sway

Firefox tracking bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1548496

Some Firefox "popup" surfaces (context menus, tooltips, plugin popups) toggle between visible and invisible for every surface commit. The easiest way to reproduce is to open a context menu with right flick a few times, and then move the cursor around, with every pixel moved causing the state to toggle for some surfaces. It can sometimes take a few tries.

The issue was introduced when Firefox changed its popup handling to create windows with GDK_WINDOW_TYPE_HINT_POPUP_MENU on Wayland, calling gtk_window_set_transient_for to assign the popup to its parent. Before, it used for wayland GDK_WINDOW_TYPE_HINT_UTILITY. The change was introduced in response to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1532643, by this patch: https://phabricator.services.mozilla.com/D26112.

Tests:

  • Sway: Flicker
  • Rootston: OK
  • Weston: OK
  • GNOME: OK

WAYLAND_DEBUG for firefox, opening a context menu, moving the cursor while observing flicker, and then leaving the window:

[1420963,649] [email protected](2139321, 19,292969, 2126,281250)
[1420963,798] [email protected]()
[1421395,778] [email protected](8692, 2139753, 273, 1)
[1421395,882] [email protected]()
[1421406,286]  -> [email protected]_surface(new id wl_surface@62)
[1421406,310]  -> [email protected]_positioner(new id xdg_positioner@73)
[1421406,315]  -> [email protected]_size(207, 262)
[1421406,320]  -> [email protected]_anchor_rect(21, 2128, 1, 1)
[1421406,328]  -> [email protected]_offset(0, 0)
[1421406,332]  -> [email protected]_anchor(5)
[1421406,335]  -> [email protected]_gravity(8)
[1421406,341]  -> [email protected]_constraint_adjustment(15)
[1421406,344]  -> [email protected]_xdg_surface(new id xdg_surface@75, wl_surface@62)
[1421406,354]  -> [email protected]_popup(new id xdg_popup@74, xdg_surface@30, xdg_positioner@73)
[1421406,362]  -> [email protected]()
[1421406,366]  -> [email protected]()
[1421407,239]  -> [email protected](new id wl_callback@79)
[1421407,820] [email protected]_id(73)
[1421407,831] [email protected](wl_output@19)
[1421407,836] [email protected](21, 1867, 207, 262)
[1421407,852] [email protected](8693)
[1421407,860]  -> [email protected]_configure(8693)
[1421407,937]  -> [email protected]_pool(new id wl_shm_pool@73, fd 98, 216936)
[1421407,969]  -> [email protected]_buffer(new id wl_buffer@51, 0, 207, 262, 828, 0)
[1421408,093]  -> [email protected](wl_buffer@51, 0, 0)
[1421408,102]  -> [email protected]_buffer_scale(1)
[1421408,106]  -> [email protected](0, 0, 207, 262)
[1421408,113]  -> [email protected]_window_geometry(0, 0, 207, 262)
[1421408,134]  -> [email protected](new id wl_callback@77)
[1421408,140]  -> [email protected]()
[1421408,433] [email protected]()
[1421420,128] [email protected]_id(79)
[1421420,146] [email protected]_id(77)
[1421420,150] [email protected](2139777)
[1421420,155] [email protected](2139777)
[1421423,861]  -> [email protected]_surface(new id wl_surface@77)
[1421423,893]  -> [email protected]_subsurface(new id wl_subsurface@79, wl_surface@77, wl_surface@62)
[1421423,904]  -> [email protected]_position(0, 0)
[1421423,910]  -> [email protected]_desync()
[1421423,914]  -> [email protected]_region(new id wl_region@59)
[1421423,921]  -> [email protected]_input_region(wl_region@59)
[1421423,927]  -> [email protected]()
[1421423,932]  -> [email protected]_buffer_scale(1)
[1421423,937]  -> [email protected]()
[1421423,952]  -> [email protected](0, 0, 207, 262)
[1421423,964]  -> [email protected](new id wl_callback@65)
[1421423,971]  -> [email protected]_buffer_scale(1)
[1421423,977]  -> [email protected](wl_buffer@54, 0, 0)
[1421423,986]  -> [email protected]()
[1421424,366] [email protected]_id(59)
[1421426,266] [email protected]()
[1421437,092] [email protected]_id(65)
[1421438,672] [email protected](2139794)
[1421438,697]  -> [email protected](7, 239, 16, 17)
[1421438,713]  -> [email protected](new id wl_callback@65)
[1421438,732]  -> [email protected](wl_buffer@54, 0, 0)
[1421438,747]  -> [email protected]()
[1421442,817] [email protected]()
[1421453,943] [email protected]_id(65)
[1421455,157] [email protected](2139811)
[1421492,039] [email protected](8694, 2139849, 273, 0)
[1421492,131] [email protected]()
[1422492,169] [email protected](8695, wl_surface@28)
[1422492,249]  -> [email protected]_cursor(8686, wl_surface@15, 1, 1)
[1422492,313]  -> [email protected](wl_buffer@52, 0, 0)
[1422492,357]  -> [email protected]_buffer_scale(1)
[1422492,380]  -> [email protected](0, 0, 10, 16)
[1422492,443]  -> [email protected]()
[1422492,466] [email protected]()
[1422508,868] [email protected](wl_output@19)
[1422508,930]  -> [email protected]_cursor(8686, wl_surface@15, 1, 1)
[1422508,983]  -> [email protected](wl_buffer@52, 0, 0)
[1422509,037]  -> [email protected]_buffer_scale(1)
[1422509,057]  -> [email protected](0, 0, 10, 16)
[1422509,103]  -> [email protected]()
[1422509,124] [email protected](8696, wl_surface@28, 19,292969, 2126,281250)
[1422509,193]  -> [email protected]_cursor(8696, wl_surface@15, 1, 1)
[1422509,244]  -> [email protected](wl_buffer@52, 0, 0)
[1422509,292]  -> [email protected]_buffer_scale(1)
[1422509,313]  -> [email protected](0, 0, 10, 16)
[1422509,367]  -> [email protected]()
[1422509,390] [email protected]()
[1422509,431] [email protected](2140865, 18,675781, 2126,281250)
[1422509,492] [email protected]()
[1423509,309] [email protected](8697, wl_surface@28)
[1423509,394]  -> [email protected]_cursor(8696, wl_surface@15, 1, 1)
[1423509,460]  -> [email protected](wl_buffer@52, 0, 0)
[1423509,511]  -> [email protected]_buffer_scale(1)
[1423509,537]  -> [email protected](0, 0, 10, 16)
[1423509,586]  -> [email protected]()
[1423509,609] [email protected]()
[1423821,194] [email protected](wl_output@19)
[1423821,257]  -> [email protected]_cursor(8696, wl_surface@15, 1, 1)
[1423821,312]  -> [email protected](wl_buffer@52, 0, 0)
[1423821,364]  -> [email protected]_buffer_scale(1)
[1423821,388]  -> [email protected](0, 0, 10, 16)
[1423821,441]  -> [email protected]()
[1423821,459] [email protected](8698, wl_surface@28, 18,675781, 2126,281250)
[1423821,533]  -> [email protected]_cursor(8698, wl_surface@15, 1, 1)
[1423821,608]  -> [email protected](wl_buffer@52, 0, 0)
[1423821,661]  -> [email protected]_buffer_scale(1)
[1423821,686]  -> [email protected](0, 0, 10, 16)
[1423821,790]  -> [email protected]()
[1423821,809] [email protected]()
[1423821,858] [email protected](8699, 2142176, 273, 1)
[1423821,918] [email protected]()
[1423825,517]  -> [email protected]()
[1423825,559]  -> [email protected]()
[1423825,574]  -> [email protected]()
[1423825,595]  -> [email protected]()
[1423825,612]  -> [email protected]()
[1423825,713]  -> [email protected]()
[1423825,753]  -> [email protected]()
[1423827,984] [email protected]_id(74)
[1423828,003] [email protected]_id(75)
[1423828,024] [email protected]_id(62)
[1423828,029] [email protected]_id(51)
[1423828,052] [email protected]_id(73)
[1423828,056] [email protected]_id(79)
[1423828,060] [email protected]_id(77)
[1423915,691] [email protected](8700, 2142273, 273, 0)
[1423915,875] [email protected]()
[1424916,256] [email protected](8701, wl_surface@28)
[1424916,332]  -> [email protected]_cursor(8698, wl_surface@15, 1, 1)
[1424916,396]  -> [email protected](wl_buffer@52, 0, 0)
[1424916,448]  -> [email protected]_buffer_scale(1)
[1424916,474]  -> [email protected](0, 0, 10, 16)
[1424916,526]  -> [email protected]()
[1424916,548] [email protected]()
[1425245,292] [email protected](wl_output@19)
[1425245,360]  -> [email protected]_cursor(8698, wl_surface@15, 1, 1)
[1425245,419]  -> [email protected](wl_buffer@52, 0, 0)
[1425245,467]  -> [email protected]_buffer_scale(1)
[1425245,493]  -> [email protected](0, 0, 10, 16)
[1425245,537]  -> [email protected]()
[1425245,556] [email protected](8702, wl_surface@28, 18,675781, 2126,281250)
[1425245,641]  -> [email protected]_cursor(8702, wl_surface@15, 1, 1)
[1425245,706]  -> [email protected](wl_buffer@52, 0, 0)
[1425245,788]  -> [email protected]_buffer_scale(1)
[1425245,805]  -> [email protected](0, 0, 10, 16)
[1425245,841]  -> [email protected]()
[1425245,860] [email protected]()
[1425245,910] [email protected](2143601, 18,046875, 2126,281250)
bug

Most helpful comment

Can you update the Firefox issue to make it clear it's sway specific and likely a sway bug?

The WAYLAND_DEBUG trace looks good to me. I believe this is a damage issue.

All 6 comments

Can you update the Firefox issue to make it clear it's sway specific and likely a sway bug?

The WAYLAND_DEBUG trace looks good to me. I believe this is a damage issue.

Added link to this issue from the Firefox bug report, and mentioned that it only seems to reproduce in Sway out of the 4 compositors I tested.

The post-bug surface creation is very busy, but so far the only difference I have been able to isolate is that the new code utilizes xdg_popup.

Snippet:

[3312253.900] [email protected]_id(56)
[3312321.644] [email protected](18, 9792548, 272, 0)
[3312321.760] [email protected]()
[3312642.210] [email protected](19, 9792869, 273, 1)
[3312642.306] [email protected]()
[3312660.750]  -> [email protected]_surface(new id wl_surface@60)
[3312660.829]  -> [email protected]_positioner(new id xdg_positioner@55)
[3312660.849]  -> [email protected]_size(207, 309)
[3312660.884]  -> [email protected]_anchor_rect(542, 1085, 207, 309)
[3312660.911]  -> [email protected]_offset(0, 0)
[3312660.931]  -> [email protected]_anchor(5)
[3312660.944]  -> [email protected]_gravity(8)
[3312660.954]  -> [email protected]_constraint_adjustment(63)
[3312660.984]  -> [email protected]_xdg_surface(new id xdg_surface@70, wl_surface@60)
[3312661.002]  -> [email protected]_popup(new id xdg_popup@59, xdg_surface@32, xdg_positioner@55)
[3312661.069]  -> [email protected]()
[3312661.096]  -> [email protected]()
[3312662.061]  -> [email protected](new id wl_callback@57)
[3312662.871] [email protected]_id(55)
[3312662.906] [email protected](wl_output@17)
[3312662.917] [email protected](542, 1085, 207, 309)
[3312662.950] [email protected](20)
[3312662.990]  -> [email protected]_configure(20)
[3312663.121]  -> [email protected]_pool(new id wl_shm_pool@55, fd 97, 255852)
[3312663.192]  -> [email protected]_buffer(new id wl_buffer@68, 0, 207, 309, 828, 0)
[3312663.519]  -> [email protected](wl_buffer@68, 0, 0)
[3312663.558]  -> [email protected]_buffer_scale(1)
[3312663.569]  -> [email protected](0, 0, 207, 309)
[3312663.594]  -> [email protected]_window_geometry(0, 0, 207, 309)
[3312663.671]  -> [email protected](new id wl_callback@69)
[3312663.683]  -> [email protected]()
[3312664.033] [email protected]()
[3312664.443] [email protected]()

but so far the only difference I have been able to isolate is that the new code utilizes xdg_popup.

What do you mean?

My bet would be that this is not a protocol issue, but just a sway internal rendering issue.

but so far the only difference I have been able to isolate is that the new code utilizes xdg_popup.

What do you mean?

My bet would be that this is not a protocol issue, but just a sway internal rendering issue.

I also believe that to be the case. Due to not being very familiar with sway/wlroots codebases, I took a quite generic debugging approach: Attempting to trace sway/wlroots behavior between the working and non-working Firefox revisions to locate what difference there may be between the working and non-working surfaces.

The commit/damage part of the two revisions appeared fairly identical to me (including some fprintf debug in sway and wlroots), so my train of thought made me assume that whatever difference there may be, including damage issues on render, would originate from surface configuration. That the broken revision utilizes xdg_popup surfaces could be such a difference.

Still digging around, though.

The problem is subsurfaces of popups.

Firefox creates an xdg_popup with an xdg_positioner whose anchor_rect is set to the desired position. The result of this is a view child in sway, whose root coords is correctly calculated by popup_get_root_coords, the get_root_coords implementation assigned to the view child.

Then, firefox creates a subsurface on this xdg_popup through view_child_handle_surface_new_subsurface. This subsurface does not end up having a handle to the view child of the parent, and utilizes its own get_root_coords implementation which takes its own view child, and any parent subsurfaces into account.

The result is that the subsurface does not take surface->popup->geometry of the parent into account, which is the geometry containing the popup offset, resulting in a 0,0 root for the subsurface.

We need to get a hold of get_root_coords of the parent view child. I made a quick test where a view child can optionally store a pointer to its parent, so that subsurface_get_root_coords can call the parents' root coords implementation, and that did indeed solve the issue. It also segfaults like crazy, likely due to the parent being destroyed before a call to subsurface_get_root_coords, but it was a test.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emersion picture emersion  路  4Comments

soymjolk picture soymjolk  路  3Comments

RyanDwyer picture RyanDwyer  路  3Comments

ddevault picture ddevault  路  4Comments

ddevault picture ddevault  路  3Comments