aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/config_error_notification.rs8
-rw-r--r--src/ui/exit_confirm_dialog.rs8
-rw-r--r--src/ui/hotkey_overlay.rs10
-rw-r--r--src/utils/mod.rs5
4 files changed, 15 insertions, 16 deletions
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 <span face='monospace' bgcolor='#000000'>niri validate</span> \
@@ -171,9 +171,7 @@ impl ConfigErrorNotification {
fn render(scale: f64, created_path: Option<&Path>) -> anyhow::Result<MemoryBuffer> {
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<MemoryBuffe
};
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/exit_confirm_dialog.rs b/src/ui/exit_confirm_dialog.rs
index d58df076..6007eeda 100644
--- a/src/ui/exit_confirm_dialog.rs
+++ b/src/ui/exit_confirm_dialog.rs
@@ -13,7 +13,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 = "Are you sure you want to exit niri?\n\n\
Press <span face='mono' bgcolor='#2C2C2C'> Enter </span> to confirm.";
@@ -101,12 +101,10 @@ impl ExitConfirmDialog {
fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
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<RenderedOverlay> {
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::<Vec<_>>();
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<f64, Logical>) -> Point<f64, Logical> {
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<i32, Logical> {
let output_scale = output.current_scale().integer_scale();
let output_transform = output.current_transform();