summarylogtreecommitdiffstats
path: root/swaydim
diff options
context:
space:
mode:
authorfossdd2024-04-01 21:42:14 +0000
committerfossdd2024-04-01 21:42:14 +0000
commitcfa64f09fdd324944c29c502aaef31c5de0b9c1f (patch)
tree0e55d34b3db8ffcf54fa9764d9383d14c9257f8c /swaydim
downloadaur-swaydim.tar.gz
upgpkg: swaydim 1-1
Diffstat (limited to 'swaydim')
-rwxr-xr-xswaydim47
1 files changed, 47 insertions, 0 deletions
diff --git a/swaydim b/swaydim
new file mode 100755
index 000000000000..b1b29bfdde3e
--- /dev/null
+++ b/swaydim
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+#
+# Dims your display using brightnessctl
+#
+
+import subprocess
+import os
+import sys
+
+default_multiplier = 0.1
+
+def run(cmd):
+ print(cmd)
+ process = subprocess.run(
+ cmd.split(" "),
+ capture_output=True,
+ text = True
+ )
+ return process.stdout.strip("\n")
+
+def brightnessctl(args):
+ template = "brightnessctl {args}"
+ cmd = template.format(
+ args = args
+ )
+ return run(cmd)
+
+def multiplier():
+ if len(sys.argv) == 2:
+ return float(sys.argv[1])
+ else:
+ return float(default_multiplier)
+
+path = "/tmp/brightness-" + str(multiplier())
+
+if os.path.exists(path):
+ with open(path, "r") as file:
+ brightnessctl("set {brightness}".format(brightness=file.readlines()[0]))
+ os.remove(path)
+else:
+ current_brightness = brightnessctl("get")
+
+ with open(path, "w") as file:
+ file.write(current_brightness)
+
+ new_brightness = int(current_brightness) * multiplier()
+ brightnessctl("set {new_brightness}".format(new_brightness=new_brightness))