From 2c411fce5a7d7e0708be1cee875bb3547f40887d Mon Sep 17 00:00:00 2001 From: outfoxxed <outfoxxed@outfoxxed.me> Date: Tue, 7 Jan 2025 03:11:19 -0800 Subject: [PATCH] all: fix new lints --- .clang-tidy | 2 + Justfile | 6 +- src/core/desktopentry.cpp | 3 + src/core/iconimageprovider.cpp | 5 +- src/core/imageprovider.cpp | 26 ++- src/core/module.md | 1 + src/core/paths.cpp | 2 + src/core/plugin.cpp | 11 +- src/core/popupanchor.cpp | 9 +- src/core/test/scriptmodel.cpp | 2 + src/core/variants.cpp | 2 +- src/core/variants.hpp | 4 +- src/crash/handler.cpp | 2 + src/crash/main.cpp | 84 ++++---- src/dbus/bus.cpp | 2 + src/dbus/dbusmenu/dbusmenu.cpp | 8 +- src/dbus/properties.cpp | 16 +- src/dbus/properties.hpp | 2 +- src/debug/lint.cpp | 6 + src/io/fileview.cpp | 2 + src/launch/command.cpp | 222 ++++++++++---------- src/launch/launch.cpp | 4 + src/launch/main.cpp | 62 +++--- src/services/greetd/connection.cpp | 2 + src/services/mpris/player.cpp | 2 + src/services/mpris/watcher.cpp | 2 + src/services/notifications/dbusimage.cpp | 1 + src/services/notifications/notification.cpp | 1 + src/services/notifications/server.cpp | 1 + src/services/pipewire/core.cpp | 2 + src/services/pipewire/defaults.cpp | 2 + src/services/pipewire/device.cpp | 2 + src/services/pipewire/link.cpp | 2 + src/services/pipewire/metadata.cpp | 2 + src/services/pipewire/node.cpp | 2 + src/services/status_notifier/item.cpp | 1 - src/services/upower/core.cpp | 2 + src/services/upower/device.cpp | 2 + src/wayland/hyprland/ipc/connection.cpp | 31 ++- src/wayland/init.cpp | 4 +- src/wayland/platformmenu.cpp | 4 + src/wayland/wlr_layershell/surface.cpp | 91 ++++---- src/x11/i3/ipc/connection.cpp | 28 ++- 43 files changed, 351 insertions(+), 316 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ca6c9549..002c444d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: > -bugprone-easily-swappable-parameters, -bugprone-forward-declararion-namespace, -bugprone-forward-declararion-namespace, + -bugprone-return-const-ref-from-parameter, concurrency-*, cppcoreguidelines-*, -cppcoreguidelines-owning-memory, @@ -44,6 +45,7 @@ Checks: > -readability-container-data-pointer, -readability-implicit-bool-conversion, -readability-avoid-nested-conditional-operator, + -readability-math-missing-parentheses, tidyfox-*, CheckOptions: performance-for-range-copy.WarnOnAllAutoCopies: true diff --git a/Justfile b/Justfile index b4fe87ec..f60771aa 100644 --- a/Justfile +++ b/Justfile @@ -4,13 +4,13 @@ fmt: find src -type f \( -name "*.cpp" -o -name "*.hpp" \) -print0 | xargs -0 clang-format -i lint: - find src -type f -name "*.cpp" -print0 | parallel -q0 --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }} + find src -type f -name "*.cpp" -print0 | parallel -j$(nproc) -q0 --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }} lint-ci: - find src -type f -name "*.cpp" -print0 | parallel -q0 --no-notice --will-cite --tty clang-tidy --load={{ env_var("TIDYFOX") }} + find src -type f -name "*.cpp" -print0 | parallel -j$(nproc) -q0 --no-notice --will-cite --tty clang-tidy --load={{ env_var("TIDYFOX") }} lint-changed: - git diff --name-only HEAD | grep "^.*\.cpp\$" | parallel --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }} + git diff --name-only HEAD | grep "^.*\.cpp\$" | parallel -j$(nproc) --no-notice --will-cite --tty --bar clang-tidy --load={{ env_var("TIDYFOX") }} configure target='debug' *FLAGS='': cmake -GNinja -B {{builddir}} \ diff --git a/src/core/desktopentry.cpp b/src/core/desktopentry.cpp index 3714df01..975db3b4 100644 --- a/src/core/desktopentry.cpp +++ b/src/core/desktopentry.cpp @@ -18,7 +18,9 @@ #include "model.hpp" +namespace { Q_LOGGING_CATEGORY(logDesktopEntry, "quickshell.desktopentry", QtWarningMsg); +} struct Locale { explicit Locale() = default; @@ -78,6 +80,7 @@ struct Locale { QString modifier; }; +// NOLINTNEXTLINE(misc-use-internal-linkage) QDebug operator<<(QDebug debug, const Locale& locale) { auto saver = QDebugStateSaver(debug); debug.nospace() << "Locale(language=" << locale.language << ", territory=" << locale.territory diff --git a/src/core/iconimageprovider.cpp b/src/core/iconimageprovider.cpp index cf24d37d..43e00fd8 100644 --- a/src/core/iconimageprovider.cpp +++ b/src/core/iconimageprovider.cpp @@ -1,4 +1,5 @@ #include "iconimageprovider.hpp" +#include <algorithm> #include <qcolor.h> #include <qicon.h> @@ -49,8 +50,8 @@ IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& re QPixmap IconImageProvider::missingPixmap(const QSize& size) { auto width = size.width() % 2 == 0 ? size.width() : size.width() + 1; auto height = size.height() % 2 == 0 ? size.height() : size.height() + 1; - if (width < 2) width = 2; - if (height < 2) height = 2; + width = std::max(width, 2); + height = std::max(height, 2); auto pixmap = QPixmap(width, height); pixmap.fill(QColorConstants::Black); diff --git a/src/core/imageprovider.cpp b/src/core/imageprovider.cpp index cc81c47f..256faaed 100644 --- a/src/core/imageprovider.cpp +++ b/src/core/imageprovider.cpp @@ -8,7 +8,21 @@ #include <qpixmap.h> #include <qqmlengine.h> -static QMap<QString, QsImageHandle*> liveImages; // NOLINT +namespace { + +QMap<QString, QsImageHandle*> liveImages; // NOLINT + +void parseReq(const QString& req, QString& target, QString& param) { + auto splitIdx = req.indexOf('/'); + if (splitIdx != -1) { + target = req.sliced(0, splitIdx); + param = req.sliced(splitIdx + 1); + } else { + target = req; + } +} + +} // namespace QsImageHandle::QsImageHandle(QQmlImageProviderBase::ImageType type, QObject* parent) : QObject(parent) @@ -43,16 +57,6 @@ QPixmap QsImageHandle:: return QPixmap(); } -void parseReq(const QString& req, QString& target, QString& param) { - auto splitIdx = req.indexOf('/'); - if (splitIdx != -1) { - target = req.sliced(0, splitIdx); - param = req.sliced(splitIdx + 1); - } else { - target = req; - } -} - QImage QsImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize) { QString target; QString param; diff --git a/src/core/module.md b/src/core/module.md index 831f561b..c8b17ab9 100644 --- a/src/core/module.md +++ b/src/core/module.md @@ -28,5 +28,6 @@ headers = [ "types.hpp", "qsmenuanchor.hpp", "clock.hpp", + "scriptmodel.hpp", ] ----- diff --git a/src/core/paths.cpp b/src/core/paths.cpp index e108da03..e49a9d41 100644 --- a/src/core/paths.cpp +++ b/src/core/paths.cpp @@ -15,7 +15,9 @@ #include "instanceinfo.hpp" +namespace { Q_LOGGING_CATEGORY(logPaths, "quickshell.paths", QtWarningMsg); +} QsPaths* QsPaths::instance() { static auto* instance = new QsPaths(); // NOLINT diff --git a/src/core/plugin.cpp b/src/core/plugin.cpp index c6ceb13e..0eb9a067 100644 --- a/src/core/plugin.cpp +++ b/src/core/plugin.cpp @@ -10,16 +10,9 @@ static QVector<QsEnginePlugin*> plugins; // NOLINT void QsEnginePlugin::registerPlugin(QsEnginePlugin& plugin) { plugins.push_back(&plugin); } void QsEnginePlugin::initPlugins() { - plugins.erase( - std::remove_if( - plugins.begin(), - plugins.end(), - [](QsEnginePlugin* plugin) { return !plugin->applies(); } - ), - plugins.end() - ); + plugins.removeIf([](QsEnginePlugin* plugin) { return !plugin->applies(); }); - std::sort(plugins.begin(), plugins.end(), [](QsEnginePlugin* a, QsEnginePlugin* b) { + std::ranges::sort(plugins, [](QsEnginePlugin* a, QsEnginePlugin* b) { return b->dependencies().contains(a->name()); }); diff --git a/src/core/popupanchor.cpp b/src/core/popupanchor.cpp index 2b5b1bae..f72d5c59 100644 --- a/src/core/popupanchor.cpp +++ b/src/core/popupanchor.cpp @@ -1,4 +1,5 @@ #include "popupanchor.hpp" +#include <algorithm> #include <qcontainerfwd.h> #include <qlogging.h> @@ -276,9 +277,7 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only effectiveX = screenGeometry.right() - windowGeometry.width() + 1; } - if (effectiveX < screenGeometry.left()) { - effectiveX = screenGeometry.left(); - } + effectiveX = std::max(effectiveX, screenGeometry.left()); } if (adjustment.testFlag(PopupAdjustment::SlideY)) { @@ -286,9 +285,7 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only effectiveY = screenGeometry.bottom() - windowGeometry.height() + 1; } - if (effectiveY < screenGeometry.top()) { - effectiveY = screenGeometry.top(); - } + effectiveY = std::max(effectiveY, screenGeometry.top()); } if (adjustment.testFlag(PopupAdjustment::ResizeX)) { diff --git a/src/core/test/scriptmodel.cpp b/src/core/test/scriptmodel.cpp index bdf9c709..66746832 100644 --- a/src/core/test/scriptmodel.cpp +++ b/src/core/test/scriptmodel.cpp @@ -22,6 +22,7 @@ bool ModelOperation::operator==(const ModelOperation& other) const { && other.length == this->length && other.destIndex == this->destIndex; } +// NOLINTNEXTLINE(misc-use-internal-linkage) QDebug& operator<<(QDebug& debug, const ModelOperation& op) { auto saver = QDebugStateSaver(debug); debug.nospace(); @@ -43,6 +44,7 @@ QDebug& operator<<(QDebug& debug, const ModelOperation& op) { return debug; } +// NOLINTNEXTLINE(misc-use-internal-linkage) QDebug& operator<<(QDebug& debug, const QVariantList& list) { auto str = QString(); diff --git a/src/core/variants.cpp b/src/core/variants.cpp index 6c8713b6..a190e36d 100644 --- a/src/core/variants.cpp +++ b/src/core/variants.cpp @@ -196,7 +196,7 @@ V* AwfulMap<K, V>::get(const K& key) { } template <typename K, typename V> -void AwfulMap<K, V>::insert(K key, V value) { +void AwfulMap<K, V>::insert(const K& key, V value) { this->values.push_back(QPair<K, V>(key, value)); } diff --git a/src/core/variants.hpp b/src/core/variants.hpp index ebf87ae1..fa0333d3 100644 --- a/src/core/variants.hpp +++ b/src/core/variants.hpp @@ -20,8 +20,8 @@ class AwfulMap { public: [[nodiscard]] bool contains(const K& key) const; [[nodiscard]] V* get(const K& key); - void insert(K key, V value); // assumes no duplicates - bool remove(const K& key); // returns true if anything was removed + void insert(const K& key, V value); // assumes no duplicates + bool remove(const K& key); // returns true if anything was removed QList<QPair<K, V>> values; }; diff --git a/src/crash/handler.cpp b/src/crash/handler.cpp index 1f300cc9..8d9a8a71 100644 --- a/src/crash/handler.cpp +++ b/src/crash/handler.cpp @@ -22,7 +22,9 @@ using namespace google_breakpad; namespace qs::crash { +namespace { Q_LOGGING_CATEGORY(logCrashHandler, "quickshell.crashhandler", QtWarningMsg); +} struct CrashHandlerPrivate { ExceptionHandler* exceptionHandler = nullptr; diff --git a/src/crash/main.cpp b/src/crash/main.cpp index 1beb6749..7c3bad73 100644 --- a/src/crash/main.cpp +++ b/src/crash/main.cpp @@ -22,49 +22,10 @@ #include "build.hpp" #include "interface.hpp" +namespace { + Q_LOGGING_CATEGORY(logCrashReporter, "quickshell.crashreporter", QtWarningMsg); -void recordCrashInfo(const QDir& crashDir, const InstanceInfo& instance); - -void qsCheckCrash(int argc, char** argv) { - auto fd = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_FD"); - if (fd.isEmpty()) return; - auto app = QApplication(argc, argv); - - RelaunchInfo info; - - auto crashProc = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_PID").toInt(); - - { - auto infoFd = qEnvironmentVariable("__QUICKSHELL_CRASH_INFO_FD").toInt(); - - QFile file; - file.open(infoFd, QFile::ReadOnly, QFile::AutoCloseHandle); - file.seek(0); - - auto ds = QDataStream(&file); - ds >> info; - } - - LogManager::init( - !info.noColor, - info.timestamp, - info.sparseLogsOnly, - info.defaultLogLevel, - info.logRules - ); - - auto crashDir = QsPaths::crashDir(info.instance.instanceId); - - qCInfo(logCrashReporter) << "Starting crash reporter..."; - - recordCrashInfo(crashDir, info.instance); - - auto gui = CrashReporterGui(crashDir.path(), crashProc); - gui.show(); - exit(QApplication::exec()); // NOLINT -} - int tryDup(int fd, const QString& path) { QFile sourceFile; if (!sourceFile.open(fd, QFile::ReadOnly, QFile::AutoCloseHandle)) { @@ -184,3 +145,44 @@ void recordCrashInfo(const QDir& crashDir, const InstanceInfo& instance) { qCDebug(logCrashReporter) << "Recorded crash information."; } + +} // namespace + +void qsCheckCrash(int argc, char** argv) { + auto fd = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_FD"); + if (fd.isEmpty()) return; + auto app = QApplication(argc, argv); + + RelaunchInfo info; + + auto crashProc = qEnvironmentVariable("__QUICKSHELL_CRASH_DUMP_PID").toInt(); + + { + auto infoFd = qEnvironmentVariable("__QUICKSHELL_CRASH_INFO_FD").toInt(); + + QFile file; + file.open(infoFd, QFile::ReadOnly, QFile::AutoCloseHandle); + file.seek(0); + + auto ds = QDataStream(&file); + ds >> info; + } + + LogManager::init( + !info.noColor, + info.timestamp, + info.sparseLogsOnly, + info.defaultLogLevel, + info.logRules + ); + + auto crashDir = QsPaths::crashDir(info.instance.instanceId); + + qCInfo(logCrashReporter) << "Starting crash reporter..."; + + recordCrashInfo(crashDir, info.instance); + + auto gui = CrashReporterGui(crashDir.path(), crashProc); + gui.show(); + exit(QApplication::exec()); // NOLINT +} diff --git a/src/dbus/bus.cpp b/src/dbus/bus.cpp index 6f560e9e..dc6d21bf 100644 --- a/src/dbus/bus.cpp +++ b/src/dbus/bus.cpp @@ -14,7 +14,9 @@ namespace qs::dbus { +namespace { Q_LOGGING_CATEGORY(logDbus, "quickshell.dbus", QtWarningMsg); +} void tryLaunchService( QObject* parent, diff --git a/src/dbus/dbusmenu/dbusmenu.cpp b/src/dbus/dbusmenu/dbusmenu.cpp index e86b580d..0267af8e 100644 --- a/src/dbus/dbusmenu/dbusmenu.cpp +++ b/src/dbus/dbusmenu/dbusmenu.cpp @@ -368,11 +368,9 @@ void DBusMenu::updateLayoutRecursive( auto childrenChanged = false; auto iter = item->mChildren.begin(); while (iter != item->mChildren.end()) { - auto existing = std::find_if( - layout.children.begin(), - layout.children.end(), - [&](const DBusMenuLayout& layout) { return layout.id == *iter; } - ); + auto existing = std::ranges::find_if(layout.children, [&](const DBusMenuLayout& layout) { + return layout.id == *iter; + }); if (!item->mShowChildren || existing == layout.children.end()) { qCDebug(logDbusMenu) << "Removing missing layout item" << this->items.value(*iter) << "from" diff --git a/src/dbus/properties.cpp b/src/dbus/properties.cpp index a9ef2d27..52f50060 100644 --- a/src/dbus/properties.cpp +++ b/src/dbus/properties.cpp @@ -190,11 +190,9 @@ void DBusPropertyGroup::updateAllViaGetAll() { void DBusPropertyGroup::updatePropertySet(const QVariantMap& properties, bool complainMissing) { for (const auto [name, value]: properties.asKeyValueRange()) { - auto prop = std::find_if( - this->properties.begin(), - this->properties.end(), - [&name](DBusPropertyCore* prop) { return prop->nameRef() == name; } - ); + auto prop = std::ranges::find_if(this->properties, [&name](DBusPropertyCore* prop) { + return prop->nameRef() == name; + }); if (prop == this->properties.end()) { qCDebug(logDbusProperties) << "Ignoring untracked property update" << name << "for" @@ -312,11 +310,9 @@ void DBusPropertyGroup::onPropertiesChanged( << "Received property change set and invalidations for" << this->toString(); for (const auto& name: invalidatedProperties) { - auto prop = std::find_if( - this->properties.begin(), - this->properties.end(), - [&name](DBusPropertyCore* prop) { return prop->nameRef() == name; } - ); + auto prop = std::ranges::find_if(this->properties, [&name](DBusPropertyCore* prop) { + return prop->nameRef() == name; + }); if (prop == this->properties.end()) { qCDebug(logDbusProperties) << "Ignoring untracked property invalidation" << name << "for" diff --git a/src/dbus/properties.hpp b/src/dbus/properties.hpp index f800ef3e..6feaa43d 100644 --- a/src/dbus/properties.hpp +++ b/src/dbus/properties.hpp @@ -66,7 +66,7 @@ template <typename T> void asyncReadProperty( QDBusAbstractInterface& interface, const QString& property, - std::function<void(T, QDBusError)> callback + const std::function<void(T, QDBusError)>& callback ) { asyncReadPropertyInternal( QMetaType::fromType<T>(), diff --git a/src/debug/lint.cpp b/src/debug/lint.cpp index f9727968..eb0450f8 100644 --- a/src/debug/lint.cpp +++ b/src/debug/lint.cpp @@ -13,10 +13,12 @@ namespace qs::debug { +namespace { Q_LOGGING_CATEGORY(logLint, "quickshell.linter", QtWarningMsg); void lintZeroSized(QQuickItem* item); bool isRenderable(QQuickItem* item); +} // namespace void lintObjectTree(QObject* object) { if (!logLint().isWarningEnabled()) return; @@ -41,6 +43,8 @@ void lintItemTree(QQuickItem* item) { } } +namespace { + void lintZeroSized(QQuickItem* item) { if (!item->isEnabled() || !item->isVisible()) return; if (item->childItems().isEmpty()) return; @@ -71,4 +75,6 @@ bool isRenderable(QQuickItem* item) { return std::ranges::any_of(item->childItems(), [](auto* item) { return isRenderable(item); }); } +} // namespace + } // namespace qs::debug diff --git a/src/io/fileview.cpp b/src/io/fileview.cpp index 29e6971b..23656d34 100644 --- a/src/io/fileview.cpp +++ b/src/io/fileview.cpp @@ -24,7 +24,9 @@ namespace qs::io { +namespace { Q_LOGGING_CATEGORY(logFileView, "quickshell.io.fileview", QtWarningMsg); +} QString FileViewError::toString(FileViewError::Enum value) { switch (value) { diff --git a/src/launch/command.cpp b/src/launch/command.cpp index 9e8ac27c..eb27df74 100644 --- a/src/launch/command.cpp +++ b/src/launch/command.cpp @@ -34,113 +34,7 @@ namespace qs::launch { using qs::ipc::IpcClient; -int readLogFile(CommandState& cmd); -int listInstances(CommandState& cmd); -int killInstances(CommandState& cmd); -int msgInstance(CommandState& cmd); -int launchFromCommand(CommandState& cmd, QCoreApplication* coreApplication); -int locateConfigFile(CommandState& cmd, QString& path); - -int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { - auto state = CommandState(); - if (auto ret = parseCommand(argc, argv, state); ret != 65535) return ret; - - if (state.misc.checkCompat) { - if (strcmp(qVersion(), QT_VERSION_STR) != 0) { - QTextStream(stdout) << "\033[31mCOMPATIBILITY WARNING: Quickshell was built against Qt " - << QT_VERSION_STR << " but the system has updated to Qt " << qVersion() - << " without rebuilding the package. This is likely to cause crashes, so " - "you must rebuild the quickshell package.\n"; - return 1; - } - - return 0; - } - - // Has to happen before extra threads are spawned. - if (state.misc.daemonize) { - auto closepipes = std::array<int, 2>(); - if (pipe(closepipes.data()) == -1) { - qFatal().nospace() << "Failed to create messaging pipes for daemon with error " << errno - << ": " << qt_error_string(); - } - - pid_t pid = fork(); // NOLINT (include) - - if (pid == -1) { - qFatal().nospace() << "Failed to fork daemon with error " << errno << ": " - << qt_error_string(); - } else if (pid == 0) { - DAEMON_PIPE = closepipes[1]; - close(closepipes[0]); - - if (setsid() == -1) { - qFatal().nospace() << "Failed to setsid with error " << errno << ": " << qt_error_string(); - } - } else { - close(closepipes[1]); - - int ret = 0; - if (read(closepipes[0], &ret, sizeof(int)) == -1) { - qFatal() << "Failed to wait for daemon launch (it may have crashed)"; - } - - return ret; - } - } - - { - auto level = state.log.verbosity == 0 ? QtWarningMsg - : state.log.verbosity == 1 ? QtInfoMsg - : QtDebugMsg; - - LogManager::init( - !state.log.noColor, - state.log.timestamp, - state.log.sparse, - level, - *state.log.rules, - *state.subcommand.log ? "READER" : "" - ); - } - - if (state.misc.printVersion) { - qCInfo(logBare).noquote().nospace() << "quickshell pre-release, revision " << GIT_REVISION - << ", distributed by: " << DISTRIBUTOR; - - if (state.log.verbosity > 1) { - qCInfo(logBare).noquote() << "\nBuildtime Qt Version:" << QT_VERSION_STR; - qCInfo(logBare).noquote() << "Runtime Qt Version:" << qVersion(); - qCInfo(logBare).noquote() << "Compiler:" << COMPILER; - qCInfo(logBare).noquote() << "Compile Flags:" << COMPILE_FLAGS; - } - - if (state.log.verbosity > 0) { - qCInfo(logBare).noquote() << "\nBuild Type:" << BUILD_TYPE; - qCInfo(logBare).noquote() << "Build configuration:"; - qCInfo(logBare).noquote().nospace() << BUILD_CONFIGURATION; - } - } else if (*state.subcommand.log) { - return readLogFile(state); - } else if (*state.subcommand.list) { - return listInstances(state); - } else if (*state.subcommand.kill) { - return killInstances(state); - } else if (*state.subcommand.msg) { - return msgInstance(state); - } else { - if (strcmp(qVersion(), QT_VERSION_STR) != 0) { - qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR - << "but the system has updated to Qt" << qVersion() - << "without rebuilding the package. This is likely to cause crashes, so " - "the quickshell package must be rebuilt.\n"; - } - - return launchFromCommand(state, coreApplication); - } - - return 0; -} +namespace { int locateConfigFile(CommandState& cmd, QString& path) { if (!cmd.config.path->isEmpty()) { @@ -209,7 +103,7 @@ int locateConfigFile(CommandState& cmd, QString& path) { } void sortInstances(QVector<InstanceLockInfo>& list) { - std::sort(list.begin(), list.end(), [](const InstanceLockInfo& a, const InstanceLockInfo& b) { + std::ranges::sort(list, [](const InstanceLockInfo& a, const InstanceLockInfo& b) { return a.instance.launchTime < b.instance.launchTime; }); }; @@ -230,12 +124,9 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) { path = basePath->filePath("by-pid"); auto instances = QsPaths::collectInstances(path); - auto itr = - std::remove_if(instances.begin(), instances.end(), [&](const InstanceLockInfo& info) { - return !info.instance.instanceId.startsWith(*cmd.instance.id); - }); - - instances.erase(itr, instances.end()); + instances.removeIf([&](const InstanceLockInfo& info) { + return !info.instance.instanceId.startsWith(*cmd.instance.id); + }); if (instances.isEmpty()) { qCInfo(logBare) << "No running instances start with" << *cmd.instance.id; @@ -444,4 +335,107 @@ int launchFromCommand(CommandState& cmd, QCoreApplication* coreApplication) { ); } +} // namespace + +int runCommand(int argc, char** argv, QCoreApplication* coreApplication) { + auto state = CommandState(); + if (auto ret = parseCommand(argc, argv, state); ret != 65535) return ret; + + if (state.misc.checkCompat) { + if (strcmp(qVersion(), QT_VERSION_STR) != 0) { + QTextStream(stdout) << "\033[31mCOMPATIBILITY WARNING: Quickshell was built against Qt " + << QT_VERSION_STR << " but the system has updated to Qt " << qVersion() + << " without rebuilding the package. This is likely to cause crashes, so " + "you must rebuild the quickshell package.\n"; + return 1; + } + + return 0; + } + + // Has to happen before extra threads are spawned. + if (state.misc.daemonize) { + auto closepipes = std::array<int, 2>(); + if (pipe(closepipes.data()) == -1) { + qFatal().nospace() << "Failed to create messaging pipes for daemon with error " << errno + << ": " << qt_error_string(); + } + + pid_t pid = fork(); // NOLINT (include) + + if (pid == -1) { + qFatal().nospace() << "Failed to fork daemon with error " << errno << ": " + << qt_error_string(); + } else if (pid == 0) { + DAEMON_PIPE = closepipes[1]; + close(closepipes[0]); + + if (setsid() == -1) { + qFatal().nospace() << "Failed to setsid with error " << errno << ": " << qt_error_string(); + } + } else { + close(closepipes[1]); + + int ret = 0; + if (read(closepipes[0], &ret, sizeof(int)) == -1) { + qFatal() << "Failed to wait for daemon launch (it may have crashed)"; + } + + return ret; + } + } + + { + auto level = state.log.verbosity == 0 ? QtWarningMsg + : state.log.verbosity == 1 ? QtInfoMsg + : QtDebugMsg; + + LogManager::init( + !state.log.noColor, + state.log.timestamp, + state.log.sparse, + level, + *state.log.rules, + *state.subcommand.log ? "READER" : "" + ); + } + + if (state.misc.printVersion) { + qCInfo(logBare).noquote().nospace() << "quickshell pre-release, revision " << GIT_REVISION + << ", distributed by: " << DISTRIBUTOR; + + if (state.log.verbosity > 1) { + qCInfo(logBare).noquote() << "\nBuildtime Qt Version:" << QT_VERSION_STR; + qCInfo(logBare).noquote() << "Runtime Qt Version:" << qVersion(); + qCInfo(logBare).noquote() << "Compiler:" << COMPILER; + qCInfo(logBare).noquote() << "Compile Flags:" << COMPILE_FLAGS; + } + + if (state.log.verbosity > 0) { + qCInfo(logBare).noquote() << "\nBuild Type:" << BUILD_TYPE; + qCInfo(logBare).noquote() << "Build configuration:"; + qCInfo(logBare).noquote().nospace() << BUILD_CONFIGURATION; + } + } else if (*state.subcommand.log) { + return readLogFile(state); + } else if (*state.subcommand.list) { + return listInstances(state); + } else if (*state.subcommand.kill) { + return killInstances(state); + } else if (*state.subcommand.msg) { + return msgInstance(state); + } else { + if (strcmp(qVersion(), QT_VERSION_STR) != 0) { + qWarning() << "\033[31mQuickshell was built against Qt" << QT_VERSION_STR + << "but the system has updated to Qt" << qVersion() + << "without rebuilding the package. This is likely to cause crashes, so " + "the quickshell package must be rebuilt.\n"; + } + + return launchFromCommand(state, coreApplication); + } + + return 0; +} + } // namespace qs::launch diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index ec5863e9..848da499 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -32,6 +32,8 @@ namespace qs::launch { +namespace { + template <typename T> QString base36Encode(T number) { const QString digits = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -52,6 +54,8 @@ QString base36Encode(T number) { return result; } +} // namespace + int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplication) { auto pathId = QCryptographicHash::hash(args.configPath.toUtf8(), QCryptographicHash::Md5).toHex(); auto shellId = QString(pathId); diff --git a/src/launch/main.cpp b/src/launch/main.cpp index 3a2b5822..2bcbebd3 100644 --- a/src/launch/main.cpp +++ b/src/launch/main.cpp @@ -22,36 +22,7 @@ namespace qs::launch { -void checkCrashRelaunch(char** argv, QCoreApplication* coreApplication); - -int DAEMON_PIPE = -1; // NOLINT - -void exitDaemon(int code) { - if (DAEMON_PIPE == -1) return; - - if (write(DAEMON_PIPE, &code, sizeof(int)) == -1) { - qCritical().nospace() << "Failed to write daemon exit command with error code " << errno << ": " - << qt_error_string(); - } - - close(DAEMON_PIPE); - - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - - if (open("/dev/null", O_RDONLY) != STDIN_FILENO) { // NOLINT - qFatal() << "Failed to open /dev/null on stdin"; - } - - if (open("/dev/null", O_WRONLY) != STDOUT_FILENO) { // NOLINT - qFatal() << "Failed to open /dev/null on stdout"; - } - - if (open("/dev/null", O_WRONLY) != STDERR_FILENO) { // NOLINT - qFatal() << "Failed to open /dev/null on stderr"; - } -} +namespace { void checkCrashRelaunch(char** argv, QCoreApplication* coreApplication) { #if CRASH_REPORTER @@ -96,6 +67,37 @@ void checkCrashRelaunch(char** argv, QCoreApplication* coreApplication) { #endif } +} // namespace + +int DAEMON_PIPE = -1; // NOLINT + +void exitDaemon(int code) { + if (DAEMON_PIPE == -1) return; + + if (write(DAEMON_PIPE, &code, sizeof(int)) == -1) { + qCritical().nospace() << "Failed to write daemon exit command with error code " << errno << ": " + << qt_error_string(); + } + + close(DAEMON_PIPE); + + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + + if (open("/dev/null", O_RDONLY) != STDIN_FILENO) { // NOLINT + qFatal() << "Failed to open /dev/null on stdin"; + } + + if (open("/dev/null", O_WRONLY) != STDOUT_FILENO) { // NOLINT + qFatal() << "Failed to open /dev/null on stdout"; + } + + if (open("/dev/null", O_WRONLY) != STDERR_FILENO) { // NOLINT + qFatal() << "Failed to open /dev/null on stderr"; + } +} + int main(int argc, char** argv) { QCoreApplication::setApplicationName("quickshell"); diff --git a/src/services/greetd/connection.cpp b/src/services/greetd/connection.cpp index 822df5fb..ecfd9a59 100644 --- a/src/services/greetd/connection.cpp +++ b/src/services/greetd/connection.cpp @@ -15,7 +15,9 @@ #include "../../core/generation.hpp" +namespace { Q_LOGGING_CATEGORY(logGreetd, "quickshell.service.greetd"); +} QString GreetdState::toString(GreetdState::Enum value) { switch (value) { diff --git a/src/services/mpris/player.cpp b/src/services/mpris/player.cpp index c4fe2ac9..4aac2826 100644 --- a/src/services/mpris/player.cpp +++ b/src/services/mpris/player.cpp @@ -21,7 +21,9 @@ using namespace qs::dbus; namespace qs::service::mpris { +namespace { Q_LOGGING_CATEGORY(logMprisPlayer, "quickshell.service.mp.player", QtWarningMsg); +} QString MprisPlaybackState::toString(MprisPlaybackState::Enum status) { switch (status) { diff --git a/src/services/mpris/watcher.cpp b/src/services/mpris/watcher.cpp index 8a788933..94619074 100644 --- a/src/services/mpris/watcher.cpp +++ b/src/services/mpris/watcher.cpp @@ -14,7 +14,9 @@ namespace qs::service::mpris { +namespace { Q_LOGGING_CATEGORY(logMprisWatcher, "quickshell.service.mpris.watcher", QtWarningMsg); +} MprisWatcher::MprisWatcher() { qCDebug(logMprisWatcher) << "Starting MprisWatcher"; diff --git a/src/services/notifications/dbusimage.cpp b/src/services/notifications/dbusimage.cpp index 46a72a78..9c10e222 100644 --- a/src/services/notifications/dbusimage.cpp +++ b/src/services/notifications/dbusimage.cpp @@ -9,6 +9,7 @@ namespace qs::service::notifications { +// NOLINTNEXTLINE(misc-use-internal-linkage) Q_DECLARE_LOGGING_CATEGORY(logNotifications); // server.cpp QImage DBusNotificationImage::createImage() const { diff --git a/src/services/notifications/notification.cpp b/src/services/notifications/notification.cpp index b1bbdf3a..51a64154 100644 --- a/src/services/notifications/notification.cpp +++ b/src/services/notifications/notification.cpp @@ -18,6 +18,7 @@ namespace qs::service::notifications { +// NOLINTNEXTLINE(misc-use-internal-linkage) Q_DECLARE_LOGGING_CATEGORY(logNotifications); // server.cpp QString NotificationUrgency::toString(NotificationUrgency::Enum value) { diff --git a/src/services/notifications/server.cpp b/src/services/notifications/server.cpp index 9a866f7c..0c41fb84 100644 --- a/src/services/notifications/server.cpp +++ b/src/services/notifications/server.cpp @@ -19,6 +19,7 @@ namespace qs::service::notifications { +// NOLINTNEXTLINE(misc-use-internal-linkage) Q_LOGGING_CATEGORY(logNotifications, "quickshell.service.notifications"); NotificationServer::NotificationServer() { diff --git a/src/services/pipewire/core.cpp b/src/services/pipewire/core.cpp index c4b31ab5..c325bb33 100644 --- a/src/services/pipewire/core.cpp +++ b/src/services/pipewire/core.cpp @@ -15,7 +15,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logLoop, "quickshell.service.pipewire.loop", QtWarningMsg); +} PwCore::PwCore(QObject* parent): QObject(parent), notifier(QSocketNotifier::Read) { qCInfo(logLoop) << "Creating pipewire event loop."; diff --git a/src/services/pipewire/defaults.cpp b/src/services/pipewire/defaults.cpp index cd018f9f..0333c87f 100644 --- a/src/services/pipewire/defaults.cpp +++ b/src/services/pipewire/defaults.cpp @@ -18,7 +18,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logDefaults, "quickshell.service.pipewire.defaults", QtWarningMsg); +} PwDefaultTracker::PwDefaultTracker(PwRegistry* registry): registry(registry) { QObject::connect(registry, &PwRegistry::metadataAdded, this, &PwDefaultTracker::onMetadataAdded); diff --git a/src/services/pipewire/device.cpp b/src/services/pipewire/device.cpp index 06ed102a..0a1e1b6a 100644 --- a/src/services/pipewire/device.cpp +++ b/src/services/pipewire/device.cpp @@ -23,7 +23,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logDevice, "quickshell.service.pipewire.device", QtWarningMsg); +} // https://github.com/PipeWire/wireplumber/blob/895c1c7286e8809fad869059179e53ab39c807e9/modules/module-mixer-api.c#L397 // https://github.com/PipeWire/pipewire/blob/48c2e9516585ccc791335bc7baf4af6952ec54a0/src/modules/module-protocol-pulse/pulse-server.c#L2743-L2743 diff --git a/src/services/pipewire/link.cpp b/src/services/pipewire/link.cpp index 8370446b..c6421af6 100644 --- a/src/services/pipewire/link.cpp +++ b/src/services/pipewire/link.cpp @@ -14,7 +14,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logLink, "quickshell.service.pipewire.link", QtWarningMsg); +} QString PwLinkState::toString(Enum value) { return QString(pw_link_state_as_string(static_cast<pw_link_state>(value))); diff --git a/src/services/pipewire/metadata.cpp b/src/services/pipewire/metadata.cpp index 930725c3..ea79611a 100644 --- a/src/services/pipewire/metadata.cpp +++ b/src/services/pipewire/metadata.cpp @@ -15,7 +15,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logMeta, "quickshell.service.pipewire.metadata", QtWarningMsg); +} void PwMetadata::bindHooks() { pw_metadata_add_listener(this->proxy(), &this->listener.hook, &PwMetadata::EVENTS, this); diff --git a/src/services/pipewire/node.cpp b/src/services/pipewire/node.cpp index b89bbff0..ffb8c164 100644 --- a/src/services/pipewire/node.cpp +++ b/src/services/pipewire/node.cpp @@ -28,7 +28,9 @@ namespace qs::service::pipewire { +namespace { Q_LOGGING_CATEGORY(logNode, "quickshell.service.pipewire.node", QtWarningMsg); +} QString PwAudioChannel::toString(Enum value) { switch (value) { diff --git a/src/services/status_notifier/item.cpp b/src/services/status_notifier/item.cpp index 347edbbd..d145c451 100644 --- a/src/services/status_notifier/item.cpp +++ b/src/services/status_notifier/item.cpp @@ -35,7 +35,6 @@ using namespace qs::dbus::dbusmenu; using namespace qs::menu::platform; Q_LOGGING_CATEGORY(logStatusNotifierItem, "quickshell.service.sni.item", QtWarningMsg); -Q_LOGGING_CATEGORY(logSniMenu, "quickshell.service.sni.item.menu", QtWarningMsg); namespace qs::service::sni { diff --git a/src/services/upower/core.cpp b/src/services/upower/core.cpp index 750da5c9..9fe0e60c 100644 --- a/src/services/upower/core.cpp +++ b/src/services/upower/core.cpp @@ -20,7 +20,9 @@ namespace qs::service::upower { +namespace { Q_LOGGING_CATEGORY(logUPower, "quickshell.service.upower", QtWarningMsg); +} UPower::UPower() { qCDebug(logUPower) << "Starting UPower Service"; diff --git a/src/services/upower/device.cpp b/src/services/upower/device.cpp index dd9fbaa2..b7c61e12 100644 --- a/src/services/upower/device.cpp +++ b/src/services/upower/device.cpp @@ -15,7 +15,9 @@ using namespace qs::dbus; namespace qs::service::upower { +namespace { Q_LOGGING_CATEGORY(logUPowerDevice, "quickshell.service.upower.device", QtWarningMsg); +} QString UPowerDeviceState::toString(UPowerDeviceState::Enum status) { switch (status) { diff --git a/src/wayland/hyprland/ipc/connection.cpp b/src/wayland/hyprland/ipc/connection.cpp index c33ebd60..1e1af05a 100644 --- a/src/wayland/hyprland/ipc/connection.cpp +++ b/src/wayland/hyprland/ipc/connection.cpp @@ -26,8 +26,10 @@ namespace qs::hyprland::ipc { +namespace { Q_LOGGING_CATEGORY(logHyprlandIpc, "quickshell.hyprland.ipc", QtWarningMsg); Q_LOGGING_CATEGORY(logHyprlandIpcEvents, "quickshell.hyprland.ipc.events", QtWarningMsg); +} // namespace HyprlandIpc::HyprlandIpc() { auto his = qEnvironmentVariable("HYPRLAND_INSTANCE_SIGNATURE"); @@ -241,9 +243,8 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) { const auto& mList = this->mMonitors.valueList(); auto name = QString::fromUtf8(event->data); - auto monitorIter = std::find_if(mList.begin(), mList.end(), [name](const HyprlandMonitor* m) { - return m->name() == name; - }); + auto monitorIter = + std::ranges::find_if(mList, [name](const HyprlandMonitor* m) { return m->name() == name; }); if (monitorIter == mList.end()) { qCWarning(logHyprlandIpc) << "Got removal for monitor" << name @@ -292,9 +293,8 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) { const auto& mList = this->mWorkspaces.valueList(); - auto workspaceIter = std::find_if(mList.begin(), mList.end(), [id](const HyprlandWorkspace* m) { - return m->id() == id; - }); + auto workspaceIter = + std::ranges::find_if(mList, [id](const HyprlandWorkspace* m) { return m->id() == id; }); if (workspaceIter == mList.end()) { qCWarning(logHyprlandIpc) << "Got removal for workspace id" << id << "name" << name @@ -359,9 +359,8 @@ HyprlandWorkspace* HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint32 id) { const auto& mList = this->mWorkspaces.valueList(); - auto workspaceIter = std::find_if(mList.begin(), mList.end(), [name](const HyprlandWorkspace* m) { - return m->name() == name; - }); + auto workspaceIter = + std::ranges::find_if(mList, [name](const HyprlandWorkspace* m) { return m->name() == name; }); if (workspaceIter != mList.end()) { return *workspaceIter; @@ -395,10 +394,9 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) { auto object = entry.toObject().toVariantMap(); auto name = object.value("name").toString(); - auto workspaceIter = - std::find_if(mList.begin(), mList.end(), [name](const HyprlandWorkspace* m) { - return m->name() == name; - }); + auto workspaceIter = std::ranges::find_if(mList, [name](const HyprlandWorkspace* m) { + return m->name() == name; + }); auto* workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter; auto existed = workspace != nullptr; @@ -436,9 +434,8 @@ HyprlandMonitor* HyprlandIpc::findMonitorByName(const QString& name, bool createIfMissing, qint32 id) { const auto& mList = this->mMonitors.valueList(); - auto monitorIter = std::find_if(mList.begin(), mList.end(), [name](const HyprlandMonitor* m) { - return m->name() == name; - }); + auto monitorIter = + std::ranges::find_if(mList, [name](const HyprlandMonitor* m) { return m->name() == name; }); if (monitorIter != mList.end()) { return *monitorIter; @@ -506,7 +503,7 @@ void HyprlandIpc::refreshMonitors(bool canCreate) { auto object = entry.toObject().toVariantMap(); auto name = object.value("name").toString(); - auto monitorIter = std::find_if(mList.begin(), mList.end(), [name](const HyprlandMonitor* m) { + auto monitorIter = std::ranges::find_if(mList, [name](const HyprlandMonitor* m) { return m->name() == name; }); diff --git a/src/wayland/init.cpp b/src/wayland/init.cpp index 7c024c42..3f2a18b4 100644 --- a/src/wayland/init.cpp +++ b/src/wayland/init.cpp @@ -10,8 +10,8 @@ #include "wlr_layershell.hpp" #endif -void installPlatformMenuHook(); -void installPopupPositioner(); +void installPlatformMenuHook(); // NOLINT(misc-use-internal-linkage) +void installPopupPositioner(); // NOLINT(misc-use-internal-linkage) namespace { diff --git a/src/wayland/platformmenu.cpp b/src/wayland/platformmenu.cpp index e64e8880..117d028d 100644 --- a/src/wayland/platformmenu.cpp +++ b/src/wayland/platformmenu.cpp @@ -12,6 +12,8 @@ using namespace qs::menu::platform; +namespace { + // fixes positioning of submenus when hitting screen edges void platformMenuHook(PlatformMenuQMenu* menu) { auto* window = menu->windowHandle(); @@ -62,4 +64,6 @@ void platformMenuHook(PlatformMenuQMenu* menu) { window->setProperty("_q_waylandPopupConstraintAdjustment", constraintAdjustment); } +} // namespace + void installPlatformMenuHook() { PlatformMenuEntry::registerCreationHook(&platformMenuHook); } diff --git a/src/wayland/wlr_layershell/surface.cpp b/src/wayland/wlr_layershell/surface.cpp index 25b58ff8..3c0338c7 100644 --- a/src/wayland/wlr_layershell/surface.cpp +++ b/src/wayland/wlr_layershell/surface.cpp @@ -22,12 +22,51 @@ #include <qpoint.h> #endif -// clang-format off -[[nodiscard]] QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const WlrLayer::Enum& layer) noexcept; -[[nodiscard]] QtWayland::zwlr_layer_surface_v1::anchor toWaylandAnchors(const Anchors& anchors) noexcept; -[[nodiscard]] QtWayland::zwlr_layer_surface_v1::keyboard_interactivity toWaylandKeyboardFocus(const WlrKeyboardFocus::Enum& focus) noexcept; -[[nodiscard]] QSize constrainedSize(const Anchors& anchors, const QSize& size) noexcept; -// clang-format on +namespace { + +[[nodiscard]] QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const WlrLayer::Enum& layer +) noexcept { + switch (layer) { + case WlrLayer::Background: return QtWayland::zwlr_layer_shell_v1::layer_background; + case WlrLayer::Bottom: return QtWayland::zwlr_layer_shell_v1::layer_bottom; + case WlrLayer::Top: return QtWayland::zwlr_layer_shell_v1::layer_top; + case WlrLayer::Overlay: return QtWayland::zwlr_layer_shell_v1::layer_overlay; + } + + return QtWayland::zwlr_layer_shell_v1::layer_top; +} + +[[nodiscard]] QtWayland::zwlr_layer_surface_v1::anchor toWaylandAnchors(const Anchors& anchors +) noexcept { + quint32 wl = 0; + if (anchors.mLeft) wl |= QtWayland::zwlr_layer_surface_v1::anchor_left; + if (anchors.mRight) wl |= QtWayland::zwlr_layer_surface_v1::anchor_right; + if (anchors.mTop) wl |= QtWayland::zwlr_layer_surface_v1::anchor_top; + if (anchors.mBottom) wl |= QtWayland::zwlr_layer_surface_v1::anchor_bottom; + return static_cast<QtWayland::zwlr_layer_surface_v1::anchor>(wl); +} + +[[nodiscard]] QtWayland::zwlr_layer_surface_v1::keyboard_interactivity +toWaylandKeyboardFocus(const WlrKeyboardFocus::Enum& focus) noexcept { + switch (focus) { + case WlrKeyboardFocus::None: return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_none; + case WlrKeyboardFocus::Exclusive: + return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_exclusive; + case WlrKeyboardFocus::OnDemand: + return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_on_demand; + } + + return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_none; +} + +[[nodiscard]] QSize constrainedSize(const Anchors& anchors, const QSize& size) noexcept { + return QSize( + anchors.horizontalConstraint() ? 0 : size.width(), + anchors.verticalConstraint() ? 0 : size.height() + ); +} + +} // namespace QSWaylandLayerSurface::QSWaylandLayerSurface( QSWaylandLayerShellIntegration* shell, @@ -148,46 +187,6 @@ void QSWaylandLayerSurface::updateKeyboardFocus() { this->window()->waylandSurface()->commit(); } -QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const WlrLayer::Enum& layer) noexcept { - switch (layer) { - case WlrLayer::Background: return QtWayland::zwlr_layer_shell_v1::layer_background; - case WlrLayer::Bottom: return QtWayland::zwlr_layer_shell_v1::layer_bottom; - case WlrLayer::Top: return QtWayland::zwlr_layer_shell_v1::layer_top; - case WlrLayer::Overlay: return QtWayland::zwlr_layer_shell_v1::layer_overlay; - } - - return QtWayland::zwlr_layer_shell_v1::layer_top; -} - -QtWayland::zwlr_layer_surface_v1::anchor toWaylandAnchors(const Anchors& anchors) noexcept { - quint32 wl = 0; - if (anchors.mLeft) wl |= QtWayland::zwlr_layer_surface_v1::anchor_left; - if (anchors.mRight) wl |= QtWayland::zwlr_layer_surface_v1::anchor_right; - if (anchors.mTop) wl |= QtWayland::zwlr_layer_surface_v1::anchor_top; - if (anchors.mBottom) wl |= QtWayland::zwlr_layer_surface_v1::anchor_bottom; - return static_cast<QtWayland::zwlr_layer_surface_v1::anchor>(wl); -} - -QtWayland::zwlr_layer_surface_v1::keyboard_interactivity -toWaylandKeyboardFocus(const WlrKeyboardFocus::Enum& focus) noexcept { - switch (focus) { - case WlrKeyboardFocus::None: return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_none; - case WlrKeyboardFocus::Exclusive: - return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_exclusive; - case WlrKeyboardFocus::OnDemand: - return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_on_demand; - } - - return QtWayland::zwlr_layer_surface_v1::keyboard_interactivity_none; -} - -QSize constrainedSize(const Anchors& anchors, const QSize& size) noexcept { - return QSize( - anchors.horizontalConstraint() ? 0 : size.width(), - anchors.verticalConstraint() ? 0 : size.height() - ); -} - void QSWaylandLayerSurface::attachPopup(QtWaylandClient::QWaylandShellSurface* popup) { std::any role = popup->surfaceRole(); diff --git a/src/x11/i3/ipc/connection.cpp b/src/x11/i3/ipc/connection.cpp index 8ce78228..b6aa1513 100644 --- a/src/x11/i3/ipc/connection.cpp +++ b/src/x11/i3/ipc/connection.cpp @@ -28,10 +28,12 @@ #include "monitor.hpp" #include "workspace.hpp" +namespace qs::i3::ipc { + +namespace { Q_LOGGING_CATEGORY(logI3Ipc, "quickshell.I3.ipc", QtWarningMsg); Q_LOGGING_CATEGORY(logI3IpcEvents, "quickshell.I3.ipc.events", QtWarningMsg); - -namespace qs::i3::ipc { +} // namespace void I3Ipc::makeRequest(const QByteArray& request) { if (!this->valid) { @@ -262,9 +264,8 @@ void I3Ipc::handleGetWorkspacesEvent(I3IpcEvent* event) { auto object = entry.toObject().toVariantMap(); auto name = object["name"].toString(); - auto workspaceIter = std::find_if(mList.begin(), mList.end(), [name](const I3Workspace* m) { - return m->name() == name; - }); + auto workspaceIter = + std::ranges::find_if(mList, [name](const I3Workspace* m) { return m->name() == name; }); auto* workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter; auto existed = workspace != nullptr; @@ -319,9 +320,8 @@ void I3Ipc::handleGetOutputsEvent(I3IpcEvent* event) { auto object = elem.toObject().toVariantMap(); auto name = object["name"].toString(); - auto monitorIter = std::find_if(mList.begin(), mList.end(), [name](const I3Monitor* m) { - return m->name() == name; - }); + auto monitorIter = + std::ranges::find_if(mList, [name](const I3Monitor* m) { return m->name() == name; }); auto* monitor = monitorIter == mList.end() ? nullptr : *monitorIter; auto existed = monitor != nullptr; @@ -477,25 +477,23 @@ I3Monitor* I3Ipc::monitorFor(QuickshellScreenInfo* screen) { I3Workspace* I3Ipc::findWorkspaceByID(qint32 id) { auto list = this->mWorkspaces.valueList(); auto workspaceIter = - std::find_if(list.begin(), list.end(), [id](const I3Workspace* m) { return m->id() == id; }); + std::ranges::find_if(list, [id](const I3Workspace* m) { return m->id() == id; }); return workspaceIter == list.end() ? nullptr : *workspaceIter; } I3Workspace* I3Ipc::findWorkspaceByName(const QString& name) { auto list = this->mWorkspaces.valueList(); - auto workspaceIter = std::find_if(list.begin(), list.end(), [name](const I3Workspace* m) { - return m->name() == name; - }); + auto workspaceIter = + std::ranges::find_if(list, [name](const I3Workspace* m) { return m->name() == name; }); return workspaceIter == list.end() ? nullptr : *workspaceIter; } I3Monitor* I3Ipc::findMonitorByName(const QString& name) { auto list = this->mMonitors.valueList(); - auto monitorIter = std::find_if(list.begin(), list.end(), [name](const I3Monitor* m) { - return m->name() == name; - }); + auto monitorIter = + std::ranges::find_if(list, [name](const I3Monitor* m) { return m->name() == name; }); return monitorIter == list.end() ? nullptr : *monitorIter; }