Kaydet (Commit) 5074d1b4 authored tarafından Andrzej Hunt's avatar Andrzej Hunt

Deduplicate XAutoLock inhibition and move to ScreenSaverInhibitor

(Successfully tested with xautolock 2.2)

Change-Id: I55a3703322dd6792689ff3c3e85b27840ee2bc55
üst e97b1b6c
...@@ -262,7 +262,6 @@ class GtkSalFrame : public SalFrame, public X11WindowProvider ...@@ -262,7 +262,6 @@ class GtkSalFrame : public SalFrame, public X11WindowProvider
void Center(); void Center();
void SetDefaultSize(); void SetDefaultSize();
void setAutoLock( bool bLock );
void doKeyCallback( guint state, void doKeyCallback( guint state,
guint keyval, guint keyval,
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX #ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
#define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX #define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
#include <prex.h>
#include <postx.h>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <vcl/dllapi.h> #include <vcl/dllapi.h>
...@@ -20,7 +23,8 @@ ...@@ -20,7 +23,8 @@
class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor
{ {
public: 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: private:
boost::optional<guint> mnFDOCookie; boost::optional<guint> mnFDOCookie;
...@@ -29,6 +33,8 @@ private: ...@@ -29,6 +33,8 @@ private:
// Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs GSM (Uninhibit) // Note: the Uninhibit call has different spelling in FDO (UnInhibit) vs GSM (Uninhibit)
void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason ); void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason );
void inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, const guint xid ); 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 #endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
......
...@@ -2189,87 +2189,15 @@ void X11SalFrame::ShowFullScreen( bool bFullScreen, sal_Int32 nScreen ) ...@@ -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 ) void X11SalFrame::StartPresentation( bool bStart )
{ {
maScreenSaverInhibitor.inhibit( bStart, maScreenSaverInhibitor.inhibit( bStart,
"presentation", "presentation",
true, // isX11 true, // isX11
mhWindow ); mhWindow,
GetXDisplay() );
vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation ); vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
if ( bStart )
MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
else
MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_ENABLE );
if( ! bStart && hPresentationWindow != None ) if( ! bStart && hPresentationWindow != None )
doReparentPresentationDialogues( GetDisplay() ); doReparentPresentationDialogues( GetDisplay() );
......
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include <generic/gensys.h> #include <generic/gensys.h>
#include <unx/screensaverinhibitor.hxx> #include <unx/screensaverinhibitor.hxx>
#include <prex.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <postx.h>
#ifdef ENABLE_DBUS #ifdef ENABLE_DBUS
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
...@@ -24,16 +29,25 @@ ...@@ -24,16 +29,25 @@
#include <sal/log.hxx> #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 gchar* appname = SalGenericSystem::getFrameClassName();
const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 ); const OString aReason = OUStringToOString( sReason, RTL_TEXTENCODING_UTF8 );
inhibitFDO( bInhibit, appname, aReason.getStr() ); 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 ...@@ -154,4 +168,33 @@ void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, cons
mnGSMCookie ); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -2538,40 +2538,21 @@ void GtkSalFrame::ShowFullScreen( bool bFullScreen, sal_Int32 nScreen ) ...@@ -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 ) 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, m_ScreenSaverInhibitor.inhibit( bStart,
"presentation", "presentation",
getDisplay()->IsX11Display(), getDisplay()->IsX11Display(),
widget_get_xid(m_pWindow) ); aWindow,
aDisplay );
setAutoLock( !bStart );
if( !getDisplay()->IsX11Display() ) if( !getDisplay()->IsX11Display() )
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment