diff options
author | Andrzej Hunt <andrzej@ahunt.org> | 2015-10-19 17:04:13 +0200 |
---|---|---|
committer | Andrzej Hunt <andrzej@ahunt.org> | 2015-10-20 18:14:38 +0200 |
commit | 095396f9eac1842fdfabb0c395dd7b9db8529cb4 (patch) | |
tree | 51bbb89b3f1b2e948f8876c019a732633d62bffb /vcl/unx/generic/window | |
parent | 3021a25b6d38e7de2e7a512c06adfea04a5394ec (diff) |
Move org.gnome.SessionManager.Inhibit to ScreenSaverInhibitor
We should be using the same inhibition code irregardless of
vcl backend on Linux.
Change-Id: I996630666e32c40a52958edb248466c815a5e0e5
Diffstat (limited to 'vcl/unx/generic/window')
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/generic/window/screensaverinhibitor.cxx | 90 |
2 files changed, 92 insertions, 3 deletions
diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index e913ccd0b97c..c5881a173685 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 4f0523f816b9..4ac63fe5750e 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 } |