The module prints %cpu0 at the third placeholder where it should report
an error.
This commit fixes this behavior by initializing `number' to -1. If the
cpu is missing in %cpu placeholder, the sscanf function does not set
`number'. Because `number' is -1 (lower to 0), an error is reported and
the placeholder is skipped.
$ i3status -c ./config
i3status: trying to auto-detect output_format setting
i3status: auto-detected "term"
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=-48% cpu=
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=11% cpu=
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=03% cpu=
...
arcnmx [Wed, 21 Feb 2018 18:25:08 +0000 (13:25 -0500)]
Provide a more natural volume percentage with ALSA.
The rationale of the code is explained in the header:
http://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=alsamixer/volume_mapping.c;h=1c0d7c45e6686239464e1b0bbc8983ea57f3914f;hb=HEAD
> The mapping is designed so that the position in the interval is
> proportional to the volume as a human ear would perceive it (i.e., the
> position is the cubic root of the linear sample multiplication
> factor).
and the commit message:
http://git.alsa-project.org/?p=alsa-utils.git;a=commit;h=34bb514b5fd1d6f91ba9a7b3a70b0ea0c6014250
> use a mapping where the bar height is proportional to the audible
> volume, i.e., where the amplitude is the cube of the bar height.
and further explanation can be found in the pull request:
https://github.com/i3/i3status/pull/268#pullrequestreview-147429763
Felix Buehler [Sat, 2 Jun 2018 00:32:25 +0000 (02:32 +0200)]
able to print percentage
its now possible to have percentage before and after a variable. except
for the date. But percentage with dates does not make much sense to me, so
i skipped it.
Olivier Gayot [Wed, 20 Jun 2018 16:09:41 +0000 (18:09 +0200)]
Stop requiring CAP_NET_ADMIN
Since the following commit in the Linux kernel tree
0fdc100bdc4b ethtool: allow non-netadmin to query settings
it is no longer necessary to have the CAP_NET_ADMIN capability to query
a device speed using ioctl(..., SIOCETHTOOL) in conjonction with the
ETHTOOL_GSET ethtool command.
The mentioned commit landed first in the 2.6.37 version of the Kernel.
This version is no longer maintained nowdays.
Since it is not necessary anymore, it is strongly prefered from a
security standpoint to drop the CAP_NET_ADMIN capability from the
binary.
Olivier Gayot [Wed, 20 Jun 2018 09:42:59 +0000 (11:42 +0200)]
Fix invalid handling of glob() errors on Linux
The manual of glob(3) says that the function returns 0 on successful
completion. Any other integer value should be considered an error, not
only negative integers.
In practice, *BSD systems use negative values but Linux uses positive
integers.
Olivier Gayot [Mon, 11 Jun 2018 22:52:29 +0000 (00:52 +0200)]
No longer use a temporary buffer in the die() function
Before the following change
f947d0a Breaks configfiles! Major refactoring of i3status, see below
The die(fmt, ...) function was outputting the reason to the status bar
in addition to stderr. For this reason, it was meaningful to create a
temporary string according to the format string and then passing it
around to the different functions.
Nowadays, we only display the error message to stderr so calling
fprintf(stderr, ...) is much simpler.
introduced a way to show the IP address of an interface when a label is
associated to the IP.
When a label is associated to an IP, the structure returned by
getifaddrs() has the label concatenated to the interface name in the
.ifa_name field as in the following example:
As a consequence, using a strict comparison between the interface name
and the .ifa_name field yields a falsy result. However, checking if the
.ifa_name starts with the interface name (e.g. eth0) does not work
either because other network interfaces can have a name which starts
with eth0.
This commit solves the issue by stripping out the optional label from
the .ifa_name field before making a strict comparison with the interface
name.
Carlin Bingham [Mon, 12 Feb 2018 13:12:04 +0000 (02:12 +1300)]
OpenBSD: fix volume display on some hardware
On some hardware the AUDIO_MIXER_READ ioctl requires the current number
of channels to be set, and the mute device found needs to be checked if
it belongs to the master output device.
johcgt [Sun, 28 Jan 2018 14:37:51 +0000 (14:37 +0000)]
Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by
dividing batt_info.remaining by `full`. If `full` is `0` then the
battery remaining will be reported as "inf".
Before this, it tries to set `full` to either the design capacity or to
the last known good charge. It determines if these values are available
by checking whether their fields in `batt_info` are non-negative. As it
initialized `batt_info` with values of `-1`, a non-negative value
implies that something has provided a value.
`slurp_all_batteries` and `add_battery_info` however initialize these
fields to zero, so if these functions are called then
`batt_info.full_design` will always be used.
This means that on systems that don't provide a value for design
capacity the percentage remaining will be reported as "inf", unless the
user has set `last_full_capacity` to `true` in their `i3status.conf`.
This patch changes `print_battery_info` to expect values for the battery
capacity to be strictly greater than zero. This seems reasonable as a
battery with a capacity of zero isn't useful.
An alternative solution would be to change `slurp_all_batteries` and
`add_battery_info` to initialize `batt_info` with `-1`, as
`print_battery_info` does. This is less appealing as `add_battery_info`
is accumulating the values, so using `-1` would introduce off-by-one
errors without additional code to avoid them.
GuyOfThePery [Sat, 9 Dec 2017 11:24:11 +0000 (13:24 +0200)]
Fixed minor typos
"you can chose" -> "you can choose"
"You can either disable the default separator altogether setting it to the empty string." -> " You can also disable the default separator altogether by setting it to the empty string."
The orignal proposed code had a memory leak when returning true.
Furthermore I included the handy BEGINS_WITH macro of i3 which makes the
code (IMHO) a lot more readable.