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 17 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
5 changes: 3 additions & 2 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class Bar {
Bar(const Bar &) = delete;
~Bar() = default;

void setVisible(bool visible);
void toggle();
auto setVisible(bool nvis) -> void;
auto toggle() -> void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm nitpicking, but why was that change necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's totally justified. I took the wrong definition while resolving the merge conflicts. I will correct this.

auto removeExclusiveZone() const -> void;
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 @@ -179,7 +179,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
37 changes: 20 additions & 17 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,23 +529,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 @@ -607,6 +590,26 @@ void waybar::Bar::handleSignal(int signal) {
}
}

auto waybar::Bar::setVisible(bool nvis) -> void {
visible = nvis;
if (!visible) {
window.get_style_context()->add_class("hidden");
surface_impl_->setLayer(bar_layer::BOTTOM);
} else {
window.get_style_context()->remove_class("hidden");
surface_impl_->setLayer(bar_layer::TOP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overrides the layer set in the config file.
You can implement that differently:

void waybar::Bar::setLayer(bar_layer layer) {
  layer_ = layer;
  surface_impl_->setLayer(layer_);
}

and call the method from the same location where you are disabling exclusive zone.

}
wl_surface_commit(surface);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous wl_surface_commit is known to be able to crash Gtk in certain cases (as found and fixed in gtk-layer-shell). Also, surface can be unset you call that on an unmapped window.
That's why the code in master branch is calling surface_impl_->commit() which is noop for the most cases.

}

auto waybar::Bar::removeExclusiveZone() const -> void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to do it like this:

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

surface_impl_->setExclusiveZone(false);
}

auto waybar::Bar::toggle() -> void {
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
52 changes: 52 additions & 0 deletions src/modules/sway/hide.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#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));
// Do not reserve space for the bar anymore
bar.removeExclusiveZone();
// Launch worker
worker();
}

void Hide::onEvent(const struct Ipc::ipc_response& res) {
auto payload = parser_.parse(res.payload);
std::lock_guard<std::mutex> lock(mutex_);
if (payload.isMember("mode")) {
// barconfig_update: get mode
auto mode = payload["mode"].asString();
if (mode == "hide") {
// Hide the bars when configuring the "hide" bar
for (auto& bar : waybar::Client::inst()->bars) {
bar->setVisible(false);
}
}
emirror-de marked this conversation as resolved.
Show resolved Hide resolved
} else if (payload.isMember("visible_by_modifier")) {
// bar_state_update: get visible_by_modifier
visible_by_modifier_ = payload["visible_by_modifier"].asBool();
spdlog::info("WayBar Shown: {}", visible_by_modifier_);
emirror-de marked this conversation as resolved.
Show resolved Hide resolved
for (auto& bar : waybar::Client::inst()->bars) {
bar->setVisible(visible_by_modifier_);
}
}
}

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

auto Hide::update() -> void {
}
} // namespace waybar::modules::sway