[PATCH] xineliboutput-1.0.0rc2 - Gnome Screensaver support in vdr-sxfe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Please find attached my second attempt at this patch that will disable the gnome screensaver when vdr-sxfe starts and enable it when it quits.

The first version was originally posted to the xineliboutput mailing list, this version of the patch has more intelligent Makefile that checks for dbus dev libraries and gets the paths for the dbus includes.

Most of the code is taken from this patch for mplayer:
http://codebrowse.launchpad.net/~ubuntu-dev/mplayer/ubuntu-feisty/bundle/nafallo%40magicalforest.se-20070311045121-8tq06wthciy3n0sc/bundle.txt

from what I could gather on the mplayer mailing list this patch was originally done by Piotr Kaczuba (pepe@xxxxxxxxxxxxx) so most credit should go to him. The gnome_screensaver.c file is pretty much entirely his with some changes to make it work with the vdr-sxfe logging so if it's used please be sure to credit him.

Any feedback appreciated.

Cheers,

Alex
diff -Nru ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.c vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.c
--- ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.c	1970-01-01 01:00:00.000000000 +0100
+++ vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.c	2007-07-02 14:28:21.000000000 +0100
@@ -0,0 +1,122 @@
+/*
+ * gnome_screensaver.c v0.0.7
+ *
+ * Enable/Disable the GNOME screensaver
+ * Supports GNOME screensaver API 2.14 and 2.15
+ *
+ * Call gnome_screensaver_control(1) to enable and
+ * gnome_screensaver_control(0) to disable
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <dbus/dbus-glib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#define NEED_x_syslog
+#define LOG_MODULENAME "[vdr-fe]    "
+
+#include "logdefs.h"
+#include "gnome_screensaver.h"
+
+#define GS_SERVICE   "org.gnome.ScreenSaver"
+#define GS_PATH      "/org/gnome/ScreenSaver"
+#define GS_INTERFACE "org.gnome.ScreenSaver"
+
+#define GS_APPLICATION_NAME     "vdr-sxfe"
+#define GS_REASON_FOR_INHIBIT   "Watching TV"
+
+// Log Messages
+#define MSG_OpenBusConnectionError "Failed to open connection to bus: %s"
+#define MSG_RemoteMethodException "Caught remote method exception %s: %s"
+#define MSG_GnomeAPI215Failed "GNOME screensaver 2.15 API failed, trying 2.14 API"
+#define MSG_GError "Error: %s"
+#define MSG_GNOMEScreensaverEnabled "GNOME screensaver enabled"
+#define MSG_GNOMEScreensaverDisabled "GNOME screensaver disabled"
+
+static guint32 cookie;
+
+void gnome_screensaver_control(int enable)
+{
+    DBusGConnection *connection;
+    GError *error;
+    DBusGProxy *proxy;
+    gboolean ret;
+
+    g_type_init();
+
+    /* Get a connection to the session bus */
+    error = NULL;
+    connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+    if (connection == NULL) {
+	LOGERR(MSG_OpenBusConnectionError, 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);
+
+    /* Enable the screensaver */
+    if (enable) {
+        /* First call the GNOME screensaver 2.15 API method */
+        error = NULL;
+        ret =
+            dbus_g_proxy_call(proxy, "UnInhibit", &error, G_TYPE_UINT,
+                              cookie, G_TYPE_INVALID, G_TYPE_INVALID);
+
+        /* If this fails, try the GNOME screensaver 2.14 API */
+        if (!ret && error->domain == DBUS_GERROR
+            && error->code == DBUS_GERROR_UNKNOWN_METHOD) {
+            LOGERR(MSG_GnomeAPI215Failed);
+            g_error_free(error);
+            error = NULL;
+            ret =
+                dbus_g_proxy_call(proxy, "AllowActivation", &error,
+                                  G_TYPE_INVALID, G_TYPE_INVALID);
+        }
+    }
+    /* Disable the screensaver */
+    else {
+        /* First call the GNOME screensaver 2.15 API method */
+        error = NULL;
+        ret =
+            dbus_g_proxy_call(proxy, "Inhibit", &error, G_TYPE_STRING,
+                              GS_APPLICATION_NAME, G_TYPE_STRING,
+                              GS_REASON_FOR_INHIBIT, G_TYPE_INVALID,
+                              G_TYPE_UINT, cookie, G_TYPE_INVALID);
+
+        /* If this fails, try the GNOME screensaver 2.14 API */
+        if (!ret && error->domain == DBUS_GERROR
+            && error->code == DBUS_GERROR_UNKNOWN_METHOD) {
+            LOGERR(MSG_GnomeAPI215Failed);
+            g_error_free(error);
+            error = NULL;
+            ret =
+                dbus_g_proxy_call(proxy, "InhibitActivation", &error,
+                                  G_TYPE_STRING, GS_REASON_FOR_INHIBIT,
+                                  G_TYPE_INVALID, G_TYPE_INVALID);
+        }
+    }
+
+    if (!ret) {
+        /* Check if it's a remote exception or a regular GError */
+        if (error->domain == DBUS_GERROR
+            && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+            LOGERR(MSG_RemoteMethodException, dbus_g_error_get_name(error), error->message);
+        }
+        else {
+            LOGERR(MSG_GError, error->message);
+        }
+        g_error_free(error);
+    }
+    else {
+        LOGMSG(enable ? MSG_GNOMEScreensaverEnabled : MSG_GNOMEScreensaverDisabled);
+    }
+
+    g_object_unref(proxy);
+}
diff -Nru ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.h vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.h
--- ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.h	1970-01-01 01:00:00.000000000 +0100
+++ vdr-plugin-xineliboutput-1.0.0~rc2/gnome_screensaver.h	2007-06-29 14:41:36.000000000 +0100
@@ -0,0 +1,6 @@
+#ifndef _GNOME_SCREENSAVER_H
+#define _GNOME_SCREENSAVER_H
+
+extern void gnome_screensaver_control(int enable);
+
+#endif /* !_GNOME_SCREENSAVER_H */
diff -Nru ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/Makefile vdr-plugin-xineliboutput-1.0.0~rc2/Makefile
--- ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/Makefile	2007-06-30 13:52:59.000000000 +0100
+++ vdr-plugin-xineliboutput-1.0.0~rc2/Makefile	2007-07-02 15:10:58.000000000 +0100
@@ -27,6 +27,9 @@
 
     ifeq ($(XINELIBOUTPUT_X11), 1)
         #$(warning Detected X11)
+
+        # Check for DBUS libs, if they exist we'll compile gnome screensaver support
+        XINELIBOUTPUT_DBUS = $(shell (pkg-config --exists dbus-glib-1 >/dev/null 2>&1 && echo "1") || echo "0")
     else
         $(warning ********************************************************)
         $(warning X11 not detected ! X11 frontends will not be compiled.  )
@@ -46,6 +49,7 @@
 
 USE_ICONV = 1
 #XINELIBOUTPUT_X11        = 1
+#XINELIBOUTPUT_DBUS       = 1
 #XINELIBOUTPUT_FB         = 1
 #XINELIBOUTPUT_XINEPLUGIN = 1
 #XINELIBOUTPUT_VDRPLUGIN  = 1
@@ -233,6 +237,14 @@
   DEFINES += -DSTARTUP_IMAGE_FILE='"$(STARTUP_IMAGE_FILE)"'
 endif
 
+# dbus define, libs and includes for gnome screensaver support
+ifeq ($(XINELIBOUTPUT_DBUS), 1)
+  DEFINES   += -DHAVE_DBUS_GLIB
+  LIBS_DBUS += $(shell pkg-config --libs dbus-glib-1 2>/dev/null)
+  INCLUDES  += $(shell pkg-config --cflags dbus-glib-1 2>/dev/null)
+endif
+
+
 
 ###
 ### configuration
@@ -259,8 +271,13 @@
 endif
 
 ifeq ($(XINELIBOUTPUT_X11), 1)
-  OBJS_SXFE_SO = xine_sxfe_frontend.o xine/post.o
-  OBJS_SXFE = xine_sxfe_frontend_standalone.o xine/post.o tools/vdrdiscovery_standalone.o
+  ifeq ($(XINELIBOUTPUT_DBUS), 1)
+    OBJS_SXFE_SO = xine_sxfe_frontend.o xine/post.o gnome_screensaver.o
+    OBJS_SXFE = xine_sxfe_frontend_standalone.o xine/post.o tools/vdrdiscovery_standalone.o gnome_screensaver.o
+  else 
+    OBJS_SXFE_SO = xine_sxfe_frontend.o xine/post.o
+    OBJS_SXFE = xine_sxfe_frontend_standalone.o xine/post.o tools/vdrdiscovery_standalone.o
+  endif 
 else
   OBJS_SXFE_SO = 
   OBJS_SXFE = 
@@ -330,7 +347,7 @@
 
 xine_sxfe_frontend.o: xine_sxfe_frontend.c xine_frontend.c xine_frontend.h \
 		xine_input_vdr.h xine_osd_command.h xine/post.h logdefs.h \
-		xineliboutput.c
+		xineliboutput.c gnome_screensaver.c
 	$(CC) $(CFLAGS) -c $(DEFINES) $(INCLUDES) $(OPTFLAGS) xine_sxfe_frontend.c
 xine_fbfe_frontend.o: xine_fbfe_frontend.c xine_frontend.c xine_frontend.h \
 		xine_input_vdr.h xine_osd_command.h xine/post.h logdefs.h \
@@ -339,13 +356,15 @@
 xine_sxfe_frontend_standalone.o: xine_sxfe_frontend.c xine_frontend.c \
 		xine_frontend.h xine_input_vdr.h xine_osd_command.h \
 		xine/post.h logdefs.h xine_frontend_main.c xine_frontend_lirc.c \
-		xineliboutput.c tools/vdrdiscovery.h
+		xineliboutput.c tools/vdrdiscovery.h gnome_screensaver.c
 	$(CC) $(CFLAGS) -c $(DEFINES) -DFE_STANDALONE $(INCLUDES) $(OPTFLAGS) xine_sxfe_frontend.c -o $@
 xine_fbfe_frontend_standalone.o: xine_fbfe_frontend.c xine_frontend.c \
 		xine_frontend.h xine_input_vdr.h xine_osd_command.h \
 		xine/post.h logdefs.h xine_frontend_main.c xine_frontend_lirc.c \
 		xineliboutput.c tools/vdrdiscovery.h
 	$(CC) $(CFLAGS) -c $(DEFINES) -DFE_STANDALONE $(INCLUDES) $(OPTFLAGS) xine_fbfe_frontend.c -o $@
+gnome_screensaver.o: gnome_screensaver.c gnome_screensaver.h
+	$(CC) $(CFLAGS) -c $(DEFINES) -DFE_STANDALONE $(INCLUDES) $(OPTFLAGS) gnome_screensaver.c
 
 
 ###
@@ -383,11 +402,11 @@
 
 ifeq ($(XINELIBOUTPUT_X11), 1)
 $(VDRPLUGIN_SXFE_SO): $(OBJS_SXFE_SO)
-	$(CC) $(CFLAGS) $(LDFLAGS_SO) $(OBJS_SXFE_SO) $(LIBS_X11) $(LIBS_XINE) -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS_SO) $(OBJS_SXFE_SO) $(LIBS_X11) ${LIBS_DBUS} $(LIBS_XINE) -o $@
 	@-rm -rf $(LIBDIR)/$(VDRPLUGIN_SXFE_SO).$(VERSION)
 	@cp $@ $(LIBDIR)/$(VDRPLUGIN_SXFE_SO).$(VERSION)
 $(VDRSXFE): $(OBJS_SXFE)
-	$(CC) -g $(OBJS_SXFE) $(LIBS_X11) -ljpeg $(LIBS_XINE) -o $@
+	$(CC) -g $(OBJS_SXFE) $(LIBS_X11) ${LIBS_DBUS} -ljpeg $(LIBS_XINE) -o $@
 endif
 
 ifeq ($(XINELIBOUTPUT_FB), 1)
diff -Nru ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/xine_sxfe_frontend.c vdr-plugin-xineliboutput-1.0.0~rc2/xine_sxfe_frontend.c
--- ../vdr/vdr-plugin-xineliboutput-1.0.0~rc2/xine_sxfe_frontend.c	2007-03-17 12:41:21.000000000 +0000
+++ vdr-plugin-xineliboutput-1.0.0~rc2/xine_sxfe_frontend.c	2007-06-30 13:30:07.000000000 +0100
@@ -63,6 +63,10 @@
 
 #include "xine_frontend.h"
 #include "xine/post.h"
+ 
+#ifdef HAVE_DBUS_GLIB
+#  include "gnome_screensaver.h"
+#endif
 
 #define MWM_HINTS_DECORATIONS       (1L << 1)
 #define PROP_MWM_HINTS_ELEMENTS     5
@@ -561,6 +565,10 @@
   }
 #endif
 
+#ifdef HAVE_DBUS_GLIB
+  gnome_screensaver_control(0);
+#endif
+
   this->xine_visual_type     = XINE_VISUAL_TYPE_X11;
   this->vis.display          = this->display;
   this->vis.screen           = this->screen;
@@ -881,6 +889,10 @@
 
   if(this && this->display) {
     
+#ifdef HAVE_DBUS_GLIB
+    gnome_screensaver_control(1);
+#endif
+
     if(this->xine)
       this->fe.xine_exit(this_gen);
     
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux