vcl/Library_vcl.mk                              |    8 
 vcl/inc/unx/gtk/gtkframe.hxx                    |    5 
 vcl/inc/unx/salframe.h                          |    3 
 vcl/inc/unx/screensaverinhibitor.hxx            |   73 +++++
 vcl/unx/generic/window/salframe.cxx             |  180 -------------
 vcl/unx/generic/window/screensaverinhibitor.cxx |  332 ++++++++++++++++++++++++
 vcl/unx/gtk/window/gtksalframe.cxx              |  195 --------------
 7 files changed, 440 insertions(+), 356 deletions(-)

New commits:
commit 68570131013cfcf29f4c934a727053c2903e35b1
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Tue Oct 20 17:24:44 2015 +0200

    Add org.mate.SessionManager support
    
    This is valid for Mate <= 1.10
    (As of writing, 1.10 is the current stable release - so we'll have
     to keep shipping this for quite a few years to come.)
    
    Change-Id: I4d1f81c50923148e710eac22f5428b2a1c41f0e9

diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index f00e61f..286c18d 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -33,6 +33,7 @@ private:
     boost::optional<guint> mnFDOCookie; // FDO ScreenSaver Inhibit
     boost::optional<guint> mnFDOPMCookie; // FDO PowerManagement Inhibit
     boost::optional<guint> mnGSMCookie;
+    boost::optional<guint> mnMSMCookie;
 
     boost::optional<int> mnXScreenSaverTimeout;
 
@@ -53,11 +54,14 @@ private:
     // FDOPM: org.freedesktop.PowerManagement.Inhibit::Inhibit - XFCE, (KDE) ?
     //        (KDE: doesn't inhibit screensaver, but does inhibit 
PowerManagement)
     // GSM: org.gnome.SessionManager::Inhibit - gnome 3
+    // MSM: org.mate.Sessionmanager::Inhibit - Mate <= 1.10, is identical to 
GSM
+    //       (This is replaced by the GSM interface from Mate 1.12 onwards)
     //
     // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
     void inhibitFDOPM( bool bInhibit, const gchar* appname, const gchar* 
reason );
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
+    void inhibitMSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 
     void inhibitXScreenSaver( bool bInhibit, Display* pDisplay );
     static void inhibitXAutoLock( bool bInhibit, Display* pDisplay );
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index e26b17d..5346ac4 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -29,6 +29,11 @@
 #define GSM_DBUS_SERVICE        "org.gnome.SessionManager"
 #define GSM_DBUS_PATH           "/org/gnome/SessionManager"
 #define GSM_DBUS_INTERFACE      "org.gnome.SessionManager"
+
+// Mate <= 1.10 uses org.mate.SessionManager, > 1.10 will use 
org.gnome.SessionManager
+#define MSM_DBUS_SERVICE        "org.mate.SessionManager"
+#define MSM_DBUS_PATH           "/org/mate/SessionManager"
+#define MSM_DBUS_INTERFACE      "org.mate.SessionManager"
 #endif
 
 #include <sal/log.hxx>
@@ -54,6 +59,7 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const 
OUString& sReason,
         if ( xid != boost::none )
         {
             inhibitGSM( bInhibit, appname, aReason.getStr(), xid.get() );
+            inhibitMSM( bInhibit, appname, aReason.getStr(), xid.get() );
         }
     }
 }
@@ -198,6 +204,31 @@ void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, 
const gchar* appname, cons
                  mnGSMCookie );
 }
 
+void ScreenSaverInhibitor::inhibitMSM( bool bInhibit, const gchar* appname, 
const gchar* reason, const guint xid )
+{
+    dbusInhibit( bInhibit,
+                 MSM_DBUS_SERVICE, MSM_DBUS_PATH, MSM_DBUS_INTERFACE,
+                 [appname, reason, xid] ( DBusGProxy *proxy, guint& nCookie, 
GError*& error ) -> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Inhibit", &error,
+                                               G_TYPE_STRING, appname,
+                                               G_TYPE_UINT, xid,
+                                               G_TYPE_STRING, reason,
+                                               G_TYPE_UINT, 8, //Inhibit the 
session being marked as idle
+                                               G_TYPE_INVALID,
+                                               G_TYPE_UINT, &nCookie,
+                                               G_TYPE_INVALID );
+                 },
+                 [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) 
-> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Uninhibit", &error,
+                                               G_TYPE_UINT, nCookie,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_INVALID );
+                 },
+                 mnMSMCookie );
+}
+
 /**
  * Disable screensavers using the XSetScreenSaver/XGetScreenSaver API.
  *
commit f99674421d91d417abd965612fffd1d139473e7f
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Tue Oct 20 16:36:33 2015 +0200

    Add support for org.freedesktop.PowerManagement.Inhibit too
    
    This one seems to be supported by KDE (partially) and XFCE.
    On KDE it doesn't inhibit the ScreenSaver, however it's the only
    inhibition that appears to be available on XFCE (untested due
    to lack of XFCE system at hand).
    
    Change-Id: I4eab04d8ef66fc4fa55f57add46cb1ad15a8e2b3

diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index 2486961..f00e61f 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -30,7 +30,8 @@ public:
                   bool bIsX11, const boost::optional<guint> xid, 
boost::optional<Display*> pDisplay );
 
 private:
-    boost::optional<guint> mnFDOCookie;
+    boost::optional<guint> mnFDOCookie; // FDO ScreenSaver Inhibit
+    boost::optional<guint> mnFDOPMCookie; // FDO PowerManagement Inhibit
     boost::optional<guint> mnGSMCookie;
 
     boost::optional<int> mnXScreenSaverTimeout;
@@ -42,8 +43,20 @@ private:
     CARD16 mnDPMSOffTimeout;
 #endif
 
+    // There are a bunch of different dbus based inhibition APIs. Some call
+    // themselves ScreenSaver inhibition, some are PowerManagement inhibition,
+    // but they appear to have the same effect. There doesn't appear to be one
+    // all encompassing standard, hence we should just try all of tem.
+    //
+    // The current APIs we have: (note: the list of supported environments is 
incomplete)
+    // FDO: org.freedesktop.ScreenSaver::Inhibit - appears to be supported 
only by KDE?
+    // FDOPM: org.freedesktop.PowerManagement.Inhibit::Inhibit - XFCE, (KDE) ?
+    //        (KDE: doesn't inhibit screensaver, but does inhibit 
PowerManagement)
+    // GSM: org.gnome.SessionManager::Inhibit - gnome 3
+    //
     // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
+    void inhibitFDOPM( bool bInhibit, const gchar* appname, const gchar* 
reason );
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 
     void inhibitXScreenSaver( bool bInhibit, Display* pDisplay );
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 3b4b1db..e26b17d 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -22,6 +22,10 @@
 #define FDO_DBUS_PATH           "/org/freedesktop/ScreenSaver"
 #define FDO_DBUS_INTERFACE      "org.freedesktop.ScreenSaver"
 
+#define FDOPM_DBUS_SERVICE      "org.freedesktop.PowerManagement.Inhibit"
+#define FDOPM_DBUS_PATH         "/org/freedesktop/PowerManagement/Inhibit"
+#define FDOPM_DBUS_INTERFACE    "org.freedesktop.PowerManagement.Inhibit"
+
 #define GSM_DBUS_SERVICE        "org.gnome.SessionManager"
 #define GSM_DBUS_PATH           "/org/gnome/SessionManager"
 #define GSM_DBUS_INTERFACE      "org.gnome.SessionManager"
@@ -36,6 +40,7 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const 
OUString& sReason,
     const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 
);
 
     inhibitFDO( bInhibit, appname, aReason.getStr() );
+    inhibitFDOPM( bInhibit, appname, aReason.getStr() );
 
     if ( bIsX11 )
     {
@@ -145,6 +150,29 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, 
const gchar* appname, cons
                  mnFDOCookie );
 }
 
+void ScreenSaverInhibitor::inhibitFDOPM( bool bInhibit, const gchar* appname, 
const gchar* reason )
+{
+    dbusInhibit( bInhibit,
+                 FDOPM_DBUS_SERVICE, FDOPM_DBUS_PATH, FDOPM_DBUS_INTERFACE,
+                 [appname, reason] ( DBusGProxy *proxy, guint& nCookie, 
GError*& error ) -> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Inhibit", &error,
+                                               G_TYPE_STRING, appname,
+                                               G_TYPE_STRING, reason,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_UINT, &nCookie,
+                                               G_TYPE_INVALID );
+                 },
+                 [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) 
-> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "UnInhibit", &error,
+                                               G_TYPE_UINT, nCookie,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_INVALID );
+                 },
+                 mnFDOPMCookie );
+}
+
 void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, 
const gchar* reason, const guint xid )
 {
     dbusInhibit( bInhibit,
commit 18817c8cc0cb9d63bbb8c737ab221a9c47b4090a
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Tue Oct 20 12:20:04 2015 +0200

    Move DPMS inhibition to ScreenSaverInhibitor
    
    We should also be doing this irregardless of vcl backend
    
    Change-Id: I46ec2c654dfd9ab3c6bcf6da19e7ffa2c05890b9

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index d485f33..575a64f 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -734,6 +734,7 @@ $(eval $(call gb_Library_add_libs,vcl,\
        -lpthread \
     -lGL \
     -lX11 \
+       -lXext \
 ))
 
 $(eval $(call gb_Library_add_exception_objects,vcl,\
diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index 8c9ad54..2486961 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -11,6 +11,9 @@
 #define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
 
 #include <prex.h>
+#if !defined(SOLARIS) && !defined(AIX)
+#include <X11/extensions/dpms.h>
+#endif
 #include <postx.h>
 
 #include <rtl/ustring.hxx>
@@ -32,12 +35,20 @@ private:
 
     boost::optional<int> mnXScreenSaverTimeout;
 
+#if !defined(SOLARIS) && !defined(AIX)
+    BOOL mbDPMSWasEnabled;
+    CARD16 mnDPMSStandbyTimeout;
+    CARD16 mnDPMSSuspendTimeout;
+    CARD16 mnDPMSOffTimeout;
+#endif
+
     // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 
     void inhibitXScreenSaver( bool bInhibit, Display* pDisplay );
     static void inhibitXAutoLock( bool bInhibit, Display* pDisplay );
+    void inhibitDPMS( bool bInhibit, Display* pDisplay );
 };
 
 #endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
diff --git a/vcl/unx/generic/window/salframe.cxx 
b/vcl/unx/generic/window/salframe.cxx
index c1122f7..4be20a7 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -41,9 +41,6 @@
 #include <X11/keysym.h>
 #include "FWS.hxx"
 #include <X11/extensions/shape.h>
-#if !defined(SOLARIS) && !defined(AIX)
-#include <X11/extensions/dpms.h>
-#endif
 #include <postx.h>
 
 #include "unx/salunx.h"
@@ -2202,73 +2199,13 @@ void X11SalFrame::StartPresentation( bool bStart )
         doReparentPresentationDialogues( GetDisplay() );
     hPresentationWindow = (bStart && IsOverrideRedirect() ) ? GetWindow() : 
None;
 
-    // needs static here to save DPMS settings
-    int dummy;
-    static bool DPMSExtensionAvailable =
-#if !defined(SOLARIS) && !defined(AIX)
-        (DPMSQueryExtension(GetXDisplay(), &dummy, &dummy) != 0);
-    static sal_Bool DPMSEnabled = false;
-#else
-        false;
-    bool DPMSEnabled = false;
-    (void)dummy;
-#define CARD16 unsigned short
-#endif
-    static CARD16 dpms_standby_timeout=0;
-    static CARD16 dpms_suspend_timeout=0;
-    static CARD16 dpms_off_timeout=0;
-
-    if( bStart  || DPMSEnabled)
+    if( bStart && hPresentationWindow )
     {
-        if( hPresentationWindow )
-        {
-            /*  #i10559# workaround for WindowMaker: try to restore
-             *  current focus after presentation window is gone
-             */
-            int revert_to = 0;
-            XGetInputFocus( GetXDisplay(), &hPresFocusWindow, &revert_to );
-        }
-
-        // get the DPMS state right before the start
-        if (DPMSExtensionAvailable)
-        {
-#if !defined(SOLARIS) && !defined(AIX)
-            CARD16 state; // card16 is defined in Xdm.h
-            DPMSInfo(   GetXDisplay(),
-                        &state,
-                        &DPMSEnabled);
-#endif
-        }
-        if( bStart ) // start show
-        {
-#if !defined(SOLARIS) && !defined(AIX)
-            if( DPMSEnabled )
-            {
-                if ( DPMSExtensionAvailable )
-                {
-                    DPMSGetTimeouts(    GetXDisplay(),
-                                        &dpms_standby_timeout,
-                                        &dpms_suspend_timeout,
-                                        &dpms_off_timeout);
-                    DPMSSetTimeouts(GetXDisplay(), 0,0,0);
-                }
-            }
-#endif
-        }
-        else
-        {
-#if !defined(SOLARIS) && !defined(AIX)
-            if ( DPMSEnabled )
-            {
-                if ( DPMSExtensionAvailable )
-                {
-                // restore timeouts
-                    DPMSSetTimeouts(GetXDisplay(), dpms_standby_timeout,
-                        dpms_suspend_timeout, dpms_off_timeout);
-                }
-            }
-#endif
-        }
+        /*  #i10559# workaround for WindowMaker: try to restore
+         *  current focus after presentation window is gone
+         */
+        int revert_to = 0;
+        XGetInputFocus( GetXDisplay(), &hPresFocusWindow, &revert_to );
     }
 }
 
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 4add4bd..3b4b1db 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -43,6 +43,7 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const 
OUString& sReason,
         {
             inhibitXScreenSaver( bInhibit, pDisplay.get() );
             inhibitXAutoLock( bInhibit, pDisplay.get() );
+            inhibitDPMS( bInhibit, pDisplay.get() );
         }
 
         if ( xid != boost::none )
@@ -229,4 +230,44 @@ void ScreenSaverInhibitor::inhibitXAutoLock( bool 
bInhibit, Display* pDisplay )
                      sizeof( nMessage ) );
 }
 
+void ScreenSaverInhibitor::inhibitDPMS( bool bInhibit, Display* pDisplay )
+{
+#if !defined(SOLARIS) && !defined(AIX)
+    int dummy;
+    // This won't change while X11 is running, hence
+    // we can evaluate only once and store as static
+    static bool bDPMSExtensionAvailable = ( DPMSQueryExtension( pDisplay, 
&dummy, &dummy) != 0 );
+
+    if ( !bDPMSExtensionAvailable )
+    {
+        return;
+    }
+
+    if ( bInhibit )
+    {
+        CARD16 state; // unused by us
+        DPMSInfo( pDisplay, &state, &mbDPMSWasEnabled );
+
+        if ( mbDPMSWasEnabled )
+        {
+            DPMSGetTimeouts( pDisplay,
+                             &mnDPMSStandbyTimeout,
+                             &mnDPMSSuspendTimeout,
+                             &mnDPMSOffTimeout );
+            DPMSSetTimeouts( pDisplay,
+                             0,
+                             0,
+                             0 );
+        }
+    }
+    else if ( !bInhibit && mbDPMSWasEnabled )
+    {
+        DPMSSetTimeouts( pDisplay,
+                         mnDPMSStandbyTimeout,
+                         mnDPMSSuspendTimeout,
+                         mnDPMSOffTimeout );
+    }
+#endif // !defined(SOLARIS) && !defined(AIX)
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 189aabbcde1fe544a4e98ab9ee82aea03f1e00f3
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 21:50:39 2015 +0200

    Deduplicate XGet/SetScreenSaver, move to ScreenSaverInhibitor
    
    I haven't been able to find anyone actually using this API,
    however it's probably best not to remove it either?
    
    Change-Id: I0ca11591bfd54f9882d8081a94b012f638936ce5

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index e6cdbd7..4f73ac8 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -192,7 +192,6 @@ class GtkSalFrame : public SalFrame, public 
X11WindowProvider
     GdkCursor                      *m_pCurrentCursor;
     GdkVisibilityState              m_nVisibility;
     PointerStyle                    m_ePointerStyle;
-    int                             m_nSavedScreenSaverTimeout;
     ScreenSaverInhibitor            m_ScreenSaverInhibitor;
     int                             m_nWorkArea;
     bool                            m_bFullscreen;
diff --git a/vcl/inc/unx/salframe.h b/vcl/inc/unx/salframe.h
index b10bebd..d595c44 100644
--- a/vcl/inc/unx/salframe.h
+++ b/vcl/inc/unx/salframe.h
@@ -100,7 +100,6 @@ class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, 
public X11WindowProvider
     int             m_nWorkArea;
     bool            m_bSetFocusOnMap;
 
-    int             nScreenSaversTimeout_;
     ScreenSaverInhibitor maScreenSaverInhibitor;
     Rectangle       maPaintRegion;
 
diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index 56d1849..8c9ad54 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -30,10 +30,13 @@ private:
     boost::optional<guint> mnFDOCookie;
     boost::optional<guint> mnGSMCookie;
 
+    boost::optional<int> mnXScreenSaverTimeout;
+
     // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 
+    void inhibitXScreenSaver( bool bInhibit, Display* pDisplay );
     static void inhibitXAutoLock( bool bInhibit, Display* pDisplay );
 };
 
diff --git a/vcl/unx/generic/window/salframe.cxx 
b/vcl/unx/generic/window/salframe.cxx
index 331f82a..c1122f7 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -803,7 +803,6 @@ X11SalFrame::X11SalFrame( SalFrame *pParent, 
SalFrameStyleFlags nSalFrameStyle,
     mbInShow                    = false;
     m_bXEmbed                   = false;
 
-    nScreenSaversTimeout_       = 0;
 
     mpInputContext              = NULL;
     mbInputFocus                = False;
@@ -2219,7 +2218,7 @@ void X11SalFrame::StartPresentation( bool bStart )
     static CARD16 dpms_suspend_timeout=0;
     static CARD16 dpms_off_timeout=0;
 
-    if( bStart || nScreenSaversTimeout_ || DPMSEnabled)
+    if( bStart  || DPMSEnabled)
     {
         if( hPresentationWindow )
         {
@@ -2229,12 +2228,6 @@ void X11SalFrame::StartPresentation( bool bStart )
             int revert_to = 0;
             XGetInputFocus( GetXDisplay(), &hPresFocusWindow, &revert_to );
         }
-        int timeout, interval, prefer_blanking, allow_exposures;
-        XGetScreenSaver( GetXDisplay(),
-                         &timeout,
-                         &interval,
-                         &prefer_blanking,
-                         &allow_exposures );
 
         // get the DPMS state right before the start
         if (DPMSExtensionAvailable)
@@ -2248,16 +2241,6 @@ void X11SalFrame::StartPresentation( bool bStart )
         }
         if( bStart ) // start show
         {
-            if ( timeout )
-            {
-                nScreenSaversTimeout_ = timeout;
-                XResetScreenSaver( GetXDisplay() );
-                XSetScreenSaver( GetXDisplay(),
-                                 0,
-                                 interval,
-                                 prefer_blanking,
-                                 allow_exposures );
-            }
 #if !defined(SOLARIS) && !defined(AIX)
             if( DPMSEnabled )
             {
@@ -2274,15 +2257,6 @@ void X11SalFrame::StartPresentation( bool bStart )
         }
         else
         {
-            if( nScreenSaversTimeout_ )
-            {
-                XSetScreenSaver( GetXDisplay(),
-                             nScreenSaversTimeout_,
-                             interval,
-                             prefer_blanking,
-                             allow_exposures );
-                nScreenSaversTimeout_ = 0;
-            }
 #if !defined(SOLARIS) && !defined(AIX)
             if ( DPMSEnabled )
             {
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 0636b06..4add4bd 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -41,6 +41,7 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const 
OUString& sReason,
     {
         if ( pDisplay != boost::none )
         {
+            inhibitXScreenSaver( bInhibit, pDisplay.get() );
             inhibitXAutoLock( bInhibit, pDisplay.get() );
         }
 
@@ -168,6 +169,37 @@ void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, 
const gchar* appname, cons
                  mnGSMCookie );
 }
 
+/**
+ * Disable screensavers using the XSetScreenSaver/XGetScreenSaver API.
+ *
+ * Worth noting: xscreensaver explicitly ignores this and does it's own
+ * timeout handling.
+ */
+void ScreenSaverInhibitor::inhibitXScreenSaver( bool bInhibit, Display* 
pDisplay )
+{
+    int nTimeout, nInterval, bPreferBlanking, bAllowExposures;
+    XGetScreenSaver( pDisplay, &nTimeout, &nInterval,
+                     &bPreferBlanking, &bAllowExposures );
+
+    // To disable/reenable we simply fiddle the timeout, whilst
+    // retaining all other properties.
+    if ( bInhibit && nTimeout)
+    {
+        mnXScreenSaverTimeout = nTimeout;
+        XResetScreenSaver( pDisplay );
+        XSetScreenSaver( pDisplay, 0, nInterval,
+                         bPreferBlanking, bAllowExposures );
+    }
+    else if ( !bInhibit && ( mnXScreenSaverTimeout != boost::none ) )
+    {
+        XSetScreenSaver( pDisplay, mnXScreenSaverTimeout.get(),
+                         nInterval, bPreferBlanking,
+                         bAllowExposures );
+        mnXScreenSaverTimeout = boost::none;
+    }
+}
+
+
 /* definitions from xautolock.c (pl15) */
 #define XAUTOLOCK_DISABLE 1
 #define XAUTOLOCK_ENABLE  2
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx 
b/vcl/unx/gtk/window/gtksalframe.cxx
index 498161e..e2d5507 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -1118,7 +1118,6 @@ void GtkSalFrame::InitCommon()
     m_bSendModChangeOnRelease = false;
     m_pIMHandler        = NULL;
     m_hBackgroundPixmap = None;
-    m_nSavedScreenSaverTimeout = 0;
     m_nExtStyle         = 0;
     m_pRegion           = NULL;
     m_ePointerStyle     = static_cast<PointerStyle>(0xffff);
@@ -2553,39 +2552,6 @@ void GtkSalFrame::StartPresentation( bool bStart )
                                     getDisplay()->IsX11Display(),
                                     aWindow,
                                     aDisplay );
-
-    if( !getDisplay()->IsX11Display() )
-        return;
-
-#if !GTK_CHECK_VERSION(3,0,0)
-    Display *pDisplay = GDK_DISPLAY_XDISPLAY( getGdkDisplay() );
-
-    int nTimeout, nInterval, bPreferBlanking, bAllowExposures;
-    XGetScreenSaver( pDisplay, &nTimeout, &nInterval,
-                     &bPreferBlanking, &bAllowExposures );
-#endif
-    if( bStart )
-    {
-#if !GTK_CHECK_VERSION(3,0,0)
-        if ( nTimeout )
-        {
-            m_nSavedScreenSaverTimeout = nTimeout;
-            XResetScreenSaver( pDisplay );
-            XSetScreenSaver( pDisplay, 0, nInterval,
-                             bPreferBlanking, bAllowExposures );
-        }
-#endif
-    }
-    else
-    {
-#if !GTK_CHECK_VERSION(3,0,0)
-        if( m_nSavedScreenSaverTimeout )
-            XSetScreenSaver( pDisplay, m_nSavedScreenSaverTimeout,
-                             nInterval, bPreferBlanking,
-                             bAllowExposures );
-#endif
-        m_nSavedScreenSaverTimeout = 0;
-    }
 }
 
 void GtkSalFrame::SetAlwaysOnTop( bool bOnTop )
commit 5074d1b4d712cd35798758e8168ffbdfe59a11a9
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 20:11:53 2015 +0200

    Deduplicate XAutoLock inhibition and move to ScreenSaverInhibitor
    
    (Successfully tested with xautolock 2.2)
    
    Change-Id: I55a3703322dd6792689ff3c3e85b27840ee2bc55

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 1a56cdf..e6cdbd7 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -262,7 +262,6 @@ class GtkSalFrame : public SalFrame, public 
X11WindowProvider
 
     void            Center();
     void            SetDefaultSize();
-    void            setAutoLock( bool bLock );
 
     void            doKeyCallback( guint state,
                                    guint keyval,
diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index b1c742f..56d1849 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -10,6 +10,9 @@
 #ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
 #define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
 
+#include <prex.h>
+#include <postx.h>
+
 #include <rtl/ustring.hxx>
 #include <vcl/dllapi.h>
 
@@ -20,7 +23,8 @@
 class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor
 {
 public:
-    void inhibit( bool bInhibit, const rtl::OUString& sReason, bool bIsX11, 
const boost::optional<guint> xid );
+    void inhibit( bool bInhibit, const rtl::OUString& sReason,
+                  bool bIsX11, const boost::optional<guint> xid, 
boost::optional<Display*> pDisplay );
 
 private:
     boost::optional<guint> mnFDOCookie;
@@ -29,6 +33,8 @@ private:
     // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
+
+    static void inhibitXAutoLock( bool bInhibit, Display* pDisplay );
 };
 
 #endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
diff --git a/vcl/unx/generic/window/salframe.cxx 
b/vcl/unx/generic/window/salframe.cxx
index c5881a1..331f82a 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -2189,87 +2189,15 @@ void X11SalFrame::ShowFullScreen( bool bFullScreen, 
sal_Int32 nScreen )
     }
 }
 
-/* ---------------------------------------------------------------------
-   the xautolock pseudo screen saver needs special treatment since it
-   doesn't cooperate with XxxxScreenSaver settings
-   ------------------------------------------------------------------- */
-
-static Bool
-IsRunningXAutoLock( Display *p_display, ::Window a_window )
-{
-    const char *p_atomname = "XAUTOLOCK_SEMAPHORE_PID";
-    Atom        a_pidatom;
-
-    // xautolock interns this atom
-    a_pidatom    = XInternAtom( p_display, p_atomname, True );
-    if ( a_pidatom == None )
-        return False;
-
-    Atom          a_type;
-    int           n_format;
-    unsigned long n_items;
-    unsigned long n_bytes_after;
-    pid_t        *p_pid;
-    pid_t         n_pid;
-    // get pid of running xautolock
-    XGetWindowProperty (p_display, a_window, a_pidatom, 0L, 2L, False,
-            AnyPropertyType, &a_type, &n_format, &n_items, &n_bytes_after,
-            reinterpret_cast<unsigned char**>(&p_pid) );
-    n_pid = *p_pid;
-    XFree( p_pid );
-
-      if ( a_type == XA_INTEGER )
-      {
-        // check if xautolock pid points to a running process
-        if ( kill(n_pid, 0) == -1 )
-            return False;
-        else
-            return True;
-    }
-
-    return False;
-}
-
-/* definitions from xautolock.c (pl15) */
-#define XAUTOLOCK_DISABLE 1
-#define XAUTOLOCK_ENABLE  2
-
-static Bool
-MessageToXAutoLock( Display *p_display, int n_message )
-{
-    const char *p_atomname = "XAUTOLOCK_MESSAGE" ;
-    Atom        a_messageatom;
-    ::Window    a_rootwindow;
-
-    a_rootwindow = RootWindowOfScreen( ScreenOfDisplay(p_display, 0) );
-    if ( ! IsRunningXAutoLock(p_display, a_rootwindow) )
-    {
-        // remove any pending messages
-        a_messageatom = XInternAtom( p_display, p_atomname, True );
-        if ( a_messageatom != None )
-            XDeleteProperty( p_display, a_rootwindow, a_messageatom );
-        return False;
-    }
-
-    a_messageatom = XInternAtom( p_display, p_atomname, False );
-    XChangeProperty (p_display, a_rootwindow, a_messageatom, XA_INTEGER,
-            8, PropModeReplace, reinterpret_cast<unsigned char*>(&n_message), 
sizeof(n_message) );
-
-    return True;
-}
-
 void X11SalFrame::StartPresentation( bool bStart )
 {
     maScreenSaverInhibitor.inhibit( bStart,
                                     "presentation",
                                     true, // isX11
-                                    mhWindow );
+                                    mhWindow,
+                                    GetXDisplay() );
 
     vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
-    if ( bStart )
-        MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
-    else
-        MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_ENABLE );
 
     if( ! bStart && hPresentationWindow != None )
         doReparentPresentationDialogues( GetDisplay() );
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index b352c1d..0636b06 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -10,6 +10,11 @@
 #include <generic/gensys.h>
 #include <unx/screensaverinhibitor.hxx>
 
+#include <prex.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <postx.h>
+
 #ifdef ENABLE_DBUS
 #include <dbus/dbus-glib.h>
 
@@ -24,16 +29,25 @@
 
 #include <sal/log.hxx>
 
-void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason, 
bool bIsX11, const boost::optional<guint> xid )
+void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason,
+                                    bool bIsX11, const boost::optional<guint> 
xid, boost::optional<Display*> pDisplay )
 {
     const gchar* appname = SalGenericSystem::getFrameClassName();
     const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 
);
 
     inhibitFDO( bInhibit, appname, aReason.getStr() );
 
-    if ( bIsX11 && ( xid != boost::none ) )
+    if ( bIsX11 )
     {
-        inhibitGSM( bInhibit, appname, aReason.getStr(), xid.get() );
+        if ( pDisplay != boost::none )
+        {
+            inhibitXAutoLock( bInhibit, pDisplay.get() );
+        }
+
+        if ( xid != boost::none )
+        {
+            inhibitGSM( bInhibit, appname, aReason.getStr(), xid.get() );
+        }
     }
 }
 
@@ -154,4 +168,33 @@ void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, 
const gchar* appname, cons
                  mnGSMCookie );
 }
 
+/* definitions from xautolock.c (pl15) */
+#define XAUTOLOCK_DISABLE 1
+#define XAUTOLOCK_ENABLE  2
+
+void ScreenSaverInhibitor::inhibitXAutoLock( bool bInhibit, Display* pDisplay )
+{
+    ::Window aRootWindow = RootWindowOfScreen( ScreenOfDisplay( pDisplay, 0 ) 
);
+
+    Atom nAtom = XInternAtom( pDisplay,
+                              "XAUTOLOCK_MESSAGE",
+                              False );
+
+    if ( nAtom == None )
+    {
+        return;
+    }
+
+    int nMessage = bInhibit ? XAUTOLOCK_DISABLE : XAUTOLOCK_ENABLE;
+
+    XChangeProperty( pDisplay,
+                     aRootWindow,
+                     nAtom,
+                     XA_INTEGER,
+                     8, // format -- 8 bit quantity
+                     PropModeReplace,
+                     reinterpret_cast<unsigned char*>( &nMessage ),
+                     sizeof( nMessage ) );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx 
b/vcl/unx/gtk/window/gtksalframe.cxx
index 4d74e67a..498161e 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -2538,40 +2538,21 @@ void GtkSalFrame::ShowFullScreen( bool bFullScreen, 
sal_Int32 nScreen )
     }
 }
 
-/* definitions from xautolock.c (pl15) */
-#define XAUTOLOCK_DISABLE 1
-#define XAUTOLOCK_ENABLE  2
-
-void GtkSalFrame::setAutoLock( bool bLock )
-{
-    if( isChild() || !getDisplay()->IsX11Display() )
-        return;
-
-    GdkScreen  *pScreen = gtk_window_get_screen( GTK_WINDOW(m_pWindow) );
-    GdkDisplay *pDisplay = gdk_screen_get_display( pScreen );
-    GdkWindow  *pRootWin = gdk_screen_get_root_window( pScreen );
-
-    Atom nAtom = XInternAtom( GDK_DISPLAY_XDISPLAY( pDisplay ),
-                              "XAUTOLOCK_MESSAGE", False );
-
-    int nMessage = bLock ? XAUTOLOCK_ENABLE : XAUTOLOCK_DISABLE;
-
-    XChangeProperty( GDK_DISPLAY_XDISPLAY( pDisplay ),
-                     GDK_WINDOW_XID( pRootWin ),
-                     nAtom, XA_INTEGER,
-                     8, PropModeReplace,
-                     reinterpret_cast<unsigned char*>(&nMessage),
-                     sizeof( nMessage ) );
-}
-
 void GtkSalFrame::StartPresentation( bool bStart )
 {
+    boost::optional<guint> aWindow;
+    boost::optional<Display*> aDisplay;
+    if( getDisplay()->IsX11Display() )
+    {
+        aWindow = widget_get_xid(m_pWindow);
+        aDisplay = GDK_DISPLAY_XDISPLAY( getGdkDisplay() );
+    }
+
     m_ScreenSaverInhibitor.inhibit( bStart,
                                     "presentation",
                                     getDisplay()->IsX11Display(),
-                                    widget_get_xid(m_pWindow) );
-
-    setAutoLock( !bStart );
+                                    aWindow,
+                                    aDisplay );
 
     if( !getDisplay()->IsX11Display() )
         return;
commit e97b1b6c28529487467ad9b4051ec288aa0f0c31
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 18:03:37 2015 +0200

    Lambda'ise the almost identical FDO and GSM screensaver inhibition
    
    This doesn't save us much for now, but could be useful when yet another
    screensaver inhibition standard is introduced. (The GSM/gnome inhibition
    currently requires passing the X11 window handle/id, which suggests that
    at some point they will have to update their screensaver inhibition api.)
    
    Change-Id: I4fa7bc15f089d112777fb166ab469045c002ae48

diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 4ac63fe..b352c1d 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -37,11 +37,15 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const 
OUString& sReason, bool
     }
 }
 
-void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, 
const gchar* reason )
+void dbusInhibit( bool bInhibit,
+                  const gchar* service, const gchar* path, const gchar* 
interface,
+                  std::function<bool( DBusGProxy*, guint&, GError*& )> 
fInhibit,
+                  std::function<bool( DBusGProxy*, const guint, GError*& )> 
fUnInhibit,
+                  boost::optional<guint>& rCookie )
 {
 #ifdef ENABLE_DBUS
-    if ( ( !bInhibit && ( mnFDOCookie == boost::none ) ) ||
-         ( bInhibit && ( mnFDOCookie != boost::none ) ) )
+    if ( ( !bInhibit && ( rCookie == boost::none ) ) ||
+         ( bInhibit && ( rCookie != boost::none ) ) )
     {
         return;
     }
@@ -58,46 +62,36 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const 
gchar* appname, cons
     }
 
     proxy = dbus_g_proxy_new_for_name( session_connection,
-                                       FDO_DBUS_SERVICE,
-                                       FDO_DBUS_PATH,
-                                       FDO_DBUS_INTERFACE );
+                                       service,
+                                       path,
+                                       interface );
     if (proxy == NULL) {
-        SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " 
FDO_DBUS_SERVICE );
+        SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " << 
service );
         return;
     }
 
     if ( bInhibit )
     {
         guint nCookie;
-        res = dbus_g_proxy_call( proxy,
-                                 "Inhibit", &error,
-                                 G_TYPE_STRING, appname,
-                                 G_TYPE_STRING, reason,
-                                 G_TYPE_INVALID,
-                                 G_TYPE_UINT, &nCookie,
-                                 G_TYPE_INVALID);
+        res = fInhibit( proxy, nCookie, error );
+
         if (res)
         {
-            mnFDOCookie = nCookie;
+            rCookie = nCookie;
         }
         else
         {
-            SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".Inhibit 
failed");
+            SAL_INFO( "vcl.screensaverinhibitor", service << ".Inhibit 
failed");
         }
     }
     else
     {
-        res = dbus_g_proxy_call (proxy,
-                                 "UnInhibit",
-                                 &error,
-                                 G_TYPE_UINT, mnFDOCookie.get(),
-                                 G_TYPE_INVALID,
-                                 G_TYPE_INVALID);
-        mnFDOCookie = boost::none;
+        res = fUnInhibit( proxy, rCookie.get(), error );
+        rCookie = boost::none;
 
         if (!res)
         {
-            SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".UnInhibit 
failed" );
+            SAL_INFO( "vcl.screensaverinhibitor", service << ".UnInhibit 
failed" );
         }
     }
 
@@ -112,81 +106,52 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, 
const gchar* appname, cons
 #endif // ENABLE_DBUS
 }
 
-void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, 
const gchar* reason, const guint xid )
+void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, 
const gchar* reason )
 {
-#ifdef ENABLE_DBUS
-    if ( ( !bInhibit && ( mnGSMCookie == boost::none ) ) ||
-         ( bInhibit && ( mnGSMCookie != boost::none ) ) )
-    {
-        return;
-    }
-
-    gboolean         res;
-    GError          *error = NULL;
-    DBusGProxy      *proxy = NULL;
-
-    DBusGConnection *session_connection = dbus_g_bus_get( DBUS_BUS_SESSION, 
&error );
-    if (error != NULL) {
-        SAL_WARN( "vcl.screensaverinhibitor", "failed to connect to dbus 
session bus: " << error->message );
-        g_error_free( error );
-        return;
-    }
-
-    proxy = dbus_g_proxy_new_for_name( session_connection,
-                                       GSM_DBUS_SERVICE,
-                                       GSM_DBUS_PATH,
-                                       GSM_DBUS_INTERFACE );
-    if (proxy == NULL) {
-        SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " 
GSM_DBUS_SERVICE );
-        return;
-    }
-
-    if ( bInhibit )
-    {
-        guint nCookie;
-        res = dbus_g_proxy_call (proxy,
-                                 "Inhibit", &error,
-                                 G_TYPE_STRING, appname,
-                                 G_TYPE_UINT, xid,
-                                 G_TYPE_STRING, reason,
-                                 G_TYPE_UINT, 8, //Inhibit the session being 
marked as idle
-                                 G_TYPE_INVALID,
-                                 G_TYPE_UINT, &nCookie,
-                                 G_TYPE_INVALID);
-        if ( res )
-        {
-            mnGSMCookie = nCookie;
-        }
-        else
-        {
-            SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Inhibit 
failed" );
-        }
-    }
-    else
-    {
-        res = dbus_g_proxy_call (proxy,
-                                 "Uninhibit",
-                                 &error,
-                                 G_TYPE_UINT, mnGSMCookie.get(),
-                                 G_TYPE_INVALID,
-                                 G_TYPE_INVALID);
-        mnGSMCookie = boost::none;
-
-        if ( !res )
-        {
-            SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Uninhibit 
failed" );
-        }
-    }
-
-    if (error != NULL)
-    {
-        SAL_INFO( "vcl.screensaverinhibitor", "Error: " << error->message );
-        g_error_free( error );
-    }
-
-    g_object_unref( G_OBJECT( proxy ) );
+    dbusInhibit( bInhibit,
+                 FDO_DBUS_SERVICE, FDO_DBUS_PATH, FDO_DBUS_INTERFACE,
+                 [appname, reason] ( DBusGProxy *proxy, guint& nCookie, 
GError*& error ) -> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Inhibit", &error,
+                                               G_TYPE_STRING, appname,
+                                               G_TYPE_STRING, reason,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_UINT, &nCookie,
+                                               G_TYPE_INVALID );
+                 },
+                 [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) 
-> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "UnInhibit", &error,
+                                               G_TYPE_UINT, nCookie,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_INVALID );
+                 },
+                 mnFDOCookie );
+}
 
-#endif // ENABLE_DBUS
+void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, 
const gchar* reason, const guint xid )
+{
+    dbusInhibit( bInhibit,
+                 GSM_DBUS_SERVICE, GSM_DBUS_PATH, GSM_DBUS_INTERFACE,
+                 [appname, reason, xid] ( DBusGProxy *proxy, guint& nCookie, 
GError*& error ) -> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Inhibit", &error,
+                                               G_TYPE_STRING, appname,
+                                               G_TYPE_UINT, xid,
+                                               G_TYPE_STRING, reason,
+                                               G_TYPE_UINT, 8, //Inhibit the 
session being marked as idle
+                                               G_TYPE_INVALID,
+                                               G_TYPE_UINT, &nCookie,
+                                               G_TYPE_INVALID );
+                 },
+                 [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) 
-> bool {
+                     return dbus_g_proxy_call( proxy,
+                                               "Uninhibit", &error,
+                                               G_TYPE_UINT, nCookie,
+                                               G_TYPE_INVALID,
+                                               G_TYPE_INVALID );
+                 },
+                 mnGSMCookie );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit a50ac1f8c7828836a9b1f928975196d79d21eb6a
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 17:50:24 2015 +0200

    Add comment on gsm vs fdo differences
    
    Change-Id: I30d1c24e84f1b28fad9933407b362be886821864

diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index 896f49a..b1c742f 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -26,6 +26,7 @@ private:
     boost::optional<guint> mnFDOCookie;
     boost::optional<guint> mnGSMCookie;
 
+    // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs 
GSM (Uninhibit)
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
     void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 };
commit 095396f9eac1842fdfabb0c395dd7b9db8529cb4
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 17:04:13 2015 +0200

    Move org.gnome.SessionManager.Inhibit to ScreenSaverInhibitor
    
    We should be using the same inhibition code irregardless of
    vcl backend on Linux.
    
    Change-Id: I996630666e32c40a52958edb248466c815a5e0e5

diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 9cc7404..1a56cdf 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -193,7 +193,6 @@ class GtkSalFrame : public SalFrame, public 
X11WindowProvider
     GdkVisibilityState              m_nVisibility;
     PointerStyle                    m_ePointerStyle;
     int                             m_nSavedScreenSaverTimeout;
-    guint                           m_nGSMCookie;
     ScreenSaverInhibitor            m_ScreenSaverInhibitor;
     int                             m_nWorkArea;
     bool                            m_bFullscreen;
diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
index 93b6027..896f49a 100644
--- a/vcl/inc/unx/screensaverinhibitor.hxx
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -20,12 +20,14 @@
 class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor
 {
 public:
-    void inhibit( bool bInhibit, bool bIsX11, const rtl::OUString& sReason );
+    void inhibit( bool bInhibit, const rtl::OUString& sReason, bool bIsX11, 
const boost::optional<guint> xid );
 
 private:
     boost::optional<guint> mnFDOCookie;
+    boost::optional<guint> mnGSMCookie;
 
     void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
+    void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, 
const guint xid );
 };
 
 #endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
diff --git a/vcl/unx/generic/window/salframe.cxx 
b/vcl/unx/generic/window/salframe.cxx
index e913ccd..c5881a1 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -2260,7 +2260,10 @@ MessageToXAutoLock( Display *p_display, int n_message )
 
 void X11SalFrame::StartPresentation( bool bStart )
 {
-    maScreenSaverInhibitor.inhibit( bStart, /* isX11 */ true, "presentation" );
+    maScreenSaverInhibitor.inhibit( bStart,
+                                    "presentation",
+                                    true, // isX11
+                                    mhWindow );
 
     vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
     if ( bStart )
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 4f0523f..4ac63fe 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -16,17 +16,25 @@
 #define FDO_DBUS_SERVICE        "org.freedesktop.ScreenSaver"
 #define FDO_DBUS_PATH           "/org/freedesktop/ScreenSaver"
 #define FDO_DBUS_INTERFACE      "org.freedesktop.ScreenSaver"
+
+#define GSM_DBUS_SERVICE        "org.gnome.SessionManager"
+#define GSM_DBUS_PATH           "/org/gnome/SessionManager"
+#define GSM_DBUS_INTERFACE      "org.gnome.SessionManager"
 #endif
 
 #include <sal/log.hxx>
 
-void ScreenSaverInhibitor::inhibit( bool bInhibit, bool bIsX11, const 
OUString& sReason )
+void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason, 
bool bIsX11, const boost::optional<guint> xid )
 {
     const gchar* appname = SalGenericSystem::getFrameClassName();
     const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 
);
 
-    (void ) bIsX11; // Will be needed once all inhibition tooling is moved here
     inhibitFDO( bInhibit, appname, aReason.getStr() );
+
+    if ( bIsX11 && ( xid != boost::none ) )
+    {
+        inhibitGSM( bInhibit, appname, aReason.getStr(), xid.get() );
+    }
 }
 
 void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, 
const gchar* reason )
@@ -100,6 +108,84 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, 
const gchar* appname, cons
     }
 
     g_object_unref( G_OBJECT( proxy ) );
+
+#endif // ENABLE_DBUS
+}
+
+void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, 
const gchar* reason, const guint xid )
+{
+#ifdef ENABLE_DBUS
+    if ( ( !bInhibit && ( mnGSMCookie == boost::none ) ) ||
+         ( bInhibit && ( mnGSMCookie != boost::none ) ) )
+    {
+        return;
+    }
+
+    gboolean         res;
+    GError          *error = NULL;
+    DBusGProxy      *proxy = NULL;
+
+    DBusGConnection *session_connection = dbus_g_bus_get( DBUS_BUS_SESSION, 
&error );
+    if (error != NULL) {
+        SAL_WARN( "vcl.screensaverinhibitor", "failed to connect to dbus 
session bus: " << error->message );
+        g_error_free( error );
+        return;
+    }
+
+    proxy = dbus_g_proxy_new_for_name( session_connection,
+                                       GSM_DBUS_SERVICE,
+                                       GSM_DBUS_PATH,
+                                       GSM_DBUS_INTERFACE );
+    if (proxy == NULL) {
+        SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " 
GSM_DBUS_SERVICE );
+        return;
+    }
+
+    if ( bInhibit )
+    {
+        guint nCookie;
+        res = dbus_g_proxy_call (proxy,
+                                 "Inhibit", &error,
+                                 G_TYPE_STRING, appname,
+                                 G_TYPE_UINT, xid,
+                                 G_TYPE_STRING, reason,
+                                 G_TYPE_UINT, 8, //Inhibit the session being 
marked as idle
+                                 G_TYPE_INVALID,
+                                 G_TYPE_UINT, &nCookie,
+                                 G_TYPE_INVALID);
+        if ( res )
+        {
+            mnGSMCookie = nCookie;
+        }
+        else
+        {
+            SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Inhibit 
failed" );
+        }
+    }
+    else
+    {
+        res = dbus_g_proxy_call (proxy,
+                                 "Uninhibit",
+                                 &error,
+                                 G_TYPE_UINT, mnGSMCookie.get(),
+                                 G_TYPE_INVALID,
+                                 G_TYPE_INVALID);
+        mnGSMCookie = boost::none;
+
+        if ( !res )
+        {
+            SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Uninhibit 
failed" );
+        }
+    }
+
+    if (error != NULL)
+    {
+        SAL_INFO( "vcl.screensaverinhibitor", "Error: " << error->message );
+        g_error_free( error );
+    }
+
+    g_object_unref( G_OBJECT( proxy ) );
+
 #endif // ENABLE_DBUS
 }
 
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx 
b/vcl/unx/gtk/window/gtksalframe.cxx
index 332d6f5..4d74e67a 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -87,14 +87,6 @@
 #  include <gdk/gdkkeysyms-compat.h>
 #endif
 
-#ifdef ENABLE_DBUS
-#include <dbus/dbus-glib.h>
-
-#define GSM_DBUS_SERVICE        "org.gnome.SessionManager"
-#define GSM_DBUS_PATH           "/org/gnome/SessionManager"
-#define GSM_DBUS_INTERFACE      "org.gnome.SessionManager"
-#endif
-
 #include <config_folders.h>
 
 #if GTK_CHECK_VERSION(3,0,0)
@@ -1127,7 +1119,6 @@ void GtkSalFrame::InitCommon()
     m_pIMHandler        = NULL;
     m_hBackgroundPixmap = None;
     m_nSavedScreenSaverTimeout = 0;
-    m_nGSMCookie = 0;
     m_nExtStyle         = 0;
     m_pRegion           = NULL;
     m_ePointerStyle     = static_cast<PointerStyle>(0xffff);
@@ -2573,118 +2564,12 @@ void GtkSalFrame::setAutoLock( bool bLock )
                      sizeof( nMessage ) );
 }
 
-#ifdef ENABLE_DBUS
-/** cookie is returned as an unsigned integer */
-static guint
-dbus_inhibit_gsm (const gchar *appname,
-                  const gchar *reason,
-                  guint xid)
-{
-        gboolean         res;
-        guint            cookie;
-        GError          *error = NULL;
-        DBusGProxy      *proxy = NULL;
-
-        /* get the DBUS session connection */
-        DBusGConnection *session_connection = dbus_g_bus_get 
(DBUS_BUS_SESSION, &error);
-        if (error != NULL) {
-                g_debug ("DBUS cannot connect : %s", error->message);
-                g_error_free (error);
-                return -1;
-        }
-
-        /* get the proxy with gnome-session-manager */
-        proxy = dbus_g_proxy_new_for_name (session_connection,
-                                           GSM_DBUS_SERVICE,
-                                           GSM_DBUS_PATH,
-                                           GSM_DBUS_INTERFACE);
-        if (proxy == NULL) {
-                g_debug ("Could not get DBUS proxy: %s", GSM_DBUS_SERVICE);
-                return -1;
-        }
-
-        res = dbus_g_proxy_call (proxy,
-                                 "Inhibit", &error,
-                                 G_TYPE_STRING, appname,
-                                 G_TYPE_UINT, xid,
-                                 G_TYPE_STRING, reason,
-                                 G_TYPE_UINT, 8, //Inhibit the session being 
marked as idle
-                                 G_TYPE_INVALID,
-                                 G_TYPE_UINT, &cookie,
-                                 G_TYPE_INVALID);
-
-        /* check the return value */
-        if (! res) {
-                cookie = -1;
-                g_debug ("Inhibit method failed");
-        }
-
-        /* check the error value */
-        if (error != NULL) {
-                g_debug ("Inhibit problem : %s", error->message);
-                g_error_free (error);
-                cookie = -1;
-        }
-
-        g_object_unref (G_OBJECT (proxy));
-        return cookie;
-}
-
-static void
-dbus_uninhibit_gsm (guint cookie)
-{
-        gboolean         res;
-        GError          *error = NULL;
-        DBusGProxy      *proxy = NULL;
-        DBusGConnection *session_connection = NULL;
-
-        if (cookie == guint(-1)) {
-                g_debug ("Invalid cookie");
-                return;
-        }
-
-        /* get the DBUS session connection */
-        session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-        if (error) {
-                g_debug ("DBUS cannot connect : %s", error->message);
-                g_error_free (error);
-                return;
-        }
-
-        /* get the proxy with gnome-session-manager */
-        proxy = dbus_g_proxy_new_for_name (session_connection,
-                                           GSM_DBUS_SERVICE,
-                                           GSM_DBUS_PATH,
-                                           GSM_DBUS_INTERFACE);
-        if (proxy == NULL) {
-                g_debug ("Could not get DBUS proxy: %s", GSM_DBUS_SERVICE);
-                return;
-        }
-
-        res = dbus_g_proxy_call (proxy,
-                                 "Uninhibit",
-                                 &error,
-                                 G_TYPE_UINT, cookie,
-                                 G_TYPE_INVALID,
-                                 G_TYPE_INVALID);
-
-        /* check the return value */
-        if (! res) {
-                g_debug ("Uninhibit method failed");
-        }
-
-        /* check the error value */
-        if (error != NULL) {
-                g_debug ("Uninhibit problem : %s", error->message);
-                g_error_free (error);
-        }
-        g_object_unref (G_OBJECT (proxy));
-}
-#endif
-
 void GtkSalFrame::StartPresentation( bool bStart )
 {
-    m_ScreenSaverInhibitor.inhibit( bStart, getDisplay()->IsX11Display(), 
"presentation" );
+    m_ScreenSaverInhibitor.inhibit( bStart,
+                                    "presentation",
+                                    getDisplay()->IsX11Display(),
+                                    widget_get_xid(m_pWindow) );
 
     setAutoLock( !bStart );
 
@@ -2709,10 +2594,6 @@ void GtkSalFrame::StartPresentation( bool bStart )
                              bPreferBlanking, bAllowExposures );
         }
 #endif
-#ifdef ENABLE_DBUS
-        m_nGSMCookie = dbus_inhibit_gsm(g_get_application_name(), 
"presentation",
-                    widget_get_xid(m_pWindow));
-#endif
     }
     else
     {
@@ -2723,9 +2604,6 @@ void GtkSalFrame::StartPresentation( bool bStart )
                              bAllowExposures );
 #endif
         m_nSavedScreenSaverTimeout = 0;
-#ifdef ENABLE_DBUS
-        dbus_uninhibit_gsm(m_nGSMCookie);
-#endif
     }
 }
 
commit 3021a25b6d38e7de2e7a512c06adfea04a5394ec
Author: Andrzej Hunt <andr...@ahunt.org>
Date:   Mon Oct 19 17:01:02 2015 +0200

    Implement org.freedesktop.ScreenSaver inhibition
    
    This is required for screensaver inhibition on kde (this might
    also be supported on further desktops).
    
    It would appear to make sense to move all screensaver inhibiting
    code here into one location, since it should be shared across
    the generic unx, and gtk vcl backends - currently we have completely
    independent implementations for gtk/gtk3 (which only supports
    XSetScreenSaver, and gnome's dbus inhibition), and the generic backend
    for all other plugins, which supports XSetScreenSaver, xautolock, DPMS,
    but no dbus inhibition.
    
    Change-Id: I9c5af8021b0b49b5c93ed75a7d25e3208d5e9629

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index b54642f..d485f33 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -43,6 +43,12 @@ $(eval $(call gb_Library_set_include,vcl,\
        $(if $(filter WNTGCC,$(OS)$(COM)),-I$(MINGW_SYSROOT)/include/gdiplus) \
 ))
 
+ifeq ($(ENABLE_DBUS),TRUE)
+$(eval $(call gb_Library_add_defs,vclplug_gen,\
+       -DENABLE_DBUS \
+))
+endif
+
 $(eval $(call gb_Library_add_defs,vcl,\
     -DVCL_DLLIMPLEMENTATION \
        -DCUI_DLL_NAME=\"$(call gb_Library_get_runtime_filename,$(call 
gb_Library__get_name,cui))\" \
@@ -575,6 +581,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/unx/generic/printer/ppdparser \
     vcl/unx/generic/gdi/cairotextrender \
     vcl/unx/generic/gdi/x11windowprovider \
+    vcl/unx/generic/window/screensaverinhibitor \
     $(if $(filter TRUE,$(ENABLE_CUPS)),\
         vcl/unx/generic/printer/cupsmgr \
         vcl/unx/generic/printer/printerinfomanager \
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 8ccba66..9cc7404 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -35,6 +35,7 @@
 #include <vcl/sysdata.hxx>
 #include <unx/x11windowprovider.hxx>
 #include <unx/saltype.h>
+#include <unx/screensaverinhibitor.hxx>
 
 #include "tools/link.hxx"
 
@@ -193,6 +194,7 @@ class GtkSalFrame : public SalFrame, public 
X11WindowProvider
     PointerStyle                    m_ePointerStyle;
     int                             m_nSavedScreenSaverTimeout;
     guint                           m_nGSMCookie;
+    ScreenSaverInhibitor            m_ScreenSaverInhibitor;
     int                             m_nWorkArea;
     bool                            m_bFullscreen;
     bool                            m_bSpanMonitorsWhenFullscreen;
diff --git a/vcl/inc/unx/salframe.h b/vcl/inc/unx/salframe.h
index 489ee25..b10bebd 100644
--- a/vcl/inc/unx/salframe.h
+++ b/vcl/inc/unx/salframe.h
@@ -26,6 +26,7 @@
 #include <unx/salunx.h>
 #include <unx/saltype.h>
 #include <unx/saldisp.hxx>
+#include <unx/screensaverinhibitor.hxx>
 #include <unx/x11windowprovider.hxx>
 #include <salframe.hxx>
 #include <salwtype.hxx>
@@ -100,6 +101,7 @@ class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, 
public X11WindowProvider
     bool            m_bSetFocusOnMap;
 
     int             nScreenSaversTimeout_;
+    ScreenSaverInhibitor maScreenSaverInhibitor;
     Rectangle       maPaintRegion;
 
     Timer           maAlwaysOnTopRaiseTimer;
diff --git a/vcl/inc/unx/screensaverinhibitor.hxx 
b/vcl/inc/unx/screensaverinhibitor.hxx
new file mode 100644
index 0000000..93b6027
--- /dev/null
+++ b/vcl/inc/unx/screensaverinhibitor.hxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
+#define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
+
+#include <rtl/ustring.hxx>
+#include <vcl/dllapi.h>
+
+#include <boost/optional.hpp>
+
+#include <glib.h>
+
+class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor
+{
+public:
+    void inhibit( bool bInhibit, bool bIsX11, const rtl::OUString& sReason );
+
+private:
+    boost::optional<guint> mnFDOCookie;
+
+    void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason 
);
+};
+
+#endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/window/salframe.cxx 
b/vcl/unx/generic/window/salframe.cxx
index 604ab60..e913ccd 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -2260,6 +2260,8 @@ MessageToXAutoLock( Display *p_display, int n_message )
 
 void X11SalFrame::StartPresentation( bool bStart )
 {
+    maScreenSaverInhibitor.inhibit( bStart, /* isX11 */ true, "presentation" );
+
     vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
     if ( bStart )
         MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx 
b/vcl/unx/generic/window/screensaverinhibitor.cxx
new file mode 100644
index 0000000..4f0523f
--- /dev/null
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <generic/gensys.h>
+#include <unx/screensaverinhibitor.hxx>
+
+#ifdef ENABLE_DBUS
+#include <dbus/dbus-glib.h>
+
+#define FDO_DBUS_SERVICE        "org.freedesktop.ScreenSaver"
+#define FDO_DBUS_PATH           "/org/freedesktop/ScreenSaver"
+#define FDO_DBUS_INTERFACE      "org.freedesktop.ScreenSaver"
+#endif
+
+#include <sal/log.hxx>
+
+void ScreenSaverInhibitor::inhibit( bool bInhibit, bool bIsX11, const 
OUString& sReason )
+{
+    const gchar* appname = SalGenericSystem::getFrameClassName();
+    const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 
);
+
+    (void ) bIsX11; // Will be needed once all inhibition tooling is moved here
+    inhibitFDO( bInhibit, appname, aReason.getStr() );
+}
+
+void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, 
const gchar* reason )
+{
+#ifdef ENABLE_DBUS
+    if ( ( !bInhibit && ( mnFDOCookie == boost::none ) ) ||
+         ( bInhibit && ( mnFDOCookie != boost::none ) ) )
+    {
+        return;
+    }
+
+    gboolean         res;
+    GError          *error = NULL;
+    DBusGProxy      *proxy = NULL;
+
+    DBusGConnection *session_connection = dbus_g_bus_get( DBUS_BUS_SESSION, 
&error );
+    if (error != NULL) {
+        SAL_WARN( "vcl.screensaverinhibitor", "failed to connect to dbus 
session bus: " << error->message );
+        g_error_free( error );
+        return;
+    }
+
+    proxy = dbus_g_proxy_new_for_name( session_connection,
+                                       FDO_DBUS_SERVICE,
+                                       FDO_DBUS_PATH,
+                                       FDO_DBUS_INTERFACE );
+    if (proxy == NULL) {
+        SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " 
FDO_DBUS_SERVICE );
+        return;
+    }
+
+    if ( bInhibit )
+    {
+        guint nCookie;
+        res = dbus_g_proxy_call( proxy,
+                                 "Inhibit", &error,
+                                 G_TYPE_STRING, appname,
+                                 G_TYPE_STRING, reason,
+                                 G_TYPE_INVALID,
+                                 G_TYPE_UINT, &nCookie,
+                                 G_TYPE_INVALID);
+        if (res)
+        {
+            mnFDOCookie = nCookie;
+        }
+        else
+        {
+            SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".Inhibit 
failed");
+        }
+    }
+    else
+    {
+        res = dbus_g_proxy_call (proxy,
+                                 "UnInhibit",
+                                 &error,
+                                 G_TYPE_UINT, mnFDOCookie.get(),
+                                 G_TYPE_INVALID,
+                                 G_TYPE_INVALID);
+        mnFDOCookie = boost::none;
+
+        if (!res)
+        {
+            SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".UnInhibit 
failed" );
+        }
+    }
+
+    if (error != NULL)
+    {
+        SAL_INFO( "vcl.screensaverinhibitor", "Error: " << error->message );
+        g_error_free( error );
+    }
+
+    g_object_unref( G_OBJECT( proxy ) );
+#endif // ENABLE_DBUS
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx 
b/vcl/unx/gtk/window/gtksalframe.cxx
index 25f3fe5..332d6f5 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -2684,6 +2684,8 @@ dbus_uninhibit_gsm (guint cookie)
 
 void GtkSalFrame::StartPresentation( bool bStart )
 {
+    m_ScreenSaverInhibitor.inhibit( bStart, getDisplay()->IsX11Display(), 
"presentation" );
+
     setAutoLock( !bStart );
 
     if( !getDisplay()->IsX11Display() )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to