hyprland/workspaces: add debounce timer to prevent workspace button flicker
When switching between workspaces rapidly (especially empty ones), Hyprland sends createworkspace and destroyworkspace events slightly out of order. This causes workspace buttons to render in wrong positions for a split second before snapping to their correct spots. Add a 7ms debounce timer that batches workspace events before calling dp.emit(), preventing the visual glitch. Fixes #4376
This commit is contained in:
@@ -211,6 +211,9 @@ class Workspaces : public AModule, public EventHandler {
|
||||
Gtk::Box m_box;
|
||||
sigc::connection m_scrollEventConnection_;
|
||||
IPC& m_ipc;
|
||||
|
||||
sigc::connection m_debounceTimer;
|
||||
bool m_updatePending = false;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::hyprland
|
||||
|
||||
@@ -338,6 +338,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& c
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const std::string& ev) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
const auto separator = ev.find(">>");
|
||||
if (separator == std::string::npos) {
|
||||
@@ -376,8 +377,23 @@ void Workspaces::onEvent(const std::string& ev) {
|
||||
} else if (eventName == "configreloaded") {
|
||||
onConfigReloaded();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_debounceTimer.connected()) {
|
||||
m_debounceTimer.disconnect();
|
||||
m_updatePending = false;
|
||||
}
|
||||
|
||||
m_updatePending = true;
|
||||
m_debounceTimer = Glib::signal_timeout().connect([this]() {
|
||||
if (!m_updatePending) return false;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_updatePending) {
|
||||
dp.emit();
|
||||
m_updatePending = false;
|
||||
}
|
||||
return false;
|
||||
}, 7);
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceActivated(std::string const& payload) {
|
||||
|
||||
Reference in New Issue
Block a user