refactor and shizz

This commit is contained in:
2025-12-25 21:13:00 +01:00
parent a06c96f648
commit 9b5db719cb
27 changed files with 286 additions and 312 deletions

View File

@@ -19,9 +19,9 @@ class App {
private:
Glib::RefPtr<Gtk::Application> app;
std::vector<Bar *> bars;
HyprlandService hyprlandService;
HyprlandService *hyprlandService = HyprlandService::getInstance();
NotificationService notificationService;
TrayService trayService;
TrayService *trayService = TrayService::getInstance();
void setupServices();
};

View File

@@ -4,8 +4,6 @@
#include <gtkmm.h>
#include "icons.hpp"
#include "services/hyprland.hpp"
#include "services/tray.hpp"
#include "widgets/clock.hpp"
#include "widgets/date.hpp"
#include "widgets/tray.hpp"
@@ -16,17 +14,16 @@
class Bar : public Gtk::Window {
public:
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, int monitorId);
Bar(GdkMonitor *monitor, int monitorId);
private:
int monitorId;
protected:
Gtk::CenterBox main_box{};
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
Gtk::Box right_box{Gtk::Orientation::HORIZONTAL};
private:
int monitorId;
Clock clock;
Date date;
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
@@ -36,8 +33,6 @@ class Bar : public Gtk::Window {
TrayWidget *trayWidget = nullptr;
VolumeWidget *volumeWidget = nullptr;
TrayService &trayService;
HyprlandService &hyprlandService;
void setup_ui();
void setup_left_box();

View File

@@ -0,0 +1,18 @@
#pragma once
#include <gtkmm/button.h>
#include "gtkmm/image.h"
#include "sigc++/signal.h"
class Button : public Gtk::Button {
public:
Button(const std::string label);
Button(Gtk::Image &image);
sigc::signal<void()> onClickedSignal;
private:
void on_clicked() {
onClickedSignal.emit();
}
};

View File

@@ -3,10 +3,11 @@
#include <gtkmm/button.h>
#include <gtkmm/popover.h>
#include <string>
#include "components/base/button.hpp"
class Popover : public Gtk::Button {
class Popover : public Button {
public:
Popover(std::string icon, std::string name);
Popover(const std::string icon, std::string name);
~Popover() override;
protected:

View File

@@ -7,7 +7,6 @@
class TodoEntry : public Gtk::Box {
public:
TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited);
~TodoEntry() override;
int get_id() const { return id; }
std::string get_text() const { return text; }

View File

@@ -8,15 +8,13 @@
#include "sigc++/signal.h"
class BluetoothService {
static BluetoothService *instance;
inline static BluetoothService *instance = nullptr;
public:
sigc::signal<void(bool)> powerStateChangedSignal;
sigc::signal<void(bool)> isDiscoveringChangedSignal;
bool getPowerState();
bool getIsDiscovering();
void togglePowerState();

View File

@@ -5,9 +5,12 @@
#include <map>
#include <sigc++/sigc++.h>
#include <string>
#include <sys/stat.h>
#include <vector>
class HyprlandService {
inline static HyprlandService *instance = nullptr;
public:
static constexpr int kWorkspaceSlotCount = 7;
const char *kMonitorCommand = "hyprctl monitors -j";
@@ -36,9 +39,6 @@ class HyprlandService {
int focusedWorkspaceId = -1;
};
HyprlandService();
~HyprlandService();
void start();
void on_hyprland_event(std::string event, std::string data);
void printMonitor(const Monitor &mon) const;
@@ -55,11 +55,21 @@ class HyprlandService {
return this->workspaces;
}
static HyprlandService *getInstance() {
if (HyprlandService::instance == nullptr) {
HyprlandService::instance = new HyprlandService();
}
return HyprlandService::instance;
}
private:
HyprlandService();
~HyprlandService();
int fd = -1;
std::map<int, Monitor> monitors;
std::map<int, WorkspaceState *> workspaces;
// persistent buffer for socket reads to handle partial messages
std::string socket_buffer;
std::string get_socket_path();

View File

@@ -16,6 +16,7 @@
#include <vector>
class TrayService {
inline static TrayService *instance = nullptr;
public:
struct Item {
std::string id;
@@ -29,9 +30,6 @@ class TrayService {
Glib::RefPtr<Gdk::Paintable> iconPaintable;
};
TrayService();
~TrayService();
void start();
void stop();
@@ -44,7 +42,6 @@ class TrayService {
Glib::RefPtr<Gio::MenuModel> get_menu_model(const std::string &id);
Glib::RefPtr<Gio::ActionGroup> get_menu_action_group(const std::string &id);
void debug_dump_menu_layout(const std::string &id);
struct MenuNode {
int id = 0;
std::string label;
@@ -60,7 +57,18 @@ class TrayService {
sigc::signal<void(const std::string &)> &signal_item_removed();
sigc::signal<void(const Item &)> &signal_item_updated();
static TrayService *getInstance() {
if (TrayService::instance == nullptr) {
TrayService::instance = new TrayService();
}
return TrayService::instance;
}
private:
TrayService();
~TrayService();
struct TrackedItem {
Item publicData;
guint signalSubscriptionId = 0;

View File

@@ -2,6 +2,7 @@
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include "components/base/button.hpp"
class BluetoothWidget : public Gtk::Box {
public:
@@ -21,11 +22,11 @@ class BluetoothWidget : public Gtk::Box {
Gtk::Box statusArea;
Gtk::Box *deviceList = nullptr;
Gtk::Button *scanButton = nullptr;
Gtk::Button *powerButton = nullptr;
Button *scanButton = nullptr;
Button *powerButton = nullptr;
void onPowerButtonClicked();
void onScanButtonClicked();
void toggleButton(Gtk::Button *button, bool state);
void toggleButton(Button *button, bool state);
};

View File

@@ -16,15 +16,16 @@
#include <string>
#include "services/tray.hpp"
#include "components/base/button.hpp"
class TrayIconWidget : public Gtk::Button {
class TrayIconWidget : public Button {
public:
TrayIconWidget(TrayService &service, std::string id);
TrayIconWidget(std::string id);
void update(const TrayService::Item &item);
private:
TrayService &service;
TrayService &service = *TrayService::getInstance();
std::string id;
Gtk::Box container;
Gtk::Picture picture;
@@ -53,11 +54,11 @@ class TrayIconWidget : public Gtk::Button {
class TrayWidget : public Gtk::Box {
public:
explicit TrayWidget(TrayService &service);
explicit TrayWidget();
~TrayWidget() override;
private:
TrayService &service;
TrayService *service = TrayService::getInstance();
std::map<std::string, std::unique_ptr<TrayIconWidget>> icons;
sigc::connection addConnection;

View File

@@ -8,6 +8,4 @@
class WebWidget : public Popover {
public:
WebWidget(std::string icon, std::string title, std::string url);
private:
};

View File

@@ -6,22 +6,23 @@
#include <sigc++/connection.h>
#include "services/hyprland.hpp"
#include "gtkmm/overlay.h"
class WorkspaceIndicator : public Gtk::Box {
public:
WorkspaceIndicator(HyprlandService &service, int monitorId);
WorkspaceIndicator(int monitorId);
~WorkspaceIndicator() override;
private:
HyprlandService &service;
HyprlandService *service = HyprlandService::getInstance();
int monitorId;
sigc::connection workspaceConnection;
sigc::connection monitorConnection;
std::map<int, Gtk::Label *> workspaceLabels;
std::map<int, Gtk::Overlay *> workspaceIndicators;
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
void rebuild();
void on_workspace_update();
void on_monitor_update();
void refreshLabel(Gtk::Label *label, const HyprlandService::WorkspaceState &state);
void refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state);
};