Skip to content

Commit

Permalink
feat(hyprland): support workspacev2
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fff committed Jan 10, 2025
1 parent 301bfb5 commit 17f1088
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Workspaces : public AModule, public EventHandler {

bool m_withIcon;
uint64_t m_monitorId;
std::string m_activeWorkspaceName;
int m_activeWorkspaceId;
std::string m_activeSpecialWorkspaceName;
std::vector<std::unique_ptr<Workspace>> m_workspaces;
std::vector<std::pair<Json::Value, Json::Value>> m_workspacesToCreate;
Expand Down
29 changes: 18 additions & 11 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Workspaces::~Workspaces() {
}

void Workspaces::init() {
m_activeWorkspaceName = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString();
m_activeWorkspaceId = (gIPC->getSocket1JsonReply("activeworkspace"))["id"].asInt();

initializeWorkspaces();
dp.emit();
Expand Down Expand Up @@ -316,7 +316,7 @@ void Workspaces::onEvent(const std::string &ev) {
std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>'));
std::string payload = ev.substr(eventName.size() + 2);

if (eventName == "workspace") {
if (eventName == "workspacev2") {
onWorkspaceActivated(payload);
} else if (eventName == "activespecial") {
onSpecialWorkspaceActivated(payload);
Expand Down Expand Up @@ -348,7 +348,8 @@ void Workspaces::onEvent(const std::string &ev) {
}

void Workspaces::onWorkspaceActivated(std::string const &payload) {
m_activeWorkspaceName = payload;
std::string workspaceIdStr = payload.substr(0, payload.find(','));
m_activeWorkspaceId = std::stoi(workspaceIdStr);
}

void Workspaces::onSpecialWorkspaceActivated(std::string const &payload) {
Expand Down Expand Up @@ -405,7 +406,7 @@ void Workspaces::onWorkspaceMoved(std::string const &payload) {
spdlog::debug("Workspace moved: {}", payload);

// Update active workspace
m_activeWorkspaceName = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString();
m_activeWorkspaceId = (gIPC->getSocket1JsonReply("activeworkspace"))["id"].asInt();

if (allOutputs()) return;

Expand All @@ -428,9 +429,6 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {
std::string newName = payload.substr(payload.find(',') + 1);
for (auto &workspace : m_workspaces) {
if (workspace->id() == workspaceId) {
if (workspace->name() == m_activeWorkspaceName) {
m_activeWorkspaceName = newName;
}
workspace->setName(newName);
break;
}
Expand All @@ -440,7 +438,16 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {

void Workspaces::onMonitorFocused(std::string const &payload) {
spdlog::trace("Monitor focused: {}", payload);
m_activeWorkspaceName = payload.substr(payload.find(',') + 1);

std::string workspaceName = payload.substr(payload.find(',') + 1);

// TODO this can be stripped out when we upgrade to focusedmonv2
for (auto &workspace : m_workspaces) {
if (workspace->name() == workspaceName) {
m_activeWorkspaceId = workspace->id();
break;
}
}

for (Json::Value &monitor : gIPC->getSocket1JsonReply("monitors")) {
if (monitor["name"].asString() == payload.substr(0, payload.find(','))) {
Expand Down Expand Up @@ -668,7 +675,7 @@ void Workspaces::registerOrphanWindow(WindowCreationPayload create_window_payloa
}

auto Workspaces::registerIpc() -> void {
gIPC->registerForIPC("workspace", this);
gIPC->registerForIPC("workspacev2", this);
gIPC->registerForIPC("activespecial", this);
gIPC->registerForIPC("createworkspacev2", this);
gIPC->registerForIPC("destroyworkspacev2", this);
Expand Down Expand Up @@ -890,9 +897,9 @@ void Workspaces::updateWorkspaceStates() {
const std::vector<std::string> visibleWorkspaces = getVisibleWorkspaces();
auto updatedWorkspaces = gIPC->getSocket1JsonReply("workspaces");
for (auto &workspace : m_workspaces) {
workspace->setActive(workspace->name() == m_activeWorkspaceName ||
workspace->setActive(workspace->id() == m_activeWorkspaceId ||
workspace->name() == m_activeSpecialWorkspaceName);
if (workspace->name() == m_activeWorkspaceName && workspace->isUrgent()) {
if (workspace->id() == m_activeWorkspaceId && workspace->isUrgent()) {
workspace->setUrgent(false);
}
workspace->setVisible(std::find(visibleWorkspaces.begin(), visibleWorkspaces.end(),
Expand Down

0 comments on commit 17f1088

Please sign in to comment.