diff options
-rw-r--r-- | vcl/Library_vcl.mk | 7 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/unx/salframe.h | 2 | ||||
-rw-r--r-- | vcl/inc/unx/screensaverinhibitor.hxx | 33 | ||||
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/window/screensaverinhibitor.cxx | 106 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtksalframe.cxx | 2 |
7 files changed, 154 insertions, 0 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index b54642feb18a..d485f335e899 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -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 \ diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 8ccba66b914d..9cc74046c051 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -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; diff --git a/vcl/inc/unx/salframe.h b/vcl/inc/unx/salframe.h index 489ee25cdd26..b10bebd6c16b 100644 --- a/vcl/inc/unx/salframe.h +++ b/vcl/inc/unx/salframe.h @@ -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; diff --git a/vcl/inc/unx/screensaverinhibitor.hxx b/vcl/inc/unx/screensaverinhibitor.hxx new file mode 100644 index 000000000000..93b6027582f5 --- /dev/null +++ b/vcl/inc/unx/screensaverinhibitor.hxx @@ -0,0 +1,33 @@ +/* -*- 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: */ diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 604ab609d93f..e913ccd0b97c 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -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 ); diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx b/vcl/unx/generic/window/screensaverinhibitor.cxx new file mode 100644 index 000000000000..4f0523f816b9 --- /dev/null +++ b/vcl/unx/generic/window/screensaverinhibitor.cxx @@ -0,0 +1,106 @@ +/* -*- 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: */ diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx index 25f3fe560e55..332d6f57b6d4 100644 --- a/vcl/unx/gtk/window/gtksalframe.cxx +++ b/vcl/unx/gtk/window/gtksalframe.cxx @@ -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() ) |