Browse Source

fix some kwin json issues. tweak values for influx.

Thomas B 1 month ago
parent
commit
a42c4bb29e
3 changed files with 21 additions and 6 deletions
  1. 11
    4
      client/brightness.py
  2. 2
    1
      client/kwin_check.js
  3. 8
    1
      client/window.py

+ 11
- 4
client/brightness.py View File

@@ -24,7 +24,7 @@ def cal(v, c):
24 24
     return c[1] + c[0] * c_in[0] * max(0, c_in[1] + v)
25 25
 
26 26
 def filter_lux(old, new):
27
-    return (old * filter_fact) + (new * (1.0 - filter_fact))
27
+    return max(0.1, (old * filter_fact) + (new * (1.0 - filter_fact)))
28 28
 
29 29
 def lux_to_disp(name, val):
30 30
     if name in calibration:
@@ -93,10 +93,17 @@ if __name__ == "__main__":
93 93
         if (time.time() - time_window) > 20.0:
94 94
             time_window = time.time()
95 95
             info = window.query()
96
+
96 97
             if info["fullscreen"] and is_active:
97
-                print("App \"{}\" is now fullscreen! Pausing.".format(info["name"]))
98
+                print("{}: App \"{}\" is now fullscreen! Pausing.".format(time.ctime(), info["name"]))
99
+
98 100
             if (not info["fullscreen"]) and (not is_active):
99
-                print("No longer fullscreen. Continuing.")
101
+                print("{}: No longer fullscreen. Continuing.".format(time.ctime()))
102
+
103
+                # re-apply previous brightness values soon
104
+                for d in disps:
105
+                    d["prev"] = -1
106
+
100 107
             is_active = not info["fullscreen"]
101 108
 
102 109
         # set displays at most every 10s
@@ -114,4 +121,4 @@ if __name__ == "__main__":
114 121
                         print(e)
115 122
 
116 123
                         # set to zero to show display is disconnected
117
-                        d["prev"] = 0
124
+                        d["prev"] = -1

+ 2
- 1
client/kwin_check.js View File

@@ -2,4 +2,5 @@ var win = workspace.activeWindow;
2 2
 var name = win.caption;
3 3
 var pid = win.pid;
4 4
 var state = (win.bufferGeometry == win.output.geometry);
5
-print('{ "name": "' + name + '", "pid": ' + pid + ', "fullscreen": ' + state + ' }');
5
+var obj = { name: name, pid: pid, fullscreen: state };
6
+print(JSON.stringify(obj));

+ 8
- 1
client/window.py View File

@@ -4,6 +4,7 @@ import os
4 4
 import subprocess
5 5
 from datetime import datetime
6 6
 import json
7
+import time
7 8
 
8 9
 max_comm_retries = 5
9 10
 
@@ -44,7 +45,11 @@ def query_internal(verbose=False):
44 45
         print("Errs 4", result.stderr.decode("utf-8"))
45 46
 
46 47
     msg = result.stdout.decode().rstrip().split("\n")[0][4:]
47
-    return json.loads(msg)
48
+    try:
49
+        return json.loads(msg)
50
+    except Exception as e:
51
+        print("Failed msg: \"{}\"".format(msg))
52
+        raise e
48 53
 
49 54
 def query(verbose=False):
50 55
     for attempts in range(0, max_comm_retries):
@@ -53,6 +58,8 @@ def query(verbose=False):
53 58
         except Exception as e:
54 59
             if attempts >= (max_comm_retries - 1):
55 60
                 raise e
61
+            else:
62
+                time.sleep(0.5)
56 63
 
57 64
 if __name__ == "__main__":
58 65
     info = query()

Loading…
Cancel
Save