summaryrefslogtreecommitdiff
path: root/vcl/unx
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej@ahunt.org>2015-10-19 20:11:53 +0200
committerAndrzej Hunt <andrzej@ahunt.org>2015-10-20 18:14:39 +0200
commit5074d1b4d712cd35798758e8168ffbdfe59a11a9 (patch)
tree08a67859c2bd39050ec8fb859dc0d08f5d15f831 /vcl/unx
parente97b1b6c28529487467ad9b4051ec288aa0f0c31 (diff)
Deduplicate XAutoLock inhibition and move to ScreenSaverInhibitor
(Successfully tested with xautolock 2.2) Change-Id: I55a3703322dd6792689ff3c3e85b27840ee2bc55
Diffstat (limited to 'vcl/unx')
-rw-r--r--vcl/unx/generic/window/salframe.cxx76
-rw-r--r--vcl/unx/generic/window/screensaverinhibitor.cxx49
-rw-r--r--vcl/unx/gtk/window/gtksalframe.cxx39
3 files changed, 58 insertions, 106 deletions
diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx
index c5881a173685..331f82af845d 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 b352c1d2e862..0636b06b68fe 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 4d74e67ac15c..498161e60d24 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;