optimized the code, added some bugs :)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <gtk4-layer-shell/gtk4-layer-shell.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "icons.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/tray.hpp"
|
||||
#include "widgets/clock.hpp"
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "widgets/tray.hpp"
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
#include "icons.hpp"
|
||||
|
||||
class Bar : public Gtk::Window {
|
||||
public:
|
||||
@@ -26,8 +25,8 @@ class Bar : public Gtk::Window {
|
||||
private:
|
||||
Clock clock;
|
||||
Date date;
|
||||
WebWidget homeAssistant {ICON_HOME, "Home Assistant",
|
||||
"https://home.rivercry.com"};
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant",
|
||||
"https://home.rivercry.com"};
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
int monitorId;
|
||||
|
||||
@@ -6,22 +6,27 @@
|
||||
#include <map>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class HyprlandService {
|
||||
public:
|
||||
static constexpr int kWorkspaceSlotCount = 5;
|
||||
static constexpr int kWorkspaceSlotCount = 7;
|
||||
|
||||
struct WindowState {
|
||||
int hyprId = -1;
|
||||
};
|
||||
|
||||
struct WorkspaceState {
|
||||
int id = -1;
|
||||
int hyprId = -1;
|
||||
int monitorId = -1;
|
||||
bool active = false;
|
||||
bool focused = false;
|
||||
bool urgent = false;
|
||||
std::vector<int> urgentWindows;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
struct Monitor {
|
||||
std::map<int, WorkspaceState> workspaceStates;
|
||||
std::map<int, WorkspaceState*> workspaceStates;
|
||||
std::string name;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
@@ -45,58 +50,21 @@ class HyprlandService {
|
||||
const Monitor *getMonitorById(int id) const;
|
||||
Monitor *getMonitorByIndex(std::size_t index);
|
||||
const Monitor *getMonitorByIndex(std::size_t index) const;
|
||||
// Switch to a workspace slot on a given monitor. If the workspace has an
|
||||
// associated Hyprland workspace id (hyprId >= 0) that id will be used.
|
||||
// Otherwise the slot and monitor name will be used to request creation
|
||||
// / activation via `hyprctl`.
|
||||
void switchToWorkspace(int workspaceId);
|
||||
|
||||
std::map<int, WorkspaceState> getAllWorkspaces() const {
|
||||
return this->workspaces;
|
||||
}
|
||||
|
||||
private:
|
||||
int fd = -1;
|
||||
std::string buffer;
|
||||
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);
|
||||
std::string get_socket_path();
|
||||
void refresh_monitors();
|
||||
void refresh_workspaces();
|
||||
void handle_urgent_window(std::string windowAddress);
|
||||
};
|
||||
|
||||
inline void HyprlandService::printMonitor(const Monitor &mon) const {
|
||||
std::cout << "=== Monitor Info ===\n";
|
||||
std::cout << "Name: " << mon.name << " (ID: " << mon.id << ")\n";
|
||||
std::cout << "Position: (" << mon.x << ", " << mon.y << ")\n";
|
||||
std::cout << "Focused Workspace ID: " << mon.focusedWorkspaceId << "\n";
|
||||
|
||||
std::cout << "Workspaces:\n";
|
||||
|
||||
if (mon.workspaceStates.empty()) {
|
||||
std::cout << " (None)\n";
|
||||
} else {
|
||||
for (int slot = 1; slot <= HyprlandService::kWorkspaceSlotCount;
|
||||
++slot) {
|
||||
const auto it = mon.workspaceStates.find(slot);
|
||||
if (it == mon.workspaceStates.end()) {
|
||||
std::cout << " - [Slot: " << slot << " | HyprID: n/a]"
|
||||
<< " Label: <none> | Active: No | Focused: No | "
|
||||
"Urgent: No\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
const WorkspaceState &ws = it->second;
|
||||
std::cout << " - [Slot: " << ws.id << " | HyprID: "
|
||||
<< (ws.hyprId >= 0 ? std::to_string(ws.hyprId)
|
||||
: std::string("n/a"))
|
||||
<< "] "
|
||||
<< "Label: " << (ws.label.empty() ? "<none>" : ws.label)
|
||||
<< " | "
|
||||
<< "Active: " << (ws.active ? "Yes" : "No") << " | "
|
||||
<< "Focused: " << (ws.focused ? "Yes" : "No") << " | "
|
||||
<< "Urgent: " << (ws.urgent ? "Yes" : "No") << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "====================\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user