Compare commits

..

163 Commits

Author SHA1 Message Date
3ecd4030e3 chore: v0.9.20 2023-07-18 08:29:32 +02:00
841a004acd fix: lint 2023-07-18 08:28:19 +02:00
839975c348 Merge pull request #2318 from calvinchd/hyprland-window-remove-empty-css
hyprland/window remove duplicate empty css
2023-07-18 08:22:27 +02:00
185aa104b0 Merge pull request #2326 from czM1K3/master
hyprland/language: Differentiating keyboard layout variants
2023-07-18 08:21:52 +02:00
b2279c9565 Differencing keyboard layout variant for hyprland/language 2023-07-17 22:20:50 +02:00
388912d4a7 Merge pull request #2324 from xytovl/fix-crash-on-resume 2023-07-17 08:26:53 +02:00
f62b3d0e9d Ensure signal is disconnected in destructor 2023-07-16 23:29:28 +02:00
1e2b9cb5ed Merge pull request #2306 from stefonarch/patch-1
Fix wrong name for {name}
2023-07-16 18:21:00 +02:00
85b4ff4f81 Merge pull request #2321 from calvinchd/hyprland-runtime-err 2023-07-16 15:10:03 +02:00
0f6eff1f20 hyprland: fix json parser runtime err from socket read ending early 2023-07-16 22:18:27 +10:00
7a5e702334 Merge pull request #2317 from m4rch3n1ng/backlight-percent 2023-07-16 09:34:47 +02:00
8687ed2068 Update man for hyprland/window to replace #window.empty with window#waybar.empty #window 2023-07-16 16:41:50 +10:00
2be0e966e1 hyprland/window: remove .empty css class for #window 2023-07-16 16:40:54 +10:00
may
facb53e81f backlight: do not convert percent to string in fmt 2023-07-16 04:14:43 +02:00
2211a79840 Merge pull request #2308 from gardenappl/hidden-fix
hyprland/window: rename .hidden to .swallowing (and fix grouped windows)
2023-07-12 18:13:50 +02:00
daca57129f hyprland/window: rename .hidden to .swallowing (and fix grouped windows) 2023-07-12 19:01:45 +03:00
19c7c0763f Merge pull request #2307 from gardenappl/hidden-fix
hyprland/window: Fix overlap with .hidden class from default style
2023-07-12 17:27:37 +02:00
14c6550593 hyprland/window: Fix overlap with .hidden class from default style 2023-07-12 17:56:12 +03:00
7aae93e7ed Fix wrong name for {name} 2023-07-12 16:31:58 +02:00
dffba78401 Merge pull request #2303 from Mr-Pine/hyprland-window-icon 2023-07-11 08:08:20 +02:00
a8a1a4985f Add removed secondary identifier
(class for xwayland under sway)
2023-07-10 23:48:18 +02:00
31683d9e2a Implemented AAppIconLabel for sway/window 2023-07-10 22:55:46 +02:00
00e143d47e Introducce AAppIconLabel class
Implemented for hyprland
2023-07-10 22:50:58 +02:00
6e9ba3fc01 Fix spacing if icon is false 2023-07-10 22:26:02 +02:00
a373f6b654 Icon working 2023-07-10 22:02:03 +02:00
91bd28d410 Merge pull request #2294 from Mr-Pine/hyprland-window-data
`hyprland/window` expose more data
2023-07-09 10:18:26 +02:00
acde076913 Merge pull request #2288 from LukashonakV/arch_cava
Arch CI cava
2023-07-09 10:17:55 +02:00
f5655526d0 Merge pull request #2296 from m-bdf/clock-tz-changes 2023-07-09 04:22:15 +02:00
56f956ff90 clock: handle timezone changes (again) 2023-07-09 01:44:39 +02:00
f97c1c7136 remove getWindowData 2023-07-08 23:22:29 +02:00
9ee883ee1b No dashes is format arg name 2023-07-08 23:11:11 +02:00
1887512ba1 Update scd 2023-07-08 22:40:16 +02:00
2ae13c4092 consitent naming 2023-07-08 22:40:16 +02:00
c5f1771375 Use already existing queryActiveWorkspace() 2023-07-08 22:40:16 +02:00
c4bace504c Separate query and struct 2023-07-08 22:40:16 +02:00
3bfeed31bc Merge pull request #2293 from sigboe/master 2023-07-08 21:47:04 +02:00
d774de6c46 fix, default to true, sway/workspaces: warp-on-scroll 2023-07-08 21:32:19 +02:00
b20041d85d cava dependencies 2023-07-08 08:41:37 +00:00
e4900db9a2 Merge pull request #2286 from calvinchd/hyprland-window-noinfo 2023-07-06 08:24:11 +02:00
e2bfa5e019 hyprland/window: fix no info with separate-outputs=true 2023-07-06 11:01:24 +10:00
423d8495e4 Merge pull request #2284 from jbeich/dbus 2023-07-05 20:17:51 +02:00
1fb2b8efd5 fix(util): don't abort modules from SleeperThread after 3c9cbc99d7
[warning] module sway/workspaces: Disabling module "sway/workspaces", Unable to connect to the SYSTEM Bus!...
[warning] module sway/mode: Disabling module "sway/mode", Unable to connect to the SYSTEM Bus!...
[warning] module sway/scratchpad: Disabling module "sway/scratchpad", Unable to connect to the SYSTEM Bus!...
[warning] module custom/media: Disabling module "custom/media", Unable to connect to the SYSTEM Bus!...
[warning] module sway/window: Disabling module "sway/window", Unable to connect to the SYSTEM Bus!...
[warning] module cpu: Disabling module "cpu", Unable to connect to the SYSTEM Bus!...
[warning] module memory: Disabling module "memory", Unable to connect to the SYSTEM Bus!...
[warning] module temperature: Disabling module "temperature", Unable to connect to the SYSTEM Bus!...
[warning] module sway/language: Disabling module "sway/language", Unable to connect to the SYSTEM Bus!...
[warning] module battery: Disabling module "battery", Unable to connect to the SYSTEM Bus!...
[warning] module battery#bat2: Disabling module "battery#bat2", Unable to connect to the SYSTEM Bus!...
2023-07-05 17:47:24 +00:00
3299d4a25c Merge pull request #2270 from gardenappl/hypr-backend
hyprland/window: Add .hidden CSS class, account for hidden & fullscreen windows
2023-07-05 08:14:49 +02:00
e125bbeb4d hyprland/window: properly check visibility for .floating class 2023-07-05 03:43:03 +03:00
55c59253d6 Update man pages 2023-07-05 03:15:59 +03:00
e7deab92c7 Merge pull request #2282 from zjeffer/fix/build-warnings
Fixed build warnings
2023-07-04 23:09:13 +02:00
d21f29cb14 Fixed build warnings 2023-07-04 23:05:26 +02:00
d8a808f76c chore: 0.9.19 2023-07-04 23:03:50 +02:00
5ef6636237 Merge pull request #2265 from tengyifei/master
Partially revert 3af1853260 to fix use-after-free
2023-07-04 22:59:45 +02:00
fc632f50ec fix: lint 2023-07-04 22:52:24 +02:00
31e4c9023e Merge pull request #1872 from HarHarLinks/patch-1
Add output parameter format to manpage
2023-07-04 22:46:06 +02:00
3e1c341933 Merge branch 'master' into patch-1 2023-07-04 22:45:15 +02:00
0d1016d4d2 Merge pull request #2203 from rodrgz/mprisImprovement
mpris: dynamic tag ordering and separator customization
2023-07-04 22:44:21 +02:00
12725f4418 Merge pull request #2220 from sigboe/warp-on-scroll-toggle
sway/workspaces: setting to not warp to window when scrolling
2023-07-04 22:42:53 +02:00
5c64d034a2 Merge pull request #2010 from chayleaf/improve-flake
improve nix dev shell; override the nixpkgs waybar
2023-07-04 22:40:52 +02:00
14fa9cf7b7 Merge pull request #2128 from Alan-Kuan/image-tooltip
Image tooltip
2023-07-04 22:40:04 +02:00
6c196b8f8d fix: lint 2023-07-04 22:35:27 +02:00
18d6dfea88 feat(man): start_hidden 2023-07-04 22:35:15 +02:00
d2eb8eb9fc Merge pull request #2175 from maqrrr/start_hidden
Add a new start_hidden flag
2023-07-04 22:33:33 +02:00
65f73d3e95 Merge pull request #2269 from Arcus92/master
wlr/taskbar: add support for rewrite rules
2023-07-04 22:31:37 +02:00
265b4edb2e Merge pull request #2276 from skligys/fix_mpris_ui_spamming
Stop MPRIS module from updating every ~20ms
2023-07-04 22:29:48 +02:00
18f5af835f Merge pull request #2280 from zjeffer/fix/hyprland/workspaces 2023-07-04 19:58:07 +02:00
7ef80d563b Formatting fixes 2023-07-04 19:48:04 +02:00
d3be9a7363 Fix rare segfault when destroying workspace 2023-07-04 19:40:43 +02:00
5f29e5a5e8 Merge pull request #2279 from LukashonakV/Catch_bump 2023-07-04 18:37:30 +02:00
cf4d58f30a Catch2 bump 2023-07-04 11:30:44 -04:00
bb61461aad Merge pull request #2278 from Anakael/pr/anakael/hyprland-workspaces 2023-07-04 08:02:45 +02:00
c91c8bbc45 Merge pull request #2277 from Aparicio99/fix_icon_theme_segfault 2023-07-04 08:01:45 +02:00
f26a125d15 format 2023-07-04 01:26:16 +03:00
de626dcbbc format 2023-07-04 01:24:34 +03:00
c9b963e82b fix segfault 2023-07-04 01:17:26 +03:00
a1cd0acac5 Fix random segfault on GTK icon functions
The segfaults were happening on GTK icon theme functions, which are
called via the C++ interface functions such as Gtk::IconTheme::has_icon.

There are multiple modules and threads using this functions on the default
icon theme by calling Gtk::IconTheme::get_default(), which returns the same
object for all callers, and was causing concurrent access to the same internal
data structures on the GTK lib. Even a seemingly read-only function such as
has_icon can cause writes due to the internal icon cache being updated.

To avoid this issues, a program wide global mutex must be used to ensure
a single thread is accessing the default icon theme instance.

This commit implements wrappers for the existing IconTheme function calls,
ensuring the global lock is held while calling the underling GTK functions.
2023-07-03 22:32:24 +01:00
c2f9d889f4 Stop MPRIS module from updating every ~20ms as onPlayerMetadata(), onPlayerPlay()
callbacks get triggered without regard for update interval.
2023-07-03 13:52:57 -07:00
cdece498c1 hyprland/window: .solo class accounts for hidden & fullscreen windows 2023-07-02 20:58:42 +03:00
58bdc6a41c fix spaces in waybar-wlr-taskbar.5.scd 2023-07-02 12:51:54 +02:00
c55cd82b39 wlr/taskbar: add support for rewrite rules 2023-07-02 12:23:36 +02:00
91588fb8bb Merge pull request #2212 from evyatark2/wpscroll
wireplumber: Support for scrolling
2023-07-02 11:46:56 +02:00
6b9600fecd Merge pull request #2267 from korylprince/reverse-scrolling
Don't apply reverse scrolling to mice wheels
2023-07-02 11:45:44 +02:00
0bfb29789c Merge pull request #2268 from zjeffer/hyprland/workspaces
Fixes for hyprland/workspaces
2023-07-02 11:45:09 +02:00
f6a62e258e fixes for hyprland/workspaces 2023-07-01 18:53:17 +02:00
1ba05d1ffa add reverse-mouse-scrolling to configure mouse wheel reverse scrolling 2023-07-01 10:35:37 -05:00
7a01143359 ignore reverse-scrolling from mouse wheel 2023-07-01 10:33:55 -05:00
35496f461f fix regression from #2232: reverse-scrolling was not applied to
GTK_SCROLL_SMOOTH events
2023-07-01 10:33:55 -05:00
b9cd0287f4 fix: typo 2023-07-01 11:12:46 +02:00
9d741f89e2 fix: lint 2023-07-01 11:12:14 +02:00
cc4370f1b2 fix: build 2023-07-01 11:08:31 +02:00
85854c71d6 Merge pull request #2219 from xytovl/wake_threads_on_resume
Wake all sleeping threads when leaving suspend
2023-07-01 11:02:13 +02:00
6ed550117c Merge pull request #2237 from LukashonakV/Gentoo_CI
Refresh Gentoo docker
2023-07-01 10:57:33 +02:00
15fe85d18d Merge pull request #2264 from Anakael/pr/anakael/hyprland-workspaces
feat: hyprland/workspaces
2023-07-01 10:55:24 +02:00
b62e5eb822 Merge pull request #2266 from zjeffer/master
Fixed some build warnings
2023-07-01 10:53:24 +02:00
25c2aaabcb Fixed build warnings 2023-07-01 10:12:24 +02:00
cd49eef229 Partially revert 3af1853260 to fix use-after-free
After upgrading to the latest release of Waybar the bar will crash
whenever I close the laptop lid. After some debugging I believe it is
because the watching added by watch_name is not being correctly canceled
using unwatch_name. After the Tray object and Host object are destroyed,
additional callbacks will become use-after-free.

Looks like commit 3af1853260 removed the
unwatch_name. I'm not sure why it did that, but it seemed dangerous.

Additionally, bus_name_id_ is created by own_name. According to that
function's documentation, the correct inverse operation is unown_name.
2023-06-30 23:25:24 -07:00
4f9fbbfa54 fix format 2023-07-01 02:25:15 +03:00
0b602632f2 return catch2 2023-07-01 02:23:37 +03:00
dbc7471f83 add docs 2023-07-01 02:13:36 +03:00
887c44bf68 finish MVP 2023-07-01 00:18:57 +03:00
33236c222f save 2023-06-28 02:52:01 +03:00
4116490535 Merge pull request #2256 from luttermann/master
Add output port (display) of workspace to template function of sway/workspace
2023-06-27 13:50:54 +02:00
08e18387c9 Add output port of workspace to template 2023-06-27 13:41:42 +02:00
0fff38c751 Merge pull request #2258 from Anakael/pr/anakael/hide-empty-taskbar
[wrl/taskbare] fix: use empty class for empty taskbar
2023-06-27 08:58:54 +02:00
afc489869a fix format 2023-06-27 00:18:49 +03:00
ce4da59f34 finish 2023-06-27 00:07:40 +03:00
43434254e0 Add output port of workspace to template 2023-06-26 11:01:50 +02:00
66ce74d29b mpris: Rename dynamic-priority to dynamic-importance-order keeping backward compatibility 2023-06-22 02:13:44 -03:00
77a8420aaf mpris: Add dynamic-order and dynamic-separator
This commit allows better handling of ordering and exclusion of the tags in Dynamics tags.
It also becomes possible to choose the separator between the tags.
2023-06-22 02:13:34 -03:00
b0f89f2bc1 Merge pull request #2241 from yangyingchao/master
support multiple items in hwmon-path of temperature module
2023-06-20 13:22:36 +02:00
7cda2dfd1a Merge pull request #2245 from gardenappl/main
hyprland/window: Add CSS customization similar to sway/window
2023-06-20 13:22:12 +02:00
238cfa9547 Merge pull request #2247 from gardenappl/hypr-backend
More robust Hyprland backend
2023-06-20 13:21:34 +02:00
b163b21ace More robust Hyprland backend 2023-06-20 13:36:48 +03:00
30c4f08773 hyprland/window: Correct application of .solo class 2023-06-20 03:54:02 +03:00
fd7c2a2012 hyprland/language: Show language on startup 2023-06-20 00:43:33 +03:00
4f14ce3285 hyprland/window: add .floating and .fullscreen CSS classes 2023-06-20 00:42:19 +03:00
e233022d1a hyprland/window: Rework, add .empty, .solo and .<app_id> CSS classes 2023-06-19 23:44:20 +03:00
e403c3b71b support multiple items in hwmon-path of temperature module
So user can share configuration file among different machines with different hardware
configurations.
2023-06-17 11:33:14 +08:00
d367b7e1d6 Merge pull request #2229 from LukashonakV/Upower_nativePath
Upower native-path filter
2023-06-16 15:38:58 +02:00
038644f8d9 Merge pull request #2238 from LukashonakV/ISSUE#2204
Issue#2204
2023-06-16 15:38:20 +02:00
d650c597f9 Renew clock man page
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-15 16:36:33 +03:00
5196009656 Refresh Gentoo docker
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-15 13:58:33 +03:00
4d8515930f Use local TZ, when user sets blank TZ in config
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-13 23:32:28 +03:00
192cea97f2 Upower man
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-13 18:44:29 +03:00
83f3c2321e Merge pull request #2231 from RobertMueller2/appid-fix
sway/window: fix appid style not cleared
2023-06-12 15:40:56 +02:00
dff0583c12 Merge pull request #2232 from robertgzr/reverse-scroll
Lift reverse-scrolling option into AModule
2023-06-12 08:54:38 +02:00
73c7e54535 pulseaudio: document reverse-scrolling option
Signed-off-by: Robert Günzler <r@gnzler.io>
2023-06-12 14:08:22 +09:00
0f8c156f24 Lift reverse-scrolling option into AModule
The option is generally useful when scrolling is used, when configuring
input devices to use "natural scroll direction".
Both backlight and pulseaudio were using different implementations, this
unifies and documents them.

Signed-off-by: Robert Günzler <r@gnzler.io>
2023-06-12 14:08:18 +09:00
fff4509723 sway/window: fix appid style not cleared (#2227)
Probably a rebase error during development of #1419. The code block now
removed was not supposed to be there anymore.
2023-06-11 08:41:20 +02:00
17af49d421 Upower native-path filter
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-09 18:22:24 +03:00
9f38631c7f Merge pull request #2223 from Anakael/pr/shchemel/fix-class-priority 2023-06-09 08:36:34 +02:00
62f4125927 change order 2023-06-08 23:31:14 +03:00
a67e692d4a sway: warp-on-scroll toggle 2023-06-07 15:49:11 +02:00
3c9cbc99d7 Wake all sleeping threads when leaving suspend
std::condition_variable::wait_for does not count time spent in sleep
mode, resulting in longer than expected waits.
2023-06-07 10:17:42 +02:00
c5379fa52d Merge pull request #2218 from LukashonakV/Wdeprecated
deprecated: implicit capture of 'this' via '[=]'
2023-06-06 22:56:27 +02:00
070110af0c Merge pull request #2217 from LukashonakV/g_bus_unwatch_name
Tray module causes: Invalid id passed to g_bus_unwatch_name()
2023-06-06 22:37:46 +02:00
6bf5b15c13 deprecated: implicit capture of 'this' via '[=]'
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-06 23:31:12 +03:00
a9779c2aa2 Happy Linter
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-06 23:06:11 +03:00
3af1853260 Tray module cause error g_bus_unwatch_name()
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-06 23:02:36 +03:00
d638610db1 Merge pull request #2216 from LukashonakV/small_fixies
Small performance fixies
2023-06-06 13:03:52 +02:00
87023c39f8 Small performance fixies
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
2023-06-06 13:58:05 +03:00
e96610e31a Use consistent tabbing 2023-06-06 12:01:25 +03:00
d61b1d54de Document new wireplumber module functionality 2023-06-06 11:44:17 +03:00
e397f568b7 Round volume instead of truncating it 2023-06-06 11:42:31 +03:00
d22fd3bbd1 Use a minimum step as provided by wireplubmer; Default step to 1 2023-06-06 11:42:02 +03:00
75990c2867 Fix linting 2023-06-05 22:23:46 +03:00
88a1a702b4 wireplumber: Support for scrolling 2023-06-05 22:03:46 +03:00
24407dbf4a Merge pull request #2196 from calvinchd/hyprland-window-empty-css
[hyprland/window] Add css class for empty window name
2023-06-05 16:48:59 +02:00
108285e9ac Merge pull request #2210 from D3vil0p3r/patch-1
Fixing 'incomplete type error' during building
2023-06-05 16:30:00 +02:00
b728a37b6d Fixing 'incomplete type error' during building
Fixing errors during the building due to missing library after latest GCC updates.
2023-06-05 16:28:32 +02:00
938a93a0d7 Merge pull request #2209 from Matias-Hall/river_window_tooltip 2023-06-05 12:39:38 +02:00
ff6f727631 river/window: Add tooltip. 2023-06-05 18:29:19 +08:00
84077e0253 Merge pull request #2207 from dejor/dwl-module 2023-06-04 18:39:03 +02:00
d2787cc2d8 fix: typo to avoid null pointer 2023-06-04 12:45:33 +02:00
17a56aa4f7 hyprland/window: use empty() for empty window name check 2023-06-03 12:29:36 +10:00
ca52892ab9 Merge pull request #2200 from Visne/patch-1 2023-06-01 22:52:54 +02:00
655bc8f215 Fix broken link 2023-06-01 22:08:54 +02:00
a3912436be hyprland/window: add css class for empty label 2023-06-01 21:38:27 +10:00
339bea1213 Add a new start_hidden bool 2023-05-15 07:01:00 -04:00
9389c8d854 chore: update manual of the image modle 2023-04-21 16:51:04 +08:00
6a17139423 feat: tooltip for image module 2023-04-21 16:38:21 +08:00
3f23792df0 use the recommended way of using flake-compat 2023-02-16 20:31:02 +07:00
529031f44f fix typo 2023-02-16 20:26:57 +07:00
f51894614d after updating nix.lock all this soup isn't needed 2023-02-16 20:25:07 +07:00
a7dbab79e5 add default.nix for compatibility; update flake.lock 2023-02-16 20:02:39 +07:00
4dcce810d2 improve nix dev shell; override the nixpkgs waybar
for example, the update from 0.9.16 to 0.9.17 broke this flake, after
this change the derivation will be the same as the nixpkgs one. This is
the better option since the flake is unmaintained in this repo (although
it may still break inbetween releases)
2023-02-16 19:45:58 +07:00
1130e8c8ec Add output parameter format to manpage 2022-12-06 19:05:08 +01:00
70 changed files with 1677 additions and 602 deletions

View File

@ -3,5 +3,5 @@
FROM archlinux:base-devel
RUN pacman -Syu --noconfirm && \
pacman -S --noconfirm git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc libpulse libdbusmenu-gtk3 libmpdclient gobject-introspection libxkbcommon playerctl && \
pacman -S --noconfirm git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc libpulse libdbusmenu-gtk3 libmpdclient gobject-introspection libxkbcommon playerctl iniparser fftw && \
sed -Ei 's/#(en_(US|GB)\.UTF)/\1/' /etc/locale.gen && locale-gen

View File

@ -6,6 +6,6 @@ RUN export FEATURES="-ipc-sandbox -network-sandbox -pid-sandbox -sandbox -usersa
emerge --sync && \
eselect news read --quiet new 1>/dev/null 2>&1 && \
emerge --verbose --update --deep --with-bdeps=y --backtrack=30 --newuse @world && \
USE="wayland gtk3 gtk -doc X" emerge dev-vcs/git dev-libs/wayland dev-libs/wayland-protocols =dev-cpp/gtkmm-3.24.6 x11-libs/libxkbcommon \
USE="wayland gtk3 gtk -doc X pulseaudio minimal" emerge dev-vcs/git dev-libs/wayland dev-libs/wayland-protocols =dev-cpp/gtkmm-3.24.6 x11-libs/libxkbcommon \
x11-libs/gtk+:3 dev-libs/libdbusmenu dev-libs/libnl sys-power/upower media-libs/libpulse dev-libs/libevdev media-libs/libmpdclient \
media-sound/sndio gui-libs/gtk-layer-shell app-text/scdoc media-sound/playerctl dev-libs/iniparser
media-sound/sndio gui-libs/gtk-layer-shell app-text/scdoc media-sound/playerctl dev-libs/iniparser sci-libs/fftw

View File

@ -1,7 +1,7 @@
# Waybar [![Licence](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Paypal Donate](https://img.shields.io/badge/Donate-Paypal-2244dd.svg)](https://paypal.me/ARouillard)<br>![Waybar](https://raw.githubusercontent.com/alexays/waybar/master/preview-2.png)
> Highly customizable Wayland bar for Sway and Wlroots based compositors.<br>
> Available in Arch [community](https://www.archlinux.org/packages/community/x86_64/waybar/) or
> Available in Arch [community](https://www.archlinux.org/packages/extra/x86_64/waybar/) or
[AUR](https://aur.archlinux.org/packages/waybar-git/), [Gentoo](https://packages.gentoo.org/packages/gui-apps/waybar), [openSUSE](https://build.opensuse.org/package/show/X11:Wayland/waybar), and [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=waybar).<br>
> *Waybar [examples](https://github.com/Alexays/Waybar/wiki/Examples)*

10
default.nix Normal file
View File

@ -0,0 +1,10 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix

35
flake.lock generated
View File

@ -6,11 +6,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1667210711,
"narHash": "sha256-IoErjXZAkzYWHEpQqwu/DeRNJGFdR7X2OGbkhMqMrpw=",
"lastModified": 1676293499,
"narHash": "sha256-uIOTlTxvrXxpKeTvwBI1JGDGtCxMXE3BI0LFwoQMhiQ=",
"owner": "numtide",
"repo": "devshell",
"rev": "96a9dd12b8a447840cc246e17a47b81a4268bba7",
"rev": "71e3022e3ab20bbf1342640547ef5bc14fb43bf4",
"type": "github"
},
"original": {
@ -19,6 +19,22 @@
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1642700792,
@ -36,11 +52,11 @@
},
"flake-utils_2": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"lastModified": 1676283394,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
"type": "github"
},
"original": {
@ -67,11 +83,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1670152712,
"narHash": "sha256-LJttwIvJqsZIj8u1LxVRv82vwUtkzVqQVi7Wb8gxPS4=",
"lastModified": 1676300157,
"narHash": "sha256-1HjRzfp6LOLfcj/HJHdVKWAkX9QRAouoh6AjzJiIerU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14ddeaebcbe9a25748221d1d7ecdf98e20e2325e",
"rev": "545c7a31e5dedea4a6d372712a18e00ce097d462",
"type": "github"
},
"original": {
@ -84,6 +100,7 @@
"root": {
"inputs": {
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
}

View File

@ -5,9 +5,13 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devshell.url = "github:numtide/devshell";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, flake-utils, devshell, nixpkgs }:
outputs = { self, flake-utils, devshell, nixpkgs, flake-compat }:
let
inherit (nixpkgs) lib;
genSystems = lib.genAttrs [
@ -26,9 +30,9 @@
]);
in
{
overlays.default = _: prev: rec {
overlays.default = _: prev: {
waybar = prev.callPackage ./nix/default.nix {
version = "0.9.16" + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
version = prev.waybar.version + "+date=" + (mkDate (self.lastModifiedDate or "19700101")) + "_" + (self.shortRev or "dirty");
};
};
packages = genSystems
@ -57,8 +61,32 @@
devshell.packages = with pkgs; [
clang-tools
gdb
];
language.c.libraries = with pkgs; [
# from nativeBuildInputs
gnumake
meson
ninja
pkg-config
scdoc
] ++ (map lib.getDev [
# from buildInputs
wayland wlroots gtkmm3 libsigcxx jsoncpp spdlog gtk-layer-shell howard-hinnant-date libxkbcommon
# optional dependencies
gobject-introspection glib playerctl python3.pkgs.pygobject3
libevdev libinput libjack2 libmpdclient playerctl libnl
libpulseaudio sndio sway libdbusmenu-gtk3 udev upower wireplumber
# from propagated build inputs?
at-spi2-atk atkmm cairo cairomm catch2 fmt_8 fontconfig
gdk-pixbuf glibmm gtk3 harfbuzz pango pangomm wayland-protocols
]);
env = with pkgs; [
{ name = "CPLUS_INCLUDE_PATH"; prefix = "$DEVSHELL_DIR/include"; }
{ name = "PKG_CONFIG_PATH"; prefix = "$DEVSHELL_DIR/lib/pkgconfig"; }
{ name = "PKG_CONFIG_PATH"; prefix = "$DEVSHELL_DIR/share/pkgconfig"; }
{ name = "PATH"; prefix = "${wayland.bin}/bin"; }
{ name = "LIBRARY_PATH"; prefix = "${lib.getLib sndio}/lib"; }
{ name = "LIBRARY_PATH"; prefix = "${lib.getLib zlib}/lib"; }
{ name = "LIBRARY_PATH"; prefix = "${lib.getLib howard-hinnant-date}/lib"; }
];
};
});

27
include/AAppIconLabel.hpp Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include "AIconLabel.hpp"
namespace waybar {
class AAppIconLabel : public AIconLabel {
public:
AAppIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval = 0, bool ellipsize = false,
bool enable_click = false, bool enable_scroll = false);
virtual ~AAppIconLabel() = default;
auto update() -> void override;
protected:
void updateAppIconName(const std::string &app_identifier,
const std::string &alternative_app_identifier);
void updateAppIcon();
unsigned app_icon_size_{24};
bool update_app_icon_{true};
std::string app_icon_name_;
};
} // namespace waybar

View File

@ -31,6 +31,7 @@
#include "modules/hyprland/language.hpp"
#include "modules/hyprland/submap.hpp"
#include "modules/hyprland/window.hpp"
#include "modules/hyprland/workspaces.hpp"
#endif
#if defined(__FreeBSD__) || (defined(__linux__) && !defined(NO_FILESYSTEM))
#include "modules/battery.hpp"

View File

@ -6,6 +6,8 @@
#include <string>
#include <thread>
#include "util/json.hpp"
namespace waybar::modules::hyprland {
class EventHandler {
@ -22,12 +24,14 @@ class IPC {
void unregisterForIPC(EventHandler*);
std::string getSocket1Reply(const std::string& rq);
Json::Value getSocket1JsonReply(const std::string& rq);
private:
void startIPC();
void parseIPC(const std::string&);
std::mutex callbackMutex;
util::JsonParser parser_;
std::list<std::pair<std::string, EventHandler*>> callbacks;
};

View File

@ -1,15 +1,13 @@
#include <fmt/format.h>
#include <tuple>
#include "ALabel.hpp"
#include "AAppIconLabel.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "util/json.hpp"
namespace waybar::modules::hyprland {
class Window : public waybar::ALabel, public EventHandler {
class Window : public waybar::AAppIconLabel, public EventHandler {
public:
Window(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Window();
@ -17,15 +15,46 @@ class Window : public waybar::ALabel, public EventHandler {
auto update() -> void override;
private:
int getActiveWorkspaceID(std::string);
std::string getLastWindowTitle(int);
struct Workspace {
int id;
int windows;
std::string last_window;
std::string last_window_title;
static auto parse(const Json::Value&) -> Workspace;
};
struct WindowData {
bool floating;
int monitor = -1;
std::string class_name;
std::string initial_class_name;
std::string title;
std::string initial_title;
bool fullscreen;
bool grouped;
static auto parse(const Json::Value&) -> WindowData;
};
auto getActiveWorkspace(const std::string&) -> Workspace;
auto getActiveWorkspace() -> Workspace;
void onEvent(const std::string&) override;
void queryActiveWorkspace();
void setClass(const std::string&, bool enable);
bool separate_outputs;
std::mutex mutex_;
const Bar& bar_;
util::JsonParser parser_;
std::string lastView;
WindowData window_data_;
Workspace workspace_;
std::string solo_class_;
std::string last_solo_class_;
bool solo_;
bool all_floating_;
bool swallowing_;
bool fullscreen_;
};
} // namespace waybar::modules::hyprland

View File

@ -0,0 +1,64 @@
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <memory>
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
namespace waybar::modules::hyprland {
struct WorkspaceDto {
int id;
static WorkspaceDto parse(const Json::Value& value);
};
class Workspace {
public:
Workspace(int id);
Workspace(WorkspaceDto dto);
int id() const { return id_; };
int active() const { return active_; };
std::string& select_icon(std::map<std::string, std::string>& icons_map);
void set_active(bool value = true) { active_ = value; };
Gtk::Button& button() { return button_; };
void update(const std::string& format, const std::string& icon);
private:
int id_;
bool active_;
Gtk::Button button_;
Gtk::Box content_;
Gtk::Label label_;
};
class Workspaces : public AModule, public EventHandler {
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Workspaces();
void update() override;
void init();
private:
void onEvent(const std::string&) override;
void sort_workspaces();
void create_workspace(int id);
void remove_workspace(int id);
std::string format_;
std::map<std::string, std::string> icons_map_;
bool with_icon_;
int active_workspace_id;
std::vector<std::unique_ptr<Workspace>> workspaces_;
std::vector<int> workspaces_to_create_;
std::vector<int> workspaces_to_remove_;
std::mutex mutex_;
const Bar& bar_;
Gtk::Box box_;
};
} // namespace waybar::modules::hyprland

View File

@ -24,12 +24,15 @@ class Image : public AModule {
private:
void delayWorker();
void handleEvent();
void parseOutputRaw();
Gtk::Box box_;
Gtk::Image image_;
std::string path_;
std::string tooltip_;
int size_;
int interval_;
util::command::res output_;
util::SleeperThread thread_;
};

View File

@ -67,6 +67,8 @@ class Mpris : public ALabel {
int title_len_;
int dynamic_len_;
std::vector<std::string> dynamic_prio_;
std::vector<std::string> dynamic_order_;
std::string dynamic_separator_;
bool truncate_hours_;
bool tooltip_len_limits_;
std::string ellipsis_;
@ -80,6 +82,7 @@ class Mpris : public ALabel {
std::string lastPlayer;
util::SleeperThread thread_;
std::chrono::time_point<std::chrono::system_clock> last_update_;
};
} // namespace waybar::modules::mpris

View File

@ -78,7 +78,6 @@ class Network : public ALabel {
int32_t signal_strength_dbm_;
uint8_t signal_strength_;
std::string signal_strength_app_;
float frequency_;
uint32_t route_priority;
util::SleeperThread thread_;
@ -86,6 +85,7 @@ class Network : public ALabel {
#ifdef WANT_RFKILL
util::Rfkill rfkill_;
#endif
float frequency_;
};
} // namespace waybar::modules

View File

@ -8,6 +8,7 @@
#include <cstring>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include "ipc.hpp"

View File

@ -4,7 +4,7 @@
#include <tuple>
#include "AIconLabel.hpp"
#include "AAppIconLabel.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
@ -12,7 +12,7 @@
namespace waybar::modules::sway {
class Window : public AIconLabel, public sigc::trackable {
class Window : public AAppIconLabel, public sigc::trackable {
public:
Window(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Window() = default;
@ -25,8 +25,6 @@ class Window : public AIconLabel, public sigc::trackable {
std::tuple<std::size_t, int, int, std::string, std::string, std::string, std::string, std::string>
getFocusedNode(const Json::Value& nodes, std::string& output);
void getTree();
void updateAppIconName();
void updateAppIcon();
const Bar& bar_;
std::string window_;
@ -37,9 +35,6 @@ class Window : public AIconLabel, public sigc::trackable {
std::string old_app_id_;
std::size_t app_nb_;
std::string shell_;
unsigned app_icon_size_{24};
bool update_app_icon_{true};
std::string app_icon_name_;
int floating_count_;
util::JsonParser parser_;
std::mutex mutex_;

View File

@ -74,6 +74,7 @@ class UPower : public AModule {
bool showAltText;
bool upowerRunning;
guint upowerWatcher_id;
std::string nativePath_;
};
} // namespace waybar::modules::upower

View File

@ -27,6 +27,8 @@ class Wireplumber : public ALabel {
static void onMixerChanged(waybar::modules::Wireplumber* self, uint32_t id);
static void onDefaultNodesApiChanged(waybar::modules::Wireplumber* self);
bool handleScroll(GdkEventScroll* e) override;
WpCore* wp_core_;
GPtrArray* apis_;
WpObjectManager* om_;
@ -36,6 +38,7 @@ class Wireplumber : public ALabel {
uint32_t pending_plugins_;
bool muted_;
double volume_;
double min_step_;
uint32_t node_id_{0};
std::string node_name_;
};

14
include/util/gtk_icon.hpp Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <gtkmm/icontheme.h>
#include <mutex>
#include <string>
class DefaultGtkIconThemeWrapper {
private:
static std::mutex default_theme_mutex;
public:
static bool has_icon(const std::string&);
static Glib::RefPtr<Gdk::Pixbuf> load_icon(const char*, int, Gtk::IconLookupFlags);
};

View File

@ -0,0 +1,9 @@
#pragma once
#include "SafeSignal.hpp"
namespace waybar::util {
// Get a signal emited with value true when entering sleep, and false when exiting
SafeSignal<bool>& prepare_for_sleep();
} // namespace waybar::util

View File

@ -6,6 +6,8 @@
#include <functional>
#include <thread>
#include "prepare_for_sleep.h"
namespace waybar::util {
/**
@ -33,7 +35,11 @@ class SleeperThread {
signal_ = false;
func();
}
}} {}
}} {
connection_ = prepare_for_sleep().connect([this](bool sleep) {
if (not sleep) wake_up();
});
}
SleeperThread& operator=(std::function<void()> func) {
thread_ = std::thread([this, func] {
@ -42,6 +48,11 @@ class SleeperThread {
func();
}
});
if (connection_.empty()) {
connection_ = prepare_for_sleep().connect([this](bool sleep) {
if (not sleep) wake_up();
});
}
return *this;
}
@ -61,7 +72,7 @@ class SleeperThread {
return condvar_.wait_until(lk, time_point, [this] { return signal_ || !do_run_; });
}
auto wake_up() {
void wake_up() {
{
std::lock_guard<std::mutex> lck(mutex_);
signal_ = true;
@ -84,6 +95,7 @@ class SleeperThread {
}
~SleeperThread() {
connection_.disconnect();
stop();
if (thread_.joinable()) {
thread_.join();
@ -96,6 +108,7 @@ class SleeperThread {
std::mutex mutex_;
bool do_run_ = true;
bool signal_ = false;
sigc::connection connection_;
};
} // namespace waybar::util

View File

@ -1,105 +1,167 @@
waybar-clock(5)
waybar-clock(5) "waybar-clock" "User Manual"
# NAME
waybar - clock module
clock
# DESCRIPTION
The *clock* module displays the current date and time.
*clock* module displays current date and time
# FILES
$XDG_CONFIG_HOME/waybar/config ++
Per user configuration file
# CONFIGURATION
*interval*: ++
typeof: integer ++
default: 60 ++
The interval in which the information gets polled.
1. Addressed by *clock*
[- *Option*
:- *Typeof*
:- *Default*
:- *Description*
|[ *interval*
:[ integer
:[ 60
:[ The interval in which the information gets polled
|[ *format*
:[ string
:[ *{:%H:%M}*
:[ The format, how the date and time should be displayed. See format options below
|[ *timezone*
:[ string
:[
:[ The timezone to display the time in, e.g. America/New_York. "" represents
the system's local timezone. See Wikipedia's unofficial list of timezones <https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>
|[ *timezones*
:[ list of strings
:[
:[ A list of timezones (as in *timezone*) to use for time display, changed using
the scroll wheel. Do not specify *timezone* option when *timezones* is specified.
"" represents the system's local timezone
|[ *locale*
:[ string
:[
:[ A locale to be used to display the time. Intended to render times in custom
timezones with the proper language and format
|[ *max-length*
:[ integer
:[
:[ The maximum length in character the module should display
|[ *rotate*
:[ integer
:[
:[ Positive value to rotate the text label
|[ *on-click*
:[ string
:[
:[ Command to execute when clicked on the module
|[ *on-click-middle*
:[ string
:[
:[ Command to execute when you middle clicked on the module using mousewheel
|[ *on-click-right*
:[ string
:[
:[ Command to execute when you right clicked on the module
|[ *on-scroll-up*
:[ string
:[
:[ Command to execute when scrolling up on the module
|[ *on-scroll-down*
:[ string
:[
:[ Command to execute when scrolling down on the module
|[ *smooth-scrolling-threshold*
:[ double
:[
:[ Threshold to be used when scrolling
|[ *tooltip*
:[ bool
:[ true
:[ Option to enable tooltip on hover
|[ *tooltip-format*
:[ string
:[ same as format
:[ Tooltip on hover
*format*: ++
typeof: string ++
default: {:%H:%M} ++
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.
View all valid format options in *strftime(3)* or have a look <https://fmt.dev/latest/syntax.html#chrono-specs>
*timezone*: ++
typeof: string ++
default: inferred local timezone ++
The timezone to display the time in, e.g. America/New_York. ++
This field will be ignored if *timezones* field is set and have at least one value.
2. Addressed by *clock: calendar*
[- *Option*
:- *Typeof*
:- *Default*
:- *Description*
|[ *mode*
:[ string
:[ month
:[ Calendar view mode. Possible values: year|month
|[ *mode-mon-col*
:[ integer
:[ 3
:[ Relevant for *mode=year*. Count of months per row
|[ *weeks-pos*
:[ integer
:[
:[ The position where week numbers should be displayed. Disabled when is empty.
Possible values: left|right
|[ *on-scroll*
:[ integer
:[ 1
:[ Value to scroll months/years forward/backward. Can be negative. Is
configured under *on-scroll* option
*timezones*: ++
typeof: list of strings ++
A list of timezones to use for time display, changed using the scroll wheel. ++
Use "" to represent the system's local timezone. Using %Z in the format or tooltip format is useful to track which time zone is currently displayed.
3. Adressed by *clock: calendar: format*
[- *Option*
:- *Typeof*
:- *Default*
:- *Description*
|[ *months*
:[ string
:[
:[ Format is applied to months header(January, February,...etc.)
|[ *days*
:[ string
:[
:[ Format is applied to days
|[ *weeks*
:[ string
:[ *{:%U}*
:[ Format is applied to week numbers. When weekday format is not provided then
is used default format: '{:%W}' when week starts with Monday, '{:%U}' otherwise
|[ *weekdays*
:[ string
:[
:[ Format is applied to weeks header(Su,Mo,...etc.)
|[ *today*
:[ string
:[ *<b><u>{}</u></b>*
:[ Format is applied to Today
*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.
## Actions
*today-format*: ++
typeof: string ++
default: <b><u>{}</u></b> ++
The format of today's date in the calendar.
*max-length*: ++
typeof: integer ++
The maximum length in character the module should display.
*min-length*: ++
typeof: integer ++
The minimum length in characters the module should take up.
*align*: ++
typeof: float ++
The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text.
*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
*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 ++
Command to execute when you right clicked on the module.
*on-update*: ++
typeof: string ++
Command to execute when the module is updated.
*on-scroll-up*: ++
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.
*smooth-scrolling-threshold*: ++
typeof: double ++
Threshold to be used when scrolling.
*tooltip*: ++
typeof: bool ++
default: true ++
Option to disable tooltip on hover.
View all valid format options in *strftime(3)*.
[- *String*
:- *Action*
|[ *mode*
:[ Switch calendar mode between year/month
|[ *tz_up*
:[ Switch to the next provided time zone
|[ *tz_down*
:[ Switch to the previous provided time zone
|[ *shift_up*
:[ Switch to the next calendar month/year
|[ *shift_down*
:[ Switch to the previous calendar month/year
# FORMAT REPLACEMENTS
*{calendar}*: Current month calendar
*{timezoned_time_list}*: List of time in the rest timezones, if more than one timezone is set in the config
- *{calendar}*: Current month calendar
- *{timezoned_time_list}*: List of time in the rest timezones, if more than one timezone is set in the config
# EXAMPLES
1. General
```
"clock": {
"interval": 60,
@ -108,6 +170,101 @@ View all valid format options in *strftime(3)*.
}
```
2. Calendar
```
"clock": {
"format": "{:%H:%M}  ",
"format-alt": "{:%A, %B %d, %Y (%R)}  ",
"tooltip-format": "<tt><small>{calendar}</small></tt>",
"calendar": {
"mode" : "year",
"mode-mon-col" : 3,
"weeks-pos" : "right",
"on-scroll" : 1,
"on-click-right": "mode",
"format": {
"months": "<span color='#ffead3'><b>{}</b></span>",
"days": "<span color='#ecc6d9'><b>{}</b></span>",
"weeks": "<span color='#99ffdd'><b>W{}</b></span>",
"weekdays": "<span color='#ffcc66'><b>{}</b></span>",
"today": "<span color='#ff6699'><b><u>{}</u></b></span>"
}
},
"actions": {
"on-click-right": "mode",
"on-click-forward": "tz_up",
"on-click-backward": "tz_down",
"on-scroll-up": "shift_up",
"on-scroll-down": "shift_down"
}
},
```
3. Full date on hover
```
"clock": {
"interval": 60,
"tooltip": true,
"format": "{:%H.%M}",
"tooltip-format": "{:%Y-%m-%d}",
}
```
# STYLE
- *#clock*
# Troubleshooting
If clock module is disabled at startup with locale::facet::\_S\_create\_c\_locale ++
name not valid error message try one of the followings:
- check if LC_TIME is set properly (glibc)
- set locale to C in the config file (musl)
The locale option must be set for {calendar} to use the correct start-of-week, regardless of system locale.
## Calendar in Chinese. Alignment
In order to have aligned Chinese calendar there are some useful recommendations:
. Use "WenQuanYi Zen Hei Mono" which is provided in most Linux distributions
. Try different font sizes and find best for you. size = 9pt should be fine
. In case when "WenQuanYi Zen Hei Mono" font is used disable monospace font pango tag
Example of working config
```
"clock": {
"format": "{:%H:%M}  ",
"format-alt": "{:%A, %B %d, %Y (%R)}  ",
"tooltip-format": "\n<span size='9pt' font='WenQuanYi Zen Hei Mono'>{calendar}</span>",
"calendar": {
"mode" : "year",
"mode-mon-col" : 3,
"weeks-pos" : "right",
"on-scroll" : 1,
"on-click-right": "mode",
"format": {
"months": "<span color='#ffead3'><b>{}</b></span>",
"days": "<span color='#ecc6d9'><b>{}</b></span>",
"weeks": "<span color='#99ffdd'><b>W{}</b></span>",
"weekdays": "<span color='#ffcc66'><b>{}</b></span>",
"today": "<span color='#ff6699'><b><u>{}</u></b></span>"
}
},
"actions": {
"on-click-right": "mode",
"on-click-forward": "tz_up",
"on-click-backward": "tz_down",
"on-scroll-up": "shift_up",
"on-scroll-down": "shift_down"
}
},
```
# AUTHOR
Alexis Rouillard <contact@arouillard.fr>

View File

@ -14,13 +14,28 @@ Addressed by *hyprland/window*
*format*: ++
typeof: string ++
default: {} ++
default: {title} ++
The format, how information should be displayed. On {} the current window title is displayed.
*rewrite*: ++
typeof: object ++
Rules to rewrite window title. See *rewrite rules*.
*separate-outputs*: ++
typeof: bool ++
Show the active window of the monitor the bar belongs to, instead of the focused window.
# FORMAT REPLACEMENTS
See the output of "hyprctl clients" for examples
*{title}*: The current title of the focused window.
*{initialTitle}*: The initial title of the focused window.
*{class}*: The current class of the focused window.
*{initialClass}*: The initial class of the focused window.
# REWRITE RULES
*rewrite* is an object where keys are regular expressions and values are
@ -48,3 +63,17 @@ Invalid expressions (e.g., mismatched parentheses) are skipped.
# STYLE
- *#window*
- *window#waybar.empty #window* When no windows are in the workspace
The following classes are applied to the entire Waybar rather than just the
window widget:
- *window#waybar.empty* When no windows are in the workspace
- *window#waybar.solo* When one tiled window is visible in the workspace
(floating windows may be present)
- *window#waybar.<app_id>* Where *<app_id>* is the *class* (e.g. *chromium*) of
the solo tiled window in the workspace (use *hyprctl clients* to see classes)
- *window#waybar.floating* When there are only floating windows in the workspace
- *window#waybar.fullscreen* When there is a fullscreen window in the workspace;
useful with Hyprland's *fullscreen, 1* mode
- *window#waybar.swallowing* When there is a swallowed window in the workspace

View File

@ -0,0 +1,59 @@
waybar-wlr-workspaces(5)
# NAME
waybar - hyprland workspaces module
# DESCRIPTION
The *workspaces* module displays the currently used workspaces in hyprland compositor.
# CONFIGURATION
Addressed by *hyprland/workspaces*
*format*: ++
typeof: string ++
default: {id} ++
The format, how information should be displayed.
*format-icons*: ++
typeof: array ++
Based on the workspace id and state, the corresponding icon gets selected. See *icons*.
# FORMAT REPLACEMENTS
*{id}*: id of workspace assigned by compositor
*{icon}*: Icon, as defined in *format-icons*.
# ICONS
Additional to workspace name matching, the following *format-icons* can be set.
- *default*: Will be shown, when no string match is found.
- *active*: Will be shown, when workspace is active
# EXAMPLES
```
"wlr/workspaces": {
"format": "{name}: {icon}",
"format-icons": {
"1": "",
"2": "",
"3": "",
"4": "",
"5": "",
"active": "",
"default": ""
},
"sort-by-number": true
}
```
# Style
- *#workspaces*
- *#workspaces button*
- *#workspaces button.active*

View File

@ -57,6 +57,20 @@ The *image* module displays an image from a path.
typeof: double ++
Threshold to be used when scrolling.
*tooltip*: ++
typeof: bool ++
default: true ++
Option to enable tooltip on hover.
# SCRIPT OUTPUT
Similar to the *custom* module, output values of the script is *newline* separated.
The following is the output format:
```
$path\\n$tooltip
```
# EXAMPLES
```

View File

@ -71,11 +71,27 @@ The *mpris* module displays currently playing media via libplayerctl.
something less than or equal to this value, so the title will always be ++
displayed.
*dynamic-priority*: ++
*dynamic-order*: ++
typeof: []string ++
default: ["title", "length", "position", "artist", "album"] ++
Priority of the tags when truncating the Dynamic tag (absence in this
list means force inclusion).
default: ["title", "artist", "album", "position", "length"] ++
Order of the tags shown by Dynamic tag. The position and length tags ++
will always be combined in the format [{position}/{length}]. The order ++
of these tags in relation to other tags will be determined based on the ++
declaration of the first among the two tags. Absence in this list means ++
force exclusion.
*dynamic-importance-order*: ++
typeof: []string ++
default: ["title", "artist", "album", "position", "length"] ++
Priority of the tags when truncating the Dynamic tag. The final ones ++
will be the first to be truncated. Absence in this list means force ++
inclusion.
*dynamic-separator*: ++
typeof: string ++
default: " - " ++
These characters will be used to separate two different tags, except ++
when one of these tags is position and length.
*truncate-hours*: ++
typeof: bool ++

View File

@ -51,12 +51,12 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu
The maximum length in character the module should display.
*min-length*: ++
typeof: integer ++
The minimum length in characters the module should take up.
typeof: integer ++
The minimum length in characters the module should take up.
*align*: ++
typeof: float ++
The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text.
typeof: float ++
The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text.
*scroll-step*: ++
typeof: float ++
@ -91,6 +91,10 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu
typeof: double ++
Threshold to be used when scrolling.
*reverse-scrolling*: ++
typeof: bool ++
Option to reverse the scroll direction.
*tooltip*: ++
typeof: bool ++
default: true ++

View File

@ -84,7 +84,7 @@ Addressed by *sway/window*
typeof: bool ++
default: false ++
If the workspace itself is focused and the workspace contains nodes or floating_nodes, show the workspace name. If not set, text remains empty but styles according to nodes in the workspace are still applied.
*rewrite*: ++
typeof: object ++
Rules to rewrite the module format output. See *rewrite rules*.
@ -136,6 +136,10 @@ Invalid expressions (e.g., mismatched parentheses) are skipped.
# STYLE
- *#window*
The following classes are applied to the entire Waybar rather than just the
window widget:
- *window#waybar.empty* When no windows are in the workspace, or screen is not focused and offscreen-css option is not set
- *window#waybar.solo* When one tiled window is in the workspace
- *window#waybar.floating* When there are only floating windows in the workspace

View File

@ -77,6 +77,11 @@ Addressed by *sway/workspaces*
typeof: bool ++
Whether to sort workspaces alphabetically. Please note this can make "swaymsg workspace prev/next" move to workspaces inconsistent with the ordering shown in Waybar.
warp-on-scroll: ++
typeof: bool ++
default: true ++
If set to false, you can scroll to cycle through workspaces without mouse warping being enabled. If set to true this behaviour is disabled.
# FORMAT REPLACEMENTS
*{value}*: Name of the workspace, as defined by sway.
@ -87,6 +92,8 @@ Addressed by *sway/workspaces*
*{index}*: Index of the workspace.
*{output}*: Output where the workspace is located.
# ICONS
Additional to workspace name matching, the following *format-icons* can be set.

View File

@ -19,6 +19,8 @@ Addressed by *temperature*
*hwmon-path*: ++
typeof: string ++
The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*.
This can also be an array of strings. In this case, waybar will check each item in the array and use the first valid one.
This is suitable if you want to share the same configuration file among different machines with different hardware configurations.
*hwmon-path-abs*: ++
typeof: string ++
@ -117,7 +119,7 @@ Addressed by *temperature*
```
"temperature": {
// "thermal-zone": 2,
// "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input",
// "hwmon-path": ["/sys/class/hwmon/hwmon2/temp1_input", "/sys/class/thermal/thermal_zone0/temp"],
// "critical-threshold": 80,
// "format-critical": "{temperatureC}°C ",
"format": "{temperatureC}°C "

View File

@ -11,6 +11,12 @@ compatible devices in the tooltip.
# CONFIGURATION
*native-path*: ++
typeof: string ++
default: ++
The battery to monitor. Refer to the https://upower.freedesktop.org/docs/UpDevice.html#UpDevice--native-path ++
Can be obtained using `upower --dump`
*icon-size*: ++
typeof: integer ++
default: 20 ++
@ -68,6 +74,25 @@ depending on the charging state.
"tooltip-spacing": 20
}
```
```
"upower": {
"native-path": "/org/bluez/hci0/dev_D4_AE_41_38_D0_EF",
"icon-size": 20,
"hide-if-empty": true,
"tooltip": true,
"tooltip-spacing": 20
}
```
```
"upower": {
"native-path": "battery_sony_controller_battery_d0o27o88o32ofcoee",
"icon-size": 20,
"hide-if-empty": true,
"tooltip": true,
"tooltip-spacing": 20
}
```
# STYLE

View File

@ -11,59 +11,77 @@ The *wireplumber* module displays the current volume reported by WirePlumber.
# CONFIGURATION
*format*: ++
typeof: string ++
default: *{volume}%* ++
The format, how information should be displayed. This format is used when other formats aren't specified.
typeof: string ++
default: *{volume}%* ++
The format, how information should be displayed. This format is used when other formats aren't specified.
*format-muted*: ++
typeof: string ++
This format is used when the sound is muted.
typeof: string ++
This format is used when the sound is muted.
*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: *{node_name}* ++
The format of information displayed in the tooltip.
typeof: string ++
default: *{node_name}* ++
The format of information displayed in the tooltip.
*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
typeof: integer ++
Positive value to rotate the text label.
*states*: ++
typeof: object ++
A number of volume states which get activated on certain volume levels. See *waybar-states(5)*.
typeof: object ++
A number of volume states which get activated on certain volume levels. See *waybar-states(5)*.
*max-length*: ++
typeof: integer ++
The maximum length in character the module should display.
typeof: integer ++
The maximum length in character the module should display.
*min-length*: ++
typeof: integer ++
The minimum length in characters the module should take up.
typeof: integer ++
The minimum length in characters the module should take up.
*align*: ++
typeof: float ++
The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text.
typeof: float ++
The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text.
*scroll-step*: ++
typeof: float ++
default: 1.0 ++
The speed in which to change the volume when scrolling.
*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.
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-update*: ++
typeof: string ++
Command to execute when the module is updated.
typeof: string ++
Command to execute when the module is updated.
*on-scroll-up*: ++
typeof: string ++
Command to execute when scrolling up on the module. This replaces the default behaviour of volume control.
*on-scroll-down*: ++
typeof: string ++
Command to execute when scrolling down on the module. This replaces the default behaviour of volume control.
*max-volume*: ++
typeof: float ++
default: 100 ++
The maximum volume that can be set, in percentage.
# FORMAT REPLACEMENTS

View File

@ -81,11 +81,15 @@ Addressed by *wlr/taskbar*
typeof: object ++
Dictionary of app_id to be replaced with
*rewrite*: ++
typeof: object ++
Rules to rewrite the module format output. See *rewrite rules*.
# FORMAT REPLACEMENTS
*{icon}*: The icon of the application.
*{title}*: The application name as in desktop file if appropriate desktop fils found, otherwise same as {app_id}
*{name}*: The application name as in desktop file if appropriate desktop fils found, otherwise same as {app_id}
*{title}*: The title of the application.
@ -109,6 +113,18 @@ Addressed by *wlr/taskbar*
*close*: Close the application.
# REWRITE RULES
*rewrite* is an object where keys are regular expressions and values are
rewrite rules if the expression matches. Rules may contain references to
captures of the expression.
Regular expression and replacement follow ECMA-script rules.
If no expression matches, the format output is left unchanged.
Invalid expressions (e.g., mismatched parentheses) are skipped.
# EXAMPLES
```
@ -124,6 +140,10 @@ Addressed by *wlr/taskbar*
],
"app_ids-mapping": {
"firefoxdeveloperedition": "firefox-developer-edition"
},
"rewrite": {
"Firefox Web Browser": "Firefox",
"Foot Server": "Terminal"
}
}
```

View File

@ -65,7 +65,7 @@ Addressed by *wlr/workspaces*
Additional to workspace name matching, the following *format-icons* can be set.
- *default*: Will be shown, when no string match is found.
- *focused*: Will be shown, when workspace is focused
- *active*: Will be shown, when workspace is active
# EXAMPLES
@ -78,7 +78,7 @@ Additional to workspace name matching, the following *format-icons* can be set.
"3": "",
"4": "",
"5": "",
"focused": "",
"active": "",
"default": ""
},
"sort-by-number": true

View File

@ -30,6 +30,7 @@ Also a minimal example configuration can be found on the at the bottom of this m
*output* ++
typeof: string|array ++
Specifies on which screen this bar will be displayed. Exclamation mark(*!*) can be used to exclude specific output.
Output specification follows sway's and can either be the output port such as "HDMI-A-1" or a string consisting of the make, model and serial such as "Some Company ABC123 0x00000000". See *sway-output(5)* for details.
In an array, star '*\**' can be used at the end to accept all outputs, in case all previous entries are exclusions.
*position* ++
@ -78,7 +79,12 @@ Also a minimal example configuration can be found on the at the bottom of this m
Selects one of the preconfigured display modes. This is an equivalent of the sway-bar(5) *mode* command and supports the same values: *dock*, *hide*, *invisible*, *overlay*. ++
Note: *hide* and *invisible* modes may be not as useful without Sway IPC.
modifier-reset ++
*start_hidden* ++
typeof: bool ++
default: *false* ++
Option to start the bar hidden.
*modifier-reset* ++
typeof: string ++
default: *press*
Defines the timing of modifier key to reset the bar visibility.
@ -288,3 +294,7 @@ Valid options for the (optional) "orientation" property are: "horizontal", "vert
- *waybar-wlr-workspaces(5)*
- *waybar-temperature(5)*
- *waybar-tray(5)*
# SEE ALSO
*sway-output(5)*

View File

@ -1,6 +1,6 @@
project(
'waybar', 'cpp', 'c',
version: '0.9.18',
version: '0.9.20',
license: 'MIT',
meson_version: '>= 0.50.0',
default_options : [
@ -159,6 +159,7 @@ src_files = files(
'src/AModule.cpp',
'src/ALabel.cpp',
'src/AIconLabel.cpp',
'src/AAppIconLabel.cpp',
'src/modules/custom.cpp',
'src/modules/disk.cpp',
'src/modules/idle_inhibitor.cpp',
@ -170,9 +171,11 @@ src_files = files(
'src/client.cpp',
'src/config.cpp',
'src/group.cpp',
'src/util/prepare_for_sleep.cpp',
'src/util/ustring_clen.cpp',
'src/util/sanitize_str.cpp',
'src/util/rewrite_string.cpp'
'src/util/rewrite_string.cpp',
'src/util/gtk_icon.cpp'
)
inc_dirs = ['include']
@ -240,6 +243,7 @@ if true
src_files += 'src/modules/hyprland/window.cpp'
src_files += 'src/modules/hyprland/language.cpp'
src_files += 'src/modules/hyprland/submap.cpp'
src_files += 'src/modules/hyprland/workspaces.cpp'
endif
if libnl.found() and libnlgen.found()

View File

@ -1,60 +1,11 @@
{ lib
, stdenv
, fetchFromGitHub
, meson
, pkg-config
, ninja
, wrapGAppsHook
, wayland
, wlroots
, gtkmm3
, libsigcxx
, jsoncpp
, scdoc
, spdlog
, gtk-layer-shell
, howard-hinnant-date
, libinotify-kqueue
, libxkbcommon
, evdevSupport ? true
, libevdev
, inputSupport ? true
, libinput
, jackSupport ? true
, libjack2
, mpdSupport ? true
, libmpdclient
, nlSupport ? true
, libnl
, pulseSupport ? true
, libpulseaudio
, rfkillSupport ? true
, runTests ? true
, catch2_3
, sndioSupport ? true
, sndio
, swaySupport ? true
, sway
, traySupport ? true
, libdbusmenu-gtk3
, udevSupport ? true
, udev
, upowerSupport ? true
, upower
, wireplumberSupport ? true
, wireplumber
, withMediaPlayer ? false
, glib
, gobject-introspection
, python3
, playerctl
, waybar
, version
}:
stdenv.mkDerivation rec {
pname = "waybar";
waybar.overrideAttrs (prev: {
inherit version;
# version = "0.9.16";
# version = "0.9.17";
src = lib.cleanSourceWith {
filter = name: type:
@ -66,74 +17,4 @@ stdenv.mkDerivation rec {
);
src = lib.cleanSource ../.;
};
nativeBuildInputs = [
meson
ninja
pkg-config
scdoc
wrapGAppsHook
] ++ lib.optional withMediaPlayer gobject-introspection;
propagatedBuildInputs = lib.optionals withMediaPlayer [
glib
playerctl
python3.pkgs.pygobject3
];
strictDeps = false;
buildInputs = with lib;
[ wayland wlroots gtkmm3 libsigcxx jsoncpp spdlog gtk-layer-shell howard-hinnant-date libxkbcommon ]
++ optional (!stdenv.isLinux) libinotify-kqueue
++ optional evdevSupport libevdev
++ optional inputSupport libinput
++ optional jackSupport libjack2
++ optional mpdSupport libmpdclient
++ optional nlSupport libnl
++ optional pulseSupport libpulseaudio
++ optional sndioSupport sndio
++ optional swaySupport sway
++ optional traySupport libdbusmenu-gtk3
++ optional udevSupport udev
++ optional upowerSupport upower
++ optional wireplumberSupport wireplumber;
checkInputs = [ catch2_3 ];
doCheck = runTests;
mesonFlags = (lib.mapAttrsToList
(option: enable: "-D${option}=${if enable then "enabled" else "disabled"}")
{
dbusmenu-gtk = traySupport;
jack = jackSupport;
libinput = inputSupport;
libnl = nlSupport;
libudev = udevSupport;
mpd = mpdSupport;
pulseaudio = pulseSupport;
rfkill = rfkillSupport;
sndio = sndioSupport;
tests = runTests;
upower_glib = upowerSupport;
wireplumber = wireplumberSupport;
}
) ++ [
"-Dsystemd=disabled"
"-Dgtk-layer-shell=enabled"
"-Dman-pages=enabled"
];
preFixup = lib.optionalString withMediaPlayer ''
cp $src/resources/custom_modules/mediaplayer.py $out/bin/waybar-mediaplayer.py
wrapProgram $out/bin/waybar-mediaplayer.py \
--prefix PYTHONPATH : "$PYTHONPATH:$out/${python3.sitePackages}"
'';
meta = with lib; {
description = "Highly customizable Wayland bar for Sway and Wlroots based compositors";
license = licenses.mit;
maintainers = with maintainers; [ FlorianFranzen minijackson synthetica lovesegfault ];
platforms = platforms.unix;
homepage = "https://github.com/alexays/waybar";
};
}
})

View File

@ -12,6 +12,7 @@
// "sway/workspaces": {
// "disable-scroll": true,
// "all-outputs": true,
// "warp-on-scroll": false,
// "format": "{name}: {icon}",
// "format-icons": {
// "1": "",

133
src/AAppIconLabel.cpp Normal file
View File

@ -0,0 +1,133 @@
#include "AAppIconLabel.hpp"
#include <gdkmm/pixbuf.h>
#include <glibmm/fileutils.h>
#include <glibmm/keyfile.h>
#include <glibmm/miscutils.h>
#include <spdlog/spdlog.h>
#include <filesystem>
#include <optional>
#include "util/gtk_icon.hpp"
namespace waybar {
AAppIconLabel::AAppIconLabel(const Json::Value& config, const std::string& name,
const std::string& id, const std::string& format, uint16_t interval,
bool ellipsize, bool enable_click, bool enable_scroll)
: AIconLabel(config, name, id, format, interval, ellipsize, enable_click, enable_scroll) {
// Icon size
if (config["icon-size"].isUInt()) {
app_icon_size_ = config["icon-size"].asUInt();
}
image_.set_pixel_size(app_icon_size_);
}
std::optional<std::string> getDesktopFilePath(const std::string& app_identifier,
const std::string& alternative_app_identifier) {
const auto data_dirs = Glib::get_system_data_dirs();
for (const auto& data_dir : data_dirs) {
const auto data_app_dir = data_dir + "applications/";
auto desktop_file_path = data_app_dir + app_identifier + ".desktop";
if (std::filesystem::exists(desktop_file_path)) {
return desktop_file_path;
}
if (!alternative_app_identifier.empty()) {
desktop_file_path = data_app_dir + alternative_app_identifier + ".desktop";
if (std::filesystem::exists(desktop_file_path)) {
return desktop_file_path;
}
}
}
return {};
}
std::optional<Glib::ustring> getIconName(const std::string& app_identifier,
const std::string& alternative_app_identifier) {
const auto desktop_file_path = getDesktopFilePath(app_identifier, alternative_app_identifier);
if (!desktop_file_path.has_value()) {
// Try some heuristics to find a matching icon
if (DefaultGtkIconThemeWrapper::has_icon(app_identifier)) {
return app_identifier;
}
const auto app_identifier_desktop = app_identifier + "-desktop";
if (DefaultGtkIconThemeWrapper::has_icon(app_identifier_desktop)) {
return app_identifier_desktop;
}
const auto to_lower = [](const std::string& str) {
auto str_cpy = str;
std::transform(str_cpy.begin(), str_cpy.end(), str_cpy.begin(),
[](unsigned char c) { return std::tolower(c); });
return str;
};
const auto first_space = app_identifier.find_first_of(' ');
if (first_space != std::string::npos) {
const auto first_word = to_lower(app_identifier.substr(0, first_space));
if (DefaultGtkIconThemeWrapper::has_icon(first_word)) {
return first_word;
}
}
const auto first_dash = app_identifier.find_first_of('-');
if (first_dash != std::string::npos) {
const auto first_word = to_lower(app_identifier.substr(0, first_dash));
if (DefaultGtkIconThemeWrapper::has_icon(first_word)) {
return first_word;
}
}
return {};
}
try {
Glib::KeyFile desktop_file;
desktop_file.load_from_file(desktop_file_path.value());
return desktop_file.get_string("Desktop Entry", "Icon");
} catch (Glib::FileError& error) {
spdlog::warn("Error while loading desktop file {}: {}", desktop_file_path.value(),
error.what().c_str());
} catch (Glib::KeyFileError& error) {
spdlog::warn("Error while loading desktop file {}: {}", desktop_file_path.value(),
error.what().c_str());
}
return {};
}
void AAppIconLabel::updateAppIconName(const std::string& app_identifier,
const std::string& alternative_app_identifier) {
if (!iconEnabled()) {
return;
}
const auto icon_name = getIconName(app_identifier, alternative_app_identifier);
if (icon_name.has_value()) {
app_icon_name_ = icon_name.value();
} else {
app_icon_name_ = "";
}
update_app_icon_ = true;
}
void AAppIconLabel::updateAppIcon() {
if (update_app_icon_) {
update_app_icon_ = false;
if (app_icon_name_.empty()) {
image_.set_visible(false);
} else {
image_.set_from_icon_name(app_icon_name_, Gtk::ICON_SIZE_INVALID);
image_.set_visible(true);
}
}
}
auto AAppIconLabel::update() -> void {
updateAppIcon();
AIconLabel::update();
}
} // namespace waybar

View File

@ -97,11 +97,21 @@ bool AModule::handleToggle(GdkEventButton* const& e) {
}
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
// only affects up/down
bool reverse = config_["reverse-scrolling"].asBool();
bool reverse_mouse = config_["reverse-mouse-scrolling"].asBool();
// ignore reverse-scrolling if event comes from a mouse wheel
GdkDevice* device = gdk_event_get_source_device((GdkEvent*)e);
if (device != NULL && gdk_device_get_source(device) == GDK_SOURCE_MOUSE) {
reverse = reverse_mouse;
}
switch (e->direction) {
case GDK_SCROLL_UP:
return SCROLL_DIR::UP;
return reverse ? SCROLL_DIR::DOWN : SCROLL_DIR::UP;
case GDK_SCROLL_DOWN:
return SCROLL_DIR::DOWN;
return reverse ? SCROLL_DIR::UP : SCROLL_DIR::DOWN;
case GDK_SCROLL_LEFT:
return SCROLL_DIR::LEFT;
case GDK_SCROLL_RIGHT:
@ -118,9 +128,9 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
}
if (distance_scrolled_y_ < -threshold) {
dir = SCROLL_DIR::UP;
dir = reverse ? SCROLL_DIR::DOWN : SCROLL_DIR::UP;
} else if (distance_scrolled_y_ > threshold) {
dir = SCROLL_DIR::DOWN;
dir = reverse ? SCROLL_DIR::UP : SCROLL_DIR::DOWN;
} else if (distance_scrolled_x_ > threshold) {
dir = SCROLL_DIR::RIGHT;
} else if (distance_scrolled_x_ < -threshold) {

View File

@ -593,6 +593,10 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
setMode(MODE_DEFAULT);
}
if (config["start_hidden"].asBool()) {
setVisible(false);
}
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap));
#if HAVE_SWAY

View File

@ -83,6 +83,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
if (ref == "hyprland/submap") {
return new waybar::modules::hyprland::Submap(id, bar_, config_[name]);
}
if (ref == "hyprland/workspaces") {
return new waybar::modules::hyprland::Workspaces(id, bar_, config_[name]);
}
#endif
if (ref == "idle_inhibitor") {
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);

View File

@ -190,9 +190,8 @@ auto waybar::modules::Backlight::update() -> void {
event_box_.show();
const uint8_t percent =
best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max());
std::string desc =
fmt::format(fmt::runtime(format_), fmt::arg("percent", std::to_string(percent)),
fmt::arg("icon", getIcon(percent)));
std::string desc = fmt::format(fmt::runtime(format_), fmt::arg("percent", percent),
fmt::arg("icon", getIcon(percent)));
label_.set_markup(desc);
getState(percent);
if (tooltipEnabled()) {
@ -202,7 +201,7 @@ auto waybar::modules::Backlight::update() -> void {
}
if (!tooltip_format.empty()) {
label_.set_tooltip_text(fmt::format(fmt::runtime(tooltip_format),
fmt::arg("percent", std::to_string(percent)),
fmt::arg("percent", percent),
fmt::arg("icon", getIcon(percent))));
} else {
label_.set_tooltip_text(desc);
@ -305,14 +304,6 @@ bool waybar::modules::Backlight::handleScroll(GdkEventScroll *e) {
return true;
}
if (config_["reverse-scrolling"].asBool()) {
if (dir == SCROLL_DIR::UP) {
dir = SCROLL_DIR::DOWN;
} else if (dir == SCROLL_DIR::DOWN) {
dir = SCROLL_DIR::UP;
}
}
// Get scroll step
double step = 1;

View File

@ -102,7 +102,6 @@ waybar::modules::Cava::Cava(const std::string& id, const Json::Value& config)
thread_fetch_input_ = [this] {
thread_fetch_input_.sleep_for(fetch_input_delay_);
input_source_(&audio_data_);
dp.emit();
};
thread_ = [this] {

View File

@ -22,25 +22,33 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
is_timezoned_list_in_tooltip_(false) {
if (config_["timezones"].isArray() && !config_["timezones"].empty()) {
for (const auto& zone_name : config_["timezones"]) {
if (!zone_name.isString() || zone_name.asString().empty()) continue;
if (!zone_name.isString()) continue;
if (zone_name.asString().empty())
// nullptr means that local time should be shown
time_zones_.push_back(nullptr);
else
try {
time_zones_.push_back(date::locate_zone(zone_name.asString()));
} catch (const std::exception& e) {
spdlog::warn("Timezone: {0}. {1}", zone_name.asString(), e.what());
}
}
} else if (config_["timezone"].isString()) {
if (config_["timezone"].asString().empty())
// nullptr means that local time should be shown
time_zones_.push_back(nullptr);
else
try {
time_zones_.push_back(date::locate_zone(zone_name.asString()));
time_zones_.push_back(date::locate_zone(config_["timezone"].asString()));
} catch (const std::exception& e) {
spdlog::warn("Timezone: {0}. {1}", zone_name.asString(), e.what());
spdlog::warn("Timezone: {0}. {1}", config_["timezone"].asString(), e.what());
}
}
} else if (config_["timezone"].isString() && !config_["timezone"].asString().empty()) {
try {
time_zones_.push_back(date::locate_zone(config_["timezone"].asString()));
} catch (const std::exception& e) {
spdlog::warn("Timezone: {0}. {1}", config_["timezone"].asString(), e.what());
}
}
// If all timezones are parsed and no one is good, add current time zone. nullptr in timezones
// vector means that local time should be shown
// If all timezones are parsed and no one is good
if (!time_zones_.size()) {
time_zones_.push_back(date::current_zone());
// nullptr means that local time should be shown
time_zones_.push_back(nullptr);
}
// Check if a particular placeholder is present in the tooltip format, to know what to calculate
@ -150,8 +158,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
}
const date::time_zone* waybar::modules::Clock::current_timezone() {
return time_zones_[current_time_zone_idx_] ? time_zones_[current_time_zone_idx_]
: date::current_zone();
return is_timezone_fixed() ? time_zones_[current_time_zone_idx_] : date::current_zone();
}
bool waybar::modules::Clock::is_timezone_fixed() {

View File

@ -72,7 +72,7 @@ static void handle_global(void *data, struct wl_registry *registry, uint32_t nam
const char *interface, uint32_t version) {
if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) {
static_cast<Tags *>(data)->status_manager_ = static_cast<struct zdwl_ipc_manager_v2 *>(
(zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 3));
(zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
}
if (std::strcmp(interface, wl_seat_interface.name) == 0) {
version = std::min<uint32_t>(version, 1);

View File

@ -16,9 +16,9 @@
#include "glibmm/ustring.h"
#include "glibmm/variant.h"
#include "glibmm/varianttype.h"
#include "gtkmm/icontheme.h"
#include "gtkmm/label.h"
#include "gtkmm/tooltip.h"
#include "util/gtk_icon.hpp"
namespace waybar::modules {
Gamemode::Gamemode(const std::string& id, const Json::Value& config)
@ -224,7 +224,7 @@ auto Gamemode::update() -> void {
label_.set_markup(str);
if (useIcon) {
if (!Gtk::IconTheme::get_default()->has_icon(iconName)) {
if (!DefaultGtkIconThemeWrapper::has_icon(iconName)) {
iconName = DEFAULT_ICON_NAME;
}
icon_.set_from_icon_name(iconName, Gtk::ICON_SIZE_INVALID);

View File

@ -181,17 +181,25 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
}
char buffer[8192] = {0};
std::string response;
sizeWritten = read(SERVERSOCKET, buffer, 8192);
do {
sizeWritten = read(SERVERSOCKET, buffer, 8192);
if (sizeWritten < 0) {
spdlog::error("Hyprland IPC: Couldn't read (5)");
return "";
}
if (sizeWritten < 0) {
spdlog::error("Hyprland IPC: Couldn't read (5)");
close(SERVERSOCKET);
return "";
}
response.append(buffer, sizeWritten);
} while (sizeWritten > 0);
close(SERVERSOCKET);
return response;
}
return std::string(buffer);
Json::Value IPC::getSocket1JsonReply(const std::string& rq) {
return parser_.parse(getSocket1Reply("j/" + rq));
}
} // namespace waybar::modules::hyprland

View File

@ -22,7 +22,7 @@ Language::Language(const std::string& id, const Bar& bar, const Json::Value& con
initLanguage();
label_.hide();
ALabel::update();
update();
// register for hyprland ipc
gIPC->registerForIPC("activelayout", this);
@ -38,7 +38,10 @@ auto Language::update() -> void {
std::lock_guard<std::mutex> lg(mutex_);
std::string layoutName = std::string{};
if (config_.isMember("format-" + layout_.short_description)) {
if (config_.isMember("format-" + layout_.short_description + "-" + layout_.variant)) {
const auto propName = "format-" + layout_.short_description + "-" + layout_.variant;
layoutName = fmt::format(fmt::runtime(format_), config_[propName].asString());
} else if (config_.isMember("format-" + layout_.short_description)) {
const auto propName = "format-" + layout_.short_description;
layoutName = fmt::format(fmt::runtime(format_), config_[propName].asString());
} else {

View File

@ -1,31 +1,38 @@
#include "modules/hyprland/window.hpp"
#include <glibmm/fileutils.h>
#include <glibmm/keyfile.h>
#include <glibmm/miscutils.h>
#include <spdlog/spdlog.h>
#include <algorithm>
#include <regex>
#include <util/sanitize_str.hpp>
#include <vector>
#include "modules/hyprland/backend.hpp"
#include "util/command.hpp"
#include "util/json.hpp"
#include "util/rewrite_string.hpp"
namespace waybar::modules::hyprland {
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "window", id, "{}", 0, true), bar_(bar) {
: AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) {
modulesReady = true;
separate_outputs = config["separate-outputs"].as<bool>();
separate_outputs = config["separate-outputs"].asBool();
if (!gIPC.get()) {
gIPC = std::make_unique<IPC>();
}
label_.hide();
ALabel::update();
queryActiveWorkspace();
update();
// register for hyprland ipc
gIPC->registerForIPC("activewindow", this);
gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this);
gIPC->registerForIPC("changefloatingmode", this);
gIPC->registerForIPC("fullscreen", this);
}
Window::~Window() {
@ -38,63 +45,163 @@ auto Window::update() -> void {
// fix ampersands
std::lock_guard<std::mutex> lg(mutex_);
std::string window_name = waybar::util::sanitize_string(workspace_.last_window_title);
std::string window_address = workspace_.last_window;
window_data_.title = window_name;
if (!format_.empty()) {
label_.show();
label_.set_markup(fmt::format(fmt::runtime(format_),
waybar::util::rewriteString(lastView, config_["rewrite"])));
label_.set_markup(waybar::util::rewriteString(
fmt::format(fmt::runtime(format_), fmt::arg("title", window_name),
fmt::arg("initialTitle", window_data_.initial_title),
fmt::arg("class", window_data_.class_name),
fmt::arg("initialClass", window_data_.initial_class_name)),
config_["rewrite"]));
} else {
label_.hide();
}
ALabel::update();
setClass("empty", workspace_.windows == 0);
setClass("solo", solo_);
setClass("floating", all_floating_);
setClass("swallowing", swallowing_);
setClass("fullscreen", fullscreen_);
if (!last_solo_class_.empty() && solo_class_ != last_solo_class_) {
if (bar_.window.get_style_context()->has_class(last_solo_class_)) {
bar_.window.get_style_context()->remove_class(last_solo_class_);
spdlog::trace("Removing solo class: {}", last_solo_class_);
}
}
if (!solo_class_.empty() && solo_class_ != last_solo_class_) {
bar_.window.get_style_context()->add_class(solo_class_);
spdlog::trace("Adding solo class: {}", solo_class_);
}
last_solo_class_ = solo_class_;
AAppIconLabel::update();
}
int Window::getActiveWorkspaceID(std::string monitorName) {
auto cmd = waybar::util::command::exec("hyprctl monitors -j");
assert(cmd.exit_code == 0);
Json::Value json = parser_.parse(cmd.out);
assert(json.isArray());
auto monitor = std::find_if(json.begin(), json.end(),
auto Window::getActiveWorkspace() -> Workspace {
const auto workspace = gIPC->getSocket1JsonReply("activeworkspace");
assert(workspace.isObject());
return Workspace::parse(workspace);
}
auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace {
const auto monitors = gIPC->getSocket1JsonReply("monitors");
assert(monitors.isArray());
auto monitor = std::find_if(monitors.begin(), monitors.end(),
[&](Json::Value monitor) { return monitor["name"] == monitorName; });
if (monitor == std::end(json)) {
return 0;
if (monitor == std::end(monitors)) {
spdlog::warn("Monitor not found: {}", monitorName);
return Workspace{-1, 0, "", ""};
}
return (*monitor)["activeWorkspace"]["id"].as<int>();
const int id = (*monitor)["activeWorkspace"]["id"].asInt();
const auto workspaces = gIPC->getSocket1JsonReply("workspaces");
assert(workspaces.isArray());
auto workspace = std::find_if(workspaces.begin(), workspaces.end(),
[&](Json::Value workspace) { return workspace["id"] == id; });
if (workspace == std::end(workspaces)) {
spdlog::warn("No workspace with id {}", id);
return Workspace{-1, 0, "", ""};
}
return Workspace::parse(*workspace);
}
std::string Window::getLastWindowTitle(int workspaceID) {
auto cmd = waybar::util::command::exec("hyprctl workspaces -j");
assert(cmd.exit_code == 0);
Json::Value json = parser_.parse(cmd.out);
assert(json.isArray());
auto workspace = std::find_if(json.begin(), json.end(), [&](Json::Value workspace) {
return workspace["id"].as<int>() == workspaceID;
});
auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace {
return Workspace{value["id"].asInt(), value["windows"].asInt(), value["lastwindow"].asString(),
value["lastwindowtitle"].asString()};
}
if (workspace == std::end(json)) {
return "";
auto Window::WindowData::parse(const Json::Value& value) -> Window::WindowData {
return WindowData{value["floating"].asBool(), value["monitor"].asInt(),
value["class"].asString(), value["initialClass"].asString(),
value["title"].asString(), value["initialTitle"].asString(),
value["fullscreen"].asBool(), !value["grouped"].empty()};
}
void Window::queryActiveWorkspace() {
std::lock_guard<std::mutex> lg(mutex_);
if (separate_outputs) {
workspace_ = getActiveWorkspace(this->bar_.output->name);
} else {
workspace_ = getActiveWorkspace();
}
if (workspace_.windows > 0) {
const auto clients = gIPC->getSocket1JsonReply("clients");
assert(clients.isArray());
auto active_window = std::find_if(clients.begin(), clients.end(), [&](Json::Value window) {
return window["address"] == workspace_.last_window;
});
if (active_window == std::end(clients)) {
return;
}
window_data_ = WindowData::parse(*active_window);
updateAppIconName(window_data_.class_name, window_data_.initial_class_name);
std::vector<Json::Value> workspace_windows;
std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspace_windows),
[&](Json::Value window) {
return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool();
});
swallowing_ = std::any_of(workspace_windows.begin(), workspace_windows.end(),
[&](Json::Value window) { return !window["swallowing"].isNull(); });
std::vector<Json::Value> visible_windows;
std::copy_if(workspace_windows.begin(), workspace_windows.end(),
std::back_inserter(visible_windows),
[&](Json::Value window) { return !window["hidden"].asBool(); });
solo_ = 1 == std::count_if(visible_windows.begin(), visible_windows.end(),
[&](Json::Value window) { return !window["floating"].asBool(); });
all_floating_ = std::all_of(visible_windows.begin(), visible_windows.end(),
[&](Json::Value window) { return window["floating"].asBool(); });
fullscreen_ = window_data_.fullscreen;
// Fullscreen windows look like they are solo
if (fullscreen_) {
solo_ = true;
}
// Grouped windows have a tab bar and therefore don't look fullscreen or solo
if (window_data_.grouped) {
fullscreen_ = false;
solo_ = false;
}
if (solo_) {
solo_class_ = window_data_.class_name;
} else {
solo_class_ = "";
}
} else {
window_data_ = WindowData{};
all_floating_ = false;
swallowing_ = false;
fullscreen_ = false;
solo_ = false;
solo_class_ = "";
}
return (*workspace)["lastwindowtitle"].as<std::string>();
}
void Window::onEvent(const std::string& ev) {
std::lock_guard<std::mutex> lg(mutex_);
std::string windowName;
if (separate_outputs) {
windowName = getLastWindowTitle(getActiveWorkspaceID(this->bar_.output->name));
} else {
windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256);
}
windowName = waybar::util::sanitize_string(windowName);
if (windowName == lastView) return;
lastView = windowName;
spdlog::debug("hyprland window onevent with {}", windowName);
queryActiveWorkspace();
dp.emit();
}
void Window::setClass(const std::string& classname, bool enable) {
if (enable) {
if (!bar_.window.get_style_context()->has_class(classname)) {
bar_.window.get_style_context()->add_class(classname);
}
} else {
bar_.window.get_style_context()->remove_class(classname);
}
}
} // namespace waybar::modules::hyprland

View File

@ -0,0 +1,199 @@
#include "modules/hyprland/workspaces.hpp"
#include <json/value.h>
#include <spdlog/spdlog.h>
#include <algorithm>
#include <charconv>
#include <memory>
#include <string>
namespace waybar::modules::hyprland {
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: AModule(config, "workspaces", id, false, false),
bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
Json::Value config_format = config["format"];
format_ = config_format.isString() ? config_format.asString() : "{id}";
with_icon_ = format_.find("{icon}") != std::string::npos;
if (with_icon_ && icons_map_.empty()) {
Json::Value format_icons = config["format-icons"];
for (std::string &name : format_icons.getMemberNames()) {
icons_map_.emplace(name, format_icons[name].asString());
}
icons_map_.emplace("", "");
}
box_.set_name("workspaces");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
event_box_.add(box_);
modulesReady = true;
if (!gIPC.get()) {
gIPC = std::make_unique<IPC>();
}
init();
gIPC->registerForIPC("workspace", this);
gIPC->registerForIPC("createworkspace", this);
gIPC->registerForIPC("destroyworkspace", this);
}
auto Workspaces::update() -> void {
for (int &workspace_to_remove : workspaces_to_remove_) {
remove_workspace(workspace_to_remove);
}
workspaces_to_remove_.clear();
for (int &workspace_to_create : workspaces_to_create_) {
create_workspace(workspace_to_create);
}
workspaces_to_create_.clear();
for (std::unique_ptr<Workspace> &workspace : workspaces_) {
workspace->set_active(workspace->id() == active_workspace_id);
std::string &workspace_icon = icons_map_[""];
if (with_icon_) {
workspace_icon = workspace->select_icon(icons_map_);
}
workspace->update(format_, workspace_icon);
}
AModule::update();
}
void Workspaces::onEvent(const std::string &ev) {
std::lock_guard<std::mutex> lock(mutex_);
std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>'));
std::string payload = ev.substr(eventName.size() + 2);
if (eventName == "workspace") {
std::from_chars(payload.data(), payload.data() + payload.size(), active_workspace_id);
} else if (eventName == "destroyworkspace") {
int deleted_workspace_id;
std::from_chars(payload.data(), payload.data() + payload.size(), deleted_workspace_id);
workspaces_to_remove_.push_back(deleted_workspace_id);
} else if (eventName == "createworkspace") {
int new_workspace_id;
std::from_chars(payload.data(), payload.data() + payload.size(), new_workspace_id);
workspaces_to_create_.push_back(new_workspace_id);
}
dp.emit();
}
void Workspaces::create_workspace(int id) {
workspaces_.push_back(std::make_unique<Workspace>(id));
Gtk::Button &new_workspace_button = workspaces_.back()->button();
box_.pack_start(new_workspace_button, false, false);
sort_workspaces();
new_workspace_button.show_all();
}
void Workspaces::remove_workspace(int id) {
auto workspace = std::find_if(workspaces_.begin(), workspaces_.end(),
[&](std::unique_ptr<Workspace> &x) { return x->id() == id; });
if (workspace == workspaces_.end()) {
spdlog::warn("Can't find workspace with id {}", id);
return;
}
box_.remove(workspace->get()->button());
workspaces_.erase(workspace);
}
void Workspaces::init() {
const auto activeWorkspace = WorkspaceDto::parse(gIPC->getSocket1JsonReply("activeworkspace"));
active_workspace_id = activeWorkspace.id;
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces");
for (const Json::Value &workspace_json : workspaces_json) {
workspaces_.push_back(
std::make_unique<Workspace>(Workspace(WorkspaceDto::parse(workspace_json))));
}
for (auto &workspace : workspaces_) {
box_.pack_start(workspace->button(), false, false);
}
sort_workspaces();
dp.emit();
}
Workspaces::~Workspaces() {
gIPC->unregisterForIPC(this);
// wait for possible event handler to finish
std::lock_guard<std::mutex> lg(mutex_);
}
WorkspaceDto WorkspaceDto::parse(const Json::Value &value) {
return WorkspaceDto{value["id"].asInt()};
}
Workspace::Workspace(WorkspaceDto dto) : Workspace(dto.id){};
Workspace::Workspace(int id) : id_(id) {
button_.set_relief(Gtk::RELIEF_NONE);
content_.set_center_widget(label_);
button_.add(content_);
};
void add_or_remove_class(Glib::RefPtr<Gtk::StyleContext> context, bool condition,
const std::string &class_name) {
if (condition) {
context->add_class(class_name);
} else {
context->remove_class(class_name);
}
}
void Workspace::update(const std::string &format, const std::string &icon) {
Glib::RefPtr<Gtk::StyleContext> style_context = button_.get_style_context();
add_or_remove_class(style_context, active(), "active");
label_.set_markup(
fmt::format(fmt::runtime(format), fmt::arg("id", id()), fmt::arg("icon", icon)));
}
void Workspaces::sort_workspaces() {
std::sort(workspaces_.begin(), workspaces_.end(),
[](std::unique_ptr<Workspace> &lhs, std::unique_ptr<Workspace> &rhs) {
return lhs->id() < rhs->id();
});
for (size_t i = 0; i < workspaces_.size(); ++i) {
box_.reorder_child(workspaces_[i]->button(), i);
}
}
std::string &Workspace::select_icon(std::map<std::string, std::string> &icons_map) {
if (active()) {
auto active_icon_it = icons_map.find("active");
if (active_icon_it != icons_map.end()) {
return active_icon_it->second;
}
}
auto named_icon_it = icons_map.find(std::to_string(id()));
if (named_icon_it != icons_map.end()) {
return named_icon_it->second;
}
auto default_icon_it = icons_map.find("default");
if (default_icon_it != icons_map.end()) {
return default_icon_it->second;
}
return icons_map[""];
}
} // namespace waybar::modules::hyprland

View File

@ -41,14 +41,12 @@ void waybar::modules::Image::refresh(int sig) {
}
auto waybar::modules::Image::update() -> void {
util::command::res output_;
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
if (config_["path"].isString()) {
path_ = config_["path"].asString();
} else if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString());
path_ = output_.out;
parseOutputRaw();
} else {
path_ = "";
}
@ -58,6 +56,11 @@ auto waybar::modules::Image::update() -> void {
pixbuf = {};
if (pixbuf) {
if (tooltipEnabled() && !tooltip_.empty()) {
if (box_.get_tooltip_markup() != tooltip_) {
box_.set_tooltip_markup(tooltip_);
}
}
image_.set(pixbuf);
image_.show();
} else {
@ -67,3 +70,19 @@ auto waybar::modules::Image::update() -> void {
AModule::update();
}
void waybar::modules::Image::parseOutputRaw() {
std::istringstream output(output_.out);
std::string line;
int i = 0;
while (getline(output, line)) {
if (i == 0) {
path_ = line;
} else if (i == 1) {
tooltip_ = line;
} else {
break;
}
i++;
}
}

View File

@ -24,14 +24,17 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
album_len_(-1),
title_len_(-1),
dynamic_len_(-1),
dynamic_prio_({"title", "length", "position", "artist", "album"}),
dynamic_prio_({"title", "artist", "album", "position", "length"}),
dynamic_order_({"title", "artist", "album", "position", "length"}),
dynamic_separator_(" - "),
truncate_hours_(true),
tooltip_len_limits_(false),
// this character is used in Gnome so it's fine to use it here
ellipsis_("\u2026"),
player_("playerctld"),
manager(),
player() {
player(),
last_update_(std::chrono::system_clock::now() - interval_) {
if (config_["format-playing"].isString()) {
format_playing_ = config_["format-playing"].asString();
}
@ -44,6 +47,9 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
if (config_["ellipsis"].isString()) {
ellipsis_ = config_["ellipsis"].asString();
}
if (config_["dynamic-separator"].isString()) {
dynamic_separator_ = config_["dynamic-separator"].asString();
}
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
tooltip_ = config_["tooltip-format"].asString();
@ -74,12 +80,23 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
if (config["dynamic-len"].isUInt()) {
dynamic_len_ = config["dynamic-len"].asUInt();
}
if (config_["dynamic-priority"].isArray()) {
// "dynamic-priority" has been kept for backward compatibility
if (config_["dynamic-importance-order"].isArray() || config_["dynamic-priority"].isArray()) {
dynamic_prio_.clear();
for (auto it = config_["dynamic-priority"].begin(); it != config_["dynamic-priority"].end();
++it) {
const auto& dynamic_priority = config_["dynamic-importance-order"].isArray()
? config_["dynamic-importance-order"]
: config_["dynamic-priority"];
for (const auto& value : dynamic_priority) {
if (value.isString()) {
dynamic_prio_.push_back(value.asString());
}
}
}
if (config_["dynamic-order"].isArray()) {
dynamic_order_.clear();
for (auto it = config_["dynamic-order"].begin(); it != config_["dynamic-order"].end(); ++it) {
if (it->isString()) {
dynamic_prio_.push_back(it->asString());
dynamic_order_.push_back(it->asString());
}
}
}
@ -272,18 +289,28 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) ->
size_t lengthLen = length.length();
size_t posLen = position.length();
bool showArtist = artistLen != 0;
bool showAlbum = albumLen != 0;
bool showTitle = titleLen != 0;
bool showLength = lengthLen != 0;
bool showPos = posLen != 0;
bool showArtist = (artistLen != 0) && (std::find(dynamic_order_.begin(), dynamic_order_.end(),
"artist") != dynamic_order_.end());
bool showAlbum = (albumLen != 0) && (std::find(dynamic_order_.begin(), dynamic_order_.end(),
"album") != dynamic_order_.end());
bool showTitle = (titleLen != 0) && (std::find(dynamic_order_.begin(), dynamic_order_.end(),
"title") != dynamic_order_.end());
bool showLength = (lengthLen != 0) && (std::find(dynamic_order_.begin(), dynamic_order_.end(),
"length") != dynamic_order_.end());
bool showPos = (posLen != 0) && (std::find(dynamic_order_.begin(), dynamic_order_.end(),
"position") != dynamic_order_.end());
if (truncated && dynamic_len_ >= 0) {
size_t dynamicLen = dynamic_len_;
if (showArtist) artistLen += 3;
if (showAlbum) albumLen += 3;
if (showLength) lengthLen += 3;
if (showPos) posLen += 3;
// Since the first element doesn't present a separator and we don't know a priori which one
// it will be, we add a "virtual separatorLen" to the dynamicLen, since we are adding the
// separatorLen to all the other lengths.
size_t separatorLen = utf8_width(dynamic_separator_);
size_t dynamicLen = dynamic_len_ + separatorLen;
if (showArtist) artistLen += separatorLen;
if (showAlbum) albumLen += separatorLen;
if (showTitle) albumLen += separatorLen;
if (showLength) lengthLen += separatorLen;
if (showPos) posLen += separatorLen;
size_t totalLen = 0;
@ -330,20 +357,44 @@ auto Mpris::getDynamicStr(const PlayerInfo& info, bool truncated, bool html) ->
album = Glib::Markup::escape_text(album);
title = Glib::Markup::escape_text(title);
}
if (showArtist) dynamic << artist << " - ";
if (showAlbum) dynamic << album << " - ";
if (showTitle) dynamic << title;
if (showLength || showPos) {
dynamic << ' ';
if (html) dynamic << "<small>";
dynamic << '[';
if (showPos) {
dynamic << position;
if (showLength) dynamic << '/';
bool lengthOrPositionShown = false;
bool previousShown = false;
std::string previousOrder = "";
for (const std::string& order : dynamic_order_) {
if ((order == "artist" && showArtist) || (order == "album" && showAlbum) ||
(order == "title" && showTitle)) {
if (previousShown && previousOrder != "length" && previousOrder != "position") {
dynamic << dynamic_separator_;
}
if (order == "artist") {
dynamic << artist;
} else if (order == "album") {
dynamic << album;
} else if (order == "title") {
dynamic << title;
}
previousShown = true;
} else if (order == "length" || order == "position") {
if (!lengthOrPositionShown && (showLength || showPos)) {
if (html) dynamic << "<small>";
if (previousShown) dynamic << ' ';
dynamic << '[';
if (showPos) {
dynamic << position;
if (showLength) dynamic << '/';
}
if (showLength) dynamic << length;
dynamic << ']';
if (!dynamic.str().empty()) dynamic << ' ';
if (html) dynamic << "</small>";
lengthOrPositionShown = true;
}
}
if (showLength) dynamic << length;
dynamic << ']';
if (html) dynamic << "</small>";
previousOrder = order;
}
return dynamic.str();
}
@ -559,6 +610,10 @@ bool Mpris::handleToggle(GdkEventButton* const& e) {
}
auto Mpris::update() -> void {
const auto now = std::chrono::system_clock::now();
if (now - last_update_ < interval_) return;
last_update_ = now;
auto opt = getPlayerInfo();
if (!opt) {
event_box_.set_visible(false);

View File

@ -81,13 +81,6 @@ bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
if (dir == SCROLL_DIR::NONE) {
return true;
}
if (config_["reverse-scrolling"].asInt() == 1) {
if (dir == SCROLL_DIR::UP) {
dir = SCROLL_DIR::DOWN;
} else if (dir == SCROLL_DIR::DOWN) {
dir = SCROLL_DIR::UP;
}
}
double volume_tick = static_cast<double>(PA_VOLUME_NORM) / 100;
pa_volume_t change = volume_tick;
pa_cvolume pa_volume = pa_volume_;

View File

@ -106,7 +106,11 @@ void Window::handle_focused_view(const char *title) {
label_.hide(); // hide empty labels or labels with empty format
} else {
label_.show();
label_.set_markup(fmt::format(fmt::runtime(format_), Glib::Markup::escape_text(title).raw()));
auto text = fmt::format(fmt::runtime(format_), Glib::Markup::escape_text(title).raw());
label_.set_markup(text);
if (tooltipEnabled()) {
label_.set_tooltip_markup(text);
}
}
ALabel::update();

View File

@ -19,7 +19,7 @@ Host::Host(const std::size_t id, const Json::Value& config, const Bar& bar,
Host::~Host() {
if (bus_name_id_ > 0) {
Gio::DBus::unwatch_name(bus_name_id_);
Gio::DBus::unown_name(bus_name_id_);
bus_name_id_ = 0;
}
if (watcher_id_ > 0) {

View File

@ -9,6 +9,7 @@
#include <map>
#include "util/format.hpp"
#include "util/gtk_icon.hpp"
template <>
struct fmt::formatter<Glib::VariantBase> : formatter<std::string> {
@ -379,10 +380,8 @@ Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int reque
return icon_theme->load_icon(name.c_str(), tmp_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
}
Glib::RefPtr<Gtk::IconTheme> default_theme = Gtk::IconTheme::get_default();
default_theme->rescan_if_needed();
return default_theme->load_icon(name.c_str(), tmp_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
return DefaultGtkIconThemeWrapper::load_icon(name.c_str(), tmp_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
}
double Item::getScaledIconSize() {

View File

@ -18,7 +18,6 @@ Watcher::~Watcher() {
g_slist_free_full(hosts_, gfWatchFree);
hosts_ = nullptr;
}
if (items_ != nullptr) {
g_slist_free_full(items_, gfWatchFree);
items_ = nullptr;

View File

@ -5,25 +5,19 @@
#include <glibmm/keyfile.h>
#include <glibmm/miscutils.h>
#include <gtkmm/enums.h>
#include <gtkmm/icontheme.h>
#include <spdlog/spdlog.h>
#include <filesystem>
#include <regex>
#include <string>
#include "util/gtk_icon.hpp"
#include "util/rewrite_string.hpp"
namespace waybar::modules::sway {
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: AIconLabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
// Icon size
if (config_["icon-size"].isUInt()) {
app_icon_size_ = config["icon-size"].asUInt();
}
image_.set_pixel_size(app_icon_size_);
: AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
ipc_.subscribe(R"(["window","workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
@ -49,7 +43,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
auto output = payload["output"].isString() ? payload["output"].asString() : "";
std::tie(app_nb_, floating_count_, windowId_, window_, app_id_, app_class_, shell_, layout_) =
getFocusedNode(payload["nodes"], output);
updateAppIconName();
updateAppIconName(app_id_, app_class_);
dp.emit();
} catch (const std::exception& e) {
spdlog::error("Window: {}", e.what());
@ -57,106 +51,6 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
}
}
std::optional<std::string> getDesktopFilePath(const std::string& app_id,
const std::string& app_class) {
const auto data_dirs = Glib::get_system_data_dirs();
for (const auto& data_dir : data_dirs) {
const auto data_app_dir = data_dir + "applications/";
auto desktop_file_path = data_app_dir + app_id + ".desktop";
if (std::filesystem::exists(desktop_file_path)) {
return desktop_file_path;
}
if (!app_class.empty()) {
desktop_file_path = data_app_dir + app_class + ".desktop";
if (std::filesystem::exists(desktop_file_path)) {
return desktop_file_path;
}
}
}
return {};
}
std::optional<Glib::ustring> getIconName(const std::string& app_id, const std::string& app_class) {
const auto desktop_file_path = getDesktopFilePath(app_id, app_class);
if (!desktop_file_path.has_value()) {
// Try some heuristics to find a matching icon
const auto default_icon_theme = Gtk::IconTheme::get_default();
if (default_icon_theme->has_icon(app_id)) {
return app_id;
}
const auto app_id_desktop = app_id + "-desktop";
if (default_icon_theme->has_icon(app_id_desktop)) {
return app_id_desktop;
}
const auto to_lower = [](const std::string& str) {
auto str_cpy = str;
std::transform(str_cpy.begin(), str_cpy.end(), str_cpy.begin(),
[](unsigned char c) { return std::tolower(c); });
return str;
};
const auto first_space = app_id.find_first_of(' ');
if (first_space != std::string::npos) {
const auto first_word = to_lower(app_id.substr(0, first_space));
if (default_icon_theme->has_icon(first_word)) {
return first_word;
}
}
const auto first_dash = app_id.find_first_of('-');
if (first_dash != std::string::npos) {
const auto first_word = to_lower(app_id.substr(0, first_dash));
if (default_icon_theme->has_icon(first_word)) {
return first_word;
}
}
return {};
}
try {
Glib::KeyFile desktop_file;
desktop_file.load_from_file(desktop_file_path.value());
return desktop_file.get_string("Desktop Entry", "Icon");
} catch (Glib::FileError& error) {
spdlog::warn("Error while loading desktop file {}: {}", desktop_file_path.value(),
error.what().c_str());
} catch (Glib::KeyFileError& error) {
spdlog::warn("Error while loading desktop file {}: {}", desktop_file_path.value(),
error.what().c_str());
}
return {};
}
void Window::updateAppIconName() {
if (!iconEnabled()) {
return;
}
const auto icon_name = getIconName(app_id_, app_class_);
if (icon_name.has_value()) {
app_icon_name_ = icon_name.value();
} else {
app_icon_name_ = "";
}
update_app_icon_ = true;
}
void Window::updateAppIcon() {
if (update_app_icon_) {
update_app_icon_ = false;
if (app_icon_name_.empty()) {
image_.set_visible(false);
} else {
image_.set_from_icon_name(app_icon_name_, Gtk::ICON_SIZE_INVALID);
image_.set_visible(true);
}
}
}
auto Window::update() -> void {
spdlog::trace("workspace layout {}, tiled count {}, floating count {}", layout_, app_nb_,
floating_count_);
@ -178,10 +72,6 @@ auto Window::update() -> void {
} else {
mode += 32;
}
if (!app_id_.empty() && !bar_.window.get_style_context()->has_class(app_id_)) {
bar_.window.get_style_context()->add_class(app_id_);
old_app_id_ = app_id_;
}
}
if (!old_app_id_.empty() && ((mode & 2) == 0 || old_app_id_ != app_id_) &&
@ -215,7 +105,7 @@ auto Window::update() -> void {
updateAppIcon();
// Call parent update
AIconLabel::update();
AAppIconLabel::update();
}
void Window::setClass(std::string classname, bool enable) {

View File

@ -235,7 +235,8 @@ auto Workspaces::update() -> void {
auto format = config_["format"].asString();
output = fmt::format(fmt::runtime(format), fmt::arg("icon", getIcon(output, *it)),
fmt::arg("value", output), fmt::arg("name", trimWorkspaceName(output)),
fmt::arg("index", (*it)["num"].asString()));
fmt::arg("index", (*it)["num"].asString()),
fmt::arg("output", (*it)["output"].asString()));
}
if (!config_["disable-markup"].asBool()) {
static_cast<Gtk::Label *>(button.get_children()[0])->set_markup(output);
@ -278,7 +279,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
}
std::string Workspaces::getIcon(const std::string &name, const Json::Value &node) {
std::vector<std::string> keys = {name, "urgent", "focused", "visible", "default"};
std::vector<std::string> keys = {"urgent", "focused", name, "visible", "default"};
for (auto const &key : keys) {
if (key == "focused" || key == "visible" || key == "urgent") {
if (config_["format-icons"][key].isString() && node[key].asBool()) {
@ -326,11 +327,17 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
return true;
}
}
if (!config_["warp-on-scroll"].isNull() && !config_["warp-on-scroll"].asBool()) {
ipc_.sendCmd(IPC_COMMAND, fmt::format("mouse_warping none"));
}
try {
ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, "--no-auto-back-and-forth", name));
} catch (const std::exception &e) {
spdlog::error("Workspaces: {}", e.what());
}
if (!config_["warp-on-scroll"].isNull() && !config_["warp-on-scroll"].asBool()) {
ipc_.sendCmd(IPC_COMMAND, fmt::format("mouse_warping container"));
}
return true;
}

View File

@ -11,8 +11,18 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
#if defined(__FreeBSD__)
// try to read sysctl?
#else
if (config_["hwmon-path"].isString()) {
file_path_ = config_["hwmon-path"].asString();
auto& hwmon_path = config_["hwmon-path"];
if (hwmon_path.isString()) {
file_path_ = hwmon_path.asString();
} else if (hwmon_path.isArray()) {
// if hwmon_path is an array, loop to find first valid item
for (auto& item : hwmon_path) {
auto path = item.asString();
if (std::filesystem::exists(path)) {
file_path_ = path;
break;
}
}
} else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) {
file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString()))
.path()

View File

@ -5,10 +5,8 @@
#include <cstring>
#include <string>
#include "gtkmm/icontheme.h"
#include "gtkmm/label.h"
#include "gtkmm/tooltip.h"
#include "modules/upower/upower_tooltip.hpp"
#include "util/gtk_icon.hpp"
namespace waybar::modules::upower {
UPower::UPower(const std::string& id, const Json::Value& config)
@ -25,6 +23,8 @@ UPower::UPower(const std::string& id, const Json::Value& config)
box_.set_name(name_);
event_box_.add(box_);
// Device user wants
if (config_["native-path"].isString()) nativePath_ = config_["native-path"].asString();
// Icon Size
if (config_["icon-size"].isUInt()) {
iconSize = config_["icon-size"].asUInt();
@ -195,8 +195,26 @@ void UPower::addDevice(UpDevice* device) {
void UPower::setDisplayDevice() {
std::lock_guard<std::mutex> guard(m_Mutex);
displayDevice = up_client_get_display_device(client);
g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
if (nativePath_.empty())
displayDevice = up_client_get_display_device(client);
else {
g_ptr_array_foreach(
up_client_get_devices2(client),
[](gpointer data, gpointer user_data) {
UpDevice* device{static_cast<UpDevice*>(data)};
UPower* thisPtr{static_cast<UPower*>(user_data)};
gchar* nativePath;
if (!thisPtr->displayDevice) {
g_object_get(device, "native-path", &nativePath, NULL);
if (!std::strcmp(nativePath, thisPtr->nativePath_.c_str()))
thisPtr->displayDevice = device;
}
},
this);
}
if (displayDevice) g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
}
void UPower::removeDevices() {
@ -278,14 +296,22 @@ auto UPower::update() -> void {
double percentage;
gint64 time_empty;
gint64 time_full;
gchar* icon_name;
gchar* icon_name{(char*)'\0'};
std::string percentString{""};
std::string time_format{""};
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
NULL);
bool displayDeviceValid{false};
bool displayDeviceValid =
kind == UpDeviceKind::UP_DEVICE_KIND_BATTERY || kind == UpDeviceKind::UP_DEVICE_KIND_UPS;
if (displayDevice) {
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
NULL);
/* Every Device which is handled by Upower and which is not
* UP_DEVICE_KIND_UNKNOWN (0) or UP_DEVICE_KIND_LINE_POWER (1) is a Battery
*/
displayDeviceValid = (kind != UpDeviceKind::UP_DEVICE_KIND_UNKNOWN &&
kind != UpDeviceKind::UP_DEVICE_KIND_LINE_POWER);
}
// CSS status class
const std::string status = getDeviceStatus(state);
@ -308,32 +334,30 @@ auto UPower::update() -> void {
event_box_.set_visible(true);
// Tooltip
if (tooltip_enabled) {
uint tooltipCount = upower_tooltip->updateTooltip(devices);
// Disable the tooltip if there aren't any devices in the tooltip
box_.set_has_tooltip(!devices.empty() && tooltipCount > 0);
}
// Set percentage
std::string percentString = "";
if (displayDeviceValid) {
percentString = std::to_string(int(percentage + 0.5)) + "%";
}
// Tooltip
if (tooltip_enabled) {
uint tooltipCount = upower_tooltip->updateTooltip(devices);
// Disable the tooltip if there aren't any devices in the tooltip
box_.set_has_tooltip(!devices.empty() && tooltipCount > 0);
}
// Label format
std::string time_format = "";
switch (state) {
case UP_DEVICE_STATE_CHARGING:
case UP_DEVICE_STATE_PENDING_CHARGE:
time_format = timeToString(time_full);
break;
case UP_DEVICE_STATE_DISCHARGING:
case UP_DEVICE_STATE_PENDING_DISCHARGE:
time_format = timeToString(time_empty);
break;
default:
break;
// Set percentage
percentString = std::to_string(int(percentage + 0.5)) + "%";
// Label format
switch (state) {
case UP_DEVICE_STATE_CHARGING:
case UP_DEVICE_STATE_PENDING_CHARGE:
time_format = timeToString(time_full);
break;
case UP_DEVICE_STATE_DISCHARGING:
case UP_DEVICE_STATE_PENDING_DISCHARGE:
time_format = timeToString(time_empty);
break;
default:
break;
}
}
std::string label_format =
fmt::format(fmt::runtime(showAltText ? format_alt : format),
@ -348,7 +372,7 @@ auto UPower::update() -> void {
label_.set_markup(onlySpaces ? "" : label_format);
// Set icon
if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) {
if (icon_name == NULL || !DefaultGtkIconThemeWrapper::has_icon(icon_name)) {
icon_name = (char*)"battery-missing-symbolic";
}
icon_.set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID);

View File

@ -2,9 +2,9 @@
#include "gtkmm/box.h"
#include "gtkmm/enums.h"
#include "gtkmm/icontheme.h"
#include "gtkmm/image.h"
#include "gtkmm/label.h"
#include "util/gtk_icon.hpp"
namespace waybar::modules::upower {
UPowerTooltip::UPowerTooltip(uint iconSize_, uint tooltipSpacing_, uint tooltipPadding_)
@ -62,7 +62,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) {
std::string deviceIconName = getDeviceIcon(kind);
Gtk::Image* deviceIcon = new Gtk::Image();
deviceIcon->set_pixel_size(iconSize);
if (!Gtk::IconTheme::get_default()->has_icon(deviceIconName)) {
if (!DefaultGtkIconThemeWrapper::has_icon(deviceIconName)) {
deviceIconName = "battery-missing-symbolic";
}
deviceIcon->set_from_icon_name(deviceIconName, Gtk::ICON_SIZE_INVALID);
@ -79,7 +79,7 @@ uint UPowerTooltip::updateTooltip(Devices& devices) {
// Set icon
Gtk::Image* icon = new Gtk::Image();
icon->set_pixel_size(iconSize);
if (icon_name == NULL || !Gtk::IconTheme::get_default()->has_icon(icon_name)) {
if (icon_name == NULL || !DefaultGtkIconThemeWrapper::has_icon(icon_name)) {
icon_name = (char*)"battery-missing-symbolic";
}
icon->set_from_icon_name(icon_name, Gtk::ICON_SIZE_INVALID);

View File

@ -15,6 +15,7 @@ waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Val
pending_plugins_(0),
muted_(false),
volume_(0.0),
min_step_(0.0),
node_id_(0) {
wp_init(WP_INIT_PIPEWIRE);
wp_core_ = wp_core_new(NULL, NULL);
@ -39,6 +40,9 @@ waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Val
activatePlugins();
dp.emit();
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Wireplumber::handleScroll));
}
waybar::modules::Wireplumber::~Wireplumber() {
@ -83,7 +87,6 @@ void waybar::modules::Wireplumber::updateNodeName(waybar::modules::Wireplumber*
void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* self, uint32_t id) {
spdlog::debug("[{}]: updating volume", self->name_);
double vol;
GVariant* variant = NULL;
if (!isValidNodeId(id)) {
@ -99,11 +102,11 @@ void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* se
throw std::runtime_error(err);
}
g_variant_lookup(variant, "volume", "d", &vol);
g_variant_lookup(variant, "volume", "d", &self->volume_);
g_variant_lookup(variant, "step", "d", &self->min_step_);
g_variant_lookup(variant, "mute", "b", &self->muted_);
g_clear_pointer(&variant, g_variant_unref);
self->volume_ = std::round(vol * 100.0F);
self->dp.emit();
}
@ -280,11 +283,12 @@ auto waybar::modules::Wireplumber::update() -> void {
label_.get_style_context()->remove_class("muted");
}
int vol = round(volume_ * 100.0);
std::string markup = fmt::format(fmt::runtime(format), fmt::arg("node_name", node_name_),
fmt::arg("volume", volume_), fmt::arg("icon", getIcon(volume_)));
fmt::arg("volume", vol), fmt::arg("icon", getIcon(vol)));
label_.set_markup(markup);
getState(volume_);
getState(vol);
if (tooltipEnabled()) {
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
@ -292,9 +296,9 @@ auto waybar::modules::Wireplumber::update() -> void {
}
if (!tooltip_format.empty()) {
label_.set_tooltip_text(
fmt::format(fmt::runtime(tooltip_format), fmt::arg("node_name", node_name_),
fmt::arg("volume", volume_), fmt::arg("icon", getIcon(volume_))));
label_.set_tooltip_text(fmt::format(fmt::runtime(tooltip_format),
fmt::arg("node_name", node_name_),
fmt::arg("volume", vol), fmt::arg("icon", getIcon(vol))));
} else {
label_.set_tooltip_text(node_name_);
}
@ -303,3 +307,49 @@ auto waybar::modules::Wireplumber::update() -> void {
// Call parent update
ALabel::update();
}
bool waybar::modules::Wireplumber::handleScroll(GdkEventScroll* e) {
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
return AModule::handleScroll(e);
}
auto dir = AModule::getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}
if (config_["reverse-scrolling"].asInt() == 1) {
if (dir == SCROLL_DIR::UP) {
dir = SCROLL_DIR::DOWN;
} else if (dir == SCROLL_DIR::DOWN) {
dir = SCROLL_DIR::UP;
}
}
double max_volume = 1;
double step = 1.0 / 100.0;
if (config_["scroll-step"].isDouble()) {
step = config_["scroll-step"].asDouble() / 100.0;
}
if (config_["max-volume"].isDouble()) {
max_volume = config_["max-volume"].asDouble() / 100.0;
}
if (step < min_step_) step = min_step_;
double new_vol = volume_;
if (dir == SCROLL_DIR::UP) {
if (volume_ < max_volume) {
new_vol = volume_ + step;
if (new_vol > max_volume) new_vol = max_volume;
}
} else if (dir == SCROLL_DIR::DOWN) {
if (volume_ > 0) {
new_vol = volume_ - step;
if (new_vol < 0) new_vol = 0;
}
}
if (new_vol != volume_) {
GVariant* variant = g_variant_new_double(new_vol);
gboolean ret;
g_signal_emit_by_name(mixer_api_, "set-volume", node_id_, variant, &ret);
}
return true;
}

View File

@ -20,6 +20,7 @@
#include "glibmm/fileutils.h"
#include "glibmm/refptr.h"
#include "util/format.hpp"
#include "util/rewrite_string.hpp"
#include "util/string.hpp"
namespace waybar::modules::wlr {
@ -506,11 +507,11 @@ void Task::handle_closed() {
spdlog::debug("{} closed", repr());
zwlr_foreign_toplevel_handle_v1_destroy(handle_);
handle_ = nullptr;
tbar_->remove_task(id_);
if (button_visible_) {
tbar_->remove_button(button);
button_visible_ = false;
}
tbar_->remove_task(id_);
}
bool Task::handle_clicked(GdkEventButton *bt) {
@ -622,6 +623,9 @@ void Task::update() {
fmt::format(fmt::runtime(format_before_), fmt::arg("title", title), fmt::arg("name", name),
fmt::arg("app_id", app_id), fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true)));
txt = waybar::util::rewriteString(txt, config_["rewrite"]);
if (markup)
text_before_.set_markup(txt);
else
@ -633,6 +637,9 @@ void Task::update() {
fmt::format(fmt::runtime(format_after_), fmt::arg("title", title), fmt::arg("name", name),
fmt::arg("app_id", app_id), fmt::arg("state", state_string()),
fmt::arg("short_state", state_string(true)));
txt = waybar::util::rewriteString(txt, config_["rewrite"]);
if (markup)
text_after_.set_markup(txt);
else
@ -710,6 +717,7 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class("empty");
event_box_.add(box_);
struct wl_display *display = Client::inst()->wl_display;
@ -862,11 +870,19 @@ void Taskbar::handle_finished() {
manager_ = nullptr;
}
void Taskbar::add_button(Gtk::Button &bt) { box_.pack_start(bt, false, false); }
void Taskbar::add_button(Gtk::Button &bt) {
box_.pack_start(bt, false, false);
box_.get_style_context()->remove_class("empty");
}
void Taskbar::move_button(Gtk::Button &bt, int pos) { box_.reorder_child(bt, pos); }
void Taskbar::remove_button(Gtk::Button &bt) { box_.remove(bt); }
void Taskbar::remove_button(Gtk::Button &bt) {
box_.remove(bt);
if (tasks_.empty()) {
box_.get_style_context()->add_class("empty");
}
}
void Taskbar::remove_task(uint32_t id) {
auto it = std::find_if(std::begin(tasks_), std::end(tasks_),

View File

@ -64,7 +64,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
auto WorkspaceManager::workspace_comparator() const
-> std::function<bool(std::unique_ptr<Workspace> &, std::unique_ptr<Workspace> &)> {
return [=](std::unique_ptr<Workspace> &lhs, std::unique_ptr<Workspace> &rhs) {
return [=, this](std::unique_ptr<Workspace> &lhs, std::unique_ptr<Workspace> &rhs) {
auto is_name_less = lhs->get_name() < rhs->get_name();
auto is_name_eq = lhs->get_name() == rhs->get_name();
auto is_coords_less = lhs->get_coords() < rhs->get_coords();
@ -73,7 +73,7 @@ auto WorkspaceManager::workspace_comparator() const
try {
auto is_number_less = std::stoi(lhs->get_name()) < std::stoi(rhs->get_name());
return is_number_less;
} catch (std::invalid_argument) {
} catch (const std::invalid_argument &) {
}
}

25
src/util/gtk_icon.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "util/gtk_icon.hpp"
/* We need a global mutex for accessing the object returned by Gtk::IconTheme::get_default()
* because it always returns the same object across different threads, and concurrent
* access can cause data corruption and lead to invalid memory access and crashes.
* Even concurrent calls that seem read only such as has_icon can cause issues because
* the GTK lib may update the internal icon cache on this calls.
*/
std::mutex DefaultGtkIconThemeWrapper::default_theme_mutex;
bool DefaultGtkIconThemeWrapper::has_icon(const std::string& value) {
const std::lock_guard<std::mutex> lock(default_theme_mutex);
return Gtk::IconTheme::get_default()->has_icon(value);
}
Glib::RefPtr<Gdk::Pixbuf> DefaultGtkIconThemeWrapper::load_icon(const char* name, int tmp_size,
Gtk::IconLookupFlags flags) {
const std::lock_guard<std::mutex> lock(default_theme_mutex);
auto default_theme = Gtk::IconTheme::get_default();
default_theme->rescan_if_needed();
return default_theme->load_icon(name, tmp_size, flags);
}

View File

@ -0,0 +1,50 @@
#include "util/prepare_for_sleep.h"
#include <gio/gio.h>
#include <spdlog/spdlog.h>
namespace {
class PrepareForSleep {
private:
PrepareForSleep() {
GError *error = NULL;
login1_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!login1_connection) {
spdlog::warn("Unable to connect to the SYSTEM Bus!...");
} else {
login1_id = g_dbus_connection_signal_subscribe(
login1_connection, "org.freedesktop.login1", "org.freedesktop.login1.Manager",
"PrepareForSleep", "/org/freedesktop/login1", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
prepareForSleep_cb, this, NULL);
}
}
static void prepareForSleep_cb(GDBusConnection *system_bus, const gchar *sender_name,
const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *parameters,
gpointer user_data) {
if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(b)"))) {
gboolean sleeping;
g_variant_get(parameters, "(b)", &sleeping);
PrepareForSleep *self = static_cast<PrepareForSleep *>(user_data);
self->signal.emit(sleeping);
}
}
public:
static PrepareForSleep &GetInstance() {
static PrepareForSleep instance;
return instance;
}
waybar::SafeSignal<bool> signal;
private:
guint login1_id;
GDBusConnection *login1_connection;
};
} // namespace
waybar::SafeSignal<bool> &waybar::util::prepare_for_sleep() {
return PrepareForSleep::GetInstance().signal;
}

View File

@ -63,7 +63,7 @@ bool waybar::util::Rfkill::on_event(Glib::IOCondition cond) {
return false;
}
if (len < RFKILL_EVENT_SIZE_V1) {
if (static_cast<size_t>(len) < RFKILL_EVENT_SIZE_V1) {
spdlog::error("Wrong size of RFKILL event: {} < {}", len, RFKILL_EVENT_SIZE_V1);
return true;
}
@ -73,10 +73,9 @@ bool waybar::util::Rfkill::on_event(Glib::IOCondition cond) {
on_update.emit(event);
}
return true;
} else {
spdlog::error("Failed to poll RFKILL control device");
return false;
}
spdlog::error("Failed to poll RFKILL control device");
return false;
}
bool waybar::util::Rfkill::getState() const { return state_; }

View File

@ -1,12 +1,10 @@
[wrap-file]
directory = Catch2-3.1.0
source_url = https://github.com/catchorg/Catch2/archive/v3.1.0.tar.gz
source_filename = Catch2-3.1.0.tar.gz
source_hash = c252b2d9537e18046d8b82535069d2567f77043f8e644acf9a9fffc22ea6e6f7
patch_filename = catch2_3.1.0-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/catch2_3.1.0-1/get_patch
patch_hash = 4ebf4277aed574a9912a79f4817a310d837798e099bbafa6097be23a7f5e3ae4
wrapdb_version = 3.1.0-1
directory = Catch2-3.3.2
source_url = https://github.com/catchorg/Catch2/archive/v3.3.2.tar.gz
source_filename = Catch2-3.3.2.tar.gz
source_hash = 8361907f4d9bff3ae7c1edb027f813659f793053c99b67837a0c0375f065bae2
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.3.2-1/Catch2-3.3.2.tar.gz
wrapdb_version = 3.3.2-1
[provide]
catch2 = catch2_dep