Commit Graph

30 Commits

Author SHA1 Message Date
Aaron Marcher
74c4f4ebda Add the percent sign to *_perc functions
Units should be added to the corresponding numbers
2018-05-19 20:33:06 +02:00
Laslo Hunhold
422cadfd5f Implement esnprintf() and make formatted calls more efficient
Within the components, snprintf() was unchecked and had inefficient
calls in some places.
We implement esnprintf() that does all the dirty laundry for us
and use it exclusively now.
2018-05-19 19:44:02 +02:00
Aaron Marcher
74891945d8 Revert aac29e2 as it is nonsense 2018-05-19 13:25:35 +02:00
Aaron Marcher
aac29e2bba battery: Move out struct as common code 2018-05-19 01:49:46 +02:00
Aaron Marcher
f317819984 Use %d instead of accidentally %i 2018-05-18 19:58:51 +02:00
Aaron Marcher
f170028527 Port battery_remaining to Linux
Additionally unify the format of battery_state and uptime
2018-05-18 17:25:09 +02:00
Aaron Marcher
b04ca3ef45 Fix memory leak 2018-05-18 16:55:37 +02:00
Tobias Tschinkowitz
367f8a8c44 battery: fixed remaining time on connected AC
when an AC is connected apm_info shows a non-valid value for remaining
minutes. it was decided that in that case the function should return an
empty string.
2018-05-18 16:35:32 +02:00
Aaron Marcher
2604f25b16 Fix indentation
Tabs for indentation, spaces for alignment
2018-05-18 15:32:15 +02:00
Tobias Tschinkowitz
8c8326f793 Add battery_remaining function on OpenBSD
Implementation of a battery_remaining function which returns the
remaining battery time in HH:MM format. Linux function still needs
implementation.
Move common code to load_apm_power_info
2018-05-18 15:25:42 +02:00
Laslo Hunhold
80fc20d1d6 Add warn() and die()
Given slstatus is a tool that runs in the background, most likely run
from .xinitrc, it's important to prepend the name of the tool to error
messages so it becomes clear where the error is coming from.

To make this much more consistent, this commit adds warn() and die()
utility functions consistent with other suckless projects and adapts all
calls to fprintf(stderr, *) to the warn() and die() functions, greatly
increasing the readability of the code.
2018-05-18 11:13:05 +02:00
Aaron Marcher
b759662983 Remove UNUSED macro
Use variables named unused instead which is simpler
2018-05-17 20:05:57 +02:00
Aaron Marcher
fc8b6f81a5 Mark unused parameters, fix compiler warnings 2018-05-17 18:29:25 +02:00
Aaron Marcher
7ab183c97f Unify type of in for loops 2018-05-17 18:05:38 +02:00
Aaron Marcher
7be675f154 Unify type of i in for loops
int for normal indexes
size_t for usage with the LEN macro
2018-05-17 17:42:26 +02:00
Aaron Marcher
ee5ec75621 Fix coding style
- Use block for single statement ifs
- Keep lines to reasonable length (current debate as to reasonable)
- When functions return -1 for error test against 0 not -1
- Do not indent cases another level
- Do not test against NULL and 0 explicitly
- Use tabs for indentation, use spaces for alignment
2018-05-06 22:28:56 +02:00
Aaron Marcher
417f473fe2 battery: Remove full indicator
It does not respect charging thresholds and it is not trivial to
implement the indicator in OpenBSD.
2018-05-04 18:04:53 +02:00
Aaron Marcher
2bd581a47b battery_state: Unify unknown state with "?" symbol 2018-05-02 08:16:21 +02:00
Aaron Marcher
4f5ac5d9fe Remove battery_power for various reasons
- Battery power cannot be easily gatherable via apm(4)
- IMHO it does not represent essential information
2018-05-01 21:01:25 +02:00
Aaron Marcher
41deabf2ec battery_perc: Port to OpenBSD 2018-05-01 20:45:29 +02:00
Laslo Hunhold
9750a3d731 Use indentation to increase readability
Granted, this style is definitely not common, but for the short
utility-functions of this program it's just the right choice. This
provides great flexibility, such that in the long run, it will be
possible to also share code between the OS-implementations.

This also keeps the state-keeping at a minimum and makes it clearer
which functions are implemented on which OS without having to jiggle
around with too many files in the process.
2018-05-01 19:43:49 +02:00
Laslo Hunhold
42edfea89a Revert component-split
this reverts the commits from 92ab9ef52e up to
d42870d6ca.

After heavy consideration, the component split has more disadvantages
than advantages, especially given there will be utility-functions
sharing quite a lot of code that would then need to be duplicated, as it
does not fit into the util.c due to its speciality.

One big advantage of the component-wise build is readability, and
without doubt, this was achieved here. This point will be addressed
with a different approach that will be visible in the upcoming commits.

One big disadvantage of the component build is the fact that it
introduces state to the build process which is not necessary. Before its
introduction, the only influencing factors where the system-defines
__linux__ and __OpenBSD__. With the components, we are also relying on
the output of uname(1).
Additionally, if the os.mk is not present, make gives the output

     $ make
     Makefile:5: os.mk: No such file or directory
     make: *** No rule to make target 'os.mk'.  Stop.

This could easily be fixed by providing some sort of meta-rule for this
file, however, it indicates the problem we have here, and this entire
statefulness will heavily complicate packaging of this tool and makes
the build process much more complex than it actually has to be.
2018-05-01 19:43:34 +02:00
Quentin Rameau
720569bd56 battery: OS split 2018-04-30 15:40:59 +02:00
Aaron Marcher
09950055ba battery: Separate function for readbility 2018-04-29 20:02:42 +02:00
Aaron Marcher
faa52bdcc0 Format error messages properly
Make use of strerror(errno) and format all errors equally:
function ['parameters']: error message
2018-03-28 19:46:27 +02:00
Aaron Marcher
96f3a8a54e Get rid of err.h as it is not portable
Replace warn() and warnx() with fprintf() and add <stdio.h> where
necessary.
2018-03-28 18:26:56 +02:00
Aaron Marcher
e79d4932ea More robust preprocessor switches
Replace #ifdef with #if defined() and #elif with #elif defined() as it
should only test if it is defined or not.
2018-03-21 12:21:37 +01:00
Aaron Marcher
7e3f80c1a3 battery_perc: Port to OpenBSD.
In OpenBSD battery percentage gets fetched using apm now.
2018-03-19 18:46:52 +01:00
Aaron Marcher
ebf5a35052 Build Linux-only functions only on Linux 2018-03-18 23:26:13 +01:00
Laslo Hunhold
7246dc4381
Move components into dedicated subdirectory
This brings us a lot more tidiness.
2017-09-24 17:20:27 +02:00