From 708bd9c891cd58a840236b3d77340fa25f197281 Mon Sep 17 00:00:00 2001
From: Quantenzitrone <74491719+Quantenzitrone@users.noreply.github.com>
Date: Sun, 21 Aug 2022 19:10:48 +0200
Subject: [PATCH 1/4] feat(temperature): %temperature-k% token for Kelvin
(#2784)
* added kelvin option for module/temperature
* changelog for the changes i made
* fixed typos
* fixed the temperature conversion to be more precise
* Update CHANGELOG.md
Co-authored-by: Patrick Ziegler
* changed the calculation of the different temperatures
it now uses float as a initial value and makes m_temp temp_k and temp_f by converting and rounding with std::round
* std::lround makes more sense to use than std::round
Co-authored-by: Patrick Ziegler
---
CHANGELOG.md | 1 +
src/modules/temperature.cpp | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfd265b0..62557462 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `custom/text`: The `content` setting and all its properties are deprecated in favor of `format` with the same functionality. ([`#2676`](https://github.com/polybar/polybar/pull/2676))
### Added
+- `internal/temperature`: `%temperature-k%` token displays the temperature in kelvin ([`#2774`](https://github.com/polybar/polybar/discussions/2774), [`#2784`](https://github.com/polybar/polybar/pull/2784))
- `internal/pulseaudio`: `reverse-scroll` option ([`#2664`](https://github.com/polybar/polybar/pull/2664))
- `custom/script`: Repeat interval for script failure (`interval-fail`) and `exec-if` (`interval-if`) ([`#943`](https://github.com/polybar/polybar/issues/943), [`#2606`](https://github.com/polybar/polybar/issues/2606), [`#2630`](https://github.com/polybar/polybar/pull/2630))
- `custom/text`: Loads the `format` setting, which supports the `` tag, if the deprecated `content` is not defined ([`#1331`](https://github.com/polybar/polybar/issues/1331), [`#2673`](https://github.com/polybar/polybar/pull/2673), [`#2676`](https://github.com/polybar/polybar/pull/2676))
diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp
index 06cf88ff..061e86a7 100644
--- a/src/modules/temperature.cpp
+++ b/src/modules/temperature.cpp
@@ -51,22 +51,27 @@ namespace modules {
}
bool temperature_module::update() {
- m_temp = std::strtol(file_util::contents(m_path).c_str(), nullptr, 10) / 1000.0f + 0.5f;
- int temp_f = floor(((1.8 * m_temp) + 32) + 0.5);
+ float temp = float(std::strtol(file_util::contents(m_path).c_str(), nullptr, 10)) / 1000.0;
+ m_temp = std::lround( temp );
+ int temp_f = std::lround( (temp * 1.8) + 32.0 );
+ int temp_k = std::lround( temp + 273.15 );
string temp_c_string = to_string(m_temp);
string temp_f_string = to_string(temp_f);
+ string temp_k_string = to_string(temp_k);
// Add units if `units = true` in config
if(m_units) {
temp_c_string += "°C";
temp_f_string += "°F";
+ temp_k_string += "K";
}
const auto replace_tokens = [&](label_t& label) {
label->reset_tokens();
label->replace_token("%temperature-f%", temp_f_string);
label->replace_token("%temperature-c%", temp_c_string);
+ label->replace_token("%temperature-k%", temp_k_string);
// DEPRECATED: Will be removed in later release
label->replace_token("%temperature%", temp_c_string);
From 6ccecbfca2356a7cf964bd36bf498db476b6bbcd Mon Sep 17 00:00:00 2001
From: Dave
Date: Sun, 21 Aug 2022 21:55:42 +0430
Subject: [PATCH 2/4] feat(temperature): Add `zone-type` setting (#2752)
Signed-off-by: xphoniex
Signed-off-by: xphoniex
---
CHANGELOG.md | 1 +
cmake/02-opts.cmake | 2 ++
include/modules/temperature.hpp | 1 +
include/settings.hpp.cmake | 1 +
src/modules/temperature.cpp | 21 +++++++++++++++++++++
src/settings.cpp.cmake | 1 +
6 files changed, 27 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62557462..6a0deabd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `custom/text`: Loads the `format` setting, which supports the `` tag, if the deprecated `content` is not defined ([`#1331`](https://github.com/polybar/polybar/issues/1331), [`#2673`](https://github.com/polybar/polybar/pull/2673), [`#2676`](https://github.com/polybar/polybar/pull/2676))
- Added experimental support for positioning the tray like a module
- `internal/backlight`: `scroll-interval` option ([`#2696`](https://github.com/polybar/polybar/issues/2696), [`#2700`](https://github.com/polybar/polybar/pull/2700))
+- `internal/temperature`: Added `zone-type` setting ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2752`](https://github.com/polybar/polybar/pull/2752)) by [@xphoniex](https://github.com/xphoniex)
### Changed
- `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705))
diff --git a/cmake/02-opts.cmake b/cmake/02-opts.cmake
index 5c3ea913..0c31f1a6 100644
--- a/cmake/02-opts.cmake
+++ b/cmake/02-opts.cmake
@@ -20,3 +20,5 @@ set(SETTING_PATH_MESSAGING_FIFO "/tmp/polybar_mqueue.%pid%"
CACHE STRING "Path to file containing the current temperature")
set(SETTING_PATH_TEMPERATURE_INFO "/sys/class/thermal/thermal_zone%zone%/temp"
CACHE STRING "Path to file containing the current temperature")
+set(SETTING_PATH_THERMAL_ZONE_WILDCARD "/sys/class/thermal/thermal_zone*"
+ CACHE STRING "Wildcard path to different thermal zones")
diff --git a/include/modules/temperature.hpp b/include/modules/temperature.hpp
index f075d2ec..f59c1abe 100644
--- a/include/modules/temperature.hpp
+++ b/include/modules/temperature.hpp
@@ -30,6 +30,7 @@ namespace modules {
ramp_t m_ramp;
string m_path;
+ string m_zone_type;
int m_zone = 0;
// Base temperature used for where to start the ramp
int m_tempbase = 0;
diff --git a/include/settings.hpp.cmake b/include/settings.hpp.cmake
index d1016db8..19c5fb40 100644
--- a/include/settings.hpp.cmake
+++ b/include/settings.hpp.cmake
@@ -66,6 +66,7 @@ extern const char* const PATH_CPU_INFO;
extern const char* const PATH_MEMORY_INFO;
extern const char* const PATH_MESSAGING_FIFO;
extern const char* const PATH_TEMPERATURE_INFO;
+extern const char* const PATH_THERMAL_ZONE_WILDCARD;
extern const char* const WIRELESS_LIB;
bool version_details(const std::vector& args);
diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp
index 061e86a7..98e0f38e 100644
--- a/src/modules/temperature.cpp
+++ b/src/modules/temperature.cpp
@@ -16,12 +16,33 @@ namespace modules {
temperature_module::temperature_module(const bar_settings& bar, string name_)
: timer_module(bar, move(name_)) {
m_zone = m_conf.get(name(), "thermal-zone", 0);
+ m_zone_type = m_conf.get(name(), "zone-type", ""s);
m_path = m_conf.get(name(), "hwmon-path", ""s);
m_tempbase = m_conf.get(name(), "base-temperature", 0);
m_tempwarn = m_conf.get(name(), "warn-temperature", 80);
set_interval(1s);
m_units = m_conf.get(name(), "units", m_units);
+ if (!m_zone_type.empty()) {
+ bool zone_found = false;
+ vector zone_paths = file_util::glob(PATH_THERMAL_ZONE_WILDCARD);
+ vector available_zones;
+ for (auto &z: zone_paths) {
+ string zone_file = z + "/type";
+ string z_zone_type = string_util::strip_trailing_newline(file_util::contents(zone_file));
+ available_zones.push_back(z_zone_type);
+ if (z_zone_type == m_zone_type) {
+ m_path = z + "/temp";
+ zone_found = true;
+ break;
+ }
+ }
+
+ if (!zone_found) {
+ throw module_error("zone-type '" + m_zone_type + "' was not found, available zone types: " + string_util::join(available_zones, ", "));
+ }
+ }
+
if (m_path.empty()) {
m_path = string_util::replace(PATH_TEMPERATURE_INFO, "%zone%", to_string(m_zone));
}
diff --git a/src/settings.cpp.cmake b/src/settings.cpp.cmake
index 5b65578c..31de345a 100644
--- a/src/settings.cpp.cmake
+++ b/src/settings.cpp.cmake
@@ -19,6 +19,7 @@ const char* const PATH_CPU_INFO{"@SETTING_PATH_CPU_INFO@"};
const char* const PATH_MEMORY_INFO{"@SETTING_PATH_MEMORY_INFO@"};
const char* const PATH_MESSAGING_FIFO{"@SETTING_PATH_MESSAGING_FIFO@"};
const char* const PATH_TEMPERATURE_INFO{"@SETTING_PATH_TEMPERATURE_INFO@"};
+const char* const PATH_THERMAL_ZONE_WILDCARD{"@SETTING_PATH_THERMAL_ZONE_WILDCARD@"};
const char* const WIRELESS_LIB{"@WIRELESS_LIB@"};
bool version_details(const std::vector& args) {
From 7838241a77e0c9677066883853ae602ef8db0453 Mon Sep 17 00:00:00 2001
From: Ashwin Rajesh <46510831+VanillaViking@users.noreply.github.com>
Date: Thu, 25 Aug 2022 08:36:38 +1000
Subject: [PATCH 3/4] feat(tokens): Negative minimum length adds right padding
(#2801)
* negative minimum length adds right padding
* missing else statement
* updated changelog
---
CHANGELOG.md | 1 +
include/drawtypes/label.hpp | 1 +
src/drawtypes/label.cpp | 10 +++++++++-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a0deabd..df5c71e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705))
- `internal/backlight`: Detect backlight if none specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2728`](https://github.com/polybar/polybar/pull/2728))
+- Providing a negative min-width to a token adds right-padding ([`#2789`](https://github.com/polybar/polybar/issues/2789), [`#2801`](https://github.com/polybar/polybar/pull/2801)) by [@VanillaViking](https://github.com/VanillaViking).
### Fixed
- Waiting for double click interval on modules that don't have a double click action ([`#2663`](https://github.com/polybar/polybar/issues/2663), [`#2695`](https://github.com/polybar/polybar/pull/2695))
diff --git a/include/drawtypes/label.hpp b/include/drawtypes/label.hpp
index 3e178fdf..58635efa 100644
--- a/include/drawtypes/label.hpp
+++ b/include/drawtypes/label.hpp
@@ -16,6 +16,7 @@ namespace drawtypes {
size_t max{0_z};
string suffix{""s};
bool zpad{false};
+ bool rpadding{false};
};
class label : public non_copyable_mixin {
diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp
index e4317d9b..e5ba8911 100644
--- a/src/drawtypes/label.cpp
+++ b/src/drawtypes/label.cpp
@@ -86,7 +86,11 @@ namespace drawtypes {
if (tok.max != 0_z && string_util::char_len(repl) > tok.max) {
repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix;
} else if (tok.min != 0_z && repl.length() < tok.min) {
- repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' ');
+ if (tok.rpadding) {
+ repl.append(tok.min - repl.length(), ' ');
+ } else {
+ repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' ');
+ }
}
/*
@@ -231,6 +235,10 @@ namespace drawtypes {
text = string_util::replace(text, token_str, token.token);
try {
+ if (token_str[pos + 1] == '-') {
+ token.rpadding = true;
+ pos++;
+ }
token.min = std::stoul(&token_str[pos + 1], nullptr, 10);
// When the number starts with 0 the string is 0-padded
token.zpad = token_str[pos + 1] == '0';
From d817080ee8e7934e52424af21e25105cb3ec33ea Mon Sep 17 00:00:00 2001
From: Patrick Ziegler
Date: Thu, 25 Aug 2022 00:55:16 +0200
Subject: [PATCH 4/4] fix(renderer): Small gaps when rendering emojis (#2802)
If any rendered text uses a non-integer number of pixels (often emojis),
rendering of subsequent text blocks will start between pixels which
results in small gaps in the background and over/underline colors caused
by cairo only rendering at fractional-intensity in the beginning and end
pixel.
Simply rounding up text width can solve this.
Fixes #2785
---
CHANGELOG.md | 1 +
include/cairo/context.hpp | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index df5c71e1..74fb3f4c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Waiting for double click interval on modules that don't have a double click action ([`#2663`](https://github.com/polybar/polybar/issues/2663), [`#2695`](https://github.com/polybar/polybar/pull/2695))
+- renderer: Small gaps when rendering emojis ([`#2785`](https://github.com/polybar/polybar/issues/2785), [`#2802`](https://github.com/polybar/polybar/pull/2802))
- config:
- Error reporting for deprecated config values ([`#2724`](https://github.com/polybar/polybar/issues/2724))
- Also monitor include-files for changes when --reload is set ([`#675`](https://github.com/polybar/polybar/issues/675), [`#2759`](https://github.com/polybar/polybar/pull/2759))
diff --git a/include/cairo/context.hpp b/include/cairo/context.hpp
index f0be75bc..23167dfe 100644
--- a/include/cairo/context.hpp
+++ b/include/cairo/context.hpp
@@ -196,6 +196,12 @@ namespace cairo {
cairo_text_extents_t extents;
f->textwidth(subset, &extents);
+ /*
+ * Make sure we don't advance partial pixels, this can cause problems
+ * later when cairo renders background colors over half-pixels.
+ */
+ extents.x_advance = std::ceil(extents.x_advance);
+
// Draw the background
if (t.bg_rect.h != 0.0) {
save();