test_gnome.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. """GNOME on Wayland via the Shell extension: desktop window, per monitor pause, desktop menu, extension removal."""
  2. import time
  3. from pathlib import Path
  4. import pytest
  5. from conftest import REPO, changed_fraction
  6. from desktops.runner import terminate
  7. UUID = "linux-wallpaperengine@wallpaperenginelover.github.io"
  8. WALLPAPER = "global.get_window_actors().map(a => a.meta_window).find(w => w.get_wm_class() === 'linux-wallpaperengine')"
  9. POINTER = ("const C = imports.gi.Clutter, G = imports.gi.GLib;"
  10. "if (!global._lweLabPointer) global._lweLabPointer = C.get_default_backend().get_default_seat()"
  11. ".create_virtual_device(C.InputDeviceType.POINTER_DEVICE);"
  12. "const pointer = global._lweLabPointer, now = () => G.get_monotonic_time();")
  13. CLICK_PROBE = REPO / "tests/desktops/fixtures/clickprobe"
  14. def _engine(desktop, engine, log, *extra, wallpaper=None):
  15. return desktop.client([engine["binary"], "--assets-dir", engine["assets"], "--screen-root",
  16. desktop.output_names()[0], "--silent", "--fps", "30", *extra,
  17. str(wallpaper or engine["wallpaper"])],
  18. log=log, env={"LWE_FRAME_STATS": "1", "LWE_SCRIPT_LOG": "1"})
  19. def _point(desktop, x, y):
  20. """moves the lab's virtual pointer, again until the Shell has it (it sometimes keeps an older position)"""
  21. # the hot corner at the start position opens the overview
  22. desktop.eval(POINTER + f"pointer.notify_absolute_motion(now(), {x}, {y}); 1")
  23. time.sleep(0.5)
  24. desktop.eval("Main.overview.hide(); 1")
  25. time.sleep(0.5)
  26. for _ in range(20):
  27. desktop.eval(POINTER + f"pointer.notify_absolute_motion(now(), {x}, {y}); 1")
  28. time.sleep(0.25)
  29. if desktop.eval("global.get_pointer().slice(0, 2).join(',')") == f'"{x},{y}"':
  30. return
  31. raise AssertionError(f"the virtual pointer never got to {x},{y}")
  32. def _click(desktop, button=1):
  33. desktop.eval(POINTER + f"pointer.notify_button(now(), {button}, C.ButtonState.PRESSED); 1")
  34. time.sleep(0.3)
  35. desktop.eval(POINTER + f"pointer.notify_button(now(), {button}, C.ButtonState.RELEASED); 1")
  36. def _frame_lines(log):
  37. return Path(log).read_text(errors="replace").count("FRAME-STATS")
  38. def _window(desktop, mode, name=None):
  39. """a GTK probe window, focused like a user would: Mutter maps it without the focus when the session never saw
  40. any input (focus stealing prevention), and WE counts only the focused window as fullscreen"""
  41. process = desktop.spawn(name or f"{mode}-probe", ["python3", str(REPO / "tools/desktops/wayland_window.py"), mode])
  42. title = f"lwe-{mode}-probe"
  43. for _ in range(40):
  44. time.sleep(0.25)
  45. if desktop.eval(f"const w = global.display.list_all_windows().find(w => w.get_title() === '{title}');"
  46. "if (w) w.activate(global.display.get_current_time_roundtrip()); !!w") == "true":
  47. break
  48. return process
  49. def _renders(log, seconds=5):
  50. before = _frame_lines(log)
  51. time.sleep(seconds)
  52. return _frame_lines(log) > before
  53. # 49/50: Meta.Window.set_type, 46-48: helper's Meta.WaylandClient, 45: bottom normal-layer window
  54. @pytest.fixture(params=["gnome", "gnome49", "gnome48", "gnome47", "gnome46", "gnome45"])
  55. def gnome(request, desktop_factory):
  56. return desktop_factory(request.param)
  57. def test_wallpaper_is_a_desktop_window(gnome, engine, tmp_path):
  58. process = _engine(gnome, engine, tmp_path / "engine.log")
  59. try:
  60. time.sleep(8)
  61. assert process.poll() is None, (tmp_path / "engine.log").read_text()[-1500:]
  62. state = gnome.eval(f"const w = {WALLPAPER}; const r = w.get_frame_rect();"
  63. "[w.get_window_type(), w.skip_taskbar, w.is_fullscreen(), r.width, r.height].join(',')")
  64. width, height = gnome.size
  65. if gnome.name == "gnome45":
  66. # 45: normal window hidden from the window lists, kept in the work area
  67. window_type, skip, fullscreen, frame_width, frame_height = state.strip('"').split(",")
  68. assert (window_type, skip, fullscreen, frame_width) == ("0", "true", "false", str(width))
  69. assert int(frame_height) >= height - 64
  70. else:
  71. # Meta.WindowType.DESKTOP
  72. assert state == f'"1,true,false,{width},{height}"'
  73. assert gnome.eval("global.display.get_monitor_in_fullscreen(0)") == "false"
  74. assert gnome.eval("Shell.AppSystem.get_default().get_running().length") == "0"
  75. finally:
  76. process.terminate()
  77. process.wait(10)
  78. @pytest.mark.parametrize("mode", ["maximized", "fullscreen"])
  79. def test_covering_window_pauses_rendering(gnome, engine, tmp_path, mode):
  80. log = tmp_path / "engine.log"
  81. process = _engine(gnome, engine, log)
  82. probe = None
  83. try:
  84. time.sleep(8)
  85. assert _renders(log), "the engine does not render on GNOME"
  86. probe = _window(gnome, mode)
  87. time.sleep(4)
  88. assert not _renders(log), f"still rendering under a {mode} window"
  89. terminate([probe.pid])
  90. probe = None
  91. time.sleep(4)
  92. assert _renders(log), f"rendering did not resume after the {mode} window"
  93. normal = _window(gnome, "normal")
  94. try:
  95. time.sleep(4)
  96. assert _renders(log), "a plain window paused the wallpaper"
  97. finally:
  98. terminate([normal.pid])
  99. finally:
  100. if probe is not None:
  101. terminate([probe.pid])
  102. process.terminate()
  103. process.wait(10)
  104. def test_desktop_menu_opens_over_the_wallpaper(gnome, engine, tmp_path):
  105. process = _engine(gnome, engine, tmp_path / "engine.log")
  106. try:
  107. width, height = gnome.size
  108. gnome.eval(POINTER + f"pointer.notify_absolute_motion(now(), {width // 2}, {height // 2}); 1")
  109. time.sleep(0.5)
  110. gnome.eval("Main.overview.hide(); 1")
  111. time.sleep(8)
  112. # the lab pointer sometimes lags, resend until the Shell has it
  113. target = f"{width // 2},{height // 2}"
  114. for _ in range(20):
  115. gnome.eval(POINTER + f"pointer.notify_absolute_motion(now(), {width // 2}, {height // 2}); 1")
  116. time.sleep(0.25)
  117. if gnome.eval("global.get_pointer().slice(0, 2).join(',')") == f'"{target}"':
  118. break
  119. gnome.shot(tmp_path / "before.png")
  120. gnome.eval(POINTER + "pointer.notify_button(now(), 3, C.ButtonState.PRESSED);"
  121. "pointer.notify_button(now() + 20000, 3, C.ButtonState.RELEASED); 1")
  122. time.sleep(2)
  123. opened = gnome.eval("Main.layoutManager._bgManagers.some(m => m.backgroundActor._backgroundMenu?.isOpen)")
  124. gnome.shot(tmp_path / "after.png")
  125. gnome.eval("Main.layoutManager._bgManagers.forEach(m => m.backgroundActor._backgroundMenu?.close()); 1")
  126. assert opened == "true", "a right click on the wallpaper did not reach GNOME's desktop menu"
  127. assert changed_fraction(tmp_path / "before.png", tmp_path / "after.png") > 0.01
  128. finally:
  129. process.terminate()
  130. process.wait(10)
  131. def test_engine_stops_without_the_extension(gnome, engine, tmp_path):
  132. log = tmp_path / "engine.log"
  133. process = _engine(gnome, engine, log)
  134. try:
  135. time.sleep(6)
  136. assert process.poll() is None
  137. gnome.run(["gnome-extensions", "disable", UUID])
  138. process.wait(10)
  139. assert "GNOME Shell extension went away" in log.read_text(errors="replace")
  140. deadline = time.monotonic() + 10
  141. while gnome.eval(f"!!{WALLPAPER}") != "false" and time.monotonic() < deadline:
  142. time.sleep(0.5)
  143. assert gnome.eval(f"!!{WALLPAPER}") == "false", "the wallpaper window outlived the extension"
  144. refused = _engine(gnome, engine, tmp_path / "refused.log")
  145. assert refused.wait(20) != 0
  146. assert "without the GNOME Shell extension" in (tmp_path / "refused.log").read_text(errors="replace")
  147. finally:
  148. gnome.run(["gnome-extensions", "enable", UUID])
  149. if process.poll() is None:
  150. process.terminate()
  151. process.wait(10)
  152. def test_overview_shows_the_live_wallpaper(gnome, engine, tmp_path):
  153. log = tmp_path / "engine.log"
  154. gnome.eval("Main.overview.show(); 1")
  155. time.sleep(3)
  156. gnome.shot(tmp_path / "bare.png")
  157. gnome.eval("Main.overview.hide(); 1")
  158. time.sleep(2)
  159. process = _engine(gnome, engine, log)
  160. try:
  161. time.sleep(8)
  162. gnome.eval("Main.overview.show(); 1")
  163. time.sleep(3)
  164. gnome.shot(tmp_path / "overview.png")
  165. # only the clones keep frame callbacks coming in the overview
  166. assert _renders(log), "the wallpaper stopped rendering in the overview"
  167. assert changed_fraction(tmp_path / "bare.png", tmp_path / "overview.png") > 0.2, \
  168. "the overview still shows GNOME's own background"
  169. finally:
  170. gnome.eval("Main.overview.hide(); 1")
  171. process.terminate()
  172. process.wait(10)
  173. def test_focused_window_pauses_with_pause_on_focus(gnome, engine, tmp_path):
  174. log = tmp_path / "engine.log"
  175. process = _engine(gnome, engine, log, "--pause-on-focus")
  176. probe = None
  177. try:
  178. time.sleep(8)
  179. assert _renders(log), "the engine does not render on GNOME"
  180. probe = _window(gnome, "normal", "focus-probe")
  181. time.sleep(4)
  182. assert not _renders(log), "--pause-on-focus kept rendering while another application had the focus"
  183. terminate([probe.pid])
  184. probe = None
  185. time.sleep(4)
  186. assert _renders(log), "rendering did not resume once the focused window was gone"
  187. finally:
  188. if probe is not None:
  189. terminate([probe.pid])
  190. process.terminate()
  191. process.wait(10)
  192. # DING: own desktop window on GNOME 50, bottom-layer normal one on Ubuntu 46
  193. @pytest.fixture(params=["gnome-ding", "gnome46-ding", "gnome45-ding"])
  194. def ding(request, desktop_factory):
  195. return desktop_factory(request.param)
  196. def test_wallpaper_stays_under_desktop_icons(ding, engine, tmp_path):
  197. log = tmp_path / "engine.log"
  198. process = _engine(ding, engine, log, "--pause-on-focus", wallpaper=CLICK_PROBE)
  199. try:
  200. time.sleep(8)
  201. order = ding.eval("global.display.sort_windows_by_stacking(global.display.list_all_windows())"
  202. ".map(w => w.get_gtk_application_id() || w.get_wm_class()).join('|')").strip('"').split("|")
  203. icons = order.index("com.rastersoft.ding")
  204. wallpaper = order.index("linux-wallpaperengine")
  205. assert wallpaper < icons, f"the wallpaper is above the desktop icons: {order}"
  206. # WE counts the icon view as the desktop: clicks reach the wallpaper, focusing it isn't another app
  207. width, height = ding.size
  208. _point(ding, width // 2, height // 2)
  209. _click(ding)
  210. time.sleep(1.5)
  211. text = log.read_text(errors="replace")
  212. assert "LWE-CLICK down" in text and "LWE-CLICK up" in text, "the click on the desktop never reached the wallpaper"
  213. assert ding.eval("global.display.focus_window?.get_gtk_application_id() ?? ''") == '"com.rastersoft.ding"'
  214. assert _renders(log), "focusing the desktop icons paused the wallpaper"
  215. finally:
  216. process.terminate()
  217. process.wait(10)