Clear urgency hint with modifier press
If the modifier is pressed and release without another event, the intended behaviour is to clear an urgency hint and hide the bar again. Note that if multiple workspaces have the urgency hint set, the bar is hidden again and an urgent workspace is focused, the bar does not stay hidden anymore.
This commit is contained in:
parent
e3700b924e
commit
93f9b3d213
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
|
@ -43,6 +44,7 @@ class BarIpcClient {
|
||||||
swaybar_config bar_config_;
|
swaybar_config bar_config_;
|
||||||
bool visible_by_modifier_ = false;
|
bool visible_by_modifier_ = false;
|
||||||
bool visible_by_urgency_ = false;
|
bool visible_by_urgency_ = false;
|
||||||
|
std::atomic<bool> modifier_no_action_ = false;
|
||||||
|
|
||||||
SafeSignal<bool> signal_visible_;
|
SafeSignal<bool> signal_visible_;
|
||||||
SafeSignal<bool> signal_urgency_;
|
SafeSignal<bool> signal_urgency_;
|
||||||
|
|
|
@ -23,7 +23,9 @@ BarIpcClient::BarIpcClient(waybar::Bar& bar) : bar_{bar} {
|
||||||
signal_visible_.connect(sigc::mem_fun(*this, &BarIpcClient::onVisibilityUpdate));
|
signal_visible_.connect(sigc::mem_fun(*this, &BarIpcClient::onVisibilityUpdate));
|
||||||
signal_urgency_.connect(sigc::mem_fun(*this, &BarIpcClient::onUrgencyUpdate));
|
signal_urgency_.connect(sigc::mem_fun(*this, &BarIpcClient::onUrgencyUpdate));
|
||||||
|
|
||||||
ipc_.subscribe(R"(["bar_state_update", "barconfig_update", "workspace"])");
|
// Subscribe to non bar events to determine if the modifier key press is followed by another
|
||||||
|
// action.
|
||||||
|
ipc_.subscribe(R"(["bar_state_update", "barconfig_update", "workspace", "mode", "binding"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &BarIpcClient::onIpcEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &BarIpcClient::onIpcEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &BarIpcClient::onCmd));
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &BarIpcClient::onCmd));
|
||||||
// Launch worker
|
// Launch worker
|
||||||
|
@ -79,8 +81,13 @@ void BarIpcClient::onIpcEvent(const struct Ipc::ipc_response& res) {
|
||||||
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
modifier_no_action_ = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case IPC_EVENT_MODE:
|
||||||
|
case IPC_EVENT_BINDING:
|
||||||
|
modifier_no_action_ = false;
|
||||||
|
break;
|
||||||
case IPC_EVENT_BAR_STATE_UPDATE:
|
case IPC_EVENT_BAR_STATE_UPDATE:
|
||||||
case IPC_EVENT_BARCONFIG_UPDATE:
|
case IPC_EVENT_BARCONFIG_UPDATE:
|
||||||
if (auto id = payload["id"]; id.isString() && id.asString() != bar_.bar_id) {
|
if (auto id = payload["id"]; id.isString() && id.asString() != bar_.bar_id) {
|
||||||
|
@ -133,6 +140,16 @@ void BarIpcClient::onConfigUpdate(const swaybar_config& config) {
|
||||||
void BarIpcClient::onVisibilityUpdate(bool visible_by_modifier) {
|
void BarIpcClient::onVisibilityUpdate(bool visible_by_modifier) {
|
||||||
spdlog::debug("visibility update for {}: {}", bar_.bar_id, visible_by_modifier);
|
spdlog::debug("visibility update for {}: {}", bar_.bar_id, visible_by_modifier);
|
||||||
visible_by_modifier_ = visible_by_modifier;
|
visible_by_modifier_ = visible_by_modifier;
|
||||||
|
if (visible_by_modifier) {
|
||||||
|
modifier_no_action_ = true;
|
||||||
|
}
|
||||||
|
if (!visible_by_modifier_ && modifier_no_action_) {
|
||||||
|
// Modifier key was pressed and released without a different action.
|
||||||
|
// This signals an acknowledgment and should hide the bar again.
|
||||||
|
// Hide the bar and clear the urgency flag.
|
||||||
|
visible_by_urgency_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue