Merge branch 'master' into master

This commit is contained in:
Alex 2019-03-05 10:15:05 +01:00 committed by GitHub
commit 1974766125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 16 deletions

View File

@ -28,9 +28,8 @@ protected:
bool alt_ = false; bool alt_ = false;
std::string default_format_; std::string default_format_;
private: virtual bool handleToggle(GdkEventButton *const &ev);
bool handleToggle(GdkEventButton *const &ev); virtual bool handleScroll(GdkEventScroll *);
bool handleScroll(GdkEventScroll *);
}; };
} // namespace waybar } // namespace waybar

View File

@ -13,7 +13,7 @@ class IdleInhibitor: public ALabel {
~IdleInhibitor(); ~IdleInhibitor();
auto update() -> void; auto update() -> void;
private: private:
bool onClick(GdkEventButton* const& ev); bool handleToggle(GdkEventButton* const& e);
const Bar& bar_; const Bar& bar_;
std::string status_; std::string status_;

View File

@ -20,6 +20,7 @@ class Workspaces : public IModule {
private: private:
void worker(); void worker();
void addWorkspace(const Json::Value&); void addWorkspace(const Json::Value&);
void onButtonReady(const Json::Value&, Gtk::Button&);
std::string getIcon(const std::string&, const Json::Value&); std::string getIcon(const std::string&, const Json::Value&);
bool handleScroll(GdkEventScroll*); bool handleScroll(GdkEventScroll*);
std::string getPrevWorkspace(); std::string getPrevWorkspace();

View File

@ -1,5 +1,5 @@
#include "modules/idle_inhibitor.hpp" #include "modules/idle_inhibitor.hpp"
#include "util/command.hpp"
waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config) waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "{status}"), bar_(bar), status_("deactivated"), idle_inhibitor_(nullptr) : ALabel(config, "{status}"), bar_(bar), status_("deactivated"), idle_inhibitor_(nullptr)
@ -10,7 +10,7 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar&
} }
event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect( event_box_.signal_button_press_event().connect(
sigc::mem_fun(*this, &IdleInhibitor::onClick)); sigc::mem_fun(*this, &IdleInhibitor::handleToggle));
dp.emit(); dp.emit();
} }
@ -32,9 +32,8 @@ auto waybar::modules::IdleInhibitor::update() -> void
} }
} }
bool waybar::modules::IdleInhibitor::onClick(GdkEventButton* const& e) bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
{ if (e->button == 1) {
if(e->button == 1) {
if (idle_inhibitor_) { if (idle_inhibitor_) {
zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); zwp_idle_inhibitor_v1_destroy(idle_inhibitor_);
idle_inhibitor_ = nullptr; idle_inhibitor_ = nullptr;
@ -44,7 +43,13 @@ bool waybar::modules::IdleInhibitor::onClick(GdkEventButton* const& e)
bar_.client.idle_inhibit_manager, bar_.surface); bar_.client.idle_inhibit_manager, bar_.surface);
status_ = "activated"; status_ = "activated";
} }
if (config_["on-click"].isString() && e->button == 1) {
waybar::util::command::forkExec(config_["on-click"].asString());
} }
} else {
ALabel::handleToggle(e);
}
dp.emit(); dp.emit();
return true; return true;
} }

View File

@ -135,10 +135,17 @@ void waybar::modules::Network::worker()
auto waybar::modules::Network::update() -> void auto waybar::modules::Network::update() -> void
{ {
std::string connectiontype; std::string connectiontype;
std::string tooltip_format = "";
if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
if (ifid_ <= 0 || ipaddr_.empty()) { if (ifid_ <= 0 || ipaddr_.empty()) {
if (config_["format-disconnected"].isString()) { if (config_["format-disconnected"].isString()) {
default_format_ = config_["format-disconnected"].asString(); default_format_ = config_["format-disconnected"].asString();
} }
if (config_["tooltip-format-disconnected"].isString()) {
tooltip_format = config_["tooltip-format-disconnected"].asString();
}
label_.get_style_context()->add_class("disconnected"); label_.get_style_context()->add_class("disconnected");
connectiontype = "disconnected"; connectiontype = "disconnected";
} else { } else {
@ -146,11 +153,17 @@ auto waybar::modules::Network::update() -> void
if (config_["format-ethernet"].isString()) { if (config_["format-ethernet"].isString()) {
default_format_ = config_["format-ethernet"].asString(); default_format_ = config_["format-ethernet"].asString();
} }
if (config_["tooltip-format-ethernet"].isString()) {
tooltip_format = config_["tooltip-format-ethernet"].asString();
}
connectiontype = "ethernet"; connectiontype = "ethernet";
} else { } else {
if (config_["format-wifi"].isString()) { if (config_["format-wifi"].isString()) {
default_format_ = config_["format-wifi"].asString(); default_format_ = config_["format-wifi"].asString();
} }
if (config_["tooltip-format-wifi"].isString()) {
tooltip_format = config_["tooltip-format-wifi"].asString();
}
connectiontype = "wifi"; connectiontype = "wifi";
} }
label_.get_style_context()->remove_class("disconnected"); label_.get_style_context()->remove_class("disconnected");
@ -158,7 +171,7 @@ auto waybar::modules::Network::update() -> void
if (!alt_) { if (!alt_) {
format_ = default_format_; format_ = default_format_;
} }
label_.set_markup(fmt::format(format_, auto text = fmt::format(format_,
fmt::arg("essid", essid_), fmt::arg("essid", essid_),
fmt::arg("signaldBm", signal_strength_dbm_), fmt::arg("signaldBm", signal_strength_dbm_),
fmt::arg("signalStrength", signal_strength_), fmt::arg("signalStrength", signal_strength_),
@ -167,7 +180,25 @@ auto waybar::modules::Network::update() -> void
fmt::arg("ipaddr", ipaddr_), fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_), fmt::arg("cidr", cidr_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype)) fmt::arg("icon", getIcon(signal_strength_, connectiontype))
)); );
label_.set_markup(text);
if (tooltipEnabled()) {
if (!tooltip_format.empty()) {
auto tooltip_text = fmt::format(tooltip_format,
fmt::arg("essid", essid_),
fmt::arg("signaldBm", signal_strength_dbm_),
fmt::arg("signalStrength", signal_strength_),
fmt::arg("ifname", ifname_),
fmt::arg("netmask", netmask_),
fmt::arg("ipaddr", ipaddr_),
fmt::arg("cidr", cidr_),
fmt::arg("icon", getIcon(signal_strength_, connectiontype))
);
label_.set_tooltip_text(tooltip_text);
} else {
label_.set_tooltip_text(text);
}
}
} }
void waybar::modules::Network::disconnected() void waybar::modules::Network::disconnected()

View File

@ -87,7 +87,8 @@ auto waybar::modules::sway::Workspaces::update() -> void
} else { } else {
button.set_label(icon); button.set_label(icon);
} }
button.show();
onButtonReady(node, button);
} }
} }
if (scrolling_) { if (scrolling_) {
@ -131,7 +132,8 @@ void waybar::modules::sway::Workspaces::addWorkspace(const Json::Value &node)
if (node["urgent"].asBool()) { if (node["urgent"].asBool()) {
button.get_style_context()->add_class("urgent"); button.get_style_context()->add_class("urgent");
} }
button.show();
onButtonReady(node, button);
} }
std::string waybar::modules::sway::Workspaces::getIcon(const std::string &name, std::string waybar::modules::sway::Workspaces::getIcon(const std::string &name,
@ -251,6 +253,19 @@ std::string waybar::modules::sway::Workspaces::trimWorkspaceName(std::string nam
return name; return name;
} }
void waybar::modules::sway::Workspaces::onButtonReady(const Json::Value& node, Gtk::Button& button)
{
if (config_["current-only"].asBool()) {
if (node["focused"].asBool()) {
button.show();
} else {
button.hide();
}
} else {
button.show();
}
}
waybar::modules::sway::Workspaces::operator Gtk::Widget &() { waybar::modules::sway::Workspaces::operator Gtk::Widget &() {
return box_; return box_;
} }