Browse Source

fix some kwin json issues. tweak values for influx.

Thomas B 2 months 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
     return c[1] + c[0] * c_in[0] * max(0, c_in[1] + v)
24
     return c[1] + c[0] * c_in[0] * max(0, c_in[1] + v)
25
 
25
 
26
 def filter_lux(old, new):
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
 def lux_to_disp(name, val):
29
 def lux_to_disp(name, val):
30
     if name in calibration:
30
     if name in calibration:
93
         if (time.time() - time_window) > 20.0:
93
         if (time.time() - time_window) > 20.0:
94
             time_window = time.time()
94
             time_window = time.time()
95
             info = window.query()
95
             info = window.query()
96
+
96
             if info["fullscreen"] and is_active:
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
             if (not info["fullscreen"]) and (not is_active):
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
             is_active = not info["fullscreen"]
107
             is_active = not info["fullscreen"]
101
 
108
 
102
         # set displays at most every 10s
109
         # set displays at most every 10s
114
                         print(e)
121
                         print(e)
115
 
122
 
116
                         # set to zero to show display is disconnected
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
 var name = win.caption;
2
 var name = win.caption;
3
 var pid = win.pid;
3
 var pid = win.pid;
4
 var state = (win.bufferGeometry == win.output.geometry);
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
 import subprocess
4
 import subprocess
5
 from datetime import datetime
5
 from datetime import datetime
6
 import json
6
 import json
7
+import time
7
 
8
 
8
 max_comm_retries = 5
9
 max_comm_retries = 5
9
 
10
 
44
         print("Errs 4", result.stderr.decode("utf-8"))
45
         print("Errs 4", result.stderr.decode("utf-8"))
45
 
46
 
46
     msg = result.stdout.decode().rstrip().split("\n")[0][4:]
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
 def query(verbose=False):
54
 def query(verbose=False):
50
     for attempts in range(0, max_comm_retries):
55
     for attempts in range(0, max_comm_retries):
53
         except Exception as e:
58
         except Exception as e:
54
             if attempts >= (max_comm_retries - 1):
59
             if attempts >= (max_comm_retries - 1):
55
                 raise e
60
                 raise e
61
+            else:
62
+                time.sleep(0.5)
56
 
63
 
57
 if __name__ == "__main__":
64
 if __name__ == "__main__":
58
     info = query()
65
     info = query()

Loading…
Cancel
Save