From f927da9fd85ea3b4c7d64558d76accdb892b4544 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 27 May 2026 07:58:20 -0500 Subject: [PATCH] vcl/qt: add Mac display sleep inhibit support Change-Id: I8a5085529fe85ab43a6db462fbc2b4953d22d58f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207984 Reviewed-by: Dan Williams Tested-by: Jenkins --- vcl/Library_vclplug_osx.mk | 1 + vcl/inc/osx/salframe.h | 7 ++----- vcl/inc/osx/sessioninhibitor.hxx | 35 ++++++++++++++++++++++++++++++++ vcl/inc/qt5/QtFrame.hxx | 6 ++++-- vcl/osx/salframe.cxx | 7 ++----- vcl/osx/sessioninhibitor.cxx | 33 ++++++++++++++++++++++++++++++ vcl/qt5/QtFrame.cxx | 2 +- 7 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 vcl/inc/osx/sessioninhibitor.hxx create mode 100644 vcl/osx/sessioninhibitor.cxx diff --git a/vcl/Library_vclplug_osx.mk b/vcl/Library_vclplug_osx.mk index 043bbfee2c98..aa2179e5fcbe 100644 --- a/vcl/Library_vclplug_osx.mk +++ b/vcl/Library_vclplug_osx.mk @@ -136,6 +136,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_osx,\ vcl/osx/salsys \ vcl/osx/saltimer \ vcl/osx/service_entry \ + vcl/osx/sessioninhibitor \ vcl/quartz/CoreTextFont \ vcl/quartz/CoreTextFontFace \ vcl/quartz/SystemFontList \ diff --git a/vcl/inc/osx/salframe.h b/vcl/inc/osx/salframe.h index e26583dda03b..8cdf86792a3e 100644 --- a/vcl/inc/osx/salframe.h +++ b/vcl/inc/osx/salframe.h @@ -19,10 +19,6 @@ #pragma once -#include -#include -#include - #include #include @@ -30,6 +26,7 @@ #include #include #include +#include #include @@ -85,7 +82,7 @@ public: InputContextFlags mnICOptions; // To prevent display sleep during presentation - IOPMAssertionID mnAssertionID; + SessionManagerInhibitor mSessionManagerInhibitor; NSRect maFrameRect; NSRect maContentRect; diff --git a/vcl/inc/osx/sessioninhibitor.hxx b/vcl/inc/osx/sessioninhibitor.hxx new file mode 100644 index 000000000000..b3979078adb2 --- /dev/null +++ b/vcl/inc/osx/sessioninhibitor.hxx @@ -0,0 +1,35 @@ +/* -*- 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/. + */ + +#pragma once + +#include +#include +#include + +#include +#include +#include + +enum ApplicationInhibitFlags +{ + APPLICATION_INHIBIT_IDLE = (1 << 3) // Inhibit the session being marked as idle +}; + +class VCLPLUG_OSX_PUBLIC SessionManagerInhibitor +{ +public: + void inhibit(bool bInhibit, std::u16string_view sReason = u"", + ApplicationInhibitFlags eType = APPLICATION_INHIBIT_IDLE); + +private: + IOPMAssertionID mnAssertionID; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx index 2e4828e6d259..f1915dc646ee 100644 --- a/vcl/inc/qt5/QtFrame.hxx +++ b/vcl/inc/qt5/QtFrame.hxx @@ -26,7 +26,9 @@ #include "QtWidget.hxx" #include -#if defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD +#if defined MACOSX +#include +#elif defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD #include #endif #include @@ -100,7 +102,7 @@ class VCLPLUG_QT_PUBLIC QtFrame : public QObject, public SalFrame sal_uInt32 m_nRestoreScreen; QRect m_aRestoreGeometry; -#if defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD +#if defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD || defined MACOSX SessionManagerInhibitor m_SessionManagerInhibitor; #endif #if CHECK_ANY_QT_USING_X11 diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx index 64412511d6ce..84a656f89986 100644 --- a/vcl/osx/salframe.cxx +++ b/vcl/osx/salframe.cxx @@ -1052,10 +1052,7 @@ void AquaSalFrame::StartPresentation( bool bStart ) if( bStart ) { GetSalData()->maPresentationFrames.push_back( this ); - IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, - kIOPMAssertionLevelOn, - CFSTR("LibreOffice presentation running"), - &mnAssertionID); + mSessionManagerInhibitor.inhibit(true); [mpNSWindow setLevel: NSPopUpMenuWindowLevel]; if( mbShown ) [mpNSWindow makeMainWindow]; @@ -1063,7 +1060,7 @@ void AquaSalFrame::StartPresentation( bool bStart ) else { GetSalData()->maPresentationFrames.remove( this ); - IOPMAssertionRelease(mnAssertionID); + mSessionManagerInhibitor.inhibit(false); [mpNSWindow setLevel: NSNormalWindowLevel]; } } diff --git a/vcl/osx/sessioninhibitor.cxx b/vcl/osx/sessioninhibitor.cxx new file mode 100644 index 000000000000..1d37fe030ee9 --- /dev/null +++ b/vcl/osx/sessioninhibitor.cxx @@ -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/. + */ + +#include + +#include + +#include + +void SessionManagerInhibitor::inhibit(bool bInhibit, std::u16string_view sReason, + ApplicationInhibitFlags eType) +{ + (void)sReason; + assert(eType == APPLICATION_INHIBIT_IDLE); + + if (bInhibit) + { + IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, + CFSTR("LibreOffice presentation running"), &mnAssertionID); + } + else + { + IOPMAssertionRelease(mnAssertionID); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index c6351c2a9885..6411d69a7112 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -668,7 +668,7 @@ void QtFrame::ShowFullScreen(bool bFullScreen, sal_Int32 nScreen) void QtFrame::StartPresentation(bool bStart) { -#if defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD +#if defined LINUX || defined __sun || defined FREEBSD || defined OPENBSD || defined MACOSX #if CHECK_QT5_USING_X11 unsigned int nRootWindow(0); std::optional aDisplay;