Skip to content

Commit 6221797

Browse files
power buttons + clang format (#15)
* feat(greeter): add power actions * feat(greeter): display 3 power action buttons * feat(nix): add devshell * .gitignore: copy from noctalia * clang-format: copy from noctalia * chore: format
1 parent 0c7c3f9 commit 6221797

115 files changed

Lines changed: 5123 additions & 5215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 2
3+
ColumnLimit: 120
4+
PointerAlignment: Left
5+
NamespaceIndentation: All
6+
AlignAfterOpenBracket: BlockIndent
7+
AlignOperands: DontAlign
8+
BreakBeforeBinaryOperators: NonAssignment
9+
BreakBinaryOperations: RespectPrecedence
10+
SortIncludes: CaseSensitive
11+
IncludeBlocks: Regroup
12+
IncludeCategories:
13+
- Regex: '^".*"'
14+
Priority: 1
15+
- Regex: '^<.*>'
16+
Priority: 2

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build
2+
build*/
3+
cmake-build-*/
4+
compile_commands.json
5+
6+
# Python cache
7+
__pycache__
8+
9+
# Compiled binary
10+
noctalia
11+
12+
# Editor / IDE
13+
.vscode/
14+
.idea/
15+
.cache/
16+
*.swp
17+
*.swo
18+
*~
19+
20+
# OS
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Nix
25+
.envrc
26+
.direnv/
27+
result/
28+
result
29+
result-*

flake.nix

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@
3333
default = pkgs.callPackage ./nix/package.nix {};
3434
}
3535
);
36-
36+
37+
devShells = forEachSystem (
38+
{
39+
pkgs,
40+
system,
41+
}: {
42+
default = pkgs.callPackage ./nix/devshell.nix {
43+
noctalia-greeter = self.packages.${system}.default;
44+
};
45+
}
46+
);
47+
3748
nixosModules.default = {
3849
pkgs,
3950
lib,

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ _greeter_sources = files(
159159
'src/greeter/greeter_surface.cpp',
160160
'src/greeter/greeter_window.cpp',
161161
'src/greeter/logind_resume.cpp',
162+
'src/greeter/power_actions.cpp',
162163
'src/greeter/greeter.cpp',
163164
'src/main.cpp',
164165
) + _protocol_sources

nix/devshell.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
pkgs,
3+
noctalia-greeter,
4+
}:
5+
pkgs.mkShell {
6+
inputsFrom = [noctalia-greeter];
7+
8+
nativeBuildInputs = with pkgs; [
9+
# Workflow & Hooks
10+
just
11+
lefthook
12+
13+
# Formatting & linting (required by Justfile)
14+
llvmPackages_22.clang-tools
15+
cppcheck
16+
gnugrep
17+
gnused
18+
findutils
19+
20+
# Debugging
21+
gdb
22+
];
23+
24+
shellHook = ''
25+
echo " Noctalia greeter dev-shell | 'just --list' to see available tasks"
26+
'';
27+
}

src/accounts/accounts_icon.cpp

Lines changed: 96 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,120 +8,114 @@
88

99
namespace accounts {
1010

11-
namespace {
12-
13-
std::optional<GVariant *> dbusUserProperty(GDBusConnection *connection,
14-
const char *userPath,
15-
const char *propertyName) {
16-
GError *error = nullptr;
17-
GVariant *result = g_dbus_connection_call_sync(
18-
connection, "org.freedesktop.Accounts", userPath,
19-
"org.freedesktop.DBus.Properties", "Get",
20-
g_variant_new("(ss)", "org.freedesktop.Accounts.User", propertyName),
21-
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, 5000, nullptr, &error);
22-
if (result == nullptr) {
23-
if (error != nullptr) {
24-
g_error_free(error);
11+
namespace {
12+
13+
std::optional<GVariant*>
14+
dbusUserProperty(GDBusConnection* connection, const char* userPath, const char* propertyName) {
15+
GError* error = nullptr;
16+
GVariant* result = g_dbus_connection_call_sync(
17+
connection, "org.freedesktop.Accounts", userPath, "org.freedesktop.DBus.Properties", "Get",
18+
g_variant_new("(ss)", "org.freedesktop.Accounts.User", propertyName), G_VARIANT_TYPE("(v)"),
19+
G_DBUS_CALL_FLAGS_NONE, 5000, nullptr, &error
20+
);
21+
if (result == nullptr) {
22+
if (error != nullptr) {
23+
g_error_free(error);
24+
}
25+
return std::nullopt;
26+
}
27+
28+
GVariant* wrapped = nullptr;
29+
g_variant_get(result, "(v)", &wrapped);
30+
g_variant_unref(result);
31+
return wrapped;
2532
}
26-
return std::nullopt;
27-
}
2833

29-
GVariant *wrapped = nullptr;
30-
g_variant_get(result, "(v)", &wrapped);
31-
g_variant_unref(result);
32-
return wrapped;
33-
}
34-
35-
std::optional<std::string> dbusUserStringProperty(GDBusConnection *connection,
36-
const char *userPath,
37-
const char *propertyName) {
38-
const auto property = dbusUserProperty(connection, userPath, propertyName);
39-
if (!property.has_value()) {
40-
return std::nullopt;
41-
}
34+
std::optional<std::string>
35+
dbusUserStringProperty(GDBusConnection* connection, const char* userPath, const char* propertyName) {
36+
const auto property = dbusUserProperty(connection, userPath, propertyName);
37+
if (!property.has_value()) {
38+
return std::nullopt;
39+
}
40+
41+
std::optional<std::string> value;
42+
if (g_variant_is_of_type(*property, G_VARIANT_TYPE_STRING)) {
43+
const char* text = g_variant_get_string(*property, nullptr);
44+
if (text != nullptr && text[0] != '\0') {
45+
value = text;
46+
}
47+
}
48+
g_variant_unref(*property);
49+
return value;
50+
}
4251

43-
std::optional<std::string> value;
44-
if (g_variant_is_of_type(*property, G_VARIANT_TYPE_STRING)) {
45-
const char *text = g_variant_get_string(*property, nullptr);
46-
if (text != nullptr && text[0] != '\0') {
47-
value = text;
52+
std::optional<std::uint64_t>
53+
dbusUserUint64Property(GDBusConnection* connection, const char* userPath, const char* propertyName) {
54+
const auto property = dbusUserProperty(connection, userPath, propertyName);
55+
if (!property.has_value()) {
56+
return std::nullopt;
57+
}
58+
59+
std::optional<std::uint64_t> value;
60+
if (g_variant_is_of_type(*property, G_VARIANT_TYPE_UINT64)) {
61+
value = g_variant_get_uint64(*property);
62+
}
63+
g_variant_unref(*property);
64+
return value;
4865
}
49-
}
50-
g_variant_unref(*property);
51-
return value;
52-
}
53-
54-
std::optional<std::uint64_t> dbusUserUint64Property(GDBusConnection *connection,
55-
const char *userPath,
56-
const char *propertyName) {
57-
const auto property = dbusUserProperty(connection, userPath, propertyName);
58-
if (!property.has_value()) {
59-
return std::nullopt;
60-
}
6166

62-
std::optional<std::uint64_t> value;
63-
if (g_variant_is_of_type(*property, G_VARIANT_TYPE_UINT64)) {
64-
value = g_variant_get_uint64(*property);
65-
}
66-
g_variant_unref(*property);
67-
return value;
68-
}
69-
70-
[[nodiscard]] bool iconPathReadable(const std::string &path) {
71-
std::error_code ec;
72-
return !path.empty() && std::filesystem::is_regular_file(path, ec) && !ec;
73-
}
74-
75-
} // namespace
76-
77-
std::optional<std::string> iconFileForUid(const uid_t uid) {
78-
GError *error = nullptr;
79-
GDBusConnection *connection =
80-
g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
81-
if (connection == nullptr) {
82-
if (error != nullptr) {
83-
g_error_free(error);
67+
[[nodiscard]] bool iconPathReadable(const std::string& path) {
68+
std::error_code ec;
69+
return !path.empty() && std::filesystem::is_regular_file(path, ec) && !ec;
8470
}
85-
return std::nullopt;
86-
}
8771

88-
GVariant *result = g_dbus_connection_call_sync(
89-
connection, "org.freedesktop.Accounts", "/org/freedesktop/Accounts",
90-
"org.freedesktop.Accounts", "FindUserById",
91-
g_variant_new("(x)", static_cast<gint64>(uid)), G_VARIANT_TYPE("(o)"),
92-
G_DBUS_CALL_FLAGS_NONE, 5000, nullptr, &error);
93-
if (result == nullptr) {
94-
if (error != nullptr) {
95-
g_error_free(error);
72+
} // namespace
73+
74+
std::optional<std::string> iconFileForUid(const uid_t uid) {
75+
GError* error = nullptr;
76+
GDBusConnection* connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
77+
if (connection == nullptr) {
78+
if (error != nullptr) {
79+
g_error_free(error);
80+
}
81+
return std::nullopt;
9682
}
97-
g_object_unref(connection);
98-
return std::nullopt;
99-
}
10083

101-
const char *userPath = nullptr;
102-
g_variant_get(result, "(&o)", &userPath);
103-
const std::string userObjectPath = userPath != nullptr ? userPath : "";
104-
g_variant_unref(result);
105-
if (userObjectPath.empty()) {
106-
g_object_unref(connection);
107-
return std::nullopt;
108-
}
84+
GVariant* result = g_dbus_connection_call_sync(
85+
connection, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", "FindUserById",
86+
g_variant_new("(x)", static_cast<gint64>(uid)), G_VARIANT_TYPE("(o)"), G_DBUS_CALL_FLAGS_NONE, 5000, nullptr,
87+
&error
88+
);
89+
if (result == nullptr) {
90+
if (error != nullptr) {
91+
g_error_free(error);
92+
}
93+
g_object_unref(connection);
94+
return std::nullopt;
95+
}
10996

110-
const std::optional<std::uint64_t> reportedUid =
111-
dbusUserUint64Property(connection, userObjectPath.c_str(), "Uid");
112-
if (!reportedUid.has_value() || static_cast<uid_t>(*reportedUid) != uid) {
113-
g_object_unref(connection);
114-
return std::nullopt;
115-
}
97+
const char* userPath = nullptr;
98+
g_variant_get(result, "(&o)", &userPath);
99+
const std::string userObjectPath = userPath != nullptr ? userPath : "";
100+
g_variant_unref(result);
101+
if (userObjectPath.empty()) {
102+
g_object_unref(connection);
103+
return std::nullopt;
104+
}
116105

117-
const std::optional<std::string> iconFile =
118-
dbusUserStringProperty(connection, userObjectPath.c_str(), "IconFile");
119-
g_object_unref(connection);
106+
const std::optional<std::uint64_t> reportedUid = dbusUserUint64Property(connection, userObjectPath.c_str(), "Uid");
107+
if (!reportedUid.has_value() || static_cast<uid_t>(*reportedUid) != uid) {
108+
g_object_unref(connection);
109+
return std::nullopt;
110+
}
120111

121-
if (!iconFile.has_value() || !iconPathReadable(*iconFile)) {
122-
return std::nullopt;
112+
const std::optional<std::string> iconFile = dbusUserStringProperty(connection, userObjectPath.c_str(), "IconFile");
113+
g_object_unref(connection);
114+
115+
if (!iconFile.has_value() || !iconPathReadable(*iconFile)) {
116+
return std::nullopt;
117+
}
118+
return iconFile;
123119
}
124-
return iconFile;
125-
}
126120

127121
} // namespace accounts

src/accounts/accounts_icon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace accounts {
88

9-
// Returns a readable IconFile path for uid from org.freedesktop.Accounts.
10-
[[nodiscard]] std::optional<std::string> iconFileForUid(uid_t uid);
9+
// Returns a readable IconFile path for uid from org.freedesktop.Accounts.
10+
[[nodiscard]] std::optional<std::string> iconFileForUid(uid_t uid);
1111

1212
} // namespace accounts

src/core/key_modifiers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <cstdint>
44

55
namespace KeyMod {
6-
inline constexpr std::uint32_t Shift = 1u << 0;
7-
inline constexpr std::uint32_t Ctrl = 1u << 1;
8-
inline constexpr std::uint32_t Alt = 1u << 2;
9-
inline constexpr std::uint32_t Super = 1u << 3;
6+
inline constexpr std::uint32_t Shift = 1u << 0;
7+
inline constexpr std::uint32_t Ctrl = 1u << 1;
8+
inline constexpr std::uint32_t Alt = 1u << 2;
9+
inline constexpr std::uint32_t Super = 1u << 3;
1010
} // namespace KeyMod

0 commit comments

Comments
 (0)