[MPlayer-dev-eng] [PATCH] Add support for GNOME screensaver
Piotr Kaczuba
pepe at attika.ath.cx
Thu Apr 27 17:30:18 CEST 2006
Below the forth revision of my patch. I've made the following changes:
1. Make HAVE_DBUS_GLIB actually appear in config.h
2. Move gnome_screensaver.o rule from config.mak to Makefile
3. Run autodetection in configure only if _dbus_glib = auto
4. Replace g_print/g_printerr with mp_msg in gnome_screensaver.c
Piotr
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.367
diff -u -r1.367 Makefile
--- Makefile 25 Apr 2006 02:01:21 -0000 1.367
+++ Makefile 27 Apr 2006 14:56:50 -0000
@@ -74,6 +74,7 @@
$(DIRECTFB_LIB) \
$(CACA_LIB) \
$(VESA_LIB) \
+ $(DBUS_GLIB_LIB) \
ifeq ($(EXTERNAL_VIDIX),yes)
VO_LIBS += $(EXTERNAL_VIDIX_LIB)
Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.1179
diff -u -r1.1179 configure
--- configure 26 Apr 2006 01:59:05 -0000 1.1179
+++ configure 27 Apr 2006 14:56:51 -0000
@@ -222,6 +222,7 @@
--disable-ftp Disable ftp support [enabled]
--disable-vstream Disable tivo vstream client support [autodetect]
--disable-pthreads Disable Posix threads support [autodetect]
+ --disable-dbus-glib Disable D-BUS GLib interface (required for GNOME screensaver support) [autodetect]
Codecs:
--enable-gif enable gif support [autodetect]
@@ -1601,6 +1602,7 @@
_musepack=auto
_vstream=auto
_pthreads=yes
+_dbus_glib=auto
for ac_option do
case "$ac_option" in
# Skip 1st pass
@@ -1878,6 +1880,8 @@
--disable-vstream) _vstream=no ;;
--enable-pthreads) _pthreads=yes ;;
--disable-pthreads) _pthreads=no ;;
+ --enable-dbus-glib) _dbus_glib=yes ;;
+ --disable-dbus-glib) _dbus_glib=no ;;
--enable-fribidi) _fribidi=yes ;;
--disable-fribidi) _fribidi=no ;;
@@ -6815,6 +6819,24 @@
fi
echores "$_gethostbyname2"
+echocheck "D-BUS GLib interface"
+if test "$_dbus_glib" = auto && pkg-config --exists dbus-glib-1; then
+ _dbus_glib=yes
+ _inc_dbus_glib=`pkg-config --cflags dbus-glib-1 2>/dev/null`
+ _ld_dbus_glib=`pkg-config --libs dbus-glib-1 2>/dev/null`
+fi
+
+if test "$_dbus_glib" = yes; then
+ _def_dbus_glib='#define HAVE_DBUS_GLIB 1'
+ # Enable GNOME screensaver support if both D-BUS GLib and X11 are present
+ if test "$_x11" = yes; then
+ _vosrc="$_vosrc gnome_screensaver.c"
+ fi
+else
+ _def_dbus_glib='#undef HAVE_DBUS_GLIB'
+fi
+echores "$_dbus_glib"
+
# --------------- GUI specific tests begin -------------------
echocheck "GUI"
echo "$_gui"
@@ -7290,6 +7312,8 @@
AA_LIB = $_ld_aa
CACA_INC = $_inc_caca
CACA_LIB = $_ld_caca
+DBUS_GLIB_INC = $_inc_dbus_glib
+DBUS_GLIB_LIB = $_ld_dbus_glib
# audio output
ALSA_LIB = $_ld_alsa
@@ -8095,6 +8119,7 @@
$_def_tga
$_def_toolame
$_def_twolame
+$_def_dbus_glib
/* used by GUI: */
$_def_xshape
Index: libvo/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/Makefile,v
retrieving revision 1.54
diff -u -r1.54 Makefile
--- libvo/Makefile 28 Mar 2006 22:44:16 -0000 1.54
+++ libvo/Makefile 27 Apr 2006 14:56:51 -0000
@@ -62,6 +62,9 @@
vo_mpegpes.o: vo_mpegpes.c
$(CC) -c $(CFLAGS) $(DVB_INC) -o $@ $<
+gnome_screensaver.o: gnome_screensaver.c
+ $(CC) -c $(CFLAGS) $(DBUS_GLIB_INC) -o $@ $<
+
all: $(LIBNAME)
clean:
Index: libvo/gnome_screensaver.c
===================================================================
RCS file: libvo/gnome_screensaver.c
diff -N libvo/gnome_screensaver.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libvo/gnome_screensaver.c 27 Apr 2006 14:56:51 -0000
@@ -0,0 +1,107 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <dbus/dbus-glib.h>
+
+#include "gnome_screensaver.h"
+#include "mp_msg.h"
+
+#define GS_SERVICE "org.gnome.ScreenSaver"
+#define GS_PATH "/org/gnome/ScreenSaver"
+#define GS_INTERFACE "org.gnome.ScreenSaver"
+
+void gnome_screensaver_enable()
+{
+ DBusGConnection *connection;
+ GError *error;
+ DBusGProxy *proxy;
+
+ g_type_init();
+
+ error = NULL;
+ connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (connection == NULL) {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_enable(): Failed to open connection to bus: %s\n",
+ error->message);
+ g_error_free(error);
+ return;
+ }
+
+ /* Create a proxy object */
+ proxy = dbus_g_proxy_new_for_name(connection,
+ GS_SERVICE, GS_PATH, GS_INTERFACE);
+
+ /* Call method, wait for reply */
+ error = NULL;
+ if (!dbus_g_proxy_call
+ (proxy, "AllowActivation", &error, G_TYPE_INVALID,
+ G_TYPE_INVALID)) {
+ /* Just do demonstrate remote exceptions versus regular GError */
+ if (error->domain == DBUS_GERROR
+ && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_enable(): Caught remote method exception %s: %s",
+ dbus_g_error_get_name(error), error->message);
+ }
+ else {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_enable(): Error: %s\n",
+ error->message);
+ }
+ g_error_free(error);
+ }
+ else {
+ mp_msg(MSGT_VO, MSGL_INFO, "GNOME screensaver enabled\n");
+ }
+
+ g_object_unref(proxy);
+}
+
+
+void gnome_screensaver_disable()
+{
+ DBusGConnection *connection;
+ GError *error;
+ DBusGProxy *proxy;
+
+ g_type_init();
+
+ error = NULL;
+ connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (connection == NULL) {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_disable(): Failed to open connection to bus: %s\n",
+ error->message);
+ g_error_free(error);
+ return;
+ }
+
+ /* Create a proxy object */
+ proxy = dbus_g_proxy_new_for_name(connection,
+ GS_SERVICE, GS_PATH, GS_INTERFACE);
+
+ /* Call method, wait for reply */
+ error = NULL;
+ if (!dbus_g_proxy_call
+ (proxy, "InhibitActivation", &error, G_TYPE_STRING,
+ "Playing a movie", G_TYPE_INVALID, G_TYPE_INVALID)) {
+ /* Just do demonstrate remote exceptions versus regular GError */
+ if (error->domain == DBUS_GERROR
+ && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_disable(): Caught remote method exception %s: %s",
+ dbus_g_error_get_name(error), error->message);
+ }
+ else {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "gnome_screensaver_disable(): Error: %s\n",
+ error->message);
+ }
+ g_error_free(error);
+ }
+ else {
+ mp_msg(MSGT_VO, MSGL_INFO, "GNOME screensaver disabled\n");
+ }
+
+ g_object_unref(proxy);
+}
Index: libvo/gnome_screensaver.h
===================================================================
RCS file: libvo/gnome_screensaver.h
diff -N libvo/gnome_screensaver.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libvo/gnome_screensaver.h 27 Apr 2006 14:56:51 -0000
@@ -0,0 +1,7 @@
+#ifndef _GNOME_SCREENSAVER_H
+#define _GNOME_SCREENSAVER_H
+
+extern void gnome_screensaver_enable();
+extern void gnome_screensaver_disable();
+
+#endif /* !_GNOME_SCREENSAVER_H */
Index: libvo/x11_common.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/x11_common.c,v
retrieving revision 1.210
diff -u -r1.210 x11_common.c
--- libvo/x11_common.c 25 Apr 2006 21:36:02 -0000 1.210
+++ libvo/x11_common.c 27 Apr 2006 14:56:51 -0000
@@ -58,6 +58,10 @@
#include "mplayer.h"
#endif
+#ifdef HAVE_DBUS_GLIB
+#include "gnome_screensaver.h"
+#endif
+
#define WIN_LAYER_ONBOTTOM 2
#define WIN_LAYER_NORMAL 4
#define WIN_LAYER_ONTOP 6
@@ -1692,8 +1696,12 @@
timeout_save = 0;
}
- if (stop_xscreensaver)
+ if (stop_xscreensaver) {
xscreensaver_enable();
+#ifdef HAVE_DBUS_GLIB
+ gnome_screensaver_enable();
+#endif
+ }
if (kdescreensaver_was_running && stop_xscreensaver)
{
system
@@ -1738,8 +1746,12 @@
allow_exp);
}
// turning off screensaver
- if (stop_xscreensaver)
+ if (stop_xscreensaver) {
xscreensaver_disable(mDisplay);
+#ifdef HAVE_DBUS_GLIB
+ gnome_screensaver_disable();
+#endif
+ }
if (stop_xscreensaver && !kdescreensaver_was_running)
{
kdescreensaver_was_running =
More information about the MPlayer-dev-eng
mailing list