From 8a67f1700326bc6a1b889242b358087a8bb343cd Mon Sep 17 00:00:00 2001 From: Salt Date: Sun, 26 Aug 2018 16:11:25 -0500 Subject: [PATCH] dtfscripts: Major refactor with more modular service startup --- .config/bspwm/bspwmrc | 1 + .config/conky/conky.conf | 1 + .../dtfscripts/{ => devices}/dsk-cstm-0.rc | 0 .../dtfscripts/{ => devices}/lap-th-e560-0.rc | 0 .config/dtfscripts/services/common.bash | 53 ++++++ .config/dtfscripts/services/compton.dtf | 23 +++ .config/dtfscripts/services/conky.dtf | 24 +++ .config/dtfscripts/services/dunst.dtf | 12 ++ .config/dtfscripts/services/kill_krunner.dtf | 16 ++ .config/dtfscripts/services/plasmashell.dtf | 12 ++ .config/dtfscripts/services/polybar.dtf | 35 ++++ .config/dtfscripts/services/sxhkd.dtf | 23 +++ .config/dtfscripts/wmstartup.sh | 178 ++++-------------- .config/polybar/start.sh | 35 ---- 14 files changed, 234 insertions(+), 179 deletions(-) rename .config/dtfscripts/{ => devices}/dsk-cstm-0.rc (100%) rename .config/dtfscripts/{ => devices}/lap-th-e560-0.rc (100%) create mode 100755 .config/dtfscripts/services/common.bash create mode 100755 .config/dtfscripts/services/compton.dtf create mode 100755 .config/dtfscripts/services/conky.dtf create mode 100755 .config/dtfscripts/services/dunst.dtf create mode 100755 .config/dtfscripts/services/kill_krunner.dtf create mode 100755 .config/dtfscripts/services/plasmashell.dtf create mode 100755 .config/dtfscripts/services/polybar.dtf create mode 100755 .config/dtfscripts/services/sxhkd.dtf delete mode 100755 .config/polybar/start.sh diff --git a/.config/bspwm/bspwmrc b/.config/bspwm/bspwmrc index 5d514612..014b86a9 100755 --- a/.config/bspwm/bspwmrc +++ b/.config/bspwm/bspwmrc @@ -72,5 +72,6 @@ bspc rule -a explorer.exe state=fullscreen bspc rule -a plasmashell state=floating sticky=on border=off bspc rule -a krunner state=floating layer=above sticky=on border=off # Widgets +bspc rule -a Conky state=floating layer=below sticky=on bspc rule -a pavucontrol-qt state=floating layer=above sticky=on diff --git a/.config/conky/conky.conf b/.config/conky/conky.conf index 2ff9e891..d4600816 100644 --- a/.config/conky/conky.conf +++ b/.config/conky/conky.conf @@ -5,6 +5,7 @@ conky.config = { own_window_title = 'Conky', own_window_class = 'Conky', own_window_type = 'desktop', + own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager', own_window_colour = '282828', double_buffer = true, diff --git a/.config/dtfscripts/dsk-cstm-0.rc b/.config/dtfscripts/devices/dsk-cstm-0.rc similarity index 100% rename from .config/dtfscripts/dsk-cstm-0.rc rename to .config/dtfscripts/devices/dsk-cstm-0.rc diff --git a/.config/dtfscripts/lap-th-e560-0.rc b/.config/dtfscripts/devices/lap-th-e560-0.rc similarity index 100% rename from .config/dtfscripts/lap-th-e560-0.rc rename to .config/dtfscripts/devices/lap-th-e560-0.rc diff --git a/.config/dtfscripts/services/common.bash b/.config/dtfscripts/services/common.bash new file mode 100755 index 00000000..09af2568 --- /dev/null +++ b/.config/dtfscripts/services/common.bash @@ -0,0 +1,53 @@ +#! /usr/bin/env bash +# +# wmstartup service common functions +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +service_name="unnamed_service" +service_process="true" + +function svc_log() { + if [ -z ${1+x} ]; then return 1; fi + dtf_log "$service_name: $1" +} + +function prestart() { + if ! which $service_process > /dev/null 2>&1; then + svc_log "Could not find process" + return 1 + fi + return 0 +} + +function start() { + if ! prestart; then + svc_log "Failed pre-start checks" + return 1 + fi + svc_log "Starting" + $service_process > /dev/null 2>&1 & + return 0 +} + +function stop() { + svc_log "Stopping" + killall $service_process & + for i in {1..100}; do + if ! isup; then break; fi + sleep 0.01 + if (( $i > 99 )); then + svc_log "Stopping with prejudice" + killall -9 $service_process + fi + done + return $? +} + +function isup() { + pgrep "$service_process" > /dev/null 2>&1 + return $? +} + diff --git a/.config/dtfscripts/services/compton.dtf b/.config/dtfscripts/services/compton.dtf new file mode 100755 index 00000000..6dd8c935 --- /dev/null +++ b/.config/dtfscripts/services/compton.dtf @@ -0,0 +1,23 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Compton" +service_process="compton" + +function start() { + if [[ "$HOST" == "vm-*" ]]; then + svc_log "Will not start: in a VM" + return 0 + else + svc_log "Starting" + $service_process > /dev/null 2>&1 & + return 0 + fi +} + diff --git a/.config/dtfscripts/services/conky.dtf b/.config/dtfscripts/services/conky.dtf new file mode 100755 index 00000000..68d143c4 --- /dev/null +++ b/.config/dtfscripts/services/conky.dtf @@ -0,0 +1,24 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Conky" +service_process="conky" + +function start() { + if ! prestart; then + svc_log "Failed pre-start checks" + return 1 + fi + for file in $XDG_CONFIG_HOME/conky/*.conf; do + svc_log "Starting with config $file" + conky -c $file > /dev/null 2>&1 & + done + return 0 +} + diff --git a/.config/dtfscripts/services/dunst.dtf b/.config/dtfscripts/services/dunst.dtf new file mode 100755 index 00000000..4a9dd9f0 --- /dev/null +++ b/.config/dtfscripts/services/dunst.dtf @@ -0,0 +1,12 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Dunst" +service_process="dunst" + diff --git a/.config/dtfscripts/services/kill_krunner.dtf b/.config/dtfscripts/services/kill_krunner.dtf new file mode 100755 index 00000000..30ab4e36 --- /dev/null +++ b/.config/dtfscripts/services/kill_krunner.dtf @@ -0,0 +1,16 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Krunner" +service_process="krunner" + +function start() { + return 0 +} + diff --git a/.config/dtfscripts/services/plasmashell.dtf b/.config/dtfscripts/services/plasmashell.dtf new file mode 100755 index 00000000..7a98e8ed --- /dev/null +++ b/.config/dtfscripts/services/plasmashell.dtf @@ -0,0 +1,12 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Plasma" +service_process="plasmashell" + diff --git a/.config/dtfscripts/services/polybar.dtf b/.config/dtfscripts/services/polybar.dtf new file mode 100755 index 00000000..04192543 --- /dev/null +++ b/.config/dtfscripts/services/polybar.dtf @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="Polybar" +service_process="polybar" + +function start() { + if ! prestart; then + svc_log "Failed pre-start checks" + return 1 + fi + export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}') + svc_log "Starting primary on monitor $PB_MONITOR" + polybar -r primary& > /dev/null 2>&1 + polybar -r primary-2& > /dev/null 2>&1 + + export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}') + if [[ "$secondary_monitors" == "" ]]; then + return 0 + fi + for monitor in $secondary monitors; do + svc_log "Starting secondary on monitor $monitor" + PB_MONITOR=$monitor + polybar -r secondary& > /dev/null 2>&1 + polybar -r secondary-2& > /dev/null 2>&1 + done + return 0 +} + diff --git a/.config/dtfscripts/services/sxhkd.dtf b/.config/dtfscripts/services/sxhkd.dtf new file mode 100755 index 00000000..086679d3 --- /dev/null +++ b/.config/dtfscripts/services/sxhkd.dtf @@ -0,0 +1,23 @@ +#! /usr/bin/env bash +# +# Simple wmstartup service +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +source $DTF_SERVICES_DIR/common.bash +service_name="sxhkd" +service_process="sxhkd" + +function prestart() { + if ! which $service_process > /dev/null 2>&1; then + svc_log "Could not find process" + fi + if ! pgrep bspwm > /dev/null 2>&1; then + svc_log "Not under bspwm" + return 1 + fi + return 0 +} + diff --git a/.config/dtfscripts/wmstartup.sh b/.config/dtfscripts/wmstartup.sh index e3e3ac4a..5887d45e 100755 --- a/.config/dtfscripts/wmstartup.sh +++ b/.config/dtfscripts/wmstartup.sh @@ -20,11 +20,12 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -## Clean up some variables that I use in device-specific scripts +## Clean up some variables # General unset TERMINAL # Specific to this script unset DTF_KILL_EXTRA +unset DTF_SERVICES # Polybar unset PB_MONITOR unset PB_WM_RESTACK @@ -39,158 +40,47 @@ unset PB_MODULE_WLAN_INTERFACE unset BSPWM_DESKTOPS_TOTAL unset BSPWM_DESKTOPS_PRIMARY -## Patch path, if not already done -if [[ "$PATH" != "*$HOME/.local/bin*" ]]; then - printf "[INFO] Patching path for $HOME/.local/bin\n" +# First parameter is the indentation level +# Second is the message +function dtf_log() { + name="$(basename $0 .sh)" + if [ -z ${1+x} ]; then return 1; fi + printf "$name: $1\n" +} + +## Patch some directories +if [[ "$PATH" != *"$HOME/.local/bin"* ]]; then + dtf_log "Patching path for $HOME/.local/bin" export PATH="$HOME/.local/bin:$PATH" fi - -## Set the runtime directory, if not already +if [[ "$XDG_CONFIG_HOME" == "" ]]; then + dtf_log "Correcting configuration directory" + export XDG_CONFIG_HOME="$HOME/.config" +fi if [[ "$XDG_RUNTIME_DIR" == "" ]]; then + dtf_log "Correcting runtime directory" export XDG_RUNTIME_DIR="/run/user/$UID" fi +## Set some more variables +export DTF_SERVICES_DIR="$XDG_CONFIG_HOME/dtfscripts/services" + ## Load device-specific scripts -if [[ -x "$HOME/.config/dtfscripts/$(hostname).rc" ]]; then - printf "[INFO] Sourcing ~/.config/dtfscripts/$(hostname).rc\n" - source $HOME/.config/dtfscripts/$(hostname).rc +if [[ -x "$XDG_CONFIG_HOME/dtfscripts/devices/$(hostname).rc" ]]; then + dtf_log "Sourcing devices/$(hostname).rc" + source $HOME/.config/dtfscripts/devices/$(hostname).rc fi -printf "[INFO] Performing simple configuration\n" -## SIMPLE CONFIGURATION -xset -b -xset -dpms -xset s off -# This depends on a script found at rehashedsalt/bin -xrdbupdate - -## SERVICES AND DAEMONS -# Kill everything -printf "[INFO] Stopping existing services\n" -services="plasmashell krunner xfdesktop polybar compton conky sxhkd dunst xob" -for service in $services; do - printf " [INFO] Sending signal to all $service\n" - killall $service -done -# Kill more everything -printf "[INFO] Running secondary kill tasks\n" -for service in $DTF_KILL_EXTRA; do - printf " [INFO] Sending signal to all $service\n" - killall $service -done -# Wait for them to die -for service in $services; do - i=0 - while pgrep $service > /dev/null 2>&1; do - if [[ "$i" = "10" ]]; then - printf " [INFO] Waited too long, killing $service with prejudice\n" - pkill -9 $service - break - else - printf " [INFO] Waiting on $service\n" - sleep 0.5 - i=$(expr $i + 1) - fi - done - unset i -done - -# Start them back up -printf "[INFO] Starting services\n" -# Start with key functionality -# SXHKD -if pgrep bspwm > /dev/null 2>&1; then - printf " [INFO] Found bspwm, starting sxhkd\n" - sxhkd & -else - printf " [WARN] bspwm was started, but sxhkd wasn't! Session may be unusable!\n" -fi - -# Compton -if which compton > /dev/null 2>&1; then - # Don't start the compositor in a VM - if [[ $(hostname) != "vm"* ]]; then - printf " [INFO] Starting compton\n" - compton & - else - printf " [INFO] In a VM, not starting compositor\n" +## Run startup scripts +for service in $DTF_SERVICES_DIR/*.dtf; do + ( + source $service + if isup; then + stop fi -else - printf " [INFO] Could not find a compositor\n" -fi + start + ) +done -# Polybar -if which polybar > /dev/null 2>&1; then - printf " [INFO] Starting polybar\n" - $HOME/.config/polybar/start.sh & -else - printf " [INFO] Could not find a bar\n" -fi - -# Dunst -if which dunst > /dev/null 2>&1; then - printf " [INFO] Starting dunst\n" - dunst& -else - printf " [INFO] Could not find a notification daemon\n" -fi - -# XOB -if which xob > /dev/null 2>&1; then - printf " [INFO] Starting xob instances\n" - pipes="brightness volume misc" - # Set up pipes - export XOB_PIPE_DIR="$XDG_RUNTIME_DIR/xob" - printf " [INFO] Using pipe directory \"$XOB_PIPE_DIR\"\n" - mkdir -m 700 "$XOB_PIPE_DIR" - for pipe in $pipes; do - if [ -p "$XOB_PIPE_DIR/$pipe" ]; then - printf " [INFO] Removing existing pipe \"$pipe\"\n" - rm "$XOB_PIPE_DIR/$pipe" - fi - mkfifo "$XOB_PIPE_DIR/$pipe" - if [ -p "$XOB_PIPE_DIR/$pipe" ]; then - printf " [INFO] Successfully created pipe \"$pipe\". Binding an xob instance to it\n" - export $pipe="$XOB_PIPE_DIR/$pipe" - tail -f "$XOB_PIPE_DIR/$pipe" | xob -s "$pipe" -t 2 & - else - printf " [WARN] Failed to create pipe \"$pipe\"\n" - fi - done -else - printf " [INFO] Could not find a bar overlay application\n" -fi - -# Conky -if which conky > /dev/null 2>&1; then - printf " [INFO] Starting conky\n" - # Use all the config files in its config directory - for file in $HOME/.config/conky/*.conf; do - printf " [INFO] Found config file $file\n" - conky -c $file& - done -else - printf " [INFO] Could not find a desktop statistics application\n" -fi - -# Wallpaper management -printf "[INFO] Setting wallpaper\n" -if which plasmashell > /dev/null 2>&1; then - printf " [INFO] Starting Plasma\n" - plasmashell & -elif which xfdesktop > /dev/null 2>&1; then - printf " [INFO] Starting xfdesktop\n" - xfdesktop --disable-wm-check& -elif which feh > /dev/null 2>&1; then - printf " [INFO] Setting wallpaper with feh\n" - printf " [WARN] This solution may cause problems on multi-monitor systems\n" - feh --randomize --bg-fill ~/Pictures/Wallpapers/.active & -elif which xsetroot > /dev/null 2>&1; then - printf " [INFO] Setting root window color\n" - xsetroot -solid "#282828" -else - printf " [WARN] Could not find a wallpaper manager\n" -fi - -printf "[INFO] Finished initialization\n" +dtf_log "Finished initialization" diff --git a/.config/polybar/start.sh b/.config/polybar/start.sh deleted file mode 100755 index 89377db3..00000000 --- a/.config/polybar/start.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# start.sh -# Copyright (C) 2018 salt -# -# Distributed under terms of the MIT license. -# -export PB_WM_RESTACK=bspwm - -# Iterate through monitors and spawn bars on each -# Starting with the primary monitor... -export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}') -if [[ $PB_MONITOR == "" ]]; then - unset PB_MONITOR -fi -printf "[INFO] Starting Polybar primary on monitor $PB_MONITOR" -polybar -r primary& -polybar -r primary-2& -# ...and then moving on to secondaries, if we have them -# Alright, now this looks *really* bad, spawning so many subprocesses, but -# there's no way in hell you can get me to attempt to solve this with regex. -# To hell with regex. It starts more problems than it solves -export secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}') -if [[ $secondary_monitors == "" ]]; then - exit 0 -fi -for monitor in $secondary_monitors; do - printf "[INFO] Starting Polybar secondary on monitor $monitor" - PB_MONITOR=$monitor - polybar -r secondary& - polybar -r secondary-2& -done - -disown -exit