wmstartup: Add tasks frameworking
Because one-off services are kind of hacky
This commit is contained in:
parent
8d17082a6c
commit
e96a76e29a
@ -27,10 +27,6 @@ if [[ -x "$dtfscript" ]]; then
|
|||||||
fi
|
fi
|
||||||
unset dtfscript
|
unset dtfscript
|
||||||
|
|
||||||
# Monitor setup script
|
|
||||||
# Unique to bspwm, because i3 handles this alright
|
|
||||||
$HOME/.config/bspwm/monitorset.sh
|
|
||||||
|
|
||||||
## Behavior
|
## Behavior
|
||||||
# Tiling behavior
|
# Tiling behavior
|
||||||
bspc config split_ratio 0.50
|
bspc config split_ratio 0.50
|
||||||
|
14
.config/dtfscripts/common_task.sh
Executable file
14
.config/dtfscripts/common_task.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
#
|
||||||
|
# wmstartup service common functions
|
||||||
|
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
||||||
|
#
|
||||||
|
# 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"
|
||||||
|
}
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
#! /usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Simple wmstartup service
|
|
||||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
|
||||||
#
|
|
||||||
# Distributed under terms of the MIT license.
|
|
||||||
#
|
|
||||||
|
|
||||||
service_name="Krunner"
|
|
||||||
service_process="krunner"
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
#! /usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Simple wmstartup service
|
|
||||||
# Copyright (C) 2018 salt <salt@lap-th-e560-0>
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
20
.config/dtfscripts/tasks/kill_krunner.sh
Executable file
20
.config/dtfscripts/tasks/kill_krunner.sh
Executable file
@ -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
|
||||||
|
|
@ -6,8 +6,11 @@
|
|||||||
# Distributed under terms of the MIT license.
|
# Distributed under terms of the MIT license.
|
||||||
#
|
#
|
||||||
|
|
||||||
printf "[INFO] Setting up monitors\n"
|
if ! pgrep bspwm > /dev/null 2>&1; then
|
||||||
# Get the primary first, to ensure it's the first element
|
tsk_log "Not running in bspwm"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
monitor_primary=$(xrandr -q | awk '/primary/{print $1}')
|
monitor_primary=$(xrandr -q | awk '/primary/{print $1}')
|
||||||
monitors_secondary=($(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{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
|
# Sanity checks
|
||||||
if ! [[ "$desktops_total" -ge 1 ]]; then
|
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
|
desktops_total=8
|
||||||
fi
|
fi
|
||||||
if ! [[ "$desktops_primary" -ge 1 ]]; then
|
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
|
desktops_primary=6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Do we have enough desktops for all monitors?
|
# Do we have enough desktops for all monitors?
|
||||||
# We can correct this without defaulting, so don't error
|
# We can correct this without defaulting, so don't error
|
||||||
if [[ $desktops_secondary -lt ${#monitors_secondary[@]} ]]; then
|
if [[ $desktops_secondary -lt ${#monitors_secondary[@]} ]]; then
|
||||||
printf " [WARN] Configuration would leave some monitors without desktops!\n" 1>&2
|
tsk_log "Configuration would leave some monitors without desktops; adding more"
|
||||||
printf " [INFO] Adding more desktops\n"
|
|
||||||
desktops_secondary=${#monitors_secondary[@]}
|
desktops_secondary=${#monitors_secondary[@]}
|
||||||
desktops_total=$(($desktops_secondary + $desktops_primary))
|
desktops_total=$(($desktops_secondary + $desktops_primary))
|
||||||
deskpermon=1
|
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
|
fi
|
||||||
|
|
||||||
# Can we actually reach all of these desktops via keybinds?
|
# Can we actually reach all of these desktops via keybinds?
|
||||||
if [[ $desktops_total -gt 10 ]]; then
|
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
|
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))
|
desktops_primary=$(($desktops_total - $desktops_secondary))
|
||||||
printf " [INFO] Set reserved desktops to $desktops_primary\n"
|
tsk_log "Set reserved desktops to $desktops_primary"
|
||||||
else
|
else
|
||||||
printf " [WARN] Cannot resolve this situation without starving the primary monitor of desktops!\n"
|
tsk_log "Cannot resolve this situation without starving the primary monitor of desktops!"
|
||||||
printf " [WARN] This may result in desktops being allocated that cannot be easily accessed!\n"
|
tsk_log "This may result in desktops being allocated that cannot be easily accessed!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -55,18 +57,18 @@ fi
|
|||||||
if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then
|
if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then
|
||||||
# We only have one monitor, so give it everything
|
# We only have one monitor, so give it everything
|
||||||
layout=$(seq --separator=" " 1 $desktops_total)
|
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
|
bspc monitor $monitor_primary -d $layout
|
||||||
else
|
else
|
||||||
deskpermon=$(($desktops_secondary / ${#monitors_secondary[@]}))
|
deskpermon=$(($desktops_secondary / ${#monitors_secondary[@]}))
|
||||||
layout=$(seq --separator=" " 1 $desktops_primary)
|
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
|
bspc monitor $monitor_primary -d $layout
|
||||||
unset 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
|
for m in $(seq 0 $((${#monitors_secondary[@]} - 1))); do
|
||||||
layout=$(seq --separator=" " $((1 + $m + $desktops_primary)) ${#monitors_secondary[@]} "$desktops_total")
|
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
|
bspc monitor ${monitors_secondary[$m]} -d $layout
|
||||||
done
|
done
|
||||||
fi
|
fi
|
14
.config/dtfscripts/tasks/xrdbupdate.sh
Executable file
14
.config/dtfscripts/tasks/xrdbupdate.sh
Executable file
@ -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
|
||||||
|
|
@ -25,6 +25,7 @@
|
|||||||
unset TERMINAL
|
unset TERMINAL
|
||||||
# Specific to these dtfscripts
|
# Specific to these dtfscripts
|
||||||
unset DTF_SERVICES
|
unset DTF_SERVICES
|
||||||
|
unset DTF_TASKS
|
||||||
# Polybar
|
# Polybar
|
||||||
unset PB_MONITOR
|
unset PB_MONITOR
|
||||||
unset PB_WM_RESTACK
|
unset PB_WM_RESTACK
|
||||||
@ -64,6 +65,7 @@ fi
|
|||||||
## Set some more variables
|
## Set some more variables
|
||||||
export DTF_CONFIG_HOME="$XDG_CONFIG_HOME/dtfscripts"
|
export DTF_CONFIG_HOME="$XDG_CONFIG_HOME/dtfscripts"
|
||||||
export DTF_SERVICES_DIR="$DTF_CONFIG_HOME/services"
|
export DTF_SERVICES_DIR="$DTF_CONFIG_HOME/services"
|
||||||
|
export DTF_TASKS_DIR="$DTF_CONFIG_HOME/tasks"
|
||||||
|
|
||||||
## Load device-specific scripts
|
## Load device-specific scripts
|
||||||
if [[ -x "$DTF_CONFIG_HOME/devices/$(hostname).rc" ]]; then
|
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
|
source $HOME/.config/dtfscripts/devices/$(hostname).rc
|
||||||
fi
|
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
|
## Determine which services to run
|
||||||
# If DTF_SERVICES is set, use that
|
# Same as above
|
||||||
# Otherwise, populate it with every service
|
|
||||||
if [[ "$DTF_SERVICES" == "" ]]; then
|
if [[ "$DTF_SERVICES" == "" ]]; then
|
||||||
dtf_log "Starting all available services"
|
dtf_log "Starting all available services"
|
||||||
for service in $DTF_SERVICES_DIR/*.dtf; do
|
for service in $DTF_SERVICES_DIR/*.dtf; do
|
||||||
@ -83,6 +96,23 @@ else
|
|||||||
dtf_log "Starting a subset of available services"
|
dtf_log "Starting a subset of available services"
|
||||||
fi
|
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
|
## Run startup scripts
|
||||||
for service in $DTF_SERVICES; do
|
for service in $DTF_SERVICES; do
|
||||||
service_full="$DTF_SERVICES_DIR/$service"
|
service_full="$DTF_SERVICES_DIR/$service"
|
||||||
|
Reference in New Issue
Block a user