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,115 @@
#pragma once
#include "components/button/iconButton.hpp"
#include "connection/dbus/bluetooth.hpp"
#include "gtkmm/box.h"
#include "gtkmm/button.h"
#include "gtkmm/image.h"
#include "gtkmm/label.h"
class BluetoothSettingsRow : public Gtk::Box {
public:
BluetoothSettingsRow(const BluetoothDevice &device) : device(device) {
set_orientation(Gtk::Orientation::HORIZONTAL);
set_spacing(10);
set_margin_bottom(6);
if (!device.icon.empty()) {
this->icon.set_from_icon_name(device.icon);
this->icon.set_pixel_size(24);
append(this->icon);
}
nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name);
nameLabel.set_halign(Gtk::Align::START);
nameLabel.set_valign(Gtk::Align::CENTER);
append(nameLabel);
addressLabel.set_text(device.address);
addressLabel.set_halign(Gtk::Align::START);
addressLabel.set_valign(Gtk::Align::CENTER);
addressLabel.add_css_class("bluetooth-device-address");
append(addressLabel);
pairButton.set_label(device.paired ? "Unpair" : "Pair");
pairButton.signal_clicked().connect([device]() {
if (device.paired) {
BluetoothController::getInstance()->unpairDevice(device.object_path);
} else {
BluetoothController::getInstance()->pairDevice(device.object_path);
}
});
append(pairButton);
connectButton.set_label(device.connected ? "Disconnect" : "Connect");
connectButton.signal_clicked().connect([device]() {
if (device.connected) {
BluetoothController::getInstance()->disconnectDevice(device.object_path);
} else {
BluetoothController::getInstance()->connectDevice(device.object_path);
}
});
append(connectButton);
trustButton.set_label(device.trusted ? "Distrust" : "Trust");
trustButton.signal_clicked().connect([device]() {
BluetoothController::getInstance()->trustDevice(device.object_path, !device.trusted);
});
append(trustButton);
}
void updateDevice(const BluetoothDevice &device) {
this->device = device;
if (!device.icon.empty()) {
this->icon.set_from_icon_name(device.icon);
}
nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name);
addressLabel.set_text(device.address);
pairButton.set_label(device.paired ? "Unpair" : "Pair");
connectButton.set_label(device.connected ? "Disconnect" : "Connect");
trustButton.set_label(device.trusted ? "Distrust" : "Trust");
}
private:
BluetoothDevice device;
Gtk::Image icon;
Gtk::Label nameLabel;
Gtk::Label addressLabel;
Gtk::Button pairButton;
Gtk::Button connectButton;
Gtk::Button trustButton;
};
class BluetoothSettings : public Gtk::Box {
public:
BluetoothSettings();
private:
std::shared_ptr<BluetoothController> bluetoothController = BluetoothController::getInstance();
std::map<std::string, BluetoothDevice> activeBluetoothDevices;
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> scanButton = std::make_shared<IconButton>(Icon::BLUETOOTH_SEARCHING);
Gtk::Box connectedDevicesBox;
Gtk::Box availableDevicesBox;
bool bluetoothIsPowered = false;
bool bluetoothIsScanning = false;
void addBluetoothDevice(const BluetoothDevice &device);
void removeBluetoothDevice(const std::string &object_path);
void updateBluetoothDevice(const BluetoothDevice &device);
void setBluetoothPowered(bool powered);
void setScanning(bool scanning);
};

View File

@@ -6,6 +6,7 @@
#include "components/button/tabButton.hpp"
#include "components/popover.hpp"
#include "widgets/controlCenter/mediaWidget.hpp"
#include "widgets/controlCenter/settings.hpp"
#include "widgets/controlCenter/timer.hpp"
#include "widgets/weather.hpp"
@@ -27,10 +28,12 @@ class ControlCenter : public Popover {
std::unique_ptr<TabButton> mediaTabButton;
std::unique_ptr<TabButton> infoTabButton;
std::unique_ptr<TabButton> timerButton;
std::unique_ptr<TabButton> settingsTabButton;
std::unique_ptr<WeatherWidget> weatherWidget;
std::unique_ptr<MediaWidget> mediaControlWidget;
std::unique_ptr<TimerWidget> timerWidget;
std::unique_ptr<SettingsWidget> settingsWidget;
void addPlayerWidget(const std::string &bus_name);
void removePlayerWidget(const std::string &bus_name);

View File

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

View File

@@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include <sigc++/connection.h>
#include <sys/types.h>
#include "components/timer.hpp"
#include "services/timerService.hpp"
@@ -9,6 +10,7 @@
class TimerWidget : public Gtk::Box {
public:
TimerWidget();
~TimerWidget();
void addTimer(const std::string &duration, uint64_t timerId);
void removeTimer(uint64_t timerId);
void activateTimer(uint64_t timerId);
@@ -19,4 +21,8 @@ class TimerWidget : public Gtk::Box {
std::string rawDigits;
std::map<uint64_t, std::unique_ptr<Timer>> activeTimers;
sigc::connection timerSetConnection;
sigc::connection timerCancelledConnection;
sigc::connection timerExpiredConnection;
sigc::connection tickConnection;
};