wrappers: nitrogen and xrandr

This commit is contained in:
Daniel Napora 2022-07-12 17:41:03 +02:00
parent 4d256c040a
commit 8739b5c4ca
2 changed files with 116 additions and 0 deletions

100
common/wrappers/nitrogen Executable file
View File

@ -0,0 +1,100 @@
#!/usr/bin/env bash
#
# Wrapper for nitrogen, so LightDM wallpaper is synced.
#
# Copyright (C) 2021 Rafael Cavalcanti - rafaelc.org
# Licensed under GPLv3
set -euo pipefail
/usr/bin/nitrogen "$@"
if [[ "${1:-}" == "--restore" ]]; then
exit $?
fi
readonly bg_path="$(awk -F '=' '/file/{print $2}' "$HOME/.config/nitrogen/bg-saved.cfg")"
dbus-send \
--print-reply \
--system \
--dest=org.freedesktop.Accounts \
/org/freedesktop/Accounts/User$(id -u) \
org.freedesktop.DBus.Properties.Set \
string:org.freedesktop.DisplayManager.AccountsService \
string:BackgroundFile \
variant:string:"$bg_path"
# Generate wallpaper color palette
WALLPALDIR="$HOME/.config/colormenu/palettes/wallp"
mkdir -p "$WALLPALDIR"
read WALLPATH<<< $(grep file "$HOME/.config/nitrogen/bg-saved.cfg" | cut -d'=' -f2)
WALLPAPER=${WALLPATH##*/}
if [ ! -f "$WALLPALDIR/$WALLPAPER.clr" ]; then
convert ${WALLPATH} -resize 25% -colors 16 -unique-colors txt:- |grep -v '^#'| awk '{print substr($3,1,7)}' |pastel sort-by brightness |pastel format hex > "$WALLPALDIR/$WALLPAPER.clr"
fi
# GENERATE THUMBNAIL
THUMBDIR="$HOME/.config/mabox/wallthumbs"
mkdir -p ${THUMBDIR}
THUMB="${THUMBDIR}/${WALLPAPER}.png"
if [[ ! -f "$THUMB" ]]; then
convert ${WALLPATH} -resize 270x150^ -gravity center -extent 270x150 ${THUMB}
fi
# auto generate themes
if command -v w2theme &> /dev/null
then
## Generate Conkys, Menu themes from wallpaper colors
source ~/.config/mabox/mabox.conf
# if enabled
if [[ "$wall2themes" == "true" ]];then
#if not invoked by mb-obthemes
#notify-send.sh "Theme generation" "Enabled"
LOCKED=${wall2themeslock:-false}
if [[ "$LOCKED" != "true" ]];then
#notify-send.sh "Lock" "not set"
# CONKY
case "$wall2themes_conky" in
dark) w2theme conky dark;;
light) w2theme conky light;;
*)
:
;;
esac
# MENUS
case "$wall2themes_menu" in
dark) w2theme menu dark;;
light) w2theme menu light;;
*)
:
;;
esac
# ACCENT_COLOR
mapfile -t w < "$WALLPALDIR/$WALLPAPER.clr"
case "$wall2themes_accent" in
dark)
#TODO: SWITCH TO MBCOLORS theme
obtctl theme MBcolors
obtctl clractivebg ${w[1]}
;;
light)
#TODO: SWITCH TO MBCOLORS theme
obtctl theme MBcolors
obtctl clractivebg ${w[-1]}
;;
*)
:
;;
esac
# PYRADIO THEME
case "$wall2themes_pyradio" in
dark) w2theme pyradio dark;;
light) w2theme pyradio light;;
*)
:
;;
esac
fi
fi
fi

16
common/wrappers/xrandr Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
#
# Wrapper for xrandr, so wallpaper and Conky are reloaded on resolution change.
#
# Copyright (C) 2022 Daniel Napora - maboxlinux.org
# Licensed under GPLv3
set -euo pipefail
/usr/bin/xrandr "$@"
if [[ "$@" == *"--output"* ]];then
nitrogen --restore
if pgrep conky;then
killall -SIGUSR1 conky 2> /dev/null
fi
fi