Commit graph

415 commits

Author SHA1 Message Date
Daniel Eklöf
f4ceaaad52
module/sway-xkb: handle device being added again
If a device is removed while the computer is hibernating, and then
reconnected after waking it up, Sway sends an “added” event without
first sending a “removed” event.

Yambar used to assert that an “added” event didn’t refer to an already
tracked device.

This patch changes this, and simply ignores duplicate “added” events.

Closes #177
2022-06-03 19:37:52 +02:00
Daniel Eklöf
ca077447c2
module/network: tx/rx-bitrate is now in bits/s instead of Mb/s 2022-06-02 22:25:53 +02:00
Daniel Eklöf
c738f1c63d
module/river: add support for the ‘mode’ event
Seat status v3 adds a new ‘mode’ event, that informs us of the current
mode (as set by e.g. ‘riverctl enter-mode passthrough’)

The mode is exposed as a tag (named “mode”) on river’s “title”
particle:

  - river:
      title:
        map:
          default: {empty: {}}
          conditions:
            mode == passthrough:
              string: {text: " {mode} ", deco: {background: {color: ff0000ff}}}
2022-06-02 17:24:42 +02:00
Daniel Eklöf
62ca06eccb
module/cpu: don’t use core ID from /proc/stat as array index
/proc/stat lists CPU usage, in the form:

  cpu ...
  cpu0 ...
  cpu1 ...
  ...
  cpuN ...

where the first line is a summary line. We’ve been using the CPU
numbers from /proc/stat to index into our internal stats array.

This doesn’t work on systems where the core IDs aren’t
consecutive. Examples of such systems are SMT systems with SMT
disabled. Here, /proc/stat may look like this instead:

  cpu ...
  cpu0 ...
  cpu2 ...
  cpu4 ...
  ...

With this patch, we ignore the CPU ID from /proc/stat. Instead, we use
a simple counter that is incremented for each (valid) cpu line found
in /proc/stat. To protect against corrupt /proc/stat content, stop
parsing /proc/stat if the number of parsed CPU lines exceed what we
consider to the be total number of CPUs in the system.

Closes #172
2022-04-07 13:28:35 +02:00
Daniel Eklöf
fce2787bdf
module/cpu: use get_nprocs() to retrieve the CPU count 2022-04-07 13:21:41 +02:00
Daniel Eklöf
fd014dc33b
Don’t loop 65536 FDs, trying to close them, when fork+exec:ing
All FDs should now have the CLOEXEC flag set, and thus there’s no
longer needed to manually loop “all” possible FDs and (trying to)
close them.

Note: the alsa module (alsalib, actually) is “racy” - while booting
up, it temporarily opens the asoundrc file without CLOEXEC. If
e.g. the script module starts its script inside this window, it’ll
have a leaked FD. Not much we can do about it though :/

Closes #169
2022-03-29 18:23:55 +02:00
Daniel Eklöf
068c25d8f6
module/script: open comm-pipe + /dev/null with CLOEXEC
This ensures we don’t leak FDs when exec:ing e.g. on-click
handlers.

Note that the comm-pipe FD is *supposed* to stay open when we execing
the script. This is handled by the call to dup2(), which drops the
CLOEXEC flag. Since dup2() is called after the fork, the dup:ed FD is
never visible in the “parent” yambar process.
2022-03-29 18:22:08 +02:00
Daniel Eklöf
2b6f5b1e36
module/removables: open /proc/self/mountinfo with CLOEXEC 2022-03-29 18:21:44 +02:00
Daniel Eklöf
4bb81e8940
modules: add SOCK_CLOEXEC to all socket() calls 2022-03-29 18:21:13 +02:00
Daniel Eklöf
c44970717b
module/i3: workspace::focus is apparently Sway only
On i3, users are currently greeted with:

  err: modules/i3.c:94: workspace reply/event without 'name' and/or
       'output', and/or 'focus' properties

This patch makes ‘focus’ an optional attribute. When missing, we
assume a node-count of 0, which means the workspace’s ‘empty’ tag will
always be true. Document this in the i3 man page.
2022-02-15 21:14:08 +01:00
Daniel Eklöf
ca407cd166
module/i3: treat workspaces on the form N:name as numerical 2022-02-14 18:33:14 +01:00
Daniel Eklöf
a2cf05a64d
module/i3: add ‘strip-workspace-numbers’ option
This is a boolean option. When set, “N:” prefixes will be stripped
from the workspaces’ name tag, *after* having been sorted (if the
‘sort’ option is being used).

This makes it useful to arrange the workspaces in a fixed order, by
prefixing the names with a number in the Sway config:

  set $ws1 “1:xyz”
  set $ws2 “2:abc”

Then, in the yambar config:

  i3:
    sort: ascending
    strip-workspace-numbers: true
2022-02-11 21:44:43 +01:00
Daniel Eklöf
d9316a202d
module/removables: audio CD support
Audio CDs are special, in that they don’t (usually) have any data
partitions. They also don’t have a volume label. They just have
tracks.

Before this patch, we ignored all optical mediums that did *not* have
a filesystem (that includes audio CDs).

Now, instead of using the ID_FS_USAGE property to determine whether
there’s media present in the CD-ROM or not, we use the
ID_CDROM_MEDIA. This property is set to ‘1’ for both audio CDs and
data CDs.

Then, we read the ID_CDROM_MEDIA_TRACK_COUNT_AUDIO property to
determine how many audio tracks there are.

If the CD has a filesystem, we treat it as a data CD, and use the
already existing add_partition() function to track it.

If the CD does _not_ have a filesystem, but it _does_ have at least
one audio track, we treat it as an audio CD and use the new
add_audio_cd() function to track it.

This function is almost identical to add_partition(), but instead of
reading the ID_FS_LABEL property, it reads the
ID_CDROM_MEDIA_TRACK_COUNT_AUDIO property and synthesizes a label on
the form “Audio CD - N tracks”.

Finally, a new boolean tag, “audio”, has been added. It is set to true
for audio CD “partitions”, and to false in all other cases.
2021-12-26 12:22:54 +01:00
Alexandre Acebedo
ae5c7e0fc3 modules: add cpu module 2021-12-21 18:44:36 +01:00
Alexandre Acebedo
337ce7681f modules: add mem module 2021-12-21 18:44:14 +01:00
Daniel Eklöf
3e133d8618
module/i3: add ‘empty’ boolean tag
Set to true for empty (no windows) workspaces.

Mostly useful with persistent workspaces, to be able to differentiate
between invisible non-empty workspaces and actually empty
workspaces (the latter not being possible with non-persistent
workspaces).
2021-12-19 17:54:40 +01:00
Daniel Eklöf
9cff50a39e
module/xwindow: handle poll() failures 2021-12-17 11:55:38 +01:00
Daniel Eklöf
96c75b7f73
module/xkb: handle poll() failures 2021-12-17 11:55:38 +01:00
Daniel Eklöf
ffa86d84a5
module/removables: handle poll() failures 2021-12-17 11:55:36 +01:00
Daniel Eklöf
5d09e59f11
module/mpd: handle poll() failures 2021-12-17 11:55:36 +01:00
Daniel Eklöf
8a11a3fbe5
module/clock: handle poll() failures 2021-12-17 11:55:31 +01:00
Daniel Eklöf
cdd0b5b4f0
module/clock: fold long line 2021-12-17 11:28:05 +01:00
Daniel Eklöf
82ef48f666
module/clock: remove unused include 2021-12-17 11:27:53 +01:00
Daniel Eklöf
f922973450
module/battery: handle poll() failures 2021-12-17 11:25:37 +01:00
Daniel Eklöf
6612a9af9f
module/backlight: handle poll() failures 2021-12-17 11:23:59 +01:00
Daniel Eklöf
f166bbbf54
modules: verify: use conf_verify_unsigned() for options that should be >= 0 2021-11-15 18:17:29 +01:00
Daniel Eklöf
9ffd305b59
network: must re-send station request when we receive family ID
The get station request also fails if the family ID is invalid.
2021-10-24 17:47:54 +02:00
Daniel Eklöf
4e96dbd7f7
network: don’t send nl80211 request if we don’t have a family-id
This fixes an issue where we sometimes failed to retrieve the SSID; we
sent one initial request before the family ID had been set.

Then, we received the family ID and tried to send another
request. However, if the first request was still in progress, the
second request was never made.

Since the first request lacked the family ID, that response didn’t
contain anything useful.
2021-10-24 17:35:15 +02:00
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