diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index c76ac267..0a834f11 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -41,6 +41,8 @@ class CreateWindow { std::string workspace_name() const { return workspace_name_; } WindowAddress addr() const { return window_address_; } + void move_to_worksace(std::string& new_workspace_name); + private: void clear_addr(); void clear_workspace_name(); diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index e26fe757..416e06f3 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -367,6 +367,15 @@ void Workspaces::on_window_moved(std::string payload) { std::string window_repr; + // If the window was still queued to be created, just change its destination + // and exit + for (auto &window : windows_to_create_) { + if (window.addr() == window_address) { + window.move_to_worksace(workspace_name); + return; + } + } + // Take the window's representation from the old workspace... for (auto &workspace : workspaces_) { try { @@ -379,7 +388,9 @@ void Workspaces::on_window_moved(std::string payload) { } // ...and add it to the new workspace - windows_to_create_.emplace_back(CreateWindow(workspace_name, window_address, window_repr)); + if (!window_repr.empty()) { + windows_to_create_.emplace_back(CreateWindow(workspace_name, window_address, window_repr)); + } } void Workspaces::update_window_count() { @@ -934,4 +945,8 @@ void CreateWindow::clear_workspace_name() { } } +void CreateWindow::move_to_worksace(std::string &new_workspace_name) { + workspace_name_ = new_workspace_name; +} + } // namespace waybar::modules::hyprland