clang format

This commit is contained in:
2026-02-09 13:50:26 +01:00
parent e1217305a5
commit ea9ab4b2cb
19 changed files with 66 additions and 67 deletions

View File

@@ -71,11 +71,11 @@ class Timer : public Gtk::Box {
} }
void updateTimeLeft(uint64_t timeValue) { void updateTimeLeft(uint64_t timeValue) {
uint64_t s = timeValue % 100; uint64_t s = timeValue % 100;
uint64_t m = (timeValue / 100) % 100; uint64_t m = (timeValue / 100) % 100;
uint64_t h = timeValue / 10000; uint64_t h = timeValue / 10000;
uint64_t totalSeconds = h * 3600 + m * 60 + s; uint64_t totalSeconds = h * 3600 + m * 60 + s;
this->timeLeft = totalSeconds; this->timeLeft = totalSeconds;
std::ostringstream out; std::ostringstream out;
if (h > 0) { if (h > 0) {

View File

@@ -4,8 +4,8 @@
#include <array> #include <array>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <span>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <span>
#include <string> #include <string>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
@@ -57,7 +57,7 @@ class HyprctlHelper {
int socketFd = socket(AF_UNIX, SOCK_STREAM, 0); int socketFd = socket(AF_UNIX, SOCK_STREAM, 0);
assert(socketFd != -1 && "Failed to create Hyprland command socket"); assert(socketFd != -1 && "Failed to create Hyprland command socket");
struct sockaddr_un addr {}; struct sockaddr_un addr{};
std::memset(&addr, 0, sizeof(addr)); std::memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
@@ -78,7 +78,7 @@ class HyprctlHelper {
std::string response; std::string response;
constexpr size_t kBufferSize = 4096; constexpr size_t kBufferSize = 4096;
std::array<char, kBufferSize> buffer {}; std::array<char, kBufferSize> buffer{};
while (true) { while (true) {
ssize_t bytesRead = recv(socketFd, buffer.data(), buffer.size(), 0); ssize_t bytesRead = recv(socketFd, buffer.data(), buffer.size(), 0);
if (bytesRead <= 0) { if (bytesRead <= 0) {

View File

@@ -46,7 +46,7 @@ class StringHelper {
while (len > 0 && (static_cast<unsigned char>(input[len]) & 0xC0) == 0x80) { while (len > 0 && (static_cast<unsigned char>(input[len]) & 0xC0) == 0x80) {
len--; len--;
} }
return input.substr(0, len) + "..."; return input.substr(0, len) + "...";
} }
}; };

View File

@@ -19,7 +19,6 @@
class HyprlandService { class HyprlandService {
static inline std::shared_ptr<HyprlandService> instance; static inline std::shared_ptr<HyprlandService> instance;
public: public:
struct Client { struct Client {
std::string address; std::string address;
@@ -66,7 +65,7 @@ class HyprlandService {
private: private:
HyprlandService(); HyprlandService();
enum SocketEventType { enum SocketEventType {
WORKSPACE_CHANGED, WORKSPACE_CHANGED,
@@ -92,7 +91,7 @@ class HyprlandService {
{"monitorremoved", MONITOR_REMOVED}, {"monitorremoved", MONITOR_REMOVED},
{"monitoradded", MONITOR_ADDED}, {"monitoradded", MONITOR_ADDED},
}; };
void onWorkspaceChanged(int workspaceId); void onWorkspaceChanged(int workspaceId);
void onFocusedMonitorChanged(std::string monitorData); void onFocusedMonitorChanged(std::string monitorData);
void onOpenWindow(std::string windowData); void onOpenWindow(std::string windowData);

View File

@@ -12,7 +12,7 @@
#include "gdkmm/monitor.h" #include "gdkmm/monitor.h"
class NotificationController { class NotificationController {
inline static std::shared_ptr<NotificationController> instance = nullptr; inline static std::shared_ptr<NotificationController> instance = nullptr;
public: public:
static std::shared_ptr<NotificationController> getInstance() { static std::shared_ptr<NotificationController> getInstance() {

View File

@@ -49,7 +49,6 @@ class TimerService {
} }
ringingTimerCounter++; ringingTimerCounter++;
} }
void removeTimer(uint64_t timerId) { void removeTimer(uint64_t timerId) {

View File

@@ -15,7 +15,6 @@ class BluetoothSettingsRow : public Gtk::Box {
set_spacing(10); set_spacing(10);
set_margin_bottom(6); set_margin_bottom(6);
if (!device.icon.empty()) { if (!device.icon.empty()) {
this->icon.set_from_icon_name(device.icon); this->icon.set_from_icon_name(device.icon);
this->icon.set_pixel_size(24); this->icon.set_pixel_size(24);
@@ -94,16 +93,13 @@ class BluetoothSettings : public Gtk::Box {
std::map<std::string, BluetoothDevice> activeBluetoothDevices; std::map<std::string, BluetoothDevice> activeBluetoothDevices;
std::map<std::string, std::shared_ptr<BluetoothSettingsRow>> deviceRows; std::map<std::string, std::shared_ptr<BluetoothSettingsRow>> deviceRows;
std::shared_ptr<IconButton> powerButton = std::make_shared<IconButton>(Icon::POWER_SETTINGS_NEW); std::shared_ptr<IconButton> powerButton = std::make_shared<IconButton>(Icon::POWER_SETTINGS_NEW);
std::shared_ptr<IconButton> scanButton = std::make_shared<IconButton>(Icon::BLUETOOTH_SEARCHING); std::shared_ptr<IconButton> scanButton = std::make_shared<IconButton>(Icon::BLUETOOTH_SEARCHING);
Gtk::Box connectedDevicesBox; Gtk::Box connectedDevicesBox;
Gtk::Box availableDevicesBox; Gtk::Box availableDevicesBox;
bool bluetoothIsPowered = false; bool bluetoothIsPowered = false;
bool bluetoothIsScanning = false; bool bluetoothIsScanning = false;
void addBluetoothDevice(const BluetoothDevice &device); void addBluetoothDevice(const BluetoothDevice &device);

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#include "components/mediaPlayer.hpp"
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include "components/mediaPlayer.hpp"
#include "connection/dbus/mpris.hpp" #include "connection/dbus/mpris.hpp"
#include "gtkmm/box.h" #include "gtkmm/box.h"

View File

@@ -1,14 +1,16 @@
#pragma once #pragma once
#include <map> #include <map>
#include "connection/dbus/bluetooth.hpp" #include "connection/dbus/bluetooth.hpp"
#include "widgets/controlCenter/bluetoothSettings.hpp" #include "widgets/controlCenter/bluetoothSettings.hpp"
#include "gtkmm/box.h" #include "gtkmm/box.h"
class SettingsWidget : public Gtk::Box { class SettingsWidget : public Gtk::Box {
public: public:
SettingsWidget(); SettingsWidget();
private:
private:
BluetoothSettings bluetoothSettings; BluetoothSettings bluetoothSettings;
}; };

View File

@@ -3,8 +3,10 @@
#include <memory> #include <memory>
#include <sigc++/connection.h> #include <sigc++/connection.h>
#include <sys/types.h> #include <sys/types.h>
#include "components/timer.hpp" #include "components/timer.hpp"
#include "services/timerService.hpp" #include "services/timerService.hpp"
#include "gtkmm/box.h" #include "gtkmm/box.h"
class TimerWidget : public Gtk::Box { class TimerWidget : public Gtk::Box {
@@ -17,7 +19,7 @@ class TimerWidget : public Gtk::Box {
private: private:
std::shared_ptr<TimerService> timerService = TimerService::getInstance(); std::shared_ptr<TimerService> timerService = TimerService::getInstance();
bool updatingText = false; bool updatingText = false;
std::string rawDigits; std::string rawDigits;
std::map<uint64_t, std::unique_ptr<Timer>> activeTimers; std::map<uint64_t, std::unique_ptr<Timer>> activeTimers;

View File

@@ -1,7 +1,6 @@
#include "app.hpp" #include "app.hpp"
int main() int main() {
{
App app; App app;
return app.run(); return app.run();

View File

@@ -1,6 +1,5 @@
#include "components/mediaPlayer.hpp"
#include "components/button/iconButton.hpp" #include "components/button/iconButton.hpp"
#include "components/mediaPlayer.hpp"
#include "helpers/string.hpp" #include "helpers/string.hpp"
#include "services/textureCache.hpp" #include "services/textureCache.hpp"

View File

@@ -16,7 +16,6 @@ Popover::~Popover() {
if (popover) { if (popover) {
popover->popdown(); popover->popdown();
popover->unparent(); popover->unparent();
} }
}; };

View File

@@ -84,7 +84,8 @@ void BluetoothController::pairDevice(const std::string &object_path) {
void BluetoothController::unpairDevice(const std::string &object_path) { void BluetoothController::unpairDevice(const std::string &object_path) {
spdlog::info("Bluetooth: unpairing device {}", object_path); spdlog::info("Bluetooth: unpairing device {}", object_path);
if (!m_adapter_proxy) return; if (!m_adapter_proxy)
return;
auto params = Glib::VariantContainerBase::create_tuple( auto params = Glib::VariantContainerBase::create_tuple(
Glib::Variant<Glib::DBusObjectPathString>::create(object_path)); Glib::Variant<Glib::DBusObjectPathString>::create(object_path));
@@ -148,7 +149,8 @@ void BluetoothController::onBusConnected(const Glib::RefPtr<Gio::AsyncResult> &r
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
void BluetoothController::enumerateObjects() { void BluetoothController::enumerateObjects() {
if (!m_object_manager_proxy) return; if (!m_object_manager_proxy)
return;
try { try {
auto result = m_object_manager_proxy->call_sync("GetManagedObjects"); auto result = m_object_manager_proxy->call_sync("GetManagedObjects");
@@ -230,7 +232,8 @@ void BluetoothController::onObjectManagerSignal(
.get()); .get());
auto ifaces = Glib::VariantBase::cast_dynamic< auto ifaces = Glib::VariantBase::cast_dynamic<
Glib::Variant<std::vector<Glib::ustring>>>(parameters.get_child(1)).get(); Glib::Variant<std::vector<Glib::ustring>>>(parameters.get_child(1))
.get();
for (const auto &iface : ifaces) { for (const auto &iface : ifaces) {
if (iface == "org.bluez.Device1") { if (iface == "org.bluez.Device1") {
@@ -307,7 +310,7 @@ void BluetoothController::onAdapterPropertiesChanged(
void BluetoothController::addDevice(const std::string &path, void BluetoothController::addDevice(const std::string &path,
const PropertiesMap &properties) { const PropertiesMap &properties) {
auto device = parseDeviceProperties(path, properties); auto device = parseDeviceProperties(path, properties);
m_devices[path] = device; m_devices[path] = device;
spdlog::info("Bluetooth device added: {} ({}) {}", device.name, device.address, device.icon); spdlog::info("Bluetooth device added: {} ({}) {}", device.name, device.address, device.icon);
@@ -344,7 +347,8 @@ void BluetoothController::onDevicePropertiesChanged(
const std::vector<Glib::ustring> &) { const std::vector<Glib::ustring> &) {
auto it = m_devices.find(object_path); auto it = m_devices.find(object_path);
if (it == m_devices.end()) return; if (it == m_devices.end())
return;
auto &device = it->second; auto &device = it->second;
@@ -404,10 +408,12 @@ BluetoothDevice BluetoothController::parseDeviceProperties(
return false; return false;
}; };
device.address = getString("Address"); device.address = getString("Address");
device.name = getString("Name"); device.name = getString("Name");
if (device.name.empty()) device.name = getString("Alias"); if (device.name.empty())
if (device.name.empty()) device.name = device.address; device.name = getString("Alias");
if (device.name.empty())
device.name = device.address;
device.icon = getString("Icon"); device.icon = getString("Icon");
device.paired = getBool("Paired"); device.paired = getBool("Paired");
device.connected = getBool("Connected"); device.connected = getBool("Connected");
@@ -429,17 +435,17 @@ void BluetoothController::setDbusProperty(const std::string &object_path,
const std::string &interface, const std::string &interface,
const std::string &property, const std::string &property,
const Glib::VariantBase &value) { const Glib::VariantBase &value) {
if (!connection || object_path.empty()) return; if (!connection || object_path.empty())
return;
try { try {
auto props_proxy = Gio::DBus::Proxy::create_sync( auto props_proxy = Gio::DBus::Proxy::create_sync(
connection, "org.bluez", object_path, "org.freedesktop.DBus.Properties"); connection, "org.bluez", object_path, "org.freedesktop.DBus.Properties");
auto wrapped = Glib::Variant<Glib::VariantBase>::create(value); auto wrapped = Glib::Variant<Glib::VariantBase>::create(value);
auto params = Glib::VariantContainerBase::create_tuple({ auto params = Glib::VariantContainerBase::create_tuple({Glib::Variant<Glib::ustring>::create(interface),
Glib::Variant<Glib::ustring>::create(interface), Glib::Variant<Glib::ustring>::create(property),
Glib::Variant<Glib::ustring>::create(property), wrapped});
wrapped});
props_proxy->call_sync("Set", params); props_proxy->call_sync("Set", params);
} catch (const Glib::Error &ex) { } catch (const Glib::Error &ex) {

View File

@@ -284,26 +284,26 @@ void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) {
void HyprlandService::onMonitorAdded(std::string monitorName) { void HyprlandService::onMonitorAdded(std::string monitorName) {
spdlog::info("[Hyprland] Monitor added: {}", monitorName); spdlog::info("[Hyprland] Monitor added: {}", monitorName);
auto monitorDataJson = HyprctlHelper::getMonitorData(); auto monitorDataJson = HyprctlHelper::getMonitorData();
auto monitorIt = std::ranges::find_if(monitorDataJson, auto monitorIt = std::ranges::find_if(monitorDataJson,
[&monitorName](const auto &item) { [&monitorName](const auto &item) {
return item.contains("name") && item["name"] == monitorName; return item.contains("name") && item["name"] == monitorName;
}); });
if (monitorIt == monitorDataJson.end()) { if (monitorIt == monitorDataJson.end()) {
spdlog::warn("[Hyprland] Monitor data not found for {}", monitorName); spdlog::warn("[Hyprland] Monitor data not found for {}", monitorName);
return; return;
} }
auto monitorPtr = std::make_shared<Monitor>(); auto monitorPtr = std::make_shared<Monitor>();
monitorPtr->id = (*monitorIt)["id"]; monitorPtr->id = (*monitorIt)["id"];
monitorPtr->name = monitorName; monitorPtr->name = monitorName;
monitorPtr->activeWorkspaceId = (*monitorIt)["activeWorkspace"]["id"]; monitorPtr->activeWorkspaceId = (*monitorIt)["activeWorkspace"]["id"];
monitorPtr->focused = (*monitorIt)["focused"]; monitorPtr->focused = (*monitorIt)["focused"];
this->monitors[monitorName] = monitorPtr; this->monitors[monitorName] = monitorPtr;
auto onClick = sigc::mem_fun(*this, &HyprlandService::switchToWorkspace); auto onClick = sigc::mem_fun(*this, &HyprlandService::switchToWorkspace);
for (int i = 1; i <= NUM_WORKSPACES; i++) { for (int i = 1; i <= NUM_WORKSPACES; i++) {
auto state = std::make_shared<WorkspaceData>(); auto state = std::make_shared<WorkspaceData>();
int workspaceId = i + (NUM_WORKSPACES * monitorPtr->id); int workspaceId = i + (NUM_WORKSPACES * monitorPtr->id);
state->id = workspaceId; state->id = workspaceId;
@@ -337,7 +337,7 @@ void HyprlandService::onMonitorAdded(std::string monitorName) {
if (this->clients.find(address) != this->clients.end()) { if (this->clients.find(address) != this->clients.end()) {
continue; continue;
} }
int workspaceId = client["workspace"]["id"].get<int>(); int workspaceId = client["workspace"]["id"].get<int>();
auto workspaceIt = workspaces.find(workspaceId); auto workspaceIt = workspaces.find(workspaceId);
if (workspaceIt == workspaces.end()) { if (workspaceIt == workspaces.end()) {
continue; continue;
@@ -413,7 +413,7 @@ void HyprlandService::onActiveWindowChanged(std::string windowAddress) {
} }
std::shared_ptr<Gtk::Box> HyprlandService::getWorkspaceIndicatorsForMonitor(std::string monitorName) { std::shared_ptr<Gtk::Box> HyprlandService::getWorkspaceIndicatorsForMonitor(std::string monitorName) {
auto box = std::make_shared<Gtk::Box>(Gtk::Orientation::HORIZONTAL); auto box = std::make_shared<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
auto monitorIt = monitors.find(monitorName); auto monitorIt = monitors.find(monitorName);
if (monitorIt == monitors.end()) { if (monitorIt == monitors.end()) {
return box; return box;
@@ -434,7 +434,7 @@ void HyprlandService::switchToWorkspace(int workspaceId) {
void HyprlandService::refreshIndicator(std::shared_ptr<Workspace> workspace) { void HyprlandService::refreshIndicator(std::shared_ptr<Workspace> workspace) {
auto view = workspace->view; auto view = workspace->view;
auto state = workspace->state; auto state = workspace->state;
auto monitorIt = monitors.find(state->monitorName); auto monitorIt = monitors.find(state->monitorName);
if (monitorIt == monitors.end()) { if (monitorIt == monitors.end()) {
return; return;

View File

@@ -154,7 +154,7 @@ void NotificationController::closeNotification(uint64_t notificationId) {
} }
void NotificationController::addMonitor(std::shared_ptr<Gdk::Monitor> monitor) { void NotificationController::addMonitor(std::shared_ptr<Gdk::Monitor> monitor) {
auto name = monitor->get_connector(); auto name = monitor->get_connector();
this->activeMonitors[name] = monitor; this->activeMonitors[name] = monitor;
} }

View File

@@ -24,9 +24,9 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->tabRow.set_margin_bottom(4); this->tabRow.set_margin_bottom(4);
this->tabRow.add_css_class("control-center-tab-row"); this->tabRow.add_css_class("control-center-tab-row");
this->mediaTabButton = std::make_unique<TabButton>(Icon::PLAY_CIRCLE); this->mediaTabButton = std::make_unique<TabButton>(Icon::PLAY_CIRCLE);
this->infoTabButton = std::make_unique<TabButton>(Icon::EMPTY_DASHBOARD); this->infoTabButton = std::make_unique<TabButton>(Icon::EMPTY_DASHBOARD);
this->timerButton = std::make_unique<TabButton>(Icon::TOKEN); this->timerButton = std::make_unique<TabButton>(Icon::TOKEN);
this->settingsTabButton = std::make_unique<TabButton>(Icon::SETTINGS); this->settingsTabButton = std::make_unique<TabButton>(Icon::SETTINGS);
this->tabRow.append(*this->mediaTabButton); this->tabRow.append(*this->mediaTabButton);
@@ -41,9 +41,9 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE); this->contentStack.set_transition_type(Gtk::StackTransitionType::CROSSFADE);
this->mediaControlWidget = std::make_unique<MediaWidget>(); this->mediaControlWidget = std::make_unique<MediaWidget>();
this->weatherWidget = std::make_unique<WeatherWidget>(); this->weatherWidget = std::make_unique<WeatherWidget>();
this->timerWidget = std::make_unique<TimerWidget>(); this->timerWidget = std::make_unique<TimerWidget>();
this->settingsWidget = std::make_unique<SettingsWidget>(); this->settingsWidget = std::make_unique<SettingsWidget>();
this->contentStack.add(*this->mediaControlWidget, "controls", "Controls"); this->contentStack.add(*this->mediaControlWidget, "controls", "Controls");
this->contentStack.add(*this->weatherWidget, "info", "Info"); this->contentStack.add(*this->weatherWidget, "info", "Info");
@@ -87,4 +87,3 @@ void ControlCenter::setActiveTab(const std::string &tab_name) {
this->timerButton->setActive(true); this->timerButton->setActive(true);
} }
} }

View File

@@ -33,7 +33,7 @@ void MediaWidget::addPlayerWidget(const std::string &bus_name) {
auto controller = MprisController::createForPlayer(bus_name); auto controller = MprisController::createForPlayer(bus_name);
auto widget = std::make_unique<MediaPlayer>(controller); auto widget = std::make_unique<MediaPlayer>(controller);
this->mediaWidgets.emplace(bus_name, std::move(widget)); this->mediaWidgets.emplace(bus_name, std::move(widget));
this->container.append(*this->mediaWidgets[bus_name]); this->container.append(*this->mediaWidgets[bus_name]);
} }
@@ -44,7 +44,7 @@ void MediaWidget::removePlayerWidget(const std::string &bus_name) {
if (it == this->mediaWidgets.end()) { if (it == this->mediaWidgets.end()) {
return; return;
} }
this->container.remove(*it->second); this->container.remove(*it->second);
this->mediaWidgets.erase(it); this->mediaWidgets.erase(it);
} }

View File

@@ -6,7 +6,6 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sys/types.h> #include <sys/types.h>
#include "gtkmm/entry.h" #include "gtkmm/entry.h"
#include "gtkmm/eventcontrollerkey.h" #include "gtkmm/eventcontrollerkey.h"
#include "gtkmm/label.h" #include "gtkmm/label.h"