#pragma once #include #include #include #include #include #include #include class HyprlandService { 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 urgentWindows; std::string label; }; struct Monitor { std::map workspaceStates; std::string name; int x = 0; int y = 0; int id = -1; int focusedWorkspaceId = -1; }; void start(); void on_hyprland_event(std::string event, std::string data); void printMonitor(const Monitor &mon) const; sigc::signal socketEventSignal; sigc::signal workspaceStateChanged; sigc::signal monitorStateChanged; Monitor *getMonitorById(int id); Monitor *getMonitorByIndex(std::size_t index); void switchToWorkspace(int workspaceId); std::map getAllWorkspaces() const { return this->workspaces; } static HyprlandService *getInstance() { if (HyprlandService::instance == nullptr) { HyprlandService::instance = new HyprlandService(); } return HyprlandService::instance; } private: const char *kMonitorCommand = "hyprctl monitors -j"; const char *kWorkspaceCommand = "hyprctl workspaces -j"; const char *kClientsCommand = "hyprctl clients -j"; HyprlandService(); ~HyprlandService(); int fd = -1; std::map monitors; std::map workspaces; std::string socket_buffer; 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); };