base function of indicators work again
This commit is contained in:
@@ -19,7 +19,7 @@ class App {
|
||||
private:
|
||||
Glib::RefPtr<Gtk::Application> app;
|
||||
std::vector<Bar *> bars;
|
||||
HyprlandService *hyprlandService = HyprlandService::getInstance();
|
||||
HyprlandService *hyprlandService = nullptr;
|
||||
NotificationService notificationService;
|
||||
TrayService *trayService = TrayService::getInstance();
|
||||
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
|
||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||
#include <gtkmm.h>
|
||||
#include <memory>
|
||||
|
||||
#include "widgets/clock.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/tray.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
#include "widgets/controlCenter.hpp"
|
||||
|
||||
class Bar : public Gtk::Window {
|
||||
public:
|
||||
Bar(GdkMonitor *monitor, int monitorId);
|
||||
Bar(GdkMonitor *monitor);
|
||||
|
||||
void addLeftWidget(std::shared_ptr<Gtk::Widget> widget) { left_box.append(*widget); }
|
||||
void addCenterWidget(std::shared_ptr<Gtk::Widget> widget) { center_box.append(*widget); }
|
||||
void addRightWidget(std::shared_ptr<Gtk::Widget> widget) { right_box.append(*widget); }
|
||||
|
||||
private:
|
||||
int monitorId;
|
||||
|
||||
Gtk::CenterBox main_box{};
|
||||
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
|
||||
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
|
||||
@@ -28,9 +30,8 @@ class Bar : public Gtk::Window {
|
||||
WebWidget homeAssistant{"\ue88a", "Home Assistant", "https://home.rivercry.com"};
|
||||
ControlCenter controlCenter{"\ue88a", "Control Center"};
|
||||
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
VolumeWidget *volumeWidget = nullptr;
|
||||
std::shared_ptr<TrayWidget> trayWidget = nullptr;
|
||||
std::shared_ptr<VolumeWidget> volumeWidget = nullptr;
|
||||
|
||||
|
||||
void setup_ui();
|
||||
|
||||
14
include/components/workspaceIndicator.hpp
Normal file
14
include/components/workspaceIndicator.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "gtkmm/box.h"
|
||||
#include "gtkmm/button.h"
|
||||
#include "gtkmm/overlay.h"
|
||||
|
||||
class WorkspaceIndicator : public Gtk::Box {
|
||||
public:
|
||||
WorkspaceIndicator(std::string label, sigc::slot<void()> onClick = {});
|
||||
|
||||
private:
|
||||
Gtk::Button button;
|
||||
};
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <vector>
|
||||
|
||||
#include "helper/string.hpp"
|
||||
#include "helpers/string.hpp"
|
||||
|
||||
class SocketHelper {
|
||||
typedef struct SocketMessage {
|
||||
@@ -18,6 +18,7 @@ class SocketHelper {
|
||||
static std::vector<SocketMessage> parseSocketMessage(int socketFd, const std::string &delimiter) {
|
||||
char buffer[4096];
|
||||
std::string data;
|
||||
|
||||
ssize_t bytesRead = recv(socketFd, buffer, sizeof(buffer) - 1, 0);
|
||||
if (bytesRead > 0) {
|
||||
buffer[bytesRead] = '\0';
|
||||
@@ -34,17 +35,15 @@ class SocketHelper {
|
||||
assert(false && "Delimiter not found in socket message");
|
||||
}
|
||||
|
||||
auto splitMessages = StringHelper::split(data, '\n');
|
||||
auto splitMessages = StringHelper::split(data, '\n');
|
||||
auto splitMessagesFinal = std::vector<SocketMessage>();
|
||||
for (auto splitMessage : splitMessages) {
|
||||
|
||||
|
||||
SocketMessage message;
|
||||
auto messageCommandVector = StringHelper::split(splitMessage, ">>");
|
||||
|
||||
message.eventType = messageCommandVector[0];
|
||||
message.eventData = messageCommandVector.size() > 1 ? messageCommandVector[1] : "";
|
||||
splitMessagesFinal.push_back(message);
|
||||
SocketMessage message;
|
||||
auto messageCommandVector = StringHelper::split(splitMessage, delimiter);
|
||||
|
||||
message.eventType = messageCommandVector[0];
|
||||
message.eventData = messageCommandVector.size() > 1 ? messageCommandVector[1] : "";
|
||||
splitMessagesFinal.push_back(message);
|
||||
}
|
||||
|
||||
return splitMessagesFinal;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/gestureclick.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <sigc++/connection.h>
|
||||
|
||||
#include "services/hyprland.hpp"
|
||||
#include "gtkmm/overlay.h"
|
||||
|
||||
class WorkspaceIndicator : public Gtk::Box {
|
||||
public:
|
||||
WorkspaceIndicator(int monitorId);
|
||||
~WorkspaceIndicator() override;
|
||||
|
||||
private:
|
||||
HyprlandService *service = HyprlandService::getInstance();
|
||||
int monitorId;
|
||||
sigc::connection workspaceConnection;
|
||||
sigc::connection monitorConnection;
|
||||
std::map<int, Gtk::Overlay *> workspaceIndicators;
|
||||
std::map<int, Glib::RefPtr<Gtk::GestureClick>> workspaceGestures;
|
||||
|
||||
void rebuild();
|
||||
void on_workspace_update();
|
||||
void on_monitor_update();
|
||||
void refreshLabel(Gtk::Overlay *overlay, const HyprlandService::WorkspaceState &state);
|
||||
};
|
||||
Reference in New Issue
Block a user