diff --git a/src/ui/config_error_notification.rs b/src/ui/config_error_notification.rs
index cdef5d6e..ffa5e130 100644
--- a/src/ui/config_error_notification.rs
+++ b/src/ui/config_error_notification.rs
@@ -18,7 +18,7 @@ use crate::render_helpers::memory::MemoryBuffer;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::renderer::NiriRenderer;
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
-use crate::utils::output_size;
+use crate::utils::{apply_scale, output_size};
const TEXT: &str = "Failed to parse the config file. \
Please run niri validate \
@@ -171,9 +171,7 @@ impl ConfigErrorNotification {
fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result {
let _span = tracy_client::span!("config_error_notification::render");
- let apply_scale = |val: i32| (f64::from(val) * scale).round() as i32;
-
- let padding = apply_scale(PADDING);
+ let padding = apply_scale(scale, PADDING);
let mut text = String::from(TEXT);
let mut border_color = (1., 0.3, 0.3);
@@ -187,7 +185,7 @@ fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result Enter to confirm.";
@@ -101,12 +101,10 @@ impl ExitConfirmDialog {
fn render(scale: f64) -> anyhow::Result {
let _span = tracy_client::span!("exit_confirm_dialog::render");
- let apply_scale = |val: i32| (f64::from(val) * scale).round() as i32;
-
- let padding = apply_scale(PADDING);
+ let padding = apply_scale(scale, PADDING);
let mut font = FontDescription::from_string(FONT);
- font.set_absolute_size(apply_scale(font.size()).into());
+ font.set_absolute_size(apply_scale(scale, font.size()).into());
let surface = ImageSurface::create(cairo::Format::ARgb32, 0, 0)?;
let cr = cairo::Context::new(&surface)?;
diff --git a/src/ui/hotkey_overlay.rs b/src/ui/hotkey_overlay.rs
index ac61e562..e93dcb30 100644
--- a/src/ui/hotkey_overlay.rs
+++ b/src/ui/hotkey_overlay.rs
@@ -18,7 +18,7 @@ use crate::input::CompositorMod;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::renderer::NiriRenderer;
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
-use crate::utils::output_size;
+use crate::utils::{apply_scale, output_size};
const PADDING: i32 = 8;
// const MARGIN: i32 = PADDING * 2;
@@ -133,11 +133,9 @@ fn render(
) -> anyhow::Result {
let _span = tracy_client::span!("hotkey_overlay::render");
- let apply_scale = |val: i32| (f64::from(val) * scale).round() as i32;
-
// let margin = MARGIN * scale;
- let padding = apply_scale(PADDING);
- let line_interval = apply_scale(LINE_INTERVAL);
+ let padding = apply_scale(scale, PADDING);
+ let line_interval = apply_scale(scale, LINE_INTERVAL);
// FIXME: if it doesn't fit, try splitting in two columns or something.
// let mut target_size = output_size;
@@ -247,7 +245,7 @@ fn render(
.collect::>();
let mut font = FontDescription::from_string(FONT);
- font.set_absolute_size(apply_scale(font.size()).into());
+ font.set_absolute_size(apply_scale(scale, font.size()).into());
let surface = ImageSurface::create(cairo::Format::ARgb32, 0, 0)?;
let cr = cairo::Context::new(&surface)?;
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 7d41b923..2fd1d8f8 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -90,6 +90,11 @@ pub fn center_f64(rect: Rectangle) -> Point {
rect.loc + rect.size.downscale(2.0).to_point()
}
+/// Convert logical pixels to physical, rounding to physical pixels.
+pub fn apply_scale(scale: f64, val: i32) -> i32 {
+ (f64::from(val) * scale).round() as i32
+}
+
pub fn output_size(output: &Output) -> Size {
let output_scale = output.current_scale().integer_scale();
let output_transform = output.current_transform();