Waybar/include/util
Calvin Lee 09873f0ed9 search for dark or light mode stylesheet
summary:
-------
This commit adds xdg-desktop-portal support to waybar. If a portal
supporting `org.freedesktop.portal.Settings` exists, then it will be
queried for the current colorscheme. This colorscheme will then be used
to prefer a `style-light.css` or `style-dark.css` over the basic
`style.css`.

technical details:
-----------------
Appearance is provided by several libraries, such as libhandy (mobile)
and libadwaita. However, waybar links to neither of these libraries. As
the amount of code required to communicate with xdg-desktop portal as a
client is rather minimal, I believe doing so is better than linking to
an additional library.

The Gio library for communicating with dbus is rather messy, Instead of
the `Portal` class containing a `Gio::Dbus::Proxy`, it extends it which
simplifies signal handling.

`Portal` then exposes its own signal, which can be listened to by waybar
to update CSS.

For a reference implementation, please see another one of my projects:
https://github.com/4e554c4c/darkman.nvim/blob/main/portal.go

test plan:
---------
If no desktop portal which provides `Settings` exists, then waybar
continues with the log line
```
[2023-09-06 14:14:37.754] [info] Unable to receive desktop appearance: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.Settings” on object at path /org/freedesktop/portal/desktop
```

Furthermore, if `style-light.css` or `style-dark.css` do not exist, then
`style.css` will still be searched for.

Waybar has been tested with both light and dark startup. E.g. if the
appearance is dark on startup the log lines
```
[2023-09-06 14:27:45.379] [info] Discovered appearance 'dark'
[2023-09-06 14:27:45.379] [debug] Try expanding: $XDG_CONFIG_HOME/waybar/style-dark.css
[2023-09-06 14:27:45.379] [debug] Found config file: $XDG_CONFIG_HOME/waybar/style-dark.css
[2023-09-06 14:27:45.379] [info] Using CSS file /home/pounce/.config/waybar/style-dark.css
```
will be observed.
If the color then changes to light during the operation of waybar, it
will change css files:
```
[2023-09-06 14:28:17.173] [info] Received new appearance 'dark'
[2023-09-06 14:28:17.173] [debug] Try expanding: $XDG_CONFIG_HOME/waybar/style-light.css
[2023-09-06 14:28:17.173] [debug] Found config file: $XDG_CONFIG_HOME/waybar/style-light.css
[2023-09-06 14:28:17.173] [info] Using CSS file /home/pounce/.config/waybar/style-light.css
```

Finally, tested resetting waybar and toggling style (works, and style is
only changed once).

fixes: Alexays/Waybar#1973
2023-09-06 15:19:56 +00:00
..
SafeSignal.hpp refactor: lint 2022-04-06 08:37:19 +02:00
clara.hpp fix: lint 2023-04-03 09:41:24 +02:00
command.hpp fix: lint 2023-05-29 09:24:33 +02:00
date.hpp feat(clock): support chrono Time Zone extensions. 2023-01-21 02:18:44 -08:00
format.hpp Explicitly cast ustring to string when passing to fmt 2023-08-15 20:57:07 +02:00
gtk_icon.hpp fix: lint 2023-07-04 22:35:27 +02:00
json.hpp fix: adapt to fmt 9.0.0 breaking changes 2022-07-13 22:36:32 -07:00
portal.hpp search for dark or light mode stylesheet 2023-09-06 15:19:56 +00:00
prepare_for_sleep.h Wake all sleeping threads when leaving suspend 2023-06-07 10:17:42 +02:00
rewrite_string.hpp Rename function name 2023-03-25 17:33:01 +01:00
rfkill.hpp refactor: lint 2022-04-06 08:37:19 +02:00
sanitize_str.hpp utils: add sanitize_str to encode '&' etc. 2022-10-17 00:31:19 +02:00
sleeper_thread.hpp Ensure signal is disconnected in destructor 2023-07-16 23:29:28 +02:00
string.hpp ltrim and rtrim take argument by const-ref 2022-02-05 21:02:58 +01:00
ustring_clen.hpp Use g_unichar_iswide to properly align calendar on CJK locales 2021-01-31 11:53:53 -08:00