diff --git a/.config/bspwm/bspwmrc b/.config/bspwm/bspwmrc index 43a9def2..595fa06a 100755 --- a/.config/bspwm/bspwmrc +++ b/.config/bspwm/bspwmrc @@ -27,10 +27,6 @@ if [[ -x "$dtfscript" ]]; then fi unset dtfscript -# Monitor setup script -# Unique to bspwm, because i3 handles this alright -$HOME/.config/bspwm/monitorset.sh - ## Behavior # Tiling behavior bspc config split_ratio 0.50 diff --git a/.config/dtfscripts/common_task.sh b/.config/dtfscripts/common_task.sh new file mode 100755 index 00000000..698f24c1 --- /dev/null +++ b/.config/dtfscripts/common_task.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env bash +# +# wmstartup service common functions +# Copyright (C) 2018 salt +# +# Distributed under terms of the MIT license. +# + +# Basic logging service. Do not override unless necessary +function tsk_log() { + if [ -z ${1+x} ]; then return 1; fi + dtf_log "$task: $1" +} + diff --git a/.config/dtfscripts/services/0_kill_krunner.dtf b/.config/dtfscripts/services/0_kill_krunner.dtf deleted file mode 100755 index 4aa77466..00000000 --- a/.config/dtfscripts/services/0_kill_krunner.dtf +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env bash -# -# Simple wmstartup service -# Copyright (C) 2018 salt -# -# Distributed under terms of the MIT license. -# - -service_name="Krunner" -service_process="krunner" - -function start() { - return 0 -} - diff --git a/.config/dtfscripts/services/0_xrdbupdate.dtf b/.config/dtfscripts/services/0_xrdbupdate.dtf deleted file mode 100755 index e3367764..00000000 --- a/.config/dtfscripts/services/0_xrdbupdate.dtf +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env bash -# -# Simple wmstartup service -# Copyright (C) 2018 salt -# -# Distributed under terms of the MIT license. -# - -service_name="Xresources" -service_process="xrdbupdate" -service_kill_on_reload="false" - -function start() { - svc_log "Updating" - $service_process $service_flags > /dev/null 2>&1 & - return 0 -} - -function stop() { - return 1 -} - diff --git a/.config/dtfscripts/tasks/kill_krunner.sh b/.config/dtfscripts/tasks/kill_krunner.sh new file mode 100755 index 00000000..ba3b6812 --- /dev/null +++ b/.config/dtfscripts/tasks/kill_krunner.sh @@ -0,0 +1,20 @@ +#! /bin/sh +if ! pgrep krunner > /dev/null 2>&1; then + exit 0 +fi +killall krunner +for i in {1..100}; do + if ! pgrep krunner; then break ;fi + sleep 0.01 + if (( $i > 99 )); then + killall -9 krunner + fi +done +if pgrep krunner > /dev/null 2>&1; then + tsk_log "Failed to kill krunner" + exit 1 +else + tsk_log "Killed krunner" + exit 0 +fi + diff --git a/.config/bspwm/monitorset.sh b/.config/dtfscripts/tasks/monitorset.sh similarity index 58% rename from .config/bspwm/monitorset.sh rename to .config/dtfscripts/tasks/monitorset.sh index bb4b1371..ae68ed5c 100755 --- a/.config/bspwm/monitorset.sh +++ b/.config/dtfscripts/tasks/monitorset.sh @@ -6,8 +6,11 @@ # Distributed under terms of the MIT license. # -printf "[INFO] Setting up monitors\n" -# Get the primary first, to ensure it's the first element +if ! pgrep bspwm > /dev/null 2>&1; then + tsk_log "Not running in bspwm" + exit 1 +fi + monitor_primary=$(xrandr -q | awk '/primary/{print $1}') monitors_secondary=($(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')) @@ -17,35 +20,34 @@ desktops_secondary=$(($desktops_total - $desktops_primary)) # Sanity checks if ! [[ "$desktops_total" -ge 1 ]]; then - printf " [ERROR] desktops_total cannot be $desktops_total, defaulting to 8\n" 1>&2 + tsk_log "desktops_total cannot be $desktops_total, defaulting to 8" desktops_total=8 fi if ! [[ "$desktops_primary" -ge 1 ]]; then - printf " [ERROR] desktops_primary cannot be $desktops_primary, defaulting to 6\n" 1>&2 + tsk_log "desktops_primary cannot be $desktops_primary, defaulting to 6" desktops_primary=6 fi # Do we have enough desktops for all monitors? # We can correct this without defaulting, so don't error if [[ $desktops_secondary -lt ${#monitors_secondary[@]} ]]; then - printf " [WARN] Configuration would leave some monitors without desktops!\n" 1>&2 - printf " [INFO] Adding more desktops\n" + tsk_log "Configuration would leave some monitors without desktops; adding more" desktops_secondary=${#monitors_secondary[@]} desktops_total=$(($desktops_secondary + $desktops_primary)) deskpermon=1 - printf " [INFO] Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total\n" + tsk_log "Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total" fi # Can we actually reach all of these desktops via keybinds? if [[ $desktops_total -gt 10 ]]; then - printf " [WARN] More than ten desktops were allocated! Not all of these can be reached via keybinds!\n" 1>&2 + tsk_log "More than ten desktops were allocated! Not all of these can be reached via keybinds!" if [[ $(($desktops_total - $desktops_secondary)) -gt 0 ]]; then - printf " [INFO] Adjusting primary desktop reservation\n" + tsk_log "Adjusting primary desktop reservation" desktops_primary=$(($desktops_total - $desktops_secondary)) - printf " [INFO] Set reserved desktops to $desktops_primary\n" + tsk_log "Set reserved desktops to $desktops_primary" else - printf " [WARN] Cannot resolve this situation without starving the primary monitor of desktops!\n" - printf " [WARN] This may result in desktops being allocated that cannot be easily accessed!\n" + tsk_log "Cannot resolve this situation without starving the primary monitor of desktops!" + tsk_log "This may result in desktops being allocated that cannot be easily accessed!" fi fi @@ -55,18 +57,18 @@ fi if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then # We only have one monitor, so give it everything layout=$(seq --separator=" " 1 $desktops_total) - printf " [INFO] Found one monitor: $monitor_primary, so giving it layout \"$layout\"\n" + tsk_log "Found one monitor: $monitor_primary, so giving it layout \"$layout\"" bspc monitor $monitor_primary -d $layout else deskpermon=$(($desktops_secondary / ${#monitors_secondary[@]})) layout=$(seq --separator=" " 1 $desktops_primary) - printf " [INFO] Giving primary monitor $monitor_primary layout \"$layout\"\n" + tsk_log "Giving primary monitor $monitor_primary layout \"$layout\"" bspc monitor $monitor_primary -d $layout unset layout - printf " [INFO] Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each\n" + tsk_log "Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each" for m in $(seq 0 $((${#monitors_secondary[@]} - 1))); do layout=$(seq --separator=" " $((1 + $m + $desktops_primary)) ${#monitors_secondary[@]} "$desktops_total") - printf " [INFO] Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\"\n" + tsk_log "Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\"" bspc monitor ${monitors_secondary[$m]} -d $layout done fi diff --git a/.config/dtfscripts/tasks/xrdbupdate.sh b/.config/dtfscripts/tasks/xrdbupdate.sh new file mode 100755 index 00000000..14440888 --- /dev/null +++ b/.config/dtfscripts/tasks/xrdbupdate.sh @@ -0,0 +1,14 @@ +#! /bin/sh +if [ -r ~/.Xresources ]; then + tsk_log "Loading .Xresources" + xrdb ~/.Xresources +fi +for file in $XDG_CONFIG_HOME/xrdb/*.xresources; do + if ! [ -r "$file" ]; then + tsk_log "Could not read file \"$file\"" + else + tsk_log "Merging in file \"$file\"" + xrdb -merge "$file" + fi +done + diff --git a/.config/dtfscripts/wmstartup.sh b/.config/dtfscripts/wmstartup.sh index 167e520f..75a0f4cd 100755 --- a/.config/dtfscripts/wmstartup.sh +++ b/.config/dtfscripts/wmstartup.sh @@ -25,6 +25,7 @@ unset TERMINAL # Specific to these dtfscripts unset DTF_SERVICES +unset DTF_TASKS # Polybar unset PB_MONITOR unset PB_WM_RESTACK @@ -64,6 +65,7 @@ fi ## Set some more variables export DTF_CONFIG_HOME="$XDG_CONFIG_HOME/dtfscripts" export DTF_SERVICES_DIR="$DTF_CONFIG_HOME/services" +export DTF_TASKS_DIR="$DTF_CONFIG_HOME/tasks" ## Load device-specific scripts if [[ -x "$DTF_CONFIG_HOME/devices/$(hostname).rc" ]]; then @@ -71,9 +73,20 @@ if [[ -x "$DTF_CONFIG_HOME/devices/$(hostname).rc" ]]; then source $HOME/.config/dtfscripts/devices/$(hostname).rc fi +## Determine which tasks to run +# If DTF_TASKS is set, use that +# Otherwise, run everything +if [[ "$DTF_TASKS" == "" ]]; then + dtf_log "Performing all tasks" + for task in $DTF_TASKS_DIR/*; do + export DTF_TASKS="$DTF_TASKS $(basename "$task")" + done +else + dtf_log "Performing a subset of all tasks" +fi + ## Determine which services to run -# If DTF_SERVICES is set, use that -# Otherwise, populate it with every service +# Same as above if [[ "$DTF_SERVICES" == "" ]]; then dtf_log "Starting all available services" for service in $DTF_SERVICES_DIR/*.dtf; do @@ -83,6 +96,23 @@ else dtf_log "Starting a subset of available services" fi +## Run tasks +for task in $DTF_TASKS; do + task_full="$DTF_TASKS_DIR/$task" + ( + if ! [ -r "$task_full" ]; then + dtf_log "Task is unreadable or missing: $task" + exit 1 + fi + if ! [ -x "$task_full" ]; then + dtf_log "Task is unexecutable: $task" + exit 1 + fi + source "$DTF_CONFIG_HOME/common_task.sh" + source "$task_full" + ) +done + ## Run startup scripts for service in $DTF_SERVICES; do service_full="$DTF_SERVICES_DIR/$service"