add workspace indicators

This commit is contained in:
2025-12-09 22:53:29 +01:00
parent 25c73f67a7
commit d53dfa27f1
8 changed files with 501 additions and 132 deletions

View File

@@ -5,15 +5,24 @@
#include "services/hyprland.hpp"
#include "widgets/clock.hpp"
#include "widgets/workspaceIndicator.hpp"
class Bar : public Gtk::Window
{
public:
Bar(GdkMonitor* monitor, HyprlandService::Monitor* hyprlandMonitor);
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, int monitorId);
protected:
Clock clock;
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:
HyprlandService &m_hyprlandService;
int m_monitorId;
WorkspaceIndicator *m_workspaceIndicator = nullptr;
void setup_ui();
void load_css();

View File

@@ -1,68 +1,100 @@
#pragma once
#include <cstddef>
#include <glibmm.h>
#include <iostream>
#include <map>
#include <sigc++/sigc++.h>
#include <string>
class HyprlandService {
class HyprlandService
{
public:
typedef struct WorkspaceState {
int id;
bool active;
bool focused;
bool urgent;
} WorkspaceState;
static constexpr int kWorkspaceSlotCount = 5;
typedef struct Monitor {
struct WorkspaceState
{
int id = -1;
int hyprId = -1;
bool active = false;
bool focused = false;
bool urgent = false;
std::string label;
};
struct Monitor
{
std::map<int, WorkspaceState> workspaceStates;
std::string name;
int x;
int y;
int id;
int focusedWorkspaceId;
} Monitor;
int x = 0;
int y = 0;
int id = -1;
int focusedWorkspaceId = -1;
};
HyprlandService();
~HyprlandService();
// For debugging purposes
void printMonitor(const Monitor mon) {
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";
} else {
for (const auto &pair : mon.workspaceStates) {
const WorkspaceState ws = pair.second;
std::cout << " - [ID: " << ws.id << "] "
<< "Active: " << (ws.active ? "Yes" : "No") << " | "
<< "Focused: " << (ws.focused ? "Yes" : "No") << " | "
<< "Urgent: " << (ws.urgent ? "Yes" : "No") << "\n";
}
}
std::cout << "====================\n";
}
sigc::signal<void(std::string, std::string)> socketEventSignal;
void start();
void on_hyprland_event(std::string event, std::string data);
Monitor* getMonitorById(const int &name);
void printMonitor(const Monitor &mon) const;
sigc::signal<void(std::string, std::string)> socketEventSignal;
sigc::signal<void(int)> workspaceStateChanged;
sigc::signal<void()> monitorStateChanged;
Monitor *getMonitorById(int id);
const Monitor *getMonitorById(int id) const;
Monitor *getMonitorByIndex(std::size_t index);
const Monitor *getMonitorByIndex(std::size_t index) const;
private:
int m_fd = -1;
std::string m_buffer;
std::map<int, Monitor*> monitors;
std::map<int, Monitor> m_monitors;
bool on_socket_read(Glib::IOCondition condition);
void parse_message(const std::string &line);
std::string get_socket_path();
void refresh_monitors();
void refresh_workspaces();
};
inline 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";
}
else
{
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 << " - [Slot: " << ws.id << " | 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.urgent ? "Yes" : "No") << "\n";
}
}
std::cout << "====================\n";
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <sigc++/connection.h>
#include "services/hyprland.hpp"
class WorkspaceIndicator : public Gtk::Box
{
public:
WorkspaceIndicator(HyprlandService &service, int monitorId);
~WorkspaceIndicator() override;
private:
HyprlandService &m_service;
int m_monitorId;
sigc::connection m_workspaceConnection;
sigc::connection m_monitorConnection;
void rebuild();
void on_workspace_update(int monitorId);
void on_monitor_update();
void clear_children();
};