Commit Graph
100 Commits
Author SHA1 Message Date
Aleksei Bavshin 43d52c59d9 test: fix build with Catch2 v2.x
Use smaller includes for Catch2 v3.
2023-01-20 22:49:59 -08:00
Aleksei Bavshin ca9d237b00 fix(sway): add missing includes for GCC 13
See also: https://gcc.gnu.org/gcc-13/porting_to.html
2023-01-20 22:49:58 -08:00
Aleksei Bavshin 22084691ff fix(battery): ignore non-system power supplies
Linux power_supply sysfs interface allows checking if the battery powers
the whole system or a specific device/tree of devices with `scope`
attribute[1]. We can use it to skip the non-system power supplies in the
battery module and avoid adding HIDs or other peripheral devices to the
total.

The logic is based on UPower, where it is assumed that "Unknown" devices
or devices without a `scope` are system power supplies.

[1]: https://lore.kernel.org/lkml/alpine.LNX.2.00.1201031556460.24984@pobox.suse.cz/T/
2022-12-04 00:14:42 -08:00
Aleksei Bavshin a44622aa9f fix: fmt 9.x deprecation warning for implicit enum conversions 2022-07-13 22:36:37 -07:00
Aleksei Bavshin 3117aefdf3 fix: drop conditionals for ancient fmt versions 2022-07-13 22:36:33 -07:00
Aleksei Bavshin 24a8332b62 fix: adapt to fmt 9.0.0 breaking changes 2022-07-13 22:36:32 -07:00
Aleksei Bavshin 13fdbc13c3 refactor: change enum ipc_command_type to uint32_t
As we always use the enum to compare or initialize uint32_t values, it
would be better to declare it with the right type. This way we could
avoid `-Wnarrowing` warnings or unnecessary type casts.
2022-04-10 12:52:46 -07:00
Aleksei Bavshin ce404199de chore: add tzdata to the alpine builder
Fixes date formatting test execution on alpine.
2022-01-07 22:50:23 -08:00
Aleksei Bavshin 7f6bef2049 fix(util): make waybar_time formatter compatible with fmt 8.1.0
Stop using private implementation details of the `formatter<std::tm>`.
We never needed anything from the class besides the format specifier,
which is easily obtainable with public API.
2022-01-07 22:34:00 -08:00
Aleksei Bavshin 1489a539f8 chore: bump supported fmt ver to 7.0.0
Certain features we use were added only in 7.0 and the code no longer
compiles with any earlier versions.
2022-01-07 22:33:52 -08:00
Aleksei Bavshin 766c8a1035 test: add tests for waybar_time formatter 2022-01-07 22:33:50 -08:00
Aleksei Bavshin 8c41aaae04 refactor(test): use single executable 2022-01-07 19:21:51 -08:00
Aleksei Bavshin c0d84853ea refactor(clock): extract waybar_time to util/waybar_time.hpp 2022-01-07 18:09:44 -08:00
Aleksei Bavshin b6d0a4b63f feat(bar): allow customization of bar modes
Allow changing existing modes and adding new ones via `modes`
configuration key.
`modes` accepts a JSON object roughly described by the following type
```typescript
type BarMode = {
    layer: 'bottom' | 'top' | 'overlay';
    exclusive: bool;
    passthrough: bool;
    visible: bool;
};
type BarModeList = {
    [name: string]: BarMode;
};
```
and will be merged with the default modes defined in `bar.cpp`.

Note that with absence of other ways to set mode, only those defined in
the `sway-bar(5)`[1] documentation could be used right now.

[1]: https://github.com/swaywm/sway/blob/master/sway/sway-bar.5.scd
2021-11-28 12:19:45 -08:00
Aleksei Bavshin cf5ddb2a5e fix(swaybar-ipc): avoid unnecessary copy of struct swaybar_config 2021-11-28 11:34:21 -08:00
Aleksei Bavshin 4b5dc1bb3a test: count copies and moves done by SafeSignal 2021-11-28 09:52:18 -08:00
Aleksei Bavshin b4e19678b7 ci: increase FreeBSD VM memory to 2048MB
Intermittent CI failures without any useful diagnostics could be caused
by the OOM killer. 1024MB is not really enough to run 3 parallel jobs
with a modern C++ compiler.
2021-11-23 19:48:31 -08:00
Aleksei Bavshin 8fe42ebd2e doc: update exclusive and passthrough defaults 2021-11-23 19:18:24 -08:00
Aleksei Bavshin 2290fe10aa fix(bar): handle ipc connection errors.
Try to use the default bar id (`bar-0`) if none is set.
2021-11-23 08:46:58 -08:00
Aleksei Bavshin 6bfb674d1b fix(swaybar-ipc): better logs 2021-11-21 17:28:47 -08:00
Aleksei Bavshin 4154492603 ci: update FreeBSD configuration
Use latest action v0.1.5.
Pin runner to macos-10.15. macos-latest will start using macos-11 images
without VirtualBox in less than a month[1].

[1] https://github.com/actions/virtual-environments/issues/4060
2021-11-19 21:17:55 -08:00
Aleksei Bavshin 5baffbf8f8 doc: document swaybar ipc options, ipc and id 2021-11-19 20:28:57 -08:00
Aleksei Bavshin fbedc3d133 fix(tray): fix visibility of Passive items
`show_all` call from `Tray::update` attempts to walk the widget tree and
make every widget visible. Since we control individual tray item
visibility based on `Status` SNI property, we don't want that to happen.

Modify `Tray::update` to control the visibility of a whole tray module
only and ensure that the children of `Item` are still visible when
necessary.
2021-10-02 00:08:45 -07:00
Aleksei Bavshin 5991bbb741 ci: run unit-tests 2021-09-15 22:20:46 +07:00
Aleksei Bavshin d7d606b721 doc: update documentation for 'include' 2021-09-15 22:20:45 +07:00
Aleksei Bavshin 0c1d3e30b6 fix(config): preserve explicit null when merging objects 2021-09-15 22:20:44 +07:00
Aleksei Bavshin ccc60b4245 refactor(config): more sensible multi-bar include behavior 2021-09-15 22:15:27 +07:00
Aleksei Bavshin 8912bd3ed0 test: multi-bar config with includes 2021-09-15 21:34:56 +07:00
Aleksei Bavshin 9f3b34e4d9 test: validate configuration load 2021-09-15 21:34:55 +07:00
Aleksei Bavshin 6eba62f060 test: add build configs for catch2 2021-09-15 21:34:55 +07:00
Aleksei Bavshin 1f16d7955d refactor(config): drop getValidPath 2021-09-15 21:34:54 +07:00
Aleksei Bavshin 1f7d399b8e refactor(config): remove style handling from Config 2021-09-15 21:34:53 +07:00
Aleksei Bavshin 4fff2eaaa0 refactor(client): change config visibility to public 2021-09-15 21:34:10 +07:00
Aleksei Bavshin b377520a38 refactor(client): extract config handling into a new class 2021-09-14 13:15:54 +07:00
Aleksei Bavshin a5fe6f40b8 feat(tray): handle Status property
On the `Passive` value of `Status` tray items would be hidden unless
`show-passive-items` is set to true.
On the `NeedsAttention` value of `Status` tray items will have a
`.needs-attention` CSS class.
2021-07-22 08:04:06 -07:00
Aleksei Bavshin 245f7f4b11 feat(tray): handle scroll events 2021-07-22 08:04:05 -07:00
Aleksei Bavshin 1418f96e46 feat(tray): fallback to Title for items without ToolTip 2021-07-22 08:04:04 -07:00
Aleksei Bavshin 84a8f79bbe feat(tray): implement tooltips (text only) for tray items 2021-07-22 08:04:03 -07:00
Aleksei Bavshin 4b6253e810 refactor(tray): infer changed properties from signal name
Comparing two GVariants is too expensive; let's collect the set of
properties updated by each signal and apply them unconditionally.
2021-07-22 08:04:00 -07:00
Aleksei Bavshin 929fc16994 fix(tray): ignore unused WindowId property 2021-07-22 08:01:25 -07:00
Aleksei Bavshin 5420a91046 chore: update FreeBSD action to address ntp sync issue 2021-07-01 00:13:30 -07:00
Aleksei Bavshin 2a52efa99a chore: update fedora dockerfile 2021-06-30 23:51:28 -07:00
Aleksei Bavshin d3c59c42ef feat(ci): add GitHub CI jobs on Linux 2021-06-30 23:51:09 -07:00
Aleksei Bavshin 5da268077c fix(util): protect std::condition_variable methods from pthread_cancel
The changes in GCC 11.x made `std::condition_variable` implementation
internals `noexcept`. `noexcept` is known to interact particularly bad
with `pthread_cancel`, i.e. `__cxxabiv1::__force_unwind` passing through
the `noexcept` call stack frame causes a `std::terminate` call and
immediate termination of the program

Digging through the GCC ML archives[1] lead me to the idea of patching
this with a few pthread_setcancelstate's. As bad as the solution is, it
seems to be the best we can do within C++17 limits and without major
rework.

[1]: https://gcc.gnu.org/legacy-ml/gcc/2017-08/msg00156.html
2021-06-12 12:56:44 -07:00
Aleksei Bavshin da2d603b53 doc: add man for exclusive and passthrough flags 2021-05-21 22:44:19 -07:00
Aleksei Bavshin 7aaa3df701 feat(bar): add config flag to disable exclusive zone 2021-05-21 22:44:18 -07:00
Aleksei Bavshin 729553d3bc feat(bar): add config flag for pointer event passthrough 2021-05-21 22:44:17 -07:00
Aleksei Bavshin 943ba3a2da fix: schedule output destruction on idle callback
Defer destruction of bars for the output to the next iteration of the
event loop to avoid deleting objects referenced by currently executed
code.
2021-02-22 18:35:09 -08:00
Aleksei Bavshin e786ea601e fix(rfkill): handle EAGAIN correctly 2021-02-10 08:26:21 -08:00
Aleksei Bavshin 6d5afdaa5f fix(network): don't block the main thread on rfkill update
Moving rfkill to the main event loop had unexpected side-effects.
Notably, the network module mutex can block all the main thread events
for several seconds while the network worker thread is sleeping.

Instead of waiting for the mutex let's hope that the worker thread
succeeds and schedule timer thread wakeup just in case.
2021-02-09 21:27:22 -08:00
Aleksei Bavshin 52dd3d2446 refactor(bluetooth): remove interval and timer thread
The timer thread was always reading the same value from Rfkill state.
2021-02-09 21:27:21 -08:00
Aleksei Bavshin ecc32ddd18 refactor(bluetooth): remove Bluetooth::status_
The string was always overwritten in `update()`; don't need to store
temporary value in the class.
2021-02-09 21:27:20 -08:00
Aleksei Bavshin 38c29fc242 refactor(rfkill): poll rfkill events from Glib main loop
Open rfkill device only once per module.
Remove rfkill threads and use `Glib::signal_io` as a more efficient way
to poll the rfkill device.
Handle runtime errors from rfkill and stop polling of the device instead
of crashing waybar.
2021-02-09 21:27:19 -08:00
Aleksei Bavshin 40f4dc9ecf fix(rfkill): accept events larger than v1 event size
Kernel 5.11 added one more field to the `struct rfkill_event` and broke
unnecessarily strict check in `rfkill.cpp`. According to `linux/rfkill.h`,
we must accept events at least as large as v1 event size and should be
prepared to get additional fields at the end of a v1 event structure.
2021-02-09 21:27:18 -08:00
Aleksei Bavshin 89b5e819a3 fix(client): improve guard from repeated xdg_output.done events
Multiple .done events may arrive in batch. In this case libwayland would
queue xdg_output.destroy and dispatch all pending events, triggering
this callback several times for the same output.

Delete xdg_output pointer immediately on the first event and use the
value as a guard for reentering.
2021-02-08 23:25:58 -08:00
Aleksei Bavshin 6585381230 fix(client): remove unnecessary wl_output_roundtrip
At this point we're not awaiting any protocol events and flushing
wayland queue makes little sense. As #1019 shows, it may be even harmful
as an extra roundtrip could process wl_output disappearance and delete
output object right from under our code.
2021-02-08 22:30:01 -08:00
Aleksei Bavshin 7fa1c11833 fix(client): unsubscribe after receiving xdg_output.done event
Ignore any further xdg_output events. Name and description are constant
for the lifetime of wl_output in xdg-output-unstable-v1 version 2 and we
don't need other properties.

Fixes #990.
2021-01-21 08:35:38 -08:00
Aleksei Bavshin ab0f2c13af fix(client): attach styles only once
Gdk >= 3.10 has only one GdkScreen. No need to reattach styles on every
output change.
2021-01-21 08:32:44 -08:00
Aleksei Bavshin b79301a5bd fix(wlr/taskbar): protocol error when reconnecting outputs
Destroy request is not specified for foreign toplevel manager and it
does not prevent the compositor from sending more events.
Libwayland would ignore events to a destroyed objects, but that could
indirectly cause a gap in the sequence of new object ids and trigger
error condition in the library.

With this commit waybar sends a `stop` request to notify the compositor
about the destruction of a toplevel manager. That fixes abnormal
termination of the bar with following errors:
```
(waybar:11791): Gdk-DEBUG: 20:04:19.778: not a valid new object id (4278190088), message toplevel(n)

Gdk-Message: 20:04:19.778: Error reading events from display: Invalid argument
```
2021-01-08 15:41:48 -08:00
Aleksei Bavshin ef9c3ef1cb fix(wlr/taskbar): fix wl_array out-of-bounds access
wl_array->size contains the number of bytes in the array instead of the
number of elements.
2021-01-08 15:28:29 -08:00
Aleksei Bavshin 68b6136989 fix(sway/workspaces): ignore emulated scroll events
GDK Wayland backend can emit two events for mouse scroll: one is a
GDK_SCROLL_SMOOTH and the other one is an emulated scroll event with
direction. We only receive emulated events on a window, thus it is not
possible to handle these in a module and stop propagation.

Ignoring emulated events should be safe since those are duplicates of
smooth scroll events anyways.

Fixes #386
2020-12-04 01:09:42 -08:00
Aleksei Bavshin 2695985da0 fix: compilation error with gcc 11
../src/modules/network.cpp:22:6: error: ‘optional’ in namespace ‘std’ does not name a template type
   22 | std::optional<unsigned long long> read_netstat(std::string_view category, std::string_view key) {
      |      ^~~~~~~~
../src/modules/network.cpp:7:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
    6 | #include "util/format.hpp"
  +++ |+#include <optional>
    7 | #ifdef WANT_RFKILL
2020-11-26 15:42:44 -08:00
Aleksei Bavshin 85e00b2aab fix: build fails with meson < 0.53.0
meson.build:12:0: ERROR: Module "fs" does not exist

Fixes #909
2020-11-26 15:40:24 -08:00
Aleksei Bavshin 9c566564e1 fix(bar): address some of RawSurfaceImpl resizing issues 2020-10-28 08:22:26 -07:00
Aleksei Bavshin fc5906dbd4 feat(bar): change layer to bottom when hidden
Invisible bar on a `top` layer would still intercept pointer events and
stop them from reaching windows below. Always changing the layer to
to `bottom` along with making bar invisible would prevent that.
2020-10-28 08:18:49 -07:00
Aleksei Bavshin fe3aeb36c5 refactor(bar): wrap layer_surface pointer in unique_ptr 2020-10-28 08:15:02 -07:00
Aleksei Bavshin 591a417b7d fix(bar): rework surface commit calls for RawSurfaceImpl
wayland log shows that some changes were committed twice and some
weren't committed until the next redraw.
2020-10-28 08:14:57 -07:00
Aleksei Bavshin d4d35e6b2b chore(subprojects): update gtk-layer-shell to 0.4.0 2020-10-28 08:08:04 -07:00
Aleksei Bavshin f97de599dd refactor: header cleanup
Replace a couple of header includes with forward declarations.
2020-10-28 08:08:03 -07:00
Aleksei Bavshin f01996ae99 fix(bar): CamelCase SurfaceImpl method names 2020-10-28 08:07:40 -07:00
Aleksei Bavshin 7735c80d0e refactor(bar): Split GLS and raw layer-shell implementations
Extract two surface implementations from the bar class: GLSSurfaceImpl
and RawSurfaceImpl. This change allowed to remove _all_ surface type
conditionals and significantly simplify the Bar code.

The change also applies PImpl pattern to the Bar, allowing to remove
some headers and fields from `bar.hpp`.
2020-10-28 07:53:37 -07:00
Aleksei Bavshin 2b3d7be9cb feat(bar): let gtk-layer-shell manage exclusive zone
Previous attempts to use auto exclusive zone from gtk-layer-shell failed
because gls was expecting real booleans (`TRUE`/`FALSE`) as set_anchor
arguments. With that being fixed, gtk_layer_auto_exclusive_zone_enable
makes gls handle everything related to the bar resizing.

The only remaining purpose of onConfigureGLS is to log warnings and bar
size changes; gtk-layer-shell code path no longer needs saved width_ or
height_ values.
2020-10-28 07:53:32 -07:00
Aleksei Bavshin 67d54ef3d5 fix(wlr/taskbar): do not bind to unsupported protocol versions
It's not allowed to bind to a higher version of a wayland protocol than
supported by the client. Binding wlr-foreign-toplevel-manager-v1 v3 to
a generated code for v2 causes errors in libwayland due to a missing
handler for `zwlr_foreign_toplevel_handle_v1.parent` event.
2020-10-25 10:26:44 -07:00
Aleksei Bavshin ebdeb86703 feat(swaybar-ipc): handle visibility_by_modifier update 2020-10-19 19:35:55 -07:00
Aleksei Bavshin bc13453155 feat(swaybar-ipc): handle mode update 2021-09-15 22:39:51 +07:00
Aleksei Bavshin 23e5181cac feat(swaybar-ipc): add swaybar IPC client 2020-10-19 19:34:48 -07:00
Aleksei Bavshin 452dcaa5d3 feat(client): store bar_id argument 2021-11-19 20:28:41 -08:00
Aleksei Bavshin 5905078e56 doc: document mode option of the bar config 2021-11-19 21:02:29 -08:00
Aleksei Bavshin 52361ed360 refactor(bar): make setVisible switch between "default" and "invisible" modes 2021-11-21 11:00:57 -08:00
Aleksei Bavshin 87b43c2171 feat(bar): attach CSS class mode-{mode} to window when setting mode 2021-11-19 20:02:57 -08:00
Aleksei Bavshin ae88d7d8dc feat(bar): use "default" mode to store global options
Read `layer`, `exclusive`, `passthrough` into a special mode "default".
Drop `overlay` layer hacks, as it's easier to use `"mode": "overlay"`
for the same result.
2021-11-19 19:31:41 -08:00
Aleksei Bavshin 6d2ba7a75b feat(bar): store modes as a map of presets
This allows to apply the mode atomically and adds possibility of
defining custom modes (to be implemented).
2021-11-19 19:29:51 -08:00
Aleksei Bavshin 03a641ed83 feat(bar): support swaybar mode for configuring window
Use `mode` (`waybar::Bar::setMode`) as a shorthand to configure bar
visibility, layer, exclusive zones and input event handling in the same
way as `swaybar` does.
See `sway-bar(5)` for a description of available modes.
2021-09-15 22:35:50 +07:00
Aleksei Bavshin 3e2197a82a test(util): add tests for SafeSignal
Add a fixture for writing tests that require interaction with Glib event
loop and a very basic test for SafeSignal.
2020-12-28 17:28:03 -08:00
Aleksei Bavshin 79883dbce4 feat(util): optimize SafeSignal for events from the main thread 2020-12-28 17:31:23 -08:00
Aleksei Bavshin 8a0e76c8d8 fix(util): avoid creating temporary functor for each event 2020-10-19 18:42:25 -07:00
Aleksei Bavshin 285a264aae feat(util): SafeSignal class for cross-thread signals with arguments
Implement a wrapper over Glib::Dispatcher that passes the arguments to
the signal consumer via synchronized `std::queue`.
Arguments are always passed by value and the return type of the signal
is expected to be `void`.
2020-12-28 17:26:55 -08:00
Aleksei Bavshin f4e15dd93d chore(subprojects): update gtk-layer-shell to 0.3.0
Fixes warning about xdg_wm_base.version mismatch.
Fixes potential crash when GTK does not expect wl_surface to be committed.
2020-08-14 23:53:44 -07:00
Aleksei Bavshin 3663b9193d refactor(bar): separate GTK event handlers for gtk-layer-shell
Cleanly separate resizing logic for gtk-layer-shell and manually managed
layer surface code.
2020-08-14 22:47:57 -07:00
Aleksei Bavshin dcc0201b45 chore(protocol): update wlr-layer-shell-unstable-v1 protocol.
Statically linked gtk-layer-shell would use layer-shell protocol object
file from waybar and print runtime warning if the version does not match
2020-08-05 09:46:21 -07:00
Aleksei Bavshin 66aa3574d9 chore(subprojects): update gtk-layer-shell to 0.2.0
Fixes: #530, fixes #750
2020-08-05 09:46:10 -07:00
Aleksei Bavshin 40d3f1c1fe chore(subprojects): update date to 3.0.0
Fixes #776, fixes #780
2020-08-05 09:46:01 -07:00
Aleksei Bavshin dd0144c3cd fix(bar): set exclusive zone early for gtk-layer-shell
If the bar is using initial size from the config (i.e both width and
height are set and resize is not required), GtkWindow configure event
is is not emitted. Initialize exclusive zone earlier for that case.

Fixes #609
2020-03-04 06:56:25 -08:00
Aleksei Bavshin e70f8d8730 fix(clock): lower precision of zoned_time to avoid fractional seconds in output 2020-02-06 10:04:22 -08:00
Aleksei Bavshin ae6ca36fa7 fix(sway): resolve destruction dependency between Ipc and SleeperThread
Ipc destructor closes socket and thus wakes up SleeperThread which was
waiting for socket data in Ipc::handleEvent.
Ipc::handleEvent then proceeds with sending signal to already destroyed
object, causing heap-use-after-free Address Sanitizer error.
2020-02-04 23:22:43 -08:00
Aleksei Bavshin f80270519b refactor(client): use std::list<waybar_output> to store outputs
std::unique_ptr is not required here as the only benefit it gives is
stability of address on vector resize and it's easy to invalidate it
accidentaly. std::list provides the same guarantee of stable addresses
of the elements and correct destruction while avoiding smart pointer
overhead.

Also fixes #554, caused by incorrect usage of std::remove_if.
2020-01-14 07:27:08 -08:00
Aleksei Bavshin dde700f2c9 feat: use gtk-layer-shell library for correct positioning of popups
To enable: use sway >= 1.2, compile waybar with `-Dgtk-layer-shell=enabled` meson option.
Original behavior could be restored at runtime by setting `"gtk-layer-shell": false` in waybar config.
2019-12-27 16:42:14 -08:00
Aleksei Bavshin 0e87b3938a deps: meson dependencies for gtk-layer-shell feature 2019-12-27 16:42:13 -08:00
Aleksei Bavshin d1637d34cf refactor: fetch outputs from Gtk::Display instead of wl_registry.
gtk-layer-shell wants Gdk::Monitor instead of wl_output;
change code to deal with Gdk objects and slightly simplify it.
Requires gtkmm 3.22.0+ (first release with Gdk::Monitor support).
2019-12-27 16:42:12 -08:00
Aleksei Bavshin 529daedcec fix: correct handling of margins on anchored axis 2019-09-01 01:08:15 -07:00