Commit Graph

28 Commits

Author SHA1 Message Date
Patrick Ziegler ce93188a4a
Add units support (POINT, PIXEL, SPACE) (#2578)
* add units support (POINT, PIXEL, SPACE) for polybar

- add a size_with_unit struct
- add a geometry_format_values struct
- move dpi initialisation from renderer.cpp to bar.cpp
- add a string to size_with_unit converter
- add point support (with pt)
- add pixel support (with px)

* Fix unit test compilation

* clang-format

* Better names

The old names didn't really capture the purpose of the structs and
function.

space_type -> spacing_type
space_size -> spacing_val

size_type -> extent_type
geometry -> extent_val

geometry_format_values -> percentage_with_offset

* Remove parse_size_with_unit

No longer needed. The convert<spacing_val> function in config.cpp
already does all the work for us and always setting the type to pixel
was wrong.

In addition, line-size should not be of type spacing_val but extent_val.

* Cleanup

I tried to address most of my comments on the old PR

* Fix renderer width calculation

We can't just blindly add the x difference to the width because for
example the width should increase if x < width and the increase keeps
x < width.

Similarly, we can't just add the offset to the width.

* Rename geom_format_to_pixels to percentage_with_offset_to_pixel

* Cleanup

* Apply suggested changes from Patrick on GitHub

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/components/bar.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/components/config.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/components/builder.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update src/components/builder.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* config: Use stod for parsing percentage

* Use stof instead of strtof

* units: Fix test edge cases

* Remove unnecessary clang-format toggle

* Use percentage_with_offset for margin-{top,bottom}

* Support negative extent values

* Rename unit to units and create a cpp file

* Move percentage_with_offset_to_pixel unit test to units

* Add unit tests for units_utils

* Clarify when and how negative spacing/extent is allowed

Negative spacing is never allowed and produces a config error.

Extents allow negative values in theory, but only a few use-cases accept
it.
Only the extent value used for the `%{O}` tag and the offset value in
percentage_with_offset can be negative. Everything else is capped below
at 0.

The final pixel value of percentage_with_offset also caps below at 0.

* Fix parsing errors not being caught in config

* Print a proper error message for uncaught exceptions

* Cleanup module::get_output

All changes preserve the existing semantics

* Stop using remove_trailing_space in module::get_output

Instead, we first check if the current tag is built, and only if it is,
the spacing is prepended.

* Remove unused imports

* Restore old behavior

If there are two tags and the second one isn't built (module::build
returns false), the space in between them is removed.
For example in the mpd module:

format-online = <toggle> <label-song> foo

If mpd is not running, the mpd module will return false when trying to
build the `<label-song>` tag. If we don't remove the space between
`<toggle>` and `<label-song>`, we end up with two spaces between
`<toggle>` and `foo`.

This change is to match the old behavior where at least one trailing
space character was removed from the builder.

* Add changelog entry

* Remove unused setting

* Use percentage with offset for tray-offset

Co-authored-by: Jérôme BOULMIER <jerome.boulmier@outlook.fr>
Co-authored-by: Joe Groocock <github@frebib.net>
2022-02-20 21:08:57 +01:00
patrick96 1c554dd0e0
Merge branch 'hotfix/3.5.1' 2020-12-12 13:28:57 +01:00
Patrick Ziegler 82ebad5e7a
fix(timer_module): Ensure that interval > 0 (#2274)
Since 3.5.0, we use m_interval for a modulo operation, this crashes the
bar if the interval is 0. A non-positive interval shouldn't be allowed
anyway, so we now throw an exception in that case.

Fixes #2273
2020-12-05 22:58:38 +01:00
Quan 39c73a8234
feat: Warn state for cpu, memory, fs, battery modules (#2199)
* [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps

* [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps

* Fix minor error

* Added WARN state for cpu module

* Implement WARN state for CPU, Memory modules, working on fs module

* Implement WARN state for fs module

* Simplify WARN state implementation for cpu and memory

* explicitly check percentage in get_by_percentage_with_borders

* Fixed silly error

* implement warn state on battery module, standardize the implementation on other modules

* minor fixes

* fix annoying error

* use more intuitive param name

* Fix percentage with borders bug

* Make requested changes
Hide the effect of warn states when unused

* Backward Compat: use no format instead of fallback label

* Reformat

* Refactor

* Reformat

* Reformat: convert tabs to spaces

* Reformat
2020-12-02 15:55:13 +01:00
Tudor Brindus bc560952e0 cpu: Consider steal time for load calculation (#1955)
* Add steal time to cpu_time struct

* Consider steal time as part of load calculations

* Typo fix
2019-12-16 17:05:18 +01:00
Sergey cc8947ac01 feat(cpu): Add percentage-sum token (#1517)
Adds `%percentage-sum%` token to cpu label that contains the cumulative load of all cores.
2018-12-03 01:48:18 +01:00
Patrick Ziegler b80023fd41
feat(cpu): Add ramp-coreload-spacing (#1472)
Resolves #1389
2018-10-16 01:11:05 +02:00
Patrick Ziegler 6d0cfbdfde Revert "feat(cpu): Add ramp-coreload-spacing (#1472)"
This reverts commit 06adef1055.
2018-10-16 01:01:11 +02:00
Ryan Geary 06adef1055 feat(cpu): Add ramp-coreload-spacing (#1472)
Resolves #1389
2018-10-16 00:59:45 +02:00
Vasili Karaev 2fba443f56 fix(cpu): Replace %percentage-cores% normally (#1282) 2018-09-19 19:58:09 -07:00
Michael Carlberg 3292cea786 refactor(tokens): Move token suffix to configuration 2017-01-14 18:00:35 +01:00
Michael Carlberg 14958bdd23 fix: Correct type for module interval 2016-12-31 03:04:01 +01:00
Michael Carlberg 78bb3695e6 refactor(config): Deduce return type from default value 2016-12-30 23:32:05 +01:00
Michael Carlberg 788a7ca3a3 refactor(modules): Get rid of .inl files 2016-12-21 09:21:35 +01:00
Michael Carlberg c01f111e34 refactor(modules): Move setup to constructor 2016-12-21 08:00:09 +01:00
Michael Carlberg ff55421f52 feat(cpu): Load percentage per core
Display load percentage for individual cpu cores
or a concatenated string for all cores.

Example:

  label = %percentage-core1% %percentage-core4%
  label = %percentage-cores%

Refs #256
2016-12-20 15:24:42 +01:00
Michael Carlberg f9062d031c refactor(clang-tidy): Apply fixes 2016-12-15 03:30:41 +01:00
Michael Carlberg d45fd76dcd refactor(config): Drop boost::property_tree 2016-12-14 10:57:45 +01:00
Michael Carlberg ff9be848c7 refactor(clang-tidy): Apply fixes 2016-11-25 21:58:49 +01:00
Michael Carlberg c6d85b2b92 refactor: Optimize build 2016-11-20 23:04:31 +01:00
Michael Carlberg 88c8bbd940 refactor: Fwd declare drawtypes
Ref #164
2016-11-19 15:49:06 +01:00
Michael Carlberg fd57ab0f3d fix: project rename 2016-11-19 06:26:07 +01:00
Michael Carlberg e7cb345cec wip: Separate source from definitions 2016-11-03 12:54:32 +01:00
Michael Carlberg d359ab6057 refactor: Application rewrite 2016-10-10 14:52:57 +02:00
Michael Carlberg e1f8c001dd refactor: Pass by value 2016-06-21 04:23:23 +02:00
Michael Carlberg 39d3f61497 refactor(core): Clean-up
- use "#pragma once" instead of the regular include guard
- fix errors and warnings reported by cppcheck
2016-06-02 01:32:06 +02:00
Michael Carlberg af6ef01ea6 fix(cpu): Bad value for total load percentage 2016-06-01 08:18:49 +02:00
Michael Carlberg eeefb3c610 init(git): Base commit 2016-05-19 20:23:45 +02:00