refactor and shizz
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user