Compare commits

..

62 Commits

Author SHA1 Message Date
383d999fec chore: v0.9.10 2022-03-06 14:54:48 +01:00
56ebb09e5f Merge pull request #1440 from TheDaemoness/patch-1
Add 1 to songPosition in the MPD module
2022-03-06 14:51:20 +01:00
35d6da3965 Merge pull request #1292 from FlexW/feature/sway-app-icon
Show application icon when using sway window module
2022-03-06 14:50:41 +01:00
be1d2a02ca Merge pull request #1422 from technic/fixes
minor string utils methods refactoring
2022-03-06 14:50:02 +01:00
5e7ba0c9e3 Merge pull request #1445 from GrantMoyer/keyboard_state_errors
Improve keyboard_state error messages
2022-03-06 14:49:38 +01:00
18717d4b12 Merge remote-tracking branch 'upstream/master' into keyboard_state_errors 2022-03-04 12:14:23 -05:00
4dc1989744 Merge pull request #1451 from euclio/use-after-free 2022-03-04 06:10:25 +01:00
54085dbde0 avoid use-after-free in lambda 2022-03-03 19:40:43 -05:00
4635e8c5f8 Merge pull request #1450 from Xiretza/style-css-use-fontawesome 2022-03-03 18:38:05 +01:00
adc67b6f75 style.css: add fontawesome to beginning of font list
If there is some other font installed that 1) matches the four existing
font families and 2) provides its own glyph in the private use area used
by Awesome, then that font's glyph will be used instead of the intended
icon.

For example, the following character (U+F001, "music"): 
...looks like a pair of musical notes in fontawesome, but DejaVu Sans
also provides a glyph, which looks like a couple of squares. DejaVu Sans
matches first when "sans-serif" is requested, so its (unrelated) glyph
is used.
2022-03-03 18:18:21 +01:00
ebe4424795 Fix remaining posix compatability issues in keyboard_state 2022-02-25 13:28:47 -05:00
e3f56b8110 Don't use gnu extensions which are too new for debian and ubuntu 2022-02-25 13:13:43 -05:00
8f3fbebede Make error messages portable 2022-02-25 12:56:22 -05:00
a595b61e0f Improve keyboard_state error messages 2022-02-25 12:27:08 -05:00
91339f6ad4 Merge pull request #1444 from bd-g/feat/cpu-load-fix
CPU Load Formatting Fix
2022-02-23 09:12:53 +01:00
3c18c43b9a limit cpu load figure to 2 points 2022-02-22 16:33:33 -07:00
ac20428fdf Add 1 to songPosition in the MPD module 2022-02-18 17:41:33 -08:00
ad5ea7ad2b Merge pull request #1436 from jbeich/ci 2022-02-13 18:13:42 +01:00
851508df5e ci: explicitly install wayland-protocols on FreeBSD
meson.build:86:0: ERROR: Dependency "wayland-protocols" not found, tried pkgconfig
2022-02-13 11:14:35 +00:00
fc818dd794 ci: update freebsd-vm to 0.1.6 2022-02-13 11:12:52 +00:00
e066e3080e Merge pull request #1432 from DorianRudolph/fix-unplug
fix #1431: audio output does not update on unplug
2022-02-09 15:29:36 +01:00
1a93a6cfa5 fix #1431: audio output does not update on unplug 2022-02-09 14:20:09 +01:00
074b559da5 Merge pull request #1423 from technic/fmt-refactor
move Glib ustring format helper to utils
2022-02-08 18:25:55 +01:00
7a61a00fb3 Merge pull request #1421 from gemmelos/patch-2
Update man page clock module - tooltip
2022-02-08 18:25:13 +01:00
d4da04a750 move Glib ustring format helper to utils
this formatter is useful for other modules
which want to print Glib exceptions messages
2022-02-05 21:26:48 +01:00
f3819ee954 remove duplicated string manipulation methods 2022-02-05 21:02:58 +01:00
2697d432a4 ltrim and rtrim take argument by const-ref 2022-02-05 21:02:58 +01:00
061cb76fc4 make functions in header file inline
added header guard
now string utils can be used in any part of the project
2022-02-05 21:02:58 +01:00
6c188455a4 Update man page clock module - tooltip
Add tooltip documentation to the clock man page now that this is works.
2022-02-05 19:05:50 +01:00
12caae8fd2 Merge pull request #1410 from ErikReider/reverse-tray
Reverse the tray icon order
2022-02-02 12:56:25 +01:00
26ea6fae32 Merge pull request #1413 from snehrbass/patch-1
Fix typo in example for sway/mode man page
2022-02-02 12:55:34 +01:00
26419e45b7 Merge pull request #1418 from gemmelos/patch-1
Fix disabled tooltip on clock module
2022-02-02 12:55:10 +01:00
6be741afc9 Fix disabled tooltip on clock module
Seems like the tooltip text should only be set if both `if (tooltipEnabled())` and `if (config_["tooltip-format"].isString())` passes.
2022-02-02 12:41:06 +01:00
c80cc873af Update spotify example to work on copy paste 2022-02-02 00:01:18 -05:00
2b42872b6c Merge pull request #1417 from evyatark2/master 2022-02-01 22:00:29 +01:00
895bc878f8 Properly initialize distance_scrolled members.
When they were uninitialized it caused getScrollDir() to incorrectly return SCROLL_DIR::NONE in some circumstances
2022-02-01 22:42:03 +02:00
a0ee9e7fc1 Fix Typo in Example for sway/mode 2022-01-29 14:19:53 -05:00
941cf47693 Add config option "reverse-direction" 2022-01-28 19:14:46 +01:00
32d42749f9 use pack_end instead of pack_start 2022-01-28 18:42:52 +01:00
96caa9f094 Merge pull request #1406 from Spiffyk/language-segfault
sway/language: fix segmentation fault for layouts not found in XKBContext
2022-01-25 23:08:32 +01:00
f4f1267a71 sway/language: fix segmentation fault for layouts not found in XKBContext 2022-01-25 20:03:19 +01:00
bcadf64031 Show application icon when using sway window module
Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
2022-01-24 17:37:51 +01:00
8974bbf7b4 Merge pull request #1312 from mazunki/master
Changed a setting to include {gwaddr} by default
2022-01-24 09:23:43 +01:00
1c08d26af0 Merge branch 'master' into master 2022-01-24 09:23:23 +01:00
c4cc7ae396 Update client.cpp 2022-01-24 09:22:47 +01:00
65dd245362 Update clock.cpp 2022-01-24 09:21:56 +01:00
667d0a45f4 Update command.hpp 2022-01-24 09:20:43 +01:00
53fc750fc3 Merge pull request #1404 from kevinoid/fix-issue-1139 2022-01-24 09:02:53 +01:00
27df7a9aa7 battery: read status with spaces
According to the [sysfs class power ABI],
/sys/class/power_supply/<supply_name>/status may contain "Not charging".
This is already handled by status_gt() and update() (where ' ' is
converted to '-' for use in config keys) but was not being read due to
skipws.  Read with std::getline() to handle this case.

[sysfs class power ABI]: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power

Fixes: #1139
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2022-01-23 18:36:59 -07:00
d575646c2d Merge pull request #1394 from nullobsi/patch-1
fix: Use locale when formatting clock
2022-01-18 11:35:55 +01:00
3a6e5be59d Use locale when formatting clock 2022-01-14 10:36:24 -08:00
81f0bcb3a3 Merge pull request #1388 from ericonr/man2
fix(man): add missing newlines to wlr docs.
2022-01-12 11:09:09 +01:00
9ae99c2621 Merge pull request #1386 from Anakael/pr/anakael/add-swap-flags
[Memory] feat: Add swap flags
2022-01-12 11:08:50 +01:00
5abdecc402 fix(man): add missing newlines to wlr docs. 2022-01-11 17:29:17 -03:00
2301788a81 created a hotfix for libfmt-8.1.0 and above 2022-01-08 01:44:46 +01:00
d22d6a4522 Merge branch 'master' of github.com:Alexays/Waybar 2022-01-08 01:02:57 +01:00
bb7b376fa6 removed commented useless runtime errors 2021-11-24 01:37:21 +01:00
e10c9dd011 changing want_route_dump to default to true, since we say we have gwaddr support 2021-11-09 19:04:05 +01:00
b0eab5d793 maybe we shouldn't actually runtime error, but still doing a check 2021-11-09 19:03:15 +01:00
17bb5643ae explicitly checking for errors to silence unused variable warnings when writing to fd 2021-11-09 18:38:07 +01:00
8d9e322507 Add man 2021-08-29 16:37:02 +03:00
94e53c3777 Add swap flags 2021-08-29 16:34:29 +03:00
33 changed files with 313 additions and 95 deletions

View File

@ -11,7 +11,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Test in FreeBSD VM - name: Test in FreeBSD VM
uses: vmactions/freebsd-vm@v0.1.5 # aka FreeBSD 13.0 uses: vmactions/freebsd-vm@v0.1.6 # aka FreeBSD 13.0
with: with:
mem: 2048 mem: 2048
usesh: true usesh: true
@ -21,7 +21,7 @@ jobs:
pkg install -y git # subprojects/date pkg install -y git # subprojects/date
pkg install -y catch evdev-proto gtk-layer-shell gtkmm30 jsoncpp \ pkg install -y catch evdev-proto gtk-layer-shell gtkmm30 jsoncpp \
libdbusmenu libevdev libfmt libmpdclient libudev-devd meson \ libdbusmenu libevdev libfmt libmpdclient libudev-devd meson \
pkgconf pulseaudio scdoc sndio spdlog pkgconf pulseaudio scdoc sndio spdlog wayland-protocols
run: | run: |
meson build -Dman-pages=enabled meson build -Dman-pages=enabled
ninja -C build ninja -C build

25
include/AIconLabel.hpp Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include "ALabel.hpp"
namespace waybar {
class AIconLabel : public ALabel {
public:
AIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval = 0, bool ellipsize = false,
bool enable_click = false, bool enable_scroll = false);
virtual ~AIconLabel() = default;
virtual auto update() -> void;
protected:
Gtk::Image image_;
Gtk::Box box_;
bool iconEnabled() const;
};
} // namespace waybar

View File

@ -24,8 +24,6 @@ class KeyboardState : public AModule {
auto update() -> void; auto update() -> void;
private: private:
static auto openDevice(const std::string&) -> std::pair<int, libevdev*>;
Gtk::Box box_; Gtk::Box box_;
Gtk::Label numlock_label_; Gtk::Label numlock_label_;
Gtk::Label capslock_label_; Gtk::Label capslock_label_;

View File

@ -2,7 +2,8 @@
#include <fmt/format.h> #include <fmt/format.h>
#include <tuple> #include <tuple>
#include "ALabel.hpp"
#include "AIconLabel.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "client.hpp" #include "client.hpp"
#include "modules/sway/ipc/client.hpp" #include "modules/sway/ipc/client.hpp"
@ -10,7 +11,7 @@
namespace waybar::modules::sway { namespace waybar::modules::sway {
class Window : public ALabel, public sigc::trackable { class Window : public AIconLabel, public sigc::trackable {
public: public:
Window(const std::string&, const waybar::Bar&, const Json::Value&); Window(const std::string&, const waybar::Bar&, const Json::Value&);
~Window() = default; ~Window() = default;
@ -23,6 +24,7 @@ class Window : public ALabel, public sigc::trackable {
std::string& output); std::string& output);
void getTree(); void getTree();
std::string rewriteTitle(const std::string& title); std::string rewriteTitle(const std::string& title);
void updateAppIcon();
const Bar& bar_; const Bar& bar_;
std::string window_; std::string window_;

View File

@ -68,7 +68,10 @@ inline int close(FILE* fp, pid_t pid) {
inline FILE* open(const std::string& cmd, int& pid) { inline FILE* open(const std::string& cmd, int& pid) {
if (cmd == "") return nullptr; if (cmd == "") return nullptr;
int fd[2]; int fd[2];
pipe(fd); if (pipe(fd) != 0){
spdlog::error("Unable to pipe fd");
return nullptr;
}
pid_t child_pid = fork(); pid_t child_pid = fork();

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <fmt/format.h> #include <fmt/format.h>
#include <glibmm/ustring.h>
class pow_format { class pow_format {
public: public:
@ -84,5 +85,15 @@ namespace fmt {
); );
} }
}; };
// Glib ustirng support
template <>
struct formatter<Glib::ustring> : formatter<std::string> {
template <typename FormatContext>
auto format(const Glib::ustring& value, FormatContext& ctx) {
return formatter<std::string>::format(value, ctx);
}
};
} }

View File

@ -1,15 +1,17 @@
#pragma once
#include <string> #include <string>
const std::string WHITESPACE = " \n\r\t\f\v"; const std::string WHITESPACE = " \n\r\t\f\v";
std::string ltrim(const std::string s) { inline std::string ltrim(const std::string& s) {
size_t begin = s.find_first_not_of(WHITESPACE); size_t begin = s.find_first_not_of(WHITESPACE);
return (begin == std::string::npos) ? "" : s.substr(begin); return (begin == std::string::npos) ? "" : s.substr(begin);
} }
std::string rtrim(const std::string s) { inline std::string rtrim(const std::string& s) {
size_t end = s.find_last_not_of(WHITESPACE); size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1); return (end == std::string::npos) ? "" : s.substr(0, end + 1);
} }
std::string trim(const std::string& s) { return rtrim(ltrim(s)); } inline std::string trim(const std::string& s) { return rtrim(ltrim(s)); }

View File

@ -86,6 +86,11 @@ The *clock* module displays the current date and time.
typeof: double ++ typeof: double ++
Threshold to be used when scrolling. Threshold to be used when scrolling.
*tooltip*: ++
typeof: bool ++
default: true ++
Option to disable tooltip on hover.
View all valid format options in *strftime(3)*. View all valid format options in *strftime(3)*.
# FORMAT REPLACEMENTS # FORMAT REPLACEMENTS

View File

@ -151,7 +151,8 @@ $text\\n$tooltip\\n$class*
"max-length": 40, "max-length": 40,
"interval": 30, // Remove this if your script is endless and write in loop "interval": 30, // Remove this if your script is endless and write in loop
"exec": "$HOME/.config/waybar/mediaplayer.sh 2> /dev/null", // Script in resources folder "exec": "$HOME/.config/waybar/mediaplayer.sh 2> /dev/null", // Script in resources folder
"exec-if": "pgrep spotify" "exec-if": "pgrep spotify",
"return-type": "json"
} }
``` ```

View File

@ -8,6 +8,8 @@ waybar - keyboard-state module
The *keyboard-state* module displays the state of number lock, caps lock, and scroll lock. The *keyboard-state* module displays the state of number lock, caps lock, and scroll lock.
You must be a member of the input group to use this module.
# CONFIGURATION # CONFIGURATION
*interval*: ++ *interval*: ++

View File

@ -84,12 +84,20 @@ Addressed by *memory*
*{percentage}*: Percentage of memory in use. *{percentage}*: Percentage of memory in use.
*{swapPercentage}*: Percentage of swap in use.
*{total}*: Amount of total memory available in GiB. *{total}*: Amount of total memory available in GiB.
*{swapTotal}*: Amount of total swap available in GiB.
*{used}*: Amount of used memory in GiB. *{used}*: Amount of used memory in GiB.
*{swapUsed}*: Amount of used swap in GiB.
*{avail}*: Amount of available memory in GiB. *{avail}*: Amount of available memory in GiB.
*{swapAvail}*: Amount of available swap in GiB.
# EXAMPLES # EXAMPLES
``` ```

View File

@ -69,7 +69,7 @@ Addressed by *sway/mode*
# EXAMPLES # EXAMPLES
``` ```
"sway/window": { "sway/mode": {
"format": " {}", "format": " {}",
"max-length": 50 "max-length": 50
} }

View File

@ -29,6 +29,10 @@ Addressed by *tray*
typeof: integer ++ typeof: integer ++
Defines the spacing between the tray icons. Defines the spacing between the tray icons.
*reverse-direction*: ++
typeof: bool ++
Defines if new app icons should be added in a reverse order
*on-update*: ++ *on-update*: ++
typeof: string ++ typeof: string ++
Command to execute when the module is updated. Command to execute when the module is updated.

View File

@ -93,10 +93,15 @@ Addressed by *wlr/taskbar*
# CLICK ACTIONS # CLICK ACTIONS
*activate*: Bring the application into foreground. *activate*: Bring the application into foreground.
*minimize*: Toggle application's minimized state. *minimize*: Toggle application's minimized state.
*minimize-raise*: Bring the application into foreground or toggle its minimized state. *minimize-raise*: Bring the application into foreground or toggle its minimized state.
*maximize*: Toggle application's maximized state. *maximize*: Toggle application's maximized state.
*fullscreen*: Toggle application's fullscreen state. *fullscreen*: Toggle application's fullscreen state.
*close*: Close the application. *close*: Close the application.
# EXAMPLES # EXAMPLES

View File

@ -52,6 +52,7 @@ Addressed by *wlr/workspaces*
# CLICK ACTIONS # CLICK ACTIONS
*activate*: Switch to workspace. *activate*: Switch to workspace.
*close*: Close the workspace. *close*: Close the workspace.
# ICONS # ICONS

View File

@ -1,6 +1,6 @@
project( project(
'waybar', 'cpp', 'c', 'waybar', 'cpp', 'c',
version: '0.9.9', version: '0.9.10',
license: 'MIT', license: 'MIT',
meson_version: '>= 0.49.0', meson_version: '>= 0.49.0',
default_options : [ default_options : [
@ -142,6 +142,7 @@ src_files = files(
'src/factory.cpp', 'src/factory.cpp',
'src/AModule.cpp', 'src/AModule.cpp',
'src/ALabel.cpp', 'src/ALabel.cpp',
'src/AIconLabel.cpp',
'src/modules/custom.cpp', 'src/modules/custom.cpp',
'src/modules/disk.cpp', 'src/modules/disk.cpp',
'src/modules/idle_inhibitor.cpp', 'src/modules/idle_inhibitor.cpp',

View File

@ -1,6 +1,6 @@
* { * {
/* `otf-font-awesome` is required to be installed for icons */ /* `otf-font-awesome` is required to be installed for icons */
font-family: Roboto, Helvetica, Arial, sans-serif; font-family: FontAwesome, Roboto, Helvetica, Arial, sans-serif;
font-size: 13px; font-size: 13px;
} }

28
src/AIconLabel.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "AIconLabel.hpp"
#include <gdkmm/pixbuf.h>
namespace waybar {
AIconLabel::AIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval, bool ellipsize,
bool enable_click, bool enable_scroll)
: ALabel(config, name, id, format, interval, ellipsize, enable_click, enable_scroll) {
event_box_.remove();
box_.set_orientation(Gtk::Orientation::ORIENTATION_HORIZONTAL);
box_.set_spacing(8);
box_.add(image_);
box_.add(label_);
event_box_.add(box_);
}
auto AIconLabel::update() -> void {
image_.set_visible(image_.get_visible() && iconEnabled());
ALabel::update();
}
bool AIconLabel::iconEnabled() const {
return config_["icon"].isBool() ? config_["icon"].asBool() : true;
}
} // namespace waybar

View File

@ -6,7 +6,9 @@ namespace waybar {
AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id, AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id,
bool enable_click, bool enable_scroll) bool enable_click, bool enable_scroll)
: name_(std::move(name)), config_(std::move(config)) { : name_(std::move(name)), config_(std::move(config))
, distance_scrolled_y_(0.0)
, distance_scrolled_x_(0.0) {
// configure events' user commands // configure events' user commands
if (config_["on-click"].isString() || config_["on-click-middle"].isString() || if (config_["on-click"].isString() || config_["on-click-middle"].isString() ||
config_["on-click-backward"].isString() || config_["on-click-forward"].isString() || config_["on-click-backward"].isString() || config_["on-click-forward"].isString() ||

View File

@ -750,7 +750,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, Gtk
modules_right_.emplace_back(module_sp); modules_right_.emplace_back(module_sp);
} }
} }
module->dp.connect([module, &name] { module->dp.connect([module, name] {
try { try {
module->update(); module->update();
} catch (const std::exception& e) { } catch (const std::exception& e) {

View File

@ -161,7 +161,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
uint32_t energy_now; uint32_t energy_now;
uint32_t energy_full_design; uint32_t energy_full_design;
std::string _status; std::string _status;
std::ifstream(bat / "status") >> _status; std::getline(std::ifstream(bat / "status"), _status);
// Some battery will report current and charge in μA/μAh. // Some battery will report current and charge in μA/μAh.
// Scale these by the voltage to get μW/μWh. // Scale these by the voltage to get μW/μWh.

View File

@ -99,7 +99,7 @@ auto waybar::modules::Clock::update() -> void {
// As date dep is not fully compatible, prefer fmt // As date dep is not fully compatible, prefer fmt
tzset(); tzset();
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
text = fmt::format(format_, localtime); text = fmt::format(locale_, format_, localtime);
} else { } else {
text = fmt::format(format_, wtime); text = fmt::format(format_, wtime);
} }
@ -113,10 +113,10 @@ auto waybar::modules::Clock::update() -> void {
} }
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
text = fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines)); text = fmt::format(tooltip_format, wtime, fmt::arg(kCalendarPlaceholder.c_str(), calendar_lines));
label_.set_tooltip_markup(text);
} }
} }
label_.set_tooltip_markup(text);
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }

View File

@ -62,7 +62,7 @@ auto waybar::modules::Cpu::update() -> void {
double waybar::modules::Cpu::getCpuLoad() { double waybar::modules::Cpu::getCpuLoad() {
double load[1]; double load[1];
if (getloadavg(load, 1) != -1) { if (getloadavg(load, 1) != -1) {
return load[0]; return std::ceil(load[0] * 100.0) / 100.0;
} }
throw std::runtime_error("Can't get Cpu load"); throw std::runtime_error("Can't get Cpu load");
} }

View File

@ -1,6 +1,8 @@
#include "modules/keyboard_state.hpp" #include "modules/keyboard_state.hpp"
#include <errno.h>
#include <filesystem> #include <filesystem>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <string.h>
extern "C" { extern "C" {
#include <sys/types.h> #include <sys/types.h>
@ -8,6 +10,69 @@ extern "C" {
#include <fcntl.h> #include <fcntl.h>
} }
class errno_error : public std::runtime_error {
public:
int code;
errno_error(int code, const std::string& msg)
: std::runtime_error(getErrorMsg(code, msg.c_str())),
code(code) {}
errno_error(int code, const char* msg)
: std::runtime_error(getErrorMsg(code, msg)),
code(code) {}
private:
static auto getErrorMsg(int err, const char* msg) -> std::string {
std::string error_msg{msg};
error_msg += ": ";
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 32)
// strerrorname_np gets the error code's name; it's nice to have, but it's a recent GNU extension
const auto errno_name = strerrorname_np(err);
error_msg += errno_name;
error_msg += " ";
#endif
const auto errno_str = strerror(err);
error_msg += errno_str;
return error_msg;
}
};
auto openFile(const std::string& path, int flags) -> int {
int fd = open(path.c_str(), flags);
if (fd < 0) {
if (errno == EACCES) {
throw errno_error(errno, "Can't open " + path + " (are you in the input group?)");
} else {
throw errno_error(errno, "Can't open " + path);
}
}
return fd;
}
auto closeFile(int fd) -> void {
int res = close(fd);
if (res < 0) {
throw errno_error(errno, "Can't close file");
}
}
auto openDevice(int fd) -> libevdev* {
libevdev* dev;
int err = libevdev_new_from_fd(fd, &dev);
if (err < 0) {
throw errno_error(-err, "Can't create libevdev device");
}
return dev;
}
auto supportsLockStates(const libevdev* dev) -> bool {
return libevdev_has_event_type(dev, EV_LED)
&& libevdev_has_event_code(dev, EV_LED, LED_NUML)
&& libevdev_has_event_code(dev, EV_LED, LED_CAPSL)
&& libevdev_has_event_code(dev, EV_LED, LED_SCROLLL);
}
waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, const Json::Value& config) waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, const Json::Value& config)
: AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()), : AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
@ -48,26 +113,36 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
if (config_["device-path"].isString()) { if (config_["device-path"].isString()) {
std::string dev_path = config_["device-path"].asString(); std::string dev_path = config_["device-path"].asString();
std::tie(fd_, dev_) = openDevice(dev_path); fd_ = openFile(dev_path, O_NONBLOCK | O_CLOEXEC | O_RDONLY);
dev_ = openDevice(fd_);
} else { } else {
DIR* dev_dir = opendir("/dev/input"); DIR* dev_dir = opendir("/dev/input");
if (dev_dir == nullptr) { if (dev_dir == nullptr) {
throw std::runtime_error("Failed to open /dev/input"); throw errno_error(errno, "Failed to open /dev/input");
} }
dirent *ep; dirent *ep;
while ((ep = readdir(dev_dir))) { while ((ep = readdir(dev_dir))) {
if (ep->d_type != DT_CHR) continue; if (ep->d_type != DT_CHR) continue;
std::string dev_path = std::string("/dev/input/") + ep->d_name; std::string dev_path = std::string("/dev/input/") + ep->d_name;
int fd = openFile(dev_path.c_str(), O_NONBLOCK | O_CLOEXEC | O_RDONLY);
try { try {
std::tie(fd_, dev_) = openDevice(dev_path); auto dev = openDevice(fd);
spdlog::info("Found device {} at '{}'", libevdev_get_name(dev_), dev_path); if (supportsLockStates(dev)) {
break; spdlog::info("Found device {} at '{}'", libevdev_get_name(dev), dev_path);
} catch (const std::runtime_error& e) { fd_ = fd;
continue; dev_ = dev;
break;
}
} catch (const errno_error& e) {
// ENOTTY just means the device isn't an evdev device, skip it
if (e.code != ENOTTY) {
spdlog::warn(e.what());
}
} }
closeFile(fd);
} }
if (dev_ == nullptr) { if (dev_ == nullptr) {
throw std::runtime_error("Failed to find keyboard device"); throw errno_error(errno, "Failed to find keyboard device");
} }
} }
@ -79,35 +154,13 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
waybar::modules::KeyboardState::~KeyboardState() { waybar::modules::KeyboardState::~KeyboardState() {
libevdev_free(dev_); libevdev_free(dev_);
int err = close(fd_); try {
if (err < 0) { closeFile(fd_);
// Not much we can do, so ignore it. } catch (const std::runtime_error& e) {
spdlog::warn(e.what());
} }
} }
auto waybar::modules::KeyboardState::openDevice(const std::string& path) -> std::pair<int, libevdev*> {
int fd = open(path.c_str(), O_NONBLOCK | O_CLOEXEC | O_RDONLY);
if (fd < 0) {
throw std::runtime_error("Can't open " + path);
}
libevdev* dev;
int err = libevdev_new_from_fd(fd, &dev);
if (err < 0) {
throw std::runtime_error("Can't create libevdev device");
}
if (!libevdev_has_event_type(dev, EV_LED)) {
throw std::runtime_error("Device doesn't support LED events");
}
if (!libevdev_has_event_code(dev, EV_LED, LED_NUML)
|| !libevdev_has_event_code(dev, EV_LED, LED_CAPSL)
|| !libevdev_has_event_code(dev, EV_LED, LED_SCROLLL)) {
throw std::runtime_error("Device doesn't support num lock, caps lock, or scroll lock events");
}
return std::make_pair(fd, dev);
}
auto waybar::modules::KeyboardState::update() -> void { auto waybar::modules::KeyboardState::update() -> void {
int err = LIBEVDEV_READ_STATUS_SUCCESS; int err = LIBEVDEV_READ_STATUS_SUCCESS;
while (err == LIBEVDEV_READ_STATUS_SUCCESS) { while (err == LIBEVDEV_READ_STATUS_SUCCESS) {
@ -117,8 +170,8 @@ auto waybar::modules::KeyboardState::update() -> void {
err = libevdev_next_event(dev_, LIBEVDEV_READ_FLAG_SYNC, &ev); err = libevdev_next_event(dev_, LIBEVDEV_READ_FLAG_SYNC, &ev);
} }
} }
if (err != -EAGAIN) { if (-err != EAGAIN) {
throw std::runtime_error("Failed to sync evdev device"); throw errno_error(-err, "Failed to sync evdev device");
} }
int numl = libevdev_get_event_value(dev_, EV_LED, LED_NUML); int numl = libevdev_get_event_value(dev_, EV_LED, LED_NUML);

View File

@ -12,7 +12,15 @@ auto waybar::modules::Memory::update() -> void {
parseMeminfo(); parseMeminfo();
unsigned long memtotal = meminfo_["MemTotal"]; unsigned long memtotal = meminfo_["MemTotal"];
unsigned long swaptotal = 0;
if (meminfo_.count("SwapTotal")) {
swaptotal = meminfo_["SwapTotal"];
}
unsigned long memfree; unsigned long memfree;
unsigned long swapfree = 0;
if (meminfo_.count("SwapFree")) {
swapfree = meminfo_["SwapFree"];
}
if (meminfo_.count("MemAvailable")) { if (meminfo_.count("MemAvailable")) {
// New kernels (3.4+) have an accurate available memory field. // New kernels (3.4+) have an accurate available memory field.
memfree = meminfo_["MemAvailable"] + meminfo_["zfs_size"]; memfree = meminfo_["MemAvailable"] + meminfo_["zfs_size"];
@ -24,9 +32,16 @@ auto waybar::modules::Memory::update() -> void {
if (memtotal > 0 && memfree >= 0) { if (memtotal > 0 && memfree >= 0) {
auto total_ram_gigabytes = memtotal / std::pow(1024, 2); auto total_ram_gigabytes = memtotal / std::pow(1024, 2);
auto total_swap_gigabytes = swaptotal / std::pow(1024, 2);
int used_ram_percentage = 100 * (memtotal - memfree) / memtotal; int used_ram_percentage = 100 * (memtotal - memfree) / memtotal;
int used_swap_percentage = 0;
if (swaptotal && swapfree) {
used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal;
}
auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2); auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2);
auto used_swap_gigabytes = (swaptotal - swapfree) / std::pow(1024, 2);
auto available_ram_gigabytes = memfree / std::pow(1024, 2); auto available_ram_gigabytes = memfree / std::pow(1024, 2);
auto available_swap_gigabytes = swapfree / std::pow(1024, 2);
auto format = format_; auto format = format_;
auto state = getState(used_ram_percentage); auto state = getState(used_ram_percentage);
@ -43,9 +58,13 @@ auto waybar::modules::Memory::update() -> void {
used_ram_percentage, used_ram_percentage,
fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("icon", getIcon(used_ram_percentage, icons)),
fmt::arg("total", total_ram_gigabytes), fmt::arg("total", total_ram_gigabytes),
fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
fmt::arg("swapPercentage", used_swap_percentage),
fmt::arg("used", used_ram_gigabytes), fmt::arg("used", used_ram_gigabytes),
fmt::arg("avail", available_ram_gigabytes))); fmt::arg("swapUsed", used_swap_gigabytes),
fmt::arg("avail", available_ram_gigabytes),
fmt::arg("swapAvail", available_swap_gigabytes)));
} }
if (tooltipEnabled()) { if (tooltipEnabled()) {
@ -54,9 +73,13 @@ auto waybar::modules::Memory::update() -> void {
label_.set_tooltip_text(fmt::format(tooltip_format, label_.set_tooltip_text(fmt::format(tooltip_format,
used_ram_percentage, used_ram_percentage,
fmt::arg("total", total_ram_gigabytes), fmt::arg("total", total_ram_gigabytes),
fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
fmt::arg("swapPercentage", used_swap_percentage),
fmt::arg("used", used_ram_gigabytes), fmt::arg("used", used_ram_gigabytes),
fmt::arg("avail", available_ram_gigabytes))); fmt::arg("swapUsed", used_swap_gigabytes),
fmt::arg("avail", available_ram_gigabytes),
fmt::arg("swapAvail", available_swap_gigabytes)));
} else { } else {
label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1)); label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
} }

View File

@ -129,7 +129,7 @@ void waybar::modules::MPD::setLabel() {
album = getTag(MPD_TAG_ALBUM); album = getTag(MPD_TAG_ALBUM);
title = getTag(MPD_TAG_TITLE); title = getTag(MPD_TAG_TITLE);
date = getTag(MPD_TAG_DATE); date = getTag(MPD_TAG_DATE);
song_pos = mpd_status_get_song_pos(status_.get()); song_pos = mpd_status_get_song_pos(status_.get()) + 1;
volume = mpd_status_get_volume(status_.get()); volume = mpd_status_get_volume(status_.get());
if (volume < 0) { if (volume < 0) {
volume = 0; volume = 0;

View File

@ -78,7 +78,7 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
family_(config["family"] == "ipv6" ? AF_INET6 : AF_INET), family_(config["family"] == "ipv6" ? AF_INET6 : AF_INET),
efd_(-1), efd_(-1),
ev_fd_(-1), ev_fd_(-1),
want_route_dump_(false), want_route_dump_(true),
want_link_dump_(false), want_link_dump_(false),
want_addr_dump_(false), want_addr_dump_(false),
dump_in_progress_(false), dump_in_progress_(false),
@ -106,7 +106,7 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
} }
if (!config_["interface"].isString()) { if (!config_["interface"].isString()) {
// "interface" isn't configure, then try to guess the external // "interface" isn't configured, then try to guess the external
// interface currently used for internet. // interface currently used for internet.
want_route_dump_ = true; want_route_dump_ = true;
} else { } else {

View File

@ -54,7 +54,9 @@ void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data) {
c, c,
static_cast<enum pa_subscription_mask>(static_cast<int>(PA_SUBSCRIPTION_MASK_SERVER) | static_cast<enum pa_subscription_mask>(static_cast<int>(PA_SUBSCRIPTION_MASK_SERVER) |
static_cast<int>(PA_SUBSCRIPTION_MASK_SINK) | static_cast<int>(PA_SUBSCRIPTION_MASK_SINK) |
static_cast<int>(PA_SUBSCRIPTION_MASK_SOURCE)), static_cast<int>(PA_SUBSCRIPTION_MASK_SINK_INPUT) |
static_cast<int>(PA_SUBSCRIPTION_MASK_SOURCE) |
static_cast<int>(PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT)),
nullptr, nullptr,
nullptr); nullptr);
break; break;
@ -121,8 +123,12 @@ void waybar::modules::Pulseaudio::subscribeCb(pa_context * conte
pa_context_get_server_info(context, serverInfoCb, data); pa_context_get_server_info(context, serverInfoCb, data);
} else if (facility == PA_SUBSCRIPTION_EVENT_SINK) { } else if (facility == PA_SUBSCRIPTION_EVENT_SINK) {
pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data); pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data);
} else if (facility == PA_SUBSCRIPTION_EVENT_SINK_INPUT) {
pa_context_get_sink_info_list(context, sinkInfoCb, data);
} else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE) { } else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE) {
pa_context_get_source_info_by_index(context, idx, sourceInfoCb, data); pa_context_get_source_info_by_index(context, idx, sourceInfoCb, data);
} else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT) {
pa_context_get_source_info_list(context, sourceInfoCb, data);
} }
} }
@ -279,7 +285,7 @@ auto waybar::modules::Pulseaudio::update() -> void {
fmt::arg("source_desc", source_desc_), fmt::arg("source_desc", source_desc_),
fmt::arg("icon", getIcon(volume_, getPulseIcon())))); fmt::arg("icon", getIcon(volume_, getPulseIcon()))));
getState(volume_); getState(volume_);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format.empty() && config_["tooltip-format"].isString()) { if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();

View File

@ -8,13 +8,7 @@
#include <fstream> #include <fstream>
#include <map> #include <map>
template <> #include "util/format.hpp"
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
template <typename FormatContext>
auto format(const Glib::ustring& value, FormatContext& ctx) {
return formatter<std::string>::format(value, ctx);
}
};
template <> template <>
struct fmt::formatter<Glib::VariantBase> : formatter<std::string> { struct fmt::formatter<Glib::VariantBase> : formatter<std::string> {

View File

@ -25,7 +25,11 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
} }
void Tray::onAdd(std::unique_ptr<Item>& item) { void Tray::onAdd(std::unique_ptr<Item>& item) {
box_.pack_start(item->event_box); if (config_["reverse-direction"].isBool() && config_["reverse-direction"].asBool()) {
box_.pack_end(item->event_box);
} else {
box_.pack_start(item->event_box);
}
dp.emit(); dp.emit();
} }

View File

@ -154,7 +154,10 @@ auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) ->
std::map<std::string, int> short_name_to_number_map; std::map<std::string, int> short_name_to_number_map;
for (const auto& used_layout_name : used_layouts) { for (const auto& used_layout_name : used_layouts) {
auto used_layout = &layouts_map_.find(used_layout_name)->second; auto found = layouts_map_.find(used_layout_name);
if (found == layouts_map_.end())
continue;
auto used_layout = &found->second;
auto layouts_with_same_name_list = found_by_short_names[used_layout->short_name]; auto layouts_with_same_name_list = found_by_short_names[used_layout->short_name];
if (layouts_with_same_name_list.size() < 2) { if (layouts_with_same_name_list.size() < 2) {
continue; continue;

View File

@ -1,11 +1,20 @@
#include "modules/sway/window.hpp" #include "modules/sway/window.hpp"
#include <gdkmm/pixbuf.h>
#include <glibmm/fileutils.h>
#include <glibmm/keyfile.h>
#include <glibmm/miscutils.h>
#include <gtkmm/enums.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <filesystem>
#include <regex> #include <regex>
#include <string>
namespace waybar::modules::sway { namespace waybar::modules::sway {
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) { : AIconLabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
ipc_.subscribe(R"(["window","workspace"])"); ipc_.subscribe(R"(["window","workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent)); ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd)); ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
@ -29,12 +38,60 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
auto payload = parser_.parse(res.payload); auto payload = parser_.parse(res.payload);
auto output = payload["output"].isString() ? payload["output"].asString() : ""; auto output = payload["output"].isString() ? payload["output"].asString() : "";
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output); std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output);
updateAppIcon();
dp.emit(); dp.emit();
} catch (const std::exception& e) { } catch (const std::exception& e) {
spdlog::error("Window: {}", e.what()); spdlog::error("Window: {}", e.what());
} }
} }
std::optional<std::string> getDesktopFilePath(const std::string& app_id) {
const auto data_dirs = Glib::get_system_data_dirs();
for (const auto& data_dir : data_dirs) {
const auto desktop_file_path = data_dir + "applications/" + app_id + ".desktop";
if (std::filesystem::exists(desktop_file_path)) {
return desktop_file_path;
}
}
return {};
}
std::optional<Glib::ustring> getIconName(const std::string& app_id) {
const auto desktop_file_path = getDesktopFilePath(app_id);
if (!desktop_file_path.has_value()) {
return {};
}
try {
Glib::KeyFile desktop_file;
desktop_file.load_from_file(desktop_file_path.value());
const auto icon_name = desktop_file.get_string("Desktop Entry", "Icon");
if (icon_name.empty()) {
return {};
}
return icon_name;
} catch (Glib::FileError& error) {
spdlog::warn(
"Error while loading desktop file {}: {}", desktop_file_path.value(), error.what().c_str());
} catch (Glib::KeyFileError& error) {
spdlog::warn(
"Error while loading desktop file {}: {}", desktop_file_path.value(), error.what().c_str());
}
return {};
}
void Window::updateAppIcon() {
if (!iconEnabled()) {
return;
}
const auto icon_name = getIconName(app_id_);
if (icon_name.has_value()) {
image_.set_from_icon_name(icon_name.value(), Gtk::ICON_SIZE_LARGE_TOOLBAR);
image_.set_visible(true);
return;
}
image_.set_visible(false);
}
auto Window::update() -> void { auto Window::update() -> void {
if (!old_app_id_.empty()) { if (!old_app_id_.empty()) {
bar_.window.get_style_context()->remove_class(old_app_id_); bar_.window.get_style_context()->remove_class(old_app_id_);
@ -63,7 +120,7 @@ auto Window::update() -> void {
label_.set_tooltip_text(window_); label_.set_tooltip_text(window_);
} }
// Call parent update // Call parent update
ALabel::update(); AIconLabel::update();
} }
int leafNodesInWorkspace(const Json::Value& node) { int leafNodesInWorkspace(const Json::Value& node) {

View File

@ -4,6 +4,7 @@
#include "glibmm/fileutils.h" #include "glibmm/fileutils.h"
#include "glibmm/refptr.h" #include "glibmm/refptr.h"
#include "util/format.hpp" #include "util/format.hpp"
#include "util/string.hpp"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -26,27 +27,6 @@
namespace waybar::modules::wlr { namespace waybar::modules::wlr {
/* String manipulation methods */
const std::string WHITESPACE = " \n\r\t\f\v";
static std::string ltrim(const std::string& s)
{
size_t start = s.find_first_not_of(WHITESPACE);
return (start == std::string::npos) ? "" : s.substr(start);
}
static std::string rtrim(const std::string& s)
{
size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
static std::string trim(const std::string& s)
{
return rtrim(ltrim(s));
}
/* Icon loading functions */ /* Icon loading functions */
static std::vector<std::string> search_prefix() static std::vector<std::string> search_prefix()
{ {