fix bar crashing on monitor add/remove

This commit is contained in:
2026-02-09 13:49:52 +01:00
parent a90d1c2f6c
commit e1217305a5
30 changed files with 1186 additions and 247 deletions

View File

@@ -0,0 +1,81 @@
#include "widgets/controlCenter/bluetoothSettings.hpp"
#include <memory>
void BluetoothSettings::setBluetoothPowered(bool powered) {
this->bluetoothIsPowered = powered;
if (powered) {
powerButton->remove_css_class("power-button-off");
powerButton->add_css_class("power-button-on");
powerButton->set_tooltip_text("Turn Bluetooth Off");
} else {
powerButton->remove_css_class("power-button-on");
powerButton->add_css_class("power-button-off");
powerButton->set_tooltip_text("Turn Bluetooth On");
}
}
void BluetoothSettings::setScanning(bool scanning) {
this->bluetoothIsScanning = scanning;
if (scanning) {
scanButton->add_css_class("power-button-on");
scanButton->remove_css_class("power-button-off");
scanButton->set_tooltip_text("Stop Scanning");
} else {
scanButton->remove_css_class("power-button-on");
scanButton->add_css_class("power-button-off");
scanButton->set_tooltip_text("Start Scanning");
}
}
BluetoothSettings::BluetoothSettings() : bluetoothIsPowered(this->bluetoothController->isPowered()) {
set_orientation(Gtk::Orientation::VERTICAL);
set_spacing(12);
auto devices = this->bluetoothController->getDevices();
powerButton->add_css_class("power-button");
setBluetoothPowered(bluetoothIsPowered);
powerButton->set_tooltip_text(bluetoothIsPowered ? "Turn Bluetooth Off" : "Turn Bluetooth On");
powerButton->signal_clicked().connect([this]() {
bluetoothIsPowered = !bluetoothIsPowered;
this->bluetoothController->setPowered(bluetoothIsPowered);
});
append(*powerButton);
this->bluetoothController->signalPoweredChanged().connect([this](bool powered) {
bluetoothIsPowered = powered;
setBluetoothPowered(powered);
});
for (const auto &device : devices) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
append(*row);
}
bluetoothController->signalDeviceAdded().connect([this](const BluetoothDevice &device) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
append(*row);
});
bluetoothController->signalDeviceRemoved().connect([this](const std::string &object_path) {
auto it = deviceRows.find(object_path);
if (it != deviceRows.end()) {
remove(*it->second);
deviceRows.erase(it);
}
});
bluetoothController->signalDeviceChanged().connect([this](const BluetoothDevice &device) {
auto it = deviceRows.find(device.object_path);
if (it != deviceRows.end()) {
it->second->updateDevice(device);
}
});
}

View File

@@ -27,10 +27,12 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->mediaTabButton = std::make_unique<TabButton>(Icon::PLAY_CIRCLE);
this->infoTabButton = std::make_unique<TabButton>(Icon::EMPTY_DASHBOARD);
this->timerButton = std::make_unique<TabButton>(Icon::TOKEN);
this->settingsTabButton = std::make_unique<TabButton>(Icon::SETTINGS);
this->tabRow.append(*this->mediaTabButton);
this->tabRow.append(*this->infoTabButton);
this->tabRow.append(*this->timerButton);
this->tabRow.append(*this->settingsTabButton);
this->container.append(this->tabRow);
@@ -41,10 +43,12 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->mediaControlWidget = std::make_unique<MediaWidget>();
this->weatherWidget = std::make_unique<WeatherWidget>();
this->timerWidget = std::make_unique<TimerWidget>();
this->settingsWidget = std::make_unique<SettingsWidget>();
this->contentStack.add(*this->mediaControlWidget, "controls", "Controls");
this->contentStack.add(*this->weatherWidget, "info", "Info");
this->contentStack.add(*this->timerWidget, "timer", "Timer");
this->contentStack.add(*this->settingsWidget, "settings", "Settings");
this->contentStack.set_visible_child("controls");
this->setActiveTab("controls");
@@ -63,6 +67,9 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->setActiveTab("timer");
});
this->settingsTabButton->signal_clicked().connect([this]() {
this->setActiveTab("settings");
});
}
void ControlCenter::setActiveTab(const std::string &tab_name) {

View File

@@ -0,0 +1,8 @@
#include "widgets/controlCenter/settings.hpp"
SettingsWidget::SettingsWidget() {
set_orientation(Gtk::Orientation::VERTICAL);
set_spacing(12);
this->append(this->bluetoothSettings);
}

View File

@@ -15,19 +15,19 @@ TimerWidget::TimerWidget() {
set_orientation(Gtk::Orientation::VERTICAL);
set_spacing(6);
this->timerService->getSignalTimerSet().connect([this](const std::string &duration, uint64_t timerId) {
this->timerSetConnection = this->timerService->getSignalTimerSet().connect([this](const std::string &duration, uint64_t timerId) {
this->addTimer(duration, timerId);
});
this->timerService->getSignalTimerCancelled().connect([this](uint64_t timerId) {
this->timerCancelledConnection = this->timerService->getSignalTimerCancelled().connect([this](uint64_t timerId) {
this->removeTimer(timerId);
});
this->timerService->getSignalTimerExpired().connect([this](uint64_t timerId) {
this->timerExpiredConnection = this->timerService->getSignalTimerExpired().connect([this](uint64_t timerId) {
this->activateTimer(timerId);
});
this->timerService->tickSignal.connect([this]() {
this->tickConnection = this->timerService->tickSignal.connect([this]() {
for (auto &[id, timer] : activeTimers) {
timer->tickDown();
}
@@ -101,6 +101,21 @@ TimerWidget::TimerWidget() {
append(*entry);
}
TimerWidget::~TimerWidget() {
if (this->timerSetConnection.connected()) {
this->timerSetConnection.disconnect();
}
if (this->timerCancelledConnection.connected()) {
this->timerCancelledConnection.disconnect();
}
if (this->timerExpiredConnection.connected()) {
this->timerExpiredConnection.disconnect();
}
if (this->tickConnection.connected()) {
this->tickConnection.disconnect();
}
};
void TimerWidget::addTimer(const std::string &duration, uint64_t timerId) {
std::unique_ptr<Timer> timer = std::make_unique<Timer>(duration, timerId);