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

@@ -22,7 +22,7 @@ App::App() {
try {
hyprlandMonitor =
this->hyprlandService.getMonitorByIndex(i);
this->hyprlandService->getMonitorByIndex(i);
} catch (const std::exception &ex) {
std::cerr << "[App] Failed to fetch Hyprland monitor: "
<< ex.what() << std::endl;
@@ -31,8 +31,7 @@ App::App() {
auto bar = new Bar(monitor->gobj(), this->hyprlandService,
this->trayService, hyprlandMonitor->id);
auto bar = new Bar(monitor->gobj(), hyprlandMonitor->id);
bar->set_application(app);
bar->show();
@@ -47,16 +46,16 @@ App::App() {
}
bars.clear();
this->trayService.stop();
this->trayService->stop();
});
}
void App::setupServices() {
this->hyprlandService.socketEventSignal.connect(sigc::mem_fun(
this->hyprlandService, &HyprlandService::on_hyprland_event));
this->hyprlandService->socketEventSignal.connect(sigc::mem_fun(
*this->hyprlandService, &HyprlandService::on_hyprland_event));
this->hyprlandService.start();
this->trayService.start();
this->hyprlandService->start();
this->trayService->start();
}
int App::run() { return this->app->run(); }

View File

@@ -16,10 +16,8 @@
#include "gtk/gtk.h"
#include "sigc++/functors/mem_fun.h"
Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
TrayService &trayService, int monitorId)
: hyprlandService(hyprlandService), trayService(trayService),
monitorId(monitorId) {
Bar::Bar(GdkMonitor *monitor, int monitorId)
: monitorId(monitorId) {
set_name("bar-window");
gtk_layer_init_for_window(this->gobj());
@@ -38,9 +36,8 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
set_child(main_box);
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
this->trayWidget = Gtk::make_managed<TrayWidget>(trayService);
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(monitorId);
this->trayWidget = Gtk::make_managed<TrayWidget>();
load_css();
setup_ui();

View File

@@ -0,0 +1,19 @@
#include "components/base/button.hpp"
#include "sigc++/functors/mem_fun.h"
Button::Button(const std::string label)
: Gtk::Button(label) {
signal_clicked().connect(
sigc::mem_fun(*this, &Button::on_clicked));
this->add_css_class("button");
}
Button::Button(Gtk::Image &image)
: Gtk::Button() {
set_child(image);
signal_clicked().connect(
sigc::mem_fun(*this, &Button::on_clicked));
this->add_css_class("button");
}

View File

@@ -3,10 +3,7 @@
#include "gtkmm/label.h"
#include "gtkmm/object.h"
Popover::Popover(std::string icon, std::string name) {
auto label = Gtk::make_managed<Gtk::Label>(icon);
label->add_css_class("icon-label");
set_child(*label);
Popover::Popover(const std::string icon, std::string name): Button(icon) {
signal_clicked().connect(sigc::mem_fun(*this, &Popover::on_toggle_window));
popover = new Gtk::Popover();

View File

@@ -2,8 +2,7 @@
#include <gtkmm/label.h>
#include <string>
#include "gtkmm/button.h"
#include "components/base/button.hpp"
TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed, sigc::signal<void(int, std::string)> signal_edited)
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
@@ -30,22 +29,19 @@ TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_di
buttonBox->set_valign(Gtk::Align::CENTER);
append(*buttonBox);
auto dismissButton = Gtk::make_managed<Gtk::Button>("\uf00d");
auto dismissButton = Gtk::make_managed<Button>("\uf00d");
dismissButton->set_valign(Gtk::Align::CENTER);
dismissButton->set_tooltip_text("Dismiss");
dismissButton->signal_clicked().connect(sigc::mem_fun(*this, &TodoEntry::on_dismiss_clicked));
auto editButton = Gtk::make_managed<Gtk::Button>("\uf044");
auto editButton = Gtk::make_managed<Button>("\uf044");
editButton->set_valign(Gtk::Align::CENTER);
buttonBox->append(*editButton);
buttonBox->append(*dismissButton);
}
TodoEntry::~TodoEntry() {
}
void TodoEntry::on_dismiss_clicked() {
this->signal_dismissed.emit(this->id);
}

View File

@@ -8,8 +8,6 @@
#include "glib.h"
#include "sigc++/signal.h"
BluetoothService *BluetoothService::instance = nullptr;
BluetoothService::BluetoothService() {
GError *error = nullptr;
@@ -28,9 +26,7 @@ BluetoothService::BluetoothService() {
<< error->message << std::endl;
g_error_free(error);
assert(false);
} else {
std::cout << "Bluetooth adapter proxy created successfully." << std::endl;
}
}
this->powerState = this->getPowerState();
this->isDiscovering = this->getIsDiscovering();
@@ -168,7 +164,7 @@ void BluetoothService::onPropertyChanged(GDBusProxy *proxy,
if (g_variant_lookup(changed_properties, "Discovering", "b", &is_discovering)) {
this->isDiscovering = is_discovering;
isDiscoveringChangedSignal.emit(isDiscovering);
// getDeviceObjectPaths();
getDeviceObjectPaths();
}
}
@@ -229,8 +225,6 @@ std::vector<std::string> BluetoothService::getDeviceObjectPaths() {
while (g_variant_iter_next(&iter, "{&o@a{sa{sv}}}", &object_path, &interfaces)) {
GVariant *device_props = nullptr;
if (g_variant_lookup(interfaces, "org.bluez.Device1", "@a{sv}", &device_props)) {
std::cout << "Found device: " << object_path << std::endl;
device_paths.emplace_back(object_path);
g_variant_unref(device_props);
}

View File

@@ -43,9 +43,6 @@ void HyprlandService::on_hyprland_event(std::string event, std::string data) {
refresh_workspaces();
}
// use for
// event == "focusedmon"
if (event == "monitoradded" || event == "monitorremoved") {
refresh_monitors();
}
@@ -77,8 +74,6 @@ void HyprlandService::start() {
return;
}
std::cout << "[Hyprland] Connected to event socket." << std::endl;
Glib::signal_io().connect(
sigc::mem_fun(*this, &HyprlandService::on_socket_read), fd,
Glib::IOCondition::IO_IN | Glib::IOCondition::IO_HUP |
@@ -300,45 +295,6 @@ void HyprlandService::onActiveWindowEvent(std::string windowAddress) {
}
}
void HyprlandService::printMonitor(const Monitor &mon) const {
std::cout << "=== Monitor Info ===\n";
std::cout << "Name: " << mon.name << " (ID: " << mon.id << ")\n";
std::cout << "Position: (" << mon.x << ", " << mon.y << ")\n";
std::cout << "Focused Workspace ID: " << mon.focusedWorkspaceId << "\n";
std::cout << "Workspaces:\n";
if (mon.workspaceStates.empty()) {
std::cout << " (None)\n";
return;
}
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount; ++slot) {
const auto it = mon.workspaceStates.find(slot);
if (it == mon.workspaceStates.end()) {
std::cout << " - [Slot: " << slot << " | HyprID: n/a]"
<< " Label: <none> | Active: No | Focused: No | "
"Urgent: No\n";
continue;
}
const WorkspaceState *ws = it->second;
std::cout << " - [HyprID: "
<< (ws->hyprId >= 0 ? std::to_string(ws->hyprId)
: std::string("n/a"))
<< "] "
<< "Label: " << (ws->label.empty() ? "<none>" : ws->label)
<< " | "
<< "Active: " << (ws->active ? "Yes" : "No") << " | "
<< "Focused: " << (ws->focused ? "Yes" : "No") << " | "
<< "Urgent: " << (ws->urgentWindows.size() > 0 ? "Yes" : "No")
<< "\n";
}
std::cout << "====================\n";
}
HyprlandService::Monitor *HyprlandService::getMonitorById(int id) {
auto it = monitors.find(id);
if (it == monitors.end()) {

View File

@@ -302,6 +302,4 @@ void NotificationService::intialize() {
<< "). Stop your existing notification daemon (e.g. dunst/mako/swaync) or allow replacement." << std::endl;
return;
}
std::cout << "Notifications daemon active (org.freedesktop.Notifications)." << std::endl;
}

View File

@@ -485,34 +485,6 @@ TrayService::get_menu_action_group(const std::string &id) {
return item.menuActions;
}
void TrayService::debug_dump_menu_layout(const std::string &id) {
auto it = items.find(id);
if (it == items.end() || !connection) {
return;
}
const auto &item = *it->second;
if (!item.publicData.menuAvailable || item.publicData.menuPath.empty()) {
return;
}
GVariant *result = call_get_layout(connection, item.publicData.busName,
item.publicData.menuPath);
if (!result) {
return;
}
gchar *printed = g_variant_print(result, TRUE);
if (printed) {
std::cout << "[TrayService] GetLayout for " << id << ":\n"
<< printed << std::endl;
g_free(printed);
}
g_variant_unref(result);
}
std::optional<TrayService::MenuNode>
TrayService::get_menu_layout(const std::string &id) {
auto it = items.find(id);

View File

@@ -9,12 +9,12 @@ BluetoothWidget::BluetoothWidget() : Gtk::Box() {
this->statusArea.set_halign(Gtk::Align::FILL);
this->append(this->statusArea);
this->powerButton = Gtk::make_managed<Gtk::Button>("\ue1a8");
this->powerButton = Gtk::make_managed<Button>("\ue1a8");
this->powerButton->set_tooltip_text("Turn Bluetooth Off");
this->powerButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onPowerButtonClicked));
this->powerButton->add_css_class("toggle-button");
this->scanButton = Gtk::make_managed<Gtk::Button>("\ue1aa");
this->scanButton = Gtk::make_managed<Button>("\ue1aa");
this->scanButton->set_tooltip_text("Scan for Devices");
this->scanButton->add_css_class("toggle-button");
this->scanButton->signal_clicked().connect(sigc::mem_fun(*this, &BluetoothWidget::onScanButtonClicked));
@@ -31,7 +31,7 @@ void BluetoothWidget::onScanButtonClicked() {
onIsDiscoveringButtonClickedSignal.emit();
}
void BluetoothWidget::toggleButton(Gtk::Button *button, bool state) {
void BluetoothWidget::toggleButton(Button *button, bool state) {
if (state) {
button->add_css_class("toggle-button-on");
button->remove_css_class("toggle-button-off");

View File

@@ -10,9 +10,11 @@ ControlCenter::ControlCenter(std::string icon, std::string name)
bluetoothService->powerStateChangedSignal.connect(
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setPowerState));
bluetoothWidget->onPowerStateButtonClickedSignal.connect(
bluetoothWidget->onPowerStateButtonClickedSignal.connect(
sigc::mem_fun(*this->bluetoothService, &BluetoothService::togglePowerState));
bluetoothWidget->setPowerState(bluetoothService->getPowerState());
bluetoothWidget->setPowerState(bluetoothService->getPowerState());
bluetoothService->isDiscoveringChangedSignal.connect(
sigc::mem_fun(*this->bluetoothWidget, &BluetoothWidget::setIsDiscovering));

View File

@@ -5,9 +5,10 @@
#include <gtk/gtk.h>
#include <iostream>
#include <utility>
#include "components/base/button.hpp"
TrayIconWidget::TrayIconWidget(TrayService &service, std::string id)
: service(service), id(std::move(id)),
TrayIconWidget::TrayIconWidget( std::string id)
: Button(id), id(std::move(id)),
container(Gtk::Orientation::HORIZONTAL) {
set_has_frame(false);
set_focusable(false);
@@ -131,10 +132,8 @@ bool TrayIconWidget::ensure_menu() {
populate_menu_items(layout.children, menu, actions);
const auto itemCount = menu->get_n_items();
std::cout << "[TrayIconWidget] menu update for " << id
<< ", items: " << itemCount << std::endl;
if (itemCount == 0) {
service.debug_dump_menu_layout(id);
return false;
}
@@ -174,9 +173,6 @@ void TrayIconWidget::on_menu_items_changed(guint /*position*/,
return;
}
const auto count = menuModel->get_n_items();
std::cout << "[TrayIconWidget] items changed for " << id << ": " << count
<< " entries" << std::endl;
try_popup();
}
@@ -251,17 +247,17 @@ void TrayIconWidget::on_menu_action(const Glib::VariantBase & /*parameter*/,
}
}
TrayWidget::TrayWidget(TrayService &service)
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service) {
TrayWidget::TrayWidget()
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
set_valign(Gtk::Align::CENTER);
set_halign(Gtk::Align::CENTER);
set_visible(false);
addConnection = service.signal_item_added().connect(
addConnection = service->signal_item_added().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_added));
removeConnection = service.signal_item_removed().connect(
removeConnection = service->signal_item_removed().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_removed));
updateConnection = service.signal_item_updated().connect(
updateConnection = service->signal_item_updated().connect(
sigc::mem_fun(*this, &TrayWidget::on_item_updated));
rebuild_existing();
@@ -280,7 +276,7 @@ TrayWidget::~TrayWidget() {
}
void TrayWidget::rebuild_existing() {
auto items = service.snapshotItems();
auto items = service->snapshotItems();
for (const auto &item : items) {
on_item_added(item);
}
@@ -295,7 +291,7 @@ void TrayWidget::on_item_added(const TrayService::Item &item) {
return;
}
auto icon = std::make_unique<TrayIconWidget>(service, item.id);
auto icon = std::make_unique<TrayIconWidget>(item.id);
icon->update(item);
auto *raw = icon.get();
append(*raw);

View File

@@ -3,39 +3,58 @@
#include <cassert>
#include <gdk/gdk.h>
#include <gtkmm/gestureclick.h>
#include <gtkmm/overlay.h>
#include <gtkmm/widget.h>
#include <sigc++/functors/mem_fun.h>
#include "services/hyprland.hpp"
WorkspaceIndicator::WorkspaceIndicator(HyprlandService &service, int monitorId)
: Gtk::Box(Gtk::Orientation::HORIZONTAL), service(service),
#include "gtkmm/box.h"
#include "gtkmm/label.h"
WorkspaceIndicator::WorkspaceIndicator(int monitorId)
: Gtk::Box(Gtk::Orientation::HORIZONTAL),
monitorId(monitorId) {
set_margin_top(2);
set_margin_bottom(2);
workspaceConnection = service.workspaceStateChanged.connect(
workspaceConnection = service->workspaceStateChanged.connect(
sigc::mem_fun(*this, &WorkspaceIndicator::on_workspace_update));
monitorConnection = service.monitorStateChanged.connect(
monitorConnection = service->monitorStateChanged.connect(
sigc::mem_fun(*this, &WorkspaceIndicator::on_monitor_update));
for (int i = 1; i <= HyprlandService::kWorkspaceSlotCount; ++i) {
auto label = Gtk::make_managed<Gtk::Label>(std::to_string(i));
label->add_css_class("workspace-pill");
auto overlay = Gtk::make_managed<Gtk::Overlay>();
auto numLabel = Gtk::make_managed<Gtk::Label>(std::to_string(i));
auto pillContainer = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
// create and store a gesture controller once to avoid duplicate handlers
auto gesture = Gtk::GestureClick::create();
gesture->set_button(GDK_BUTTON_PRIMARY);
gesture->signal_released().connect(
[this, i](int, double, double) {
this->service.switchToWorkspace(
i + this->monitorId * HyprlandService::kWorkspaceSlotCount);
});
label->add_controller(gesture);
workspaceGestures[i] = gesture;
gesture->signal_released().connect([this, i](int, double, double) {
this->service->switchToWorkspace(
i + this->monitorId * HyprlandService::kWorkspaceSlotCount);
});
workspaceLabels[i] = label;
append(*label);
workspaceGestures[i] = gesture;
workspaceIndicators[i] = overlay;
overlay->add_controller(gesture);
overlay->add_css_class("workspace-pill");
// if (i == 6 || i == 7) {
// auto indicator = Gtk::make_managed<Gtk::Label>(i == 6 ? "🫱🏻" : "🫲🏻");
// indicator->add_css_class(i == 6 ? "workspace-pill-six" : "workspace-pill-seven");
// indicator->set_valign(Gtk::Align::END);
// indicator->set_halign(i == 6 ? Gtk::Align::START : Gtk::Align::END);
// overlay->set_child(*indicator);
// overlay->add_overlay(*numLabel);
// pillContainer->append(*overlay);
// } else {
overlay->set_child(*numLabel);
pillContainer->append(*overlay);
// }
append(*pillContainer);
}
rebuild();
@@ -55,30 +74,32 @@ void WorkspaceIndicator::on_workspace_update() {
rebuild();
}
void WorkspaceIndicator::on_monitor_update() { rebuild(); }
void WorkspaceIndicator::on_monitor_update() {
rebuild();
}
void WorkspaceIndicator::refreshLabel(Gtk::Label *label, const HyprlandService::WorkspaceState &state) {
label->remove_css_class("workspace-pill-active");
label->remove_css_class("workspace-pill-focused");
label->remove_css_class("workspace-pill-urgent");
void WorkspaceIndicator::refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state) {
overlay->remove_css_class("workspace-pill-active");
overlay->remove_css_class("workspace-pill-focused");
overlay->remove_css_class("workspace-pill-urgent");
// controller created once in constructor and reused
if (state.urgentWindows.size() > 0) {
label->add_css_class("workspace-pill-urgent");
overlay->add_css_class("workspace-pill-urgent");
} else {
if (state.focused) {
label->add_css_class("workspace-pill-focused");
overlay->add_css_class("workspace-pill-focused");
} else if (state.active) {
label->add_css_class("workspace-pill-active");
overlay->add_css_class("workspace-pill-active");
}
}
}
void WorkspaceIndicator::rebuild() {
HyprlandService::Monitor *mon = service.getMonitorById(this->monitorId);
HyprlandService::Monitor *mon = service->getMonitorById(this->monitorId);
for (auto [id, workspaceState] : mon->workspaceStates) {
Gtk::Label *label = workspaceLabels[id];
this->refreshLabel(label, *workspaceState);
Gtk::Overlay *overlay = workspaceIndicators[id];
this->refreshLabel(overlay, *workspaceState);
}
}
}