Lots of waybar improvements

This commit is contained in:
Emmet 2024-07-29 17:08:56 -05:00
parent e68df3ff93
commit ffb88a715a
5 changed files with 1506 additions and 49 deletions

View file

@ -231,4 +231,6 @@
name = if (config.stylix.polarity == "dark") then "Papirus-Dark" else "Papirus-Light";
};
services.pasystray.enable = true;
}

View file

@ -45,6 +45,7 @@ in
env = QT_AUTO_SCREEN_SCALE_FACTOR,1
env = QT_WAYLAND_DISABLE_WINDOWDECORATION,1
env = CLUTTER_BACKEND,wayland
env = GDK_PIXBUF_MODULE_FILE,${pkgs.librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
exec-once = hyprprofile Default
@ -459,7 +460,6 @@ in
hypridle
hyprpaper
fnott
fuzzel
keepmenu
pinentry-gnome3
wev
@ -759,6 +759,7 @@ in
sed -i 's/zext_workspace_handle_v1_activate(workspace_handle_);/const std::string command = "hyprctl dispatch focusworkspaceoncurrentmonitor " + std::to_string(id());\n\tsystem(command.c_str());/g' src/modules/wlr/workspace_manager.cpp
sed -i 's/gIPC->getSocket1Reply("dispatch workspace " + std::to_string(id()));/gIPC->getSocket1Reply("dispatch focusworkspaceoncurrentmonitor " + std::to_string(id()));/g' src/modules/hyprland/workspaces.cpp
'';
patches = [./patches/waybarpaupdate.patch ./patches/waybarbatupdate.patch];
});
settings = {
mainBar = {
@ -768,28 +769,70 @@ in
margin = "7 7 3 7";
spacing = 2;
modules-left = [ "custom/os" "custom/hyprprofile" "battery" "backlight" "keyboard-state" "pulseaudio" "cpu" "memory" ];
modules-center = [ "hyprland/workspaces" ];
modules-right = [ "idle_inhibitor" "tray" "clock" ];
modules-left = [ "group/power" "group/battery" "group/backlight" "group/cpu" "group/memory" "group/pulseaudio" "keyboard-state" ];
modules-center = [ "custom/hyprprofile" "hyprland/workspaces" ];
modules-right = [ "group/time" "idle_inhibitor" "tray" ];
"custom/os" = {
"format" = " {} ";
"exec" = ''echo "" '';
"interval" = "once";
"on-click" = "nwggrid-wrapper";
"tooltip" = false;
};
"group/power" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"children-class" = "not-power";
"transition-left-to-right" = true;
};
"modules" = [
"custom/os"
"custom/hyprprofileicon"
"custom/lock"
"custom/quit"
"custom/power"
"custom/reboot"
];
};
"custom/quit" = {
"format" = "󰍃";
"tooltip" = false;
"on-click" = "hyprctl dispatch exit";
};
"custom/lock" = {
"format" = "󰍁";
"tooltip" = false;
"on-click" = "hyprlock";
};
"custom/reboot" = {
"format" = "󰜉";
"tooltip" = false;
"on-click" = "reboot now";
};
"custom/power" = {
"format" = "󰐥";
"tooltip" = false;
"on-click" = "shutdown now";
};
"custom/hyprprofileicon" = {
"format" = "󱙋";
"on-click" = "hyprprofile-dmenu";
"tooltip" = false;
};
"custom/hyprprofile" = {
"format" = " {}";
"format" = " {}";
"exec" = ''cat ~/.hyprprofile'';
"interval" = 3;
"on-click" = "hyprprofile-dmenu";
};
"keyboard-state" = {
"numlock" = true;
"format" = " {icon} ";
"format" = "{icon}";
"format-icons" = {
"locked" = "󰎠";
"unlocked" = "󱧓";
"locked" = "󰎠 ";
"unlocked" = "󱧓 ";
};
};
"hyprland/workspaces" = {
@ -813,25 +856,10 @@ in
"on-click" = "activate";
"on-scroll-up" = "hyprctl dispatch workspace e+1";
"on-scroll-down" = "hyprctl dispatch workspace e-1";
#"all-outputs" = true;
#"active-only" = true;
"all-outputs" = false;
"active-only" = false;
"ignore-workspaces" = ["scratch" "-"];
#"show-special" = false;
#"persistent-workspaces" = {
# # this block doesn't seem to work for whatever reason
# "eDP-1" = [1 2 3 4 5 6 7 8 9];
# "DP-1" = [1 2 3 4 5 6 7 8 9];
# "HDMI-A-1" = [1 2 3 4 5 6 7 8 9];
# "1" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "2" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "3" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "4" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "5" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "6" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "7" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "8" = ["eDP-1" "DP-1" "HDMI-A-1"];
# "9" = ["eDP-1" "DP-1" "HDMI-A-1"];
#};
"show-special" = false;
};
"idle_inhibitor" = {
@ -845,43 +873,106 @@ in
#"icon-size" = 21;
"spacing" = 10;
};
clock = {
"clock#time" = {
"interval" = 1;
"format" = "{:%a %Y-%m-%d %I:%M:%S %p}";
"format" = "{:%I:%M:%S %p}";
"timezone" = "America/Chicago";
"tooltip-format" = ''
<big>{:%Y %B}</big>
<tt><small>{calendar}</small></tt>'';
};
cpu = {
"format" = "{usage}% ";
"clock#date" = {
"interval" = 1;
"format" = "{:%a %Y-%m-%d}";
"timezone" = "America/Chicago";
"tooltip-format" = ''
<big>{:%Y %B}</big>
<tt><small>{calendar}</small></tt>'';
};
memory = { "format" = "{}% "; };
"group/time" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = false;
};
"modules" = [ "clock#time" "clock#date" ];
};
cpu = { "format" = "󰍛"; };
"cpu#text" = { "format" = "{usage}%"; };
"group/cpu" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = true;
};
"modules" = [ "cpu" "cpu#text" ];
};
memory = { "format" = ""; };
"memory#text" = { "format" = "{}%"; };
"group/memory" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = true;
};
"modules" = [ "memory" "memory#text" ];
};
backlight = {
"format" = "{percent}% {icon}";
"format" = "{icon}";
"format-icons" = [ "" "" "" "" "" "" "" "" "" ];
};
"backlight#text" = { "format" = "{percent}%"; };
"group/backlight" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = true;
};
"modules" = [ "backlight" "backlight#text" ];
};
battery = {
"states" = {
"good" = 95;
"good" = 75;
"warning" = 30;
"critical" = 15;
};
"format" = "{capacity}% {icon}";
"format-charging" = "{capacity}% ";
"format-plugged" = "{capacity}% ";
#"format-good" = ""; # An empty format will hide the module
#"format-full" = "";
"format-icons" = [ "" "" "" "" "" ];
"fullat" = 80;
"format" = "{icon}";
"format-charging" = "󰂄";
"format-plugged" = "󰂄";
"format-full" = "󰁹";
"format-icons" = [ "󰁺" "󰁻" "󰁼" "󰁽" "󰁾" "󰁿" "󰂀" "󰂁" "󰂂" "󰁹" ];
"interval" = 10;
};
"battery#text" = {
"states" = {
"good" = 75;
"warning" = 30;
"critical" = 15;
};
"fullat" = 80;
"format" = "{capacity}%";
};
"group/battery" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = true;
};
"modules" = [ "battery" "battery#text" ];
};
pulseaudio = {
"scroll-step" = 1;
"format" = "{volume}% {icon} {format_source}";
"format-bluetooth" = "{volume}% {icon} {format_source}";
"format-bluetooth-muted" = "󰸈 {icon} {format_source}";
"format-muted" = "󰸈 {format_source}";
"format-source" = "{volume}% ";
"format-source-muted" = " ";
"format" = "{icon}";
"format-bluetooth" = "{icon}";
"format-bluetooth-muted" = "󰸈";
"format-muted" = "󰸈";
"format-source" = "";
"format-source-muted" = "";
"format-icons" = {
"headphone" = "";
"hands-free" = "";
@ -893,6 +984,24 @@ in
};
"on-click" = "pypr toggle pavucontrol && hyprctl dispatch bringactivetotop";
};
"pulseaudio#text" = {
"scroll-step" = 1;
"format" = "{volume}%";
"format-bluetooth" = "{volume}%";
"format-bluetooth-muted" = "";
"format-muted" = "";
"format-source" = "{volume}%";
"format-source-muted" = "";
"on-click" = "pypr toggle pavucontrol && hyprctl dispatch bringactivetotop";
};
"group/pulseaudio" = {
"orientation" = "horizontal";
"drawer" = {
"transition-duration" = 500;
"transition-left-to-right" = true;
};
"modules" = [ "pulseaudio" "pulseaudio#text" ];
};
};
};
style = ''
@ -948,7 +1057,7 @@ in
}
#workspaces button {
padding: 0 7px;
padding: 0px 6px;
background-color: transparent;
color: #'' + config.lib.stylix.colors.base04 + '';
}
@ -973,7 +1082,6 @@ in
color: #'' + config.lib.stylix.colors.base09 + '';
}
#clock,
#battery,
#cpu,
#memory,
@ -988,16 +1096,44 @@ in
#mode,
#idle_inhibitor,
#scratchpad,
#custom-hyprprofileicon,
#custom-quit,
#custom-lock,
#custom-reboot,
#custom-power,
#mpd {
padding: 0 10px;
padding: 0 3px;
color: #'' + config.lib.stylix.colors.base07 + '';
border: none;
border-radius: 8px;
}
#custom-hyprprofileicon,
#custom-quit,
#custom-lock,
#custom-reboot,
#custom-power,
#idle_inhibitor {
background-color: transparent;
color: #'' + config.lib.stylix.colors.base04 + '';
}
#custom-hyprprofileicon:hover,
#custom-quit:hover,
#custom-lock:hover,
#custom-reboot:hover,
#custom-power:hover,
#idle_inhibitor:hover {
color: #'' + config.lib.stylix.colors.base07 + '';
}
#clock, #tray, #idle_inhibitor {
padding: 0 5px;
}
#window,
#workspaces {
margin: 0 4px;
margin: 0 6px;
}
/* If workspaces is the leftmost module, omit left margin */
@ -1208,6 +1344,9 @@ in
services.udiskie.enable = true;
services.udiskie.tray = "always";
programs.fuzzel.enable = true;
programs.fuzzel.package = pkgs.fuzzel.overrideAttrs (oldAttrs: {
patches = ./patches/fuzzelmouseinput.patch;
});
programs.fuzzel.settings = {
main = {
font = userSettings.font + ":size=20";

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,192 @@
From f4608b3e312448b37a8f9d6351154026e67c680a Mon Sep 17 00:00:00 2001
From: schmop <lars.richard@rocketmail.com>
Date: Thu, 25 Jul 2024 01:40:49 +0200
Subject: [PATCH] Fix battery status changes not being detected
Historically we listened to /sys/class/poewr_supply inotify events,
which does not seem to work anymore.
We switched now to udev netlink kernel events.
---
include/modules/battery.hpp | 8 +++++--
include/util/udev_deleter.hpp | 21 ++++++++++++++++++
src/modules/battery.cpp | 40 +++++++++++++++++++---------------
src/util/backlight_backend.cpp | 17 +--------------
4 files changed, 51 insertions(+), 35 deletions(-)
create mode 100644 include/util/udev_deleter.hpp
diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp
index 8e1a2ad2b..fc403be05 100644
--- a/include/modules/battery.hpp
+++ b/include/modules/battery.hpp
@@ -5,8 +5,11 @@
#include <filesystem>
#if defined(__linux__)
#include <sys/inotify.h>
+#include "util/udev_deleter.hpp"
#endif
+#include <sys/poll.h>
+
#include <algorithm>
#include <fstream>
#include <string>
@@ -36,11 +39,12 @@ class Battery : public ALabel {
const std::string formatTimeRemaining(float hoursRemaining);
void setBarClass(std::string&);
- int global_watch;
std::map<fs::path, int> batteries_;
+ std::unique_ptr<udev, util::UdevDeleter> udev_;
+ std::array<pollfd, 1> poll_fds_;
+ std::unique_ptr<udev_monitor, util::UdevMonitorDeleter> mon_;
fs::path adapter_;
int battery_watch_fd_;
- int global_watch_fd_;
std::mutex battery_list_mutex_;
std::string old_status_;
bool warnFirstTime_{true};
diff --git a/include/util/udev_deleter.hpp b/include/util/udev_deleter.hpp
new file mode 100644
index 000000000..b2f1e538b
--- /dev/null
+++ b/include/util/udev_deleter.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <libudev.h>
+
+namespace waybar::util {
+struct UdevDeleter {
+ void operator()(udev *ptr) const { udev_unref(ptr); }
+};
+
+struct UdevDeviceDeleter {
+ void operator()(udev_device *ptr) const { udev_device_unref(ptr); }
+};
+
+struct UdevEnumerateDeleter {
+ void operator()(udev_enumerate *ptr) const { udev_enumerate_unref(ptr); }
+};
+
+struct UdevMonitorDeleter {
+ void operator()(udev_monitor *ptr) const { udev_monitor_unref(ptr); }
+};
+} // namespace waybar::util
\ No newline at end of file
diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp
index d87cc6129..bad72e6b0 100644
--- a/src/modules/battery.cpp
+++ b/src/modules/battery.cpp
@@ -5,6 +5,9 @@
#include <sys/sysctl.h>
#endif
#include <spdlog/spdlog.h>
+#include <libudev.h>
+#include <poll.h>
+#include <sys/signalfd.h>
#include <iostream>
waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const Json::Value& config)
@@ -14,17 +17,18 @@ waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const J
if (battery_watch_fd_ == -1) {
throw std::runtime_error("Unable to listen batteries.");
}
-
- global_watch_fd_ = inotify_init1(IN_CLOEXEC);
- if (global_watch_fd_ == -1) {
- throw std::runtime_error("Unable to listen batteries.");
+ udev_ = std::unique_ptr<udev, util::UdevDeleter>(udev_new());
+ if (udev_ == nullptr) {
+ throw std::runtime_error("udev_new failed");
}
-
- // Watch the directory for any added or removed batteries
- global_watch = inotify_add_watch(global_watch_fd_, data_dir_.c_str(), IN_CREATE | IN_DELETE);
- if (global_watch < 0) {
- throw std::runtime_error("Could not watch for battery plug/unplug");
+ mon_ = std::unique_ptr<udev_monitor, util::UdevMonitorDeleter>(udev_monitor_new_from_netlink(udev_.get(), "kernel"));
+ if (mon_ == nullptr) {
+ throw std::runtime_error("udev monitor new failed");
}
+ if (udev_monitor_filter_add_match_subsystem_devtype(mon_.get(), "power_supply", nullptr) < 0) {
+ throw std::runtime_error("udev failed to add monitor filter");
+ }
+ udev_monitor_enable_receiving(mon_.get());
#endif
worker();
}
@@ -33,11 +37,6 @@ waybar::modules::Battery::~Battery() {
#if defined(__linux__)
std::lock_guard<std::mutex> guard(battery_list_mutex_);
- if (global_watch >= 0) {
- inotify_rm_watch(global_watch_fd_, global_watch);
- }
- close(global_watch_fd_);
-
for (auto it = batteries_.cbegin(), next_it = it; it != batteries_.cend(); it = next_it) {
++next_it;
auto watch_id = (*it).second;
@@ -74,12 +73,18 @@ void waybar::modules::Battery::worker() {
dp.emit();
};
thread_battery_update_ = [this] {
- struct inotify_event event = {0};
- int nbytes = read(global_watch_fd_, &event, sizeof(event));
- if (nbytes != sizeof(event) || event.mask & IN_IGNORED) {
+ poll_fds_[0].revents = 0;
+ poll_fds_[0].events = POLLIN;
+ poll_fds_[0].fd = udev_monitor_get_fd(mon_.get());
+ int ret = poll(poll_fds_.data(), poll_fds_.size(), -1);
+ if (ret < 0) {
thread_.stop();
return;
}
+ if ((poll_fds_[0].revents & POLLIN) != 0) {
+ signalfd_siginfo signal_info;
+ read(poll_fds_[0].fd, &signal_info, sizeof(signal_info));
+ }
refreshBatteries();
dp.emit();
};
@@ -668,6 +673,7 @@ auto waybar::modules::Battery::update() -> void {
status = getAdapterStatus(capacity);
}
auto status_pretty = status;
+ puts(status.c_str());
// Transform to lowercase and replace space with dash
std::transform(status.begin(), status.end(), status.begin(),
[](char ch) { return ch == ' ' ? '-' : std::tolower(ch); });
diff --git a/src/util/backlight_backend.cpp b/src/util/backlight_backend.cpp
index bb102cd93..df6afd564 100644
--- a/src/util/backlight_backend.cpp
+++ b/src/util/backlight_backend.cpp
@@ -1,4 +1,5 @@
#include "util/backlight_backend.hpp"
+#include "util/udev_deleter.hpp"
#include <fmt/core.h>
#include <spdlog/spdlog.h>
@@ -29,22 +30,6 @@ class FileDescriptor {
int fd_;
};
-struct UdevDeleter {
- void operator()(udev *ptr) { udev_unref(ptr); }
-};
-
-struct UdevDeviceDeleter {
- void operator()(udev_device *ptr) { udev_device_unref(ptr); }
-};
-
-struct UdevEnumerateDeleter {
- void operator()(udev_enumerate *ptr) { udev_enumerate_unref(ptr); }
-};
-
-struct UdevMonitorDeleter {
- void operator()(udev_monitor *ptr) { udev_monitor_unref(ptr); }
-};
-
void check_eq(int rc, int expected, const char *message = "eq, rc was: ") {
if (rc != expected) {
throw std::runtime_error(fmt::format(fmt::runtime(message), rc));

View file

@ -0,0 +1,71 @@
diff --git a/include/util/audio_backend.hpp b/include/util/audio_backend.hpp
index 2f53103e5..3737ae264 100644
--- a/include/util/audio_backend.hpp
+++ b/include/util/audio_backend.hpp
@@ -38,6 +38,8 @@ class AudioBackend {
std::string desc_;
std::string monitor_;
std::string current_sink_name_;
+ std::string default_sink_name;
+ bool default_sink_running_;
bool current_sink_running_;
// SOURCE
uint32_t source_idx_{0};
diff --git a/src/util/audio_backend.cpp b/src/util/audio_backend.cpp
index 3d90b6d5a..73aac148b 100644
--- a/src/util/audio_backend.cpp
+++ b/src/util/audio_backend.cpp
@@ -1,9 +1,12 @@
#include "util/audio_backend.hpp"
#include <fmt/core.h>
+#include <pulse/def.h>
#include <pulse/error.h>
+#include <pulse/introspect.h>
#include <pulse/subscribe.h>
#include <pulse/volume.h>
+#include <spdlog/spdlog.h>
#include <algorithm>
#include <cmath>
@@ -139,6 +142,10 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
void *data) {
if (i == nullptr) return;
+ auto running = i->state == PA_SINK_RUNNING;
+ auto idle = i->state == PA_SINK_IDLE;
+ spdlog::trace("Sink name {} Running:[{}] Idle:[{}]", i->name, running, idle);
+
auto *backend = static_cast<AudioBackend *>(data);
if (!backend->ignored_sinks_.empty()) {
@@ -155,11 +162,19 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
}
}
+ backend->default_sink_running_ = backend->default_sink_name == i->name &&
+ (i->state == PA_SINK_RUNNING || i->state == PA_SINK_IDLE);
+
+ if (i->name != backend->default_sink_name && !backend->default_sink_running_) {
+ return;
+ }
+
if (backend->current_sink_name_ == i->name) {
- backend->current_sink_running_ = i->state == PA_SINK_RUNNING;
+ backend->current_sink_running_ = (i->state == PA_SINK_RUNNING || i->state == PA_SINK_IDLE);
}
- if (!backend->current_sink_running_ && i->state == PA_SINK_RUNNING) {
+ if (!backend->current_sink_running_ &&
+ (i->state == PA_SINK_RUNNING || i->state == PA_SINK_IDLE)) {
backend->current_sink_name_ = i->name;
backend->current_sink_running_ = true;
}
@@ -207,5 +222,6 @@ void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *
void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) {
auto *backend = static_cast<AudioBackend *>(data);
backend->current_sink_name_ = i->default_sink_name;
+ backend->default_sink_name = i->default_sink_name;
backend->default_source_name_ = i->default_source_name;
pa_context_get_sink_info_list(context, sinkInfoCb, data);