Commit graph

38 commits

Author SHA1 Message Date
Daniel Eklöf
3ca274759a
module: const:ify ‘module’ argument to module->description() 2022-12-14 12:05:17 +01:00
Daniel Eklöf
6c10eb2153
module/alsa: use channel’s dB range instead of raw volume, if available
For channels that have a defined dB range, use that instead of the raw
volume range when calculating the volume percent.

Also use the same logic as alsamixer when calculating the percent from
the dB values: assume a linear scale if the dB range is “small
enough”, and otherwise normalize it against a logarithmic scale.

With this, yambar’s “percent” value matches alsamixer’s exactly.

The ‘volume’ tag remains unchanged - it always reflects the raw volume
values.

Instead, we add a new tag ‘dB’, that reflects the dB values.

Closes #202
2022-06-21 19:49:06 +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
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
ed2b8c4874
modules: implement description() 2021-06-20 21:15:24 +02:00
Daniel Eklöf
db53cf9245
module/alsa+backlight: round() percentage values
Closes #10
2020-09-24 13:57:05 +02:00
Daniel Eklöf
85ae4cca37
module/alsa: add ‘percent’ tag - volume level as a percentage
Fixes part of #10
2020-09-24 13:54:41 +02:00
Daniel Eklöf
bdc5dea428 module/alsa: set unmuted=false if we device doesn't have the muted property 2020-06-18 20:08:47 +02:00
Daniel Eklöf
86522d653d
modules: move 'content' and 'anchors' to MODULE_COMMON_ATTRS
All modules implement these. The only one that differs is the i3
module. It still implements them, but 'content' uses an internal
verifier function.
2020-01-24 21:08:39 +01:00
Daniel Eklöf
0550d2799d
tllist: use tllist from external git repository 2019-11-17 19:17:34 +01:00
Daniel Eklöf
b6e61f9c7e modules: use calloc() instead of malloc()
In cases where it makes sense, use calloc() instead of malloc():

* When allocating large objects with many members, many for which
  NULL/0 is a good default value.
* Arrays etc where we explicitly initialize to NULL anyway.
2019-02-09 11:11:31 +01:00
Daniel Eklöf
ae5029826b cmake: break out bar stuff to separate CMakeLists.txt 2019-02-07 12:06:16 +01:00
Daniel Eklöf
452c4b6015 plugins: export a const function pointer interface struct 2019-01-26 18:32:04 +01:00
Daniel Eklöf
cffb007009 module/alsa: handle failure(s) to attach to card or find mixer 2019-01-19 19:58:02 +01:00
Daniel Eklöf
0d591fe5a1 allow plugins to be compiled into the f00bar main binary 2019-01-14 20:57:03 +01:00
Daniel Eklöf
4a26664d8d particles: remove config-verify.h from particle.h 2019-01-13 17:41:39 +01:00
Daniel Eklöf
bc62843c91 modules: get rid of struct module_info
Since this struct only contained function pointers, make all modules
export those functions directly.

The plugin manager now defines a module interface struct, and fills it
it by dlsym:ing the functions that used to be in module_info.
2019-01-13 17:09:11 +01:00
Daniel Eklöf
76d135e257 module: remove module_run_context
Store abort_fd directly in the module struct instead. This then allows
us to pass the module pointer as-is to the modules' run functions.
2019-01-13 15:34:59 +01:00
Daniel Eklöf
acdeff3b6e module: remove ready_fd
All modules are expected to handle a call to content() after having
been instantiated.

I.e. modules *cannot* even expect run() to have started running.
2019-01-13 15:25:39 +01:00
Daniel Eklöf
a425378576 config: allow font/foreground attributes on modules too
Previously we allowed it on the bar, and on all particles. Now we also
allow it on all modules.

This allows us to specify a "default" font/foreground on a per-module
basis, having it applied to all the modules particles.
2019-01-13 14:24:44 +01:00
Daniel Eklöf
8dc278aaf2 config: pass a struct with inheritable values
For now, font and foreground color
2019-01-13 14:13:14 +01:00
Daniel Eklöf
9944a8f972 modules: don't assume module content is a dictionary
This is done by having each module implement a top-level verifier
function.
2019-01-13 11:54:57 +01:00
Daniel Eklöf
71515e4079 config: conf_verify_dict() now assumes attr list is NULL-terminated 2019-01-13 11:37:05 +01:00
Daniel Eklöf
ec4a47e5db modules: rename module_info -> plugin_info
This is the same name used by particles.
2019-01-13 11:18:32 +01:00
Daniel Eklöf
42104db1ca modules: move files back to a common directory (again) 2019-01-12 21:24:20 +01:00
Daniel Eklöf
8809cbb481 Put each module in its own subdirectory 2019-01-12 11:19:57 +01:00
Daniel Eklöf
54798567c0 module/alsa: track all channels
Warn if volume and/or muted state is inconsistent (as we only expose a
single volume/muted state).

Also, don't query for current volume if max == 0 (i.e. typically a
digital output).

Finally, make absolutely sure that volume min is really less (or
equal) to volume max, and that the current volume level is between min
and max.
2019-01-09 18:50:26 +01:00
Daniel Eklöf
efe3dd06ab alsa: initialize values, fixes valgrind warning
When snd_mixer_selem_get_*() fails, the values were left
uninitialized, trigger a valgrind warning.

In addition to fixing this, the error(s) are now logged (but only as
warnings, as they are not fatal).
2019-01-07 18:29:03 +01:00
Daniel Eklöf
43aeb1c224 module/alsa: include volume min/max/cur and muted state in info log 2019-01-02 18:14:26 +01:00
Daniel Eklöf
64a52656b1 module/alsa: log info message when up and running 2019-01-02 18:11:39 +01:00
Daniel Eklöf
2d5d1d5a46 module/alsa: disable debug logging 2019-01-02 18:08:32 +01:00
Daniel Eklöf
0d8704737e module/alsa: monitors volume and muted state of selected card/mixer 2019-01-02 18:07:16 +01:00