Files
bar/include/services/hyprland.hpp

113 lines
2.8 KiB
C++

#pragma once
#include <glibmm.h>
#include <map>
#include <memory>
#include <set>
#include <sigc++/sigc++.h>
#include <string>
#include <sys/stat.h>
#include "bar/bar.hpp"
#include "components/workspaceIndicator.hpp"
#include "helpers/socket.hpp"
#include "gtkmm/box.h"
#define NUM_WORKSPACES 7
class HyprlandService {
inline static HyprlandService *instance = nullptr;
public:
struct Client {
std::string address;
int workspaceId;
std::string title;
};
struct WorkspaceData {
int id;
std::string monitorName;
std::string label;
std::map<std::string, std::shared_ptr<Client>> clients;
std::set<std::string> urgentClients;
};
struct Workspace {
std::shared_ptr<WorkspaceData> state;
std::shared_ptr<WorkspaceIndicator> view;
};
struct Monitor {
int id;
int activeWorkspaceId;
bool focused;
std::string name;
std::map<int, std::shared_ptr<Workspace>> monitorWorkspaces;
std::shared_ptr<Bar> bar;
};
static HyprlandService *getInstance() {
if (!instance) {
instance = new HyprlandService();
}
return instance;
}
std::shared_ptr<Gtk::Box> getWorkspaceIndicatorsForMonitor(std::string monitorName);
void addBar(std::shared_ptr<Bar> bar, std::string monitorName);
private:
enum SocketEventType {
WORKSPACE_CHANGED,
ACTIVE_WINDOW,
OPEN_WINDOW,
CLOSE_WINDOW,
URGENT,
FOCUSED_MONITOR,
MONITOR_REMOVED,
};
std::map<std::string, SocketEventType> socketEventTypeMap = {
{"workspace", WORKSPACE_CHANGED},
{"activewindowv2", ACTIVE_WINDOW},
{"openwindow", OPEN_WINDOW},
{"closewindow", CLOSE_WINDOW},
{"urgent", URGENT},
{"focusedmon", FOCUSED_MONITOR},
{"monitorremoved", MONITOR_REMOVED},
};
void onWorkspaceChanged(int workspaceId);
void onFocusedMonitorChanged(std::string monitorData);
void onOpenWindow(std::string windowData);
void onCloseWindow(std::string windowData);
void onUrgent(std::string windowAddress);
void onActiveWindowChanged(std::string windowAddress);
void onMonitorRemoved(std::string monitorName);
// void onMonitorAdded(std::string monitorName);
HyprlandService();
std::map<std::string, std::shared_ptr<Monitor>> monitors;
std::map<int, std::shared_ptr<Workspace>> workspaces;
std::map<std::string, std::shared_ptr<Client>> clients;
/// maybe refactor into reusable class
std::string socketBuffer;
int socketFd;
///
void bindSocket();
void init();
void switchToWorkspace(int workspaceId);
void refreshIndicator(std::shared_ptr<Workspace> workspace);
void handleSocketMessage(SocketHelper::SocketMessage message);
};