From 9945246a5d73773041508e801855f6e3864431e0 Mon Sep 17 00:00:00 2001 From: just-some-entity Date: Sat, 8 Nov 2025 23:36:51 +0100 Subject: [PATCH 1/9] Added support for webview and changed qArgc in launch.cpp from 0 to 1 since webview expects QCoreApplication to atleast have the program name as argument, otherwise aborts leading to a crash in quickshell. --- CMakeLists.txt | 5 +++++ src/launch/CMakeLists.txt | 5 +++++ src/launch/launch.cpp | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 880b9ca3..4b77cd93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ boption(SERVICE_GREETD "Greetd" ON) boption(SERVICE_UPOWER "UPower" ON) boption(SERVICE_NOTIFICATIONS "Notifications" ON) boption(BLUETOOTH "Bluetooth" ON) +boption(WEBVIEW "WebView" ON) include(cmake/install-qml-module.cmake) include(cmake/util.cmake) @@ -127,6 +128,10 @@ if (DBUS) list(APPEND QT_FPDEPS DBus) endif() +if (WEBVIEW) + list(APPEND QT_FPDEPS WebView) +endif() + find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS}) # In Qt 6.10, private dependencies are required to be explicit, diff --git a/src/launch/CMakeLists.txt b/src/launch/CMakeLists.txt index 4db11bf0..358c9791 100644 --- a/src/launch/CMakeLists.txt +++ b/src/launch/CMakeLists.txt @@ -11,6 +11,11 @@ target_link_libraries(quickshell-launch PRIVATE Qt::Quick Qt::Widgets CLI11::CLI11 quickshell-build ) +if(WEBVIEW) + add_compile_definitions(WEBVIEW_ENABLED) + target_link_libraries(quickshell-launch PRIVATE Qt::WebView) +endif() + qs_add_pchset(launch DEPENDENCIES Qt::Core CLI11::CLI11 HEADERS diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index f269f61d..7585717c 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -17,6 +17,10 @@ #include #include +#ifdef WEBVIEW_ENABLED +#include +#endif + #include "../core/common.hpp" #include "../core/instanceinfo.hpp" #include "../core/logging.hpp" @@ -222,7 +226,13 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio delete coreApplication; QGuiApplication* app = nullptr; - auto qArgC = 0; + auto qArgC = 1; + +#ifdef WEBVIEW_ENABLED + if (qEnvironmentVariable("QS_WEBVIEW", "0") == "1") { + QtWebView::initialize(); + } +#endif if (pragmas.useQApplication) { app = new QApplication(qArgC, argv); From 93a6468cfed7ccd50ced8de6f65439c6cc36c804 Mon Sep 17 00:00:00 2001 From: just-some-entity Date: Tue, 11 Nov 2025 09:29:18 +0100 Subject: [PATCH 2/9] Removed compile options for webengine support. Added pragma for loading Qt6WebEngineQuick at runtime --- CMakeLists.txt | 4 ---- src/launch/CMakeLists.txt | 5 ----- src/launch/launch.cpp | 13 +++++-------- src/webengine/webengine.hpp | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 src/webengine/webengine.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b962d94..00d67d14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,10 +129,6 @@ if (DBUS) list(APPEND QT_FPDEPS DBus) endif() -if (WEBVIEW) - list(APPEND QT_FPDEPS WebView) -endif() - find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS}) # In Qt 6.10, private dependencies are required to be explicit, diff --git a/src/launch/CMakeLists.txt b/src/launch/CMakeLists.txt index 358c9791..4db11bf0 100644 --- a/src/launch/CMakeLists.txt +++ b/src/launch/CMakeLists.txt @@ -11,11 +11,6 @@ target_link_libraries(quickshell-launch PRIVATE Qt::Quick Qt::Widgets CLI11::CLI11 quickshell-build ) -if(WEBVIEW) - add_compile_definitions(WEBVIEW_ENABLED) - target_link_libraries(quickshell-launch PRIVATE Qt::WebView) -endif() - qs_add_pchset(launch DEPENDENCIES Qt::Core CLI11::CLI11 HEADERS diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index 7585717c..63aa2ed1 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -17,10 +17,6 @@ #include #include -#ifdef WEBVIEW_ENABLED -#include -#endif - #include "../core/common.hpp" #include "../core/instanceinfo.hpp" #include "../core/logging.hpp" @@ -28,6 +24,7 @@ #include "../core/plugin.hpp" #include "../core/rootwrapper.hpp" #include "../ipc/ipc.hpp" +#include "../webengine/webengine.hpp" #include "build.hpp" #include "launch_p.hpp" @@ -78,6 +75,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio bool nativeTextRendering = false; bool desktopSettingsAware = true; bool useSystemStyle = false; + bool useQtWebEngineQuick = false; QString iconTheme = qEnvironmentVariable("QS_ICON_THEME"); QHash envOverrides; QString dataDir; @@ -95,6 +93,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio else if (pragma == "NativeTextRendering") pragmas.nativeTextRendering = true; else if (pragma == "IgnoreSystemSettings") pragmas.desktopSettingsAware = false; else if (pragma == "RespectSystemStyle") pragmas.useSystemStyle = true; + else if (pragma == "EnableQtWebEngineQuick") pragmas.useQtWebEngineQuick = true; else if (pragma.startsWith("IconTheme ")) pragmas.iconTheme = pragma.sliced(10); else if (pragma.startsWith("Env ")) { auto envPragma = pragma.sliced(4); @@ -228,11 +227,9 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio QGuiApplication* app = nullptr; auto qArgC = 1; -#ifdef WEBVIEW_ENABLED - if (qEnvironmentVariable("QS_WEBVIEW", "0") == "1") { - QtWebView::initialize(); + if(pragmas.useQtWebEngineQuick) { + web_engine::init(); } -#endif if (pragmas.useQApplication) { app = new QApplication(qArgC, argv); diff --git a/src/webengine/webengine.hpp b/src/webengine/webengine.hpp new file mode 100644 index 00000000..2b135022 --- /dev/null +++ b/src/webengine/webengine.hpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +namespace qs::web_engine { + +inline void init() +{ + using InitializeFunc = void (*)(); + + QLibrary lib("Qt6WebEngineQuick"); + if (!lib.load()) { + qWarning() << "Failed to load library:" << lib.errorString(); + qWarning() << "You might need to install the necessary package for Qt6WebEngineQuick."; + qWarning() << "QtWebEngineQuick is not Loaded. Using the qml type WebEngineView from " + "QtWebEngine might lead to undefined behaviour!"; + return; + } + + qDebug() << "Loaded library Qt6WebEngineQuick"; + + auto initialize = reinterpret_cast(lib.resolve("_ZN16QtWebEngineQuick10initializeEv")); + if (!initialize) { + qWarning() << "Failed to resolve symbol 'void QtWebEngineQuick::initialize()' in lib " + "Qt6WebEngineQuick. This should not happen"; + qWarning() << "QtWebEngineQuick is not Loaded. Using the qml type WebEngineView from " + "QtWebEngine might lead to undefined behaviour!"; + return; + } + + qDebug() << "Found symbol QtWebEngineQuick::initialize(). Initializing WebEngine..."; + + initialize(); + + qDebug() << "Successfully initialized QtWebEngineQuick"; +} + +} // namespace qs::web_engine \ No newline at end of file From e78c7e3d2e5a457164586cae500d752c00fc3288 Mon Sep 17 00:00:00 2001 From: just-some-entity Date: Tue, 11 Nov 2025 09:41:40 +0100 Subject: [PATCH 3/9] remove boption for webview in CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00d67d14..c8670013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ boption(SERVICE_GREETD "Greetd" ON) boption(SERVICE_UPOWER "UPower" ON) boption(SERVICE_NOTIFICATIONS "Notifications" ON) boption(BLUETOOTH "Bluetooth" ON) -boption(WEBVIEW "WebView" ON) include(cmake/install-qml-module.cmake) include(cmake/util.cmake) From 8d3ad7d88b66b0cc37adc8420783035ff97c722a Mon Sep 17 00:00:00 2001 From: just-some-entity Date: Tue, 11 Nov 2025 09:51:44 +0100 Subject: [PATCH 4/9] format code with clangd --- src/launch/launch.cpp | 2 +- src/webengine/webengine.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index 63aa2ed1..4c617cc8 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -227,7 +227,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio QGuiApplication* app = nullptr; auto qArgC = 1; - if(pragmas.useQtWebEngineQuick) { + if (pragmas.useQtWebEngineQuick) { web_engine::init(); } diff --git a/src/webengine/webengine.hpp b/src/webengine/webengine.hpp index 2b135022..3cd3aaf1 100644 --- a/src/webengine/webengine.hpp +++ b/src/webengine/webengine.hpp @@ -5,8 +5,7 @@ namespace qs::web_engine { -inline void init() -{ +inline void init() { using InitializeFunc = void (*)(); QLibrary lib("Qt6WebEngineQuick"); @@ -20,7 +19,8 @@ inline void init() qDebug() << "Loaded library Qt6WebEngineQuick"; - auto initialize = reinterpret_cast(lib.resolve("_ZN16QtWebEngineQuick10initializeEv")); + auto initialize = + reinterpret_cast(lib.resolve("_ZN16QtWebEngineQuick10initializeEv")); if (!initialize) { qWarning() << "Failed to resolve symbol 'void QtWebEngineQuick::initialize()' in lib " "Qt6WebEngineQuick. This should not happen"; From 57230c64110535edfccefe7c5d3bb702375f1fd7 Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Sat, 22 Nov 2025 04:18:06 +0100 Subject: [PATCH 5/9] refactor code and add test --- src/webengine/CMakeLists.txt | 3 +++ src/webengine/test/CMakeLists.txt | 3 +++ src/webengine/test/webengine.cpp | 11 +++++++++++ src/webengine/test/webengine.hpp | 8 ++++++++ src/webengine/webengine.hpp | 33 ++++++++++++++++++++++--------- 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/webengine/CMakeLists.txt create mode 100644 src/webengine/test/CMakeLists.txt create mode 100644 src/webengine/test/webengine.cpp create mode 100644 src/webengine/test/webengine.hpp diff --git a/src/webengine/CMakeLists.txt b/src/webengine/CMakeLists.txt new file mode 100644 index 00000000..66f4cd80 --- /dev/null +++ b/src/webengine/CMakeLists.txt @@ -0,0 +1,3 @@ +if (BUILD_TESTING) + add_subdirectory(test) +endif() \ No newline at end of file diff --git a/src/webengine/test/CMakeLists.txt b/src/webengine/test/CMakeLists.txt new file mode 100644 index 00000000..168ec19c --- /dev/null +++ b/src/webengine/test/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(webengine webengine.cpp) +target_link_libraries(webengine PRIVATE Qt::Quick Qt::Test) +add_test(NAME webengine WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMAND $) \ No newline at end of file diff --git a/src/webengine/test/webengine.cpp b/src/webengine/test/webengine.cpp new file mode 100644 index 00000000..b60cd2d5 --- /dev/null +++ b/src/webengine/test/webengine.cpp @@ -0,0 +1,11 @@ +#include "webengine.hpp" + +#include + +#include "../webengine.hpp" + +void WebEngineInitTest::initDoesNotCrash() { + QVERIFY(qs::web_engine::init()); +} + +QTEST_MAIN(WebEngineInitTest) \ No newline at end of file diff --git a/src/webengine/test/webengine.hpp b/src/webengine/test/webengine.hpp new file mode 100644 index 00000000..9d70a9b0 --- /dev/null +++ b/src/webengine/test/webengine.hpp @@ -0,0 +1,8 @@ +#include + +class WebEngineInitTest: public QObject { + Q_OBJECT + +private slots: + void initDoesNotCrash(); +}; diff --git a/src/webengine/webengine.hpp b/src/webengine/webengine.hpp index 3cd3aaf1..5b932c62 100644 --- a/src/webengine/webengine.hpp +++ b/src/webengine/webengine.hpp @@ -5,16 +5,20 @@ namespace qs::web_engine { -inline void init() { +inline void printNotLoaded() { + qWarning() << "QtWebEngineQuick is not Loaded. Using the qml type WebEngineView from " + "QtWebEngine might lead to undefined behaviour!"; +} + +inline bool init() { using InitializeFunc = void (*)(); QLibrary lib("Qt6WebEngineQuick"); if (!lib.load()) { qWarning() << "Failed to load library:" << lib.errorString(); qWarning() << "You might need to install the necessary package for Qt6WebEngineQuick."; - qWarning() << "QtWebEngineQuick is not Loaded. Using the qml type WebEngineView from " - "QtWebEngine might lead to undefined behaviour!"; - return; + printNotLoaded(); + return false; } qDebug() << "Loaded library Qt6WebEngineQuick"; @@ -24,16 +28,27 @@ inline void init() { if (!initialize) { qWarning() << "Failed to resolve symbol 'void QtWebEngineQuick::initialize()' in lib " "Qt6WebEngineQuick. This should not happen"; - qWarning() << "QtWebEngineQuick is not Loaded. Using the qml type WebEngineView from " - "QtWebEngine might lead to undefined behaviour!"; - return; + + printNotLoaded(); + return false; } qDebug() << "Found symbol QtWebEngineQuick::initialize(). Initializing WebEngine..."; - initialize(); + try { + initialize(); + qDebug() << "Successfully initialized QtWebEngineQuick"; + } catch (const std::exception& e) { + qWarning() << "Exception while calling QtWebEngineQuick::initialize()" << e.what(); + printNotLoaded(); + return false; + } catch (...) { + qWarning() << "Unknown Exception while calling QtWebEngineQuick::initialize()"; + printNotLoaded(); + return false; + } - qDebug() << "Successfully initialized QtWebEngineQuick"; + return true; } } // namespace qs::web_engine \ No newline at end of file From 3f1a402d9c9fd3684c714a5995a94e4c5c0ac4d0 Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Sat, 22 Nov 2025 04:28:11 +0100 Subject: [PATCH 6/9] add webengine subdirectory to cmake --- src/CMakeLists.txt | 2 ++ src/webengine/test/webengine.cpp | 2 +- src/webengine/test/webengine.hpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52db00a5..1e2c0b4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,3 +33,5 @@ add_subdirectory(services) if (BLUETOOTH) add_subdirectory(bluetooth) endif() + +add_subdirectory(webengine) \ No newline at end of file diff --git a/src/webengine/test/webengine.cpp b/src/webengine/test/webengine.cpp index b60cd2d5..9e6aca51 100644 --- a/src/webengine/test/webengine.cpp +++ b/src/webengine/test/webengine.cpp @@ -4,7 +4,7 @@ #include "../webengine.hpp" -void WebEngineInitTest::initDoesNotCrash() { +void WebEngineInitTest::init() { QVERIFY(qs::web_engine::init()); } diff --git a/src/webengine/test/webengine.hpp b/src/webengine/test/webengine.hpp index 9d70a9b0..35ced147 100644 --- a/src/webengine/test/webengine.hpp +++ b/src/webengine/test/webengine.hpp @@ -4,5 +4,5 @@ class WebEngineInitTest: public QObject { Q_OBJECT private slots: - void initDoesNotCrash(); + void init(); }; From fccf4146c3d72eac31fc400c0bc6aa5385e299fd Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Sat, 22 Nov 2025 05:42:38 +0100 Subject: [PATCH 7/9] fix includes and make test function static --- src/webengine/test/CMakeLists.txt | 2 +- src/webengine/test/webengine.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webengine/test/CMakeLists.txt b/src/webengine/test/CMakeLists.txt index 168ec19c..1d0c7769 100644 --- a/src/webengine/test/CMakeLists.txt +++ b/src/webengine/test/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(webengine webengine.cpp) -target_link_libraries(webengine PRIVATE Qt::Quick Qt::Test) +target_link_libraries(webengine PRIVATE Qt::Core Qt::Test) add_test(NAME webengine WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMAND $) \ No newline at end of file diff --git a/src/webengine/test/webengine.hpp b/src/webengine/test/webengine.hpp index 35ced147..1e29063f 100644 --- a/src/webengine/test/webengine.hpp +++ b/src/webengine/test/webengine.hpp @@ -1,8 +1,8 @@ -#include +#include class WebEngineInitTest: public QObject { Q_OBJECT private slots: - void init(); + static void init(); }; From a4b4ca2ce9065b74e7467cd11dadb35360156bc2 Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Sat, 22 Nov 2025 05:44:00 +0100 Subject: [PATCH 8/9] format with clangd-format --- src/webengine/test/webengine.cpp | 4 +--- src/webengine/test/webengine.hpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/webengine/test/webengine.cpp b/src/webengine/test/webengine.cpp index 9e6aca51..ceabc466 100644 --- a/src/webengine/test/webengine.cpp +++ b/src/webengine/test/webengine.cpp @@ -4,8 +4,6 @@ #include "../webengine.hpp" -void WebEngineInitTest::init() { - QVERIFY(qs::web_engine::init()); -} +void WebEngineInitTest::init() { QVERIFY(qs::web_engine::init()); } QTEST_MAIN(WebEngineInitTest) \ No newline at end of file diff --git a/src/webengine/test/webengine.hpp b/src/webengine/test/webengine.hpp index 1e29063f..458e344c 100644 --- a/src/webengine/test/webengine.hpp +++ b/src/webengine/test/webengine.hpp @@ -5,4 +5,4 @@ class WebEngineInitTest: public QObject { private slots: static void init(); -}; +}; \ No newline at end of file From d80391cd5daf4a650d88c0dc8753b584553089bf Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Sat, 22 Nov 2025 06:37:13 +0100 Subject: [PATCH 9/9] add header qtestcase.h to fix linter error --- src/webengine/test/webengine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webengine/test/webengine.cpp b/src/webengine/test/webengine.cpp index ceabc466..aa726a60 100644 --- a/src/webengine/test/webengine.cpp +++ b/src/webengine/test/webengine.cpp @@ -1,6 +1,7 @@ #include "webengine.hpp" #include +#include #include "../webengine.hpp"