Skip to content

Conversation

@quandangv
Copy link
Contributor

@quandangv quandangv commented Oct 9, 2020

This is an item in the todo list from the Module State Machines project, and was requested in #570 and #956. The idea is that the modules that monitor system resources will display different labels and animations when that resource requires attention (battery low, high temperature, high cpu/memory usage).

The warn state would work like that of the temperature module. The condition to activate the warn states are as follow:

  • Memory module: percentage of memory used >= warn-percentage
  • CPU module: total percentage of all cores >= warn-percentage
  • Filesystem module: the filesystem is mounted and percentage of used space >= warn-percentage
  • Battery module: the charge percentage >= low-at

Release Notes:

This adds format-warn and label-warn to the memory, cpu and fs module and format-low and label-low to the battery module.

It also slightly changes how the ramps in those modules behave. The ramps are bounded by these warn thresholds and, the same as the temperature module, the first and last ramp elements are responsible for everything <= the lower bound or >= the upper bound. Before, the ramp generally went from 0 to 100 and the first and last ramp elements covered the same share inside the range as all other ramp elements as well as everything outside the range.

These two changes in behavior partially cancel each other out, so the change in behavior in existing configs will be barely noticeable.

It also adds the following:

  • battery: animation-low, low-at = 10
  • cpu: warn-percentage = 80
  • fs: warn-percentage = 90
  • memory: warn-percentage = 90

/Release Notes

Example configuration:

[module/cpu]
type = internal/cpu

interval = 1
warn-percentage = 80

format = <label>
format-prefix = CPU
format-background = #000
format-foreground = #fff
format-padding = 1
label = " %percentage%%"

format-warn = <label-warn>
format-warn-prefix = CPU
format-warn-background = #fff
format-warn-foreground = #000
format-warn-padding = 2
label-warn = " %percentage%%"

Closes #570
Closes #956

@codecov
Copy link

codecov bot commented Oct 9, 2020

Codecov Report

Merging #2199 (006041a) into master (50d8a1b) will increase coverage by 0.18%.
The diff coverage is 7.69%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2199      +/-   ##
=========================================
+ Coverage    7.25%   7.44%   +0.18%     
=========================================
  Files         155     156       +1     
  Lines       10594   10678      +84     
=========================================
+ Hits          769     795      +26     
- Misses       9825    9883      +58     
Flag Coverage Δ
unittests 7.44% <7.69%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
include/drawtypes/ramp.hpp 50.00% <ø> (+50.00%) ⬆️
include/modules/battery.hpp 0.00% <ø> (ø)
include/modules/fs.hpp 0.00% <ø> (ø)
include/modules/meta/base.hpp 0.00% <ø> (ø)
src/modules/battery.cpp 0.00% <0.00%> (ø)
src/modules/cpu.cpp 0.00% <0.00%> (ø)
src/modules/fs.cpp 0.00% <0.00%> (ø)
src/modules/memory.cpp 0.00% <0.00%> (ø)
src/modules/meta/base.cpp 0.00% <0.00%> (ø)
src/modules/temperature.cpp 0.00% <0.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50d8a1b...006041a. Read the comment docs.

@quandangv quandangv marked this pull request as ready for review October 9, 2020 09:52
@quandangv
Copy link
Contributor Author

This would also provide the feature requested by #1871.

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Thanks!

I do have some concerns about how this changes existing behavior. Because the thresholds for the new warn states would change how existing configs would display once we are in the warn state.

For example right now, if your CPU is over 80%, it would display whatever is in format and the labels and ramps used there. If we used the same config in this PR, it would now display just the total load percentage.

We generally want people to be able to update without it changing how their bar looks like (at least not in a substantial way). So we can't really have these warning states enabled by default, or we must make sure that they behave exactly the same as the non-warn states by default.

I can think of two solutions to this:

  1. Set the threshold to something that can never be reached. In the battery module, we would set it to anything smaller than 0. For memory, cpu, and fs, we would have to set it to something larger than 100. It has to be strictly smaller than 0 or larger than 100 because both 0% battery and 100% cpu, ram, or storage can be reached and the warn states are activated at those values.
  2. Have an extra boolean flag in each module that is set to true only if the new warn formats were defined in the module config. Only use the warn states if the flag is true.

None of these solutions are pretty unfortunately. Can you think of another way of ensuring that the module doesn't suddenly display something completely different in the warn states?


And just to note, because it also changes module behavior: This PR adds the same changes to the behavior of the first and last ramp elements for the battery, fs, cpu, and memory module as #2197 added for the temperature module.

While this can be considered a breaking change, it just changes the ranges that ramp elements are responsible for a bit. So, the same as for the temperature module, this is probably fine, we just need to make sure to mention it in the changelogs.

@quandangv
Copy link
Contributor Author

We can create a new fallback tag. The default value for FORMAT_WARN will be this tag, and when module::get_format() is called, we check if FORMAT_WARN have this tag to return DEFAULT_FORMAT instead.

Hide the effect of warn states when unused
@quandangv
Copy link
Contributor Author

Another idea on my mind is that I can write module_formatter::try_get() which will add a format only if it is defined. If we load the warn format using try_get, I can then write module_formatter::has_format() to check if the warn format exist and use the default format when it isn't.

@patrick96
Copy link
Member

Another idea on my mind is that I can write module_formatter::try_get() which will add a format only if it is defined. If we load the warn format using try_get, I can then write module_formatter::has_format() to check if the warn format exist and use the default format when it isn't.

I think that is a good idea. 👍

@quandangv
Copy link
Contributor Author

I applied it on all relevant modules.

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just some minor style changes.

Please also rebase and resolve the merge conflicts.

@quandangv
Copy link
Contributor Author

Ok, is it good?

@patrick96 patrick96 self-requested a review December 1, 2020 19:28
Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality wise, everything works now. There was a small bug in the fs module, but I added a comment for that.

The build currently breaks, I have added comments for all the places that need to be fixed.

There are also some places where you use tabs instead of spaces, I have also added comments for that.

After these changes, I think we can merge this.

@quandangv
Copy link
Contributor Author

I think I finally got the indents right.

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good now 🎉

Thanks a lot for all your efforts! 😃

@patrick96 patrick96 merged commit 39c73a8 into polybar:master Dec 2, 2020
patrick96 added a commit to patrick96/polybar that referenced this pull request Dec 3, 2020
This was a backwards-incompatible change introduced in polybar#2199, however it
was caused because `module_formatter.has` throws an exception when the
format doesn't exist instead of just returning false.

Fixes polybar#2262
Ref polybar#2199
patrick96 added a commit that referenced this pull request Dec 7, 2020
This was a backwards-incompatible change introduced in #2199, however it
was caused because `module_formatter.has` throws an exception when the
format doesn't exist instead of just returning false.

Fixes #2262
Ref #2199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditional Display of Battery label-warn for other modules

2 participants