vcl/inc/unx/gtk/gtkframe.hxx | 1 vcl/inc/unx/screensaverinhibitor.hxx | 9 ++ vcl/unx/generic/window/salframe.cxx | 76 ------------------------ vcl/unx/generic/window/screensaverinhibitor.cxx | 44 ++++++++++++- vcl/unx/gtk/window/gtksalframe.cxx | 39 +++--------- 5 files changed, 61 insertions(+), 108 deletions(-)
New commits: commit daa61470c6726b723c9aec11bf0334c80163cc70 Author: Andrzej Hunt <andr...@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 8f6d60e..4552684 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -263,7 +263,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..b95f7df 100644 --- a/vcl/inc/unx/screensaverinhibitor.hxx +++ b/vcl/inc/unx/screensaverinhibitor.hxx @@ -10,6 +10,10 @@ #ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX #define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX +#include <prex.h> +#include <X11/Xatom.h> +#include <postx.h> + #include <rtl/ustring.hxx> #include <vcl/dllapi.h> @@ -20,7 +24,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 +34,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..c85efdd 100644 --- a/vcl/unx/generic/window/screensaverinhibitor.cxx +++ b/vcl/unx/generic/window/screensaverinhibitor.cxx @@ -24,16 +24,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 +163,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 e92025b..b948209 100644 --- a/vcl/unx/gtk/window/gtksalframe.cxx +++ b/vcl/unx/gtk/window/gtksalframe.cxx @@ -2537,40 +2537,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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits