test_kde.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. processes = [_engine(kde, engine, log, output) for log, output in zip(logs, outputs)]
  63. probe = None
  64. try:
  65. time.sleep(8)
  66. assert all(_renders(log) for log in logs)
  67. probe = _window(kde, "maximized")
  68. time.sleep(4)
  69. rendering = [_renders(log) for log in logs]
  70. assert rendering.count(False) == 1, f"a maximized window should pause exactly its own output: {rendering}"
  71. finally:
  72. if probe is not None:
  73. terminate([probe.pid])
  74. for process in processes:
  75. process.terminate()
  76. process.wait(10)
  77. def test_plasma5(desktop_factory, engine, tmp_path):
  78. """KWin 5.27 runs both scripts (/<id>, not /Scripting/Script<id>); the window script says it needs Plasma 6"""
  79. kde5 = desktop_factory("kde5")
  80. log = tmp_path / "engine.log"
  81. process = _engine(kde5, engine, log, kde5.output_names()[0])
  82. probe = None
  83. try:
  84. time.sleep(8)
  85. assert _renders(log), "the engine does not render on Plasma 5"
  86. text = log.read_text(errors="replace")
  87. assert "could not load its KWin script" not in text
  88. assert "KDE window detection needs Plasma 6" in text
  89. probe = _window(kde5, "maximized")
  90. time.sleep(4)
  91. assert _renders(log), "a maximized window paused the wallpaper without window detection"
  92. finally:
  93. if probe is not None:
  94. terminate([probe.pid])
  95. process.terminate()
  96. process.wait(10)
  97. def test_script_ids_stay_unique_after_an_unload(kde, tmp_path):
  98. """KWin 6.4 numbers scripts by how many are loaded, after an unload the next one got the id of a live script
  99. (KWinScript works around it); this tells whether the KWin of this lab still does that"""
  100. scripts = []
  101. for name in ("a", "b", "c"):
  102. path = tmp_path / f"{name}.js"
  103. path.write_text("print('lwe-id-probe');\n")
  104. scripts.append(path)
  105. def call(method, *args):
  106. result = kde.run(["gdbus", "call", "--session", "--dest", "org.kde.KWin", "--object-path", "/Scripting",
  107. "--method", f"org.kde.kwin.Scripting.{method}", *args])
  108. assert result.returncode == 0, result.stderr
  109. return result.stdout.strip()
  110. def load(path, name):
  111. return int(call("loadScript", str(path), name).strip("(), \n"))
  112. first = load(scripts[0], "lwe-id-a")
  113. second = load(scripts[1], "lwe-id-b")
  114. call("unloadScript", "lwe-id-a")
  115. third = load(scripts[2], "lwe-id-c")
  116. for name in ("lwe-id-b", "lwe-id-c"):
  117. call("unloadScript", name)
  118. if third == second:
  119. pytest.xfail(f"this KWin hands the id {second} of a live script to the next one (ids {first}, {second}, {third})")