summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xinstall/scripts.fish2
-rwxr-xr-xscheme/gen-scheme.fish8
-rwxr-xr-xscheme/getlightness.py8
-rwxr-xr-xscheme/islight.py16
-rwxr-xr-xscheme/resizeimg.py29
6 files changed, 14 insertions, 50 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index c18dd8d..0000000
--- a/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-__pycache__/
diff --git a/install/scripts.fish b/install/scripts.fish
index 54b6068..314d3c1 100755
--- a/install/scripts.fish
+++ b/install/scripts.fish
@@ -2,7 +2,7 @@
. (dirname (status filename))/util.fish
-install-deps git hyprland-git hyprpaper-git okolors-git imagemagick wl-clipboard fuzzel-git socat foot jq python python-pillow python-materialyoucolor-git
+install-deps git hyprland-git hyprpaper-git okolors-git imagemagick wl-clipboard fuzzel-git socat foot jq python
install-optional-deps 'vesktop-bin (discord client)' 'btop (system monitor)' 'wf-recorder (screen recorder)' 'grim (screenshot tool)' 'firefox (web browser)' 'spotify-adblock (music player)'
set -l dist $CONFIG/scripts
diff --git a/scheme/gen-scheme.fish b/scheme/gen-scheme.fish
index 64a2918..d713744 100755
--- a/scheme/gen-scheme.fish
+++ b/scheme/gen-scheme.fish
@@ -15,9 +15,11 @@ set -l colour_names rosewater flamingo pink mauve red maroon peach yellow green
set -l layer_names text subtext1 subtext0 overlay2 overlay1 overlay0 surface2 surface1 surface0 base mantle crust
test -f "$argv[1]" && set -l img "$argv[1]" || set -l img $CACHE/wallpaper/current
-set -l img ($src/resizeimg.py $img)
+set -l img (realpath $img)
-if $src/islight.py $img
+# Light theme if background lighter than foreground
+set -l bg_fg ($src/getlightness.py (okolors $img -k 2 | string split ' '))
+if test "$bg_fg[1]" -gt "$bg_fg[2]"
set light_vals 40,6,8,10,45,50,55,60,65,70,75,80,85,90
set colour_scheme light
else
@@ -27,7 +29,7 @@ end
test "$(cat $CACHE/scheme/current.txt)" = dynamic && gsettings set org.gnome.desktop.interface color-scheme \'prefer-$colour_scheme\'
-set -l colours_raw (okolors (realpath $img) -k 15 -w 0 -l $light_vals)
+set -l colours_raw (okolors $img -k 15 -w 0 -l $light_vals)
set -l colours (string split ' ' $colours_raw[2])[2..]
set -l layers (nl-echo $colours_raw | cut -f 1 -d ' ')[3..]
diff --git a/scheme/getlightness.py b/scheme/getlightness.py
new file mode 100755
index 0000000..956153e
--- /dev/null
+++ b/scheme/getlightness.py
@@ -0,0 +1,8 @@
+#!/bin/python3
+
+import sys
+from colorsys import rgb_to_hls
+
+if __name__ == "__main__":
+ for arg in sys.argv[1:]:
+ print(rgb_to_hls(*tuple(int(arg[i:i+2], 16) for i in (0, 2, 4)))[1])
diff --git a/scheme/islight.py b/scheme/islight.py
deleted file mode 100755
index 1adcf3f..0000000
--- a/scheme/islight.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/python
-
-import sys
-from PIL import Image
-from materialyoucolor.quantize import QuantizeCelebi
-from materialyoucolor.score.score import Score
-from materialyoucolor.hct import Hct
-from resizeimg import resize
-
-
-if __name__ == "__main__":
- with Image.open(sys.argv[1]) as img:
- img = resize(img)[0]
- colours = QuantizeCelebi(list(img.getdata()), 128)
- hct = Hct.from_int(Score.score(colours)[0])
- sys.exit(0 if hct.tone > 60 else 1)
diff --git a/scheme/resizeimg.py b/scheme/resizeimg.py
deleted file mode 100755
index e18ffb8..0000000
--- a/scheme/resizeimg.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/python
-
-import sys
-import math
-from PIL import Image
-
-
-def calc_size(w, h, b = 128):
- ia = w * h
- ba = b * b
- s = math.sqrt(ba / ia) if ia > ba else 1
- return max(1, round(w * s)), max(1, round(h * s))
-
-
-def resize(img):
- w, h = calc_size(img.width, img.height)
- if w < img.width or h < img.height:
- return img.resize((w, h), Image.Resampling.BICUBIC), True
- return img, False
-
-
-if __name__ == "__main__":
- with Image.open(sys.argv[1]) as img:
- img, resized = resize(img)
- if resized:
- img.save("/tmp/caelestia-resize.png")
- print("/tmp/caelestia-resize.png")
- else:
- print(sys.argv[1])