X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2F.xlaunch;h=2aa292a978fb684548bcd6169379b87f938962a9;hb=dbc03ddf2472416405188cf46bcfdf2e0d58968b;hp=9f33d9b6cc800938684a106c3514ec0b73a53346;hpb=ac1c27a589093edb399aa3fd94a4832818778f43;p=khome.git diff --git a/home/.xlaunch b/home/.xlaunch index 9f33d9b..2aa292a 100755 --- a/home/.xlaunch +++ b/home/.xlaunch @@ -2,83 +2,98 @@ set -e +SESSION='xlaunch' +SOCK_NAME="$SESSION" +TMUX="tmux -L $SOCK_NAME" LOG_FILE=~/var/log/xlaunch.log log() { local -r fmt="$1" shift - printf "${fmt}\n" $@ | twrap.sh >> "$LOG_FILE" + printf "[%s] ${fmt}\n" "$(date +'%F %T')" $@ >> "$LOG_FILE" } -launch_then_killall() { - local -r program="$1" - local -r timeout="${2:-1}" # 2nd arg or default to 1. +counter_next() { + local -r file="$_counter_file" - "$program"& - sleep "$timeout" - killall "$program" + awk '{n = $1} END {print n + 1}' "$file" | sponge "$file" + cat "$file" } -dpi_scale() { - # IDK what magic is at work here, but launching mate-appearance-properties - # does the job better than setting scaling variables. - # TODO Get to the bottom of how it works and replicate directly. - # TODO Try this: https://wiki.archlinux.org/title/HiDPI#Xorg - launch_then_killall 'mate-appearance-properties' 1 - - # GDK 3 (GTK 3) - # https://wiki.archlinux.org/index.php/HiDPI#GDK_3_(GTK_3) - #export GDK_SCALE=2 - - # QT - # https://wiki.archlinux.org/index.php/HiDPI#Qt_5 - # https://doc.qt.io/qt-5/highdpi.html - # https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/ - #export QT_SCALE_FACTOR=2 # Causes qutebrowser UI fonts to have large gaps. - #export QT_FONT_DPI=192 # Scales qutebrowser UI fonts as expected. -} +tmux_new_win() { + local -r command="$1" + local -r window_id=$(counter_next) + local -r window_name=$(basename "$command") + local -r pane=0 + + log \ + '[debug] tmux window_id:"%s", window_name:"%s", command:"%s"' \ + "$window_id" "$window_name" "$command" -launch_common() { - local -r scripts_dir=~/.xlaunch.d - - # XXX dunst lazily started by dbus? - dunst --startup_notification -conf ~/.config/dunst/dunstrc & - xbindkeys - xscreensaver & - dpi_scale& - #mpd --kill || true - #mpd - log '[error] Looking for scripts in directory: "%s"' "$scripts_dir" - for script in "$scripts_dir"/*; do - log '[debug] Launching script: "%s"' "$script" - "$script" - done + $TMUX new-window -t "$SESSION" -n "$window_name" + $TMUX send-keys -t "$SESSION":"$window_id"."$pane" "$command" ENTER } -launch_specialized() { - local -r scripts_dir=~/.xlaunch.d."$(hostname)" +launch_from_directory() { + local -r scripts_dir="$1" - log '[error] Looking for scripts in directory: "%s"' "$scripts_dir" + log '[info] Looking for scripts in directory: "%s"' "$scripts_dir" if test -d "$scripts_dir" then for script in "$scripts_dir"/*; do log '[debug] Launching script: "%s"' "$script" - "$script" + tmux_new_win "$script" + sleep 0.1 # TODO Find a way to block between starts instead. done else - log '[error] scripts_dir not found: %s' "$scripts_dir" + log '[warning] Directory not found: %s' "$scripts_dir" fi } -main() { - log '[info] Starting X11' +_start() { + $TMUX new-session -d -s "$SESSION" + $TMUX set-option -gt "$SESSION" allow-rename off - launch_common - launch_specialized + _counter_file=$(mktemp) + launch_from_directory ~/.xlaunch.d + launch_from_directory ~/.xlaunch.d."$(hostname)" +} +_startx() { + log '[info] Starting X11' + _restart log '[info] Launching dwm' exec dwm } -main +_stop() { + $TMUX kill-session -t "$SESSION" +} + +_restart() { + _stop || true + _start +} + +_attach() { + $TMUX attach -t "$SESSION" +} + +main() { + local -r command="$1" + + case "$command" in + #'' ) _startx;; + 'startx' ) _startx;; + 'start' ) _start;; + 'stop' ) _stop;; + 'restart' ) _restart;; + 'attach' ) _attach;; + *) + echo "[error] Unknown command: \"$command\". Known: startx, start, stop, restart, attach." + exit 1;; + esac +} + +main "$*"