diff --git a/plugins/polkit/.clang-format b/plugins/polkit/.clang-format new file mode 100644 index 0000000..cf5ff2c --- /dev/null +++ b/plugins/polkit/.clang-format @@ -0,0 +1,88 @@ +--- +# SPDX-FileCopyrightText: 2019 Christoph Cullmann +# SPDX-FileCopyrightText: 2019 Gernot Gebhard +# +# SPDX-License-Identifier: MIT + +# This file got automatically created by ECM, do not edit +# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the config options +# and https://community.kde.org/Policies/Frameworks_Coding_Style#Clang-format_automatic_code_formatting +# for clang-format tips & tricks +--- +Language: JavaScript +DisableFormat: true +--- + +# Style for C++ +Language: Cpp + +# base is WebKit coding style: https://webkit.org/code-style-guidelines/ +# below are only things set that diverge from this style! +BasedOnStyle: WebKit + +# enforce C++11 (e.g. for std::vector> +Standard: Cpp11 + +# 4 spaces indent +TabWidth: 4 + +# 2 * 80 wide lines +ColumnLimit: 160 + +# sort includes inside line separated groups +SortIncludes: true + +# break before braces on function, namespace and class definitions. +BreakBeforeBraces: Linux + +# CrlInstruction *a; +PointerAlignment: Right + +# horizontally aligns arguments after an open bracket. +AlignAfterOpenBracket: Align + +# don't move all parameters to new line +AllowAllParametersOfDeclarationOnNextLine: false + +# no single line functions +AllowShortFunctionsOnASingleLine: None + +# always break before you encounter multi line strings +AlwaysBreakBeforeMultilineStrings: true + +# don't move arguments to own lines if they are not all on the same +BinPackArguments: false + +# don't move parameters to own lines if they are not all on the same +BinPackParameters: false + +# In case we have an if statement with multiple lines the operator should be at the beginning of the line +# but we do not want to break assignments +BreakBeforeBinaryOperators: NonAssignment + +# format C++11 braced lists like function calls +Cpp11BracedListStyle: true + +# do not put a space before C++11 braced lists +SpaceBeforeCpp11BracedList: false + +# remove empty lines +KeepEmptyLinesAtTheStartOfBlocks: false + +# no namespace indentation to keep indent level low +NamespaceIndentation: None + +# we use template< without space. +SpaceAfterTemplateKeyword: false + +# Always break after template declaration +AlwaysBreakTemplateDeclarations: true + +# macros for which the opening brace stays attached. +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE , wl_resource_for_each, wl_resource_for_each_safe ] + +# keep lambda formatting multi-line if not empty +AllowShortLambdasOnASingleLine: Empty + +# We do not want clang-format to put all arguments on a new line +AllowAllArgumentsOnNextLine: false diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 0000000..cf5ff2c --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,88 @@ +--- +# SPDX-FileCopyrightText: 2019 Christoph Cullmann +# SPDX-FileCopyrightText: 2019 Gernot Gebhard +# +# SPDX-License-Identifier: MIT + +# This file got automatically created by ECM, do not edit +# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the config options +# and https://community.kde.org/Policies/Frameworks_Coding_Style#Clang-format_automatic_code_formatting +# for clang-format tips & tricks +--- +Language: JavaScript +DisableFormat: true +--- + +# Style for C++ +Language: Cpp + +# base is WebKit coding style: https://webkit.org/code-style-guidelines/ +# below are only things set that diverge from this style! +BasedOnStyle: WebKit + +# enforce C++11 (e.g. for std::vector> +Standard: Cpp11 + +# 4 spaces indent +TabWidth: 4 + +# 2 * 80 wide lines +ColumnLimit: 160 + +# sort includes inside line separated groups +SortIncludes: true + +# break before braces on function, namespace and class definitions. +BreakBeforeBraces: Linux + +# CrlInstruction *a; +PointerAlignment: Right + +# horizontally aligns arguments after an open bracket. +AlignAfterOpenBracket: Align + +# don't move all parameters to new line +AllowAllParametersOfDeclarationOnNextLine: false + +# no single line functions +AllowShortFunctionsOnASingleLine: None + +# always break before you encounter multi line strings +AlwaysBreakBeforeMultilineStrings: true + +# don't move arguments to own lines if they are not all on the same +BinPackArguments: false + +# don't move parameters to own lines if they are not all on the same +BinPackParameters: false + +# In case we have an if statement with multiple lines the operator should be at the beginning of the line +# but we do not want to break assignments +BreakBeforeBinaryOperators: NonAssignment + +# format C++11 braced lists like function calls +Cpp11BracedListStyle: true + +# do not put a space before C++11 braced lists +SpaceBeforeCpp11BracedList: false + +# remove empty lines +KeepEmptyLinesAtTheStartOfBlocks: false + +# no namespace indentation to keep indent level low +NamespaceIndentation: None + +# we use template< without space. +SpaceAfterTemplateKeyword: false + +# Always break after template declaration +AlwaysBreakTemplateDeclarations: true + +# macros for which the opening brace stays attached. +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE , wl_resource_for_each, wl_resource_for_each_safe ] + +# keep lambda formatting multi-line if not empty +AllowShortLambdasOnASingleLine: Empty + +# We do not want clang-format to put all arguments on a new line +AllowAllArgumentsOnNextLine: false diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 682132f..e6d0855 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,9 +7,7 @@ include(CMakePackageConfigHelpers) include(ECMGenerateHeaders) include(ECMFindQmlModule) include(ECMQmlModule) -include(ECMGenerateQmlTypes) -include(KDEClangFormat) include(KDEInstallDirs) include(KDECMakeSettings) @@ -35,6 +33,7 @@ include_directories( set(cask_SRCS main.cpp + caskapp.cpp code/models/zpacesmodel.cpp code/models/surfacesmodel.cpp code/controllers/zpaces.cpp diff --git a/src/caskapp.cpp b/src/caskapp.cpp new file mode 100644 index 0000000..1faacca --- /dev/null +++ b/src/caskapp.cpp @@ -0,0 +1,256 @@ +#include "caskapp.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "code/controllers/zpaces.h" +#include "code/controllers/zpace.h" +#include "code/models/zpacesmodel.h" +#include "code/models/surfacesmodel.h" +#include "code/models/tasksmodel.h" +#include "code/controllers/task.h" +#include "code/controllers/xdgwindow.h" +#include "code/controllers/waylandcursorgrabber.h" + +#define ZPACES_URI "Zpaces" + +static const QEvent::Type StartupEventType = static_cast(QEvent::registerEventType()); + +static int convertPermission(const QFileInfo &fileInfo) +{ + int p = 0; + + if (fileInfo.permission(QFile::ReadUser)) + p += 400; + if (fileInfo.permission(QFile::WriteUser)) + p += 200; + if (fileInfo.permission(QFile::ExeUser)) + p += 100; + if (fileInfo.permission(QFile::ReadGroup)) + p += 40; + if (fileInfo.permission(QFile::WriteGroup)) + p += 20; + if (fileInfo.permission(QFile::ExeGroup)) + p += 10; + if (fileInfo.permission(QFile::ReadOther)) + p += 4; + if (fileInfo.permission(QFile::WriteOther)) + p += 2; + if (fileInfo.permission(QFile::ExeOther)) + p += 1; + + return p; +} + +static void registerTypes() +{ + qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "Zpace", QStringLiteral("Use it from a reference from Zpaces object")); + qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "Task", QStringLiteral("Use it from Zpaces::TasksModel.task object")); + qmlRegisterAnonymousType(ZPACES_URI, 1); + qmlRegisterAnonymousType(ZPACES_URI, 1); + qmlRegisterAnonymousType(ZPACES_URI, 1); + qmlRegisterAnonymousType(ZPACES_URI, 1); + qmlRegisterType(ZPACES_URI, 1, 0, "Zpaces"); + qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "XdgWindow", QStringLiteral("Create it from Zpaces::createXdgWIndow")); + qmlRegisterType(ZPACES_URI, 1, 0, "WaylandCursorGrabber"); +} + + +CaskApp::CaskApp(QObject *parent) : QObject(parent) + , m_failSafe(false) + , m_started(false) + , m_windowed(false) +{ + m_screens = QGuiApplication::screens(); + registerTypes(); + + // Application engine + m_appEngine = new QQmlApplicationEngine(this); + connect(m_appEngine, &QQmlApplicationEngine::objectCreated, this, &CaskApp::objectCreated); + + // Invoke shutdown sequence when quitting + connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CaskApp::shutdown); +} + +void CaskApp::setUrl(const QUrl &url) +{ + m_url = url; +} + +void CaskApp::setWindowed(bool value) +{ + m_windowed = value; +} + +bool CaskApp::setScreens(const QStringList &scrNames) +{ + QList keepers; + for (QScreen *scr : m_screens) + { + if (scrNames.contains(scr->name(), Qt::CaseInsensitive)) + { + keepers << scr; + } + } + + if (keepers.isEmpty()) + { + qWarning() << "None of the screens" << scrNames << "exist; available screens:"; + for (QScreen *scr : m_screens) + { + qWarning() << " " << scr->name() << scr->geometry(); + } + return false; + } + m_screens = keepers; + + return true; +} + +void CaskApp::customEvent(QEvent *event) +{ + if (event->type() == StartupEventType) + startup(); +} + +void CaskApp::verifyXdgRuntimeDir() +{ + QString dirName = QString::fromLocal8Bit(qgetenv("XDG_RUNTIME_DIR")); + + if (dirName.isEmpty()) { + QString msg = QObject::tr( + "The XDG_RUNTIME_DIR environment variable is not set.\n" + "Refer to your distribution on how to get it, or read\n" + "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" + "on how to implement it.\n"); + qFatal("%s", qPrintable(msg)); + } + + QFileInfo fileInfo(dirName); + + if (!fileInfo.exists()) { + QString msg = QObject::tr( + "The XDG_RUNTIME_DIR environment variable is set to " + "\"%1\", which doesn't exist.\n").arg(dirName.constData()); + qFatal("%s", qPrintable(msg)); + } + + if (convertPermission(fileInfo) != 700 || fileInfo.ownerId() != getuid()) { + QString msg = QObject::tr( + "XDG_RUNTIME_DIR is set to \"%1\" and is not configured correctly.\n" + "Unix access mode must be 0700, but is 0%2.\n" + "It must also be owned by the current user (UID %3), " + "but is owned by UID %4 (\"%5\").\n") + .arg(dirName.constData()) + .arg(convertPermission(fileInfo)) + .arg(getuid()) + .arg(fileInfo.ownerId()) + .arg(fileInfo.owner()); + qFatal("%s\n", qPrintable(msg)); + } +} + +void CaskApp::startup() +{ + // Can't do the startup sequence twice + if (m_started) + return; + + // Check whether XDG_RUNTIME_DIR is ok or not + verifyXdgRuntimeDir(); + + // // Session interface + // m_appEngine->rootContext()->setContextProperty(QStringLiteral("SessionInterface"), + // m_sessionManager); + + m_appEngine->rootContext()->setContextObject(new KLocalizedContext(m_appEngine)); + + + qunsetenv("QT_SCALE_FACTOR"); + + qputenv("QT_QPA_PLATFORM", "wayland"); // not for cask but for child processes + qputenv("GDK_BACKEND", "wayland"); // not for cask but for child processes + qputenv("MOZ_ENABLE_WAYLAND", "1"); + + // Load the compositor + m_appEngine->load(m_url); + + m_started = true; +} + +void CaskApp::shutdown() +{ + m_appEngine->deleteLater(); + m_appEngine = nullptr; + + // m_sessionManager->deleteLater(); + // m_sessionManager = nullptr; +} + +void CaskApp::objectCreated(QObject *object, const QUrl &) +{ + // All went fine + if (object) + { + + for(const auto &screen : m_screens) + { + qWarning() << screen->devicePixelRatio() << screen->logicalDotsPerInch()<< screen->physicalDotsPerInch() << screen->availableGeometry() << screen->availableSize() <availableVirtualSize(); + } + + QObject *root = m_appEngine->rootObjects().first(); + + QList windows = root->findChildren(); + auto windowIter = windows.begin(); + auto screenIter = m_screens.begin(); + while (windowIter != windows.end() && screenIter != m_screens.end()) + { + QWindow * window = *windowIter; + QScreen * screen = *screenIter; + window->setScreen(screen); + + if (m_windowed) + { + window->showNormal(); + } else + { + window->setGeometry(screen->geometry()); + window->showFullScreen(); + } + ++windowIter; + ++screenIter; + } + return; + } + + // Compositor failed to load + if (m_failSafe) { + // We give up because even the error screen has an error + qWarning("A fatal error has occurred while running Liri Shell, but the error " + "screen has errors too. Giving up."); + QCoreApplication::exit(1); + } else { + // Load the error screen in case of error + m_failSafe = true; + m_appEngine->load(QUrl(QStringLiteral("qrc:/qt/qml/compositor/qml/error/ErrorCompositor.qml"))); + } +} + +StartupEvent::StartupEvent() + : QEvent(StartupEventType) +{ +} diff --git a/src/caskapp.h b/src/caskapp.h new file mode 100644 index 0000000..4450a0b --- /dev/null +++ b/src/caskapp.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include +#include + + +QT_FORWARD_DECLARE_CLASS(QQmlApplicationEngine) + +class CaskApp : public QObject +{ + Q_OBJECT + +public: + explicit CaskApp(QObject *parent = nullptr); + + void setUrl(const QUrl &url); + void setWindowed(bool); + bool setScreens(const QStringList &values); + +protected: + void customEvent(QEvent *event) override; + +private: + QUrl m_url; + QQmlApplicationEngine *m_appEngine; + + bool m_failSafe; + bool m_started; + bool m_windowed; + QList m_screens; + + void verifyXdgRuntimeDir(); + +private Q_SLOTS: + void startup(); + void shutdown(); + void objectCreated(QObject *object, const QUrl &); +}; + +class StartupEvent : public QEvent +{ +public: + StartupEvent(); +}; diff --git a/src/main.cpp b/src/main.cpp index dba5029..f06861c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,19 +47,10 @@ #include -//models and controllers by Cask -#include "code/controllers/zpaces.h" -#include "code/controllers/zpace.h" -#include "code/models/zpacesmodel.h" -#include "code/models/surfacesmodel.h" -#include "code/models/tasksmodel.h" -#include "code/controllers/task.h" -#include "code/controllers/xdgwindow.h" -#include "code/controllers/waylandcursorgrabber.h" - #include #include "../cask_version.h" +#include "caskapp.h" #include #include @@ -77,7 +68,7 @@ static QElapsedTimer sinceStartup; extern "C" void signalHandler(int signal) { #ifdef Q_WS_X11 - // Kill window since it's frozen anyway. + // Kill window since it's frozen anyway. if (QX11Info::display()) close(ConnectionNumber(QX11Info::display())); #endif @@ -115,7 +106,7 @@ static void setupSignalHandler() return; } - // Install signal handler. + // Install signal handler. struct sigaction sa; if (sigemptyset(&sa.sa_mask) == -1) { qWarning("Warning: Failed to empty signal set (%s).", Q_FUNC_INFO); @@ -172,7 +163,7 @@ void qtMsgLog(QtMsgType type, const QMessageLogContext &context, const QString & abort(); } -static qreal highestDPR(QList &screens) +static qreal highestDPR(QList screens) { qreal ret = 0; for (const QScreen *scr : screens) { @@ -189,57 +180,46 @@ void sigintHandler(int signalNumber) qDebug() << "terminating cask session" << signalNumber; } - -static void registerTypes() -{ - qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "Zpace", QStringLiteral("Use it from a reference from Zpaces object")); - qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "Task", QStringLiteral("Use it from Zpaces::TasksModel.task object")); - qmlRegisterAnonymousType(ZPACES_URI, 1); - qmlRegisterAnonymousType(ZPACES_URI, 1); - qmlRegisterAnonymousType(ZPACES_URI, 1); - qmlRegisterAnonymousType(ZPACES_URI, 1); - qmlRegisterType(ZPACES_URI, 1, 0, "Zpaces"); - qmlRegisterUncreatableType(ZPACES_URI, 1, 0, "XdgWindow", QStringLiteral("Create it from Zpaces::createXdgWIndow")); - // qmlRegisterType(ZPACES_URI, 1, 0, "WaylandCursorGrabber"); -} - -int main(int argc, char *argv[]) +static void setupEnviroment() { - sinceStartup.start(); - if (!qEnvironmentVariableIsSet("QT_XCB_GL_INTEGRATION")) qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); // use xcomposite-glx if no EGL - // if (!qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_WINDOWDECORATION")) - // qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); + // if (!qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_WINDOWDECORATION")) + // qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1"); if (!qEnvironmentVariableIsSet("QT_LABS_CONTROLS_STYLE")) qputenv("QT_LABS_CONTROLS_STYLE", "Universal"); - // if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE")) - // qputenv("QT_QUICK_CONTROLS_STYLE", "maui-style"); + // if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE")) + // qputenv("QT_QUICK_CONTROLS_STYLE", "maui-style"); if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME")) qputenv("QT_QPA_PLATFORMTHEME", "maui"); - // if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) - // qputenv("QT_QUICK_CONTROLS_MOBILE", "1"); - - - // ShareOpenGLContexts is needed for using the threaded renderer - // on NVIDIA EGLStreams and multi output compositors in general - // (see QTBUG-63039 and QTBUG-87597) - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); - - + // if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) + // qputenv("QT_QUICK_CONTROLS_MOBILE", "1"); qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); - // qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); + // qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); { MauiMan::ScreenManager screenManager; qputenv("QT_SCALE_FACTOR", QByteArray::number(screenManager.scaleFactor())); } + +} + +int main(int argc, char *argv[]) +{ + sinceStartup.start(); + + setupEnviroment(); + // ShareOpenGLContexts is needed for using the threaded renderer + // on NVIDIA EGLStreams and multi output compositors in general + // (see QTBUG-63039 and QTBUG-87597) + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + QGuiApplication app(argc, argv); app.setOrganizationName(QStringLiteral("Maui")); app.setWindowIcon(QIcon(QStringLiteral("qrc:/mauikit-logo.png"))); @@ -252,13 +232,13 @@ int main(int argc, char *argv[]) QStringLiteral(CASK_VERSION_STRING), i18n("Convergent shell for desktop and mobile computers."), KAboutLicense::LGPL_V3, - i18n("© 2021-%1 Maui Development Team", QString::number(QDate::currentDate().year())), + QStringLiteral("© 2021-2024 Maui Development Team"), QString(QStringLiteral(GIT_BRANCH) + QStringLiteral("/") + QStringLiteral(GIT_COMMIT_HASH))); - about.addAuthor(i18n("Camilo Higuita"), i18n("Developer"), QStringLiteral("milo.h@aol.com")); + about.addAuthor(QStringLiteral("Camilo Higuita"), i18n("Developer"), QStringLiteral("milo.h@aol.com")); about.setHomepage(QStringLiteral("https://mauikit.org")); about.setProductName("maui/cask"); - about.setBugAddress("https://invent.kde.org/maui/vvave/-/issues"); + about.setBugAddress("https://github.com/Nitrux/maui-shell/issues/new/choose"); about.setOrganizationDomain(CASK_URI); about.setProgramLogo(app.windowIcon()); @@ -267,44 +247,31 @@ int main(int argc, char *argv[]) KAboutData::setApplicationData(about); - // if(MauiManUtils::isMauiSession()) - // { - //auto themeSettings = std::make_unique(); - - // QIcon::setThemeName(themeSettings->iconTheme()); - // } + if(MauiManUtils::isMauiSession()) + { + MauiMan::ThemeManager themeSettings; + QIcon::setThemeName(themeSettings.iconTheme()); + } signal(SIGINT, sigintHandler); signal(SIGTSTP, sigintHandler); app.setQuitOnLastWindowClosed(false); - // QGuiApplication::setFallbackSessionManagementEnabled(false); - auto disableSessionManagement = [](QSessionManager &sm) { - sm.setRestartHint(QSessionManager::RestartNever); - }; - // auto power = new CaskPower(); - // QObject::connect(power, &CaskPower::logoutRequested, [&app, power]() - // { - // power->deleteLater(); - // app.quit(); - // }); - QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); - QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); + // auto power = new CaskPower(); + // QObject::connect(power, &CaskPower::logoutRequested, [&app, power]() + // { + // power->deleteLater(); + // app.quit(); + // }); + QQuickStyle::setStyle(QStringLiteral("QtQuick.Controls.Maui")); caskExecutablePath = app.applicationFilePath().toLocal8Bit(); caskPID = QCoreApplication::applicationPid(); - bool windowed = false; - QList screens = QGuiApplication::screens(); - - for(const auto &screen : screens) - { - qWarning() << screen->devicePixelRatio() << screen->logicalDotsPerInch()<< screen->physicalDotsPerInch() << screen->availableGeometry() << screen->availableSize() <availableVirtualSize(); - } QCommandLineParser parser; about.setupCommandLine(&parser); @@ -343,37 +310,10 @@ int main(int argc, char *argv[]) qInstallMessageHandler(qtMsgLog); } - if (parser.isSet(screenOption)) - { - QStringList scrNames = parser.values(screenOption); - QList keepers; - for (QScreen *scr : screens) - { - if (scrNames.contains(scr->name(), Qt::CaseInsensitive)) - { - keepers << scr; - } - } - - if (keepers.isEmpty()) - { - qWarning() << "None of the screens" << scrNames << "exist; available screens:"; - for (QScreen *scr : screens) - { - qWarning() << " " << scr->name() << scr->geometry(); - } - return -1; - } - screens = keepers; - } - - if (parser.isSet(windowOption)) - windowed = true; - - qreal dpr = highestDPR(screens); - if (!qEnvironmentVariableIsSet("XCURSOR_SIZE")) { + qreal dpr = highestDPR(QGuiApplication::screens()); + // QTBUG-67579: we can't have different cursor sizes on different screens // or different windows yet, but we can override globally int cursorSize = int(32 * dpr); @@ -381,49 +321,22 @@ int main(int argc, char *argv[]) qputenv("XCURSOR_SIZE", QByteArray::number(cursorSize)); } - registerTypes(); + auto shell = new CaskApp(); - QQmlApplicationEngine engine; - const QUrl url(u"qrc:qt/qml/org/cask/shell/qml/main.qml"_qs); - - QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, - &app, [url](QObject *obj, const QUrl &objUrl) { - if (!obj && url == objUrl) - QCoreApplication::exit(-1); - }, Qt::QueuedConnection); - - engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); - - - engine.load(url); - - qunsetenv("QT_SCALE_FACTOR"); - qputenv("QT_QPA_PLATFORM", "wayland"); // not for cask but for child processes - qputenv("GDK_BACKEND", "wayland"); // not for cask but for child processes - qputenv("MOZ_ENABLE_WAYLAND", "1"); - - QObject *root = engine.rootObjects().first(); + if (parser.isSet(screenOption)) + { + shell->setScreens(parser.values(screenOption)); + } - QList windows = root->findChildren(); - auto windowIter = windows.begin(); - auto screenIter = screens.begin(); - while (windowIter != windows.end() && screenIter != screens.end()) + if (parser.isSet(windowOption)) { - QWindow * window = *windowIter; - QScreen * screen = *screenIter; - window->setScreen(screen); - - if (windowed) - { - window->showNormal(); - } else - { - window->setGeometry(screen->geometry()); - window->showFullScreen(); - } - ++windowIter; - ++screenIter; + shell->setWindowed("true"); } + const QUrl url(u"qrc:qt/qml/org/cask/shell/qml/main.qml"_qs); + shell->setUrl(url); + + QCoreApplication::postEvent(shell, new StartupEvent()); + return app.exec(); } diff --git a/src/startcask.cpp b/src/startcask.cpp index 131de8a..8aaeed2 100644 --- a/src/startcask.cpp +++ b/src/startcask.cpp @@ -6,32 +6,32 @@ #include int runCommandSync(QString command, QStringList args) { -// QProcess process; + // QProcess process; -// process.start(command, args); -// process.waitForFinished(); + // process.start(command, args); + // process.waitForFinished(); -// qDebug() << process.readAllStandardError(); + // qDebug() << process.readAllStandardError(); - QProcess p; - p.setEnvironment(QProcess::systemEnvironment()); - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.start(command, args); - // qCDebug(PLASMA_STARTUP) << "started..." << program << args; - p.waitForFinished(-1); - if (p.exitCode()) { - qWarning() << command << args << "exited with code" << p.exitCode(); - } - qWarning() << "STARTCASK FINISHED" << p.exitStatus() << p.exitCode(); - return p.exitCode(); + QProcess p; + p.setEnvironment(QProcess::systemEnvironment()); + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.start(command, args); + // qCDebug(PLASMA_STARTUP) << "started..." << program << args; + p.waitForFinished(-1); + if (p.exitCode()) { + qWarning() << command << args << "exited with code" << p.exitCode(); + } + qWarning() << "STARTCASK FINISHED" << p.exitStatus() << p.exitCode(); + return p.exitCode(); -// QFile log("home/camilo/mauilog.txt"); - //// log.open(QFile::WriteOnly | QFile::Text); - // log.write(process.readAll()); - // log.close(); -// return process.exitCode(); + // QFile log("home/camilo/mauilog.txt"); + //// log.open(QFile::WriteOnly | QFile::Text); + // log.write(process.readAll()); + // log.close(); + // return process.exitCode(); } @@ -42,8 +42,8 @@ bool isShellVariable(const QByteArray &name) { bool isSessionVariable(const QByteArray &name) { // Check is variable is specific to session. return name == "DISPLAY" || name == "XAUTHORITY" || - name == "WAYLAND_DISPLAY" || name == "WAYLAND_SOCKET" || - name.startsWith("XDG_"); + name == "WAYLAND_DISPLAY" || name == "WAYLAND_SOCKET" || + name.startsWith("XDG_"); } @@ -65,7 +65,7 @@ void sourceFiles(const QStringList &files) if (filteredFiles.isEmpty()) return; -// filteredFiles.prepend(QStringLiteral(CMAKE_INSTALL_FULL_LIBEXECDIR "/plasma-sourceenv.sh")); + // filteredFiles.prepend(QStringLiteral(CMAKE_INSTALL_FULL_LIBEXECDIR "/plasma-sourceenv.sh")); QProcess p; p.start(QStringLiteral("/bin/sh"), filteredFiles); @@ -95,8 +95,8 @@ void runEnvironmentScripts() QStringList scripts; auto locations = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation); - //`standardLocations()` returns locations sorted by "order of priority". We iterate in reverse - // order so that high-priority scripts are sourced last and their modifications take precedence. + //`standardLocations()` returns locations sorted by "order of priority". We iterate in reverse + // order so that high-priority scripts are sourced last and their modifications take precedence. for (auto loc = locations.crbegin(); loc != locations.crend(); loc++) { QDir dir(*loc); if (!dir.cd(QStringLiteral("./plasma-workspace/env"))) { @@ -114,65 +114,65 @@ void runEnvironmentScripts() int main() { - qputenv("QT_QPA_PLATFORM", "eglfs"); + qputenv("QT_QPA_PLATFORM", "eglfs"); -// qputenv("QT_QPA_EGLFS_NO_LIBINPUT", "1"); -// qputenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS", "grab=1"); -// qputenv("QT_QPA_EVDEV_MOUSE_PARAMETERS", "grab=1"); + // qputenv("QT_QPA_EGLFS_NO_LIBINPUT", "1"); + // qputenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS", "grab=1"); + // qputenv("QT_QPA_EVDEV_MOUSE_PARAMETERS", "grab=1"); -// qputenv("QT_QPA_EGLFS_DISABLE_INPUT", "1"); -// qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); - qputenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION", "wayland-egl"); + // qputenv("QT_QPA_EGLFS_DISABLE_INPUT", "1"); + // qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); + qputenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION", "wayland-egl"); -qputenv("QT_QPA_ENABLE_TERMINAL_KEYBOARD", "1"); + qputenv("QT_QPA_ENABLE_TERMINAL_KEYBOARD", "1"); -// qputenv("WAYLAND_DISPLAY", ); + // qputenv("WAYLAND_DISPLAY", ); - // Set defaults + // Set defaults - qputenv("XDG_CONFIG_DIRS", "/home/camilo/.config/kdedefaults:/etc/xdg"); + qputenv("XDG_CONFIG_DIRS", "/home/camilo/.config/kdedefaults:/etc/xdg"); - qputenv("XDG_SESSION_TYPE", "wayland"); - qputenv("XDG_CURRENT_DESKTOP", "Cask"); - qputenv("XDG_SEAT_PATH", "/org/freedesktop/DisplayManager/Seat0"); - qputenv("XDG_SESSION_PATH", "/org/freedesktop/DisplayManager/Session0"); + qputenv("XDG_SESSION_TYPE", "wayland"); + qputenv("XDG_CURRENT_DESKTOP", "Cask"); + qputenv("XDG_SEAT_PATH", "/org/freedesktop/DisplayManager/Seat0"); + qputenv("XDG_SESSION_PATH", "/org/freedesktop/DisplayManager/Session0"); -// if (qEnvironmentVariableIsEmpty("XDG_DESKTOP_PORTAL_DIR")) -// qputenv("XDG_DESKTOP_PORTAL_DIR", DATADIR "/xdg-desktop-portal/portals"); + // if (qEnvironmentVariableIsEmpty("XDG_DESKTOP_PORTAL_DIR")) + // qputenv("XDG_DESKTOP_PORTAL_DIR", DATADIR "/xdg-desktop-portal/portals"); - // Environment + // Environment qputenv("DESKTOP_SESSION", "Cask"); -// qputenv("XDG_MENU_PREFIX", "liri-"); -// qputenv("XDG_CURRENT_DESKTOP", "X-Liri"); + // qputenv("XDG_MENU_PREFIX", "liri-"); + // qputenv("XDG_CURRENT_DESKTOP", "X-Liri"); qputenv("XDG_SESSION_DESKTOP", "cask"); qputenv("QT_WAYLAND_SHELL_INTEGRATION", "xdg-shell"); - qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); + qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); // qputenv("QT_ENABLE_HIGHDPI_SCALING", "1"); -// qputenv("QT_SCALE_FACTOR", "2"); //if it is mobile., how to calculate this value based on dpi? -// qunsetenv("QT_SCALE_FACTOR"); -// qunsetenv("QT_SCREEN_SCALE_FACTORS"); - - //style releated -// qputenv("QT_QPA_PLATFORMTHEME", "breeze"); //breaks icons - qputenv("QT_QUICK_CONTROLS_STYLE", "maui-style"); - qputenv("QT_QPA_PLATFORMTHEME", "maui"); - - qputenv("XCURSOR_THEME", "breeze_cursors"); - qputenv("XCURSOR_SIZE", "24"); - -// QString command = "/home/camilo/tests/grefsen/grefsen"; - QString command = "cask"; - QStringList args; -// args << "-plugin"; -//args << "libinput"; -// << "--exit-with-session=/usr/bin/cask"; -// runEnvironmentScripts(); - return runCommandSync(command, args); + // qputenv("QT_SCALE_FACTOR", "2"); //if it is mobile., how to calculate this value based on dpi? + // qunsetenv("QT_SCALE_FACTOR"); + // qunsetenv("QT_SCREEN_SCALE_FACTORS"); + + //style releated + // qputenv("QT_QPA_PLATFORMTHEME", "breeze"); //breaks icons + qputenv("QT_QUICK_CONTROLS_STYLE", "maui-style"); + qputenv("QT_QPA_PLATFORMTHEME", "maui"); + + qputenv("XCURSOR_THEME", "breeze_cursors"); + qputenv("XCURSOR_SIZE", "24"); + + // QString command = "/home/camilo/tests/grefsen/grefsen"; + QString command = "cask"; + QStringList args; + // args << "-plugin"; + //args << "libinput"; + // << "--exit-with-session=/usr/bin/cask"; + // runEnvironmentScripts(); + return runCommandSync(command, args); }