diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a2cde00 --- /dev/null +++ b/.clang-format @@ -0,0 +1,58 @@ +--- +BasedOnStyle: LLVM +AccessModifierOffset: 0 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignOperands: Align +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +ColumnLimit: 80 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +FixNamespaceComments: true +IndentCaseLabels: false +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +ReflowComments: false +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++20 +TabWidth: 4 +UseTab: Always diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..cefd2c6 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,31 @@ +--- +Checks: > + -*, + bugprone-*, + clang-analyzer-*, + modernize-*, + -modernize-use-trailing-return-type, + performance-*, + readability-braces-around-statements, + readability-else-after-return, + readability-identifier-naming, + readability-redundant-*, + readability-simplify-*, +CheckOptions: + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.FunctionCase: camelBack + readability-identifier-naming.MemberCase: camelBack + readability-identifier-naming.MemberPrefix: m_ + readability-identifier-naming.MethodCase: camelBack + readability-identifier-naming.NamespaceCase: CamelCase + readability-identifier-naming.ParameterCase: camelBack + readability-identifier-naming.PrivateMemberPrefix: m_ + readability-identifier-naming.StaticConstantCase: UPPER_CASE + readability-identifier-naming.StaticConstantPrefix: k + readability-identifier-naming.VariableCase: camelBack +WarningsAsErrors: "*" +HeaderFilterRegex: ".*" +FormatStyle: file + +... diff --git a/CMakeLists.txt b/CMakeLists.txt index ce22903..a2e2def 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ add_compile_options( if("plugin" IN_LIST ENABLE_MODULES) add_subdirectory(Plugins) + endif() if("shell" IN_LIST ENABLE_MODULES) diff --git a/Modules/Lock/IdleMonitors.qml b/Modules/Lock/IdleMonitors.qml index 26b2854..a26cceb 100644 --- a/Modules/Lock/IdleMonitors.qml +++ b/Modules/Lock/IdleMonitors.qml @@ -2,6 +2,7 @@ pragma ComponentBehavior: Bound import Quickshell import Quickshell.Wayland +import ZShell.Internal import qs.Config import qs.Helpers @@ -29,6 +30,10 @@ Scope { Quickshell.execDetached(action); } + LidWatcher { + onAboutToSleep: root.lock.lock.locked = true + } + Variants { model: Config.general.idle.timeouts diff --git a/Modules/Settings/Categories/Lockscreen.qml b/Modules/Settings/Categories/Lockscreen.qml index d08b8a1..adfa74c 100644 --- a/Modules/Settings/Categories/Lockscreen.qml +++ b/Modules/Settings/Categories/Lockscreen.qml @@ -1,5 +1,6 @@ import qs.Modules.Settings.Categories.Lockscreen import qs.Modules.Settings.Controls +import qs.Helpers import qs.Config SettingsPage { diff --git a/Plugins/ZShell/CMakeLists.txt b/Plugins/ZShell/CMakeLists.txt index c5f041e..f691bc9 100644 --- a/Plugins/ZShell/CMakeLists.txt +++ b/Plugins/ZShell/CMakeLists.txt @@ -50,6 +50,7 @@ qml_module(ZShell Qt::Quick Qt::Concurrent Qt::Sql + Qt::DBus PkgConfig::Qalculate ) diff --git a/Plugins/ZShell/Internal/CMakeLists.txt b/Plugins/ZShell/Internal/CMakeLists.txt index dd353a3..93f1ca9 100644 --- a/Plugins/ZShell/Internal/CMakeLists.txt +++ b/Plugins/ZShell/Internal/CMakeLists.txt @@ -9,6 +9,7 @@ qml_module(ZShell-internal sparklineitem.hpp sparklineitem.cpp arcgauge.hpp arcgauge.cpp wallpaperimage.hpp wallpaperimage.cpp + lidwatcher.hpp lidwatcher.cpp LIBRARIES Qt::Gui Qt::Quick diff --git a/Plugins/ZShell/Internal/lidwatcher.cpp b/Plugins/ZShell/Internal/lidwatcher.cpp new file mode 100644 index 0000000..b6a8773 --- /dev/null +++ b/Plugins/ZShell/Internal/lidwatcher.cpp @@ -0,0 +1,86 @@ +#include "lidwatcher.hpp" + +#include +#include +#include +#include +#include + +Q_LOGGING_CATEGORY(lcLidWatcher, "caelestia.internal.logindmanager", QtInfoMsg) + +namespace ZShell::internal { + +LidWatcher::LidWatcher(QObject* parent) : QObject(parent) { + auto bus = QDBusConnection::systemBus(); + if (!bus.isConnected()) { + qCWarning(lcLidWatcher) + << "Failed to connect to system bus:" << bus.lastError().message(); + return; + } + + bool ok = bus.connect("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "PrepareForSleep", + this, + SLOT(handlePrepareForSleep(bool))); + + if (!ok) { + qCWarning(lcLidWatcher) + << "Failed to connect to PrepareForSleep signal:" + << bus.lastError().message(); + } + + QDBusInterface login1("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + bus); + const QDBusReply reply = login1.call("GetSession", "auto"); + if (!reply.isValid()) { + qCWarning(lcLidWatcher) << "Failed to get session path"; + return; + } + const auto sessionPath = reply.value().path(); + + ok = bus.connect("org.freedesktop.login1", + sessionPath, + "org.freedesktop.login1.Session", + "Lock", + this, + SLOT(handleLockRequested())); + + if (!ok) { + qCWarning(lcLidWatcher) + << "Failed to connect to Lock signal:" << bus.lastError().message(); + } + + ok = bus.connect("org.freedesktop.login1", + sessionPath, + "org.freedesktop.login1.Session", + "Unlock", + this, + SLOT(handleUnlockRequested())); + + if (!ok) { + qCWarning(lcLidWatcher) << "Failed to connect to Unlock signal:" + << bus.lastError().message(); + } +} + +void LidWatcher::handlePrepareForSleep(bool sleep) { + if (sleep) { + emit aboutToSleep(); + } else { + emit resumed(); + } +} + +void LidWatcher::handleLockRequested() { + emit lockRequested(); +} + +void LidWatcher::handleUnlockRequested() { + emit unlockRequested(); +} + +} // namespace ZShell::internal diff --git a/Plugins/ZShell/Internal/lidwatcher.hpp b/Plugins/ZShell/Internal/lidwatcher.hpp new file mode 100644 index 0000000..6a6f4dc --- /dev/null +++ b/Plugins/ZShell/Internal/lidwatcher.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace ZShell::internal { + +class LidWatcher : public QObject { + Q_OBJECT + QML_ELEMENT + + public: + explicit LidWatcher(QObject* parent = nullptr); + + signals: + void aboutToSleep(); + void resumed(); + void lockRequested(); + void unlockRequested(); + + private slots: + void handlePrepareForSleep(bool sleep); + void handleLockRequested(); + void handleUnlockRequested(); +}; + +} // namespace ZShell::internal