Commit graph

337 commits

Author SHA1 Message Date
Daniel Eklöf
515b36da0d
foreign-toplevel: refresh the bar when a top-level is closed
Fixes an issue where the last active window is still being displayed
in the bar after the corresponding top-level has been closed.

Reported here: https://github.com/johanmalm/labwc/issues/73#issuecomment-945007028
2021-10-17 09:52:28 +02:00
Daniel Eklöf
f8e544ae05
Merge branch 'freebsd-step1' 2021-10-02 12:33:08 +02:00
Baptiste Daroussin
26892c66b2 headers: basename is defined under libgen.h 2021-10-01 10:51:56 +02:00
Daniel Eklöf
1bcf116859
modules: handle udev_monitor_receive_device() returning NULL
Closes #109
2021-09-30 10:01:36 +02:00
Stanislav Ochotnický
8709e8da38 Make default battery state as unknown
When a given battery is not found or otherwise state cannot be read - we
default to "unknown" state instead of discharging with incomplete data
2021-09-20 08:38:54 +02:00
Stanislav Ochotnický
e723b039ad Make libmpdclient an optional dependency
Without this change yambar can't be installed/used without libmpdclient even for
people who do not use MPD. Let's make this optional.

We could put the optional module summary in the module meson.build but we'd have
to move summary() in main meson.build so that they appear in proper order.
2021-09-16 11:46:22 +02:00
anb
ba5b28f437 clock: add a config option to show UTC time 2021-09-12 11:19:53 -07:00
Daniel Eklöf
dabb2e1407
module/network: add support for periodically polling Wi-Fi stats
This adds a new ‘poll-interval’ option to the network module. When set
to a non-zero value, the following Wi-Fi stats will be updated:

* Signal strength
* RX+TX bitrate
2021-09-01 19:10:23 +02:00
Daniel Eklöf
d450bf12a1
module/network: re-request station info when we’re re-connected 2021-09-01 19:10:22 +02:00
Daniel Eklöf
e8a2f8df9a
module/network: reset signal strength and RX+TX bitrates on disconnect 2021-09-01 19:10:22 +02:00
Daniel Eklöf
a685dadb75
module/network: expose signal strength and rx+tx bitrates 2021-09-01 19:10:22 +02:00
Daniel Eklöf
b27eff36f9
module/network: nl80211: join the MLME mcast group, ignore messages not for us
This cleans up the nl80211 handling quite a bit, and adds initial
support for nl80211 notifications.

* We now join the nl80211 MLME multicast group (done by parsing the
  CTRL_ATTR_MCAST_GROUPS attribute in the reply to our
  CTRL_CMD_GETFAMILY request).  This gives us CONNECT and DISCONNECT
  notifications, allowing us to request and reset SSID that way, instead
  of detecting the link’s OPER state.

* Before parsing an nl80211 message, verify it’s for us, by looking
  for a NL80211_ATTR_IFINDEX attribute in the message (and comparing the
  contents with our previously detected ifindex).
2021-09-01 19:10:22 +02:00
Daniel Eklöf
9b3548736a
module/network: refactor: add foreach_nlattr()
This function iterates all attributes of a NETLINK_GENERIC message,
and calls the provided callback for each attribute.
2021-09-01 19:10:22 +02:00
Daniel Eklöf
5249d9ef79
module/network: use separate functions to connect to RT/GENL netlink 2021-09-01 19:10:21 +02:00
Daniel Eklöf
d39e6b8b94
module/network: initial support for Wifi extensions
Currently capable of getting the SSID.
2021-09-01 19:10:21 +02:00
Daniel Eklöf
e9d762fa03
module/foreign-toplevel: disable debug logging 2021-08-27 10:14:54 +02:00
Daniel Eklöf
149798fe98
Merge branch 'alsa-capture-devices' 2021-08-27 06:42:42 +02:00
Daniel Eklöf
1079bca3eb
Silence “variable length array bound evaluates to non-positive value 0” 2021-08-26 13:27:29 +02:00
Daniel Eklöf
d1c7647b03
module/alsa: add support for capture devices
This mostly comes down to tracking whether each channel is a playback,
or capture channel, and using the appropriate APIs when dealing with
it.

Some cleanup related to this:

* Add a channel struct, for per-channel data. Previously, our channel
  list was just a list of ALSA channel IDs.
* We now store current volume per-channel (but volume min/max is
  per-device)
* Muted state is stored per-channel
* Track both the device’s playback and capture volume ranges, as well
  as whether the device *has* playback or capture volume.
* Get the playback/capture volume ranges once, during init, instead of
  at each update.
* Use struct pointers for the volume/muted channels. This way we don’t
  have to iterate all channels and to string comparisons on the name
  each time we update our state.
2021-08-26 11:03:12 +02:00
Daniel Eklöf
7c7c4e7ce9
module/alsa: rename {volume,muted}_channel -> {volume,muted}_name 2021-08-26 09:42:41 +02:00
Daniel Eklöf
103c3102a9
module/river: rename the ‘per-output’ option to ‘all-monitors’
This also inverts its meaning.
2021-08-25 18:47:33 +02:00
Daniel Eklöf
9681e0aabe
module/foreign-toplevel: require version 3 of wl-output interface
The bar itself already does this, and doing so means we can always use
wl_output_release() (instead of wl_output_destroy()).
2021-08-25 18:46:19 +02:00
Daniel Eklöf
589a6f528a
module/foreign-toplevel: track outputs each toplevel is mapped on
* Bind the foreign-toplevel-manager object *after* the first round of
  global objects. This ensures we bind all pre-existing wl-output
  objects before binding the toplevel manager. This is important, since
  otherwise we wont get any output_enter() events for the initial set of
  toplevels.

* Bind xdg-output-manager, to be able to bind xdg-output objects for
  each wl-output.

* Add xdg-output-listener to each wl/xdg-output, to be able to get the
  outputs’ names.

* Add a list of outputs to each toplevel. The output_enter() event
  adds to this list, and output_leave() removes from it.

* Add option ‘all-monitors’. When not set (the default), toplevels are
  only included in the generated content if they are mapped on the same
  output as the bar itself. When *not* set, all toplevels are always
  included in the generated content.
2021-08-25 18:46:19 +02:00
Daniel Eklöf
560d7464b4
module/foreign-toplevel: initial support
* ‘content’ is a template; the module returns a list of toplevels,
  each one instantiated using the content template.
* Each toplevel has 6 tags:
  - app-id (string)
  - title (string)
  - maximized (bool)
  - minimized (bool)
  - activated (bool)
  - fullscreen (bool)

To show the application name and title of the currently active window,
one can do:

    - foreign-toplevel:
        content:
          map:
            tag: activated
            values:
              false: {empty: {}}
              true: {string: {text: "{app-id}: {title}"}}
2021-08-25 18:46:18 +02:00
Daniel Eklöf
7e7c011126
module/river: use wl_output_release() instead of wl_output_destroy() 2021-08-25 09:45:08 +02:00
Daniel Eklöf
a5be550964
module/alsa: free channel list on each connect attempt
Otherwise we’ll keep adding the same channel(s) over and over again,
for each (successful) connect attempt.

I.e. if you plug and unplug an USB soundcard repeatedly, we’ll keep
extending the channel list each time.
2021-08-21 15:26:53 +02:00
Daniel Eklöf
360e1fbada
module/alsa: don’t re-create the /dev/snd inotify watcher after each connect failure
When e.g. a USB soundcard is inserted, we get several CREATE
events. In my experiments, we only succeed in connecting to ALSA after
the last event.

This means, we’ll have several CREATE events that we receive, remove
the watcher, attempt to connect, fail, and then re-add the watcher.

What if that “last” CREATE event occurs while our watcher has been
removed? That’s right, we miss it, and will get stuck waiting forever.

The solution is keep the watcher around.

Now, if we’ve been successfully connected to ALSA for a long time,
chances are we’ve built up events (for other cards, for example). We
don’t want to trigger a storm of re-connect attempts, so drain the
event queue after having been disconnected from ALSA.

There *is* a small race here - if a card is removed and
re-added *very* fast, we _may_ accidentally drain the CREATE event. I
don’t see this happening in reality though.
2021-08-21 11:08:45 +02:00
Daniel Eklöf
25c20e5534
module/alsa: use inotify on /dev/snd instead of a poll timeout
While waiting for the configured ALSA card to become available, use
inotify and watch for CREATE events on /dev/snd instead of
polling (using a timeout in the poll(3) call).

Note that we don’t know the actual names of the files that (will) be
created. This means:

* Every time we see a CREATE event on /dev/snd, we *try* to connect to
  ALSA. If we fail, we go back to watching /dev/snd again.
* ALSA (not yambar) will log an error message each time we fail.
2021-08-21 10:52:12 +02:00
Daniel Eklöf
db12ceb026
module/alsa: volume/muted: default to “unset”; use first available channel 2021-08-20 21:41:21 +02:00
Daniel Eklöf
ae7d54fb80
module/alsa: add ‘volume’ and ‘muted’ options
These options allows you to select which channel to use as volume
source, and which channel to use as the source for the muted state.

With this, we can also remove the check for *all* (playback) channels
having the same volume/muted state. And with that, we no longer need
to warn when not all channels have the same volume/muted state.
2021-08-20 20:24:44 +02:00
Daniel Eklöf
be6e714eb0
module/alsa: handle ALSA device disappearing
With this patch, a non-existing ALSA device is no longer considered a
fatal error. Instead, we keep retrying until we succeed.

Furthermore, if we have successfully opened the ALSA device, and it
then disappears, we a) no longer crash, or cause 100% CPU usage, and
b) try to re-connect to the device.

With this, we now handle e.g. USB soundcards being disconnected and
then re-connected. We should also handle pseudo devices, like pipewire
provides ones, when yambar is started before pipewire.

Closes #59
Closes #61
Closes #86
2021-08-19 19:26:40 +02:00
Daniel Eklöf
8b6b82f1e5
module/river: add support for river-status v2 (‘urgent’ views) 2021-08-19 19:25:18 +02:00
Daniel Eklöf
7d3851046e
log: pull in log.{c,h} from foot 2021-08-15 11:41:12 +02:00
Daniel Eklöf
ba7b9e6244
module/river: add ‘per-output’ attribute
When set, river tags and seats’ view titles apply to the output yambar
is on, only.

The default is disabled, which implements the old behavior, where
river tags and seats’ view titles represent the union of all
outputs.
2021-08-09 19:56:48 +02:00
Daniel Eklöf
7da13a26d0
module/i3: add ‘persistent’ attribute
Add ‘persistent’, a list-of-strings specifying workspace names that
should be persistent. That is, workspaces that should never be
removed, even if empty.

Note that the workspaces _are_ still destroyed (in i3/Sway), but
yambar keeps abstractions for them around. This is useful to e.g. keep
a strict order between your “core” workspaces.

Closes #72
2021-07-26 21:41:59 +02:00
Daniel Eklöf
cf41d008f8
module/script: add poll-interval option
When set to a non-negative value, the script module will call the
configured script every <poll-interval> second.

In this mode, the script is expected to write one tag set and then
exit.

This is intended to simplify the implementation of scripts that would
otherwise just do a loop + sleep.

Closes #67
2021-07-04 20:23:01 +02:00
Daniel Eklöf
8f7ef7c20b
module/river: don’t refresh the bar unless there are any actual changes 2021-07-01 17:14:47 +02:00
Daniel Eklöf
7c6874d826
module/river: disable debug log output 2021-07-01 17:14:26 +02:00
Daniel Eklöf
ed2b8c4874
modules: implement description() 2021-06-20 21:15:24 +02:00
Daniel Eklöf
60ee992a73
module/script: ‘9’ is a valid digit
The script module incorrectly rejected range tag end values containing
the digit ‘9’.

Closes #60
2021-06-19 14:19:31 +02:00
mz
35e6943531 Differentiate "Not Charging" and "Discharging" in state tag of battery module.
Some batteries support charge thresholds and when the upper limit is set to a number less than 100 percent and it reaches that limit and it is connected to the charger the battery state will be "Not charging".
It doesn't charge anymore despite it's not full.
2021-06-14 19:02:01 +02:00
Daniel Eklöf
aadb1b22b3
module/battery: don’t terminate when failing to update
Some battery drivers will remove their sysfs directory when the
battery goes from charging to discharging, or vice verse.

This caused yambar’s battery module to terminate, resulting in the
last known battery state to “freeze”.

With this patch, failure to read the battery directory the *first*
time is still considered a hard failure, resulting in an error message
and then termination.

However, subsequent failures, i.e. while polling the battery state,
is *not* considered fatal; we simply don’t update the bar, and retry
again the next poll interval. Error messages are still logged however.

Closes #44
2021-06-12 21:43:57 +02:00
Daniel Eklöf
8153e40f2a
module/sway-xkb: ignore non-keyboards in input event handler
This is already being done in the initial query response. Not doing it
in the input event handler too leads to an assertion if there are
multiple devices with the same ID.

Hopefully fixes #54
2021-06-01 17:40:59 +02:00
Daniel Eklöf
463f1ea75d
module/sway-xkb: ignore non-keyboard inputs
Closes #51
2021-05-26 21:11:53 +02:00
Daniel Eklöf
264c051232
module/script: fix typo in memcmp()
Patch by Jan Beich
2021-02-10 16:15:49 +01:00
Daniel Eklöf
4f70346601
module/battery: re-open /sys/class/power_supply/<battery>/ every update 2021-01-14 11:08:57 +01:00
Daniel Eklöf
cfeb5260dd
module/battery: re-open files on every update
Closes #25
2021-01-14 11:08:57 +01:00
Daniel Eklöf
5bfa104935
module/i3: separate numerical workspace names from non-numerical
When sorting workspaces in ascending order, put numerical
workspaces *after* non-numerical ones.

When sorting in descending order, put numerical workspaces *before*
non-numerical.

In both cases, sort numerical workspaces using a numerical comparison,
rather that doing a lexicographical sorting.

Closes #30
2021-01-04 20:16:30 +01:00
Daniel Eklöf
e85e3e8ced
module/mpd: increase tag count in tag set
96d2d057e0
added a new tag, ‘volume’, but didn’t bump the tag count.

This meant the last tag in the set, ‘elapsed’ was never seen by
anybody, and not free:d when the tag set was free:d.
2021-01-04 20:01:46 +01:00
Daniel Eklöf
3da796810b
module/i3: take lock while updating ‘mode’ 2020-12-12 22:42:19 +01:00