mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ffc7ee3b3 | |||
ff28de0482 | |||
d5e8a37e63 | |||
67786c32a8 | |||
93a644eec4 | |||
aa385e28b6 | |||
2c1a3d0430 | |||
b31a64ad00 | |||
4865a9ad6c | |||
e70d8aff73 | |||
3e1c77d158 | |||
d34c3a801c | |||
794fb12e8c | |||
43d724ebad | |||
c862fde986 | |||
0d59f7b7d1 | |||
1e95f5d9b6 | |||
9234be8544 | |||
9d3255fe9f | |||
d2d9db23b5 | |||
d8be72e4b6 | |||
f8a47598ba | |||
cb2d6e1997 | |||
17291dffdf |
@ -22,6 +22,8 @@ class Custom : public ALabel {
|
||||
void continuousWorker();
|
||||
void parseOutputRaw();
|
||||
void parseOutputJson();
|
||||
bool handleScroll(GdkEventScroll* e);
|
||||
bool handleToggle(GdkEventButton* const& e);
|
||||
|
||||
const std::string name_;
|
||||
std::string text_;
|
||||
|
@ -36,8 +36,9 @@ class Network : public ALabel {
|
||||
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
|
||||
void parseEssid(struct nlattr**);
|
||||
void parseSignal(struct nlattr**);
|
||||
void parseFreq(struct nlattr**);
|
||||
bool associatedOrJoined(struct nlattr**);
|
||||
bool checkInterface(int if_index, std::string name);
|
||||
bool checkInterface(struct ifinfomsg *rtif, std::string name);
|
||||
int getPreferredIface();
|
||||
auto getInfo() -> void;
|
||||
bool wildcardMatch(const std::string& pattern, const std::string& text);
|
||||
@ -55,6 +56,9 @@ class Network : public ALabel {
|
||||
int nl80211_id_;
|
||||
std::mutex mutex_;
|
||||
|
||||
unsigned long long bandwidth_down_total_;
|
||||
unsigned long long bandwidth_up_total_;
|
||||
|
||||
std::string essid_;
|
||||
std::string ifname_;
|
||||
std::string ipaddr_;
|
||||
@ -63,6 +67,7 @@ class Network : public ALabel {
|
||||
bool linked_;
|
||||
int32_t signal_strength_dbm_;
|
||||
uint8_t signal_strength_;
|
||||
uint32_t frequency_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules
|
||||
|
@ -46,7 +46,7 @@ class Item : public sigc::trackable {
|
||||
std::string menu;
|
||||
DbusmenuGtkMenu* dbus_menu = nullptr;
|
||||
Gtk::Menu* gtk_menu = nullptr;
|
||||
bool item_is_menu;
|
||||
bool item_is_menu = false;
|
||||
|
||||
private:
|
||||
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
|
||||
@ -59,8 +59,8 @@ class Item : public sigc::trackable {
|
||||
void updateImage();
|
||||
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
|
||||
Glib::RefPtr<Gdk::Pixbuf> getIconByName(const std::string& name, int size);
|
||||
static void onMenuDestroyed(Item* self);
|
||||
bool makeMenu(GdkEventButton* const& ev);
|
||||
static void onMenuDestroyed(Item* self, GObject* old_menu_pointer);
|
||||
void makeMenu(GdkEventButton* const& ev);
|
||||
bool handleClick(GdkEventButton* const& /*ev*/);
|
||||
|
||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||
|
@ -1,6 +1,6 @@
|
||||
project(
|
||||
'waybar', 'cpp', 'c',
|
||||
version: '0.6.4',
|
||||
version: '0.6.5',
|
||||
license: 'MIT',
|
||||
default_options : [
|
||||
'cpp_std=c++17',
|
||||
|
19
src/bar.cpp
19
src/bar.cpp
@ -20,7 +20,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||
height_ = 0;
|
||||
width_ = 1;
|
||||
}
|
||||
window.set_size_request(width_, height_);
|
||||
|
||||
auto gtk_window = window.gobj();
|
||||
auto gtk_widget = GTK_WIDGET(gtk_window);
|
||||
@ -43,8 +42,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||
auto height = config["height"].isUInt() ? config["height"].asUInt() : height_;
|
||||
auto width = config["width"].isUInt() ? config["width"].asUInt() : width_;
|
||||
|
||||
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure));
|
||||
|
||||
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||
if (config["position"] == "bottom") {
|
||||
anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||
@ -73,6 +70,9 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||
wl_display_roundtrip(client->wl_display);
|
||||
|
||||
setupWidgets();
|
||||
|
||||
window.set_size_request(width_, height_);
|
||||
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure));
|
||||
}
|
||||
|
||||
void waybar::Bar::setMarginsAndZone(uint32_t height, uint32_t width) {
|
||||
@ -272,11 +272,14 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
||||
modules_right_.emplace_back(module);
|
||||
}
|
||||
module->dp.connect([module, &name] {
|
||||
try {
|
||||
module->update();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << name.asString() + ": " + e.what() << std::endl;
|
||||
}
|
||||
// Fix https://github.com/Alexays/Waybar/issues/320, proper way?
|
||||
Glib::signal_idle().connect_once([module, &name] {
|
||||
try {
|
||||
module->update();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << name.asString() + ": " + e.what() << std::endl;
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
|
@ -153,6 +153,7 @@ void waybar::Client::handleName(void * data, struct zxdg_output_v1 * /*xdg_
|
||||
wl_output_destroy(output->output);
|
||||
zxdg_output_v1_destroy(output->xdg_output);
|
||||
} else {
|
||||
wl_display_roundtrip(client->wl_display);
|
||||
for (const auto &config : configs) {
|
||||
client->bars.emplace_back(std::make_unique<Bar>(output.get(), config));
|
||||
Glib::RefPtr<Gdk::Screen> screen = client->bars.back()->window.get_screen();
|
||||
|
@ -93,10 +93,14 @@ const std::tuple<uint8_t, uint32_t, std::string> waybar::modules::Battery::getIn
|
||||
total += capacity;
|
||||
total_current += current_now;
|
||||
}
|
||||
uint16_t capacity = total / batteries_.size();
|
||||
if (status == "Charging" && total_current != 0) {
|
||||
status = "Plugged";
|
||||
if (!adapter_.empty() && status == "Discharging") {
|
||||
bool online;
|
||||
std::ifstream(adapter_ / "online") >> online;
|
||||
if (online) {
|
||||
status = "Plugged";
|
||||
}
|
||||
}
|
||||
uint16_t capacity = total / batteries_.size();
|
||||
return {capacity, total_current, status};
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
@ -113,7 +117,7 @@ const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity,
|
||||
return "Full";
|
||||
}
|
||||
if (online) {
|
||||
return current_now == 0 ? "Charging" : "Plugged";
|
||||
return "Charging";
|
||||
}
|
||||
return "Discharging";
|
||||
}
|
||||
|
@ -79,6 +79,18 @@ void waybar::modules::Custom::refresh(int sig /*signal*/) {
|
||||
}
|
||||
}
|
||||
|
||||
bool waybar::modules::Custom::handleScroll(GdkEventScroll* e) {
|
||||
auto ret = ALabel::handleScroll(e);
|
||||
thread_.wake_up();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
|
||||
auto ret = ALabel::handleToggle(e);
|
||||
thread_.wake_up();
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto waybar::modules::Custom::update() -> void {
|
||||
// Hide label if output is empty
|
||||
if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) {
|
||||
|
@ -1,5 +1,74 @@
|
||||
#include "modules/network.hpp"
|
||||
#include <sys/eventfd.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const char * NETSTAT_FILE = "/proc/net/netstat"; // std::ifstream does not take std::string_view as param
|
||||
constexpr std::string_view BANDWIDTH_CATEGORY = "IpExt";
|
||||
constexpr std::string_view BANDWIDTH_DOWN_TOTAL_KEY = "InOctets";
|
||||
constexpr std::string_view BANDWIDTH_UP_TOTAL_KEY = "OutOctets";
|
||||
|
||||
std::ifstream netstat(NETSTAT_FILE);
|
||||
std::optional<unsigned long long> read_netstat(std::string_view category, std::string_view key) {
|
||||
if (!netstat) {
|
||||
std::cerr << "Failed to open netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
return {};
|
||||
}
|
||||
netstat.seekg(std::ios_base::beg);
|
||||
|
||||
|
||||
// finding corresponding line (category)
|
||||
// looks into the file for the first line starting by the 'category' string
|
||||
auto starts_with = [](const std::string& str, std::string_view start) {
|
||||
return start == std::string_view{str.data(), std::min(str.size(), start.size())};
|
||||
};
|
||||
|
||||
std::string read;
|
||||
while (std::getline(netstat, read) && !starts_with(read, category));
|
||||
if (!starts_with(read, category)) {
|
||||
std::cerr << "Category '" << category << "' not found in netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
return {};
|
||||
}
|
||||
|
||||
// finding corresponding column (key)
|
||||
// looks into the fetched line for the first word (space separated) equal to 'key'
|
||||
int index = 0;
|
||||
auto r_it = read.begin();
|
||||
auto k_it = key.begin();
|
||||
while (k_it != key.end() && r_it != read.end()) {
|
||||
if (*r_it != *k_it) {
|
||||
r_it = std::find(r_it, read.end(), ' ');
|
||||
if (r_it != read.end()) {
|
||||
++r_it;
|
||||
}
|
||||
k_it = key.begin();
|
||||
++index;
|
||||
} else {
|
||||
++r_it;
|
||||
++k_it;
|
||||
}
|
||||
}
|
||||
|
||||
if (r_it == read.end() && k_it != key.end()) {
|
||||
std::cerr << "Key '" << key << "' not found in category '" << category << "' of netstat file " << NETSTAT_FILE << '\n' << std::flush;
|
||||
return {};
|
||||
}
|
||||
|
||||
// finally accessing value
|
||||
// accesses the line right under the fetched one
|
||||
std::getline(netstat, read);
|
||||
assert(starts_with(read, category));
|
||||
std::istringstream iss(read);
|
||||
while (index--) {
|
||||
std::getline(iss, read, ' ');
|
||||
}
|
||||
unsigned long long value;
|
||||
iss >> value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
|
||||
: ALabel(config, "{ifname}", 60),
|
||||
@ -10,11 +79,27 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
|
||||
ev_fd_(-1),
|
||||
cidr_(-1),
|
||||
signal_strength_dbm_(0),
|
||||
signal_strength_(0) {
|
||||
signal_strength_(0),
|
||||
frequency_(0) {
|
||||
label_.set_name("network");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
|
||||
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
||||
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
|
||||
if (down_octets) {
|
||||
bandwidth_down_total_ = *down_octets;
|
||||
} else {
|
||||
bandwidth_down_total_ = 0;
|
||||
}
|
||||
|
||||
if (up_octets) {
|
||||
bandwidth_up_total_ = *up_octets;
|
||||
} else {
|
||||
bandwidth_up_total_ = 0;
|
||||
}
|
||||
|
||||
createInfoSocket();
|
||||
createEventSocket();
|
||||
auto default_iface = getPreferredIface();
|
||||
@ -41,8 +126,6 @@ waybar::modules::Network::~Network() {
|
||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_LINK);
|
||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV4_ROUTE);
|
||||
nl_socket_drop_membership(ev_sock_, RTNLGRP_IPV6_ROUTE);
|
||||
nl_close(ev_sock_);
|
||||
nl_socket_free(ev_sock_);
|
||||
}
|
||||
@ -63,8 +146,6 @@ void waybar::modules::Network::createInfoSocket() {
|
||||
nl_socket_add_membership(ev_sock_, RTNLGRP_LINK);
|
||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV4_IFADDR);
|
||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV6_IFADDR);
|
||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV4_ROUTE);
|
||||
nl_socket_add_membership(ev_sock_, RTNLGRP_IPV6_ROUTE);
|
||||
efd_ = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (efd_ < 0) {
|
||||
throw std::runtime_error("Can't create epoll");
|
||||
@ -107,9 +188,12 @@ void waybar::modules::Network::createEventSocket() {
|
||||
|
||||
void waybar::modules::Network::worker() {
|
||||
thread_timer_ = [this] {
|
||||
if (ifid_ > 0) {
|
||||
getInfo();
|
||||
dp.emit();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (ifid_ > 0) {
|
||||
getInfo();
|
||||
dp.emit();
|
||||
}
|
||||
}
|
||||
thread_timer_.sleep_for(interval_);
|
||||
};
|
||||
@ -130,10 +214,22 @@ void waybar::modules::Network::worker() {
|
||||
}
|
||||
|
||||
auto waybar::modules::Network::update() -> void {
|
||||
std::string connectiontype;
|
||||
std::string tooltip_format = "";
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
tooltip_format = config_["tooltip-format"].asString();
|
||||
std::string connectiontype;
|
||||
std::string tooltip_format;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
||||
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
|
||||
|
||||
unsigned long long bandwidth_down = 0;
|
||||
if (down_octets) {
|
||||
bandwidth_down = *down_octets - bandwidth_down_total_;
|
||||
bandwidth_down_total_ = *down_octets;
|
||||
}
|
||||
|
||||
unsigned long long bandwidth_up = 0;
|
||||
if (up_octets) {
|
||||
bandwidth_up = *up_octets - bandwidth_up_total_;
|
||||
bandwidth_up_total_ = *up_octets;
|
||||
}
|
||||
if (ifid_ <= 0 || !linked_) {
|
||||
if (config_["format-disconnected"].isString()) {
|
||||
@ -176,6 +272,25 @@ auto waybar::modules::Network::update() -> void {
|
||||
format_ = default_format_;
|
||||
}
|
||||
getState(signal_strength_);
|
||||
|
||||
auto pow_format = [](unsigned long long value, const std::string& unit) {
|
||||
if (value > 2000ull * 1000ull * 1000ull) { // > 2G
|
||||
auto go = value / (1000 * 1000 * 1000);
|
||||
return std::to_string(go) + "." + std::to_string((value - go * 1000 * 1000 * 1000) / (100 * 1000 * 1000)) + "G" + unit;
|
||||
|
||||
} else if (value > 2000ull * 1000ull) { // > 2M
|
||||
auto mo = value / (1000 * 1000);
|
||||
return std::to_string(mo) + "." + std::to_string((value - mo * 1000 * 1000) / (100 * 1000)) + "M" + unit;
|
||||
|
||||
} else if (value > 2000ull) { // > 2k
|
||||
auto ko = value / 1000;
|
||||
return std::to_string(ko) + "." + std::to_string((value - ko * 1000) / 100) + "k" + unit;
|
||||
|
||||
} else {
|
||||
return std::to_string(value) + unit;
|
||||
}
|
||||
};
|
||||
|
||||
auto text = fmt::format(format_,
|
||||
fmt::arg("essid", essid_),
|
||||
fmt::arg("signaldBm", signal_strength_dbm_),
|
||||
@ -184,9 +299,19 @@ auto waybar::modules::Network::update() -> void {
|
||||
fmt::arg("netmask", netmask_),
|
||||
fmt::arg("ipaddr", ipaddr_),
|
||||
fmt::arg("cidr", cidr_),
|
||||
fmt::arg("icon", getIcon(signal_strength_, connectiontype)));
|
||||
label_.set_markup(text);
|
||||
fmt::arg("frequency", frequency_),
|
||||
fmt::arg("icon", getIcon(signal_strength_, connectiontype)),
|
||||
fmt::arg("bandwidthDownBits", pow_format(bandwidth_down * 8ull / interval_.count(), "b/s")),
|
||||
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / interval_.count(), "b/s")),
|
||||
fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / interval_.count(), "o/s")),
|
||||
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
||||
if (text != label_.get_label()) {
|
||||
label_.set_markup(text);
|
||||
}
|
||||
if (tooltipEnabled()) {
|
||||
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
||||
tooltip_format = config_["tooltip-format"].asString();
|
||||
}
|
||||
if (!tooltip_format.empty()) {
|
||||
auto tooltip_text = fmt::format(tooltip_format,
|
||||
fmt::arg("essid", essid_),
|
||||
@ -196,9 +321,16 @@ auto waybar::modules::Network::update() -> void {
|
||||
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 {
|
||||
fmt::arg("frequency", frequency_),
|
||||
fmt::arg("icon", getIcon(signal_strength_, connectiontype)),
|
||||
fmt::arg("bandwidthDownBits", pow_format(bandwidth_down * 8ull / interval_.count(), "b/s")),
|
||||
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / interval_.count(), "b/s")),
|
||||
fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / interval_.count(), "o/s")),
|
||||
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s")));
|
||||
if (label_.get_tooltip_text() != text) {
|
||||
label_.set_tooltip_text(tooltip_text);
|
||||
}
|
||||
} else if (label_.get_tooltip_text() != text) {
|
||||
label_.set_tooltip_text(text);
|
||||
}
|
||||
}
|
||||
@ -395,7 +527,7 @@ int waybar::modules::Network::netlinkResponse(void *resp, uint32_t resplen, uint
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool waybar::modules::Network::checkInterface(int if_index, std::string name) {
|
||||
bool waybar::modules::Network::checkInterface(struct ifinfomsg *rtif, std::string name) {
|
||||
if (config_["interface"].isString()) {
|
||||
return config_["interface"].asString() == name ||
|
||||
wildcardMatch(config_["interface"].asString(), name);
|
||||
@ -403,9 +535,9 @@ bool waybar::modules::Network::checkInterface(int if_index, std::string name) {
|
||||
auto external_iface = getExternalInterface();
|
||||
if (external_iface == -1) {
|
||||
// Try with lastest working external iface
|
||||
return last_ext_iface_ == if_index;
|
||||
return last_ext_iface_ == rtif->ifi_index;
|
||||
}
|
||||
return external_iface == if_index;
|
||||
return external_iface == rtif->ifi_index;
|
||||
}
|
||||
|
||||
int waybar::modules::Network::getPreferredIface() {
|
||||
@ -454,23 +586,21 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
char ifname[IF_NAMESIZE];
|
||||
if_indextoname(rtif->ifi_index, ifname);
|
||||
// Auto detected network can also be assigned here
|
||||
if (net->checkInterface(rtif->ifi_index, ifname) && net->ifid_ == -1) {
|
||||
if (net->ifid_ == -1 && net->checkInterface(rtif, ifname)) {
|
||||
net->linked_ = true;
|
||||
net->ifname_ = ifname;
|
||||
net->ifid_ = rtif->ifi_index;
|
||||
net->dp.emit();
|
||||
}
|
||||
// Check for valid interface
|
||||
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
|
||||
if (rtif->ifi_index == net->ifid_) {
|
||||
// Get Iface and WIFI info
|
||||
net->thread_timer_.wake_up();
|
||||
net->getInterfaceAddress();
|
||||
net->dp.emit();
|
||||
net->thread_timer_.wake_up();
|
||||
}
|
||||
} else if (nh->nlmsg_type == RTM_DELADDR) {
|
||||
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
|
||||
// Check for valid interface
|
||||
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
|
||||
if (rtif->ifi_index == net->ifid_) {
|
||||
net->ipaddr_.clear();
|
||||
net->netmask_.clear();
|
||||
net->cidr_ = 0;
|
||||
@ -481,7 +611,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
char ifname[IF_NAMESIZE];
|
||||
if_indextoname(rtif->ifi_index, ifname);
|
||||
// Check for valid interface
|
||||
if (net->checkInterface(rtif->ifi_index, ifname) && rtif->ifi_flags & IFF_RUNNING) {
|
||||
if (rtif->ifi_flags & IFF_RUNNING && net->checkInterface(rtif, ifname)) {
|
||||
net->linked_ = true;
|
||||
net->ifname_ = ifname;
|
||||
net->ifid_ = rtif->ifi_index;
|
||||
@ -493,13 +623,15 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
net->essid_.clear();
|
||||
net->signal_strength_dbm_ = 0;
|
||||
net->signal_strength_ = 0;
|
||||
net->frequency_ = 0;
|
||||
// Check for a new interface and get info
|
||||
auto new_iface = net->getPreferredIface();
|
||||
if (new_iface != -1) {
|
||||
net->thread_timer_.wake_up();
|
||||
net->getInterfaceAddress();
|
||||
net->thread_timer_.wake_up();
|
||||
} else {
|
||||
net->dp.emit();
|
||||
}
|
||||
net->dp.emit();
|
||||
}
|
||||
}
|
||||
return NL_SKIP;
|
||||
@ -536,7 +668,7 @@ int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) {
|
||||
}
|
||||
net->parseEssid(bss);
|
||||
net->parseSignal(bss);
|
||||
// TODO(someone): parse quality
|
||||
net->parseFreq(bss);
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
@ -576,6 +708,13 @@ void waybar::modules::Network::parseSignal(struct nlattr **bss) {
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Network::parseFreq(struct nlattr **bss) {
|
||||
if (bss[NL80211_BSS_FREQUENCY] != nullptr) {
|
||||
// in MHz
|
||||
frequency_ = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
|
||||
}
|
||||
}
|
||||
|
||||
bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) {
|
||||
if (bss[NL80211_BSS_STATUS] == nullptr) {
|
||||
return false;
|
||||
|
@ -276,39 +276,38 @@ Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int reque
|
||||
name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
}
|
||||
|
||||
void Item::onMenuDestroyed(Item* self) {
|
||||
self->gtk_menu = nullptr;
|
||||
self->dbus_menu = nullptr;
|
||||
void Item::onMenuDestroyed(Item* self, GObject* old_menu_pointer) {
|
||||
if (old_menu_pointer == reinterpret_cast<GObject*>(self->dbus_menu)) {
|
||||
self->gtk_menu = nullptr;
|
||||
self->dbus_menu = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Item::makeMenu(GdkEventButton* const& ev) {
|
||||
if (gtk_menu == nullptr) {
|
||||
if (!menu.empty()) {
|
||||
dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
||||
if (dbus_menu != nullptr) {
|
||||
g_object_ref_sink(G_OBJECT(dbus_menu));
|
||||
g_object_weak_ref(G_OBJECT(dbus_menu), (GWeakNotify)onMenuDestroyed, this);
|
||||
gtk_menu = Glib::wrap(GTK_MENU(dbus_menu));
|
||||
gtk_menu->attach_to_widget(event_box);
|
||||
}
|
||||
void Item::makeMenu(GdkEventButton* const& ev) {
|
||||
if (gtk_menu == nullptr && !menu.empty()) {
|
||||
dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
||||
if (dbus_menu != nullptr) {
|
||||
g_object_ref_sink(G_OBJECT(dbus_menu));
|
||||
g_object_weak_ref(G_OBJECT(dbus_menu), (GWeakNotify)onMenuDestroyed, this);
|
||||
gtk_menu = Glib::wrap(GTK_MENU(dbus_menu));
|
||||
gtk_menu->attach_to_widget(event_box);
|
||||
}
|
||||
}
|
||||
if (gtk_menu != nullptr) {
|
||||
#if GTK_CHECK_VERSION(3, 22, 0)
|
||||
gtk_menu->popup_at_pointer(reinterpret_cast<GdkEvent*>(ev));
|
||||
#else
|
||||
gtk_menu->popup(ev->button, ev->time);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Item::handleClick(GdkEventButton* const& ev) {
|
||||
auto parameters = Glib::VariantContainerBase::create_tuple(
|
||||
{Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)});
|
||||
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
|
||||
if (!makeMenu(ev)) {
|
||||
makeMenu(ev);
|
||||
if (gtk_menu != nullptr) {
|
||||
#if GTK_CHECK_VERSION(3, 22, 0)
|
||||
gtk_menu->popup_at_pointer(reinterpret_cast<GdkEvent*>(ev));
|
||||
#else
|
||||
gtk_menu->popup(ev->button, ev->time);
|
||||
#endif
|
||||
return true;
|
||||
} else {
|
||||
proxy_->call("ContextMenu", parameters);
|
||||
return true;
|
||||
}
|
||||
|
@ -24,8 +24,7 @@ Watcher::~Watcher() {
|
||||
items_ = nullptr;
|
||||
}
|
||||
auto iface = G_DBUS_INTERFACE_SKELETON(watcher_);
|
||||
auto conn = g_dbus_interface_skeleton_get_connection(iface);
|
||||
g_dbus_interface_skeleton_unexport_from_connection(iface, conn);
|
||||
g_dbus_interface_skeleton_unexport(iface);
|
||||
}
|
||||
|
||||
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name) {
|
||||
|
@ -15,7 +15,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
|
||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
|
||||
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
||||
if (!config["disable-workspace-scroll"].asBool()) {
|
||||
if (!config["disable-bar-scroll"].asBool()) {
|
||||
auto &window = const_cast<Bar&>(bar_).window;
|
||||
window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
|
||||
@ -215,7 +215,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
|
||||
const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterator it,
|
||||
bool prev) const {
|
||||
if (prev && it == workspaces_.begin()) {
|
||||
if (prev && it == workspaces_.begin() && !config_["disable-scroll-wraparound"].asBool()) {
|
||||
return (*(--workspaces_.end()))["name"].asString();
|
||||
}
|
||||
if (prev && it != workspaces_.begin())
|
||||
@ -223,7 +223,11 @@ const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterat
|
||||
else if (!prev && it != workspaces_.end())
|
||||
++it;
|
||||
if (!prev && it == workspaces_.end()) {
|
||||
return (*(++workspaces_.begin()))["name"].asString();
|
||||
if (config_["disable-scroll-wraparound"].asBool()) {
|
||||
--it;
|
||||
} else {
|
||||
return (*(workspaces_.begin()))["name"].asString();
|
||||
}
|
||||
}
|
||||
return (*it)["name"].asString();
|
||||
}
|
||||
@ -250,4 +254,4 @@ void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
|
||||
|
||||
Workspaces::operator Gtk::Widget &() { return box_; }
|
||||
|
||||
} // namespace waybar::modules::sway
|
||||
} // namespace waybar::modules::sway
|
||||
|
Reference in New Issue
Block a user