Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

window.py 2.4KB

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