Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Pol Rivero
2025-07-29 23:30:44 +02:00
11 changed files with 138 additions and 67 deletions

View File

@ -116,6 +116,36 @@ sudo apt install \
libxkbregistry-dev libxkbregistry-dev
``` ```
On Arch, you can use this command:
```
pacman -S \
gtkmm3 \
jsoncpp \
libsigc++ \
fmt \
wayland \
chrono-date \
spdlog \
gtk3 \
gobject-introspection \
libgirepository \
libpulse \
libnl \
libappindicator-gtk3 \
libdbusmenu-gtk3 \
libmpdclient \
sndio \
libevdev \
libxkbcommon \
upower \
meson \
cmake \
scdoc \
wayland-protocols \
glib2-devel
```
Contributions welcome!<br> Contributions welcome!<br>
Have fun :)<br> Have fun :)<br>

View File

@ -27,8 +27,8 @@ class Network : public ALabel {
auto update() -> void override; auto update() -> void override;
private: private:
static const uint8_t MAX_RETRY = 5; static const uint8_t MAX_RETRY{5};
static const uint8_t EPOLL_MAX = 200; static const uint8_t EPOLL_MAX{200};
static int handleEvents(struct nl_msg*, void*); static int handleEvents(struct nl_msg*, void*);
static int handleEventsDone(struct nl_msg*, void*); static int handleEventsDone(struct nl_msg*, void*);
@ -51,37 +51,37 @@ class Network : public ALabel {
bool wildcardMatch(const std::string& pattern, const std::string& text) const; bool wildcardMatch(const std::string& pattern, const std::string& text) const;
std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage(); std::optional<std::pair<unsigned long long, unsigned long long>> readBandwidthUsage();
int ifid_; int ifid_{-1};
ip_addr_pref addr_pref_; ip_addr_pref addr_pref_{ip_addr_pref::IPV4};
struct sockaddr_nl nladdr_ = {0}; struct sockaddr_nl nladdr_{0};
struct nl_sock* sock_ = nullptr; struct nl_sock* sock_{nullptr};
struct nl_sock* ev_sock_ = nullptr; struct nl_sock* ev_sock_{nullptr};
int efd_; int efd_{-1};
int ev_fd_; int ev_fd_{-1};
int nl80211_id_; int nl80211_id_{-1};
std::mutex mutex_; std::mutex mutex_;
bool want_route_dump_; bool want_route_dump_{false};
bool want_link_dump_; bool want_link_dump_{false};
bool want_addr_dump_; bool want_addr_dump_{false};
bool dump_in_progress_; bool dump_in_progress_{false};
bool is_p2p_; bool is_p2p_{false};
unsigned long long bandwidth_down_total_; unsigned long long bandwidth_down_total_{0};
unsigned long long bandwidth_up_total_; unsigned long long bandwidth_up_total_{0};
std::string state_; std::string state_;
std::string essid_; std::string essid_;
std::string bssid_; std::string bssid_;
bool carrier_; bool carrier_{false};
std::string ifname_; std::string ifname_;
std::string ipaddr_; std::string ipaddr_;
std::string ipaddr6_; std::string ipaddr6_;
std::string gwaddr_; std::string gwaddr_;
std::string netmask_; std::string netmask_;
std::string netmask6_; std::string netmask6_;
int cidr_; int cidr_{0};
int cidr6_; int cidr6_{0};
int32_t signal_strength_dbm_; int32_t signal_strength_dbm_;
uint8_t signal_strength_; uint8_t signal_strength_;
std::string signal_strength_app_; std::string signal_strength_app_;
@ -90,9 +90,9 @@ class Network : public ALabel {
util::SleeperThread thread_; util::SleeperThread thread_;
util::SleeperThread thread_timer_; util::SleeperThread thread_timer_;
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
util::Rfkill rfkill_; util::Rfkill rfkill_{RFKILL_TYPE_WLAN};
#endif #endif
float frequency_; float frequency_{0};
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -5,6 +5,8 @@
#include <sigc++/signal.h> #include <sigc++/signal.h>
#include <sigc++/trackable.h> #include <sigc++/trackable.h>
#include <atomic>
namespace waybar::util { namespace waybar::util {
class Rfkill : public sigc::trackable { class Rfkill : public sigc::trackable {
@ -17,7 +19,7 @@ class Rfkill : public sigc::trackable {
private: private:
enum rfkill_type rfkill_type_; enum rfkill_type rfkill_type_;
bool state_ = false; std::atomic_bool state_ = false;
int fd_ = -1; int fd_ = -1;
bool on_event(Glib::IOCondition cond); bool on_event(Glib::IOCondition cond);

View File

@ -16,6 +16,11 @@ Addressed by *network*
typeof: string ++ typeof: string ++
Use the defined interface instead of auto-detection. Accepts wildcard. Use the defined interface instead of auto-detection. Accepts wildcard.
*rfkill*: ++
typeof: bool ++
default: true ++
If enabled, the *disabled* format will be used when rfkill is blocking wlan interfaces.
*interval*: ++ *interval*: ++
typeof: integer ++ typeof: integer ++
default: 60 ++ default: 60 ++
@ -49,7 +54,7 @@ Addressed by *network*
*format-disabled*: ++ *format-disabled*: ++
typeof: string ++ typeof: string ++
This format is used when the displayed interface is disabled. This format is used when rfkill is blocking wlan interfaces.
*format-icons*: ++ *format-icons*: ++
typeof: array/object ++ typeof: array/object ++
@ -127,7 +132,7 @@ Addressed by *network*
*tooltip-format-disabled*: ++ *tooltip-format-disabled*: ++
typeof: string ++ typeof: string ++
This format is used when the displayed interface is disabled. This format is used when rfkill is blocking wlan interfaces.
*menu*: ++ *menu*: ++
typeof: string ++ typeof: string ++
@ -157,7 +162,7 @@ Addressed by *network*
*{netmask}*: The subnetmask corresponding to the IP(V4). *{netmask}*: The subnetmask corresponding to the IP(V4).
*{netmask6}*: The subnetmask corresponding to the IP(V6). *{netmask6}*: The subnetmask corresponding to the IP(V6).
*{cidr}*: The subnetmask corresponding to the IP(V4) in CIDR notation. *{cidr}*: The subnetmask corresponding to the IP(V4) in CIDR notation.

View File

@ -151,15 +151,19 @@ void waybar::Client::handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> mon
const std::string waybar::Client::getStyle(const std::string &style, const std::string waybar::Client::getStyle(const std::string &style,
std::optional<Appearance> appearance = std::nullopt) { std::optional<Appearance> appearance = std::nullopt) {
auto gtk_settings = Gtk::Settings::get_default();
std::optional<std::string> css_file; std::optional<std::string> css_file;
if (style.empty()) { if (style.empty()) {
std::vector<std::string> search_files; std::vector<std::string> search_files;
switch (appearance.value_or(portal->getAppearance())) { switch (appearance.value_or(portal->getAppearance())) {
case waybar::Appearance::LIGHT: case waybar::Appearance::LIGHT:
search_files.emplace_back("style-light.css"); search_files.emplace_back("style-light.css");
gtk_settings->property_gtk_application_prefer_dark_theme() = false;
break; break;
case waybar::Appearance::DARK: case waybar::Appearance::DARK:
search_files.emplace_back("style-dark.css"); search_files.emplace_back("style-dark.css");
gtk_settings->property_gtk_application_prefer_dark_theme() = true;
break; break;
case waybar::Appearance::UNKNOWN: case waybar::Appearance::UNKNOWN:
break; break;
@ -169,9 +173,11 @@ const std::string waybar::Client::getStyle(const std::string &style,
} else { } else {
css_file = style; css_file = style;
} }
if (!css_file) { if (!css_file) {
throw std::runtime_error("Missing required resource files"); throw std::runtime_error("Missing required resource files");
} }
spdlog::info("Using CSS file {}", css_file.value()); spdlog::info("Using CSS file {}", css_file.value());
return css_file.value(); return css_file.value();
}; };

View File

@ -704,7 +704,7 @@ auto waybar::modules::Battery::update() -> void {
} else if (config_["tooltip-format"].isString()) { } else if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_.set_tooltip_text( label_.set_tooltip_markup(
fmt::format(fmt::runtime(tooltip_format), fmt::arg("timeTo", tooltip_text_default), fmt::format(fmt::runtime(tooltip_format), fmt::arg("timeTo", tooltip_text_default),
fmt::arg("power", power), fmt::arg("capacity", capacity), fmt::arg("power", power), fmt::arg("capacity", capacity),
fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles), fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles),

View File

@ -66,14 +66,17 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
void Workspaces::createWorkspace(Json::Value const &workspace_data, void Workspaces::createWorkspace(Json::Value const &workspace_data,
Json::Value const &clients_data) { Json::Value const &clients_data) {
auto workspaceName = workspace_data["name"].asString(); auto workspaceName = workspace_data["name"].asString();
auto workspaceId = workspace_data["id"].asInt();
spdlog::debug("Creating workspace {}", workspaceName); spdlog::debug("Creating workspace {}", workspaceName);
// avoid recreating existing workspaces // avoid recreating existing workspaces
auto workspace = auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> const &w) {
std::ranges::find_if(m_workspaces, [workspaceName](std::unique_ptr<Workspace> const &w) { if (workspaceId > 0) {
return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) || return w->id() == workspaceId;
workspaceName == w->name(); }
}); return (workspaceName.starts_with("special:") && workspaceName.substr(8) == w->name()) ||
workspaceName == w->name();
});
if (workspace != m_workspaces.end()) { if (workspace != m_workspaces.end()) {
// don't recreate workspace, but update persistency if necessary // don't recreate workspace, but update persistency if necessary
@ -254,10 +257,8 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs
// value is an array => create defined workspaces for this monitor // value is an array => create defined workspaces for this monitor
if (canCreate) { if (canCreate) {
for (const Json::Value &workspace : value) { for (const Json::Value &workspace : value) {
if (workspace.isInt()) { spdlog::debug("Creating workspace {} on monitor {}", workspace, currentMonitor);
spdlog::debug("Creating workspace {} on monitor {}", workspace, currentMonitor); persistentWorkspacesToCreate.emplace_back(workspace.asString());
persistentWorkspacesToCreate.emplace_back(std::to_string(workspace.asInt()));
}
} }
} else { } else {
// key is the workspace and value is array of monitors to create on // key is the workspace and value is array of monitors to create on
@ -293,8 +294,13 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c
if (!rule["persistent"].asBool()) { if (!rule["persistent"].asBool()) {
continue; continue;
} }
auto const &workspace = rule.isMember("defaultName") ? rule["defaultName"].asString() auto workspace = rule.isMember("defaultName") ? rule["defaultName"].asString()
: rule["workspaceString"].asString(); : rule["workspaceString"].asString();
// The prefix "name:" cause mismatches with workspace names taken anywhere else.
if (workspace.starts_with("name:")) {
workspace = workspace.substr(5);
}
auto const &monitor = rule["monitor"].asString(); auto const &monitor = rule["monitor"].asString();
// create this workspace persistently if: // create this workspace persistently if:
// 1. the allOutputs config option is enabled // 1. the allOutputs config option is enabled
@ -1040,9 +1046,17 @@ bool Workspaces::updateWindowsToCreate() {
void Workspaces::updateWorkspaceStates() { void Workspaces::updateWorkspaceStates() {
const std::vector<int> visibleWorkspaces = getVisibleWorkspaces(); const std::vector<int> visibleWorkspaces = getVisibleWorkspaces();
auto updatedWorkspaces = m_ipc.getSocket1JsonReply("workspaces"); auto updatedWorkspaces = m_ipc.getSocket1JsonReply("workspaces");
auto currentWorkspace = m_ipc.getSocket1JsonReply("activeworkspace");
std::string currentWorkspaceName =
currentWorkspace.isMember("name") ? currentWorkspace["name"].asString() : "";
for (auto &workspace : m_workspaces) { for (auto &workspace : m_workspaces) {
bool isActiveByName =
!currentWorkspaceName.empty() && workspace->name() == currentWorkspaceName;
workspace->setActive( workspace->setActive(
workspace->id() == m_activeWorkspaceId || workspace->id() == m_activeWorkspaceId || isActiveByName ||
(workspace->isSpecial() && workspace->name() == m_activeSpecialWorkspaceName)); (workspace->isSpecial() && workspace->name() == m_activeSpecialWorkspaceName));
if (workspace->isActive() && workspace->isUrgent()) { if (workspace->isActive() && workspace->isUrgent()) {
workspace->setUrgent(false); workspace->setUrgent(false);
@ -1120,4 +1134,4 @@ std::optional<int> Workspaces::parseWorkspaceId(std::string const &workspaceIdSt
} }
} }
} // namespace waybar::modules::hyprland } // namespace waybar::modules::hyprland

View File

@ -78,25 +78,7 @@ waybar::modules::Network::readBandwidthUsage() {
} }
waybar::modules::Network::Network(const std::string &id, const Json::Value &config) waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
: ALabel(config, "network", id, DEFAULT_FORMAT, 60), : ALabel(config, "network", id, DEFAULT_FORMAT, 60) {
ifid_(-1),
addr_pref_(IPV4),
efd_(-1),
ev_fd_(-1),
want_route_dump_(false),
want_link_dump_(false),
want_addr_dump_(false),
dump_in_progress_(false),
is_p2p_(false),
cidr_(0),
cidr6_(0),
signal_strength_dbm_(0),
signal_strength_(0),
#ifdef WANT_RFKILL
rfkill_{RFKILL_TYPE_WLAN},
#endif
frequency_(0.0) {
// Start with some "text" in the module's label_. update() will then // Start with some "text" in the module's label_. update() will then
// update it. Since the text should be different, update() will be able // update it. Since the text should be different, update() will be able
// to show or hide the event_box_. This is to work around the case where // to show or hide the event_box_. This is to work around the case where
@ -271,11 +253,16 @@ void waybar::modules::Network::worker() {
} }
const std::string waybar::modules::Network::getNetworkState() const { const std::string waybar::modules::Network::getNetworkState() const {
if (ifid_ == -1 || !carrier_) {
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
if (rfkill_.getState() && ifid_ == -1) return "disabled"; bool display_rfkill = true;
if (config_["rfkill"].isBool()) {
display_rfkill = config_["rfkill"].asBool();
}
if (rfkill_.getState() && display_rfkill) return "disabled";
#endif #endif
if (ifid_ == -1) return "disconnected"; return "disconnected";
if (!carrier_) return "disconnected"; }
if (ipaddr_.empty() && ipaddr6_.empty()) return "linked"; if (ipaddr_.empty() && ipaddr6_.empty()) return "linked";
if (essid_.empty()) return "ethernet"; if (essid_.empty()) return "ethernet";
return "wifi"; return "wifi";
@ -418,6 +405,7 @@ void waybar::modules::Network::clearIface() {
netmask_.clear(); netmask_.clear();
netmask6_.clear(); netmask6_.clear();
carrier_ = false; carrier_ = false;
is_p2p_ = false;
cidr_ = 0; cidr_ = 0;
cidr6_ = 0; cidr6_ = 0;
signal_strength_dbm_ = 0; signal_strength_dbm_ = 0;
@ -507,6 +495,11 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
net->ifname_ = new_ifname; net->ifname_ = new_ifname;
net->ifid_ = ifi->ifi_index; net->ifid_ = ifi->ifi_index;
if (ifi->ifi_flags & IFF_POINTOPOINT) net->is_p2p_ = true; if (ifi->ifi_flags & IFF_POINTOPOINT) net->is_p2p_ = true;
if ((ifi->ifi_flags & IFF_UP) == 0) {
// With some network drivers (e.g. mt7921e), the interface may
// report having a carrier even though interface is down.
carrier = false;
}
if (carrier.has_value()) { if (carrier.has_value()) {
net->carrier_ = carrier.value(); net->carrier_ = carrier.value();
} }

View File

@ -132,7 +132,7 @@ auto waybar::modules::Pulseaudio::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
label_.set_tooltip_text(fmt::format( label_.set_tooltip_markup(fmt::format(
fmt::runtime(tooltip_format), fmt::arg("desc", sink_desc), fmt::runtime(tooltip_format), fmt::arg("desc", sink_desc),
fmt::arg("volume", sink_volume), fmt::arg("format_source", format_source), fmt::arg("volume", sink_volume), fmt::arg("format_source", format_source),
fmt::arg("source_volume", source_volume), fmt::arg("source_desc", source_desc), fmt::arg("source_volume", source_volume), fmt::arg("source_desc", source_desc),

View File

@ -140,7 +140,25 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
category = get_variant<std::string>(value); category = get_variant<std::string>(value);
} else if (name == "Id") { } else if (name == "Id") {
id = get_variant<std::string>(value); id = get_variant<std::string>(value);
setCustomIcon(id);
/*
* HACK: Electron apps seem to have the same ID, but tooltip seems correct, so use that as ID
* to pass as the custom icon option. I'm avoiding being disruptive and setting that to the ID
* itself as I've no idea what this would affect.
* The tooltip text is converted to lowercase since that's what (most?) themes expect?
* I still haven't found a way for it to pick from theme automatically, although
* it might be my theme.
*/
if (id == "chrome_status_icon_1") {
Glib::VariantBase value;
this->proxy_->get_cached_property(value, "ToolTip");
tooltip = get_variant<ToolTip>(value);
if (!tooltip.text.empty()) {
setCustomIcon(tooltip.text.lowercase());
}
} else {
setCustomIcon(id);
}
} else if (name == "Title") { } else if (name == "Title") {
title = get_variant<std::string>(value); title = get_variant<std::string>(value);
if (tooltip.text.empty()) { if (tooltip.text.empty()) {
@ -203,6 +221,8 @@ void Item::setStatus(const Glib::ustring& value) {
} }
void Item::setCustomIcon(const std::string& id) { void Item::setCustomIcon(const std::string& id) {
spdlog::debug("SNI tray id: {}", id);
std::string custom_icon = IconManager::instance().getIconForApp(id); std::string custom_icon = IconManager::instance().getIconForApp(id);
if (!custom_icon.empty()) { if (!custom_icon.empty()) {
if (std::filesystem::exists(custom_icon)) { if (std::filesystem::exists(custom_icon)) {

View File

@ -10,7 +10,6 @@ UPower::UPower(const std::string &id, const Json::Value &config)
: AIconLabel(config, "upower", id, "{percentage}", 0, true, true, true), sleeping_{false} { : AIconLabel(config, "upower", id, "{percentage}", 0, true, true, true), sleeping_{false} {
box_.set_name(name_); box_.set_name(name_);
box_.set_spacing(0); box_.set_spacing(0);
box_.set_has_tooltip(AModule::tooltipEnabled());
// Tooltip box // Tooltip box
contentBox_.set_orientation((box_.get_orientation() == Gtk::ORIENTATION_HORIZONTAL) contentBox_.set_orientation((box_.get_orientation() == Gtk::ORIENTATION_HORIZONTAL)
? Gtk::ORIENTATION_VERTICAL ? Gtk::ORIENTATION_VERTICAL
@ -70,8 +69,10 @@ UPower::UPower(const std::string &id, const Json::Value &config)
g_signal_connect(upClient_, "device-removed", G_CALLBACK(deviceRemoved_cb), this); g_signal_connect(upClient_, "device-removed", G_CALLBACK(deviceRemoved_cb), this);
// Subscribe tooltip query events // Subscribe tooltip query events
box_.set_has_tooltip(); box_.set_has_tooltip(AModule::tooltipEnabled());
box_.signal_query_tooltip().connect(sigc::mem_fun(*this, &UPower::queryTooltipCb), false); if (AModule::tooltipEnabled()) {
box_.signal_query_tooltip().connect(sigc::mem_fun(*this, &UPower::queryTooltipCb), false);
}
resetDevices(); resetDevices();
setDisplayDevice(); setDisplayDevice();