Commit 39817c88 authored by Guilherme Semente's avatar Guilherme Semente 🌱

General code improvements in bspwm tools

parent 7f716dbb
#!/bin/bash
function query_layout() {
bspc query -T -d | jshon -e layout -u
# meta data
PROGNAME=bspwm-subscribe-handler
function pidlock() {
local progname rundir pidfile
progname="$1"
rundir="${XDG_RUNTIME_DIR:-$HOME/.local/run}"
pidfile="${rundir}/pidlock/${progname}.pid"
mkdir -p "$rundir"
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
return 1
else
echo $$ > "$pidfile"
fi
}
function hide_node() {
bspc node "$1" --flag hidden=on
}
function set_monocle_wallpaper() {
hsetroot -solid "#000000"
function query_layout() {
bspc query -T -d | jshon -e layout -u
}
function set_default_wallpaper() {
if [ -f "$X_WALLPAPER" ]; then
hsetroot -fill "$X_WALLPAPER"
function set_wallpaper_color_or_image() {
local wallpaper="$1"
if [ -f "$wallpaper" ]; then
hsetroot -fill "$wallpaper"
else
hsetroot -solid "$X_WALLPAPER"
hsetroot -solid "$wallpaper"
fi
}
function set_wallpaper() {
if [ "$(query_layout)" = "monocle" ]; then
set_monocle_wallpaper
set_wallpaper_color_or_image "${X_MONOCLE_WALLPAPER:-$X_WALLPAPER}"
else
set_default_wallpaper
set_wallpaper_color_or_image "${X_WALLPAPER}"
fi
}
bspc subscribe all | while read -a msg ; do
echo "${msg[@]}"
case "${msg[0]}" in
desktop_focus)
#xwrite "$(bspc query -D -d --names)" &
set_wallpaper
;;
desktop_layout)
set_wallpaper
;;
node_focus)
# if [ -f "$XDG_RUNTIME_DIR/bspwm-scratchpad.wid" ]; then
# id=$(cat "$XDG_RUNTIME_DIR/bspwm-scratchpad.wid")
# bspc node "$id" --flag hidden
# fi
;;
node_activate)
;;
node_flag)
;;
*)
esac
done
function subscribe() {
# shellcheck disable=SC2162
bspc subscribe all | while read -a msg ; do
local desktop_name focused_xid scratch_xid scratch_xids
desktop_name="$(bspc query -D -d --names)"
focused_xid=$(xdotool getwindowfocus)
scratch_xids=$(xdotool search --onlyvisible --class "bspwm-scratch-|TelegramDesktop|Slack")
#echo "${msg[@]}"
case "${msg[0]}" in
desktop_focus)
# hide scratch windows on desktop changes
echo "$scratch_xids" | xargs -rI{} bspc node "{}" --flag hidden=on
# just print desktop name
#xwrite "$desktop_name" &
;;
desktop_layout)
;;
node_focus)
# hide scratch windows when it lose focus
for scratch_xid in $scratch_xids; do
[ "${focused_xid:-nil}" != "${scratch_xid:-nil}" ] \
&& bspc node "$scratch_xid" --flag hidden=on
done
;;
node_activate)
;;
node_flag)
;;
*)
esac
done
}
function main() {
pidlock "$PROGNAME" || {
echo "${PROGNAME} is already running!"
exit 1
}
subscribe
}
main
......@@ -5,12 +5,39 @@
# by your desktop environment clipboard.
#
while true; do
# 240000 milliseconds / 4 minutes
if [ "$(xprintidle)" -gt 240000 ]; then
xclip -selection "primary" /dev/null
xclip -selection "secondary" /dev/null
xclip -selection "clipboard" /dev/null
readonly PROGNAME=cbd
function pidlock() {
local progname rundir pidfile
progname="$1"
rundir="${XDG_RUNTIME_DIR:-$HOME/.local/run}"
pidfile="${rundir}/pidlock/${progname}.pid"
mkdir -p "$rundir"
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
return 1
else
echo $$ > "$pidfile"
fi
sleep 60 && echo Plop!
done
}
function main() {
pidlock "$PROGNAME" || {
echo "${PROGNAME} is already running!"
exit 1
}
while true; do
# 240000 milliseconds / 4 minutes
if [ "$(xprintidle)" -gt 240000 ]; then
xclip -selection "primary" /dev/null
xclip -selection "secondary" /dev/null
xclip -selection "clipboard" /dev/null
fi
sleep 60 && echo Plop!
done
}
main
......@@ -4,16 +4,18 @@
# See <https://iristech.co/what-is-the-best-color-temperature/>.
#
readonly PROGNAME=sctd
SCTD_TEMP_TABLE=(
2800 # 00h00
2800
2800
2800
2800
3000 # 05h00
5000 # 06h00
5000
5000
2300 # 00h00
2600
2900
3200
3500
3800
4100 # 06h00
4400
4700
5000
5000
5000
......@@ -21,22 +23,44 @@ SCTD_TEMP_TABLE=(
5000
5000
5000
5000
5000
4000 # 18h00
4000
3000 # 20h00
3000
3000
3000 # 23h00
2800 # 24h00
4700
4400
4100 # 18h00
3800
3500
3200
2900
2600 # 23h00
)
while true; do
now=$(date +"%H")
#ind=$(bc <<< "$now + 1")
ind=$((10#$now + 1))
val=${SCTD_TEMP_TABLE[$ind]}
sct "$val" && echo "i:$ind v:$val"
sleep 240
done
function pidlock() {
local progname rundir pidfile
progname="$1"
rundir="${XDG_RUNTIME_DIR:-$HOME/.local/run}"
pidfile="${rundir}/pidlock/${progname}.pid"
mkdir -p "$rundir"
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
return 1
else
echo $$ > "$pidfile"
fi
}
function main() {
pidlock "$PROGNAME" || {
echo "${PROGNAME} is already running!"
exit 1
}
while true; do
ind=$(date +"%-H")
val=${SCTD_TEMP_TABLE[$ind]}
sct "$val" && echo "i:$ind v:$val"
sleep 120
done
}
main
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment