test_kde.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """KDE Plasma: the KWin window-state script pauses only the affected output."""
  2. import time
  3. from pathlib import Path
  4. import pytest
  5. from conftest import REPO
  6. from desktops.runner import terminate
  7. def _engine(desktop, engine, log, output, *extra):
  8. return desktop.client([engine["binary"], "--assets-dir", engine["assets"], "--screen-root", output, "--silent",
  9. "--fps", "30", *extra, engine["wallpaper"]], log=log, env={"LWE_FRAME_STATS": "1"})
  10. def _renders(log, seconds=5):
  11. before = Path(log).read_text(errors="replace").count("FRAME-STATS")
  12. time.sleep(seconds)
  13. return Path(log).read_text(errors="replace").count("FRAME-STATS") > before
  14. def _window(desktop, mode):
  15. return desktop.spawn(f"{mode}-probe", ["python3", str(REPO / "tools/desktops/wayland_window.py"), mode])
  16. @pytest.fixture
  17. def kde(desktop_factory):
  18. return desktop_factory("kde")
  19. @pytest.mark.parametrize("mode", ["maximized", "fullscreen"])
  20. def test_covering_window_pauses_rendering(kde, engine, tmp_path, mode):
  21. log = tmp_path / "engine.log"
  22. process = _engine(kde, engine, log, kde.output_names()[0])
  23. probe = None
  24. try:
  25. time.sleep(8)
  26. assert _renders(log), "the engine does not render on KDE"
  27. probe = _window(kde, mode)
  28. time.sleep(4)
  29. assert not _renders(log), f"still rendering under a {mode} window"
  30. terminate([probe.pid])
  31. probe = None
  32. time.sleep(4)
  33. assert _renders(log), f"rendering did not resume after the {mode} window"
  34. finally:
  35. if probe is not None:
  36. terminate([probe.pid])
  37. process.terminate()
  38. process.wait(10)
  39. @pytest.mark.parametrize("pause_on_focus", [False, True])
  40. def test_focused_window(kde, engine, tmp_path, pause_on_focus):
  41. log = tmp_path / "engine.log"
  42. process = _engine(kde, engine, log, kde.output_names()[0], *(["--pause-on-focus"] if pause_on_focus else []))
  43. probe = None
  44. try:
  45. time.sleep(8)
  46. probe = _window(kde, "normal")
  47. time.sleep(4)
  48. if pause_on_focus:
  49. assert not _renders(log), "--pause-on-focus kept rendering while another application had the focus"
  50. else:
  51. assert _renders(log), "a plain window paused the wallpaper"
  52. finally:
  53. if probe is not None:
  54. terminate([probe.pid])
  55. process.terminate()
  56. process.wait(10)
  57. def test_pause_is_per_output(desktop_factory, engine, tmp_path):
  58. kde = desktop_factory("kde-dual")
  59. outputs = kde.output_names()
  60. assert len(outputs) == 2, outputs
  61. logs = [tmp_path / f"engine-{output}.log" for output in outputs]
  62. # one engine per screen, like we_manager
  63. processes = [_engine(kde, engine, log, output) for log, output in zip(logs, outputs)]
  64. probe = None
  65. try:
  66. time.sleep(8)
  67. assert all(_renders(log) for log in logs)
  68. probe = _window(kde, "maximized")
  69. time.sleep(4)
  70. rendering = [_renders(log) for log in logs]
  71. assert rendering.count(False) == 1, f"a maximized window should pause exactly its own output: {rendering}"
  72. finally:
  73. if probe is not None:
  74. terminate([probe.pid])
  75. for process in processes:
  76. process.terminate()
  77. process.wait(10)
  78. def test_plasma5(desktop_factory, engine, tmp_path):
  79. """KWin 5.27 runs both scripts (/<id>, not /Scripting/Script<id>); the window script says it needs Plasma 6"""
  80. kde5 = desktop_factory("kde5")
  81. log = tmp_path / "engine.log"
  82. process = _engine(kde5, engine, log, kde5.output_names()[0])
  83. probe = None
  84. try:
  85. time.sleep(8)
  86. assert _renders(log), "the engine does not render on Plasma 5"
  87. text = log.read_text(errors="replace")
  88. assert "could not load its KWin script" not in text
  89. assert "KDE window detection needs Plasma 6" in text
  90. probe = _window(kde5, "maximized")
  91. time.sleep(4)
  92. assert _renders(log), "a maximized window paused the wallpaper without window detection"
  93. finally:
  94. if probe is not None:
  95. terminate([probe.pid])
  96. process.terminate()
  97. process.wait(10)