From 4dcdc3bd25def54d5411e34aa1da7ead3ef6c3eb Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 26 Apr 2023 16:46:55 -0400 Subject: Ladybird: Prohibit GUI interaction of the WebContent process on macOS The WebContent process behaves a bit awkwardly on macOS. When we launch the process, we have to create a QGuiApplication to access system fonts. But on macOS, doing so creates an entry in the Dock, and also causes the WebContent to be focused. So if you enter cmd+Q without first focusing the Ladybird GUI, WebContent is closed, while the Ladybird process keeps running. --- Ladybird/WebContent/CMakeLists.txt | 4 ++++ Ladybird/WebContent/MacOSSetup.h | 9 +++++++++ Ladybird/WebContent/MacOSSetup.mm | 15 +++++++++++++++ Ladybird/WebContent/main.cpp | 9 +++++++++ 4 files changed, 37 insertions(+) create mode 100644 Ladybird/WebContent/MacOSSetup.h create mode 100644 Ladybird/WebContent/MacOSSetup.mm (limited to 'Ladybird/WebContent') diff --git a/Ladybird/WebContent/CMakeLists.txt b/Ladybird/WebContent/CMakeLists.txt index d8c9c1b780..71c28a143e 100644 --- a/Ladybird/WebContent/CMakeLists.txt +++ b/Ladybird/WebContent/CMakeLists.txt @@ -17,6 +17,10 @@ set(WEBCONTENT_SOURCES main.cpp ) +if (APPLE) + list(APPEND WEBCONTENT_SOURCES MacOSSetup.mm) +endif() + qt_add_executable(WebContent ${WEBCONTENT_SOURCES}) target_include_directories(WebContent PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services/) diff --git a/Ladybird/WebContent/MacOSSetup.h b/Ladybird/WebContent/MacOSSetup.h new file mode 100644 index 0000000000..6125379158 --- /dev/null +++ b/Ladybird/WebContent/MacOSSetup.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +void prohibit_interaction(); diff --git a/Ladybird/WebContent/MacOSSetup.mm b/Ladybird/WebContent/MacOSSetup.mm new file mode 100644 index 0000000000..e323c58adf --- /dev/null +++ b/Ladybird/WebContent/MacOSSetup.mm @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "MacOSSetup.h" +#import + +void prohibit_interaction() +{ + // This prevents WebContent from being displayed in the macOS Dock and becoming the focused, + // interactable application upon launch. + [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited]; +} diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 9b805652cc..b715203079 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -11,6 +11,7 @@ #include "../Utilities.h" #include "../WebSocketClientManagerLadybird.h" #include +#include #include #include #include @@ -31,6 +32,10 @@ #include #include +#if defined(AK_OS_MACOS) +# include "MacOSSetup.h" +#endif + static ErrorOr load_content_filters(); static ErrorOr load_autoplay_allowlist(); @@ -40,6 +45,10 @@ ErrorOr serenity_main(Main::Arguments arguments) { QGuiApplication app(arguments.argc, arguments.argv); +#if defined(AK_OS_MACOS) + prohibit_interaction(); +#endif + Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt); Core::EventLoop event_loop; -- cgit v1.2.3