diff options
author | B. Stack <bgstack15@gmail.com> | 2022-12-02 15:40:49 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-12-02 15:40:49 -0500 |
commit | 93b900394d3eb604af0ae6c41eb328ae17d7f84f (patch) | |
tree | cde767442b02ba2f1a099dbb9d7e4eb27d7d1ed0 /src/usr/bin | |
download | arandr-trayicon-master.tar.gz arandr-trayicon-master.tar.bz2 arandr-trayicon-master.zip |
Diffstat (limited to 'src/usr/bin')
-rwxr-xr-x | src/usr/bin/arandr-trayicon | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/usr/bin/arandr-trayicon b/src/usr/bin/arandr-trayicon new file mode 100755 index 0000000..9a66c9e --- /dev/null +++ b/src/usr/bin/arandr-trayicon @@ -0,0 +1,120 @@ +#!/bin/sh +# File: arandr-trayicon +# Location: /usr/bin +# Author: bgstack15 +# SPDX-License-Identifer: CC-BY-SA 4.0 +# Startdate: 2022-11-16 +# Title: Substitute for Keyboard LED Indicators +# Project: arandr-trayicon +# Purpose: Easy menu for switching between preconfigured display layouts +# History: +# Usage: +# Reference: +# keyboard-leds-trayicons +# Improve: +# Dependencies: +# dep-raw: mktrayicon, awk +# dep-devuan: mktrayicon, mawk | gawk +# An admin needs to build /etc/screenlayouts/ scripts, probably: +# mirror.sh, laptop-only.sh, hdmi-only.sh, extend-desktop.sh + +# CONFIG FILES +test -z "${AT_GLOBAL_CONF}" && AT_GLOBAL_CONF=/etc/arandr-trayicon.conf +test -z "${AT_USER_CONF}" && AT_USER_CONF="${HOME}/.config/arandr-trayicon.conf" +# also accept AT_CONF + +# FUNCTIONS + +get_conf() { + # Ripped from framework.sh + # call: get_conf "${conffile}" + local _infile="$1" + local _tmpfile1="$( mktemp )" + sed -e 's/^\s*//;s/\s*$//;/^[#$]/d;s/\s*[^\]#.*$//;' "${_infile}" | grep -viE "^$" | while read _line ; + do + local _left="$( echo "${_line}" | cut -d'=' -f1 )" + eval "_thisval=\"\${${_left}}\"" + test -z "${_thisval}" && echo "${_line}" >> "${_tmpfile1}" + done + test -f "${_tmpfile1}" && { . "${_tmpfile1}" 1>/dev/null 2>&1 ; } + /bin/rm -rf "${_tmpfile1}" 1>/dev/null 2>&1 +} + +clean_arandr_trayicon() { + { test -e "${arandricon}" && echo "q" > "${arandricon}" ; } 1>/dev/null 2>&1 & + sleep 1 && rm -f "${arandricon}" "${AT_KILLFILE}" +} + +mask_position_on() { + # call: mask_position_on "${LEDS}" "${ledposition}" + ___result="$( printf "%08d" "${1}" | tail -c "${2}" | head -c 1 )" + ___result=$(( 1 - ___result )) + return "${___result}" +} + +# LOAD CONFIGS +# order is important! The last one called gets precedence. +# instead of simply dot-sourcing the conf file, pass it to get_conf which only applies new values, so this process's environment is preserved +for thisconf in "${AT_CONF}" "${AT_USER_CONF}" "${AT_GLOBAL_CONF}" ; +do + test -r "${thisconf}" && get_conf "${thisconf}" +done + +# DEFAULTS in case configs did not have these values +# an alternative icon is org.xfce.settings.display +test -z "${AT_ICON}" && AT_ICON=arandr-trayicon +test -z "${AT_KILLFILE}" && AT_KILLFILE="/tmp/kill-arandr-trayicon" + +# INITIALIZATION + +arandricon="/var/run/user/$( id -u )/${$}.arandr.icon" + +test "ON" = "ON" && { + mkfifo "${arandricon}" + + mktrayicon -i "${AT_ICON}" "${arandricon}" & + echo "i ${AT_ICON}" | tee "${arandricon}" + # Disabled because xfce4-settings needs something extra to apply which I have not learned yet + #echo "c xfce4-display-settings --minimal" | tee "${arandricon}" + echo "c arandr" | tee "${arandricon}" + echo "t Display settings" | tee "${arandricon}" + + # Disabled because xfce4-settings needs something extra to apply which I have not learned yet + #menu_string="m quick dialog,xfce4-display-settings --minimal|full settings,xfce4-display-settings|" + menu_string="m " + # loop through admin-defined layouts + for file in /etc/screenlayouts/*.sh ; + do + test -s "${file}" && { + name="$( basename "${file}" | sed -r -e "s/\.sh$//;" )" + grep -qiE 'name ?=' "${file}" && name="$( awk -F'=' '/\<[Nn]ame\>/{print $2}' )" + menu_string="${menu_string:+${menu_string}|}${name},sh -x ${file}" + } + done + # if any user-defined layouts exist, make a separator in the menu + test -n "$( find ~/.screenlayout/*.sh -maxdepth 0 -print -quit 2>/dev/null )" && menu_string="${menu_string}|" + # loop through user-defined layouts + for file in ~/.screenlayout/*.sh ; + do + test -s "${file}" && { + name="$( basename "${file}" | sed -r -e "s/\.sh$//;" )" + grep -qiE 'name ?=' "${file}" && name="$( awk -F'=' '/\<[Nn]ame\>/{print $2}' )" + menu_string="${menu_string:+${menu_string}|}${name},sh -x ${file}" + } + done + menu_string="${menu_string:+${menu_string}|}|quit,echo 'q' > ${arandricon} ; touch \"${AT_KILLFILE}\"" + #echo "menu_string=${menu_string}" ; + echo "${menu_string}" | tee "${arandricon}" +} + +rm -f "${AT_KILLFILE}" + +trap 'trap "" 2 ; touch "${AT_KILLFILE}" ' 2 # CTRL-C + +while ! test -e "${AT_KILLFILE}" 2>/dev/null ; +do + sleep 5 +done + +# safety shutoff +clean_arandr_trayicon |