[Xfce4-commits] <xfce4-volumed:master> 0.1.5, support for async notifications and legacy xcb-keysyms
Steve Dodier
noreply at xfce.org
Wed Oct 28 00:12:01 CET 2009
Updating branch refs/heads/master
to 4390847f0e6f19b2a2d4af809c4e683c1f671ca6 (commit)
from dcd449bb429adaf0284ad344b1a1175bbdb97b62 (commit)
commit 4390847f0e6f19b2a2d4af809c4e683c1f671ca6
Author: Steve Dodier <sidnioulz at gmail.com>
Date: Wed Oct 28 00:13:01 2009 +0100
0.1.5, support for async notifications and legacy xcb-keysyms
ChangeLog | 5 +++
configure.ac | 11 ++++++-
module.xml | 20 ------------
src/Makefile.am | 10 ++++--
src/main.c | 8 ++++-
src/xvd_data_types.h | 16 +++++++++-
src/xvd_keys.c | 67 ++++++++++++++++++++++++++++++++++++++++
src/xvd_notify.c | 82 ++++++++++++++++++++++++++++----------------------
src/xvd_notify.h | 2 +-
9 files changed, 157 insertions(+), 64 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e6e9509..6a4f61a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-27 Steve Dodier <sidnioulz at gmail.com>
+
+ * Support for asynchronous libnotify daemons
+ * Move support for legacy libxcb-keysyms to the main branch with a build toggle
+
2009-09-04 Steve Dodier <sidnioulz at gmail.com>
* Volume initialisation now includes mute check
diff --git a/configure.ac b/configure.ac
index b8dbb78..96e6cd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,9 +22,14 @@ PKG_CHECK_MODULES(GSTREAMER_AUDIO, [gstreamer-audio-0.10])
AC_SUBST(GSTREAMER_AUDIO_CFLAGS)
AC_SUBST(GSTREAMER_AUDIO_LIBS)
-PKG_CHECK_MODULES(XCB_KEYSYMS, [xcb-keysyms >= 0.3.5])
+PKG_CHECK_MODULES(XCB_KEYSYMS, xcb-keysyms >= 0.3.5, [],
+[
+ PKG_CHECK_MODULES(XCB_KEYSYMS, [xcb-keysyms])
+ LEGACY_XCB_KEYSYMS=1
+])
AC_SUBST(XCB_KEYSYMS_CFLAGS)
AC_SUBST(XCB_KEYSYMS_LIBS)
+AM_CONDITIONAL(LEGACY_XCBKEYSYMS, [test "$LEGACY_XCB_KEYSYMS" = "1"])
AC_ARG_WITH(libnotify,
AS_HELP_STRING([--with-libnotify], [enable notifications (default=autodetect)]),
@@ -54,6 +59,7 @@ fi
AC_SUBST(HAVE_LIBNOTIFY)
AM_CONDITIONAL(HAVE_LIBNOTIFY, [test "$HAVE_LIBNOTIFY" = "1"])
+
if test "x$enable_debug" = "xyes"; then
CFLAGS="-g"
else
@@ -70,6 +76,9 @@ echo "----------------------------------------"
echo "Xfce4-Volumed"
echo " Installing in : ${prefix}"
echo " Using LibNotify : ${with_libnotify}"
+if test "$LEGACY_XCB_KEYSYMS" = "1"; then
+ echo " Legacy XCB Keysyms : yes"
+fi
echo " Compiler : ${CC}"
echo " Compiler flags : ${CFLAGS}"
echo ""
diff --git a/module.xml b/module.xml
deleted file mode 100644
index 33c0c9f..0000000
--- a/module.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:foaf="http://xmlns.com/foaf/0.1/"
- xmlns:gnome="http://api.gnome.org/doap-extensions#"
- xmlns="http://usefulinc.com/ns/doap#">
-
- <name xml:lang="en">xfce4-volumed</name>
- <shortdesc xml:lang="en">Basic daemon enabling the XF86 Volume keys and supporting synchronous volume notifications</shortdesc>
- <homepage rdf:resource="https://launchpad.net/xfce4-volumed"/>
- <mailing-list rdf:resource="https://lists.ubuntu.com/mailman/listinfo/xubuntu-devel"/>
-
- <maintainer>
- <foaf:Person>
- <foaf:name>Steve Dodier</foaf:name>
- <foaf:mbox>mailto:sidnioulz at gmail.com</foaf:mbox>
- <gnome:userid>SiDi</gnome:userid>
- </foaf:Person>
- </maintainer>
-</Project>
diff --git a/src/Makefile.am b/src/Makefile.am
index c38d44c..d69fd35 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,7 @@ xfce4_volumed_SOURCES = \
xvd_notify.c \
xvd_notify.h \
xvd_xfconf.c \
- xvd_xfconf.h
+ xvd_xfconf.h
INCLUDES = \
@GLIB_CFLAGS@ \
@@ -18,7 +18,7 @@ INCLUDES = \
@GSTREAMER_CFLAGS@ \
@GSTREAMER_AUDIO_CFLAGS@ \
@XCB_KEYSYMS_CFLAGS@ \
- @LIBNOTIFY_CFLAGS@
+ @LIBNOTIFY_CFLAGS@
xfce4_volumed_LDADD = \
@GLIB_LIBS@ \
@@ -26,4 +26,8 @@ xfce4_volumed_LDADD = \
@GSTREAMER_LIBS@ \
@GSTREAMER_AUDIO_LIBS@ \
@XCB_KEYSYMS_LIBS@ \
- @LIBNOTIFY_LIBS@
+ @LIBNOTIFY_LIBS@
+
+if LEGACY_XCBKEYSYMS
+xfce4_volumed_CFLAGS = -DLEGACY_XCBKEYSYMS
+endif
diff --git a/src/main.c b/src/main.c
index 65c90de..68ffd30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -72,7 +72,7 @@ xvd_shutdown()
{
#ifdef HAVE_LIBNOTIFY
xvd_clean_mixer_bus (Inst);
- xvd_notify_uninit ();
+ xvd_notify_uninit (Inst);
#endif
xvd_clean_card_name (Inst);
@@ -104,11 +104,15 @@ xvd_instance_init(XvdInstance *i)
i->current_vol = 0;
i->muted = FALSE;
i->conn = NULL;
+ #ifndef LEGACY_XCBKEYSYMS
+ // In legacy mode xcb keycodes are not pointers to lists but structs
i->keyRaise = NULL;
i->keyLower = NULL;
i->keyMute = NULL;
+ #endif
i->kss = NULL;
- i->notifyosd = FALSE;
+ i->sync_notifications = FALSE;
+ i->notification = NULL;
}
gint
diff --git a/src/xvd_data_types.h b/src/xvd_data_types.h
index a60e9f3..45223b4 100644
--- a/src/xvd_data_types.h
+++ b/src/xvd_data_types.h
@@ -39,6 +39,9 @@
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <X11/XF86keysym.h>
+#ifdef HAVE_LIBNOTIFY
+#include <libnotify/notification.h>
+#endif
typedef struct {
/* Sound card being used and list of cards */
@@ -71,13 +74,24 @@ typedef struct {
xcb_connection_t *conn;
xcb_window_t root_win;
xcb_key_symbols_t *kss;
+ #ifndef LEGACY_XCBKEYSYMS
xcb_keycode_t *keyRaise,
*keyLower,
*keyMute;
+ #else
+ xcb_keycode_t keyRaise,
+ keyLower,
+ keyMute;
+ #endif
+
+ #ifdef HAVE_LIBNOTIFY
+ /* Libnotify vars */
+ gboolean sync_notifications;
+ NotifyNotification* notification;
+ #endif
/* Other Xvd vars */
GMainLoop *loop;
- gboolean notifyosd;
} XvdInstance;
#endif
diff --git a/src/xvd_keys.c b/src/xvd_keys.c
index 7401bf4..2a4275e 100644
--- a/src/xvd_keys.c
+++ b/src/xvd_keys.c
@@ -27,6 +27,8 @@
#include "xvd_notify.h"
#endif
+#ifndef LEGACY_XCBKEYSYMS
+// This is only needed when the keycodes are a list and not a struct
static gboolean
_xvd_keys_is_symbol(xcb_keycode_t elem,
xcb_keycode_t *list)
@@ -44,6 +46,7 @@ _xvd_keys_is_symbol(xcb_keycode_t elem,
return belongs;
}
+#endif
static gboolean
_xvd_keys_handle_events(GIOChannel *source,
@@ -61,7 +64,11 @@ _xvd_keys_handle_events(GIOChannel *source,
case XCB_KEY_PRESS:
kpe = (xcb_key_press_event_t *)ev;
+ #ifndef LEGACY_XCBKEYSYMS
if (_xvd_keys_is_symbol(kpe->detail, Inst->keyRaise)) {
+ #else
+ if (kpe->detail == Inst->keyRaise) {
+ #endif
if (xvd_mixer_change_volume (Inst, Inst->vol_step)) {
#ifdef HAVE_LIBNOTIFY
/* if (!Inst->muted) {*/
@@ -74,7 +81,11 @@ _xvd_keys_handle_events(GIOChannel *source,
}
}
+ #ifndef LEGACY_XCBKEYSYMS
else if (_xvd_keys_is_symbol(kpe->detail, Inst->keyLower)) {
+ #else
+ else if (kpe->detail == Inst->keyLower) {
+ #endif
if (xvd_mixer_change_volume (Inst, (Inst->vol_step * -1))) {
#ifdef HAVE_LIBNOTIFY
/* if (!Inst->muted) {*/
@@ -87,7 +98,11 @@ _xvd_keys_handle_events(GIOChannel *source,
}
}
+ #ifndef LEGACY_XCBKEYSYMS
else if (_xvd_keys_is_symbol(kpe->detail, Inst->keyMute)) {
+ #else
+ else if (kpe->detail == Inst->keyMute) {
+ #endif
if (xvd_mixer_toggle_mute (Inst)) {
#ifdef HAVE_LIBNOTIFY
if (Inst->muted)
@@ -155,6 +170,7 @@ xvd_keys_init(XvdInstance *Inst)
Inst->kss = xcb_key_symbols_alloc (Inst->conn);
/* Grab the XF86AudioRaiseVolume key */
+ #ifndef LEGACY_XCBKEYSYMS
Inst->keyRaise = xcb_key_symbols_get_keycode (Inst->kss, XF86XK_AudioRaiseVolume);
i = 0;
@@ -214,6 +230,55 @@ xvd_keys_init(XvdInstance *Inst)
}
i++;
}
+ #else
+ Inst->keyRaise = xcb_key_symbols_get_keycode (Inst->kss, XF86XK_AudioRaiseVolume);
+
+ cookie = xcb_grab_key_checked (Inst->conn, TRUE, Inst->root_win,
+ mod, Inst->keyRaise,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
+ error = xcb_request_check (Inst->conn, cookie);
+ if (error) {
+ fprintf (stderr, "XCB: Unable to bind RaiseVolume keycode=%d mod=0x%04x: %d\n",
+ Inst->keyRaise, mod, error->error_code);
+ }
+ else {
+ g_print ("XCB: RaiseVolume ok, keycode=%d mod=0x%04x\n",
+ Inst->keyRaise, mod);
+ }
+
+ /* Grab the XF86AudioLowerVolume key */
+ Inst->keyLower = xcb_key_symbols_get_keycode (Inst->kss, XF86XK_AudioLowerVolume);
+
+ cookie = xcb_grab_key_checked (Inst->conn, TRUE, Inst->root_win,
+ mod, Inst->keyLower,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
+ error = xcb_request_check (Inst->conn, cookie);
+ if (error) {
+ fprintf (stderr, "XCB: Unable to bind LowerVolume keycode=%d mod=0x%04x: %d\n",
+ Inst->keyLower, mod, error->error_code);
+ }
+ else {
+ g_print ("XCB: LowerVolume ok, keycode=%d mod=0x%04x\n",
+ Inst->keyLower, mod);
+ }
+
+
+ /* Grab the XF86AudioMute key */
+ Inst->keyMute = xcb_key_symbols_get_keycode (Inst->kss, XF86XK_AudioMute);
+
+ cookie = xcb_grab_key_checked (Inst->conn, TRUE, Inst->root_win,
+ mod, Inst->keyMute,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
+ error = xcb_request_check (Inst->conn, cookie);
+ if (error) {
+ fprintf (stderr, "XCB: Unable to bind Mute keycode=%d mod=0x%04x: %d\n",
+ Inst->keyMute, mod, error->error_code);
+ }
+ else {
+ g_print ("XCB: Mute ok, keycode=%d mod=0x%04x\n",
+ Inst->keyMute, mod);
+ }
+ #endif
GIOChannel *channel = g_io_channel_unix_new (xcb_get_file_descriptor (Inst->conn));
g_io_add_watch (channel, G_IO_IN|G_IO_HUP, _xvd_keys_handle_events, Inst);
@@ -222,9 +287,11 @@ xvd_keys_init(XvdInstance *Inst)
void
xvd_keys_release (XvdInstance *Inst)
{
+ #ifndef LEGACY_XCBKEYSYMS
g_free (Inst->keyRaise);
g_free (Inst->keyLower);
g_free (Inst->keyMute);
+ #endif
if (Inst->kss)
xcb_key_symbols_free (Inst->kss);
if (Inst->conn)
diff --git a/src/xvd_notify.c b/src/xvd_notify.c
index 63846c4..4d8f0b0 100644
--- a/src/xvd_notify.c
+++ b/src/xvd_notify.c
@@ -29,40 +29,38 @@ xvd_notify_notification(XvdInstance *Inst,
gchar* icon,
gint value)
{
- if (Inst->notifyosd) {
- NotifyNotification* notification = NULL;
- gchar* title = NULL;
-
- if ((icon != NULL) && (g_strcmp0(icon, "notification-audio-volume-muted") == 0)) {
- // TRANSLATORS: this is the body of the ATK interface of the volume notifications. Just before this, there is the 'Volume' word (as a notification title). If it would look too weird in your locale, translate this string as 'The volume is muted' instead.
- title = g_strdup ("Volume is muted");
- }
- else {
- // TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug.
- title = g_strdup_printf ("Volume is at %d%c", value, '%');
- }
-
- notification = notify_notification_new (
- title,
- NULL,
- icon,
- NULL);
-
- g_free (title);
-
- notify_notification_set_hint_int32 (notification,
+ gchar* title = NULL;
+
+ if ((icon != NULL) && (g_strcmp0(icon, "notification-audio-volume-muted") == 0)) {
+ // TRANSLATORS: this is the body of the ATK interface of the volume notifications. Just before this, there is the 'Volume' word (as a notification title). If it would look too weird in your locale, translate this string as 'The volume is muted' instead.
+ title = g_strdup ("Volume is muted");
+ }
+ else {
+ // TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug.
+ title = g_strdup_printf ("Volume is at %d%c", value, '%');
+ }
+
+ notify_notification_update (Inst->notification,
+ title,
+ NULL,
+ icon);
+
+ g_free (title);
+
+ if (Inst->sync_notifications) {
+ notify_notification_set_hint_int32 (Inst->notification,
"value",
value);
- notify_notification_set_hint_string (notification,
+ notify_notification_set_hint_string (Inst->notification,
"x-canonical-private-synchronous",
"");
- Inst->error = NULL;
- if (!notify_notification_show (notification, &Inst->error))
- {
- g_warning ("Error while sending notification : %s\n", Inst->error->message);
- g_error_free (Inst->error);
- }
- g_object_unref (G_OBJECT (notification));
+ }
+
+ Inst->error = NULL;
+ if (!notify_notification_show (Inst->notification, &Inst->error))
+ {
+ g_warning ("Error while sending notification : %s\n", Inst->error->message);
+ g_error_free (Inst->error);
}
}
@@ -82,20 +80,24 @@ xvd_notify_volume_notification(XvdInstance *Inst)
void
xvd_notify_overshoot_notification(XvdInstance *Inst)
{
- xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-high", 101);
+ xvd_notify_notification (Inst,
+ (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-high",
+ (Inst->sync_notifications) ? 101 : 100);
}
void
xvd_notify_undershoot_notification(XvdInstance *Inst)
{
- xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-off", -1);
+ xvd_notify_notification (Inst,
+ (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-off",
+ (Inst->sync_notifications) ? -1 : 0);
}
void
xvd_notify_init(XvdInstance *Inst,
const gchar *appname)
{
- Inst->notifyosd = TRUE;
+ Inst->sync_notifications = TRUE;
notify_init (appname);
GList *caps_list = notify_get_server_caps ();
@@ -106,19 +108,27 @@ xvd_notify_init(XvdInstance *Inst,
node = g_list_find_custom (caps_list, LAYOUT_ICON_ONLY, (GCompareFunc) g_strcmp0);
if (!node)
- Inst->notifyosd = FALSE;
+ Inst->sync_notifications = FALSE;
node = g_list_find_custom (caps_list, SYNCHRONOUS, (GCompareFunc) g_strcmp0);
if (!node)
- Inst->notifyosd = FALSE;
+ Inst->sync_notifications = FALSE;
g_list_free (caps_list);
}
+
+ Inst->notification = notify_notification_new (
+ "Xfce4-Volumed",
+ NULL,
+ NULL,
+ NULL);
}
void
-xvd_notify_uninit ()
+xvd_notify_uninit (XvdInstance *Inst)
{
+ g_object_unref (G_OBJECT (Inst->notification));
+ Inst->notification = NULL;
notify_uninit ();
}
#endif
diff --git a/src/xvd_notify.h b/src/xvd_notify.h
index 324a459..0d325d9 100644
--- a/src/xvd_notify.h
+++ b/src/xvd_notify.h
@@ -53,6 +53,6 @@ xvd_notify_init(XvdInstance *Inst,
const gchar *appname);
void
-xvd_notify_uninit();
+xvd_notify_uninit(XvdInstance *Inst);
#endif
#endif
More information about the Xfce4-commits
mailing list