diff options
Diffstat (limited to 'src/usr')
5 files changed, 173 insertions, 0 deletions
diff --git a/src/usr/bin/keyboard-leds-trayicons.sh b/src/usr/bin/keyboard-leds-trayicons.sh new file mode 100755 index 0000000..18ce82a --- /dev/null +++ b/src/usr/bin/keyboard-leds-trayicons.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env sh +# File: keyboard-leds-trayicons.sh +# License: CC-BY-SA 4.0 +# Author: bgstack15 +# Startdate: 2020-02-13 15:30 +# Title: Substitute for Keyboard LED Indicators +# Purpose: For systems that do not show LEDs for capslock and numlock +# History: +# Usage: +# Reference: +# some Internet place that demonstrated how to use xset q +# some Internet place that showed how to convert the decimal to binary with awk +# get_conf comes from framework.sh +# Improve: +# provide way to change status of capslock by clicking the icon? +# Dependencies: +# binaries: mktrayicon, awk, xset + +# little c: https://visualpharm.com/free-icons/c%20letter-595b40b65ba036ed117d1027 +# license for icons: Use for free, but link to [icons8](https://icons8.com/license) + +# CONFIG FILES +test -z "${KLT_GLOBAL_CONF}" && KLT_GLOBAL_CONF=/etc/keyboard-leds-trayicons.conf +test -z "${KLT_USER_CONF}" && KLT_USER_CONF="${HOME}/.config/keyboard-leds-trayicons.conf" +# also accept KLT_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_keyboard_leds_trayicons() { + { test -e "${capslockicon}" && echo "q" > "${capslockicon}" ; } 1>/dev/null 2>&1 & + { test -e "${numlockicon}" && echo "q" > "${numlockicon}" ; } 1>/dev/null 2>&1 & + sleep 1 && rm -f "${capslockicon}" "${numlockicon}" "${KLT_KILLFILE}" +} + +get_led_mask() { + xset q | awk 'function d2b(d,b) {while(d) {b=d%2b;d=int(d/2)}return(b)} /LED/{print d2b($NF)}' +} + +mask_position_on() { + # call: mask_position_on "${LEDS}" "${ledposition}" + ___result="$( printf "%08d" "${1}" | tail -c "${2}" | head -c 1 )" + ___result=$(( 1 - ___result )) + return "${___result}" +} + +is_capslock_on() { + # call: get_led_mask | is_capslock_on && echo "yes" + read ___ico + mask_position_on "${___ico}" "1" +} + +is_numlock_on() { + # call: get_led_mask | is_numlock_on && echo "yes" + read ___ico + mask_position_on "${___ico}" "2" +} + +# 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 "${KLT_GLOBAL_CONF}" "${KLT_USER_CONF}" "${KLT_CONF}" ; +do + test -r "${thisconf}" && get_conf "${thisconf}" +done + +# DEFAULTS in case configs did not have these values +test -z "${KLT_CAPS_ON_ICON}" && KLT_CAPS_ON_ICON=capslock-on +test -z "${KLT_CAPS_OFF_ICON}" && KLT_CAPS_OFF_ICON=capslock-off +test -z "${KLT_CAPS_ON_ICON}" && KLT_CAPS_ON_ICON=numlock-on +test -z "${KLT_CAPS_OFF_ICON}" && KLT_CAPS_OFF_ICON=numlock-off +test -z "${KLT_KILLFILE}" && KLT_KILLFILE="/tmp/kill-all-leds-trayicons" + +# INITIALIZATION + +capslockicon="/var/run/user/$( id -u )/${$}.cap.icon" +numlockicon="/var/run/user/$( id -u )/${$}.num.icon" + +test "ON" = "ON" && { + mkfifo "${capslockicon}" + mkfifo "${numlockicon}" + + mktrayicon "${capslockicon}" & + mktrayicon "${numlockicon}" & + + echo "m quit,echo 'q' > ${capslockicon} ; touch "${KLT_KILLFILE}"" > "${capslockicon}" + echo "m quit,echo 'q' > ${numlockicon} ; touch "${KLT_KILLFILE}"" > "${numlockicon}" +} + +caps_status_old=-1 +num_status_old=-1 + +rm -f "${KLT_KILLFILE}" + +trap 'trap "" 2 ; touch "${KLT_KILLFILE}" ' 2 # CTRL-C + +while ! test -e "${KLT_KILLFILE}" 2>/dev/null ; +do + x="$( get_led_mask )" + caps_status_now=0 + num_status_now=0 + echo "${x}" | is_capslock_on && caps_status_now=1 + echo "${x}" | is_numlock_on && num_status_now=1 + + if test "${caps_status_now}" != "${caps_status_old}" ; + then + test -p "${capslockicon}" && case "${caps_status_now}" in + 1) + test -n "${KLT_DEBUG}" && echo "capslock on (icon file ${KLT_CAPS_ON_ICON})" 1>&2 + echo "i ${KLT_CAPS_ON_ICON}" > "${capslockicon}" + echo "t capslock on" > "${capslockicon}" + ;; + 0) + test -n "${KLT_DEBUG}" && echo "capslock off (icon file ${KLT_CAPS_OFF_ICON})" 1>&2 + echo "i ${KLT_CAPS_OFF_ICON}" > "${capslockicon}" + echo "t capslock off" > "${capslockicon}" + ;; + esac + fi + + if test "${num_status_now}" != "${num_status_old}" ; + then + test -p "${numlockicon}" && case "${num_status_now}" in + 1) + test -n "${KLT_DEBUG}" && echo "numlock on (icon file ${KLT_NUM_ON_ICON})" 1>&2 + echo "i ${KLT_NUM_ON_ICON}" > "${numlockicon}" + echo "t numlock on" > "${numlockicon}" + ;; + 0) + test -n "${KLT_DEBUG}" && echo "numlock off (icon file ${KLT_NUM_OFF_ICON})" 1>&2 + echo "i ${KLT_NUM_OFF_ICON}" > "${numlockicon}" + echo "t numlock off" > "${numlockicon}" + ;; + esac + fi + + caps_status_old="${caps_status_now}" + num_status_old="${num_status_now}" + sleep 0.75 +done + +# safety shutoff +clean_keyboard_leds_trayicons diff --git a/src/usr/share/icons/hicolor/scalable/status/capslock-off.svg b/src/usr/share/icons/hicolor/scalable/status/capslock-off.svg new file mode 100644 index 0000000..3d3be8e --- /dev/null +++ b/src/usr/share/icons/hicolor/scalable/status/capslock-off.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"> + <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Bitstream Vera Sans" d="M 9.8125 4 A 2.0002 2.0002 0 0 0 8.59375 4.59375 L 5.59375 7.59375 A 2.0002 2.0002 0 0 0 5 9 L 5 17 A 2.0002 2.0002 0 0 0 5.59375 18.40625 L 8.59375 21.40625 A 2.0002 2.0002 0 0 0 10 22 L 16 22 A 2.0002 2.0002 0 0 0 17.40625 21.40625 L 20.40625 18.40625 L 17.59375 15.59375 L 15.1875 18 L 10.8125 18 L 9 16.1875 L 9 9.8125 L 10.8125 8 L 15.1875 8 L 17.59375 10.40625 L 20.40625 7.59375 L 17.40625 4.59375 A 2.0002 2.0002 0 0 0 16 4 L 10 4 A 2.0002 2.0002 0 0 0 9.8125 4 z" overflow="visible" enable-background="accumulate" font-family="Bitstream Vera Sans"/> +</svg>
\ No newline at end of file diff --git a/src/usr/share/icons/hicolor/scalable/status/capslock-on.svg b/src/usr/share/icons/hicolor/scalable/status/capslock-on.svg new file mode 100644 index 0000000..f4db539 --- /dev/null +++ b/src/usr/share/icons/hicolor/scalable/status/capslock-on.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"> + <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Bitstream Vera Sans" d="M 8.8125 0 A 2.0002 2.0002 0 0 0 7.59375 0.59375 L 3.59375 4.59375 A 2.0002 2.0002 0 0 0 3 6 L 3 20 A 2.0002 2.0002 0 0 0 3.59375 21.40625 L 7.59375 25.40625 A 2.0002 2.0002 0 0 0 9 26 L 17 26 A 2.0002 2.0002 0 0 0 18.40625 25.40625 L 22.40625 21.40625 L 19.59375 18.59375 L 16.1875 22 L 9.8125 22 L 7 19.1875 L 7 6.8125 L 9.8125 4 L 16.1875 4 L 19.59375 7.40625 L 22.40625 4.59375 L 18.40625 0.59375 A 2.0002 2.0002 0 0 0 17 0 L 9 0 A 2.0002 2.0002 0 0 0 8.8125 0 z" overflow="visible" enable-background="accumulate" font-family="Bitstream Vera Sans"/> +</svg>
\ No newline at end of file diff --git a/src/usr/share/icons/hicolor/scalable/status/numlock-off.svg b/src/usr/share/icons/hicolor/scalable/status/numlock-off.svg new file mode 100644 index 0000000..549e284 --- /dev/null +++ b/src/usr/share/icons/hicolor/scalable/status/numlock-off.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"> + <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Bitstream Vera Sans" d="M 5 4 L 5 22 L 9 22 L 9 10 L 11.65625 8 L 15.1875 8 L 17 9.8125 L 17 22 L 21 22 L 21 9 A 2.0002 2.0002 0 0 0 20.40625 7.59375 L 17.40625 4.59375 A 2.0002 2.0002 0 0 0 16 4 L 11 4 A 2.0002 2.0002 0 0 0 10.8125 4 A 2.0002 2.0002 0 0 0 9.8125 4.40625 L 9 5 L 9 4 L 5 4 z" overflow="visible" enable-background="accumulate" font-family="Bitstream Vera Sans"/> +</svg>
\ No newline at end of file diff --git a/src/usr/share/icons/hicolor/scalable/status/numlock-on.svg b/src/usr/share/icons/hicolor/scalable/status/numlock-on.svg new file mode 100644 index 0000000..ef65035 --- /dev/null +++ b/src/usr/share/icons/hicolor/scalable/status/numlock-on.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 26 26"> + <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Bitstream Vera Sans" d="M 3 0 L 3 26 L 7 26 L 7 9.625 L 19 20.875 L 19 26 L 23 26 L 23 0 L 19 0 L 19 15.375 L 7 4.125 L 7 0 L 3 0 z" overflow="visible" enable-background="accumulate" font-family="Bitstream Vera Sans"/> +</svg>
\ No newline at end of file |