From c58ca46057301bc93c6fb3e1a1a4933335975885 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 28 Oct 2023 22:05:48 +0200 Subject: [sway] check wallpaper brightness at night only use non-bright images --- .config/sway/bin/wallpaper.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to '.config/sway') 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) -- cgit v1.2.3