From 16079eae09944fe76e8ba78b1e8d834baf4fa289 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 25 Feb 2024 00:51:52 +0100 Subject: [PATCH 1/4] update m_output --- include/modules/hyprland/workspaces.hpp | 1 + src/modules/hyprland/workspaces.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 8d46b1a1..dac61d95 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -82,6 +82,7 @@ class Workspace { void setVisible(bool value = true) { m_isVisible = value; }; void setWindows(uint value) { m_windows = value; }; void setName(std::string const& value) { m_name = value; }; + void setOutput(std::string const& value) { m_output = value; }; bool containsWindow(WindowAddress const& addr) const { return m_windowMap.contains(addr); } void insertWindow(WindowCreationPayload create_window_paylod); std::string removeWindow(WindowAddress const& addr); diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 3e393121..ceb887ea 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -208,6 +208,7 @@ void Workspaces::doUpdate() { } spdlog::trace("Updating workspace states"); + auto IPC_workspaces = gIPC->getSocket1JsonReply("workspaces"); for (auto &workspace : m_workspaces) { // active workspace->setActive(workspace->name() == m_activeWorkspaceName || @@ -226,6 +227,15 @@ void Workspaces::doUpdate() { if (m_withIcon) { workspaceIcon = workspace->selectIcon(m_iconsMap); } + + // update m_output + auto IPC_workspace = std::find_if(IPC_workspaces.begin(), IPC_workspaces.end(), [&workspace](auto &w) { + auto wNameRaw = w["name"].asString(); + auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; + return wName == workspace->name(); + }); + workspace->setOutput((*IPC_workspace)["monitor"].asString()); + workspace->update(m_format, workspaceIcon); } From 4cc2800a78cb930e74ee089329c6c0c2b24c7551 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 25 Feb 2024 00:52:33 +0100 Subject: [PATCH 2/4] add 'onThisMonitor' css class --- src/modules/hyprland/workspaces.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index ceb887ea..aa2db524 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -871,6 +871,7 @@ void Workspace::update(const std::string &format, const std::string &icon) { addOrRemoveClass(styleContext, isPersistent(), "persistent"); addOrRemoveClass(styleContext, isUrgent(), "urgent"); addOrRemoveClass(styleContext, isVisible(), "visible"); + addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "onThisMonitor"); std::string windows; auto windowSeparator = m_workspaceManager.getWindowSeparator(); From 9bc8de88765a0c4fb76fd3fa8c0c59df0048e9b2 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 25 Feb 2024 13:46:49 +0100 Subject: [PATCH 3/4] fix clang complaints --- src/modules/hyprland/workspaces.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index aa2db524..bae73d2e 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -208,7 +208,7 @@ void Workspaces::doUpdate() { } spdlog::trace("Updating workspace states"); - auto IPC_workspaces = gIPC->getSocket1JsonReply("workspaces"); + auto updated_workspaces = gIPC->getSocket1JsonReply("workspaces"); for (auto &workspace : m_workspaces) { // active workspace->setActive(workspace->name() == m_activeWorkspaceName || @@ -229,12 +229,13 @@ void Workspaces::doUpdate() { } // update m_output - auto IPC_workspace = std::find_if(IPC_workspaces.begin(), IPC_workspaces.end(), [&workspace](auto &w) { - auto wNameRaw = w["name"].asString(); - auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; - return wName == workspace->name(); - }); - workspace->setOutput((*IPC_workspace)["monitor"].asString()); + auto updated_workspace = + std::find_if(updated_workspaces.begin(), updated_workspaces.end(), [&workspace](auto &w) { + auto wNameRaw = w["name"].asString(); + auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; + return wName == workspace->name(); + }); + workspace->setOutput((*updated_workspace)["monitor"].asString()); workspace->update(m_format, workspaceIcon); } From f014a7d2e5f08260501e24d93b44bb33a4bed861 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sat, 16 Mar 2024 21:22:01 +0100 Subject: [PATCH 4/4] man docs & different css class name --- man/waybar-hyprland-workspaces.5.scd | 1 + src/modules/hyprland/workspaces.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 12c1fe39..5646df58 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -158,3 +158,4 @@ Additional to workspace name matching, the following *format-icons* can be set. - *#workspaces button.persistent* - *#workspaces button.special* - *#workspaces button.urgent* +- *#workspaces button.hosting-monitor* (gets applied if workspace-monitor == waybar-monitor) diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index bae73d2e..1b58b417 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -872,7 +872,7 @@ void Workspace::update(const std::string &format, const std::string &icon) { addOrRemoveClass(styleContext, isPersistent(), "persistent"); addOrRemoveClass(styleContext, isUrgent(), "urgent"); addOrRemoveClass(styleContext, isVisible(), "visible"); - addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "onThisMonitor"); + addOrRemoveClass(styleContext, m_workspaceManager.getBarOutput() == output(), "hosting-monitor"); std::string windows; auto windowSeparator = m_workspaceManager.getWindowSeparator();