[PATCH] Display notifications with libnotify, if available
Tomaz Solc
tomaz.solc at tablix.org
Sat Dec 27 11:04:34 UTC 2008
If notify-send utility is found, notifications are displayed
through that, instead of using GNOME OSD.
---
debian/README.Debian | 10 +++++--
debian/control | 2 +-
etc/acpi/actions/hotkey.sh | 19 +++++++-------
etc/acpi/actions/volume.sh | 6 +++-
etc/acpi/lib/notify.sh | 57 ++++++++++++++++++++++++++++++++++----------
5 files changed, 66 insertions(+), 28 deletions(-)
diff --git a/debian/README.Debian b/debian/README.Debian
index 9e766aa..b1068c1 100644
--- a/debian/README.Debian
+++ b/debian/README.Debian
@@ -15,9 +15,13 @@ values are 'Front' and 'Headphone'.
If you want to leave volume management to any desktop environment you might
be running, set HANDLE_VOLUME to 0.
-To get nifty osd overlays on changing the volume, switching on wireless
-etc. change ENABLE_OSD to yes in /etc/default/eeepc-acpi-scripts. Make sure you
-have aosd-cat installed then.
+You will get notifications of changes in the hardware through libnotify,
+if available. If you do not want that, set ENABLE_LIBNOTIFY to no.
+
+Alternatively, you can get the same notifications through GNOME OSD.
+To disable that, set ENABLE_OSD to no in /etc/default/eeepc-acpi-scripts.
+
+You need to have aosd-cat installed in order for GNOME OSD to work.
[0] http://wiki.debian.org/DebianEeePC
diff --git a/debian/control b/debian/control
index a017a99..ce511fa 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Package: eeepc-acpi-scripts
Architecture: all
Conflicts: acpi-support
Depends: acpid (>= 1.0.4), acpi-support-base, pm-utils
-Recommends: alsa-utils
+Recommends: alsa-utils, libnotify-bin
Suggests: aosd-cat, ttf-dejavu | ttf-bitstream-vera | ttf-freefont
| gsfonts-x11 | ttf-mscorefonts-installer | ttf-liberation,
gnome-osd
diff --git a/etc/acpi/actions/hotkey.sh b/etc/acpi/actions/hotkey.sh
index a574911..d0a4960 100755
--- a/etc/acpi/actions/hotkey.sh
+++ b/etc/acpi/actions/hotkey.sh
@@ -27,11 +27,12 @@ handle_volume_down() {
show_wireless() {
detect_wlan
if grep -q $WLAN_IF /proc/net/wireless; then
- status=On
+ status=On
+ notify wireless "Wireless On" "Wireless LAN module has been turned on"
else
- status=Off
+ status=Off
+ notify wireless "Wireless Off" "Wireless LAN module has been turned off"
fi
- notify wireless "Wireless $status"
}
handle_blank_screen() {
@@ -46,9 +47,9 @@ handle_blank_screen() {
show_bluetooth() {
if bluetooth_is_on; then
- notify bluetooth 'Bluetooth On'
+ notify bluetooth 'Bluetooth On' 'Bluetooth module has been turned on'
else
- notify bluetooth 'Bluetooth Off'
+ notify bluetooth 'Bluetooth Off' 'Bluetooth module has been turned off'
fi
}
@@ -58,15 +59,15 @@ handle_bluetooth_toggle() {
toggle_bluetooth
show_bluetooth
else
- notify error 'Bluetooth unavailable'
+ notify error 'Bluetooth unavailable' 'Bluetooth module is not available'
fi
}
show_camera() {
if camera_is_on; then
- notify camera 'Camera Enabled'
+ notify camera 'Camera On' 'Integrated web camera has been turned on'
else
- notify camera 'Camera Disabled'
+ notify camera 'Camera Off' 'Integrated web camera has been turned off'
fi
}
@@ -76,7 +77,7 @@ handle_camera_toggle() {
toggle_camera
show_camera
else
- notify error 'Camera unavailable'
+ notify error 'Camera Unavailable' 'Integrated web camera is not available'
fi
}
diff --git a/etc/acpi/actions/volume.sh b/etc/acpi/actions/volume.sh
index 22b88c4..3d2d257 100755
--- a/etc/acpi/actions/volume.sh
+++ b/etc/acpi/actions/volume.sh
@@ -41,12 +41,14 @@ fi
show_muteness() {
status=$($AMIXER get $VOLUME_LABEL | sed -n '/%/{s/.*\[\(on\|off\)\].*/\u\1/p;q}')
- notify audio "Audio $status"
+ ENABLE_LIBNOTIFY="no"
+ notify audio "Audio $status" "Audio $status"
}
show_volume() {
percent=$($AMIXER get $VOLUME_LABEL | sed -n '/%/{s/.*\[\(.*\)%\].*/\1/p;q}')
- notify audio "Volume $percent"
+ ENABLE_LIBNOTIFY="no"
+ notify audio "Volume $percent" "Volume $percent"
}
case "$action" in
diff --git a/etc/acpi/lib/notify.sh b/etc/acpi/lib/notify.sh
index 0156129..ce17404 100755
--- a/etc/acpi/lib/notify.sh
+++ b/etc/acpi/lib/notify.sh
@@ -2,20 +2,11 @@
#
# this file is to be sourced
-notify() {
+NOTIFYSEND="/usr/bin/notify-send"
+
+notify_gnome_osd() {
CATEGORY=$1
MSG=$2
- if [ -n "$3" ]; then
- echo "usage: notify 'catgory' 'message text'" > /dev/stderr
- return 1
- fi
- echo "$MSG" # for /var/log/acpid
- if [ -S /tmp/.X11-unix/X0 ]; then
- detect_x_display
-
- if [ "x$ENABLE_OSD" = "xno" ]; then
- return
- fi
OSD_SHOWN=
@@ -42,8 +33,48 @@ notify() {
echo "$MSG" | aosd_cat -n "$OSD_FONT" -f 100 -u 1000 -o 100 &
fi
fi
+}
+
+notify_libnotify() {
+ CATEGORY=$1
+ SUMMARY=$2
+ MSG=$3
+
+ case "$CATEGORY" in
+ "bluetooth")
+ ICON="/usr/share/icons/hicolor/scalable/apps/bluetooth.svg"
+ ;;
+ "wireless")
+ ICON="/usr/share/icons/gnome/scalable/devices/network-wireless.svg"
+ ;;
+ "camera")
+ ICON="/usr/share/icons/gnome/scalable/devices/camera-web.svg"
+ ;;
+ esac
+
+ if [ -f "$ICON" ]; then
+ "$NOTIFYSEND" --icon "$ICON" "$SUMMARY" "$MSG"
else
- echo "$MSG" > /dev/console
+ "$NOTIFYSEND" "$SUMMARY" "$MSG"
fi
}
+notify() {
+ if [ "$#" -ne 3 ]; then
+ echo "usage: notify 'category' 'summary' 'text" > /dev/stderr
+ return 1
+ fi
+ echo "$MSG" # for /var/log/acpid
+
+ if [ -S /tmp/.X11-unix/X0 ]; then
+ detect_x_display
+
+ if [ "x$ENABLE_LIBNOTIFY" != "xno" -a -x "$NOTIFYSEND" ]; then
+ notify_libnotify "$@"
+ elif [ "x$ENABLE_OSD" != "xno" ]; then
+ notify_gnome_osd "$@"
+ fi
+ else
+ echo "$2" > /dev/console
+ fi
+}
--
1.5.6.5
--------------030705020601080109040906--
More information about the Debian-eeepc-devel
mailing list