From fa802a5f3bb3abd11b5951882f9b2225b4fbccd2 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 29 Jan 2022 15:53:08 -0700 Subject: [PATCH] Stop the display window from minimizing when the OpenLP window is not active on macOS --- openlp/core/display/window.py | 4 +++- tests/openlp_core/display/test_window.py | 30 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/openlp/core/display/window.py b/openlp/core/display/window.py index aa5825e37..46e4f6128 100644 --- a/openlp/core/display/window.py +++ b/openlp/core/display/window.py @@ -29,7 +29,7 @@ import re from PyQt5 import QtCore, QtWebChannel, QtWidgets -from openlp.core.common import is_win +from openlp.core.common import is_win, is_macosx from openlp.core.common.applocation import AppLocation from openlp.core.common.enum import ServiceItemType from openlp.core.common.i18n import translate @@ -84,6 +84,8 @@ class DisplayWindow(QtWidgets.QWidget, RegistryProperties, LogMixin): flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint if self.settings.value('advanced/x11 bypass wm'): flags |= QtCore.Qt.X11BypassWindowManagerHint + if is_macosx(): + self.setAttribute(QtCore.Qt.WA_MacAlwaysShowToolWindow, True) # Need to import this inline to get around a QtWebEngine issue from openlp.core.display.webengine import WebEngineView self._is_initialised = False diff --git a/tests/openlp_core/display/test_window.py b/tests/openlp_core/display/test_window.py index fd5ab42b8..301c34d15 100644 --- a/tests/openlp_core/display/test_window.py +++ b/tests/openlp_core/display/test_window.py @@ -93,6 +93,36 @@ def test_x11_override_off(display_window_env, mock_settings): assert x11_bit != QtCore.Qt.X11BypassWindowManagerHint +@patch('openlp.core.display.window.is_macosx') +def test_macos_toolwindow_attribute_set(mocked_is_macosx, mock_settings, display_window_env): + """ + Test that on macOS, the Qt.WA_MacAlwaysShowToolWindow attribute is set + """ + # GIVEN: We're on macOS + mocked_is_macosx.return_value = True + + # WHEN: A DisplayWindow is created + display_window = DisplayWindow() + + # THEN: The attribute is set + assert display_window.testAttribute(QtCore.Qt.WA_MacAlwaysShowToolWindow) is True + + +@patch('openlp.core.display.window.is_macosx') +def test_not_macos_toolwindow_attribute_set(mocked_is_macosx, mock_settings, display_window_env): + """ + Test that on systems other than macOS, the Qt.WA_MacAlwaysShowToolWindow attribute is NOT set + """ + # GIVEN: We're on macOS + mocked_is_macosx.return_value = False + + # WHEN: A DisplayWindow is created + display_window = DisplayWindow() + + # THEN: The attribute is set + assert display_window.testAttribute(QtCore.Qt.WA_MacAlwaysShowToolWindow) is False + + def test_set_scale_not_initialised(display_window_env, mock_settings): """ Test that the scale js is not run if the page is not initialised