From 0572f7505599847d5bc8b4f0708b1e51c0ea9dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20Kj=C3=B8nigsen?= Date: Mon, 9 Dec 2019 13:20:29 +0100 Subject: [PATCH 001/100] Provide easy bootstrap command for Ubuntu-users --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 3e14e57e..ab34b4e8 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,13 @@ libdbusmenu-gtk3 [Tray module] libmpdclient [MPD module] ``` +On Ubuntu 19.10 you can install all the relevant dependencies using this command: + +``` +sudo apt install libgtkmm-3.0-dev libjsoncpp-dev libinput-dev libsigc++-2.0-dev libpulse-dev libnl-3-dev libdbusmenu-gtk3-dev libnl-genl-3-dev libfmt-dev clang-tidy scdoc libmpdclient-dev +``` + + Contributions welcome! - have fun :)
The style guidelines is [Google's](https://google.github.io/styleguide/cppguide.html) From 278f26e5977cd3d480ded00726ffc396a0afba77 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 14 Dec 2019 22:28:31 -0800 Subject: [PATCH 002/100] add info on "on-click-middle" option --- man/waybar-custom.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index a427be38..4c804c80 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -59,6 +59,10 @@ Addressed by *custom/* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. @@ -137,6 +141,7 @@ $text\\n$tooltip\\n$class* "exec": "mpc current", "exec-if": "pgrep mpd", "on-click": "mpc toggle", + "on-click-middle": "playerctl play-pause", "on-click-right": "sonata" } ``` From 2aaf5510b8631591c5d6ec540e6d851859d41eed Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:06:23 -0800 Subject: [PATCH 003/100] Update waybar-backlight.5.scd --- man/waybar-backlight.5.scd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 2d971997..8df118bc 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -35,7 +35,11 @@ The *backlight* module displays the current backlight level. *on-click* ++ typeof: string ++ Command to execute when the module is clicked. - + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right* ++ typeof: string ++ Command to execute when the module is right clicked. From 3bb03852fee6f3df84a651b80de617e65ae2b852 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:07:07 -0800 Subject: [PATCH 004/100] Update waybar-battery.5.scd --- man/waybar-battery.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 94a99e4f..7f90cd4d 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -53,6 +53,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y *on-click* ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right* ++ typeof: string ++ From 73bb42d40cd9ab5ad1dea04e339397ff2d051920 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:07:23 -0800 Subject: [PATCH 005/100] Update waybar-clock.5.scd --- man/waybar-clock.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index d979a673..720aca43 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -31,6 +31,10 @@ The *clock* module displays the current date and time. *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ From ecce607afe1e0e1cd0c026f11bcb2e614bfceddc Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:07:38 -0800 Subject: [PATCH 006/100] Update waybar-cpu.5.scd --- man/waybar-cpu.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index e4e52504..d6333678 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -36,6 +36,11 @@ The *cpu* module displays the current cpu utilization. typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From a94d5c5ff22bf01a4f154bf32f25a71a9db3ad59 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:08:15 -0800 Subject: [PATCH 007/100] Update waybar-disk.5.scd --- man/waybar-disk.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index 2a69cf49..e0b924f2 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -39,6 +39,10 @@ Addressed by *disk* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From ad08130b52616229a5a7dd8c6947b39bcb93971c Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:08:27 -0800 Subject: [PATCH 008/100] Update waybar-idle-inhibitor.5.scd --- man/waybar-idle-inhibitor.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 74e21928..1a8dd40c 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -31,6 +31,11 @@ screensaving, also known as "presentation mode". typeof: string ++ Command to execute when clicked on the module. A click also toggles the state +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 1a05e230b915134992900b7b75ad20da15208c7e Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:08:41 -0800 Subject: [PATCH 009/100] Update waybar-memory.5.scd --- man/waybar-memory.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index a9dfb3ab..3fbbb29d 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -38,6 +38,10 @@ Addressed by *memory* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From ac8e892cbd4333fbf6311580925a5e6c4009b1d8 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:09:08 -0800 Subject: [PATCH 010/100] Update waybar-mpd.5.scd --- man/waybar-mpd.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index 155e7b30..d6661a3f 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -76,6 +76,10 @@ Addressed by *mpd* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ From 6895b3b6b699954b4272ff70909db6c6462a6fa7 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:09:33 -0800 Subject: [PATCH 011/100] Update waybar-network.5.scd --- man/waybar-network.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index ed8451f4..d24abe97 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -54,6 +54,12 @@ Addressed by *network* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From b2cec74c04db8a9272037c2116149a18e0027455 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:09:44 -0800 Subject: [PATCH 012/100] Update waybar-pulseaudio.5.scd --- man/waybar-pulseaudio.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index 2b117782..3ade2e9b 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -58,6 +58,12 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + *on-click-right*: ++ typeof: string ++ From 548589ee5df44da161d95182d3a99d983509b765 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:10:14 -0800 Subject: [PATCH 013/100] Update waybar-sway-mode.5.scd --- man/waybar-sway-mode.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 64d9a3e8..15834db4 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -28,6 +28,12 @@ Addressed by *sway/mode* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + *on-click-right*: ++ typeof: string ++ From a307042d6b60de74d88d28bd572025bd1cb18abf Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:10:26 -0800 Subject: [PATCH 014/100] Update waybar-sway-window.5.scd --- man/waybar-sway-window.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 75a974c4..d5f6f8f4 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -28,6 +28,12 @@ Addressed by *sway/window* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + + *on-click-right*: ++ typeof: string ++ From 6c3cb7c85aa42f743c1dfb55221d4ad251e257cf Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sun, 15 Dec 2019 15:11:06 -0800 Subject: [PATCH 015/100] Update waybar-temperature.5.scd --- man/waybar-temperature.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 8177969e..1d924e0e 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -53,6 +53,10 @@ Addressed by *temperature* *on-click*: ++ typeof: string ++ Command to execute when you clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ From f9543e47dd62f0c7ac117f880d3aa341ae01cef3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Dec 2019 11:58:30 +0100 Subject: [PATCH 016/100] Revert "Add info on "on-click-middle" option to custom module man page" --- man/waybar-backlight.5.scd | 6 +----- man/waybar-battery.5.scd | 5 ----- man/waybar-clock.5.scd | 4 ---- man/waybar-cpu.5.scd | 5 ----- man/waybar-custom.5.scd | 5 ----- man/waybar-disk.5.scd | 4 ---- man/waybar-idle-inhibitor.5.scd | 5 ----- man/waybar-memory.5.scd | 4 ---- man/waybar-mpd.5.scd | 4 ---- man/waybar-network.5.scd | 6 ------ man/waybar-pulseaudio.5.scd | 6 ------ man/waybar-sway-mode.5.scd | 6 ------ man/waybar-sway-window.5.scd | 6 ------ man/waybar-temperature.5.scd | 4 ---- 14 files changed, 1 insertion(+), 69 deletions(-) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 8df118bc..2d971997 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -35,11 +35,7 @@ The *backlight* module displays the current backlight level. *on-click* ++ typeof: string ++ Command to execute when the module is clicked. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - + *on-click-right* ++ typeof: string ++ Command to execute when the module is right clicked. diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 7f90cd4d..94a99e4f 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -53,11 +53,6 @@ The *battery* module displays the current capacity and state (eg. charging) of y *on-click* ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - *on-click-right* ++ typeof: string ++ diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index 720aca43..d979a673 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -31,10 +31,6 @@ The *clock* module displays the current date and time. *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index d6333678..e4e52504 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -36,11 +36,6 @@ The *cpu* module displays the current cpu utilization. typeof: string ++ Command to execute when clicked on the module. -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 4c804c80..a427be38 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -59,10 +59,6 @@ Addressed by *custom/* typeof: string ++ Command to execute when clicked on the module. -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. @@ -141,7 +137,6 @@ $text\\n$tooltip\\n$class* "exec": "mpc current", "exec-if": "pgrep mpd", "on-click": "mpc toggle", - "on-click-middle": "playerctl play-pause", "on-click-right": "sonata" } ``` diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index e0b924f2..2a69cf49 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -39,10 +39,6 @@ Addressed by *disk* typeof: string ++ Command to execute when clicked on the module. -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 1a8dd40c..74e21928 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -31,11 +31,6 @@ screensaving, also known as "presentation mode". typeof: string ++ Command to execute when clicked on the module. A click also toggles the state -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index 3fbbb29d..a9dfb3ab 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -38,10 +38,6 @@ Addressed by *memory* typeof: string ++ Command to execute when clicked on the module. -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index d6661a3f..155e7b30 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -76,10 +76,6 @@ Addressed by *mpd* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index d24abe97..ed8451f4 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -54,12 +54,6 @@ Addressed by *network* typeof: string ++ Command to execute when clicked on the module. -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - - *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index 3ade2e9b..2b117782 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -58,12 +58,6 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - *on-click-right*: ++ typeof: string ++ diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 15834db4..64d9a3e8 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -28,12 +28,6 @@ Addressed by *sway/mode* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - *on-click-right*: ++ typeof: string ++ diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index d5f6f8f4..75a974c4 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -28,12 +28,6 @@ Addressed by *sway/window* *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. - - *on-click-right*: ++ typeof: string ++ diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 1d924e0e..8177969e 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -53,10 +53,6 @@ Addressed by *temperature* *on-click*: ++ typeof: string ++ Command to execute when you clicked on the module. - -*on-click-middle*: ++ - typeof: string ++ - Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ typeof: string ++ From d1637d34cf632e6aa303a3bb971a7c22b01c57ee Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 27 Aug 2019 20:57:23 -0700 Subject: [PATCH 017/100] refactor: fetch outputs from Gtk::Display instead of wl_registry. gtk-layer-shell wants Gdk::Monitor instead of wl_output; change code to deal with Gdk objects and slightly simplify it. Requires gtkmm 3.22.0+ (first release with Gdk::Monitor support). --- include/bar.hpp | 10 ++-- include/client.hpp | 10 ++-- meson.build | 2 +- src/bar.cpp | 4 +- src/client.cpp | 120 +++++++++++++++++++-------------------------- 5 files changed, 64 insertions(+), 82 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 7566b088..60c5283c 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -15,10 +16,11 @@ namespace waybar { class Factory; struct waybar_output { - struct wl_output * output = nullptr; - std::string name; - uint32_t wl_name; - struct zxdg_output_v1 *xdg_output = nullptr; + Glib::RefPtr monitor; + std::string name; + + std::unique_ptr xdg_output = { + nullptr, &zxdg_output_v1_destroy}; }; class Bar { diff --git a/include/client.hpp b/include/client.hpp index 715ae586..65a814fc 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -34,17 +34,15 @@ class Client { bool isValidOutput(const Json::Value &config, std::unique_ptr &output); auto setupConfig(const std::string &config_file) -> void; auto setupCss(const std::string &css_file) -> void; - std::unique_ptr &getOutput(uint32_t wl_name); + std::unique_ptr &getOutput(void *); std::vector getOutputConfigs(std::unique_ptr &output); static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name); - static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t, int32_t); - static void handleLogicalSize(void *, struct zxdg_output_v1 *, int32_t, int32_t); - static void handleDone(void *, struct zxdg_output_v1 *); - static void handleName(void *, struct zxdg_output_v1 *, const char *); - static void handleDescription(void *, struct zxdg_output_v1 *, const char *); + static void handleOutputName(void *, struct zxdg_output_v1 *, const char *); + void handleMonitorAdded(Glib::RefPtr monitor); + void handleMonitorRemoved(Glib::RefPtr monitor); Json::Value config_; Glib::RefPtr style_context_; diff --git a/meson.build b/meson.build index a9d44eeb..f7ae5d8c 100644 --- a/meson.build +++ b/meson.build @@ -52,7 +52,7 @@ spdlog = dependency('spdlog', version : ['>=1.3.1'], fallback : ['spdlog', 'spdl wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') wayland_protos = dependency('wayland-protocols') -gtkmm = dependency('gtkmm-3.0') +gtkmm = dependency('gtkmm-3.0', version : ['>=3.22.0']) dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gtk')) giounix = dependency('gio-unix-2.0', required: get_option('dbusmenu-gtk')) jsoncpp = dependency('jsoncpp') diff --git a/src/bar.cpp b/src/bar.cpp index fc885119..15bdeeaf 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -146,10 +146,12 @@ void waybar::Bar::onMap(GdkEventAny* ev) { surface = gdk_wayland_window_get_wl_surface(gdk_window); auto client = waybar::Client::inst(); + // owned by output->monitor; no need to destroy + auto wl_output = gdk_wayland_monitor_get_wl_output(output->monitor->gobj()); auto layer = config["layer"] == "top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; layer_surface = zwlr_layer_shell_v1_get_layer_surface( - client->layer_shell, surface, output->output, layer, "waybar"); + client->layer_shell, surface, wl_output, layer, "waybar"); zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, false); zwlr_layer_surface_v1_set_anchor(layer_surface, anchor_); diff --git a/src/client.cpp b/src/client.cpp index 34efdf10..dd4cd50e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1,4 +1,5 @@ #include "client.hpp" +#include #include #include #include @@ -33,11 +34,6 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { client->layer_shell = static_cast( wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, version)); - } else if (strcmp(interface, wl_output_interface.name) == 0) { - auto wl_output = static_cast( - wl_registry_bind(registry, name, &wl_output_interface, version)); - client->outputs_.emplace_back(new struct waybar_output({wl_output, "", name, nullptr})); - client->handleOutput(client->outputs_.back()); } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { client->xdg_output_manager = static_cast(wl_registry_bind( @@ -50,58 +46,21 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint void waybar::Client::handleGlobalRemove(void * data, struct wl_registry * /*registry*/, uint32_t name) { - auto client = static_cast(data); - for (auto it = client->bars.begin(); it != client->bars.end();) { - if ((*it)->output->wl_name == name) { - auto output_name = (*it)->output->name; - (*it)->window.close(); - it = client->bars.erase(it); - spdlog::info("Bar removed from output: {}", output_name); - } else { - ++it; - } - } - auto it = std::find_if(client->outputs_.begin(), - client->outputs_.end(), - [&name](const auto &output) { return output->wl_name == name; }); - if (it != client->outputs_.end()) { - if ((*it)->xdg_output != nullptr) { - zxdg_output_v1_destroy((*it)->xdg_output); - (*it)->xdg_output = nullptr; - } - if ((*it)->output != nullptr) { - wl_output_destroy((*it)->output); - (*it)->output = nullptr; - } - client->outputs_.erase(it); - } + // Nothing here } void waybar::Client::handleOutput(std::unique_ptr &output) { static const struct zxdg_output_v1_listener xdgOutputListener = { - .logical_position = handleLogicalPosition, - .logical_size = handleLogicalSize, - .done = handleDone, - .name = handleName, - .description = handleDescription, + .logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, + .logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, + .done = [](void *, struct zxdg_output_v1 *) {}, + .name = &handleOutputName, + .description = [](void *, struct zxdg_output_v1 *, const char *) {}, }; - output->xdg_output = zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, output->output); - zxdg_output_v1_add_listener(output->xdg_output, &xdgOutputListener, &output->wl_name); -} - -void waybar::Client::handleLogicalPosition(void * /*data*/, - struct zxdg_output_v1 * /*zxdg_output_v1*/, - int32_t /*x*/, int32_t /*y*/) { - // Nothing here -} - -void waybar::Client::handleLogicalSize(void * /*data*/, struct zxdg_output_v1 * /*zxdg_output_v1*/, - int32_t /*width*/, int32_t /*height*/) { - // Nothing here -} - -void waybar::Client::handleDone(void * /*data*/, struct zxdg_output_v1 * /*zxdg_output_v1*/) { - // Nothing here + // owned by output->monitor; no need to destroy + auto wl_output = gdk_wayland_monitor_get_wl_output(output->monitor->gobj()); + output->xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output)); + zxdg_output_v1_add_listener(output->xdg_output.get(), &xdgOutputListener, output.get()); } bool waybar::Client::isValidOutput(const Json::Value & config, @@ -123,9 +82,9 @@ bool waybar::Client::isValidOutput(const Json::Value & config return found; } -std::unique_ptr &waybar::Client::getOutput(uint32_t wl_name) { - auto it = std::find_if(outputs_.begin(), outputs_.end(), [&wl_name](const auto &output) { - return output->wl_name == wl_name; +std::unique_ptr &waybar::Client::getOutput(void *addr) { + auto it = std::find_if(outputs_.begin(), outputs_.end(), [&addr](const auto &output) { + return output.get() == addr; }); if (it == outputs_.end()) { throw std::runtime_error("Unable to find valid output"); @@ -148,23 +107,19 @@ std::vector waybar::Client::getOutputConfigs( return configs; } -void waybar::Client::handleName(void * data, struct zxdg_output_v1 * /*xdg_output*/, - const char *name) { - auto wl_name = *static_cast(data); +void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 * /*xdg_output*/, + const char *name) { auto client = waybar::Client::inst(); try { - auto &output = client->getOutput(wl_name); + auto &output = client->getOutput(data); output->name = name; + spdlog::debug("Output detected: {} ({} {})", + name, + output->monitor->get_manufacturer(), + output->monitor->get_model()); auto configs = client->getOutputConfigs(output); if (configs.empty()) { - if (output->output != nullptr) { - wl_output_destroy(output->output); - output->output = nullptr; - } - if (output->xdg_output != nullptr) { - zxdg_output_v1_destroy(output->xdg_output); - output->xdg_output = nullptr; - } + output->xdg_output.reset(); } else { wl_display_roundtrip(client->wl_display); for (const auto &config : configs) { @@ -179,9 +134,26 @@ void waybar::Client::handleName(void * data, struct zxdg_output_v1 * /*xdg_ } } -void waybar::Client::handleDescription(void * /*data*/, struct zxdg_output_v1 * /*zxdg_output_v1*/, - const char * /*description*/) { - // Nothing here +void waybar::Client::handleMonitorAdded(Glib::RefPtr monitor) { + auto &output = outputs_.emplace_back(new struct waybar_output({monitor})); + handleOutput(output); +} + +void waybar::Client::handleMonitorRemoved(Glib::RefPtr monitor) { + spdlog::debug("Output removed: {} {}", monitor->get_manufacturer(), monitor->get_model()); + for (auto it = bars.begin(); it != bars.end();) { + if ((*it)->output->monitor == monitor) { + auto output_name = (*it)->output->name; + (*it)->window.close(); + it = bars.erase(it); + spdlog::info("Bar removed from output: {}", output_name); + } else { + ++it; + } + } + std::remove_if(outputs_.begin(), outputs_.end(), [&monitor](const auto &output) { + return output->monitor == monitor; + }); } std::tuple waybar::Client::getConfigs( @@ -240,6 +212,14 @@ void waybar::Client::bindInterfaces() { if (layer_shell == nullptr || xdg_output_manager == nullptr) { throw std::runtime_error("Failed to acquire required resources."); } + // add existing outputs and subscribe to updates + for (auto i = 0; i < gdk_display->get_n_monitors(); ++i) { + auto monitor = gdk_display->get_monitor(i); + handleMonitorAdded(monitor); + } + gdk_display->signal_monitor_added().connect(sigc::mem_fun(*this, &Client::handleMonitorAdded)); + gdk_display->signal_monitor_removed().connect( + sigc::mem_fun(*this, &Client::handleMonitorRemoved)); } int waybar::Client::main(int argc, char *argv[]) { From 0e87b3938a37b11c66ca4768f42bac21d5540eda Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Sat, 17 Aug 2019 18:12:20 -0700 Subject: [PATCH 018/100] deps: meson dependencies for gtk-layer-shell feature --- meson.build | 10 +++++++++- meson_options.txt | 1 + subprojects/gtk-layer-shell.wrap | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 subprojects/gtk-layer-shell.wrap diff --git a/meson.build b/meson.build index f7ae5d8c..a3260d34 100644 --- a/meson.build +++ b/meson.build @@ -62,6 +62,9 @@ libnlgen = dependency('libnl-genl-3.0', required: get_option('libnl')) libpulse = dependency('libpulse', required: get_option('pulseaudio')) libudev = dependency('libudev', required: get_option('libudev')) libmpdclient = dependency('libmpdclient', required: get_option('mpd')) +gtk_layer_shell = dependency('gtk-layer-shell-0', + required: get_option('gtk-layer-shell'), + fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) prefix = get_option('prefix') @@ -136,6 +139,10 @@ if libmpdclient.found() src_files += 'src/modules/mpd.cpp' endif +if gtk_layer_shell.found() + add_project_arguments('-DHAVE_GTK_LAYER_SHELL', language: 'cpp') +endif + subdir('protocol') executable( @@ -158,7 +165,8 @@ executable( libnlgen, libpulse, libudev, - libmpdclient + libmpdclient, + gtk_layer_shell ], include_directories: [include_directories('include')], install: true, diff --git a/meson_options.txt b/meson_options.txt index 1b86b57a..f70e0ffb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,3 +7,4 @@ option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable supp option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon') option('out', type: 'string', value : '/', description: 'output prefix directory') +option('gtk-layer-shell', type: 'feature', value: 'disabled', description: 'Use gtk-layer-shell library for popups support') diff --git a/subprojects/gtk-layer-shell.wrap b/subprojects/gtk-layer-shell.wrap new file mode 100644 index 00000000..b826ab9c --- /dev/null +++ b/subprojects/gtk-layer-shell.wrap @@ -0,0 +1,5 @@ +[wrap-file] +directory = gtk-layer-shell-0.1.0 +source_filename = gtk-layer-shell-0.1.0.tar.gz +source_hash = f7569e27ae30b1a94c3ad6c955cf56240d6bc272b760d9d266ce2ccdb94a5cf0 +source_url = https://github.com/wmww/gtk-layer-shell/archive/v0.1.0/gtk-layer-shell-0.1.0.tar.gz From dde700f2c97f957ef923c5313137b9ac7db0272a Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Fri, 27 Dec 2019 16:31:18 -0800 Subject: [PATCH 019/100] feat: use gtk-layer-shell library for correct positioning of popups To enable: use sway >= 1.2, compile waybar with `-Dgtk-layer-shell=enabled` meson option. Original behavior could be restored at runtime by setting `"gtk-layer-shell": false` in waybar config. --- include/bar.hpp | 20 ++++++----- src/bar.cpp | 88 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 60c5283c..fb0cd592 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -32,13 +32,12 @@ class Bar { auto toggle() -> void; void handleSignal(int); - struct waybar_output * output; - Json::Value config; - Gtk::Window window; - struct wl_surface * surface; - struct zwlr_layer_surface_v1 *layer_surface; - bool visible = true; - bool vertical = false; + struct waybar_output *output; + Json::Value config; + Gtk::Window window; + struct wl_surface * surface; + bool visible = true; + bool vertical = false; private: static constexpr const char *MIN_HEIGHT_MSG = @@ -53,7 +52,9 @@ class Bar { uint32_t, uint32_t); static void layerSurfaceHandleClosed(void *, struct zwlr_layer_surface_v1 *); - void destroyOutput(); +#ifdef HAVE_GTK_LAYER_SHELL + void initGtkLayerShell(); +#endif void onConfigure(GdkEventConfigure *ev); void onRealize(); void onMap(GdkEventAny *ev); @@ -70,6 +71,9 @@ class Bar { int bottom = 0; int left = 0; } margins_; + struct zwlr_layer_surface_v1 *layer_surface_; + // use gtk-layer-shell instead of handling layer surfaces directly + bool use_gls_ = false; uint32_t width_ = 0; uint32_t height_ = 1; uint8_t anchor_; diff --git a/src/bar.cpp b/src/bar.cpp index 15bdeeaf..7b9e9307 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -1,3 +1,7 @@ +#ifdef HAVE_GTK_LAYER_SHELL +#include +#endif + #include "bar.hpp" #include "client.hpp" #include "factory.hpp" @@ -8,7 +12,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) config(w_config), window{Gtk::WindowType::WINDOW_TOPLEVEL}, surface(nullptr), - layer_surface(nullptr), + layer_surface_(nullptr), anchor_(ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP), left_(Gtk::ORIENTATION_HORIZONTAL, 0), center_(Gtk::ORIENTATION_HORIZONTAL, 0), @@ -28,11 +32,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) height_ = config["height"].isUInt() ? config["height"].asUInt() : height_; width_ = config["width"].isUInt() ? config["width"].asUInt() : width_; - window.signal_realize().connect_notify(sigc::mem_fun(*this, &Bar::onRealize)); - window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap)); - window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure)); - window.set_size_request(width_, height_); - if (config["position"] == "bottom") { anchor_ = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; } else if (config["position"] == "left") { @@ -98,6 +97,17 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps}; } +#ifdef HAVE_GTK_LAYER_SHELL + use_gls_ = config["gtk-layer-shell"].isBool() ? config["gtk-layer-shell"].asBool() : true; + if (use_gls_) { + initGtkLayerShell(); + } +#endif + + window.signal_realize().connect_notify(sigc::mem_fun(*this, &Bar::onRealize)); + window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap)); + window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure)); + window.set_size_request(width_, height_); setupWidgets(); if (window.get_realized()) { @@ -131,11 +141,43 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) { tmp_width = ev->width; } } - if (tmp_width != width_ || tmp_height != height_) { + if (use_gls_) { + width_ = tmp_width; + height_ = tmp_height; + spdlog::debug("Set surface size {}x{} for output {}", width_, height_, output->name); + setExclusiveZone(tmp_width, tmp_height); + } else if (tmp_width != width_ || tmp_height != height_) { setSurfaceSize(tmp_width, tmp_height); } } +#ifdef HAVE_GTK_LAYER_SHELL +void waybar::Bar::initGtkLayerShell() { + auto gtk_window = window.gobj(); + // this has to be executed before GtkWindow.realize + gtk_layer_init_for_window(gtk_window); + gtk_layer_set_keyboard_interactivity(gtk_window, FALSE); + auto layer = config["layer"] == "top" ? GTK_LAYER_SHELL_LAYER_TOP : GTK_LAYER_SHELL_LAYER_BOTTOM; + gtk_layer_set_layer(gtk_window, layer); + gtk_layer_set_monitor(gtk_window, output->monitor->gobj()); + gtk_layer_set_namespace(gtk_window, "waybar"); + + gtk_layer_set_anchor( + gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT); + gtk_layer_set_anchor( + gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT); + gtk_layer_set_anchor( + gtk_window, GTK_LAYER_SHELL_EDGE_TOP, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP); + gtk_layer_set_anchor( + gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, anchor_ & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM); + + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_LEFT, margins_.left); + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right); + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top); + gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom); +} +#endif + void waybar::Bar::onRealize() { auto gdk_window = window.get_window()->gobj(); gdk_wayland_window_set_use_custom_surface(gdk_window); @@ -145,18 +187,22 @@ void waybar::Bar::onMap(GdkEventAny* ev) { auto gdk_window = window.get_window()->gobj(); surface = gdk_wayland_window_get_wl_surface(gdk_window); + if (use_gls_) { + return; + } + auto client = waybar::Client::inst(); // owned by output->monitor; no need to destroy auto wl_output = gdk_wayland_monitor_get_wl_output(output->monitor->gobj()); auto layer = config["layer"] == "top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM; - layer_surface = zwlr_layer_shell_v1_get_layer_surface( + layer_surface_ = zwlr_layer_shell_v1_get_layer_surface( client->layer_shell, surface, wl_output, layer, "waybar"); - zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, false); - zwlr_layer_surface_v1_set_anchor(layer_surface, anchor_); + zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface_, false); + zwlr_layer_surface_v1_set_anchor(layer_surface_, anchor_); zwlr_layer_surface_v1_set_margin( - layer_surface, margins_.top, margins_.right, margins_.bottom, margins_.left); + layer_surface_, margins_.top, margins_.right, margins_.bottom, margins_.left); setSurfaceSize(width_, height_); setExclusiveZone(width_, height_); @@ -164,7 +210,7 @@ void waybar::Bar::onMap(GdkEventAny* ev) { .configure = layerSurfaceHandleConfigure, .closed = layerSurfaceHandleClosed, }; - zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, this); + zwlr_layer_surface_v1_add_listener(layer_surface_, &layer_surface_listener, this); wl_surface_commit(surface); wl_display_roundtrip(client->wl_display); @@ -184,7 +230,15 @@ void waybar::Bar::setExclusiveZone(uint32_t width, uint32_t height) { } } spdlog::debug("Set exclusive zone {} for output {}", zone, output->name); - zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, zone); + +#ifdef HAVE_GTK_LAYER_SHELL + if (use_gls_) { + gtk_layer_set_exclusive_zone(window.gobj(), zone); + } else +#endif + { + zwlr_layer_surface_v1_set_exclusive_zone(layer_surface_, zone); + } } void waybar::Bar::setSurfaceSize(uint32_t width, uint32_t height) { @@ -200,7 +254,7 @@ void waybar::Bar::setSurfaceSize(uint32_t width, uint32_t height) { width += margins_.right + margins_.left; } spdlog::debug("Set surface size {}x{} for output {}", width, height, output->name); - zwlr_layer_surface_v1_set_size(layer_surface, width, height); + zwlr_layer_surface_v1_set_size(layer_surface_, width, height); } // Converting string to button code rn as to avoid doing it later @@ -284,9 +338,9 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surf void waybar::Bar::layerSurfaceHandleClosed(void* data, struct zwlr_layer_surface_v1* /*surface*/) { auto o = static_cast(data); - if (o->layer_surface) { - zwlr_layer_surface_v1_destroy(o->layer_surface); - o->layer_surface = nullptr; + if (o->layer_surface_) { + zwlr_layer_surface_v1_destroy(o->layer_surface_); + o->layer_surface_ = nullptr; } o->modules_left_.clear(); o->modules_center_.clear(); From 220028051f1d29902cb43e6a484d57dc9c5d8e63 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Dec 2019 12:13:33 +0100 Subject: [PATCH 020/100] chore: auto gtk-layer-shell option --- meson_options.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson_options.txt b/meson_options.txt index f70e0ffb..8d442c77 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,4 +7,4 @@ option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable supp option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon') option('out', type: 'string', value : '/', description: 'output prefix directory') -option('gtk-layer-shell', type: 'feature', value: 'disabled', description: 'Use gtk-layer-shell library for popups support') +option('gtk-layer-shell', type: 'feature', value: 'auto', description: 'Use gtk-layer-shell library for popups support') From 35d806b8017bcd3d2059d36175660bf92a88df15 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Dec 2019 12:35:09 +0100 Subject: [PATCH 021/100] chore: 0.9.0 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a3260d34..a099ad2b 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'waybar', 'cpp', 'c', - version: '0.8.0', + version: '0.9.0', license: 'MIT', default_options : [ 'cpp_std=c++17', From 50275ae5297018e246b4dcc27a98939d508d91cd Mon Sep 17 00:00:00 2001 From: Nils Rokita <0rokita@informatik.uni-hamburg.de> Date: Sat, 28 Dec 2019 15:19:42 +0100 Subject: [PATCH 022/100] add dependencies of gtk-layer-shell to readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab34b4e8..d8b7545d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ libsigc++ fmt wayland wlroots +libgtk-3-dev [gtk-layer-shell] +gobject-introspection [gtk-layer-shell] +libgirepository1.0-dev [gtk-layer-shell] libpulse [Pulseaudio module] libnl [Network module] sway [Sway modules] @@ -59,7 +62,7 @@ libmpdclient [MPD module] On Ubuntu 19.10 you can install all the relevant dependencies using this command: ``` -sudo apt install libgtkmm-3.0-dev libjsoncpp-dev libinput-dev libsigc++-2.0-dev libpulse-dev libnl-3-dev libdbusmenu-gtk3-dev libnl-genl-3-dev libfmt-dev clang-tidy scdoc libmpdclient-dev +sudo apt install libgtkmm-3.0-dev libjsoncpp-dev libinput-dev libsigc++-2.0-dev libpulse-dev libnl-3-dev libdbusmenu-gtk3-dev libnl-genl-3-dev libfmt-dev clang-tidy libmpdclient-dev libwayland-dev libgtk-3-dev gobject-introspection libgirepository1.0-dev scdoc ``` From c885be369e4f2a822b1e3635b8cdca098c50f113 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Dec 2019 13:44:06 +0100 Subject: [PATCH 023/100] feat(Network): hide on empty format --- src/modules/network.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index ba196cff..a332d5a2 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -280,6 +280,11 @@ auto waybar::modules::Network::update() -> void { fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / interval_.count(), "o/s"))); if (text != label_.get_label()) { label_.set_markup(text); + if (text.empty()) { + event_box_.hide(); + } else { + event_box_.show(); + } } if (tooltipEnabled()) { if (tooltip_format.empty() && config_["tooltip-format"].isString()) { From d40cc6f23a7dba1736dadd0fe180c2bed0831785 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Dec 2019 13:55:49 +0100 Subject: [PATCH 024/100] fix(Battery): replace spaces w/ underscores --- src/modules/battery.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 61ed50a4..d5cd8fd5 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -163,7 +163,12 @@ auto waybar::modules::Battery::update() -> void { } label_.set_tooltip_text(tooltip_text); } + // Transform to lowercase std::transform(status.begin(), status.end(), status.begin(), ::tolower); + // Replace space with underscore + std::transform(status.begin(), status.end(), status.begin(), [](char ch) { + return ch == ' ' ? '_' : ch; + }); auto format = format_; auto state = getState(capacity, true); if (!old_status_.empty()) { From c8821a5e7ff9de5f55189a5128d6413b9505dd51 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Dec 2019 13:56:34 +0100 Subject: [PATCH 025/100] fix(Battery): replace spaces w/ dashes --- src/modules/battery.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index d5cd8fd5..dfd67531 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -165,9 +165,9 @@ auto waybar::modules::Battery::update() -> void { } // Transform to lowercase std::transform(status.begin(), status.end(), status.begin(), ::tolower); - // Replace space with underscore + // Replace space with dash std::transform(status.begin(), status.end(), status.begin(), [](char ch) { - return ch == ' ' ? '_' : ch; + return ch == ' ' ? '-' : ch; }); auto format = format_; auto state = getState(capacity, true); From db1136d647318624cc6d1d94a8572ef51ab06e82 Mon Sep 17 00:00:00 2001 From: Adrien Lemaire Date: Wed, 1 Jan 2020 13:50:29 +0900 Subject: [PATCH 026/100] feat: show title if artist isn't available --- resources/custom_modules/mediaplayer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/custom_modules/mediaplayer.py b/resources/custom_modules/mediaplayer.py index 4d75a254..7404f48f 100755 --- a/resources/custom_modules/mediaplayer.py +++ b/resources/custom_modules/mediaplayer.py @@ -38,6 +38,8 @@ def on_metadata(player, metadata, manager): elif player.get_artist() != '' and player.get_title() != '': track_info = '{artist} - {title}'.format(artist=player.get_artist(), title=player.get_title()) + else: + track_info = player.get_title() if player.props.status != 'Playing' and track_info: track_info = ' ' + track_info @@ -123,4 +125,3 @@ def main(): if __name__ == '__main__': main() - From 2f6a70f34e9984b32b4ac9d9362b7031827215fb Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Fri, 3 Jan 2020 15:46:59 +0100 Subject: [PATCH 027/100] man: document gtk-layer-shell configuration option --- man/waybar.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/waybar.5.scd b/man/waybar.5.scd index 3278c636..72146359 100644 --- a/man/waybar.5.scd +++ b/man/waybar.5.scd @@ -66,6 +66,12 @@ Also a minimal example configuration can be found on the at the bottom of this m typeof: string ++ Optional name added as a CSS class, for styling multiple waybars. +*gtk-layer-shell* ++ + typeof: bool ++ + default: true ++ + Option to disable the use of gtk-layer-shell for popups. + Only functional if compiled with gtk-layer-shell support. + # MODULE FORMAT You can use PangoMarkupFormat (See https://developer.gnome.org/pango/stable/PangoMarkupFormat.html#PangoMarkupFormat). From f01ddb9ab39ced295aa5b612702537c83b6c5998 Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Fri, 3 Jan 2020 15:50:05 +0100 Subject: [PATCH 028/100] man: clarify options for layer configuration --- man/waybar.5.scd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man/waybar.5.scd b/man/waybar.5.scd index 72146359..758d90a9 100644 --- a/man/waybar.5.scd +++ b/man/waybar.5.scd @@ -23,7 +23,8 @@ Also a minimal example configuration can be found on the at the bottom of this m *layer* ++ typeof: string ++ default: bottom ++ - Decide if the bar is displayed in front of the windows or behind them. + Decide if the bar is displayed in front (*top*) of the windows or behind (*bottom*) + them. *output* ++ typeof: string|array ++ From 4836333bffdaab998ace77730301e909de852ad4 Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Sat, 4 Jan 2020 03:26:06 +0100 Subject: [PATCH 029/100] man: document family configuration option in network module --- man/waybar-network.5.scd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index ed8451f4..248b8b33 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -21,6 +21,11 @@ Addressed by *network* default: 60 ++ The interval in which the network information gets polled (e.g. signal strength). +*family*: ++ + typeof: string ++ + default: *ipv4* ++ + The address family that is used for the format replacement {ipaddr} and to determine if a network connection is present. + *format*: ++ typeof: string ++ default: *{ifname}* ++ From 173a7bb8cdd32e6e3d4d662d5bf7293ab24490f7 Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Sat, 4 Jan 2020 04:31:24 +0100 Subject: [PATCH 030/100] man: fix layout in battery module --- man/waybar-battery.5.scd | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 94a99e4f..81ee22dd 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -37,32 +37,32 @@ The *battery* module displays the current capacity and state (eg. charging) of y default: {H} h {M} min ++ The format, how the time should be displayed. -*format-icons* - typeof: array/object +*format-icons*: ++ + typeof: array/object ++ Based on the current capacity, the corresponding icon gets selected. ++ The order is *low* to *high*. Or by the state if it is an object. -*max-length* ++ +*max-length*: ++ typeof: integer++ The maximum length in character the module should display. -*rotate* ++ +*rotate*: ++ typeof: integer++ Positive value to rotate the text label. -*on-click* ++ +*on-click*: ++ typeof: string ++ Command to execute when clicked on the module. -*on-click-right* ++ +*on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. -*on-scroll-up* ++ +*on-scroll-up*: ++ typeof: string ++ Command to execute when scrolling up on the module. -*on-scroll-down* ++ +*on-scroll-down*: ++ typeof: string ++ Command to execute when scrolling down on the module. From 1125119dc695d5daf1864f7fd5213bde5332997b Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Sat, 4 Jan 2020 04:33:04 +0100 Subject: [PATCH 031/100] man: add icon and format-icon to network module --- man/waybar-network.5.scd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index 248b8b33..b06cbaed 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -47,6 +47,11 @@ Addressed by *network* typeof: string ++ This format is used when the displayed interface is disconnected. +*format-icons*: ++ + typeof: array/object ++ + Based on the current signal strength, the corresponding icon gets selected. ++ + The order is *low* to *high*. Or by the state if it is an object. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label. @@ -122,6 +127,8 @@ Addressed by *network* *{bandwidthDownOctets}*: Instant down speed in octets/seconds. +*{icon}*: Icon, as defined in *format-icons*. + # EXAMPLES ``` From 1f379fa5f6afdc8682517e1e62fdd352a8254130 Mon Sep 17 00:00:00 2001 From: gammafn Date: Sun, 5 Jan 2020 10:22:52 -0600 Subject: [PATCH 032/100] Don't specify WindowId property https://github.com/Alexays/Waybar/pull/536#issuecomment-570847035 --- protocol/dbus-status-notifier-item.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/protocol/dbus-status-notifier-item.xml b/protocol/dbus-status-notifier-item.xml index e46eb3c6..c33cd846 100644 --- a/protocol/dbus-status-notifier-item.xml +++ b/protocol/dbus-status-notifier-item.xml @@ -31,7 +31,9 @@ + @@ -44,4 +46,4 @@ - \ No newline at end of file + From 1145788ab34b728940d255305585890b83dc9b10 Mon Sep 17 00:00:00 2001 From: Moritz Jordan Date: Sat, 4 Jan 2020 03:11:34 +0100 Subject: [PATCH 033/100] fix(network): display of IPv6 address --- src/modules/network.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index a332d5a2..f9146c75 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -439,7 +439,6 @@ out: } void waybar::modules::Network::getInterfaceAddress() { - unsigned int cidrRaw; struct ifaddrs *ifaddr, *ifa; cidr_ = 0; int success = getifaddrs(&ifaddr); @@ -451,18 +450,34 @@ void waybar::modules::Network::getInterfaceAddress() { if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == family_ && ifa->ifa_name == ifname_) { char ipaddr[INET6_ADDRSTRLEN]; - ipaddr_ = inet_ntop(family_, - &reinterpret_cast(ifa->ifa_addr)->sin_addr, - ipaddr, - INET6_ADDRSTRLEN); char netmask[INET6_ADDRSTRLEN]; - auto net_addr = reinterpret_cast(ifa->ifa_netmask); - netmask_ = inet_ntop(family_, &net_addr->sin_addr, netmask, INET6_ADDRSTRLEN); - cidrRaw = net_addr->sin_addr.s_addr; unsigned int cidr = 0; - while (cidrRaw) { - cidr += cidrRaw & 1; - cidrRaw >>= 1; + if (family_ == AF_INET) { + ipaddr_ = inet_ntop(AF_INET, + &reinterpret_cast(ifa->ifa_addr)->sin_addr, + ipaddr, + INET_ADDRSTRLEN); + auto net_addr = reinterpret_cast(ifa->ifa_netmask); + netmask_ = inet_ntop(AF_INET, &net_addr->sin_addr, netmask, INET_ADDRSTRLEN); + unsigned int cidrRaw = net_addr->sin_addr.s_addr; + while (cidrRaw) { + cidr += cidrRaw & 1; + cidrRaw >>= 1; + } + } else { + ipaddr_ = inet_ntop(AF_INET6, + &reinterpret_cast(ifa->ifa_addr)->sin6_addr, + ipaddr, + INET6_ADDRSTRLEN); + auto net_addr = reinterpret_cast(ifa->ifa_netmask); + netmask_ = inet_ntop(AF_INET6, &net_addr->sin6_addr, netmask, INET6_ADDRSTRLEN); + for (size_t i = 0; i < sizeof(net_addr->sin6_addr.s6_addr); ++i) { + unsigned char cidrRaw = net_addr->sin6_addr.s6_addr[i]; + while (cidrRaw) { + cidr += cidrRaw & 1; + cidrRaw >>= 1; + } + } } cidr_ = cidr; break; From f6864e4a43b09d77eda317990cd200e902983c06 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:11:22 -0800 Subject: [PATCH 034/100] Update waybar-memory.5.scd --- man/waybar-memory.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index a9dfb3ab..70718e14 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -38,6 +38,10 @@ Addressed by *memory* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From c41cedd40761b1422b0e9b2f49a97508ac7f9125 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:14:33 -0800 Subject: [PATCH 035/100] Update waybar-mpd.5.scd --- man/waybar-mpd.5.scd | 124 ++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index 155e7b30..598cbc63 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -13,110 +13,114 @@ The *mpd* module displays information about a running "Music Player Daemon" inst Addressed by *mpd* *server*: ++ - typeof: string ++ - The network address or Unix socket path of the MPD server. If empty, connect to the default host. + typeof: string ++ + The network address or Unix socket path of the MPD server. If empty, connect to the default host. *port*: ++ - typeof: integer ++ - The port MPD listens to. If empty, use the default port. + typeof: integer ++ + The port MPD listens to. If empty, use the default port. *interval*: ++ - typeof: integer++ - default: 5 ++ - The interval in which the connection to the MPD server is retried + typeof: integer++ + default: 5 ++ + The interval in which the connection to the MPD server is retried *timeout*: ++ - typeof: integer++ - default: 30 ++ - The timeout for the connection. Change this if your MPD server has a low `connection_timeout` setting + typeof: integer++ + default: 30 ++ + The timeout for the connection. Change this if your MPD server has a low `connection_timeout` setting *unknown-tag*: ++ - typeof: string ++ - default: "N/A" ++ - The text to display when a tag is not present in the current song, but used in `format` + typeof: string ++ + default: "N/A" ++ + The text to display when a tag is not present in the current song, but used in `format` *format*: ++ - typeof: string ++ - default: "{album} - {artist} - {title}" ++ - Information displayed when a song is playing or paused + typeof: string ++ + default: "{album} - {artist} - {title}" ++ + Information displayed when a song is playing or paused *format-stopped*: ++ - typeof: string ++ - default: "stopped" ++ - Information displayed when the player is stopped. + typeof: string ++ + default: "stopped" ++ + Information displayed when the player is stopped. *format-disconnected*: ++ - typeof: string ++ - default: "disconnected" ++ - Information displayed when the MPD server can't be reached. + typeof: string ++ + default: "disconnected" ++ + Information displayed when the MPD server can't be reached. *tooltip*: ++ - typeof: bool ++ - default: true ++ - Option to disable tooltip on hover. + typeof: bool ++ + default: true ++ + Option to disable tooltip on hover. *tooltip-format*: ++ - typeof: string ++ - default: "MPD (connected)" ++ - Tooltip information displayed when connected to MPD. + typeof: string ++ + default: "MPD (connected)" ++ + Tooltip information displayed when connected to MPD. *tooltip-format-disconnected*: ++ - typeof: string ++ - default: "MPD (disconnected)" ++ - Tooltip information displayed when the MPD server can't be reached. + typeof: string ++ + default: "MPD (disconnected)" ++ + Tooltip information displayed when the MPD server can't be reached. *rotate*: ++ - typeof: integer ++ - Positive value to rotate the text label. + typeof: integer ++ + Positive value to rotate the text label. *max-length*: ++ - typeof: integer ++ - The maximum length in character the module should display. + typeof: integer ++ + The maximum length in character the module should display. *on-click*: ++ - typeof: string ++ - Command to execute when clicked on the module. + typeof: string ++ + Command to execute when clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ - typeof: string ++ - Command to execute when you right clicked on the module. + typeof: string ++ + Command to execute when you right clicked on the module. *on-scroll-up*: ++ - typeof: string ++ - Command to execute when scrolling up on the module. + typeof: string ++ + Command to execute when scrolling up on the module. *on-scroll-down*: ++ - typeof: string ++ - Command to execute when scrolling down on the module. + typeof: string ++ + Command to execute when scrolling down on the module. *smooth-scrolling-threshold*: ++ - typeof: double ++ - Threshold to be used when scrolling. + typeof: double ++ + Threshold to be used when scrolling. *state-icons*: ++ - typeof: object ++ - default: {} ++ - Icon to show depending on the play/pause state of the player (*{ "playing": "...", "paused": "..." }*) + typeof: object ++ + default: {} ++ + Icon to show depending on the play/pause state of the player (*{ "playing": "...", "paused": "..." }*) *consume-icons*: ++ - typeof: object ++ - default: {} ++ - Icon to show depending on the "consume" option (*{ "on": "...", "off": "..." }*) + typeof: object ++ + default: {} ++ + Icon to show depending on the "consume" option (*{ "on": "...", "off": "..." }*) *random-icons*: ++ - typeof: object ++ - default: {} ++ - Icon to show depending on the "random" option (*{ "on": "...", "off": "..." }*) + typeof: object ++ + default: {} ++ + Icon to show depending on the "random" option (*{ "on": "...", "off": "..." }*) *repeat-icons*: ++ - typeof: object ++ - default: {} ++ - Icon to show depending on the "repeat" option (*{ "on": "...", "off": "..." }*) + typeof: object ++ + default: {} ++ + Icon to show depending on the "repeat" option (*{ "on": "...", "off": "..." }*) *single-icons*: ++ - typeof: object ++ - default: {} ++ - Icon to show depending on the "single" option (*{ "on": "...", "off": "..." }*) + typeof: object ++ + default: {} ++ + Icon to show depending on the "single" option (*{ "on": "...", "off": "..." }*) # FORMAT REPLACEMENTS From e8f2bd3ad10c1bc8787d78474f2b74380d6f5573 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:19:11 -0800 Subject: [PATCH 036/100] Update waybar-backlight.5.scd --- man/waybar-backlight.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 2d971997..5f2bb82b 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -36,6 +36,10 @@ The *backlight* module displays the current backlight level. typeof: string ++ Command to execute when the module is clicked. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right* ++ typeof: string ++ Command to execute when the module is right clicked. From 4d7e19ae665b4cd2e9c94db2797e7392b04945d9 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:19:45 -0800 Subject: [PATCH 037/100] Update waybar-battery.5.scd --- man/waybar-battery.5.scd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 81ee22dd..f96f85cb 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -54,7 +54,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ Command to execute when clicked on the module. -*on-click-right*: ++ +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + +*on-click-right* ++ typeof: string ++ Command to execute when you right clicked on the module. From de3be8b2ab56e7afa04a5c09ec7386ec7a612dd1 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:20:18 -0800 Subject: [PATCH 038/100] Update waybar-clock.5.scd --- man/waybar-clock.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index d979a673..959ec94b 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -32,6 +32,10 @@ The *clock* module displays the current date and time. typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 443281f0bc473e14395dcdf00f883cd26a6f282d Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:20:29 -0800 Subject: [PATCH 039/100] Update waybar-cpu.5.scd --- man/waybar-cpu.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index e4e52504..27dde96f 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -36,6 +36,10 @@ The *cpu* module displays the current cpu utilization. typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From abeb406166a1ba6c2f2eb336c1a136c6df241955 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:21:03 -0800 Subject: [PATCH 040/100] Update waybar-custom.5.scd --- man/waybar-custom.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index a427be38..0ae7f4cd 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -59,6 +59,10 @@ Addressed by *custom/* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 01b85273337944a710877ed2ef5ac0f4440b1cbb Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:21:14 -0800 Subject: [PATCH 041/100] Update waybar-disk.5.scd --- man/waybar-disk.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index 2a69cf49..25d00b1c 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -39,6 +39,10 @@ Addressed by *disk* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 1d087f96bd35352cf45877a3089940ecdfa59a54 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:21:25 -0800 Subject: [PATCH 042/100] Update waybar-idle-inhibitor.5.scd --- man/waybar-idle-inhibitor.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 74e21928..1fba291e 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -31,6 +31,10 @@ screensaving, also known as "presentation mode". typeof: string ++ Command to execute when clicked on the module. A click also toggles the state +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 9602360d2823627da250a5043ad6f5249027ae7d Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:21:45 -0800 Subject: [PATCH 043/100] Update waybar-network.5.scd --- man/waybar-network.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index b06cbaed..a557aa32 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -64,6 +64,10 @@ Addressed by *network* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From abcac464fae1b31db078ef67625682aabd1acf50 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:21:59 -0800 Subject: [PATCH 044/100] Update waybar-pulseaudio.5.scd --- man/waybar-pulseaudio.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index 2b117782..7640c706 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -59,6 +59,10 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From ee0db260213b2da620c538ad1d4a49a408781038 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:22:36 -0800 Subject: [PATCH 045/100] Update waybar-sway-mode.5.scd --- man/waybar-sway-mode.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 64d9a3e8..85a25d13 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -29,6 +29,10 @@ Addressed by *sway/mode* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 33798c31d04ff065028cf94ce9b13a387f09a8df Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:22:53 -0800 Subject: [PATCH 046/100] Update waybar-sway-window.5.scd --- man/waybar-sway-window.5.scd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 75a974c4..6a9d4e31 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -29,6 +29,10 @@ Addressed by *sway/window* typeof: string ++ Command to execute when clicked on the module. +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. + *on-click-right*: ++ typeof: string ++ Command to execute when you right clicked on the module. From 35f7fdf684ed43d7fc5da191c3c100d7612de9b5 Mon Sep 17 00:00:00 2001 From: fuzxi <33790641+fuzxi@users.noreply.github.com> Date: Sat, 28 Dec 2019 20:24:33 -0800 Subject: [PATCH 047/100] Update waybar-temperature.5.scd --- man/waybar-temperature.5.scd | 70 +++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 8177969e..437cd29d 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -13,67 +13,71 @@ The *temperature* module displays the current temperature from a thermal zone. Addressed by *temperature* *thermal-zone*: ++ - typeof: integer ++ - The thermal zone, as in */sys/class/thermal/*. + typeof: integer ++ + The thermal zone, as in */sys/class/thermal/*. *hwmon-path*: ++ - typeof: string ++ - The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*. + typeof: string ++ + The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*. *critical-threshold*: ++ - typeof: integer ++ - The threshold before it is considered critical (Celcius). + typeof: integer ++ + The threshold before it is considered critical (Celcius). *interval*: ++ - typeof: integer ++ - default: 10 ++ - The interval in which the information gets polled. + typeof: integer ++ + default: 10 ++ + The interval in which the information gets polled. *format-critical*: ++ - typeof: string ++ - The format to use when temperature is considered critical + typeof: string ++ + The format to use when temperature is considered critical *format*: ++ - typeof: string ++ - default: {temperatureC}°C ++ - The format (Celcius/Farenheit) in which the temperature should be displayed. + typeof: string ++ + default: {temperatureC}°C ++ + The format (Celcius/Farenheit) in which the temperature should be displayed. *format-icons*: ++ - typeof: array ++ - Based on the current temperature (Celcius) and *critical-threshold* if available, the corresponding icon gets selected. The order is *low* to *high*. + typeof: array ++ + Based on the current temperature (Celcius) and *critical-threshold* if available, the corresponding icon gets selected. The order is *low* to *high*. *rotate*: ++ - typeof: integer ++ - Positive value to rotate the text label. + typeof: integer ++ + Positive value to rotate the text label. *max-length*: ++ - typeof: integer ++ - The maximum length in characters the module should display. + typeof: integer ++ + The maximum length in characters the module should display. *on-click*: ++ - typeof: string ++ - Command to execute when you clicked on the module. + typeof: string ++ + Command to execute when you clicked on the module. + +*on-click-middle*: ++ + typeof: string ++ + Command to execute when middle-clicked on the module using mousewheel. *on-click-right*: ++ - typeof: string ++ - Command to execute when you right clicked on the module. + typeof: string ++ + Command to execute when you right clicked on the module. *on-scroll-up*: ++ - typeof: string ++ - Command to execute when scrolling up on the module. + typeof: string ++ + Command to execute when scrolling up on the module. *on-scroll-down*: ++ - typeof: string ++ - Command to execute when scrolling down on the module. + typeof: string ++ + Command to execute when scrolling down on the module. *smooth-scrolling-threshold*: ++ - typeof: double ++ - Threshold to be used when scrolling. + typeof: double ++ + Threshold to be used when scrolling. *tooltip*: ++ - typeof: bool ++ - default: true ++ - Option to disable tooltip on hover. + typeof: bool ++ + default: true ++ + Option to disable tooltip on hover. # FORMAT REPLACEMENTS From 75c6e2e7d53b5d2a7efbae38b6cf1225d446aee4 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 15 Oct 2019 09:24:04 -0700 Subject: [PATCH 048/100] mpd: add paused format string --- include/modules/mpd.hpp | 1 + man/waybar-mpd.5.scd | 6 +++++- src/modules/mpd.cpp | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index d69618a9..d08b28b2 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -36,6 +36,7 @@ class MPD : public ALabel { bool stopped(); bool playing(); + bool paused(); const std::string module_name_; diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index 598cbc63..fc3b1b36 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -38,13 +38,17 @@ Addressed by *mpd* *format*: ++ typeof: string ++ default: "{album} - {artist} - {title}" ++ - Information displayed when a song is playing or paused + Information displayed when a song is playing. *format-stopped*: ++ typeof: string ++ default: "stopped" ++ Information displayed when the player is stopped. +*format-paused*: ++ + typeof: string ++ + This format is used when a song is paused. + *format-disconnected*: ++ typeof: string ++ default: "disconnected" ++ diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 7bad855b..13ab9f0d 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -140,7 +140,9 @@ void waybar::modules::MPD::setLabel() { if (playing()) { label_.get_style_context()->add_class("playing"); label_.get_style_context()->remove_class("paused"); - } else { + } else if (paused()) { + format = + config_["format-paused"].isString() ? config_["format-paused"].asString() : config_["format"].asString(); label_.get_style_context()->add_class("paused"); label_.get_style_context()->remove_class("playing"); } @@ -346,3 +348,5 @@ bool waybar::modules::MPD::stopped() { } bool waybar::modules::MPD::playing() { return connection_ != nullptr && state_ == MPD_STATE_PLAY; } + +bool waybar::modules::MPD::paused() { return connection_ != nullptr && state_ == MPD_STATE_PAUSE; } From 129713fe1b8986fb4722b8e439b16508f063b3e7 Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Tue, 7 Jan 2020 20:27:31 +0100 Subject: [PATCH 049/100] fix(network): add missing include Fixes: ../src/modules/network.cpp:68:3: error: 'assert' was not declared in this scope 68 | assert(starts_with(read, category)); | ^~~~~~ ../src/modules/network.cpp:6:1: note: 'assert' is defined in header ''; did you forget to '#include '? 5 | #include "util/format.hpp" +++ |+#include 6 | --- src/modules/network.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index f9146c75..43f29f67 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "util/format.hpp" From 569f40de9bf31d67a1c7f733146d2ab7ae7d6326 Mon Sep 17 00:00:00 2001 From: Louis des Landes Date: Thu, 9 Jan 2020 16:59:45 +1030 Subject: [PATCH 050/100] Keep aspect ratio when scaling tray icons. --- src/modules/sni/item.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index bcc66e22..b298e442 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -265,7 +265,11 @@ void Item::updateImage() { if (pixbuf->gobj() != nullptr) { // An icon specified by path and filename may be the wrong size for // the tray - pixbuf = pixbuf->scale_simple(icon_size, icon_size, Gdk::InterpType::INTERP_BILINEAR); + // Keep the aspect ratio and scale to make the height equal to icon_size + // If people have non square icons, assume they want it to grow in width not height + int width = icon_size * pixbuf->get_width() / pixbuf->get_height(); + + pixbuf = pixbuf->scale_simple(width, icon_size, Gdk::InterpType::INTERP_BILINEAR); image.set(pixbuf); } } else { From 8fb3211594ced057025d2b8a9acc1b63a27cb388 Mon Sep 17 00:00:00 2001 From: PlusMinus0 Date: Mon, 13 Jan 2020 11:18:19 +0100 Subject: [PATCH 051/100] Use PA_PROP_DEVICE_FORM_FACTOR for device icon. --- include/modules/pulseaudio.hpp | 1 + src/modules/pulseaudio.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp index d575f627..ba5a2aaf 100644 --- a/include/modules/pulseaudio.hpp +++ b/include/modules/pulseaudio.hpp @@ -34,6 +34,7 @@ class Pulseaudio : public ALabel { pa_cvolume pa_volume_; bool muted_; std::string port_name_; + std::string form_factor_; std::string desc_; std::string monitor_; // SOURCE diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index ef2bc273..eb05b8c7 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -158,6 +158,9 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_ pa->desc_ = i->description; pa->monitor_ = i->monitor_source_name; pa->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; + if (auto ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) { + pa->form_factor_ = ff; + } pa->dp.emit(); } } @@ -185,7 +188,7 @@ static const std::array ports = { }; const std::string waybar::modules::Pulseaudio::getPortIcon() const { - std::string nameLC = port_name_; + std::string nameLC = port_name_ + form_factor_; std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const &port : ports) { if (nameLC.find(port) != std::string::npos) { From f80270519b55d7b12d06538df5d989c615eea1df Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 13 Jan 2020 23:27:57 -0800 Subject: [PATCH 052/100] refactor(client): use std::list to store outputs std::unique_ptr is not required here as the only benefit it gives is stability of address on vector resize and it's easy to invalidate it accidentaly. std::list provides the same guarantee of stable addresses of the elements and correct destruction while avoiding smart pointer overhead. Also fixes #554, caused by incorrect usage of std::remove_if. --- include/client.hpp | 16 ++++++++-------- src/client.cpp | 42 +++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/include/client.hpp b/include/client.hpp index 65a814fc..39b6ae3b 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -30,12 +30,12 @@ class Client { const std::string &style) const; void bindInterfaces(); const std::string getValidPath(const std::vector &paths) const; - void handleOutput(std::unique_ptr &output); - bool isValidOutput(const Json::Value &config, std::unique_ptr &output); + void handleOutput(struct waybar_output &output); + bool isValidOutput(const Json::Value &config, struct waybar_output &output); auto setupConfig(const std::string &config_file) -> void; auto setupCss(const std::string &css_file) -> void; - std::unique_ptr &getOutput(void *); - std::vector getOutputConfigs(std::unique_ptr &output); + struct waybar_output &getOutput(void *); + std::vector getOutputConfigs(struct waybar_output &output); static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); @@ -44,10 +44,10 @@ class Client { void handleMonitorAdded(Glib::RefPtr monitor); void handleMonitorRemoved(Glib::RefPtr monitor); - Json::Value config_; - Glib::RefPtr style_context_; - Glib::RefPtr css_provider_; - std::vector> outputs_; + Json::Value config_; + Glib::RefPtr style_context_; + Glib::RefPtr css_provider_; + std::list outputs_; }; } // namespace waybar diff --git a/src/client.cpp b/src/client.cpp index dd4cd50e..f7c70e06 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -49,7 +49,7 @@ void waybar::Client::handleGlobalRemove(void * data, struct wl_registry * /*re // Nothing here } -void waybar::Client::handleOutput(std::unique_ptr &output) { +void waybar::Client::handleOutput(struct waybar_output &output) { static const struct zxdg_output_v1_listener xdgOutputListener = { .logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, .logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, @@ -58,42 +58,39 @@ void waybar::Client::handleOutput(std::unique_ptr &output) .description = [](void *, struct zxdg_output_v1 *, const char *) {}, }; // owned by output->monitor; no need to destroy - auto wl_output = gdk_wayland_monitor_get_wl_output(output->monitor->gobj()); - output->xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output)); - zxdg_output_v1_add_listener(output->xdg_output.get(), &xdgOutputListener, output.get()); + auto wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj()); + output.xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output)); + zxdg_output_v1_add_listener(output.xdg_output.get(), &xdgOutputListener, &output); } -bool waybar::Client::isValidOutput(const Json::Value & config, - std::unique_ptr &output) { +bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) { bool found = true; if (config["output"].isArray()) { bool in_array = false; for (auto const &output_conf : config["output"]) { - if (output_conf.isString() && output_conf.asString() == output->name) { + if (output_conf.isString() && output_conf.asString() == output.name) { in_array = true; break; } } found = in_array; } - if (config["output"].isString() && config["output"].asString() != output->name) { + if (config["output"].isString() && config["output"].asString() != output.name) { found = false; } return found; } -std::unique_ptr &waybar::Client::getOutput(void *addr) { - auto it = std::find_if(outputs_.begin(), outputs_.end(), [&addr](const auto &output) { - return output.get() == addr; - }); +struct waybar::waybar_output &waybar::Client::getOutput(void *addr) { + auto it = std::find_if( + outputs_.begin(), outputs_.end(), [&addr](const auto &output) { return &output == addr; }); if (it == outputs_.end()) { throw std::runtime_error("Unable to find valid output"); } return *it; } -std::vector waybar::Client::getOutputConfigs( - std::unique_ptr &output) { +std::vector waybar::Client::getOutputConfigs(struct waybar_output &output) { std::vector configs; if (config_.isArray()) { for (auto const &config : config_) { @@ -112,18 +109,18 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 * auto client = waybar::Client::inst(); try { auto &output = client->getOutput(data); - output->name = name; + output.name = name; spdlog::debug("Output detected: {} ({} {})", name, - output->monitor->get_manufacturer(), - output->monitor->get_model()); + output.monitor->get_manufacturer(), + output.monitor->get_model()); auto configs = client->getOutputConfigs(output); if (configs.empty()) { - output->xdg_output.reset(); + output.xdg_output.reset(); } else { wl_display_roundtrip(client->wl_display); for (const auto &config : configs) { - client->bars.emplace_back(std::make_unique(output.get(), config)); + client->bars.emplace_back(std::make_unique(&output, config)); Glib::RefPtr screen = client->bars.back()->window.get_screen(); client->style_context_->add_provider_for_screen( screen, client->css_provider_, GTK_STYLE_PROVIDER_PRIORITY_USER); @@ -135,7 +132,8 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 * } void waybar::Client::handleMonitorAdded(Glib::RefPtr monitor) { - auto &output = outputs_.emplace_back(new struct waybar_output({monitor})); + auto &output = outputs_.emplace_back(); + output.monitor = monitor; handleOutput(output); } @@ -151,9 +149,7 @@ void waybar::Client::handleMonitorRemoved(Glib::RefPtr monitor) { ++it; } } - std::remove_if(outputs_.begin(), outputs_.end(), [&monitor](const auto &output) { - return output->monitor == monitor; - }); + outputs_.remove_if([&monitor](const auto &output) { return output.monitor == monitor; }); } std::tuple waybar::Client::getConfigs( From 99dde1aff8db2d77a7b351985233c98c5f5cd377 Mon Sep 17 00:00:00 2001 From: Thomas Wucher Date: Thu, 16 Jan 2020 11:09:32 +0100 Subject: [PATCH 053/100] Download patch files from Github instead of wrapdb Currently wrapdb.mesonbuild.com is offline and its not clear when it will be up again. Github seems to be the more reliable source for these files. --- subprojects/fmt.wrap | 2 +- subprojects/spdlog.wrap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap index b60b22a4..eb79283c 100644 --- a/subprojects/fmt.wrap +++ b/subprojects/fmt.wrap @@ -5,6 +5,6 @@ source_url = https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz source_filename = fmt-5.3.0.tar.gz source_hash = defa24a9af4c622a7134076602070b45721a43c51598c8456ec6f2c4dbb51c89 -patch_url = https://wrapdb.mesonbuild.com/v1/projects/fmt/5.3.0/1/get_zip +patch_url = https://github.com/mesonbuild/fmt/releases/download/5.3.0-1/fmt.zip patch_filename = fmt-5.3.0-1-wrap.zip patch_hash = 18f21a3b8833949c35d4ac88a7059577d5fa24b98786e4b1b2d3d81bb811440f \ No newline at end of file diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap index 9dac4d8d..750036b9 100644 --- a/subprojects/spdlog.wrap +++ b/subprojects/spdlog.wrap @@ -5,6 +5,6 @@ source_url = https://github.com/gabime/spdlog/archive/v1.3.1.tar.gz source_filename = v1.3.1.tar.gz source_hash = 160845266e94db1d4922ef755637f6901266731c4cb3b30b45bf41efa0e6ab70 -patch_url = https://wrapdb.mesonbuild.com/v1/projects/spdlog/1.3.1/1/get_zip +patch_url = https://github.com/mesonbuild/spdlog/releases/download/1.3.1-1/spdlog.zip patch_filename = spdlog-1.3.1-1-wrap.zip patch_hash = 715a0229781019b853d409cc0bf891ee4b9d3a17bec0cf87f4ad30b28bbecc87 From 3130a57622ce173f43475487a9a5314694442f1b Mon Sep 17 00:00:00 2001 From: Michael Cordover Date: Mon, 20 Jan 2020 18:47:15 -0500 Subject: [PATCH 054/100] Add timezone support to clock module (closes #223) --- man/waybar-clock.5.scd | 5 +++++ meson.build | 6 +++++- resources/config | 1 + src/modules/clock.cpp | 32 +++++++++++++++++++++++++++++--- subprojects/date.wrap | 9 +++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 subprojects/date.wrap diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index 959ec94b..9f79f88a 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -20,6 +20,11 @@ The *clock* module displays the current date and time. default: {:%H:%M} ++ The format, how the date and time should be displayed. +*timezone*: ++ + typeof: string ++ + default: inferred local timezone ++ + The timezone to display the time in, e.g. America/New_York. + *max-length*: ++ typeof: integer ++ The maximum length in character the module should display. diff --git a/meson.build b/meson.build index a099ad2b..61f6b4c2 100644 --- a/meson.build +++ b/meson.build @@ -66,6 +66,8 @@ gtk_layer_shell = dependency('gtk-layer-shell-0', required: get_option('gtk-layer-shell'), fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) +date_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'date_dep' ]) +tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ]) prefix = get_option('prefix') conf_data = configuration_data() @@ -166,7 +168,9 @@ executable( libpulse, libudev, libmpdclient, - gtk_layer_shell + gtk_layer_shell, + date_dep, + tz_dep ], include_directories: [include_directories('include')], install: true, diff --git a/resources/config b/resources/config index 4e392399..8dfa012b 100644 --- a/resources/config +++ b/resources/config @@ -64,6 +64,7 @@ "spacing": 10 }, "clock": { + // "timezone": "America/New_York", "tooltip-format": "{:%Y-%m-%d | %H:%M}", "format-alt": "{:%Y-%m-%d}" }, diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 2fa02142..d910b2b3 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,5 +1,5 @@ #include "modules/clock.hpp" -#include +#include waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) : ALabel(config, "clock", id, "{:%H:%M}", 60) { @@ -14,8 +14,14 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) auto waybar::modules::Clock::update() -> void { tzset(); // Update timezone information - auto now = std::chrono::system_clock::now(); - auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); + const date::time_zone* zone; + auto now = std::chrono::floor(std::chrono::system_clock::now()); + if (config_["timezone"].isString()) { + zone = date::locate_zone(config_["timezone"].asString()); + } else { + zone = date::current_zone(); + } + auto localtime = date::make_zoned(zone, now); auto text = fmt::format(format_, localtime); label_.set_markup(text); @@ -29,3 +35,23 @@ auto waybar::modules::Clock::update() -> void { } } } + +template +struct fmt::formatter> { + + std::string *format_string; + + constexpr auto parse(format_parse_context& ctx) { + format_string = new std::string[1]; + auto it = ctx.begin(), end = ctx.end(); + while (it != (end - 1)) { + *format_string += *it++; + } + return it; + } + + template + auto format(const date::zoned_time& d, FormatContext& ctx) { + return format_to(ctx.out(), "{}", date::format(*format_string, d)); + } +}; diff --git a/subprojects/date.wrap b/subprojects/date.wrap new file mode 100644 index 00000000..727bfddf --- /dev/null +++ b/subprojects/date.wrap @@ -0,0 +1,9 @@ +[wrap-file] +source_url=https://github.com/HowardHinnant/date/archive/v2.4.1.tar.gz +source_filename=date-2.4.1.tar.gz +source_hash=98907d243397483bd7ad889bf6c66746db0d7d2a39cc9aacc041834c40b65b98 +directory=date-2.4.1 + +patch_url = https://wrapdb.mesonbuild.com/v1/projects/hinnant-date/2.4.1/1/get_zip +patch_filename = hinnant-date-2.4.1-1-wrap.zip +patch_hash = 2061673a6f8e6d63c3a40df4da58fa2b3de2835fd9b3e74649e8279599f3a8f6 From 6e30b7af3c233cf18fb514ca4e1572fec94e7db8 Mon Sep 17 00:00:00 2001 From: Michael Cordover Date: Tue, 21 Jan 2020 09:36:41 -0500 Subject: [PATCH 055/100] Remove duplicate dependency, use current locale --- include/modules/clock.hpp | 1 + meson.build | 2 -- src/modules/clock.cpp | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index aa9a0a22..a10f96a6 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -6,6 +6,7 @@ #else #include #endif +#include #include "ALabel.hpp" #include "util/sleeper_thread.hpp" diff --git a/meson.build b/meson.build index 61f6b4c2..69439aca 100644 --- a/meson.build +++ b/meson.build @@ -66,7 +66,6 @@ gtk_layer_shell = dependency('gtk-layer-shell-0', required: get_option('gtk-layer-shell'), fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) -date_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'date_dep' ]) tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ]) prefix = get_option('prefix') @@ -169,7 +168,6 @@ executable( libudev, libmpdclient, gtk_layer_shell, - date_dep, tz_dep ], include_directories: [include_directories('include')], diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index d910b2b3..1ad29a3d 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,5 +1,4 @@ #include "modules/clock.hpp" -#include waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) : ALabel(config, "clock", id, "{:%H:%M}", 60) { @@ -52,6 +51,6 @@ struct fmt::formatter> { template auto format(const date::zoned_time& d, FormatContext& ctx) { - return format_to(ctx.out(), "{}", date::format(*format_string, d)); + return format_to(ctx.out(), "{}", date::format(std::locale(""), *format_string, d)); } }; From 84b671f6b27090fc1d77e277a73b52e05aa4d867 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Tue, 21 Jan 2020 23:48:16 +0100 Subject: [PATCH 056/100] Attempt at supporting locale and timezones (#1) --- include/modules/clock.hpp | 3 ++ man/waybar-clock.5.scd | 8 +++++- src/modules/clock.cpp | 60 +++++++++++++++++++++------------------ 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index a10f96a6..e54f4d2c 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -20,6 +20,9 @@ class Clock : public ALabel { private: util::SleeperThread thread_; + std::locale locale_; + const date::time_zone* time_zone_; + bool fixed_time_zone_; }; } // namespace waybar::modules diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index 9f79f88a..e3213f39 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -18,13 +18,19 @@ The *clock* module displays the current date and time. *format*: ++ typeof: string ++ default: {:%H:%M} ++ - The format, how the date and time should be displayed. + The format, how the date and time should be displayed. ++ + It uses the format of the date library. See https://howardhinnant.github.io/date/date.html#to_stream_formatting for details. *timezone*: ++ typeof: string ++ default: inferred local timezone ++ The timezone to display the time in, e.g. America/New_York. +*locale*: ++ + typeof: string ++ + default: inferred from current locale ++ + A locale to be used to display the time. Intended to render times in custom timezones with the proper language and format. + *max-length*: ++ typeof: integer ++ The maximum length in character the module should display. diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 1ad29a3d..38af1152 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,7 +1,20 @@ #include "modules/clock.hpp" waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) - : ALabel(config, "clock", id, "{:%H:%M}", 60) { + : ALabel(config, "clock", id, "{:%H:%M}", 60) + , fixed_time_zone_(false) +{ + if (config_["timezone"].isString()) { + time_zone_ = date::locate_zone(config_["timezone"].asString()); + fixed_time_zone_ = true; + } + + if (config_["locale"].isString()) { + locale_ = std::locale(config_["locale"].asString()); + } else { + locale_ = std::locale(""); + } + thread_ = [this] { dp.emit(); auto now = std::chrono::system_clock::now(); @@ -11,23 +24,28 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) }; } +using zoned_time = date::zoned_time; + +struct waybar_time { + std::locale locale; + zoned_time ztime; +}; + auto waybar::modules::Clock::update() -> void { - tzset(); // Update timezone information - const date::time_zone* zone; - auto now = std::chrono::floor(std::chrono::system_clock::now()); - if (config_["timezone"].isString()) { - zone = date::locate_zone(config_["timezone"].asString()); - } else { - zone = date::current_zone(); + if (!fixed_time_zone_) { + // Time zone can change. Be sure to pick that. + time_zone_ = date::current_zone(); } - auto localtime = date::make_zoned(zone, now); - auto text = fmt::format(format_, localtime); + auto now = std::chrono::system_clock::now(); + waybar_time wtime = {locale_, date::make_zoned(time_zone_, now)}; + + auto text = fmt::format(format_, wtime); label_.set_markup(text); if (tooltipEnabled()) { if (config_["tooltip-format"].isString()) { auto tooltip_format = config_["tooltip-format"].asString(); - auto tooltip_text = fmt::format(tooltip_format, localtime); + auto tooltip_text = fmt::format(tooltip_format, wtime); label_.set_tooltip_text(tooltip_text); } else { label_.set_tooltip_text(text); @@ -35,22 +53,10 @@ auto waybar::modules::Clock::update() -> void { } } -template -struct fmt::formatter> { - - std::string *format_string; - - constexpr auto parse(format_parse_context& ctx) { - format_string = new std::string[1]; - auto it = ctx.begin(), end = ctx.end(); - while (it != (end - 1)) { - *format_string += *it++; - } - return it; - } - +template <> +struct fmt::formatter : fmt::formatter { template - auto format(const date::zoned_time& d, FormatContext& ctx) { - return format_to(ctx.out(), "{}", date::format(std::locale(""), *format_string, d)); + auto format(const waybar_time& t, FormatContext& ctx) { + return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(tm_format), t.ztime)); } }; From 1e969a48ae74e5c8f8a45a89295c1be44c6312ad Mon Sep 17 00:00:00 2001 From: Michael Cordover Date: Thu, 23 Jan 2020 08:25:53 -0500 Subject: [PATCH 057/100] Use github instead of mesonbuild for hinnant-date patch --- subprojects/date.wrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/date.wrap b/subprojects/date.wrap index 727bfddf..ea73f0fa 100644 --- a/subprojects/date.wrap +++ b/subprojects/date.wrap @@ -4,6 +4,6 @@ source_filename=date-2.4.1.tar.gz source_hash=98907d243397483bd7ad889bf6c66746db0d7d2a39cc9aacc041834c40b65b98 directory=date-2.4.1 -patch_url = https://wrapdb.mesonbuild.com/v1/projects/hinnant-date/2.4.1/1/get_zip +patch_url = https://github.com/mesonbuild/hinnant-date/releases/download/2.4.1-1/hinnant-date.zip patch_filename = hinnant-date-2.4.1-1-wrap.zip patch_hash = 2061673a6f8e6d63c3a40df4da58fa2b3de2835fd9b3e74649e8279599f3a8f6 From 8e05aab4d9564c0f5e9deccbd99baae5ac751466 Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Fri, 31 Jan 2020 08:54:41 -0800 Subject: [PATCH 058/100] Current month calendar in clock tooltip. --- man/waybar-clock.5.scd | 4 ++ meson.build | 4 +- resources/config | 2 +- src/modules/clock.cpp | 96 ++++++++++++++++++++++++++++++++++++----- subprojects/utfcpp.wrap | 9 ++++ 5 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 subprojects/utfcpp.wrap diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index e3213f39..6684d897 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -65,6 +65,10 @@ The *clock* module displays the current date and time. View all valid format options in *strftime(3)*. +# FORMAT REPLACEMENTS + +*{calendar}*: Current month calendar + # EXAMPLES ``` diff --git a/meson.build b/meson.build index 69439aca..812cc428 100644 --- a/meson.build +++ b/meson.build @@ -67,6 +67,7 @@ gtk_layer_shell = dependency('gtk-layer-shell-0', fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ]) +utfcpp = dependency('utfcpp', fallback: [ 'utfcpp', 'utfcpp_dep' ]) prefix = get_option('prefix') conf_data = configuration_data() @@ -168,7 +169,8 @@ executable( libudev, libmpdclient, gtk_layer_shell, - tz_dep + tz_dep, + utfcpp ], include_directories: [include_directories('include')], install: true, diff --git a/resources/config b/resources/config index 8dfa012b..116d377e 100644 --- a/resources/config +++ b/resources/config @@ -65,7 +65,7 @@ }, "clock": { // "timezone": "America/New_York", - "tooltip-format": "{:%Y-%m-%d | %H:%M}", + "tooltip-format": "{:%Y %B}\n{calendar}", "format-alt": "{:%Y-%m-%d}" }, "cpu": { diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 38af1152..f9181378 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,4 +1,86 @@ #include "modules/clock.hpp" +#include +#include + +using zoned_time = date::zoned_time; + +struct waybar_time { + std::locale locale; + zoned_time ztime; +}; + +namespace { + +size_t utf8_strlen(const std::string& s) { + return utf8::distance(s.begin(), s.end()); +} + +std::string utf8_substr(const std::string s, size_t len) { + utf8::iterator it(s.begin(), s.begin(), s.end()); + for (size_t i = 0; i < len; ++i) { + ++it; + } + int byte_count = it.base() - s.begin(); + return s.substr(0, byte_count); +} + +void weekdays_header(const std::locale& locale, const date::weekday& first_dow, std::ostream& os) { + auto wd = first_dow; + do { + if (wd != first_dow) os << ' '; + auto wd_string = date::format(locale, "%a", wd); + auto wd_string_len = utf8_strlen(wd_string); + if (wd_string_len > 2) { + wd_string = utf8_substr(wd_string, 2); + wd_string_len = 2; + } + const std::string pad(2 - wd_string_len, ' '); + os << pad << wd_string; + } while (++wd != first_dow); + os << "\n"; +} + +std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) { + const auto daypoint = date::floor(wtime.ztime.get_local_time()); + const auto ymd = date::year_month_day(daypoint); + const date::year_month ym(ymd.year(), ymd.month()); + const auto curr_day = ymd.day(); + + std::stringstream os; + weekdays_header(wtime.locale, first_dow, os); + + // First week prefixed with spaces if needed. + auto wd = date::weekday(ym/1); + auto empty_days = (wd - first_dow).count(); + if (empty_days > 0) { + os << std::string(empty_days * 3 - 1, ' '); + } + auto d = date::day(1); + do { + if (wd != first_dow) os << ' '; + if (d == curr_day) { + os << "" << date::format("%e", d) << ""; + } else { + os << date::format("%e", d); + } + ++d; + } while (++wd != first_dow); + + // Following weeks. + auto last_day = (ym/date::literals::last).day(); + for ( ; d <= last_day; ++d, ++wd) { + os << ((wd == first_dow) ? '\n' : ' '); + if (d == curr_day) { + os << "" << date::format("%e", d) << ""; + } else { + os << date::format("%e", d); + } + } + + return os.str(); +} + +} waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) : ALabel(config, "clock", id, "{:%H:%M}", 60) @@ -24,13 +106,6 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) }; } -using zoned_time = date::zoned_time; - -struct waybar_time { - std::locale locale; - zoned_time ztime; -}; - auto waybar::modules::Clock::update() -> void { if (!fixed_time_zone_) { // Time zone can change. Be sure to pick that. @@ -44,11 +119,12 @@ auto waybar::modules::Clock::update() -> void { if (tooltipEnabled()) { if (config_["tooltip-format"].isString()) { + const auto calendar = calendar_text(wtime, date::Sunday); auto tooltip_format = config_["tooltip-format"].asString(); - auto tooltip_text = fmt::format(tooltip_format, wtime); - label_.set_tooltip_text(tooltip_text); + auto tooltip_text = fmt::format(tooltip_format, wtime, fmt::arg("calendar", calendar)); + label_.set_tooltip_markup(tooltip_text); } else { - label_.set_tooltip_text(text); + label_.set_tooltip_markup(text); } } } diff --git a/subprojects/utfcpp.wrap b/subprojects/utfcpp.wrap new file mode 100644 index 00000000..51cf131b --- /dev/null +++ b/subprojects/utfcpp.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = utfcpp-2.3.5 +source_url = https://github.com/nemtrif/utfcpp/archive/v2.3.5.zip +source_filename = utfcpp-2.3.5.zip +source_hash = 1d5cb7d908202d734ec35b84087400013f352ffb4612e978ffb948986b76df14 + +patch_url = https://github.com/mesonbuild/utfcpp/releases/download/2.3.5-1/utfcpp.zip +patch_filename = utfcpp-2.3.5-1-wrap.zip +patch_hash = 5f504de947b34bb5995fcdb66a1ea1392288076a9400ead829da79e73441a13f From 527fa982d232eed3a22c1d6c5d707a0c57a7c708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=BChrk?= Date: Fri, 31 Jan 2020 22:47:26 +0100 Subject: [PATCH 059/100] pulseaudio: adapt icon names to form factors --- src/modules/pulseaudio.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index eb05b8c7..7f02be87 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -176,11 +176,11 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context, const pa_ser } static const std::array ports = { - "headphones", + "headphone", "speaker", "hdmi", "headset", - "handsfree", + "hands-free", "portable", "car", "hifi", From ea9591baea2e661829a7509ad51c681dc4925dff Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Sun, 2 Feb 2020 14:35:07 -0800 Subject: [PATCH 060/100] Switch from utfcpp to Glib::ustring for UTF-8 string mangling. --- meson.build | 4 +--- src/modules/clock.cpp | 28 +++++++--------------------- subprojects/utfcpp.wrap | 9 --------- 3 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 subprojects/utfcpp.wrap diff --git a/meson.build b/meson.build index 812cc428..69439aca 100644 --- a/meson.build +++ b/meson.build @@ -67,7 +67,6 @@ gtk_layer_shell = dependency('gtk-layer-shell-0', fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep']) systemd = dependency('systemd', required: get_option('systemd')) tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ]) -utfcpp = dependency('utfcpp', fallback: [ 'utfcpp', 'utfcpp_dep' ]) prefix = get_option('prefix') conf_data = configuration_data() @@ -169,8 +168,7 @@ executable( libudev, libmpdclient, gtk_layer_shell, - tz_dep, - utfcpp + tz_dep ], include_directories: [include_directories('include')], install: true, diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index f9181378..5efca403 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,6 +1,5 @@ #include "modules/clock.hpp" #include -#include using zoned_time = date::zoned_time; @@ -11,31 +10,18 @@ struct waybar_time { namespace { -size_t utf8_strlen(const std::string& s) { - return utf8::distance(s.begin(), s.end()); -} - -std::string utf8_substr(const std::string s, size_t len) { - utf8::iterator it(s.begin(), s.begin(), s.end()); - for (size_t i = 0; i < len; ++i) { - ++it; - } - int byte_count = it.base() - s.begin(); - return s.substr(0, byte_count); -} - void weekdays_header(const std::locale& locale, const date::weekday& first_dow, std::ostream& os) { auto wd = first_dow; do { if (wd != first_dow) os << ' '; - auto wd_string = date::format(locale, "%a", wd); - auto wd_string_len = utf8_strlen(wd_string); - if (wd_string_len > 2) { - wd_string = utf8_substr(wd_string, 2); - wd_string_len = 2; + Glib::ustring wd_ustring(date::format(locale, "%a", wd)); + auto wd_len = wd_ustring.length(); + if (wd_len > 2) { + wd_ustring = wd_ustring.substr(0, 2); + wd_len = 2; } - const std::string pad(2 - wd_string_len, ' '); - os << pad << wd_string; + const std::string pad(2 - wd_len, ' '); + os << pad << wd_ustring; } while (++wd != first_dow); os << "\n"; } diff --git a/subprojects/utfcpp.wrap b/subprojects/utfcpp.wrap deleted file mode 100644 index 51cf131b..00000000 --- a/subprojects/utfcpp.wrap +++ /dev/null @@ -1,9 +0,0 @@ -[wrap-file] -directory = utfcpp-2.3.5 -source_url = https://github.com/nemtrif/utfcpp/archive/v2.3.5.zip -source_filename = utfcpp-2.3.5.zip -source_hash = 1d5cb7d908202d734ec35b84087400013f352ffb4612e978ffb948986b76df14 - -patch_url = https://github.com/mesonbuild/utfcpp/releases/download/2.3.5-1/utfcpp.zip -patch_filename = utfcpp-2.3.5-1-wrap.zip -patch_hash = 5f504de947b34bb5995fcdb66a1ea1392288076a9400ead829da79e73441a13f From f6b200568742cbd94dc8cac17e7ac6728cc82008 Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Sun, 2 Feb 2020 14:44:26 -0800 Subject: [PATCH 061/100] Cache calendar tooltip text to reduce computations. --- src/modules/clock.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5efca403..e7193539 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,4 +1,5 @@ #include "modules/clock.hpp" +#include #include using zoned_time = date::zoned_time; @@ -26,9 +27,28 @@ void weekdays_header(const std::locale& locale, const date::weekday& first_dow, os << "\n"; } +struct CachedCalendar { + date::year_month_day ymd; + std::string text; + + void set(const date::year_month_day& ymd_, std::string text_) { + ymd = ymd_; + text = text_; + } +}; + +std::mutex cached_calendar_mutex; // protects cached_calendar. +CachedCalendar cached_calendar; + std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) { const auto daypoint = date::floor(wtime.ztime.get_local_time()); const auto ymd = date::year_month_day(daypoint); + + const std::lock_guard lock(cached_calendar_mutex); + if (cached_calendar.ymd == ymd) { + return cached_calendar.text; + } + const date::year_month ym(ymd.year(), ymd.month()); const auto curr_day = ymd.day(); @@ -63,7 +83,9 @@ std::string calendar_text(const waybar_time& wtime, const date::weekday& first_d } } - return os.str(); + auto result = os.str(); + cached_calendar.set(ymd, result); + return result; } } From 218bb3bc2bb607b5c2978696d24ddf3f32203454 Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Sun, 2 Feb 2020 14:55:37 -0800 Subject: [PATCH 062/100] Simpify calendar generation, single loop handles both first week and subsequent weeks. --- src/modules/clock.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index e7193539..134288ce 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -61,21 +61,13 @@ std::string calendar_text(const waybar_time& wtime, const date::weekday& first_d if (empty_days > 0) { os << std::string(empty_days * 3 - 1, ' '); } - auto d = date::day(1); - do { - if (wd != first_dow) os << ' '; - if (d == curr_day) { - os << "" << date::format("%e", d) << ""; - } else { - os << date::format("%e", d); - } - ++d; - } while (++wd != first_dow); - - // Following weeks. auto last_day = (ym/date::literals::last).day(); - for ( ; d <= last_day; ++d, ++wd) { - os << ((wd == first_dow) ? '\n' : ' '); + for (auto d = date::day(1); d <= last_day; ++d, ++wd) { + if (wd != first_dow) { + os << ' '; + } else if (unsigned(d) != 1) { + os << '\n'; + } if (d == curr_day) { os << "" << date::format("%e", d) << ""; } else { From 34a710cce3d51ff055bd3f272564e356e07ad172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20Huseb=C3=B8?= Date: Mon, 3 Feb 2020 10:40:26 +0100 Subject: [PATCH 063/100] Fix typos --- man/waybar-temperature.5.scd | 8 ++++---- resources/custom_modules/mediaplayer.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 437cd29d..f8676867 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -22,7 +22,7 @@ Addressed by *temperature* *critical-threshold*: ++ typeof: integer ++ - The threshold before it is considered critical (Celcius). + The threshold before it is considered critical (Celsius). *interval*: ++ typeof: integer ++ @@ -36,11 +36,11 @@ Addressed by *temperature* *format*: ++ typeof: string ++ default: {temperatureC}°C ++ - The format (Celcius/Farenheit) in which the temperature should be displayed. + The format (Celsius/Fahrenheit) in which the temperature should be displayed. *format-icons*: ++ typeof: array ++ - Based on the current temperature (Celcius) and *critical-threshold* if available, the corresponding icon gets selected. The order is *low* to *high*. + Based on the current temperature (Celsius) and *critical-threshold* if available, the corresponding icon gets selected. The order is *low* to *high*. *rotate*: ++ typeof: integer ++ @@ -81,7 +81,7 @@ Addressed by *temperature* # FORMAT REPLACEMENTS -*{temperatureC}*: Temperature in Celcius. +*{temperatureC}*: Temperature in Celsius. *{temperatureF}*: Temperature in Fahrenheit. diff --git a/resources/custom_modules/mediaplayer.py b/resources/custom_modules/mediaplayer.py index 7404f48f..cf3df4b6 100755 --- a/resources/custom_modules/mediaplayer.py +++ b/resources/custom_modules/mediaplayer.py @@ -79,7 +79,7 @@ def signal_handler(sig, frame): def parse_arguments(): parser = argparse.ArgumentParser() - # Increase verbosity with every occurance of -v + # Increase verbosity with every occurence of -v parser.add_argument('-v', '--verbose', action='count', default=0) # Define for which player we're listening From 4c40f9c6351fc7ef18efff290879b81b680caaf6 Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Mon, 3 Feb 2020 16:19:32 -0800 Subject: [PATCH 064/100] Stop using a mutex for guarding CachedCalendar. --- src/modules/clock.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 134288ce..ef79274e 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,5 +1,4 @@ #include "modules/clock.hpp" -#include #include using zoned_time = date::zoned_time; @@ -37,14 +36,11 @@ struct CachedCalendar { } }; -std::mutex cached_calendar_mutex; // protects cached_calendar. CachedCalendar cached_calendar; std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) { const auto daypoint = date::floor(wtime.ztime.get_local_time()); const auto ymd = date::year_month_day(daypoint); - - const std::lock_guard lock(cached_calendar_mutex); if (cached_calendar.ymd == ymd) { return cached_calendar.text; } From cd2db19267214ca2422b5ecd07d7eb99d049132e Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Mon, 3 Feb 2020 16:58:18 -0800 Subject: [PATCH 065/100] Detect presence, call nl_langinfo() to get first day of week. --- meson.build | 12 ++++++++++++ src/modules/clock.cpp | 23 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 69439aca..98dd25e8 100644 --- a/meson.build +++ b/meson.build @@ -42,6 +42,18 @@ if not compiler.has_header('filesystem') endif endif +code = '''#include +int main(int argc, char** argv) { + char* str; + str = nl_langinfo(_NL_TIME_WEEK_1STDAY); + str = nl_langinfo(_NL_TIME_FIRST_WEEKDAY); + return 0; +} +''' +if compiler.links(code, name : 'nl_langinfo with _NL_TIME_WEEK_1STDAY, _NL_TIME_FIRST_WEEKDAY') + add_project_arguments('-DHAVE_LANGINFO_1STDAY', language: 'cpp') +endif + add_global_arguments(cpp_args, language : 'cpp') add_global_link_arguments(cpp_link_args, language : 'cpp') diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index ef79274e..8419d18b 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,5 +1,8 @@ #include "modules/clock.hpp" #include +#ifdef HAVE_LANGINFO_1STDAY +#include +#endif using zoned_time = date::zoned_time; @@ -10,6 +13,17 @@ struct waybar_time { namespace { +#ifdef HAVE_LANGINFO_1STDAY +// Computations done similarly to Linux cal utility. +date::weekday first_day_of_week() { + const int i = (std::intptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); + auto ymd = date::year(i / 10000)/(i / 100 % 100)/(i % 100); + auto wd = date::weekday(ymd); + uint8_t j = *nl_langinfo(_NL_TIME_FIRST_WEEKDAY); + return wd + date::days(j - 1); +} +#endif + void weekdays_header(const std::locale& locale, const date::weekday& first_dow, std::ostream& os) { auto wd = first_dow; do { @@ -38,7 +52,7 @@ struct CachedCalendar { CachedCalendar cached_calendar; -std::string calendar_text(const waybar_time& wtime, const date::weekday& first_dow) { +std::string calendar_text(const waybar_time& wtime) { const auto daypoint = date::floor(wtime.ztime.get_local_time()); const auto ymd = date::year_month_day(daypoint); if (cached_calendar.ymd == ymd) { @@ -49,6 +63,11 @@ std::string calendar_text(const waybar_time& wtime, const date::weekday& first_d const auto curr_day = ymd.day(); std::stringstream os; +#ifdef HAVE_LANGINFO_1STDAY + const auto first_dow = first_day_of_week(); +#else + const auto first_dow = date::Sunday; +#endif weekdays_header(wtime.locale, first_dow, os); // First week prefixed with spaces if needed. @@ -115,7 +134,7 @@ auto waybar::modules::Clock::update() -> void { if (tooltipEnabled()) { if (config_["tooltip-format"].isString()) { - const auto calendar = calendar_text(wtime, date::Sunday); + const auto calendar = calendar_text(wtime); auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_text = fmt::format(tooltip_format, wtime, fmt::arg("calendar", calendar)); label_.set_tooltip_markup(tooltip_text); From f107aaddc394b7f757c1f271e604adb35aa47639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torstein=20Huseb=C3=B8?= Date: Tue, 4 Feb 2020 12:16:50 +0100 Subject: [PATCH 066/100] Finish #571 --- man/waybar-pulseaudio.5.scd | 5 +++-- resources/config | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index 7640c706..487888a4 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -100,16 +100,17 @@ The following strings for *format-icons* are supported. If they are found in the current PulseAudio port name, the corresponding icons will be selected. - *default* (Shown, when no other port is found) -- *headphones* +- *headphone* - *speaker* - *hdmi* - *headset* -- *handsfree* +- *hands-free* - *portable* - *car* - *hifi* - *phone* + # EXAMPLES ``` diff --git a/resources/config b/resources/config index 8dfa012b..fcc365e2 100644 --- a/resources/config +++ b/resources/config @@ -122,8 +122,8 @@ "format-source": "{volume}% ", "format-source-muted": "", "format-icons": { - "headphones": "", - "handsfree": "", + "headphone": "", + "hands-free": "", "headset": "", "phone": "", "portable": "", From ae6ca36fa74802f487c3b45c8ff32c571ec36833 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 27 Aug 2019 19:43:03 -0700 Subject: [PATCH 067/100] fix(sway): resolve destruction dependency between Ipc and SleeperThread Ipc destructor closes socket and thus wakes up SleeperThread which was waiting for socket data in Ipc::handleEvent. Ipc::handleEvent then proceeds with sending signal to already destroyed object, causing heap-use-after-free Address Sanitizer error. --- include/modules/sway/ipc/client.hpp | 9 ++++++--- include/modules/sway/mode.hpp | 6 +----- include/modules/sway/window.hpp | 6 +----- include/modules/sway/workspaces.hpp | 6 +----- src/modules/sway/ipc/client.cpp | 10 +++++++--- src/modules/sway/mode.cpp | 18 +++++++----------- src/modules/sway/window.cpp | 18 +++++++----------- src/modules/sway/workspaces.cpp | 18 +++++++----------- 8 files changed, 37 insertions(+), 54 deletions(-) diff --git a/include/modules/sway/ipc/client.hpp b/include/modules/sway/ipc/client.hpp index 629556f7..7df53629 100644 --- a/include/modules/sway/ipc/client.hpp +++ b/include/modules/sway/ipc/client.hpp @@ -8,6 +8,7 @@ #include #include #include "ipc.hpp" +#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -28,6 +29,7 @@ class Ipc { void sendCmd(uint32_t type, const std::string &payload = ""); void subscribe(const std::string &payload); void handleEvent(); + void setWorker(std::function &&func); protected: static inline const std::string ipc_magic_ = "i3-ipc"; @@ -38,9 +40,10 @@ class Ipc { struct ipc_response send(int fd, uint32_t type, const std::string &payload = ""); struct ipc_response recv(int fd); - int fd_; - int fd_event_; - std::mutex mutex_; + int fd_; + int fd_event_; + std::mutex mutex_; + util::SleeperThread thread_; }; } // namespace waybar::modules::sway diff --git a/include/modules/sway/mode.hpp b/include/modules/sway/mode.hpp index f0cf74c1..a1a88b02 100644 --- a/include/modules/sway/mode.hpp +++ b/include/modules/sway/mode.hpp @@ -6,7 +6,6 @@ #include "client.hpp" #include "modules/sway/ipc/client.hpp" #include "util/json.hpp" -#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -18,14 +17,11 @@ class Mode : public ALabel, public sigc::trackable { private: void onEvent(const struct Ipc::ipc_response&); - void worker(); std::string mode_; util::JsonParser parser_; std::mutex mutex_; - - util::SleeperThread thread_; - Ipc ipc_; + Ipc ipc_; }; } // namespace waybar::modules::sway diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index 5bb129d7..40aaa1a0 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -7,7 +7,6 @@ #include "client.hpp" #include "modules/sway/ipc/client.hpp" #include "util/json.hpp" -#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -20,7 +19,6 @@ class Window : public ALabel, public sigc::trackable { private: void onEvent(const struct Ipc::ipc_response&); void onCmd(const struct Ipc::ipc_response&); - void worker(); std::tuple getFocusedNode(const Json::Value& nodes, std::string& output); void getTree(); @@ -33,9 +31,7 @@ class Window : public ALabel, public sigc::trackable { std::size_t app_nb_; util::JsonParser parser_; std::mutex mutex_; - - util::SleeperThread thread_; - Ipc ipc_; + Ipc ipc_; }; } // namespace waybar::modules::sway diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 498acc95..cd806125 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -8,7 +8,6 @@ #include "client.hpp" #include "modules/sway/ipc/client.hpp" #include "util/json.hpp" -#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -21,7 +20,6 @@ class Workspaces : public AModule, public sigc::trackable { private: void onCmd(const struct Ipc::ipc_response&); void onEvent(const struct Ipc::ipc_response&); - void worker(); bool filterButtons(); Gtk::Button& addButton(const Json::Value&); void onButtonReady(const Json::Value&, Gtk::Button&); @@ -38,9 +36,7 @@ class Workspaces : public AModule, public sigc::trackable { util::JsonParser parser_; std::unordered_map buttons_; std::mutex mutex_; - - util::SleeperThread thread_; - Ipc ipc_; + Ipc ipc_; }; } // namespace waybar::modules::sway diff --git a/src/modules/sway/ipc/client.cpp b/src/modules/sway/ipc/client.cpp index eae6c76e..58aed60c 100644 --- a/src/modules/sway/ipc/client.cpp +++ b/src/modules/sway/ipc/client.cpp @@ -10,19 +10,23 @@ Ipc::Ipc() { } Ipc::~Ipc() { - // To fail the IPC header - write(fd_, "close-sway-ipc", 14); - write(fd_event_, "close-sway-ipc", 14); + thread_.stop(); + if (fd_ > 0) { + // To fail the IPC header + write(fd_, "close-sway-ipc", 14); close(fd_); fd_ = -1; } if (fd_event_ > 0) { + write(fd_event_, "close-sway-ipc", 14); close(fd_event_); fd_event_ = -1; } } +void Ipc::setWorker(std::function&& func) { thread_ = func; } + const std::string Ipc::getSocketPath() const { const char* env = getenv("SWAYSOCK"); if (env != nullptr) { diff --git a/src/modules/sway/mode.cpp b/src/modules/sway/mode.cpp index cd02c0ca..632709d0 100644 --- a/src/modules/sway/mode.cpp +++ b/src/modules/sway/mode.cpp @@ -8,7 +8,13 @@ Mode::Mode(const std::string& id, const Json::Value& config) ipc_.subscribe(R"(["mode"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent)); // Launch worker - worker(); + ipc_.setWorker([this] { + try { + ipc_.handleEvent(); + } catch (const std::exception& e) { + spdlog::error("Mode: {}", e.what()); + } + }); dp.emit(); } @@ -31,16 +37,6 @@ void Mode::onEvent(const struct Ipc::ipc_response& res) { } } -void Mode::worker() { - thread_ = [this] { - try { - ipc_.handleEvent(); - } catch (const std::exception& e) { - spdlog::error("Mode: {}", e.what()); - } - }; -} - auto Mode::update() -> void { if (mode_.empty()) { event_box_.hide(); diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 2e4ec468..c139180a 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -11,7 +11,13 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) // Get Initial focused window getTree(); // Launch worker - worker(); + ipc_.setWorker([this] { + try { + ipc_.handleEvent(); + } catch (const std::exception& e) { + spdlog::error("Window: {}", e.what()); + } + }); } void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); } @@ -28,16 +34,6 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { } } -void Window::worker() { - thread_ = [this] { - try { - ipc_.handleEvent(); - } catch (const std::exception& e) { - spdlog::error("Window: {}", e.what()); - } - }; -} - auto Window::update() -> void { if (!old_app_id_.empty()) { bar_.window.get_style_context()->remove_class(old_app_id_); diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index b65e47db..fe87f5ea 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -22,7 +22,13 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll)); } // Launch worker - worker(); + ipc_.setWorker([this] { + try { + ipc_.handleEvent(); + } catch (const std::exception &e) { + spdlog::error("Workspaces: {}", e.what()); + } + }); } void Workspaces::onEvent(const struct Ipc::ipc_response &res) { @@ -102,16 +108,6 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { } } -void Workspaces::worker() { - thread_ = [this] { - try { - ipc_.handleEvent(); - } catch (const std::exception &e) { - spdlog::error("Workspaces: {}", e.what()); - } - }; -} - bool Workspaces::filterButtons() { bool needReorder = false; for (auto it = buttons_.begin(); it != buttons_.end();) { From d1f427618fbcdab4a11d84e6fde987f1b62c9bec Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Wed, 5 Feb 2020 11:02:42 -0800 Subject: [PATCH 068/100] Cache calendar per clock instance, weekdays properly handle locales. --- include/modules/clock.hpp | 11 +++ meson.build | 10 ++- src/modules/clock.cpp | 175 ++++++++++++++++++-------------------- 3 files changed, 101 insertions(+), 95 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index e54f4d2c..bb63241d 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -12,6 +12,11 @@ namespace waybar::modules { +struct waybar_time { + std::locale locale; + date::zoned_time ztime; +}; + class Clock : public ALabel { public: Clock(const std::string&, const Json::Value&); @@ -23,6 +28,12 @@ class Clock : public ALabel { std::locale locale_; const date::time_zone* time_zone_; bool fixed_time_zone_; + date::year_month_day cached_calendar_ymd_; + std::string cached_calendar_text_; + + auto calendar_text(const waybar_time& wtime) -> std::string; + auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void; + auto first_day_of_week() -> date::weekday; }; } // namespace waybar::modules diff --git a/meson.build b/meson.build index 98dd25e8..8cfe5d89 100644 --- a/meson.build +++ b/meson.build @@ -42,11 +42,15 @@ if not compiler.has_header('filesystem') endif endif -code = '''#include +code = ''' +#include +#include int main(int argc, char** argv) { + locale_t locale = newlocale(LC_ALL, "en_US.UTF-8", nullptr); char* str; - str = nl_langinfo(_NL_TIME_WEEK_1STDAY); - str = nl_langinfo(_NL_TIME_FIRST_WEEKDAY); + str = nl_langinfo_l(_NL_TIME_WEEK_1STDAY, locale); + str = nl_langinfo_l(_NL_TIME_FIRST_WEEKDAY, locale); + freelocale(locale); return 0; } ''' diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 8419d18b..5655168f 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -1,101 +1,12 @@ #include "modules/clock.hpp" #include +#include #ifdef HAVE_LANGINFO_1STDAY #include +#include #endif -using zoned_time = date::zoned_time; - -struct waybar_time { - std::locale locale; - zoned_time ztime; -}; - -namespace { - -#ifdef HAVE_LANGINFO_1STDAY -// Computations done similarly to Linux cal utility. -date::weekday first_day_of_week() { - const int i = (std::intptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); - auto ymd = date::year(i / 10000)/(i / 100 % 100)/(i % 100); - auto wd = date::weekday(ymd); - uint8_t j = *nl_langinfo(_NL_TIME_FIRST_WEEKDAY); - return wd + date::days(j - 1); -} -#endif - -void weekdays_header(const std::locale& locale, const date::weekday& first_dow, std::ostream& os) { - auto wd = first_dow; - do { - if (wd != first_dow) os << ' '; - Glib::ustring wd_ustring(date::format(locale, "%a", wd)); - auto wd_len = wd_ustring.length(); - if (wd_len > 2) { - wd_ustring = wd_ustring.substr(0, 2); - wd_len = 2; - } - const std::string pad(2 - wd_len, ' '); - os << pad << wd_ustring; - } while (++wd != first_dow); - os << "\n"; -} - -struct CachedCalendar { - date::year_month_day ymd; - std::string text; - - void set(const date::year_month_day& ymd_, std::string text_) { - ymd = ymd_; - text = text_; - } -}; - -CachedCalendar cached_calendar; - -std::string calendar_text(const waybar_time& wtime) { - const auto daypoint = date::floor(wtime.ztime.get_local_time()); - const auto ymd = date::year_month_day(daypoint); - if (cached_calendar.ymd == ymd) { - return cached_calendar.text; - } - - const date::year_month ym(ymd.year(), ymd.month()); - const auto curr_day = ymd.day(); - - std::stringstream os; -#ifdef HAVE_LANGINFO_1STDAY - const auto first_dow = first_day_of_week(); -#else - const auto first_dow = date::Sunday; -#endif - weekdays_header(wtime.locale, first_dow, os); - - // First week prefixed with spaces if needed. - auto wd = date::weekday(ym/1); - auto empty_days = (wd - first_dow).count(); - if (empty_days > 0) { - os << std::string(empty_days * 3 - 1, ' '); - } - auto last_day = (ym/date::literals::last).day(); - for (auto d = date::day(1); d <= last_day; ++d, ++wd) { - if (wd != first_dow) { - os << ' '; - } else if (unsigned(d) != 1) { - os << '\n'; - } - if (d == curr_day) { - os << "" << date::format("%e", d) << ""; - } else { - os << date::format("%e", d); - } - } - - auto result = os.str(); - cached_calendar.set(ymd, result); - return result; -} - -} +using waybar::modules::waybar_time; waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) : ALabel(config, "clock", id, "{:%H:%M}", 60) @@ -144,6 +55,86 @@ auto waybar::modules::Clock::update() -> void { } } +auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::string { + const auto daypoint = date::floor(wtime.ztime.get_local_time()); + const auto ymd = date::year_month_day(daypoint); + if (cached_calendar_ymd_ == ymd) { + return cached_calendar_text_; + } + + const date::year_month ym(ymd.year(), ymd.month()); + const auto curr_day = ymd.day(); + + std::stringstream os; + const auto first_dow = first_day_of_week(); + weekdays_header(first_dow, os); + + // First week prefixed with spaces if needed. + auto wd = date::weekday(ym/1); + auto empty_days = (wd - first_dow).count(); + if (empty_days > 0) { + os << std::string(empty_days * 3 - 1, ' '); + } + auto last_day = (ym/date::literals::last).day(); + for (auto d = date::day(1); d <= last_day; ++d, ++wd) { + if (wd != first_dow) { + os << ' '; + } else if (unsigned(d) != 1) { + os << '\n'; + } + if (d == curr_day) { + os << "" << date::format("%e", d) << ""; + } else { + os << date::format("%e", d); + } + } + + auto result = os.str(); + cached_calendar_ymd_ = ymd; + cached_calendar_text_ = result; + return result; +} + +auto waybar::modules::Clock::weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void { + auto wd = first_dow; + do { + if (wd != first_dow) os << ' '; + Glib::ustring wd_ustring(date::format(locale_, "%a", wd)); + auto wd_len = wd_ustring.length(); + if (wd_len > 2) { + wd_ustring = wd_ustring.substr(0, 2); + wd_len = 2; + } + const std::string pad(2 - wd_len, ' '); + os << pad << wd_ustring; + } while (++wd != first_dow); + os << "\n"; +} + +#ifdef HAVE_LANGINFO_1STDAY +template +using deleter_from_fn = std::integral_constant; + +template +using deleting_unique_ptr = std::unique_ptr>; +#endif + +// Computations done similarly to Linux cal utility. +auto waybar::modules::Clock::first_day_of_week() -> date::weekday { +#ifdef HAVE_LANGINFO_1STDAY + deleting_unique_ptr::type, freelocale> + posix_locale{newlocale(LC_ALL, locale_.name().c_str(), nullptr)}; + if (posix_locale) { + const int i = (std::intptr_t) nl_langinfo_l(_NL_TIME_WEEK_1STDAY, posix_locale.get()); + auto ymd = date::year(i / 10000)/(i / 100 % 100)/(i % 100); + auto wd = date::weekday(ymd); + uint8_t j = *nl_langinfo_l(_NL_TIME_FIRST_WEEKDAY, posix_locale.get()); + return wd + date::days(j - 1); + } +#endif + return date::Sunday; +} + template <> struct fmt::formatter : fmt::formatter { template From e70f8d87302d5ec0e0dfd40076a09183c41822fa Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Wed, 5 Feb 2020 00:51:56 -0800 Subject: [PATCH 069/100] fix(clock): lower precision of zoned_time to avoid fractional seconds in output --- include/modules/clock.hpp | 2 +- src/modules/clock.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index bb63241d..e3873a6d 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -14,7 +14,7 @@ namespace waybar::modules { struct waybar_time { std::locale locale; - date::zoned_time ztime; + date::zoned_seconds ztime; }; class Clock : public ALabel { diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5655168f..7fa0ad63 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -37,8 +37,9 @@ auto waybar::modules::Clock::update() -> void { // Time zone can change. Be sure to pick that. time_zone_ = date::current_zone(); } - auto now = std::chrono::system_clock::now(); - waybar_time wtime = {locale_, date::make_zoned(time_zone_, now)}; + auto now = std::chrono::system_clock::now(); + waybar_time wtime = {locale_, + date::make_zoned(time_zone_, date::floor(now))}; auto text = fmt::format(format_, wtime); label_.set_markup(text); From aae105c998ccec3b67d770b206f5d751719725ef Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Feb 2020 23:47:23 +0000 Subject: [PATCH 070/100] chore: 0.9.1 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8cfe5d89..d65ee6bd 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'waybar', 'cpp', 'c', - version: '0.9.0', + version: '0.9.1', license: 'MIT', default_options : [ 'cpp_std=c++17', From e0c42ae4151d77bb54c42fc871f0ca525d7916ce Mon Sep 17 00:00:00 2001 From: Danilo Spinella Date: Sun, 9 Feb 2020 16:58:42 +0100 Subject: [PATCH 071/100] fix(sway): add missing unordered_map include --- include/modules/sway/workspaces.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index cd806125..fef24bf9 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include From 16c68ee13279117e493d614088159525942bd0ac Mon Sep 17 00:00:00 2001 From: Danilo Spinella Date: Tue, 11 Feb 2020 14:38:05 +0100 Subject: [PATCH 072/100] fix(meson): Support libc++ >=9.0.0 From LLVM libc++ documentation: "Prior to LLVM 9.0, libc++ provides the implementation of the filesystem library in a separate static library." Now the filesystem library (not the experimental one) is shipped inside the libc++.so library. Check if '-lc++fs' link flag is needed and supported before adding it. --- meson.build | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index d65ee6bd..b8185c27 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,8 @@ project( ], ) +compiler = meson.get_compiler('cpp') + cpp_args = [] cpp_link_args = [] @@ -16,12 +18,13 @@ if get_option('libcxx') cpp_args += ['-stdlib=libc++'] cpp_link_args += ['-stdlib=libc++', '-lc++abi'] - cpp_link_args += ['-lc++fs'] + if compiler.has_link_argument('-lc++fs') + cpp_link_args += ['-lc++fs'] + endif else cpp_link_args += ['-lstdc++fs'] endif -compiler = meson.get_compiler('cpp') git = find_program('git', required: false) if not git.found() From 4f8a396692c7ade124a736f125b2bfdeaac3c827 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sat, 15 Feb 2020 16:51:18 +0000 Subject: [PATCH 073/100] Fix for 'Network label text not updated properly when formats contain Unicode characters' (#588) --- src/modules/network.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 43f29f67..cd675c8a 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -279,7 +279,7 @@ auto waybar::modules::Network::update() -> void { 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()) { + if (text.compare(label_.get_label()) != 0) { label_.set_markup(text); if (text.empty()) { event_box_.hide(); From 543589a97b7b949a4c75fe116f9dedc8011ae23d Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 16 Feb 2020 21:48:22 +0000 Subject: [PATCH 074/100] Update pulseaudio.cpp --- src/modules/pulseaudio.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 7f02be87..1c709d0e 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -200,21 +200,23 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const { auto waybar::modules::Pulseaudio::update() -> void { auto format = format_; - std::string format_name = "format"; - if (monitor_.find("a2dp_sink") != std::string::npos) { - format_name = format_name + "-bluetooth"; - label_.get_style_context()->add_class("bluetooth"); - } else { - label_.get_style_context()->remove_class("bluetooth"); + if (!alt_) { + std::string format_name = "format"; + if (monitor_.find("a2dp_sink") != std::string::npos) { + format_name = format_name + "-bluetooth"; + label_.get_style_context()->add_class("bluetooth"); + } else { + label_.get_style_context()->remove_class("bluetooth"); + } + if (muted_ ) { + format_name = format_name + "-muted"; + label_.get_style_context()->add_class("muted"); + } else { + label_.get_style_context()->remove_class("muted"); + } + format = + config_[format_name].isString() ? config_[format_name].asString() : format; } - if (muted_ ) { - format_name = format_name + "-muted"; - label_.get_style_context()->add_class("muted"); - } else { - label_.get_style_context()->remove_class("muted"); - } - format = - config_[format_name].isString() ? config_[format_name].asString() : format; // TODO: find a better way to split source/sink std::string format_source = "{volume}%"; if (source_muted_ && config_["format-source-muted"].isString()) { From 047c2929c115783f0fbd6c0169e64af8eb127c02 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Wed, 19 Feb 2020 12:06:35 +0100 Subject: [PATCH 075/100] Use the same StatusNotifierWatcher for all trays --- include/modules/sni/tray.hpp | 2 +- include/modules/sni/watcher.hpp | 17 +++++++++++++++-- src/modules/sni/tray.cpp | 2 +- src/modules/sni/watcher.cpp | 6 +++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/modules/sni/tray.hpp b/include/modules/sni/tray.hpp index e0aced1f..aaa1e4f9 100644 --- a/include/modules/sni/tray.hpp +++ b/include/modules/sni/tray.hpp @@ -21,7 +21,7 @@ class Tray : public AModule { static inline std::size_t nb_hosts_ = 0; Gtk::Box box_; - SNI::Watcher watcher_; + SNI::Watcher::singleton watcher_; SNI::Host host_; }; diff --git a/include/modules/sni/watcher.hpp b/include/modules/sni/watcher.hpp index 599380af..5a55d2d3 100644 --- a/include/modules/sni/watcher.hpp +++ b/include/modules/sni/watcher.hpp @@ -7,10 +7,24 @@ namespace waybar::modules::SNI { class Watcher { + private: + Watcher(); + public: - Watcher(std::size_t id); ~Watcher(); + using singleton = std::shared_ptr; + static singleton getInstance() { + static std::weak_ptr weak; + + std::shared_ptr strong = weak.lock(); + if (!strong) { + strong = std::shared_ptr(new Watcher()); + weak = strong; + } + return strong; + } + private: typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType; @@ -34,7 +48,6 @@ class Watcher { void updateRegisteredItems(SnWatcher *obj); uint32_t bus_name_id_; - uint32_t watcher_id_; GSList * hosts_ = nullptr; GSList * items_ = nullptr; SnWatcher *watcher_ = nullptr; diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index a698a979..e16837f5 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -6,7 +6,7 @@ namespace waybar::modules::SNI { Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) : AModule(config, "tray", id), box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), - watcher_(nb_hosts_), + watcher_(SNI::Watcher::getInstance()), host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1), std::bind(&Tray::onRemove, this, std::placeholders::_1)) { spdlog::warn( diff --git a/src/modules/sni/watcher.cpp b/src/modules/sni/watcher.cpp index 1db37088..73b3eaca 100644 --- a/src/modules/sni/watcher.cpp +++ b/src/modules/sni/watcher.cpp @@ -3,14 +3,13 @@ using namespace waybar::modules::SNI; -Watcher::Watcher(std::size_t id) +Watcher::Watcher() : bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, "org.kde.StatusNotifierWatcher", sigc::mem_fun(*this, &Watcher::busAcquired), Gio::DBus::SlotNameAcquired(), Gio::DBus::SlotNameLost(), Gio::DBus::BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | Gio::DBus::BUS_NAME_OWNER_FLAGS_REPLACE)), - watcher_id_(id), watcher_(sn_watcher_skeleton_new()) {} Watcher::~Watcher() { @@ -23,6 +22,7 @@ Watcher::~Watcher() { g_slist_free_full(items_, gfWatchFree); items_ = nullptr; } + Gio::DBus::unown_name(bus_name_id_); auto iface = G_DBUS_INTERFACE_SKELETON(watcher_); g_dbus_interface_skeleton_unexport(iface); } @@ -34,7 +34,7 @@ void Watcher::busAcquired(const Glib::RefPtr& conn, Glib: if (error != nullptr) { // Don't print an error when a watcher is already present if (error->code != 2) { - spdlog::error("Watcher {}: {}", watcher_id_, error->message); + spdlog::error("Watcher: {}", error->message); } g_error_free(error); return; From 9a5f5114c438e358a300f99ce0089489d61c11aa Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Wed, 19 Feb 2020 12:28:36 +0100 Subject: [PATCH 076/100] pulse: track default source/sink changes --- src/modules/pulseaudio.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 1c709d0e..46dc4266 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -52,7 +52,8 @@ void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data) { pa_context_set_subscribe_callback(c, subscribeCb, data); pa_context_subscribe( c, - static_cast(static_cast(PA_SUBSCRIPTION_MASK_SINK) | + static_cast(static_cast(PA_SUBSCRIPTION_MASK_SERVER) | + static_cast(PA_SUBSCRIPTION_MASK_SINK) | static_cast(PA_SUBSCRIPTION_MASK_SOURCE)), nullptr, nullptr); @@ -109,7 +110,9 @@ void waybar::modules::Pulseaudio::subscribeCb(pa_context * conte if (operation != PA_SUBSCRIPTION_EVENT_CHANGE) { return; } - if (facility == PA_SUBSCRIPTION_EVENT_SINK) { + if (facility == PA_SUBSCRIPTION_EVENT_SERVER) { + pa_context_get_server_info(context, serverInfoCb, data); + } else if (facility == PA_SUBSCRIPTION_EVENT_SINK) { pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data); } else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE) { pa_context_get_source_info_by_index(context, idx, sourceInfoCb, data); @@ -214,7 +217,7 @@ auto waybar::modules::Pulseaudio::update() -> void { } else { label_.get_style_context()->remove_class("muted"); } - format = + format = config_[format_name].isString() ? config_[format_name].asString() : format; } // TODO: find a better way to split source/sink From 190b2dd922ba30d92b3e4b3a09b81efeffcbde22 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Mon, 24 Feb 2020 11:30:35 +0100 Subject: [PATCH 077/100] pulseaudio: track only the default sink and source When you have multiple sinks (resp. sources), the module used to display the state of the most recently changed one. This changes remembers the default sink name, and only records changes to that one. --- include/modules/pulseaudio.hpp | 2 ++ src/modules/pulseaudio.cpp | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp index ba5a2aaf..541747c2 100644 --- a/include/modules/pulseaudio.hpp +++ b/include/modules/pulseaudio.hpp @@ -37,12 +37,14 @@ class Pulseaudio : public ALabel { std::string form_factor_; std::string desc_; std::string monitor_; + std::string default_sink_name_; // SOURCE uint32_t source_idx_{0}; uint16_t source_volume_; bool source_muted_; std::string source_port_name_; std::string source_desc_; + std::string default_source_name_; }; } // namespace waybar::modules diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 46dc4266..3e9a95ea 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -134,15 +134,15 @@ void waybar::modules::Pulseaudio::volumeModifyCb(pa_context *c, int success, voi */ void waybar::modules::Pulseaudio::sourceInfoCb(pa_context * /*context*/, const pa_source_info *i, int /*eol*/, void *data) { - if (i != nullptr) { - auto self = static_cast(data); + auto pa = static_cast(data); + if (i != nullptr && pa->default_source_name_ == i->name) { auto source_volume = static_cast(pa_cvolume_avg(&(i->volume))) / float{PA_VOLUME_NORM}; - self->source_volume_ = std::round(source_volume * 100.0F); - self->source_idx_ = i->index; - self->source_muted_ = i->mute != 0; - self->source_desc_ = i->description; - self->source_port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; - self->dp.emit(); + pa->source_volume_ = std::round(source_volume * 100.0F); + pa->source_idx_ = i->index; + pa->source_muted_ = i->mute != 0; + pa->source_desc_ = i->description; + pa->source_port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; + pa->dp.emit(); } } @@ -150,9 +150,9 @@ void waybar::modules::Pulseaudio::sourceInfoCb(pa_context * /*context*/, const p * Called when the requested sink information is ready. */ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, - int /*eol*/, void * data) { - if (i != nullptr) { - auto pa = static_cast(data); + int /*eol*/, void *data) { + auto pa = static_cast(data); + if (i != nullptr && pa->default_sink_name_ == i->name) { pa->pa_volume_ = i->volume; float volume = static_cast(pa_cvolume_avg(&(pa->pa_volume_))) / float{PA_VOLUME_NORM}; pa->sink_idx_ = i->index; @@ -174,6 +174,10 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_ */ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) { + auto pa = static_cast(data); + pa->default_sink_name_ = i->default_sink_name; + pa->default_source_name_ = i->default_source_name; + pa_context_get_sink_info_by_name(context, i->default_sink_name, sinkInfoCb, data); pa_context_get_source_info_by_name(context, i->default_source_name, sourceInfoCb, data); } From 03130b75654335ff31251c6dcca0a211b2bfa635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Tue, 3 Mar 2020 22:32:02 +0100 Subject: [PATCH 078/100] systemd service: fix start up ordering the service needs to have After=wayland-session.target otherwise it'll be started in parallel to the compositor which might not be fully configured --- resources/waybar.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/waybar.service.in b/resources/waybar.service.in index 1c086bfa..03262a33 100644 --- a/resources/waybar.service.in +++ b/resources/waybar.service.in @@ -2,6 +2,7 @@ Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. Documentation=https://github.com/Alexays/Waybar/wiki/ PartOf=wayland-session.target +After=wayland-session.target [Service] Type=dbus From dd0144c3cd285cc818fb31d239c7e759d6bef823 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Wed, 4 Mar 2020 06:47:12 -0800 Subject: [PATCH 079/100] fix(bar): set exclusive zone early for gtk-layer-shell If the bar is using initial size from the config (i.e both width and height are set and resize is not required), GtkWindow configure event is is not emitted. Initialize exclusive zone earlier for that case. Fixes #609 --- src/bar.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bar.cpp b/src/bar.cpp index 7b9e9307..431a5642 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -175,6 +175,11 @@ void waybar::Bar::initGtkLayerShell() { gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_RIGHT, margins_.right); gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_TOP, margins_.top); gtk_layer_set_margin(gtk_window, GTK_LAYER_SHELL_EDGE_BOTTOM, margins_.bottom); + + if (width_ > 1 && height_ > 1) { + /* configure events are not emitted if the bar is using initial size */ + setExclusiveZone(width_, height_); + } } #endif From 3945c7766891148c339a77118b7c1dbe709af407 Mon Sep 17 00:00:00 2001 From: Jordan Cohen Date: Thu, 5 Mar 2020 08:57:19 -0500 Subject: [PATCH 080/100] readme: adding libspdlog-dev to list of ubuntu dependencies, also sorting and cleaning up list to make it easier to read and copy --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d8b7545d..be458185 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,24 @@ libmpdclient [MPD module] On Ubuntu 19.10 you can install all the relevant dependencies using this command: ``` -sudo apt install libgtkmm-3.0-dev libjsoncpp-dev libinput-dev libsigc++-2.0-dev libpulse-dev libnl-3-dev libdbusmenu-gtk3-dev libnl-genl-3-dev libfmt-dev clang-tidy libmpdclient-dev libwayland-dev libgtk-3-dev gobject-introspection libgirepository1.0-dev scdoc +sudo apt install \ + clang-tidy \ + gobject-introspection \ + libdbusmenu-gtk3-dev \ + libfmt-dev \ + libgirepository1.0-dev \ + libgtk-3-dev \ + libgtkmm-3.0-dev \ + libinput-dev \ + libjsoncpp-dev \ + libmpdclient-dev \ + libnl-3-dev \ + libnl-genl-3-dev \ + libpulse-dev \ + libsigc++-2.0-dev \ + libspdlog-dev \ + libwayland-dev \ + scdoc ``` From 2f975f870a715f6691ebd2fc12d6ad75dc752316 Mon Sep 17 00:00:00 2001 From: BoostCookie Date: Thu, 12 Mar 2020 22:04:00 +0100 Subject: [PATCH 081/100] Added support for absolute device paths for the temperature module. --- man/waybar-temperature.5.scd | 8 ++++++++ src/modules/temperature.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index f8676867..eeae5462 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -20,6 +20,14 @@ Addressed by *temperature* typeof: string ++ The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*. +*hwmon-path-abs*: ++ + typeof: string ++ + The path of the hwmon-directory of the device, e.g. */sys/devices/pci0000:00/0000:00:18.3/hwmon*. (Note that the subdirectory *hwmon/hwmon#*, where *#* is a number is not part of the path!) Has to be used together with *input-filename*. + +*input-filename*: ++ + typeof: string ++ + The temperature filename of your *hwmon-path-abs*, e.g. *temp1_input* + *critical-threshold*: ++ typeof: integer ++ The threshold before it is considered critical (Celsius). diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 78391a0d..f2dd9587 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -1,9 +1,12 @@ #include "modules/temperature.hpp" +#include waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) : ALabel(config, "temperature", id, "{temperatureC}°C", 10) { if (config_["hwmon-path"].isString()) { file_path_ = config_["hwmon-path"].asString(); + } else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) { + file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); } else { auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); From d405f28622dfc8e7979e5e7c523c11d3a373a4ba Mon Sep 17 00:00:00 2001 From: BoostCookie <62076789+BoostCookie@users.noreply.github.com> Date: Fri, 13 Mar 2020 16:42:05 +0100 Subject: [PATCH 082/100] Indent now uses spaces. --- src/modules/temperature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index f2dd9587..c1b6ebcd 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -6,7 +6,7 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val if (config_["hwmon-path"].isString()) { file_path_ = config_["hwmon-path"].asString(); } else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) { - file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); + file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString(); } else { auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); From 5e712ca255232bba6b84ae3845e4ab9b4d0d8902 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sat, 14 Mar 2020 16:25:33 -0400 Subject: [PATCH 083/100] Switch default Makefile rule from run to build This commit makes it so that running `make` without arguments builds rather than builds and runs, which is unconventional and surprising behaviour. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bb6b3342..d7182c18 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: build build-debug run clean default install -default: run +default: build build: meson build From 19743f3085cc6fc865af33f0aa08d91d64499c0c Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Fri, 20 Mar 2020 17:37:22 -0400 Subject: [PATCH 084/100] fix(memory): provide better free memory approximation on old kernels The approximation should include SReclaimable, and subtract Shmem. To prevent the parsing code from ballooning in size, this commit also refactors the parsing into a map. --- include/modules/memory.hpp | 3 +-- src/modules/memory.cpp | 41 ++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index be66611e..5b0f51bb 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -17,8 +17,7 @@ class Memory : public ALabel { static inline const std::string data_dir_ = "/proc/meminfo"; void parseMeminfo(); - unsigned long memtotal_; - unsigned long memfree_; + std::unordered_map meminfo_; util::SleeperThread thread_; }; diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index eeb92bfe..6aa7036c 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -10,11 +10,23 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config auto waybar::modules::Memory::update() -> void { parseMeminfo(); - if (memtotal_ > 0 && memfree_ >= 0) { - auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2); - int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_; - auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2); - auto available_ram_gigabytes = memfree_ / std::pow(1024, 2); + + unsigned long memtotal = meminfo_["MemTotal"]; + unsigned long memfree; + if (meminfo_.count("MemAvailable")) { + // New kernels (3.4+) have an accurate available memory field. + memfree = meminfo_["MemAvailable"]; + } else { + // Old kernel; give a best-effort approximation of available memory. + memfree = meminfo_["MemFree"] + meminfo_["Buffers"] + meminfo_["Cached"] + + meminfo_["SReclaimable"] - meminfo_["Shmem"]; + } + + if (memtotal > 0 && memfree >= 0) { + auto total_ram_gigabytes = memtotal / std::pow(1024, 2); + int used_ram_percentage = 100 * (memtotal - memfree) / memtotal; + auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2); + auto available_ram_gigabytes = memfree / std::pow(1024, 2); getState(used_ram_percentage); label_.set_markup(fmt::format(format_, @@ -33,7 +45,6 @@ auto waybar::modules::Memory::update() -> void { } void waybar::modules::Memory::parseMeminfo() { - int64_t memfree = -1, membuffer = -1, memcache = -1, memavail = -1; std::ifstream info(data_dir_); if (!info.is_open()) { throw std::runtime_error("Can't open " + data_dir_); @@ -44,23 +55,9 @@ void waybar::modules::Memory::parseMeminfo() { if (posDelim == std::string::npos) { continue; } + std::string name = line.substr(0, posDelim); int64_t value = std::stol(line.substr(posDelim + 1)); - - if (name.compare("MemTotal") == 0) { - memtotal_ = value; - } else if (name.compare("MemAvailable") == 0) { - memavail = value; - } else if (name.compare("MemFree") == 0) { - memfree = value; - } else if (name.compare("Buffers") == 0) { - membuffer = value; - } else if (name.compare("Cached") == 0) { - memcache = value; - } - if (memtotal_ > 0 && (memavail >= 0 || (memfree > -1 && membuffer > -1 && memcache > -1))) { - break; - } + meminfo_[name] = value; } - memfree_ = memavail >= 0 ? memavail : memfree + membuffer + memcache; } From cb2f5c154c1177da05e16f4c7c62312d6c80e352 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:25:27 +0100 Subject: [PATCH 085/100] feat(custon): restart_interval for continuous script --- man/waybar-custom.5.scd | 6 ++++++ src/modules/custom.cpp | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 0ae7f4cd..92eda6cd 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,6 +33,12 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. +*restart_interval*: ++ + typeof: integer ++ + The restart interval (in seconds). + Can't be used with the *interval* option, so only with continuous scripts. + Once the scripts exit, it'll be re-executed after the *restart_interval*. + *signal*: ++ typeof: integer ++ The signal number used to update the module. diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ca095088..cbc865d6 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -55,12 +55,21 @@ void waybar::modules::Custom::continuousWorker() { exit_code = WEXITSTATUS(util::command::close(fp_, pid_)); fp_ = nullptr; } - thread_.stop(); if (exit_code != 0) { output_ = {exit_code, ""}; dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } + if (config_["restart_interval"].isUInt()) { + pid_ = -1; + fp_ = util::command::open(cmd, pid_); + if (!fp_) { + throw std::runtime_error("Unable to open " + cmd); + } + thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + } else { + thread_.stop(); + } return; } std::string output = buff; From d12ad1128ec606c6c46e851eaa69c2d50393cde2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:30:22 +0100 Subject: [PATCH 086/100] fix: man --- man/waybar-custom.5.scd | 4 ++-- src/modules/custom.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 92eda6cd..905dbc1a 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,11 +33,11 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. -*restart_interval*: ++ +*restart-interval*: ++ typeof: integer ++ The restart interval (in seconds). Can't be used with the *interval* option, so only with continuous scripts. - Once the scripts exit, it'll be re-executed after the *restart_interval*. + Once the script exit, it'll be re-executed after the *restart-interval*. *signal*: ++ typeof: integer ++ diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index cbc865d6..c81f1922 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -60,13 +60,13 @@ void waybar::modules::Custom::continuousWorker() { dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } - if (config_["restart_interval"].isUInt()) { + if (config_["restart-interval"].isUInt()) { pid_ = -1; fp_ = util::command::open(cmd, pid_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); } else { thread_.stop(); } From ff36154c4bfd23651ba5bcc8e966f825b09ffad7 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:31:04 +0100 Subject: [PATCH 087/100] fix: typo --- src/modules/custom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index c81f1922..24cfa71b 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -66,7 +66,7 @@ void waybar::modules::Custom::continuousWorker() { if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); } else { thread_.stop(); } From 9acf5587fa2e7d3575b06682a8b8d936a995e861 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:53:09 +0100 Subject: [PATCH 088/100] refactor(pulseaudio): fallback to default muted format --- src/modules/pulseaudio.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 3e9a95ea..d79e6aef 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -215,7 +215,11 @@ auto waybar::modules::Pulseaudio::update() -> void { } else { label_.get_style_context()->remove_class("bluetooth"); } - if (muted_ ) { + if (muted_) { + // Check muted bluetooth format exist, otherwise fallback to default muted format + if (format_name != "format" && !config_[format_name + "-muted"].isString()) { + format_name = "format"; + } format_name = format_name + "-muted"; label_.get_style_context()->add_class("muted"); } else { From 10b152ac3e28c59c2ec818c5b34351f620420e44 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Mar 2020 09:18:47 +0100 Subject: [PATCH 089/100] fix: process last line, restart-interval --- src/modules/custom.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 24cfa71b..71140bfd 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -49,6 +49,7 @@ void waybar::modules::Custom::continuousWorker() { thread_ = [&] { char* buff = nullptr; size_t len = 0; + bool restart = false; if (getline(&buff, &len, fp_) == -1) { int exit_code = 1; if (fp_) { @@ -61,16 +62,11 @@ void waybar::modules::Custom::continuousWorker() { spdlog::error("{} stopped unexpectedly, is it endless?", name_); } if (config_["restart-interval"].isUInt()) { - pid_ = -1; - fp_ = util::command::open(cmd, pid_); - if (!fp_) { - throw std::runtime_error("Unable to open " + cmd); - } - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); + restart = true; } else { thread_.stop(); + return; } - return; } std::string output = buff; @@ -80,6 +76,14 @@ void waybar::modules::Custom::continuousWorker() { } output_ = {0, output}; dp.emit(); + if (restart) { + pid_ = -1; + fp_ = util::command::open(cmd, pid_); + if (!fp_) { + throw std::runtime_error("Unable to open " + cmd); + } + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); + } }; } From af96150f5c0d466045a325a80b7ad8820ccff419 Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sat, 28 Mar 2020 01:35:21 +0900 Subject: [PATCH 090/100] restore SIGCHLD settings to SIG_DFL. --- include/util/command.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/util/command.hpp b/include/util/command.hpp index 69b1fd46..8db7bfba 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -88,6 +88,7 @@ inline int32_t forkExec(std::string cmd) { // Child executes the command if (!pid) { setpgid(pid, pid); + signal(SIGCHLD, SIG_DFL); execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0); exit(0); } else { From ec451b5908558388608be6bc94794ee4c9f77b81 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Mar 2020 10:36:24 +0200 Subject: [PATCH 091/100] fix(command): check WIFEXITED --- include/util/command.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/util/command.hpp b/include/util/command.hpp index 8db7bfba..f3dd4e1a 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -72,7 +72,10 @@ inline struct res exec(std::string cmd) { if (!fp) return {-1, ""}; auto output = command::read(fp); auto stat = command::close(fp, pid); - return {WEXITSTATUS(stat), output}; + if (WIFEXITED(stat)) { + return {WEXITSTATUS(stat), output}; + } + return {-1, output}; } inline int32_t forkExec(std::string cmd) { From bb2c16386b512d5684422045c5c46b872a8f5797 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 4 Apr 2020 21:13:25 +0200 Subject: [PATCH 092/100] feat: format-icon for persistent workspaces --- man/waybar-sway-workspaces.5.scd | 1 + src/modules/sway/workspaces.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index fe38d238..c92b512e 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -75,6 +75,7 @@ Additional to workspace name matching, the following *format-icons* can be set. - *default*: Will be shown, when no string matches is found. - *urgent*: Will be shown, when workspace is flagged as urgent - *focused*: Will be shown, when workspace is focused +- *persistent*: Will be shown, when workspace is persistent one. # PERSISTENT WORKSPACES diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index fe87f5ea..297935ab 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -205,6 +205,8 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node if (config_["format-icons"][key].isString() && node[key].asBool()) { return config_["format-icons"][key].asString(); } + } else if (config_["format_icons"]["persistent"].isString() && node["target_output"].isString()) { + return config_["format-icons"]["persistent"].asString(); } else if (config_["format-icons"][key].isString()) { return config_["format-icons"][key].asString(); } From d5bd3be8de0f7f20f97628969fb328ffb5822b07 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2020 16:12:25 +0200 Subject: [PATCH 093/100] chore: use native git --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index b8185c27..717f36fb 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,7 @@ else cpp_link_args += ['-lstdc++fs'] endif -git = find_program('git', required: false) +git = find_program('git', native: true, required: false) if not git.found() add_project_arguments('-DVERSION="@0@"'.format(meson.project_version()), language: 'cpp') From 8e0f3c7ddfb93491d158045677b70498cc616340 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2020 16:56:51 +0200 Subject: [PATCH 094/100] feat: full-at (#649) * feat: full-at * fix(man): typo --- man/waybar-battery.5.scd | 4 ++++ src/modules/battery.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index f96f85cb..8bcd2e82 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -18,6 +18,10 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ The adapter to monitor, as in /sys/class/power_supply/ instead of auto detect. +*full-at* ++ + typeof: integer ++ + Define the max percentage of the battery, usefull for an old battery, e.g. 96 + *interval* ++ typeof: integer ++ default: 60 ++ diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index dfd67531..e7e831c9 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -115,6 +115,16 @@ const std::tuple waybar::modules::Battery::getInfos time_remaining = -(float)(total_energy_full - total_energy) / total_power; } uint16_t capacity = total / batteries_.size(); + // Handle full-at + if (config_["full-at"].isUInt()) { + auto full_at = config_["full-at"].asUInt(); + if (full_at < 100) { + capacity = static_cast(capacity / full_at) * 100; + if (capacity > full_at) { + capacity = full_at; + } + } + } return {capacity, time_remaining, status}; } catch (const std::exception& e) { spdlog::error("Battery: {}", e.what()); From 5c5031fd69a511339a1e3b098de77b3c62ecf0de Mon Sep 17 00:00:00 2001 From: JohnHolmesII Date: Sun, 5 Apr 2020 11:42:27 -0700 Subject: [PATCH 095/100] pulse: do not die when a server hasn't been started. wait first. --- src/modules/pulseaudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index d79e6aef..25c2a20d 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -21,7 +21,7 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value if (context_ == nullptr) { throw std::runtime_error("pa_context_new() failed."); } - if (pa_context_connect(context_, nullptr, PA_CONTEXT_NOAUTOSPAWN, nullptr) < 0) { + if (pa_context_connect(context_, nullptr, PA_CONTEXT_NOFAIL, nullptr) < 0) { auto err = fmt::format("pa_context_connect() failed: {}", pa_strerror(pa_context_errno(context_))); throw std::runtime_error(err); From 27fbea2b5afde7fd601aa4e2afb2b3a74c9110bf Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 12:42:04 +0200 Subject: [PATCH 096/100] refactor(workspaces): default value unstripped, fix man --- man/waybar-sway-workspaces.5.scd | 6 ++++-- src/modules/sway/workspaces.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index c92b512e..f9ef31d5 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -19,7 +19,7 @@ Addressed by *sway/workspaces* *format*: ++ typeof: string ++ - default: {name} ++ + default: {value} ++ The format, how information should be displayed. *format-icons*: ++ @@ -62,7 +62,9 @@ Addressed by *sway/workspaces* # FORMAT REPLACEMENTS -*{name}*: Name of the workspace, as defined by sway. +*{value}*: Name of the workspace, as defined by sway. + +*{name}*: Number stripped from workspace value. *{icon}*: Icon, as defined in *format-icons*. diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 297935ab..6aeaacaa 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -157,12 +157,13 @@ auto Workspaces::update() -> void { if (needReorder) { box_.reorder_child(button, it - workspaces_.begin()); } - std::string output = getIcon((*it)["name"].asString(), *it); + std::string output = (*it)["name"].asString(); if (config_["format"].isString()) { auto format = config_["format"].asString(); output = fmt::format(format, - fmt::arg("icon", output), - fmt::arg("name", trimWorkspaceName((*it)["name"].asString())), + fmt::arg("icon", getIcon(output, *it)), + fmt::arg("value", output) + fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString())); } if (!config_["disable-markup"].asBool()) { From 7c4ea397749f8afc78d88b2f624b2a0b30a3b81a Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2020 12:49:41 +0200 Subject: [PATCH 097/100] fix: add missing comma --- src/modules/sway/workspaces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 6aeaacaa..f61c98a8 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -162,7 +162,7 @@ auto Workspaces::update() -> void { auto format = config_["format"].asString(); output = fmt::format(format, fmt::arg("icon", getIcon(output, *it)), - fmt::arg("value", output) + fmt::arg("value", output), fmt::arg("name", trimWorkspaceName(output)), fmt::arg("index", (*it)["num"].asString())); } From ac3126b6cf1d30fb4adedd16f17eefa836b2d860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pla=C3=A7ais?= Date: Fri, 10 Apr 2020 15:45:29 +0200 Subject: [PATCH 098/100] feat(layout): add pugixml dependency to dockerfiles --- Dockerfiles/alpine | 2 +- Dockerfiles/archlinux | 2 +- Dockerfiles/debian | 2 +- Dockerfiles/fedora | 2 +- Dockerfiles/opensuse | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfiles/alpine b/Dockerfiles/alpine index 78a78b67..fec63c2b 100644 --- a/Dockerfiles/alpine +++ b/Dockerfiles/alpine @@ -2,4 +2,4 @@ FROM alpine:latest -RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev libnl3-dev pulseaudio-dev libmpdclient-dev scdoc +RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev pugixml libnl3-dev pulseaudio-dev libmpdclient-dev scdoc diff --git a/Dockerfiles/archlinux b/Dockerfiles/archlinux index 9197fb81..b640ce72 100644 --- a/Dockerfiles/archlinux +++ b/Dockerfiles/archlinux @@ -3,4 +3,4 @@ FROM archlinux/base:latest RUN pacman -Syu --noconfirm && \ - pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp scdoc --noconfirm + pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc --noconfirm diff --git a/Dockerfiles/debian b/Dockerfiles/debian index 8d7a0651..eedbcfbe 100644 --- a/Dockerfiles/debian +++ b/Dockerfiles/debian @@ -3,5 +3,5 @@ FROM debian:sid RUN apt-get update && \ - apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc && \ + apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc && \ apt-get clean diff --git a/Dockerfiles/fedora b/Dockerfiles/fedora index af886073..7bd9d767 100644 --- a/Dockerfiles/fedora +++ b/Dockerfiles/fedora @@ -2,6 +2,6 @@ FROM fedora:30 -RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel scdoc -y && \ +RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel pugixml-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel scdoc -y && \ dnf group install "C Development Tools and Libraries" -y && \ dnf clean all -y diff --git a/Dockerfiles/opensuse b/Dockerfiles/opensuse index c54777ee..af1be95a 100644 --- a/Dockerfiles/opensuse +++ b/Dockerfiles/opensuse @@ -4,4 +4,4 @@ FROM opensuse/tumbleweed:latest RUN zypper -n up && \ zypper -n install -t pattern devel_C_C++ && \ - zypper -n install git meson clang libinput10 libinput-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc + zypper -n install git meson clang libinput10 libinput-devel libpugixml1 libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc From 8f6273e9d005114676c51cf788165d6204c6e229 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Apr 2020 12:08:21 +0200 Subject: [PATCH 099/100] refactor(config): comment default config layer --- resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/config b/resources/config index 237c787d..832f76c8 100644 --- a/resources/config +++ b/resources/config @@ -1,5 +1,5 @@ { - "layer": "top", // Waybar at top layer + // "layer": "top", // Waybar at top layer // "position": "bottom", // Waybar position (top|bottom|left|right) "height": 30, // Waybar height (to be removed for auto height) // "width": 1280, // Waybar width From b9338c72c9dddac9d38c76b23aa3502557982a19 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Apr 2020 12:24:49 +0200 Subject: [PATCH 100/100] chore: 0.9.2 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 717f36fb..1dab13d9 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'waybar', 'cpp', 'c', - version: '0.9.1', + version: '0.9.2', license: 'MIT', default_options : [ 'cpp_std=c++17',