No Description
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.

window.py 2.0KB

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