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