Commit Graph

142 Commits

Author SHA1 Message Date
Alexis Rouillard 6f66af9ab9
Merge pull request #2134 from bruceblore/battery-weighted-percentage
Display battery percentage as weighted average of battery levels
2023-09-04 22:01:40 +02:00
Lukas Fleischer 75eacb95ef Fix SEGFAULT in battery module
In waybar::modules::Battery::~Battery(), store a copy of the batteries_
iterator before calling erase(), as erase() invalidates the iterator.

Prior to this change, disconnecting outputs resulted in a SEGFAULT when
using the battery module; e.g.,

    [debug] Received SIGCHLD in signalThread
    [debug] Cmd exited with code 0
    [debug] Received SIGCHLD in signalThread
    [debug] Cmd exited with code 0
    [debug] Received SIGCHLD in signalThread
    [debug] Cmd exited with code 0
    [debug] Output removed: AU Optronics 0x2336
    [info] Bar configured (width: 1280, height: 25) for output: eDP-1
    [info] Bar configured (width: 1280, height: 25) for output: eDP-1
    zsh: segmentation fault (core dumped)  ./build/waybar -l trace

Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
2023-05-22 10:16:30 -04:00
Bruce Blore bad6cfae6f Added option to calculate battery percentage as total_energy * 100 / total_energy_full 2023-04-22 23:43:04 -07:00
Aleksei Bavshin ea17a66dfc
fix: compilation errors with cpp_std=c++20
There were two main issues with fmtlib and C++20 mode:

 - `fmt::format` defaults to compile-time argument checking and requires
   using `fmt::runtime(format_string)` to bypass that.
 - `std::format` implementation introduces conflicting declarations and
   we have to specify the namespace for all `format`/`format_to` calls.
2023-01-20 22:50:02 -08:00
Cyril LEVIS 120cba0f5e
fix: battery time remaining
time is reported in second and should be divided by 3600 and not 1000.
2023-01-13 09:44:39 +01:00
Alex b5c686c0dd
Merge pull request #1882 from LukashonakV/ISSUE#1877 2022-12-12 09:18:10 +01:00
Viktar Lukashonak a08967e008
Happy linter 2022-12-10 16:54:26 +03:00
Alex 2a76d8e5b9
Merge pull request #1862 from alebastr/battery-ignore-scope-device 2022-12-07 15:01:26 +01:00
Cyril Levis b1833b1f36
feat: add macsmc-battery time remaining support for asahi
use time_to_empty_now and time_to_full_now
2022-12-05 22:09:05 +01: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
Simon Plakolb 5e9bbe5c76 modules: Revert button to label 2022-11-24 13:08:16 +01:00
Frederic Grabowski c0b3e9ee35 normalize capacity by number of batteries 2022-11-12 22:39:53 +01:00
Eric L 6477e539d0 Battery: Plugged status has higher priority 2022-11-04 20:01:53 +00:00
Alex a10266ceee fix: add power to tooltip format 2022-10-28 14:35:18 +02:00
Simon Plakolb 662a250705 Fix battery indicator crash on linux
A pre-processor flag was misspelled and is now corrected.
2022-10-19 13:15:21 +02:00
Loïc Bartoletti 692b90c995 fix build 2022-10-19 08:36:15 +02:00
Loïc Bartoletti 72a2ada82c remove clang-format lines 2022-10-18 19:30:43 +02:00
Loïc Bartoletti 6156a62294 fix time_remaining. FreeBSD sysctl returns minutes and not hours 2022-10-18 19:30:43 +02:00
Loïc Bartoletti d4d35e2f89 apply clang-format 2022-10-18 19:30:43 +02:00
Loïc Bartoletti a58988ea9d Battery: replace #else by #elif defined(__linux__)
Cannot use #else here when inotify_init1() is hidden behind #if defined(__Linux__).

Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
2022-10-18 19:30:43 +02:00
Loïc Bartoletti 0ada5ac8b0 Battery::getAdapterStatus: better code format 2022-10-18 19:30:41 +02:00
Loïc Bartoletti 1421163df3 remove useless include <sys/types.h> 2022-10-18 19:30:23 +02:00
Loïc Bartoletti 9d5f0e45c0 Add test if there is battery 2022-10-18 19:30:23 +02:00
Loïc Bartoletti 45e44e03bd Apply jbeich suggestion for if defined(__linux__) 2022-10-18 19:30:21 +02:00
Loïc Bartoletti 830c5cd5d0 FreeBSD: Add support to battery
This commit aims to propose a FreeBSD to gain battery support using sysctl on hw.acpi.battery.*
2022-10-18 19:30:04 +02:00
Alex 8551c4bbe3 fix: lint 2022-10-17 09:19:00 +02:00
Alex 2abeba2b52
Merge pull request #1679 from tomcharnock/master 2022-10-17 09:10:54 +02:00
Simon Plakolb 2b735f44bc modules: Set tooltip on button
Mouse-over tooltips set on the label only appear once the mouse hovers
over exactly the label. Other apps (e.g. firefox) show the tooltip once
the pointer hovers the button. Not solely its label. With this commit we
get the same behaviour.
2022-10-12 10:25:30 +02:00
Simon Plakolb 8fa5d9b838 modules: Set style-context on button
Fixes issue where the class parameters in style.css would have no
effect.

The CSS now references the GtkButton instead of the GtkLabel. Removing
all style-classes from the custom module GtkButton however removes
any properties set via style.css. Thus, the default classes 'flat' and
'text-button' are added on every update of these modules.
2022-10-12 10:25:30 +02:00
Simon Plakolb b8322c4b4b button: Add AButton class
The AButton class is designed as full a substitute to ALabel. The
GtkButton attribute 'button_' is initialized with a label. This
label can the be referenced by the subsequent inheritors of AButton
instead of the GtkLabel attribute 'label_' of ALabel.
For convenience a GtkLabel* 'label_' attribute is added to AButton.

If the button cannot be clicked it is disabled, effectively acting
like its label predecessor.

GtkButton seems to catch one-click mouse events regardless of the
flags set on it. Therefore, 'signal_pressed' is connected to a
function creating a fake GdkEventButton* and calling 'handleToggle'
(for details on this possible bug in GTK see:
https://stackoverflow.com/questions/45334911 )

In accordance with other GtkButtons (i.e. the sway/workspace ones)
set_relief(Gtk::RELIEF_NONE) is called on the 'button_' instance.
2022-10-12 10:25:29 +02:00
Tom Charnock e75eafcb34 Merge branch 'master' of https://github.com/tomcharnock/Waybar 2022-09-09 07:19:12 +00:00
Arthur Eigenbrot 6b83360e76 Add "{m}" battery format-time option for zero-pad minutes 2022-09-07 08:53:07 -06:00
Tom Charnock 912d7f8588 Making calculations uint64_t 2022-09-03 18:08:26 +02:00
Tom Charnock 5647146ac0 Added Discharging clause and corrected typo 2022-09-03 17:52:11 +02:00
Tom Charnock af2a3f8bda Added alternative calculations for time remaining 2022-09-03 16:06:13 +02:00
Tom Charnock 0d94853613 Added alternative variable calculations 2022-09-02 15:37:23 +02:00
Tom Charnock 120c68e014 Updated logic in battery module 2022-09-02 11:42:46 +02:00
Viktar Lukashonak 7f995507fe
std::filesystem::path is a string representation 2022-05-14 17:10:44 +03:00
Viktar Lukashonak b39a8ede6c
Issue#1556. Battery module: wrong string comparison
1. battery.hpp - added local bool variable. Force to print warnings the
only once in order to warn user about wrong battery configuraion. And
does not bring a mess when the battery is turned off (gamepads, etc.)
2. dir_name is an object which takes a part in comparison. So converted to the string.
2022-05-14 16:56:46 +03:00
Alex f2fcadbf62 refactor: lint 2022-04-06 08:37:19 +02:00
0cc4m 3a95f8f599 Add battery module fallback for batteries without capacity or with _avg instead of _cur files 2022-03-26 19:42:06 +01:00
Viktar Lukashonak 37d87be3c1
Add supporting of the gamepads batteries 2022-03-14 17:53:19 +03:00
Viktar Lukashonak 8aee7492d4
Plug/Unplug batteries on hot(useful for gamepads) 2022-03-14 17:12:05 +03:00
Kevin Locke 27df7a9aa7 battery: read status with spaces
According to the [sysfs class power ABI],
/sys/class/power_supply/<supply_name>/status may contain "Not charging".
This is already handled by status_gt() and update() (where ' ' is
converted to '-' for use in config keys) but was not being read due to
skipws.  Read with std::getline() to handle this case.

[sysfs class power ABI]: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power

Fixes: #1139
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
2022-01-23 18:36:59 -07:00
Amanieu d'Antras 4d067619a8 Fix power calculation when battery units are in μA instead of μW 2021-05-15 15:55:38 +01:00
Max1Truc f3a6e2d494 fix: incorrect battery percentage on Pinebook Pro 2021-05-10 21:00:14 +02:00
Gabe Gorelick 7e13e26c29
[modules/battery] allow format-discharging-full
`format-discharging-full` has been impossible since #923 made it
impossible to be full and discharging at the same time. This should
fix that by only making `format-charging-full` impossible. Whether
or not that should be allowed is a good question, but beyond the
scope of this change.

Fixes #1031
2021-04-25 22:00:24 -04:00
Petri Lehtinen c850212288 Use the correct battery status when multiple batteries are present 2021-03-28 20:07:35 +03:00
Martin Pittermann 3bcf390484 add power to battery formatter 2021-01-24 21:39:14 +01:00
Alex 66e5fda418
Merge pull request #964 from Ocisra/master
Add an option to use battery design capacity
2021-01-18 13:48:03 +01:00