summaryrefslogtreecommitdiff
path: root/.config
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-10-28 22:05:48 +0200
committerDaniel Weipert <code@drogueronin.de>2023-10-30 09:52:23 +0100
commitc58ca46057301bc93c6fb3e1a1a4933335975885 (patch)
tree311489c431a522922f11e790327f6122f9d50696 /.config
parent985cf78be800e06c497171f542ebac6c1caf8896 (diff)
[sway] check wallpaper brightness at night
only use non-bright images
Diffstat (limited to '.config')
-rwxr-xr-x.config/sway/bin/wallpaper.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/.config/sway/bin/wallpaper.py b/.config/sway/bin/wallpaper.py
index 449e5f3..906b9fe 100755
--- a/.config/sway/bin/wallpaper.py
+++ b/.config/sway/bin/wallpaper.py
@@ -4,6 +4,7 @@
import sys, os
import argparse, json
import random, re, subprocess, time
+import datetime
"""
@@ -93,7 +94,33 @@ while True:
found_file_paths = filtered_file_paths
# select file
- selected_file_path = random.choice(found_file_paths)
+ selected_file_path = ''
+ tries = 0
+ while True:
+ selected_file_path = random.choice(found_file_paths)
+
+ now_hour = datetime.datetime.now().hour
+ if now_hour > 6 and now_hour < 17: # daylight
+ break
+
+ identify_process = subprocess.run(['identify', '-format', '%[fx:mean]', selected_file_path], capture_output=True, text=True)
+ brightness = float(identify_process.stdout)
+ if brightness < 0.35: # non-bright image
+ break
+ else:
+ # remove identified bright image from possible selections
+ found_file_paths.remove(selected_file_path)
+
+ if args.unique:
+ already_selected_file_paths[selected_config['id']].append(selected_file_path)
+
+ # can't find suitable image
+ tries += 1
+ if tries >= len(found_file_paths) - 1:
+ if args.unique:
+ already_selected_file_paths[selected_config['id']] = []
+
+ break
if args.unique:
already_selected_file_paths[selected_config['id']].append(selected_file_path)