speedwm-personal/scripts/speedwm-utils

239 lines
7.5 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# speedwm-utils
# Because controlling speedwm using shell scripts is based.
# Licensed under GNU GPLv3.
case "$RUNLAUNCHER" in
"") RUNLAUNCHER=dmenu # Run launcher to use (dmenu, rofi, etc.) ;;
esac
2022-08-23 15:47:37 +02:00
HAVE_GRID="true"
if [ -e "$HOME/.config/speedwm-de/global/config" ]; then
. $HOME/.config/speedwm-de/global/config
else
mkdir -p $HOME/.config/speedwm-de/global
printf "HAVE_GRID=$HAVE_GRID # Whether or not to use the Grid argument. If you do not have the dmenu grid patch, set this to false. Doing so will disable grid." > $HOME/.config/speedwm-de/global/config
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDNUM="1"
fi
if [ "$HAVE_GRID" = "true" ]; then
GRIDARG="-g"
fi
VARS() {
BINDIR=$(cat /usr/share/speedwm-bindir)
SIGNAL_1=1 # Layout: Tiling
SIGNAL_2=2 # Layout: Floating
SIGNAL_3=3 # Layout: Monocle
SIGNAL_4=4 # Layout: Grid
SIGNAL_5=5 # Layout: Deck
SIGNAL_6=6 # Layout: Centered Master
SIGNAL_7=7 # Layout: Centered Floating Master
SIGNAL_8=8 # Layout: Fibonacci Spiral
SIGNAL_9=9 # Layout: Fibonacci Dwindle
SIGNAL_10=10 # Layout: Three Column
SIGNAL_11=11 # Layout: Bottom Stack Vertical
SIGNAL_12=12 # Layout: Bottom Stack Horizontal
SIGNAL_13=13 # Layout: Horizontal Grid
SIGNAL_14=14 # Layout: Tatami
SIGNAL_15=15 # Layout: Tilewide
SIGNAL_16=16 # Layout: Previous
SIGNAL_17=17 # Layout: Next
SIGNAL_18=18 # General: Reload resources (xrdb)
SIGNAL_19=19 # General: Set mfact (-0.05)
SIGNAL_20=20 # General: Set mfact (+0.05)
SIGNAL_21=21 # General: Toggle Scratchpad
SIGNAL_22=22 # General: Toggle Sticky
SIGNAL_23=23 # General: Toggle Bar
SIGNAL_24=24 # General: Toggle Fullscreen
SIGNAL_25=25 # General: Restart speedwm
SIGNAL_26=26 # Unused: Unused 26
SIGNAL_27=27 # Layout: Stairs
SIGNAL_28=28 # General: Reset layout/mfact
SIGNAL_29=29 # General: Reorganize Tags
SIGNAL_30=30 # General: Quit speedwm
SIGNAL_31=31 # General: Restart speedwm
SIGNAL_32=32 # Unused: Unused 32
SIGNAL_33=33 # Unused: Unused 33
SIGNAL_34=34 # Unused: Unused 34
SIGNAL_35=35 # Layout: Tiling 5:4
SIGNAL_36=36 # Layout: Columns
SIGNAL_37=37 # Layout: Dynamic Grid
}
VARS
GENERAL() {
GENERALOPTS=$(printf "mfact +\nmfact -\nToggle Scratchpad\nToggle Sticky\nToggle Bar\nToggle Fullscreen\nToggle rmaster\nReset Layout/mfact\nReorganize Tags" | $RUNLAUNCHER -l 20 -p 'What do you want to do?')
case "$GENERALOPTS" in
"mfact +") xsetroot -name "fsignal:$SIGNAL_20" ;;
"mfact -") xsetroot -name "fsignal:$SIGNAL_19" ;;
"Toggle Scratchpad") xsetroot -name "fsignal:$SIGNAL_21" ;;
"Toggle Sticky") xsetroot -name "fsignal:$SIGNAL_22" ;;
"Toggle Bar") xsetroot -name "fsignal:$SIGNAL_23" ;;
"Toggle Fullscreen") xsetroot -name "fsignal:$SIGNAL_24" ;;
"Toggle rmaster") xsetroot -name "fsignal:$SIGNAL_26" ;;
"Reorganize Tags") xsetroot -name "fsignal:$SIGNAL_29" ;;
"Reset Layout/mfact") xsetroot -name "fsignal:$SIGNAL_28" ;;
esac
}
OPT() {
MENUOPTS=$(printf "Layout\nReload .Xresources\nSpawn\nGeneral\nExit" | $RUNLAUNCHER -l 20 -p 'What do you want to do?')
case "$MENUOPTS" in
"Layout") ${0} -layout $2 && exit 0 ;;
"Reload .Xresources") ${0} -reloadxrdb && exit 0 ;;
"Spawn") ${0} -spawn $2 && exit 0 ;;
"General") ${0} -general $2 && exit 0 ;;
"Exit") exit 0 ;;
esac
}
HELP() {
printf "speedwmutils allows you to control speedwm using your terminal or dmenu/rofi.\n-- Arguments --\n-layout | Let the user select a speedwm layout\n-reloadxrdb | Reload .Xresources\n-spawn | Spawn a command through speedwm\n-exec | Execute an fsignal signum\n-list | List all available signums\n" > /tmp/speedwm-printed-help
pgrep -x $RUNLAUNCHER || cat /tmp/speedwm-printed-help
2022-08-23 15:47:37 +02:00
pgrep -x $RUNLAUNCHER && cat /tmp/speedwm-printed-help | $RUNLAUNCHER -p 'speedwmutils help' $GRIDARG $GRIDNUM -l 20
}
# Source layout data
if [ -e "/usr/share/speedwm-layouts" ]; then
. /usr/share/speedwm-layouts
fi
# Tile
if [ "$LAYOUT_TILE" = "1" ]; then
L1="$(printf "L1: Tiling\n")"
fi
# Tile (5:4)
if [ "$LAYOUT_TILE54" = "1" ]; then
L17="$(printf "L17: Tiling (5:4)\n")"
fi
# Monocle
if [ "$LAYOUT_MONOCLE" = "1" ]; then
L3="$(printf "L3: Monocle\n")"
fi
# Grid
if [ "$LAYOUT_GRID" = "1" ]; then
L4="$(printf "L4: Grid\n")"
fi
# Dwindle
if [ "$LAYOUT_DWINDLE" = "1" ]; then
L9="$(printf "L8: Dwindle\n")"
fi
# Spiral
if [ "$LAYOUT_SPIRAL" = "1" ]; then
L8="$(printf "L8: Spiral\n")"
fi
# Three Columns
if [ "$LAYOUT_TCL" = "1" ]; then
L10="$(printf "L10: Three Columns\n")"
fi
# Bottom Stack
if [ "$LAYOUT_BSTACK" = "1" ]; then
L11="$(printf "L11: Bottom Stack Vertical\n")"
fi
# Horizontal Bottom Stack
if [ "$LAYOUT_BSTACKH" = "1" ]; then
L12="$(printf "L12: Bottom Stack Horizontal\n")"
fi
# Horizontal Grid
if [ "$LAYOUT_HGRID" = "1" ]; then
L13="$(printf "L13: Horizontal Grid\n")"
fi
# Dynamic Grid
if [ "$LAYOUT_DGRID" = "1" ]; then
L19="$(printf "L19: Dynamic Grid\n")"
fi
# Tatami
if [ "$LAYOUT_TATAMI" = "1" ]; then
L14="$(printf "L14: Tatami\n")"
fi
# Tilewide
if [ "$LAYOUT_TW" = "1" ]; then
L15="$(printf "L15: Tilewide\n")"
fi
# Centered Master
if [ "$LAYOUT_CM" = "1" ]; then
L6="$(printf "L6: Centered Master\n")"
fi
# Centered Floating Master
if [ "$LAYOUT_CFM" = "1" ]; then
L7="$(printf "L7: Centered Floating Master\n")"
fi
# Deck
if [ "$LAYOUT_DECK" = "1" ]; then
L5="$(printf "L5: Deck\n")"
fi
# Columns
if [ "$LAYOUT_COL" = "1" ]; then
L18="$(printf "L18: Column\n")"
fi
# Stairs
if [ "$LAYOUT_STAIRS" = "1" ]; then
L16="$(printf "L16: Stairs\n")"
fi
case "$1" in
"-layout") SEL_LAYOUT=$(printf "${L1}\nL2: Floating\n${L3}\n${L4}\n${L5}\n${L6}\n${L7}\n${L8}\n${L9}\n${L10}\n${L11}\n${L12}\n${L13}\n${L14}\n${L15}\n${L16}\n${L17}\n${L18}\n${L19}\nPrevious Layout\nNext Layout" | $RUNLAUNCHER -l 21 -p "Pick a layout: ") ;;
"-spawn") printf "Not complete" ;;
"-list") sed 's|xsetroot -name "fsignal:||g' /usr/share/speedwm-fsignal | sed 's|"||g' ;;
"-reloadxrdb") xsetroot -name "fsignal:$SIGNAL_18" ;;
"-help") HELP ;;
"-exec")
if [ "$2" = "" ]; then
exit 0
else
xsetroot -name "fsignal:$2"
fi ;;
"-h") HELP ;;
"-general") GENERAL ;;
"") OPT ;;
esac
case "$SEL_LAYOUT" in
"Exit") exit 0 ;;
"L1: Tiling") xsetroot -name "fsignal:$SIGNAL_1" ;;
"L2: Floating") xsetroot -name "fsignal:$SIGNAL_2" ;;
"L3: Monocle") xsetroot -name "fsignal:$SIGNAL_3" ;;
"L4: Grid") xsetroot -name "fsignal:$SIGNAL_4" ;;
"L5: Deck") xsetroot -name "fsignal:$SIGNAL_5" ;;
"L6: Centered Master") xsetroot -name "fsignal:$SIGNAL_6" ;;
"L7: Centered Floating Master") xsetroot -name "fsignal:$SIGNAL_7" ;;
"L8: Fibonacci Spiral") xsetroot -name "fsignal:$SIGNAL_8" ;;
"L9: Fibonacci Dwindle") xsetroot -name "fsignal:$SIGNAL_9" ;;
"L10: Three Column") xsetroot -name "fsignal:$SIGNAL_10" ;;
"L11: Bottom Stack Vertical") xsetroot -name "fsignal:$SIGNAL_11" ;;
"L12: Bottom Stack Horizontal") xsetroot -name "fsignal:$SIGNAL_12" ;;
"L13: Horizontal Grid") xsetroot -name "fsignal:$SIGNAL_13" ;;
"L14: Tatami") xsetroot -name "fsignal:$SIGNAL_14" ;;
"L15: Tilewide") xsetroot -name "fsignal:$SIGNAL_15" ;;
"L16: Stairs") xsetroot -name "fsignal:$SIGNAL_27" ;;
"L17: Tiling (5:4)") xsetroot -name "fsignal:$SIGNAL_35" ;;
"L18: Column") xsetroot -name "fsignal:$SIGNAL_36" ;;
"L19: Dynamic Grid") xsetroot -name "fsignal:$SIGNAL_37" ;;
"Previous Layout") xsetroot -name "fsignal:$SIGNAL_16" ;;
"Next Layout") xsetroot -name "fsignal:$SIGNAL_17" ;;
esac