Kaydet (Commit) 3021a25b authored tarafından Andrzej Hunt's avatar Andrzej Hunt

Implement org.freedesktop.ScreenSaver inhibition

This is required for screensaver inhibition on kde (this might
also be supported on further desktops).

It would appear to make sense to move all screensaver inhibiting
code here into one location, since it should be shared across
the generic unx, and gtk vcl backends - currently we have completely
independent implementations for gtk/gtk3 (which only supports
XSetScreenSaver, and gnome's dbus inhibition), and the generic backend
for all other plugins, which supports XSetScreenSaver, xautolock, DPMS,
but no dbus inhibition.

Change-Id: I9c5af8021b0b49b5c93ed75a7d25e3208d5e9629
üst 03bb5d52
......@@ -43,6 +43,12 @@ $(eval $(call gb_Library_set_include,vcl,\
$(if $(filter WNTGCC,$(OS)$(COM)),-I$(MINGW_SYSROOT)/include/gdiplus) \
))
ifeq ($(ENABLE_DBUS),TRUE)
$(eval $(call gb_Library_add_defs,vclplug_gen,\
-DENABLE_DBUS \
))
endif
$(eval $(call gb_Library_add_defs,vcl,\
-DVCL_DLLIMPLEMENTATION \
-DCUI_DLL_NAME=\"$(call gb_Library_get_runtime_filename,$(call gb_Library__get_name,cui))\" \
......@@ -575,6 +581,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/unx/generic/printer/ppdparser \
vcl/unx/generic/gdi/cairotextrender \
vcl/unx/generic/gdi/x11windowprovider \
vcl/unx/generic/window/screensaverinhibitor \
$(if $(filter TRUE,$(ENABLE_CUPS)),\
vcl/unx/generic/printer/cupsmgr \
vcl/unx/generic/printer/printerinfomanager \
......
......@@ -35,6 +35,7 @@
#include <vcl/sysdata.hxx>
#include <unx/x11windowprovider.hxx>
#include <unx/saltype.h>
#include <unx/screensaverinhibitor.hxx>
#include "tools/link.hxx"
......@@ -193,6 +194,7 @@ class GtkSalFrame : public SalFrame, public X11WindowProvider
PointerStyle m_ePointerStyle;
int m_nSavedScreenSaverTimeout;
guint m_nGSMCookie;
ScreenSaverInhibitor m_ScreenSaverInhibitor;
int m_nWorkArea;
bool m_bFullscreen;
bool m_bSpanMonitorsWhenFullscreen;
......
......@@ -26,6 +26,7 @@
#include <unx/salunx.h>
#include <unx/saltype.h>
#include <unx/saldisp.hxx>
#include <unx/screensaverinhibitor.hxx>
#include <unx/x11windowprovider.hxx>
#include <salframe.hxx>
#include <salwtype.hxx>
......@@ -100,6 +101,7 @@ class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, public X11WindowProvider
bool m_bSetFocusOnMap;
int nScreenSaversTimeout_;
ScreenSaverInhibitor maScreenSaverInhibitor;
Rectangle maPaintRegion;
Timer maAlwaysOnTopRaiseTimer;
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
#define INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
#include <rtl/ustring.hxx>
#include <vcl/dllapi.h>
#include <boost/optional.hpp>
#include <glib.h>
class VCL_PLUGIN_PUBLIC ScreenSaverInhibitor
{
public:
void inhibit( bool bInhibit, bool bIsX11, const rtl::OUString& sReason );
private:
boost::optional<guint> mnFDOCookie;
void inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason );
};
#endif // INCLUDED_VCL_INC_UNX_SCREENSAVERINHIBITOR_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -2260,6 +2260,8 @@ MessageToXAutoLock( Display *p_display, int n_message )
void X11SalFrame::StartPresentation( bool bStart )
{
maScreenSaverInhibitor.inhibit( bStart, /* isX11 */ true, "presentation" );
vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
if ( bStart )
MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <generic/gensys.h>
#include <unx/screensaverinhibitor.hxx>
#ifdef ENABLE_DBUS
#include <dbus/dbus-glib.h>
#define FDO_DBUS_SERVICE "org.freedesktop.ScreenSaver"
#define FDO_DBUS_PATH "/org/freedesktop/ScreenSaver"
#define FDO_DBUS_INTERFACE "org.freedesktop.ScreenSaver"
#endif
#include <sal/log.hxx>
void ScreenSaverInhibitor::inhibit( bool bInhibit, bool bIsX11, const OUString& sReason )
{
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() );
}
void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason )
{
#ifdef ENABLE_DBUS
if ( ( !bInhibit && ( mnFDOCookie == boost::none ) ) ||
( bInhibit && ( mnFDOCookie != 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,
FDO_DBUS_SERVICE,
FDO_DBUS_PATH,
FDO_DBUS_INTERFACE );
if (proxy == NULL) {
SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " FDO_DBUS_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);
if (res)
{
mnFDOCookie = nCookie;
}
else
{
SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_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;
if (!res)
{
SAL_INFO( "vcl.screensaverinhibitor", FDO_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
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -2684,6 +2684,8 @@ dbus_uninhibit_gsm (guint cookie)
void GtkSalFrame::StartPresentation( bool bStart )
{
m_ScreenSaverInhibitor.inhibit( bStart, getDisplay()->IsX11Display(), "presentation" );
setAutoLock( !bStart );
if( !getDisplay()->IsX11Display() )
......
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