+#ifdef HAVE_DBUS
+
+static DBusConnection * dbus_init( intf_thread_t *p_intf )
+{
+ DBusError dbus_error;
+
+ dbus_error_init (&dbus_error);
+ DBusConnection * p_connection = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error );
+
+ if ( !p_connection )
+ {
+ msg_Warn( p_intf, "failed to connect to the D-BUS daemon: %s",
+ dbus_error.message);
+ dbus_error_free( &dbus_error );
+ return NULL;
+ }
+
+ return p_connection;
+}
+
+static void poke_screensaver( intf_thread_t *p_intf,
+ DBusConnection *p_connection )
+{
+ if( screensaver_is_running( p_connection ) )
+ {
+# ifdef SCREENSAVER_DEBUG
+ msg_Dbg( p_intf, "found a running gnome-screensaver instance" );
+# endif
+ /* gnome-screensaver changed it's D-Bus interface, so we need both */
+ screensaver_send_message_void( p_intf, p_connection, "Poke" );
+ screensaver_send_message_void( p_intf, p_connection,
+ "SimulateUserActivity" );
+ }
+# ifdef SCREENSAVER_DEBUG
+ else
+ {
+ msg_Dbg( p_intf, "found no running gnome-screensaver instance" );
+ }
+# endif
+}
+
+static void screensaver_send_message_void ( intf_thread_t *p_intf,
+ DBusConnection *p_connection,
+ const char *psz_name )
+{
+ DBusMessage *p_message;
+
+ if( !p_connection || !psz_name ) return;
+
+ p_message = dbus_message_new_method_call( GS_SERVICE, GS_PATH,
+ GS_INTERFACE, psz_name );
+ if( p_message == NULL )
+ {
+ msg_Err( p_intf, "DBUS initialization failed: message initialization" );
+ return;
+ }
+
+ if( !dbus_connection_send( p_connection, p_message, NULL ) )
+ {
+ msg_Err( p_intf, "DBUS communication failed" );
+ }
+
+ dbus_connection_flush( p_connection );
+
+ dbus_message_unref( p_message );
+}
+
+static vlc_bool_t screensaver_is_running( DBusConnection *p_connection )
+{
+ DBusError error;
+ vlc_bool_t b_return;
+
+ if( !p_connection ) return VLC_FALSE;
+
+ dbus_error_init( &error );
+ b_return = dbus_bus_name_has_owner( p_connection, GS_SERVICE, &error );
+ if( dbus_error_is_set( &error ) ) dbus_error_free (&error);
+
+ return b_return;
+}
+
+#endif
+