summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej@ahunt.org>2015-10-19 17:04:13 +0200
committerAndrzej Hunt <andrzej@ahunt.org>2015-10-20 18:14:38 +0200
commit095396f9eac1842fdfabb0c395dd7b9db8529cb4 (patch)
tree51bbb89b3f1b2e948f8876c019a732633d62bffb /vcl
parent3021a25b6d38e7de2e7a512c06adfea04a5394ec (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')
-rw-r--r--vcl/inc/unx/gtk/gtkframe.hxx1
-rw-r--r--vcl/inc/unx/screensaverinhibitor.hxx4
-rw-r--r--vcl/unx/generic/window/salframe.cxx5
-rw-r--r--vcl/unx/generic/window/screensaverinhibitor.cxx90
-rw-r--r--vcl/unx/gtk/window/gtksalframe.cxx130
5 files changed, 99 insertions, 131 deletions
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index 9cc74046c051..1a56cdfd5486 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 93b6027582f5..896f49ae164c 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 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
}
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx
index 332d6f57b6d4..4d74e67ac15c 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
}
}