Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. import os
  3. import subprocess
  4. from datetime import datetime
  5. import json
  6. max_comm_retries = 5
  7. # https://unix.stackexchange.com/a/776620
  8. def query_internal(verbose=False):
  9. dir_path = os.path.abspath(os.path.dirname(__file__))
  10. file_path = os.path.join(dir_path, "kwin_check.js")
  11. datetime_now = datetime.now()
  12. result = subprocess.run("dbus-send --print-reply --dest=org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript string:" + file_path, capture_output=True, shell=True)
  13. if verbose and result.stdout:
  14. print("Output 1", result.stdout.decode("utf-8"))
  15. if verbose and result.stderr:
  16. print("Errs 1", result.stderr.decode("utf-8"))
  17. n = result.stdout.decode("utf-8").split("\n")[1].split()[1]
  18. if verbose:
  19. print("Script ID", n)
  20. result = subprocess.run("dbus-send --print-reply --dest=org.kde.KWin /Scripting/Script" + n + " org.kde.kwin.Script.run", capture_output=True, shell=True)
  21. if verbose and result.stdout:
  22. print("Output 2", result.stdout.decode("utf-8"))
  23. if verbose and result.stderr:
  24. print("Errs 2", result.stderr.decode("utf-8"))
  25. result = subprocess.run("dbus-send --print-reply --dest=org.kde.KWin /Scripting/Script" + n + " org.kde.kwin.Script.stop", capture_output=True, shell=True)
  26. if verbose and result.stdout:
  27. print("Output 3", result.stdout.decode("utf-8"))
  28. if verbose and result.stderr:
  29. print("Errs 3", result.stderr.decode("utf-8"))
  30. since = str(datetime_now)
  31. result = subprocess.run("journalctl _COMM=kwin_wayland -o cat --since \"" + since + "\"", capture_output=True, shell=True)
  32. if verbose and result.stdout:
  33. print("Output 4", result.stdout.decode("utf-8"))
  34. if verbose and result.stderr:
  35. print("Errs 4", result.stderr.decode("utf-8"))
  36. msg = result.stdout.decode().rstrip().split("\n")[0][4:]
  37. return json.loads(msg)
  38. def query(verbose=False):
  39. for attempts in range(0, max_comm_retries):
  40. try:
  41. return query_internal(verbose)
  42. except Exception as e:
  43. if attempts >= (max_comm_retries - 1):
  44. raise e
  45. if __name__ == "__main__":
  46. info = query()
  47. print("Name: \"{}\"".format(info["name"]))
  48. print("PID: {}".format(info["pid"]))
  49. print("Fullscreen: {}".format(info["fullscreen"]))