Compare commits
1 commit
dev
...
feat/themi
| Author | SHA1 | Date | |
|---|---|---|---|
| e4e59c52fa |
3 changed files with 59 additions and 15 deletions
|
|
@ -7,9 +7,11 @@ in {
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
libnotify
|
jq # JSON parser
|
||||||
|
libnotify # Notifications
|
||||||
|
sunwait # Sunrise/sunset calculator
|
||||||
|
|
||||||
playerctl
|
playerctl
|
||||||
jq
|
|
||||||
j4-dmenu-desktop
|
j4-dmenu-desktop
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,27 @@ STATE_DIR="${HOME}/.local/state/sisyphus"
|
||||||
STATE_FILE="${STATE_DIR}/theme"
|
STATE_FILE="${STATE_DIR}/theme"
|
||||||
BG_DIR="${HOME}/Nextcloud/Afbeeldingen/wallpapers"
|
BG_DIR="${HOME}/Nextcloud/Afbeeldingen/wallpapers"
|
||||||
|
|
||||||
|
LATITUDE='50.50N' # Belgium
|
||||||
|
LONGITUDE='4.00E'
|
||||||
|
|
||||||
|
# Mapping inputs to themes
|
||||||
|
|
||||||
|
declare -A theme_name
|
||||||
|
theme_name['light']="${THEME_LIGHT}"
|
||||||
|
theme_name['dark']="${THEME_DARK}"
|
||||||
|
|
||||||
|
declare -A theme_time
|
||||||
|
theme_time['DAY']="${THEME_LIGHT}"
|
||||||
|
theme_time['NIGHT']="${THEME_DARK}"
|
||||||
|
|
||||||
|
# Mapping of current theme to next theme
|
||||||
|
|
||||||
declare -A theme_next
|
declare -A theme_next
|
||||||
theme_next[${THEME_LIGHT}]="${THEME_DARK}"
|
theme_next[${THEME_LIGHT}]="${THEME_DARK}"
|
||||||
theme_next[${THEME_DARK}]="${THEME_LIGHT}"
|
theme_next[${THEME_DARK}]="${THEME_LIGHT}"
|
||||||
|
|
||||||
|
# Mapping of theme to applications
|
||||||
|
|
||||||
declare -A gsettings_alt
|
declare -A gsettings_alt
|
||||||
gsettings_alt[${THEME_LIGHT}]='default'
|
gsettings_alt[${THEME_LIGHT}]='default'
|
||||||
gsettings_alt[${THEME_DARK}]='prefer-dark'
|
gsettings_alt[${THEME_DARK}]='prefer-dark'
|
||||||
|
|
@ -35,17 +52,14 @@ wallpaper[${THEME_DARK}]="bg-dark"
|
||||||
#############
|
#############
|
||||||
|
|
||||||
# Parse options
|
# Parse options
|
||||||
while getopts ":m:g" option; do
|
while getopts ":m:gt" option; do
|
||||||
case "${option}" in
|
case "${option}" in
|
||||||
m)
|
m)
|
||||||
if [ "${OPTARG}" == 'light' ]; then
|
if [ -z "${theme_name[${OPTARG}]}" ]; then
|
||||||
theme="${THEME_LIGHT}"
|
|
||||||
elif [ "${OPTARG}" == 'dark' ]; then
|
|
||||||
theme="${THEME_DARK}"
|
|
||||||
else
|
|
||||||
>&2 printf "Error: Invalid mode: '%s'.\nShould be either 'light' or 'dark'\n" "${option}"
|
>&2 printf "Error: Invalid mode: '%s'.\nShould be either 'light' or 'dark'\n" "${option}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
theme="${theme_name[${OPTARG}]}"
|
||||||
;;
|
;;
|
||||||
g)
|
g)
|
||||||
current_state="$(cat "${STATE_FILE}")"
|
current_state="$(cat "${STATE_FILE}")"
|
||||||
|
|
@ -58,6 +72,22 @@ while getopts ":m:g" option; do
|
||||||
"${gsettings_alt[${current_state}]}" "${next_state}" "${percentage:=0}" "${class:="none"}"
|
"${gsettings_alt[${current_state}]}" "${next_state}" "${percentage:=0}" "${class:="none"}"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
t)
|
||||||
|
if ! [ "$(command -v sunwait)" ]; then
|
||||||
|
>&2 printf "Error: sunwait command not found. Please install sunwait or do not use the -t option.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_time="$(sunwait poll "${LATITUDE}" "${LONGITUDE}")"
|
||||||
|
|
||||||
|
if [ -z "${current_time}" ] || [ -z "${theme_time[${current_time}]}" ]; then
|
||||||
|
>&2 printf "Error: Invalid time returned by sunwait: '%s'.\nInspect the script for more details.\n" "${current_time}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
theme="${theme_time[${current_time}]}"
|
||||||
|
printf "Setting theme based on time of day: %s -> %s\n" "${current_time}" "${theme}"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
>&2 printf "Error: Invalid option: '%s'.\n" "${option}"
|
>&2 printf "Error: Invalid option: '%s'.\n" "${option}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -67,16 +97,26 @@ done
|
||||||
shift $(( OPTIND - 1 ))
|
shift $(( OPTIND - 1 ))
|
||||||
|
|
||||||
# Check if the state file exists
|
# Check if the state file exists
|
||||||
if ! [ -d "$(dirname ${STATE_FILE})" ]; then
|
if ! [ -d "$(dirname "${STATE_FILE}")" ]; then
|
||||||
mkdir -p "$(dirname ${STATE_FILE})"
|
mkdir -p "$(dirname "${STATE_FILE}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Choose next theme
|
# Determine the theme to set
|
||||||
previous_theme="$(cat ${STATE_FILE})"
|
if [ -z "${theme}" ]; then
|
||||||
if ! [[ -z "${previous_theme}" || "${theme}" ]]; then
|
# Read from state file
|
||||||
theme="${theme_next[${previous_theme}]}"
|
if [ -f "${STATE_FILE}" ]; then
|
||||||
|
previous_theme="$(cat "${STATE_FILE}")"
|
||||||
fi
|
fi
|
||||||
echo "${theme:=${THEME_DEFAULT}}" > "${STATE_FILE}"
|
|
||||||
|
if [ -n "${previous_theme}" ]; then
|
||||||
|
theme="${theme_next[${previous_theme}]}"
|
||||||
|
else
|
||||||
|
theme="${THEME_DEFAULT}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Store the new theme in the state file
|
||||||
|
echo "${theme}" > "${STATE_FILE}"
|
||||||
|
|
||||||
######################
|
######################
|
||||||
### Set all themes ###
|
### Set all themes ###
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,8 @@ exec-once = waybar
|
||||||
|
|
||||||
# TODO Replace with something else?
|
# TODO Replace with something else?
|
||||||
exec-once = wlsunset -t 2500 -l 50.51 -L 4.21
|
exec-once = wlsunset -t 2500 -l 50.51 -L 4.21
|
||||||
|
# Set light/dark theme based on time
|
||||||
|
exec-once = bash ${SCRIPT_DIR}/toggle-light-dark.sh -t
|
||||||
|
|
||||||
exec-once = nextcloud --background
|
exec-once = nextcloud --background
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue