diff options
author | B Stack <bgstack15@gmail.com> | 2020-03-20 23:31:47 +0000 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2020-03-20 23:31:47 +0000 |
commit | de27241bd617ac3a37fdd1511d173743704e615e (patch) | |
tree | 4521e58dbb6f7a057dd5fde71b4230b115b8b326 /alt/logout-manager-trayicon.sh | |
parent | Merge branch 'add-ncurses' into 'master' (diff) | |
parent | move debian/ to stackrpms (diff) | |
download | logout-manager-de27241bd617ac3a37fdd1511d173743704e615e.tar.gz logout-manager-de27241bd617ac3a37fdd1511d173743704e615e.tar.bz2 logout-manager-de27241bd617ac3a37fdd1511d173743704e615e.zip |
Merge branch 'add-trayicon' into 'master'
release 0.0.2
Closes #1
See merge request bgstack15/logout-manager!2
Diffstat (limited to 'alt/logout-manager-trayicon.sh')
-rwxr-xr-x | alt/logout-manager-trayicon.sh | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/alt/logout-manager-trayicon.sh b/alt/logout-manager-trayicon.sh new file mode 100755 index 0000000..22cca5f --- /dev/null +++ b/alt/logout-manager-trayicon.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env sh +# File: logout-manager-trayicon.sh +# License: CC-BY-SA 4.0 +# Author: bgstack15 +# Startdate: 2020-03-19 13:34 +# Title: Tray icon for logout-manager +# Purpose: To show a tray icon for logout options +# History: +# Alternative version of a trayicon that depends on mktrayicon +# Usage: +# Reference: +# keyboard-leds-trayicons +# Improve: +# Dependencies: +# raw: mktrayicon, awk, xset +# devuan: mktrayicon, mawk | gawk, x11-xserver-utils +# Documentation: +# This script works just fine. I just want to learn how to do this in python, and have icons on the menu. + +# CONFIG FILES +test -z "${LMT_GLOBAL_CONF}" && LMT_GLOBAL_CONF=/etc/logout-manager-trayicon.conf +test -z "${LMT_USER_CONF}" && LMT_USER_CONF="${HOME}/.config/logout-manager-trayicon.conf" +# also accept LMT_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_lmt() { + { test -e "${lmicon}" && echo "q" > "${lmicon}" ; } 1>/dev/null 2>&1 & +} + +# 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 "${LMT_GLOBAL_CONF}" "${LMT_USER_CONF}" "${LMT_CONF}" ; +do + test -r "${thisconf}" && get_conf "${thisconf}" +done + +# DEFAULTS in case configs did not have these values +test -z "${LMT_ICON}" && LMT_ICON=logout + +# INITIALIZATION + +lmicon="/var/run/user/$( id -u )/${$}.logout-manager.icon" + +case "${1}" in + "run-program") + result="$( ps -eo 'pid,user,command:80' | grep -E 'logout-manager --from-[t]rayicon' | awk '{print $1}' )" + if test -n "${result}" + then + kill "${result}" + else + /usr/bin/logout-manager --from-trayicon + fi + ;; + *) + test "ON" = "ON" && { + mkfifo "${lmicon}" + mktrayicon "${lmicon}" & + echo "i ${LMT_ICON}" > "${lmicon}" + echo "m lock,logout-manager-cli.py lock|logout,logout-manager-cli.py logout|hibernate,logout-manager-cli.py hibernate|shutdown,logout-manager-cli.py shutdown|reboot,logout-manager-cli.py reboot|-----|Logged in as ${USER}|hide tray icon,echo 'q' > ${lmicon} ; kill -10 $$ 1>/dev/null 2>&1" > "${lmicon}" + echo "c $0 run-program" > "${lmicon}" + echo "t ${DRYRUN:+DRYRUN MODE: }Logged in as $USER" > "${lmicon}" + } + ;; +esac + +trap 'trap "" 2 10 ; clean_lmt' 2 10 # CTRL-C SIGUSR1 |