Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated sway-hide work to the latest master #1241

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
013bfb9
Add suppport for displaying Waybar as an overlay layer
nyyManni Oct 30, 2019
0840184
Add module sway/hide for swaybar integration
nyyManni Oct 30, 2019
0e32cff
Use layer shell version 2
somini Sep 21, 2020
4ecb22b
(does not build) try to use barconfig_update
xPMo Jan 2, 2020
4ec1718
fix: thanks nyyManni
xPMo Jan 2, 2020
551973a
Define bar setVisible method
somini Sep 21, 2020
2253f3e
Include mutext on Hide::onEvent
somini Sep 21, 2020
f1cd85f
Improve debug logs
somini Sep 21, 2020
af0b182
Remove support for "overlay" layer
somini Sep 21, 2020
d427a5b
Hide the bar on creation, in "hide" mode
somini Sep 21, 2020
3b15645
Use logging module
somini Sep 21, 2020
979a478
Don't auto-hide the bar on start
somini Sep 21, 2020
92fb316
Merge remote-tracking branch 'alexays/master' into HEAD
emirror-de Sep 12, 2021
e2590fc
Removed unnecessary functions and methods.
emirror-de Sep 12, 2021
13fbf81
Bugfix, set_opacity statements lead to address boundary SIGSEGV.
emirror-de Sep 12, 2021
1c7133c
Updated layer settings.
emirror-de Sep 12, 2021
564e231
Exclusive zone is now removed on intialization of the hide module.
emirror-de Sep 12, 2021
2e28531
sway/hide: Enable exclusive zone on {"mode":"dock"}
xPMo Sep 13, 2021
208351c
sway/hide: Print at debug level when receiving visible_by_modifier
xPMo Sep 13, 2021
24a8e85
Reset unnecessary change of function declaration.
emirror-de Sep 14, 2021
11337dc
Fixed wl_surface_commit call.
emirror-de Sep 14, 2021
00ca332
Merge remote-tracking branch 'xPMo/sway-hide' into sway-hide-updated
emirror-de Sep 14, 2021
0aecb78
Restored implementation of setVisible (to master branch state).
emirror-de Sep 14, 2021
6c3b7e4
Replaced enable-/removeExclusiveZone by setExclusive.
emirror-de Sep 14, 2021
c11aecd
Modifier key now sends the bar to TOP or BOTTOM layer, hidden class g…
emirror-de Sep 14, 2021
73de008
The sway/hide module is now limited to the bar passed by the construc…
emirror-de Sep 15, 2021
09da1f0
The mode value is now overridden to "hide" on construction of modules…
emirror-de Sep 20, 2021
8549996
Merge branch 'Alexays:master' into sway-hide-updated
emirror-de Oct 21, 2021
55ff12a
Changed how mutex is locked.
emirror-de Oct 26, 2021
e276e61
Merge branch 'sway-hide-updated' of github.com:emirror-de/Waybar into…
emirror-de Oct 26, 2021
c502e25
Merge branch 'master' into sway-hide-updated
emirror-de Oct 26, 2021
cf2312f
Added config parameter to hide the bar on startup.
emirror-de Oct 27, 2021
48f1a8f
Merge branch 'master' into sway-hide-updated
emirror-de Oct 30, 2021
d9de7c4
Refactoring sway/hide module, added hide-to-bottom-layer option
emirror-de Nov 3, 2021
0cee530
Config option hide-to-bottom-layer is now queried separately
emirror-de Nov 3, 2021
3e21eb8
Replaced worker method by a call to ipc_.setWorker.
emirror-de Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ class Bar {
~Bar() = default;

void setVisible(bool visible);
void setHiddenClass(bool value) const;
void setBottomLayerClass(bool value) const;
void moveToTopLayer() const;
void moveToBottomLayer() const;
void moveToConfiguredLayer() const;
void toggle();
void setExclusive(bool value);
void handleSignal(int);

struct waybar_output *output;
Expand Down
1 change: 1 addition & 0 deletions include/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "modules/sway/mode.hpp"
#include "modules/sway/window.hpp"
#include "modules/sway/workspaces.hpp"
#include "modules/sway/hide.hpp"
#include "modules/sway/language.hpp"
#endif
#ifdef HAVE_WLR
Expand Down
37 changes: 37 additions & 0 deletions include/modules/sway/hide.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <fmt/format.h>
#include <tuple>
#include <mutex>
#include "ALabel.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
#include "util/json.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar::modules::sway {

class Hide : public ALabel, public sigc::trackable {
public:
Hide(const std::string&, const waybar::Bar&, const Json::Value&);
~Hide() = default;
auto update() -> void;

private:
void onEvent(const struct Ipc::ipc_response&);
void worker();

std::string current_mode_;
bool visible_by_modifier_;
const Bar& bar_;
std::string window_;
int windowId_;
util::JsonParser parser_;

util::SleeperThread thread_;
std::mutex mutex_;
Ipc ipc_;
};

} // namespace waybar::modules::sway
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ src_files += [
'src/modules/sway/mode.cpp',
'src/modules/sway/language.cpp',
'src/modules/sway/window.cpp',
'src/modules/sway/workspaces.cpp'
'src/modules/sway/workspaces.cpp',
'src/modules/sway/hide.cpp',
]

if true
Expand Down
73 changes: 56 additions & 17 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,6 @@ void waybar::Bar::onMap(GdkEventAny*) {
surface = gdk_wayland_window_get_wl_surface(gdk_window);
}

void waybar::Bar::setVisible(bool value) {
visible = value;
if (!visible) {
window.get_style_context()->add_class("hidden");
window.set_opacity(0);
surface_impl_->setLayer(bar_layer::BOTTOM);
} else {
window.get_style_context()->remove_class("hidden");
window.set_opacity(1);
surface_impl_->setLayer(layer_);
}
surface_impl_->setExclusiveZone(exclusive && visible);
surface_impl_->commit();
}

void waybar::Bar::toggle() { setVisible(!visible); }

// Converting string to button code rn as to avoid doing it later
void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) {
if (config.isMember(module_name)) {
Expand Down Expand Up @@ -614,6 +597,62 @@ void waybar::Bar::handleSignal(int signal) {
}
}

void waybar::Bar::setVisible(bool value) {
visible = value;
if (!visible) {
window.get_style_context()->add_class("hidden");
window.set_opacity(0);
surface_impl_->setLayer(bar_layer::BOTTOM);
} else {
window.get_style_context()->remove_class("hidden");
window.set_opacity(1);
surface_impl_->setLayer(layer_);
}
surface_impl_->setExclusiveZone(exclusive && visible);
surface_impl_->commit();
}

void waybar::Bar::setHiddenClass(bool value) const {
if (value) {
window.get_style_context()->add_class("hidden");
} else {
window.get_style_context()->remove_class("hidden");
}
}

void waybar::Bar::setBottomLayerClass(bool value) const {
if (value) {
window.get_style_context()->add_class("bottom-layer");
} else {
window.get_style_context()->remove_class("bottom-layer");
}
}

void waybar::Bar::moveToTopLayer() const {
surface_impl_->setLayer(bar_layer::TOP);
surface_impl_->commit();
}

void waybar::Bar::moveToBottomLayer() const {
surface_impl_->setLayer(bar_layer::BOTTOM);
surface_impl_->commit();
}

void waybar::Bar::moveToConfiguredLayer() const {
surface_impl_->setLayer(layer_);
surface_impl_->commit();
}

void waybar::Bar::setExclusive(bool value) {
exclusive = value;
surface_impl_->setExclusiveZone(exclusive && visible);
surface_impl_->commit();
}

void waybar::Bar::toggle() {
return setVisible(!visible);
}

void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
if (config[pos].isArray()) {
for (const auto& name : config[pos]) {
Expand Down
3 changes: 3 additions & 0 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
if (ref == "sway/window") {
return new waybar::modules::sway::Window(id, bar_, config_[name]);
}
if (ref == "sway/hide") {
return new waybar::modules::sway::Hide(id, bar_, config_[name]);
}
if (ref == "sway/language") {
return new waybar::modules::sway::Language(id, config_[name]);
}
Expand Down
83 changes: 83 additions & 0 deletions src/modules/sway/hide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "modules/sway/hide.hpp"
#include <spdlog/spdlog.h>
#include "client.hpp"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"

namespace waybar::modules::sway {

Hide::Hide(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "hide", id, "{}", 0, true), bar_(bar), windowId_(-1) {
ipc_.subscribe(R"(["bar_state_update","barconfig_update"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Hide::onEvent));

// override mode to "hide"
auto &bar_local = const_cast<Bar &>(bar_);
bar_local.config["mode"] = "hide";
bar_local.setExclusive(false);

if (config_["hide-on-startup"].asBool()) {
spdlog::debug("sway/hide: Hiding on startup enabled!");
bar_local.setHiddenClass(true);
bar_local.moveToConfiguredLayer();
} else {
bar_local.moveToTopLayer();
}

ipc_.setWorker([this] {
try {
ipc_.handleEvent();
} catch (const std::exception& e) {
spdlog::error("Hide: {}", e.what());
}
});
}

void Hide::onEvent(const struct Ipc::ipc_response& res) {
std::lock_guard<std::mutex> lock(mutex_);
auto payload = parser_.parse(res.payload);
auto &bar = const_cast<Bar &>(bar_);

if (payload.isMember("mode")) {
auto mode = payload["mode"].asString();
if (mode == "hide") {
// Hide the bars when configuring the "hide" bar
spdlog::debug("sway/hide: hiding bar(s)");
bar.setVisible(false);
bar.setExclusive(false);
} else if (mode == "dock") { // enables toggling the bar using killall -USR2 waybar
spdlog::debug("sway/hide: showing bar(s)");
bar.setVisible(true);
bar.setExclusive(true);
}
emirror-de marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (payload.isMember("visible_by_modifier")) {
visible_by_modifier_ = payload["visible_by_modifier"].asBool();
spdlog::debug("sway/hide: visible by modifier: {}", visible_by_modifier_);

if (visible_by_modifier_) {
bar.setHiddenClass(false);
bar.setBottomLayerClass(false);
bar.moveToTopLayer();
return;
}

bool hide_to_bottom_layer_ = config_["hide-to-bottom-layer"].asBool();
if (hide_to_bottom_layer_) {
spdlog::debug("sway/hide: Moving bar to bottom layer instead of hiding.");
bar.setBottomLayerClass(true);
bar.moveToBottomLayer();
return;
}

bar.setBottomLayerClass(false);
bar.setHiddenClass(true);
bar.moveToConfiguredLayer();
}
}

auto Hide::update() -> void {
}

} // namespace waybar::modules::sway