aboutsummaryrefslogtreecommitdiff
path: root/src/usr
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-07-13 09:56:51 -0400
committerB. Stack <bgstack15@gmail.com>2023-07-13 09:56:51 -0400
commit3fcd32aa6d295ac62fe0e526931fc556a4060343 (patch)
tree244c95a3ed1cf21c4cb2705276062d98cd7e10ae /src/usr
downloadfix-alttab-3fcd32aa6d295ac62fe0e526931fc556a4060343.tar.gz
fix-alttab-3fcd32aa6d295ac62fe0e526931fc556a4060343.tar.bz2
fix-alttab-3fcd32aa6d295ac62fe0e526931fc556a4060343.zip
initial commit
Diffstat (limited to 'src/usr')
-rwxr-xr-xsrc/usr/bin/fix-alttab-daemon43
-rwxr-xr-xsrc/usr/libexec/fix-alttab75
-rw-r--r--src/usr/share/man/man1/fix-alttab-daemon.1.txt33
-rw-r--r--src/usr/share/man/man1/fix-alttab.1.txt33
4 files changed, 184 insertions, 0 deletions
diff --git a/src/usr/bin/fix-alttab-daemon b/src/usr/bin/fix-alttab-daemon
new file mode 100755
index 0000000..f32084f
--- /dev/null
+++ b/src/usr/bin/fix-alttab-daemon
@@ -0,0 +1,43 @@
+#!/bin/sh
+# File: fix-alttab-daemon
+# Location: /usr/bin
+# Author: bgstack15
+# Startdate: 2023-07-10-2 08:55
+# SPDX-License-Identifier: GPL-3.0
+# Title: fix-alttab-daemon
+# Project: fix-alttab
+# Purpose: Detect changes to connected HDMI monitors
+# History:
+# Usage:
+# run in ~/.fluxbox/startup in the background
+# Reference:
+# Improve:
+# Dependencies:
+# dep-devuan: bgscripts-core
+# Documentation: README.md
+
+# load settings
+test -z "${DEFAULTSDIR}" && DEFAULTSDIR=/etc/sysconfig
+grep -qiE 'de(vu|bi)an|ubuntu|mint' /etc/os-release 1>/dev/null 2>&1 && DEFAULTSDIR=/etc/default
+test -f "${DEFAULTSDIR}/fix-alttab" && . "${DEFAULTSDIR}/fix-alttab"
+test -f "${XDG_CONFIG_HOME:-~/.config}/fix-alttab" && . "${XDG_CONFIG_HOME:-~/.config}/fix-alttab"
+test -z "${FIX_ALTTAB_BIN}" && FIX_ALTTAB_BIN=/usr/libexec/fix-alttab
+command -v plecho 1>/dev/null && _use_plecho=1
+unset _laststatus
+while ! test -f /tmp/stop-fix-alttab-daemon ;
+do
+ sleep "${ALTTAB_DAEMON_LOOP:-3}"
+ _status="$( APPLY= "${FIX_ALTTAB_BIN}" )"
+ test "${_status}" != "${_laststatus}" && {
+ APPLY=1 "${FIX_ALTTAB_BIN}" | \
+ {
+ if test "${_use_plecho}" = "1" ;
+ then
+ timeout 2 plecho
+ else
+ timeout 2 cat
+ fi
+ }
+ } | tee -a "${ALTTAB_DAEMON_LOGFILE:-fix-alttab-daemon.log}"
+ _laststatus="${_status}"
+done
diff --git a/src/usr/libexec/fix-alttab b/src/usr/libexec/fix-alttab
new file mode 100755
index 0000000..c0b68b2
--- /dev/null
+++ b/src/usr/libexec/fix-alttab
@@ -0,0 +1,75 @@
+#!/bin/sh
+# File: fix-alttab
+# Location: /usr/libexec/fix-alttab
+# Author: bgstack15
+# Startdate: 2023-07-10-2 08:10
+# SPDX-License-Identifier: GPL-3.0
+# Title: fix-alttab
+# History:
+# Usage:
+# called by fix-alttab-daemon
+# Reference:
+# https://unix.stackexchange.com/questions/537529/how-do-i-get-xdg-config-home-from-a-shell-script-command-line
+# Improve:
+# Dependencies:
+# dep-devuan: xrandr, alttab
+# Documentation: README.md
+
+# load settings
+test -z "${DEFAULTSDIR}" && DEFAULTSDIR=/etc/sysconfig
+grep -qiE 'de(vu|bi)an|ubuntu|mint' /etc/os-release 1>/dev/null 2>&1 && DEFAULTSDIR=/etc/default
+test -f "${DEFAULTSDIR}/fix-alttab" && . "${DEFAULTSDIR}/fix-alttab"
+test -f "${XDG_CONFIG_HOME:-~/.config}/fix-alttab" && . "${XDG_CONFIG_HOME:-~/.config}/fix-alttab"
+# just in case no settings defined there
+test -z "${ALTTAB_COMMON}" && ALTTAB_COMMON="alttab -w 1 -theme numix-circle"
+test -z "${ALTTAB_LEFTYES_RIGHTYES}" && ALTTAB_LEFTYES_RIGHTYES=""
+test -z "${ALTTAB_LEFTNO_RIGHTYES}" && ALTTAB_LEFTNO_RIGHTYES="-vp 1920x1080+1920+0"
+test -z "${ALTTAB_LEFTYES_RIGHTNO}" && ALTTAB_LEFTYES_RIGHTNO="" #unsupported
+test -z "${ALTTAB_LEFTNO_RIGHTNO}" && ALTTAB_LEFTNO_RIGHTNO="" # unsupported
+
+# for better security, strip out any semicolons from these values because we evaluate without quotes
+_strip() {
+ printf '%s' "${@}" | sed -r -e 's/;.*$//;'
+}
+ALTTAB_COMMON="$( _strip "${ALTTAB_COMMON}" )"
+ALTTAB_LEFTYES_RIGHTYES="$( _strip "${ALTTAB_LEFTYES_RIGHTYES}" )"
+ALTTAB_LEFTNO_RIGHTYES="$( _strip "${ALTTAB_LEFTNO_RIGHTYES}" )"
+ALTTABLEFTYES_RIGHTNO="$( _strip "${ALTTABLEFTYES_RIGHTNO}" )"
+ALTTAB_LEFTNO_RIGHTNO="$( _strip "${ALTTAB_LEFTNO_RIGHTNO}" )"
+
+# always evaluate this
+_ALTTAB_COMMAND_TO_KILL="$( echo "${ALTTAB_COMMON}" | awk '{print $1}' )"
+
+# main
+# set environment variables "left" and "right" to yes or no, to indicate if monitor is there.
+unset right left
+eval $( xrandr | awk 'BEGIN{a[0]="no";a[1]="yes"}/HDMI-1/{if($2~/\<connected/){r=1;}else{r=0};} /HDMI-0/{if($2~/\<connected/){l=1;}else{l=0;};} END{print "right="a[r];print "left="a[l];}' )
+unset _ALTTAB_PARAMS
+case "${left}${right}" in
+ yesyes)
+ printf '%s\n' "Using left yes, right yes"
+ _ALTTAB_PARAMS="${ALTTAB_LEFTYES_RIGHTYES}"
+ ;;
+ noyes)
+ printf '%s\n' "Using left no, right yes"
+ _ALTTAB_PARAMS="${ALTTAB_LEFTNO_RIGHTYES}"
+ ;;
+ yesno)
+ printf '%s\n' "Using left no, right yes"
+ _ALTTAB_PARAMS="${ALTTAB_LEFTNO_RIGHTYES}"
+ ;;
+ nono)
+ printf '%s\n' "Using left no, right no: UNSUPPORTED!"
+ _ALTTAB_PARAMS="${ALTTAB_LEFTNO_RIGHTNO}"
+ ;;
+ *)
+ printf '%s\n' "Unknown config: leftright \"${left}${right}\". Aborted." 1>&2 ; exit 1
+ ;;
+esac
+test -n "${APPLY}" && {
+ test -n "${DEBUG}" && set -x
+ killall "${_ALTTAB_COMMAND_TO_KILL}"
+ # unquoted here:
+ ${ALTTAB_COMMON} ${_ALTTAB_PARAMS} &
+ set +x
+}
diff --git a/src/usr/share/man/man1/fix-alttab-daemon.1.txt b/src/usr/share/man/man1/fix-alttab-daemon.1.txt
new file mode 100644
index 0000000..780f145
--- /dev/null
+++ b/src/usr/share/man/man1/fix-alttab-daemon.1.txt
@@ -0,0 +1,33 @@
+title fix-alttab-daemon
+section 1
+project fix-alttab
+volume General Commands Manual
+date July 2023
+=====
+NAME
+ fix-alttab-daemon - dynamically change where alttab displays based on available displays
+SYNOPSIS
+ fix-alttab-daemon
+OPTIONS
+ None
+ENVIRONMENT
+ XDG_CONFIG_HOME is normally ~/.config, and determines where the per-user fix-alttab configuration file lives.
+DESCRIPTION
+ This daemon loops over fix-alttab, an included script that performs the work of checking available monitors and then running alttab with various configs defined in the config file (normally ~/.config/fix-alttab or /etc/sysconfig/fix-alttab)
+ The point is to keep alttab within the viewable monitor area if I change inputs on one of my workstation monitors.
+CONFIGURATION
+ These options are loaded from /etc/sysconfig/fix-alttab and then ~/.config/fix-alttab, so the last loaded value is used.
+ ALTTAB_DAEMON_LOOP how many seconds to sleep between each instance of checking the available displays. Default is 3.
+ ALTTAB_DAEMON_LOGFILE where to put logs. Default is "${XDG_RUNTIME_DIR}/fix-alttab-daemon.log"
+ ALTTAB_COMMON is the base command and any parameters to run. The first word of this value is the binary name that will be killalled if the alttab daemon needs to be restarted. Default is "alttab -w 1 -theme numix-circle"
+ The next four options are related to which monitors/X11 displays are available, and what options to pass to alttab when restarting it.
+ ALTTAB_LEFTYES_RIGHTYES ""
+ ALTTAB_LEFTNO_RIGHTYES "-vp 1920x1080+1920+0" which is the X11 geometry for this -vp options of alttab, which means that the maximum possible display screen for the alttab program is a 1920x1080-sized box, starting at pixel 1920,0, so my right monitor in a basic side-by-side organization.
+AUTHOR
+ B. Stack <bgstack15@gmail.com>
+COPYRIGHT
+ GPL 3.0
+SEE ALSO
+ `fix-alttab(1)`
+BUGS
+ Report any anomalies to the author.
diff --git a/src/usr/share/man/man1/fix-alttab.1.txt b/src/usr/share/man/man1/fix-alttab.1.txt
new file mode 100644
index 0000000..233a793
--- /dev/null
+++ b/src/usr/share/man/man1/fix-alttab.1.txt
@@ -0,0 +1,33 @@
+title fix-alttab
+section 1
+project fix-alttab
+volume General Commands Manual
+date July 2023
+=====
+NAME
+ fix-alttab - check active monitors and re-run alttab if different from before
+SYNOPSIS
+ fix-alttab
+OPTIONS
+ None
+ENVIRONMENT
+ XDG_CONFIG_HOME is normally ~/.config, and determines where the per-user fix-alttab configuration file lives.
+ APPLY If 1, then actually re-run `alttab(1)` with the parameters in the config file.
+DESCRIPTION
+ This is the main logic to react to current monitor status. that performs the work of checking available monitors and then running alttab with various configs defined in the config file (normally ~/.config/fix-alttab or /etc/sysconfig/fix-alttab)
+ The point is to keep alttab within the viewable monitor area if I change inputs on one of my workstation monitors.
+ Run this with `APPLY` unset, to print which monitors it detects. Then run with `APPLY=1` to re-run alttab.
+CONFIGURATION
+ These options are loaded from /etc/sysconfig/fix-alttab and then ~/.config/fix-alttab, so the last loaded value is used.
+ ALTTAB_COMMON is the base command and any parameters to run. The first word of this value is the binary name that will be killalled if the alttab daemon needs to be restarted. Default is "alttab -w 1 -theme numix-circle"
+ The next four options are related to which monitors/X11 displays are available, and what options to pass to alttab when restarting it.
+ ALTTAB_LEFTYES_RIGHTYES ""
+ ALTTAB_LEFTNO_RIGHTYES "-vp 1920x1080+1920+0" which is the X11 geometry for this -vp options of alttab, which means that the maximum possible display screen for the alttab program is a 1920x1080-sized box, starting at pixel 1920,0, so my right monitor in a basic side-by-side organization.
+AUTHOR
+ B. Stack <bgstack15@gmail.com>
+COPYRIGHT
+ GPL 3.0
+SEE ALSO
+ `fix-alttab-daemon(1)`
+BUGS
+ Report any anomalies to the author.
bgstack15