aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/config_error_notification.rs6
-rw-r--r--src/ui/exit_confirm_dialog.rs6
-rw-r--r--src/ui/hotkey_overlay.rs8
-rw-r--r--src/ui/screenshot_ui.rs4
-rw-r--r--src/utils/mod.rs6
5 files changed, 15 insertions, 15 deletions
diff --git a/src/ui/config_error_notification.rs b/src/ui/config_error_notification.rs
index 566941c5..2def4b20 100644
--- a/src/ui/config_error_notification.rs
+++ b/src/ui/config_error_notification.rs
@@ -18,7 +18,7 @@ use crate::animation::Animation;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::renderer::NiriRenderer;
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
-use crate::utils::{apply_scale, output_size};
+use crate::utils::{output_size, to_physical_precise_round};
const TEXT: &str = "Failed to parse the config file. \
Please run <span face='monospace' bgcolor='#000000'>niri validate</span> \
@@ -173,7 +173,7 @@ fn render(
) -> anyhow::Result<TextureBuffer<GlesTexture>> {
let _span = tracy_client::span!("config_error_notification::render");
- let padding = apply_scale(scale, PADDING);
+ let padding: i32 = to_physical_precise_round(scale, PADDING);
let mut text = String::from(TEXT);
let mut border_color = (1., 0.3, 0.3);
@@ -187,7 +187,7 @@ fn render(
};
let mut font = FontDescription::from_string(FONT);
- font.set_absolute_size(apply_scale(scale, font.size()).into());
+ font.set_absolute_size(to_physical_precise_round(scale, font.size()));
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 6007eeda..9ffae3a7 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::{apply_scale, output_size};
+use crate::utils::{output_size, to_physical_precise_round};
const TEXT: &str = "Are you sure you want to exit niri?\n\n\
Press <span face='mono' bgcolor='#2C2C2C'> Enter </span> to confirm.";
@@ -101,10 +101,10 @@ impl ExitConfirmDialog {
fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
let _span = tracy_client::span!("exit_confirm_dialog::render");
- let padding = apply_scale(scale, PADDING);
+ let padding: i32 = to_physical_precise_round(scale, PADDING);
let mut font = FontDescription::from_string(FONT);
- font.set_absolute_size(apply_scale(scale, font.size()).into());
+ font.set_absolute_size(to_physical_precise_round(scale, font.size()));
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 e93dcb30..5fef2821 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::{apply_scale, output_size};
+use crate::utils::{output_size, to_physical_precise_round};
const PADDING: i32 = 8;
// const MARGIN: i32 = PADDING * 2;
@@ -134,8 +134,8 @@ fn render(
let _span = tracy_client::span!("hotkey_overlay::render");
// let margin = MARGIN * scale;
- let padding = apply_scale(scale, PADDING);
- let line_interval = apply_scale(scale, LINE_INTERVAL);
+ let padding: i32 = to_physical_precise_round(scale, PADDING);
+ let line_interval: i32 = to_physical_precise_round(scale, LINE_INTERVAL);
// FIXME: if it doesn't fit, try splitting in two columns or something.
// let mut target_size = output_size;
@@ -245,7 +245,7 @@ fn render(
.collect::<Vec<_>>();
let mut font = FontDescription::from_string(FONT);
- font.set_absolute_size(apply_scale(scale, font.size()).into());
+ font.set_absolute_size(to_physical_precise_round(scale, font.size()));
let surface = ImageSurface::create(cairo::Format::ARgb32, 0, 0)?;
let cr = cairo::Context::new(&surface)?;
diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs
index 807d8ab4..facb9692 100644
--- a/src/ui/screenshot_ui.rs
+++ b/src/ui/screenshot_ui.rs
@@ -20,7 +20,7 @@ use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
use crate::render_helpers::RenderTarget;
-use crate::utils::apply_scale;
+use crate::utils::to_physical_precise_round;
const BORDER: i32 = 2;
@@ -212,7 +212,7 @@ impl ScreenshotUi {
*b = rect.loc + rect.size - Size::from((1, 1));
}
- let border = apply_scale(scale, BORDER);
+ let border = to_physical_precise_round(scale, BORDER);
let resize = move |buffer: &mut SolidColorBuffer, w: i32, h: i32| {
let size = Size::<_, Physical>::from((w, h));
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 2fd1d8f8..807244fa 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -16,7 +16,7 @@ use smithay::output::{self, Output};
use smithay::reexports::rustix::time::{clock_gettime, ClockId};
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
-use smithay::utils::{Logical, Point, Rectangle, Size, Transform};
+use smithay::utils::{Coordinate, Logical, Point, Rectangle, Size, Transform};
use smithay::wayland::compositor::{send_surface_state, SurfaceData};
use smithay::wayland::fractional_scale::with_fractional_scale;
@@ -91,8 +91,8 @@ pub fn center_f64(rect: Rectangle<f64, Logical>) -> Point<f64, Logical> {
}
/// 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 to_physical_precise_round<N: Coordinate>(scale: f64, logical: impl Coordinate) -> N {
+ N::from_f64((logical.to_f64() * scale).round())
}
pub fn output_size(output: &Output) -> Size<i32, Logical> {