base function of indicators work again

This commit is contained in:
2026-01-31 15:26:11 +01:00
parent ad5e678c5d
commit 7ad6f46b3c
12 changed files with 212 additions and 523 deletions

View File

@@ -1,79 +1,70 @@
#pragma once
#include <cstddef>
#include <glibmm.h>
#include <map>
#include <memory>
#include <sigc++/sigc++.h>
#include <string>
#include <sys/stat.h>
#include <vector>
#include "components/workspaceIndicator.hpp"
#include "gtkmm/box.h"
#define NUM_WORKSPACES 7
class HyprlandService {
inline static HyprlandService *instance = nullptr;
inline static HyprlandService *instance = nullptr;
public:
static constexpr int kWorkspaceSlotCount = 7;
struct WorkspaceState {
int hyprId = -1;
int monitorId = -1;
bool active = false;
bool focused = false;
std::vector<std::string> urgentWindows;
int id;
int monitorId;
bool alive = false; // window count above 0 (exists in hyprctl workspaces array)
bool presenting = false; // $(hyprctl monitors).activeWorkspace == id
bool focused = false; // $(hyprctl monitors).activeWorkspace == id && (hyprctl monitors).focused
bool urgent = false; // check ctl clients, and find ws with urgent window
std::string label;
};
struct Monitor {
std::map<int, WorkspaceState *> workspaceStates;
std::string name;
int x = 0;
int y = 0;
int id = -1;
int focusedWorkspaceId = -1;
struct Workspace {
WorkspaceState state;
std::shared_ptr<WorkspaceIndicator> view;
};
void start();
void on_hyprland_event(std::string event, std::string data);
void printMonitor(const Monitor &mon) const;
sigc::signal<void(std::string, std::string)> socketEventSignal;
sigc::signal<void()> workspaceStateChanged;
sigc::signal<void()> monitorStateChanged;
Monitor *getMonitorById(int id);
Monitor *getMonitorByIndex(std::size_t index);
void switchToWorkspace(int workspaceId);
std::map<int, WorkspaceState *> getAllWorkspaces() const {
return this->workspaces;
}
struct Monitor {
int id;
int activeWorkspaceId;
bool focused = false;
std::string name;
std::map<int, std::shared_ptr<Workspace>> monitorWorkspaces;
};
static HyprlandService *getInstance() {
if (HyprlandService::instance == nullptr) {
HyprlandService::instance = new HyprlandService();
if (!instance) {
instance = new HyprlandService();
}
return HyprlandService::instance;
return instance;
}
std::shared_ptr<Gtk::Box> getWorkspaceIndicatorsForMonitor(int monitorId);
private:
const char *kMonitorCommand = "hyprctl monitors -j";
const char *kWorkspaceCommand = "hyprctl workspaces -j";
const char *kClientsCommand = "hyprctl clients -j";
HyprlandService();
~HyprlandService();
std::map<int, std::shared_ptr<Monitor>> monitors;
std::map<int, std::shared_ptr<Workspace>> workspaces;
int fd = -1;
std::map<int, Monitor> monitors;
std::map<int, WorkspaceState *> workspaces;
std::string socket_buffer;
/// maybe refactor into reusable class
std::string socketBuffer;
int socketFd;
///
std::string get_socket_path();
bool on_socket_read(Glib::IOCondition condition);
void parse_message(const std::string &line);
void refresh_monitors();
void refresh_workspaces();
void onUrgentEvent(std::string windowAddress);
void onActiveWindowEvent(std::string windowAddress);
std::string getSocketPath();
void bindSocket();
void init();
void updateIndicator(Workspace &workspace, const WorkspaceState newState);
};