Files
bar/include/services/hyprland.hpp
2025-12-17 23:34:12 +01:00

71 lines
1.9 KiB
C++

#pragma once
#include <cstddef>
#include <glibmm.h>
#include <map>
#include <sigc++/sigc++.h>
#include <string>
#include <vector>
class HyprlandService {
public:
static constexpr int kWorkspaceSlotCount = 7;
const char *kMonitorCommand = "hyprctl monitors -j";
const char *kWorkspaceCommand = "hyprctl workspaces -j";
const char *kClientsCommand = "hyprctl clients -j";
struct WindowState {
int hyprId = -1;
};
struct WorkspaceState {
int hyprId = -1;
int monitorId = -1;
bool active = false;
bool focused = false;
std::vector<std::string> urgentWindows;
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;
};
HyprlandService();
~HyprlandService();
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;
}
private:
int fd = -1;
std::map<int, Monitor> monitors;
std::map<int, WorkspaceState *> workspaces;
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);
};