[Libreoffice-commits] core.git: Branch 'feature/screensaverinhibit-update' - 5 commits - vcl/inc vcl/unx
Andrzej Hunt
andrzej at ahunt.org
Mon Oct 19 12:53:25 PDT 2015
Rebased ref, commits from common ancestor:
commit de9436a4a1f7a3a7c83bfe30f29bbcbd03110847
Author: Andrzej Hunt <andrzej at 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 8a8dda4..cde7bb8 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 82b8879..ff97a9a 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 a0c7b00..b8aca70 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 f751016..a174dcb 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -1116,7 +1116,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);
@@ -2551,39 +2550,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 9dae54ea505d1dcfee676094571541276f906df6
Author: Andrzej Hunt <andrzej at 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 e91da12..8a8dda4 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 cf8420f..a0c7b00 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 d0be7cc..f751016 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -2536,40 +2536,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 afb86ebaeeb52c5816c5a3a7bfd0b97bbe227a55
Author: Andrzej Hunt <andrzej at 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 ad589c5232d75a5da1c4e55de80c0005f3dd8604
Author: Andrzej Hunt <andrzej at 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 8ecf86195af0e6a6ae0150092d363bd98d87ba2e
Author: Andrzej Hunt <andrzej at 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 8f6d60e..e91da12 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 e8ab616..cf8420f 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 624842c..d0be7cc 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)
@@ -1125,7 +1117,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);
@@ -2571,118 +2562,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 );
@@ -2707,10 +2592,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
{
@@ -2721,9 +2602,6 @@ void GtkSalFrame::StartPresentation( bool bStart )
bAllowExposures );
#endif
m_nSavedScreenSaverTimeout = 0;
-#ifdef ENABLE_DBUS
- dbus_uninhibit_gsm(m_nGSMCookie);
-#endif
}
}
More information about the Libreoffice-commits
mailing list