From 7763d506912933cf4342073448c634ebccef067d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20W=C3=B6lfel?= Date: Thu, 14 Apr 2022 14:39:42 +0200 Subject: [PATCH] Add reset behaviour of modifier key Add an option to change the behaviour of the modifier key to reset the visibility. --- include/modules/sway/bar.hpp | 1 + man/waybar.5.scd.in | 7 +++++++ src/modules/sway/bar.cpp | 12 ++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/modules/sway/bar.hpp b/include/modules/sway/bar.hpp index 01be788..fd48e5a 100644 --- a/include/modules/sway/bar.hpp +++ b/include/modules/sway/bar.hpp @@ -44,6 +44,7 @@ class BarIpcClient { Ipc ipc_; swaybar_config bar_config_; + std::string modifier_reset_; bool visible_by_mode_ = false; bool visible_by_modifier_ = false; bool visible_by_urgency_ = false; diff --git a/man/waybar.5.scd.in b/man/waybar.5.scd.in index 249ca7e..1ff219b 100644 --- a/man/waybar.5.scd.in +++ b/man/waybar.5.scd.in @@ -77,6 +77,13 @@ Also a minimal example configuration can be found on the at the bottom of this m Selects one of the preconfigured display modes. This is an equivalent of the sway-bar(5) *mode* command and supports the same values: *dock*, *hide*, *invisible*, *overlay*. ++ Note: *hide* and *invisible* modes may be not as useful without Sway IPC. +modifier-reset ++ + typeof: string ++ + default: *press* + Defines the timing of modifier key to reset the bar visibility. + To reset the visibility of the bar with the press of the modifier key use *press*. + Use *release* to reset the visibility upon the release of the modifier key and only if no other action happened while the key was pressed. This prevents hiding the bar when the modifier is used to switch a workspace, change binding mode or start a keybinding. + *exclusive* ++ typeof: bool ++ default: *true* ++ diff --git a/src/modules/sway/bar.cpp b/src/modules/sway/bar.cpp index 5968d3a..26234e3 100644 --- a/src/modules/sway/bar.cpp +++ b/src/modules/sway/bar.cpp @@ -37,6 +37,8 @@ BarIpcClient::BarIpcClient(waybar::Bar& bar) : bar_{bar} { subscribe_events.append("binding"); } + modifier_reset_ = bar.config.get("modifier-reset", "press").asString(); + signal_config_.connect(sigc::mem_fun(*this, &BarIpcClient::onConfigUpdate)); signal_visible_.connect(sigc::mem_fun(*this, &BarIpcClient::onVisibilityUpdate)); signal_urgency_.connect(sigc::mem_fun(*this, &BarIpcClient::onUrgencyUpdate)); @@ -188,10 +190,12 @@ void BarIpcClient::onVisibilityUpdate(bool 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. + + // Clear on either press or release depending on bar_.bar_config_.action value. + // For the check on release, make sure that the modifier key was not used for another action. + if (((modifier_reset_ == "press" && visible_by_modifier_) || + (modifier_reset_ == "release" && !visible_by_modifier_ && modifier_no_action_))) { + // Clear the flags to hide the bar. visible_by_urgency_ = false; visible_by_mode_ = false; }