Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

code heavily refactored, still needs some love to be polished

  • Loading branch information...
commit 5cfbfc129124cf4de21ab33e140bfe634b4eb7cf 1 parent 6d0db0b
@poliva authored
View
2  Makefile
@@ -17,6 +17,8 @@ install:
$(INSTALL) $(srcdir)/lightum-indicator $(bindir)/lightum-indicator
mkdir -p $(shadir)
$(INSTALL) $(srcdir)/cappind-lightum.py $(shadir)/cappind-lightum.py
+ $(INSTALL) $(srcdir)/lightum-indicator-include $(shadir)/lightum-indicator-include
+ $(INSTALL) $(srcdir)/lightum-indicator-helper $(shadir)/lightum-indicator-helper
mkdir -p $(appdir)
$(INSTALLDATA) $(srcdir)/lightum-indicator.desktop $(appdir)/lightum-indicator.desktop
mkdir -p $(shadir)/icons/
View
93 cappind-lightum.py
@@ -1,4 +1,16 @@
#!/usr/bin/python
+#
+# lightum-indicator applet
+# (c) 2012 Pau Oliva Fora
+#
+# based on:
+# cappindicator, command line generic appindicator
+# by reda_ea <reda.ea@gmail.com>
+# license is do whatever you want with this code i don't care
+#
+# changes introduced in lightum-indicator licensed under GPLv2+
+#
+
import pygtk
pygtk.require('2.0')
import gtk
@@ -7,50 +19,47 @@
import subprocess
import argparse
import gobject
+import os
ICON_THEME = gtk.icon_theme_get_default()
-# cappindicator, command line generic appindicator
-# by reda_ea <reda.ea@gmail.com>
-# license is do whatever you want with this code i don't care
-
-# accepts input in forms of multiple lines
-# of the form menu:submenu:...:entry:command
-# empty command means separator
-# implied parent menus are automatically created
-# entries in the same path appear in the same order as in the input
-# undefined behaviour on wrong input
-
-# modified by pof for lightum-indicator:
-# if a submenu item begins with '*' it will be shown as disabled
-
-class CmdAppIndicator:
+class LightumIndicator:
- def __init__(self, persist, icon, label):
- # parameters
- self.persist = persist #True
+ def __init__(self):
+ # icon
+ icon = "/usr/share/lightum-indicator/icons/lightum.png"
self.icon = icon #'terminal'
+ # status
self.status = appindicator.STATUS_ATTENTION # ACTIVE
- self.label = label
# indicator
- self.ind = appindicator.Indicator ("c-indicator", self.icon, appindicator.CATEGORY_OTHER)
- self.ind.set_label(self.label)
+ self.ind = appindicator.Indicator ("lightum-indicator", self.icon, appindicator.CATEGORY_OTHER)
#self.ind.set_attention_icon (self.icon)
self.ind.set_status(self.status)
# menu
self.menu = gtk.Menu()
+ self.read_config()
+
+
+ def read_config(self):
+ for i in self.menu.get_children():
+ self.menu.remove(i) # check here if you want to remove this child
self.submenus = dict()
- for line in sys.stdin:
+ filename = os.getenv("HOME") + '/.config/lightum/indicator.menu'
+ in_file = open(filename,"r")
+ while (1):
+ line = in_file.readline()
+ if line == "":
+ break
line = line[0:len(line)-1] # removing last '\n'
self.add_menu(self.menu, line, line)
- if self.persist:
- self.add_quit()
+ in_file.close()
+ self.add_quit()
self.menu.show()
self.ind.set_menu(self.menu)
def add_entry(self, parent, name, path, state):
ent = gtk.MenuItem(name)
- ent.connect("activate", self.say, path)
+ ent.connect("activate", self.run, path)
ent.show()
if state == 0:
ent.set_sensitive(False)
@@ -68,16 +77,11 @@ def add_quit(self):
ent.show()
self.menu.append(ent)
- def run(self, w, cmd):
- subprocess.Popen(cmd, shell=True)
- if not self.persist:
- gtk.main_quit()
-
- def say(self, w, name):
- print name
- sys.stdout.flush()
- if not self.persist:
- gtk.main_quit()
+ def run(self, w, name):
+ cmd = "/usr/share/lightum-indicator/lightum-indicator-helper " + name
+ p = subprocess.Popen(cmd, shell=True)
+ p.wait()
+ self.read_config()
def get_child(self, parent, name):
if parent not in self.submenus:
@@ -112,22 +116,5 @@ def add_menu(self, parent, line, path):
if __name__ == "__main__":
- # command line params
- parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
- description='Command line generic appindicator.\n\n'
- 'Menu elements are given in standard input as lines in the form:\n\n'
- '\tmenu:submenu:subsubmenu:entry\n\n'
- 'Menu structure is automatically built, selecting a leaf '
- 'will print the associated input line (the whole path).')
- parser.add_argument('-i', '--icon', default='terminal', help='the indicator icon name')
- parser.add_argument('-l', '--label', default='', help='optional label (not recommended)')
- parser.add_argument('-p', '--persist', action='store_true', default=False,
- help='keep the indicator running after a selection (an additional "Quit" entry will be added)')
- parser.add_argument('-t', '--timeout', type=int, default=-1,
- help='a timeout in seconds after which the indicator will be closed')
- args = parser.parse_args()
- if args.timeout >= 0:
- gobject.timeout_add(args.timeout*1000, gtk.main_quit)
- indicator = CmdAppIndicator(args.persist, args.icon, args.label)
+ indicator = LightumIndicator()
gtk.main()
-
View
412 lightum-indicator
@@ -3,35 +3,8 @@
# (c)2012 Pau Oliva Fora
# License: GPLv2+
-VERSION="0.4"
-
-function lightumreload ()
-{
- echo "#!/bin/bash" >${CONFDIR}/lightum-reload.$$
- echo "kill $$" >>${CONFDIR}/lightum-reload.$$
- echo "ps ax |grep 'cappind-lightum.py' |grep -v grep |awk '{print \$1}' |xargs -n 1 kill" >> ${CONFDIR}/lightum-reload.$$
- echo "$0 &" >> ${CONFDIR}/lightum-reload.$$
- echo "rm ${CONFDIR}/lightum-reload.$$" >> ${CONFDIR}/lightum-reload.$$
- chmod 755 ${CONFDIR}/lightum-reload.$$
-}
-
-CONFDIR="${HOME}/.config/lightum/"
-CONFIG="${CONFDIR}/lightum.conf"
-ZEN="zenity --name=lightum --title=lightum "
-
-# make sure zenity is installed
-which zenity 2>&1 >/dev/null
-if [ $? != 0 ]; then
- echo "Missing dependancy: this indicator needs zenity installed to work"
- exit 1
-fi
-
-# make sure lightum is installed
-which lightum 2>&1 >/dev/null
-if [ $? != 0 ]; then
- ${ZEN} --no-wrap --error --text "Missing dependancy: this indicator needs lightum installed to work"
- exit 1
-fi
+# load include file
+source /usr/share/lightum-indicator/lightum-indicator-include
# make sure indicator auto-starts
if [ ! -f "${HOME}/.config/autostart/lightum-indicator.desktop" ]; then
@@ -42,381 +15,8 @@ fi
# make sure lightum is running, otherwise start it
pidof lightum 2>&1 >/dev/null || lightum
-# conf dir must exist
-if [ ! -d "${CONFDIR}" ]; then
- mkdir -p "${CONFDIR}"
-fi
-
-# conf file must exist
-touch "${CONFIG}"
-
-profiles=`grep "^#PROFILE: " ${CONFDIR}/*.conf |cut -f 1 -d ":" |grep -v "${CONFIG}" |sort -u`
-
-currentprofile=`grep "^#PROFILE: " ${CONFIG} |cut -f 2 -d " "`
-if [ -z "${currentprofile}" ]; then currentprofile="Default" ; fi
-
-PROFILEOPTS="Profile:$currentprofile:Save
-Profile:$currentprofile:Save As..."
-
-for file in ${profiles} ; do
- profile=`cat ${file} |grep "^#PROFILE: " |cut -f 2 -d " "`
- if [ "${profile}" == "${currentprofile}" ]; then
- PROFILEOPTS="${PROFILEOPTS}
-Profile:$profile:*Load
-Profile:$profile:*Delete"
- else
- PROFILEOPTS="${PROFILEOPTS}
-Profile:$profile:Load
-Profile:$profile:Delete"
- fi
-done
-
-manualmode=`cat ${CONFIG} |grep "^manualmode="`
-case "$manualmode" in
-"manualmode=1")
-MANUALMODEOPTS="Mode:Auto
-Mode:*Manual"
-IC1="M"
-;;
-*)
-MANUALMODEOPTS="Mode:*Auto
-Mode:Manual"
-IC1="A"
-;;
-esac
-
-workmode=`cat ${CONFIG} |grep "^workmode="`
-case "$workmode" in
-"workmode=1")
-WORKMODEOPTS="Manage:Screen Only
-Manage:*Keyboard Only
-Manage:Screen + Keyboard
-Keyboard Options:Max Brightness
-Keyboard Options:Min Brightness
-Keyboard Options:Dim on idle time
-Screen Options:*Max Backlight
-Screen Options:*Min Backlight
-Screen Options:*Dim on idle time"
-IC2="K"
-;;
-
-"workmode=2")
-WORKMODEOPTS="Manage:*Screen Only
-Manage:Keyboard Only
-Manage:Screen + Keyboard
-Keyboard Options:*Max Brightness
-Keyboard Options:*Min Brightness
-Keyboard Options:*Dim on idle time
-Screen Options:Max Backlight
-Screen Options:Min Backlight
-Screen Options:Dim on idle time"
-IC2="S"
-;;
-
-*)
-WORKMODEOPTS="Manage:Screen Only
-Manage:Keyboard Only
-Manage:*Screen + Keyboard
-Keyboard Options:Max Brightness
-Keyboard Options:Min Brightness
-Keyboard Options:Dim on idle time
-Screen Options:Max Backlight
-Screen Options:Min Backlight
-Screen Options:Dim on idle time"
-IC2="B"
-;;
-
-esac
-
-ICON="/usr/share/lightum-indicator/icons/${IC1}${IC2}.png"
-
-echo "$PROFILEOPTS
-
-$MANUALMODEOPTS
-$WORKMODEOPTS
-About" | \
-/usr/share/lightum-indicator/cappind-lightum.py -p -i ${ICON} | \
-while read s; do
-case "$s" in
-
-"Mode:Auto")
- ${ZEN} --no-wrap --question --text="Reload lightum in auto mode?"
- if [ $? == 0 ]; then
- manualmode=`cat ${CONFIG} |grep "^manualmode="`
- if [ -z "$manualmode" ]; then
- echo "manualmode=0" >> ${CONFIG}
- else
- sed -i "s/^manualmode=.*/manualmode=0/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
-;;
-
-"Mode:Manual")
- ${ZEN} --no-wrap --question --text="Reload lightum in manual mode?"
- if [ $? == 0 ]; then
- manualmode=`cat ${CONFIG} |grep "^manualmode="`
- if [ -z "$manualmode" ]; then
- echo "manualmode=1" >> ${CONFIG}
- else
- sed -i "s/^manualmode=.*/manualmode=1/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
-;;
-
-"Manage:Screen Only")
- ${ZEN} --no-wrap --question --text="Manage only screen backlight?"
- if [ $? == 0 ]; then
- workmode=`cat ${CONFIG} |grep "^workmode="`
- if [ -z "$workmode" ]; then
- echo "workmode=2" >> ${CONFIG}
- else
- sed -i "s/^workmode=.*/workmode=2/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
-;;
-
-"Manage:Keyboard Only")
- ${ZEN} --no-wrap --question --text="Manage only keyboard brightness?"
- if [ $? == 0 ]; then
- workmode=`cat ${CONFIG} |grep "^workmode="`
- if [ -z "$workmode" ]; then
- echo "workmode=1" >> ${CONFIG}
- else
- sed -i "s/^workmode=.*/workmode=1/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
-;;
-
-"Manage:Screen + Keyboard")
- ${ZEN} --no-wrap --question --text="Manage both keyboard brightness and screen backlight?"
- if [ $? == 0 ]; then
- workmode=`cat ${CONFIG} |grep "^workmode="`
- if [ -z "$workmode" ]; then
- echo "workmode=3" >> ${CONFIG}
- else
- sed -i "s/^workmode=.*/workmode=3/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
-;;
-"Keyboard Options:Max Brightness")
- cv=`cat ${CONFIG} |grep "^maxbrightness=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=255 ; fi
- ans=`${ZEN} --forms --add-entry="maximum keyboard brightness value (between 4 and 255)" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 255 ] && [ ${ans} -ge 4 ]; then
- maxbrightness=`cat ${CONFIG} |grep "^maxbrightness="`
- if [ -z "$maxbrightness" ]; then
- echo "maxbrightness=${ans}" >> ${CONFIG}
- else
- sed -i "s/^maxbrightness=.*/maxbrightness=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "max keyboard brightness should be a value between 4 and 255."
- fi
- fi
-;;
-"Keyboard Options:Min Brightness")
- cv=`cat ${CONFIG} |grep "^minbrightness=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=0 ; fi
- ans=`${ZEN} --forms --add-entry="minimum keyboard brightness value (between 0 and 3)" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 3 ] && [ ${ans} -ge 0 ]; then
- minbrightness=`cat ${CONFIG} |grep "^minbrightness="`
- if [ -z "$minbrightness" ]; then
- echo "minbrightness=${ans}" >> ${CONFIG}
- else
- sed -i "s/^minbrightness=.*/minbrightness=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "min keyboard brightness should be a value between 0 and 3"
- fi
- fi
-;;
-"Keyboard Options:Dim on idle time")
- cv=`cat ${CONFIG} |grep "^idleoff=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=5 ; fi
- ans=`${ZEN} --forms --add-entry="Dim keyboard brightness if computer unused for X seconds" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
- idleoff=`cat ${CONFIG} |grep "^idleoff="`
- if [ -z "$idleoff" ]; then
- echo "idleoff=${ans}" >> ${CONFIG}
- else
- sed -i "s/^idleoff=.*/idleoff=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
- fi
- fi
-;;
-"Screen Options:Max Backlight")
- cv=`cat ${CONFIG} |grep "^maxbacklight=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=15 ; fi
- ans=`${ZEN} --forms --add-entry="maximum screen backlight value (between 4 and 15)" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 15 ] && [ ${ans} -ge 4 ]; then
- maxbacklight=`cat ${CONFIG} |grep "^maxbacklight="`
- if [ -z "$maxbacklight" ]; then
- echo "maxbacklight=${ans}" >> ${CONFIG}
- else
- sed -i "s/^maxbacklight=.*/maxbacklight=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "max screen backlight should be a value between 4 and 15"
- fi
- fi
-;;
-"Screen Options:Min Backlight")
- cv=`cat ${CONFIG} |grep "^minbacklight=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=0 ; fi
- ans=`${ZEN} --forms --add-entry="minimum screen backlight value (between 0 and 3)" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 3 ] && [ ${ans} -ge 0 ]; then
- minbacklight=`cat ${CONFIG} |grep "^minbacklight="`
- if [ -z "$minbacklight" ]; then
- echo "minbacklight=${ans}" >> ${CONFIG}
- else
- sed -i "s/^minbacklight=.*/minbacklight=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "min screen backlight should be a value between 0 and 3"
- fi
- fi
-;;
-"Screen Options:Dim on idle time")
- cv=`cat ${CONFIG} |grep "^screenidle=" |cut -f 2 -d "="`
- if [ -z "$cv" ]; then cv=30 ; fi
- ans=`${ZEN} --forms --add-entry="Dim screen backlight if computer unused for X seconds" --text="current value: $cv"`
- if [ $? == 0 ]; then
- if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
- screenidle=`cat ${CONFIG} |grep "^screenidle="`
- if [ -z "$screenidle" ]; then
- echo "screenidle=${ans}" >> ${CONFIG}
- else
- sed -i "s/^screenidle=.*/screenidle=${ans}/" ${CONFIG}
- fi
- kill -USR1 $(pidof lightum) || lightum
- else
- ${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
- fi
- fi
-;;
-"About")
- ${ZEN} --no-wrap --info --text "lightum-indicator version ${VERSION}\n(c)2012 Pau Oliva Fora\nLicensed under GPL"
-;;
-
-
-
-*)
- # handle profiles here
- echo "$s" |grep "Profile:.*:Save As..." >/dev/null
- if [ $? == 0 ]; then
- ans=`${ZEN} --forms --add-entry="Profile name (max 16 chars, no spaces)" --text="Enter the new profile name"`
- profile=$(echo `echo "${ans}" |grep -oi "[a-z]"` |sed -e "s/ //g" |cut -c "1-16")
- write="yes"
- if [ -z "${profile}" ]; then
- ${ZEN} --no-wrap --error --text "Invalid profile name."
- else
-
- if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
- write="no"
- ${ZEN} --no-wrap --question --text="a profile named '${profile}' already exists. Overwrite?"
- if [ $? == 0 ]; then
- write="yes"
- fi
- fi
-
- if [ "${write}" == "yes" ]; then
- cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
- grep "^#PROFILE: " "${CONFDIR}/lightum-${profile}.conf" >/dev/null
- if [ $? == 0 ]; then
- sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" "${CONFDIR}/lightum-${profile}.conf"
- else
- echo "#PROFILE: ${profile}" >> "${CONFDIR}/lightum-${profile}.conf"
- fi
- ${ZEN} --no-wrap --info --text "Profile '${profile}' successfully saved."
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
- fi
- fi
-
- echo "$s" |grep "Profile:.*:Save$" >/dev/null
- if [ $? == 0 ]; then
- profile=`echo $s |cut -f 2 -d ":"`
- if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
- write="no"
- ${ZEN} --no-wrap --question --text="Overwrite profile '${profile}' with current settings?"
- if [ $? == 0 ]; then
- write="yes"
- fi
- fi
-
- if [ "${write}" == "yes" ]; then
- grep "^#PROFILE: " ${CONFIG} >/dev/null
- if [ $? == 0 ]; then
- sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" ${CONFIG}
- else
- echo "#PROFILE: ${profile}" >> ${CONFIG}
- fi
- cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
- ${ZEN} --no-wrap --info --text "Profile '${profile}' successfully saved."
- fi
- fi
-
- echo "$s" |grep "Profile:.*:Load" >/dev/null
- if [ $? == 0 ]; then
- profile=`echo $s |cut -f 2 -d ":"`
- if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
- ${ZEN} --no-wrap --question --text="Load profile '${profile}'?"
- if [ $? == 0 ]; then
- cp "${CONFDIR}/lightum-${profile}.conf" "${CONFIG}"
- kill -USR1 $(pidof lightum) || lightum
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
- else
- ${ZEN} --no-wrap --error --text "Could not load profile, sorry."
- fi
- fi
-
- echo "$s" |grep "Profile:.*:Delete" >/dev/null
- if [ $? == 0 ]; then
- profile=`echo $s |cut -f 2 -d ":"`
- if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
- ${ZEN} --no-wrap --question --text="Really delete profile '${profile}'?"
- if [ $? == 0 ]; then
- rm -f "${CONFDIR}/lightum-${profile}.conf"
- lightumreload
- ${CONFDIR}/lightum-reload.$$ &
- fi
- else
- ${ZEN} --no-wrap --error --text "Could not delete profile, sorry."
- fi
- fi
-
-;;
-
+# update the menu file, if it doesn't exist
+updatemenu
-esac
-done
+# launch cappind-lightum
+/usr/share/lightum-indicator/cappind-lightum.py -i ${ICON} &
View
311 lightum-indicator-helper
@@ -0,0 +1,311 @@
+#!/bin/bash
+# lightum-indicator helper script
+# (c)2012 Pau Oliva Fora
+# License: GPLv2+
+
+# load include file
+source /usr/share/lightum-indicator/lightum-indicator-include
+
+# make sure zenity is installed
+which zenity 2>&1 >/dev/null
+if [ $? != 0 ]; then
+ echo "Missing dependancy: this indicator needs zenity installed to work"
+ exit 1
+fi
+
+# make sure lightum is installed
+which lightum 2>&1 >/dev/null
+if [ $? != 0 ]; then
+ ${ZEN} --no-wrap --error --text "Missing dependancy: this indicator needs lightum installed to work"
+ exit 1
+fi
+
+# conf dir must exist
+if [ ! -d "${CONFDIR}" ]; then
+ mkdir -p "${CONFDIR}"
+fi
+
+# conf file must exist
+touch "${CONFIG}"
+
+#### proced with the actions
+
+s="$*"
+
+case "$s" in
+
+"Mode:Auto")
+ ${ZEN} --no-wrap --question --text="Reload lightum in auto mode?"
+ if [ $? == 0 ]; then
+ manualmode=`cat ${CONFIG} |grep "^manualmode="`
+ if [ -z "$manualmode" ]; then
+ echo "manualmode=0" >> ${CONFIG}
+ else
+ sed -i "s/^manualmode=.*/manualmode=0/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+;;
+
+"Mode:Manual")
+ ${ZEN} --no-wrap --question --text="Reload lightum in manual mode?"
+ if [ $? == 0 ]; then
+ manualmode=`cat ${CONFIG} |grep "^manualmode="`
+ if [ -z "$manualmode" ]; then
+ echo "manualmode=1" >> ${CONFIG}
+ else
+ sed -i "s/^manualmode=.*/manualmode=1/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+;;
+
+"Manage:Screen Only")
+ ${ZEN} --no-wrap --question --text="Manage only screen backlight?"
+ if [ $? == 0 ]; then
+ workmode=`cat ${CONFIG} |grep "^workmode="`
+ if [ -z "$workmode" ]; then
+ echo "workmode=2" >> ${CONFIG}
+ else
+ sed -i "s/^workmode=.*/workmode=2/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+;;
+
+"Manage:Keyboard Only")
+ ${ZEN} --no-wrap --question --text="Manage only keyboard brightness?"
+ if [ $? == 0 ]; then
+ workmode=`cat ${CONFIG} |grep "^workmode="`
+ if [ -z "$workmode" ]; then
+ echo "workmode=1" >> ${CONFIG}
+ else
+ sed -i "s/^workmode=.*/workmode=1/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+;;
+
+"Manage:Screen + Keyboard")
+ ${ZEN} --no-wrap --question --text="Manage both keyboard brightness and screen backlight?"
+ if [ $? == 0 ]; then
+ workmode=`cat ${CONFIG} |grep "^workmode="`
+ if [ -z "$workmode" ]; then
+ echo "workmode=3" >> ${CONFIG}
+ else
+ sed -i "s/^workmode=.*/workmode=3/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+;;
+"Keyboard Options:Max Brightness")
+ cv=`cat ${CONFIG} |grep "^maxbrightness=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=255 ; fi
+ ans=`${ZEN} --forms --add-entry="maximum keyboard brightness value (between 4 and 255)" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 255 ] && [ ${ans} -ge 4 ]; then
+ maxbrightness=`cat ${CONFIG} |grep "^maxbrightness="`
+ if [ -z "$maxbrightness" ]; then
+ echo "maxbrightness=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^maxbrightness=.*/maxbrightness=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "max keyboard brightness should be a value between 4 and 255."
+ fi
+ fi
+;;
+"Keyboard Options:Min Brightness")
+ cv=`cat ${CONFIG} |grep "^minbrightness=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=0 ; fi
+ ans=`${ZEN} --forms --add-entry="minimum keyboard brightness value (between 0 and 3)" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 3 ] && [ ${ans} -ge 0 ]; then
+ minbrightness=`cat ${CONFIG} |grep "^minbrightness="`
+ if [ -z "$minbrightness" ]; then
+ echo "minbrightness=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^minbrightness=.*/minbrightness=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "min keyboard brightness should be a value between 0 and 3"
+ fi
+ fi
+;;
+"Keyboard Options:Dim on idle time")
+ cv=`cat ${CONFIG} |grep "^idleoff=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=5 ; fi
+ ans=`${ZEN} --forms --add-entry="Dim keyboard brightness if computer unused for X seconds" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
+ idleoff=`cat ${CONFIG} |grep "^idleoff="`
+ if [ -z "$idleoff" ]; then
+ echo "idleoff=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^idleoff=.*/idleoff=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
+ fi
+ fi
+;;
+"Screen Options:Max Backlight")
+ cv=`cat ${CONFIG} |grep "^maxbacklight=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=15 ; fi
+ ans=`${ZEN} --forms --add-entry="maximum screen backlight value (between 4 and 15)" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 15 ] && [ ${ans} -ge 4 ]; then
+ maxbacklight=`cat ${CONFIG} |grep "^maxbacklight="`
+ if [ -z "$maxbacklight" ]; then
+ echo "maxbacklight=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^maxbacklight=.*/maxbacklight=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "max screen backlight should be a value between 4 and 15"
+ fi
+ fi
+;;
+"Screen Options:Min Backlight")
+ cv=`cat ${CONFIG} |grep "^minbacklight=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=0 ; fi
+ ans=`${ZEN} --forms --add-entry="minimum screen backlight value (between 0 and 3)" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 3 ] && [ ${ans} -ge 0 ]; then
+ minbacklight=`cat ${CONFIG} |grep "^minbacklight="`
+ if [ -z "$minbacklight" ]; then
+ echo "minbacklight=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^minbacklight=.*/minbacklight=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "min screen backlight should be a value between 0 and 3"
+ fi
+ fi
+;;
+"Screen Options:Dim on idle time")
+ cv=`cat ${CONFIG} |grep "^screenidle=" |cut -f 2 -d "="`
+ if [ -z "$cv" ]; then cv=30 ; fi
+ ans=`${ZEN} --forms --add-entry="Dim screen backlight if computer unused for X seconds" --text="current value: $cv"`
+ if [ $? == 0 ]; then
+ if [ ${ans} -le 86400 ] && [ ${ans} -ge 0 ]; then
+ screenidle=`cat ${CONFIG} |grep "^screenidle="`
+ if [ -z "$screenidle" ]; then
+ echo "screenidle=${ans}" >> ${CONFIG}
+ else
+ sed -i "s/^screenidle=.*/screenidle=${ans}/" ${CONFIG}
+ fi
+ kill -USR1 $(pidof lightum) || lightum
+ else
+ ${ZEN} --no-wrap --error --text "idle time should be a value between 0 and 86400 seconds"
+ fi
+ fi
+;;
+"About")
+ ${ZEN} --no-wrap --info --text "lightum-indicator version ${VERSION}\n(c)2012 Pau Oliva Fora\nLicensed under GPL"
+;;
+
+
+
+*)
+ # handle profiles here
+ echo "$s" |grep "Profile:.*:Save As..." >/dev/null
+ if [ $? == 0 ]; then
+ ans=`${ZEN} --forms --add-entry="Profile name (max 16 chars, no spaces)" --text="Enter the new profile name"`
+ profile=$(echo `echo "${ans}" |grep -oi "[a-z]"` |sed -e "s/ //g" |cut -c "1-16")
+ write="yes"
+ if [ -z "${profile}" ]; then
+ ${ZEN} --no-wrap --error --text "Invalid profile name."
+ else
+
+ if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
+ write="no"
+ ${ZEN} --no-wrap --question --text="a profile named '${profile}' already exists. Overwrite?"
+ if [ $? == 0 ]; then
+ write="yes"
+ fi
+ fi
+
+ if [ "${write}" == "yes" ]; then
+ cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
+ grep "^#PROFILE: " "${CONFDIR}/lightum-${profile}.conf" >/dev/null
+ if [ $? == 0 ]; then
+ sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" "${CONFDIR}/lightum-${profile}.conf"
+ else
+ echo "#PROFILE: ${profile}" >> "${CONFDIR}/lightum-${profile}.conf"
+ fi
+ ${ZEN} --no-wrap --info --text "Profile '${profile}' successfully saved."
+ updatemenu
+ fi
+ fi
+ fi
+
+ echo "$s" |grep "Profile:.*:Save$" >/dev/null
+ if [ $? == 0 ]; then
+ profile=`echo $s |cut -f 2 -d ":"`
+ if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
+ write="no"
+ ${ZEN} --no-wrap --question --text="Overwrite profile '${profile}' with current settings?"
+ if [ $? == 0 ]; then
+ write="yes"
+ fi
+ fi
+
+ if [ "${write}" == "yes" ]; then
+ grep "^#PROFILE: " ${CONFIG} >/dev/null
+ if [ $? == 0 ]; then
+ sed -i "s/^#PROFILE: .*/#PROFILE: ${profile}/" ${CONFIG}
+ else
+ echo "#PROFILE: ${profile}" >> ${CONFIG}
+ fi
+ cp "${CONFIG}" "${CONFDIR}/lightum-${profile}.conf"
+ ${ZEN} --no-wrap --info --text "Profile '${profile}' successfully saved."
+ fi
+ fi
+
+ echo "$s" |grep "Profile:.*:Load" >/dev/null
+ if [ $? == 0 ]; then
+ profile=`echo $s |cut -f 2 -d ":"`
+ if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
+ ${ZEN} --no-wrap --question --text="Load profile '${profile}'?"
+ if [ $? == 0 ]; then
+ cp "${CONFDIR}/lightum-${profile}.conf" "${CONFIG}"
+ kill -USR1 $(pidof lightum) || lightum
+ updatemenu
+ fi
+ else
+ ${ZEN} --no-wrap --error --text "Could not load profile, sorry."
+ fi
+ fi
+
+ echo "$s" |grep "Profile:.*:Delete" >/dev/null
+ if [ $? == 0 ]; then
+ profile=`echo $s |cut -f 2 -d ":"`
+ if [ -f "${CONFDIR}/lightum-${profile}.conf" ]; then
+ ${ZEN} --no-wrap --question --text="Really delete profile '${profile}'?"
+ if [ $? == 0 ]; then
+ rm -f "${CONFDIR}/lightum-${profile}.conf"
+ updatemenu
+ fi
+ else
+ ${ZEN} --no-wrap --error --text "Could not delete profile, sorry."
+ fi
+ fi
+
+;;
+
+
+esac
+
+# make sure lightum is running, otherwise start it
+pidof lightum 2>&1 >/dev/null || lightum
View
100 lightum-indicator-include
@@ -0,0 +1,100 @@
+# lightum-indicator include script
+# (c)2012 Pau Oliva Fora
+# License: GPLv2+
+
+VERSION="0.4"
+
+CONFDIR="${HOME}/.config/lightum/"
+CONFIG="${CONFDIR}/lightum.conf"
+ZEN="zenity --name=lightum --title=lightum "
+
+function updatemenu ()
+{
+
+ profiles=`grep "^#PROFILE: " ${CONFDIR}/*.conf |cut -f 1 -d ":" |grep -v "${CONFIG}" |sort -u`
+
+ currentprofile=`grep "^#PROFILE: " ${CONFIG} |cut -f 2 -d " "`
+ if [ -z "${currentprofile}" ]; then currentprofile="Default" ; fi
+
+ PROFILEOPTS="Profile:$currentprofile:Save
+Profile:$currentprofile:Save As..."
+
+ for file in ${profiles} ; do
+ profile=`cat ${file} |grep "^#PROFILE: " |cut -f 2 -d " "`
+ if [ "${profile}" == "${currentprofile}" ]; then
+ PROFILEOPTS="${PROFILEOPTS}
+Profile:$profile:*Load
+Profile:$profile:*Delete"
+ else
+ PROFILEOPTS="${PROFILEOPTS}
+Profile:$profile:Load
+Profile:$profile:Delete"
+ fi
+ done
+
+ manualmode=`cat ${CONFIG} |grep "^manualmode="`
+ case "$manualmode" in
+ "manualmode=1")
+ MANUALMODEOPTS="Mode:Auto
+Mode:*Manual"
+ IC1="M"
+ ;;
+ *)
+ MANUALMODEOPTS="Mode:*Auto
+Mode:Manual"
+ IC1="A"
+ ;;
+ esac
+
+ workmode=`cat ${CONFIG} |grep "^workmode="`
+ case "$workmode" in
+ "workmode=1")
+ WORKMODEOPTS="Manage:Screen Only
+Manage:*Keyboard Only
+Manage:Screen + Keyboard
+Keyboard Options:Max Brightness
+Keyboard Options:Min Brightness
+Keyboard Options:Dim on idle time
+Screen Options:*Max Backlight
+Screen Options:*Min Backlight
+Screen Options:*Dim on idle time"
+ IC2="K"
+ ;;
+
+ "workmode=2")
+ WORKMODEOPTS="Manage:*Screen Only
+Manage:Keyboard Only
+Manage:Screen + Keyboard
+Keyboard Options:*Max Brightness
+Keyboard Options:*Min Brightness
+Keyboard Options:*Dim on idle time
+Screen Options:Max Backlight
+Screen Options:Min Backlight
+Screen Options:Dim on idle time"
+ IC2="S"
+ ;;
+
+ *)
+ WORKMODEOPTS="Manage:Screen Only
+Manage:Keyboard Only
+Manage:*Screen + Keyboard
+Keyboard Options:Max Brightness
+Keyboard Options:Min Brightness
+Keyboard Options:Dim on idle time
+Screen Options:Max Backlight
+Screen Options:Min Backlight
+Screen Options:Dim on idle time"
+ IC2="B"
+ ;;
+
+ esac
+
+ ICON="/usr/share/lightum-indicator/icons/${IC1}${IC2}.png"
+
+ echo "$PROFILEOPTS
+
+$MANUALMODEOPTS
+$WORKMODEOPTS
+About" > ${CONFDIR}/indicator.menu
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.