mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-11-17 23:14:23 +00:00
refactor: minor changes on scale factor logic
This commit is contained in:
parent
e73cce3455
commit
16ca0552c9
5 changed files with 39 additions and 15 deletions
|
|
@ -227,8 +227,8 @@ impl Dispatch<WpFractionalScaleV1, ()> for WindowState {
|
||||||
_qhandle: &QueueHandle<Self>,
|
_qhandle: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
if let wp_fractional_scale_v1::Event::PreferredScale { scale } = event {
|
if let wp_fractional_scale_v1::Event::PreferredScale { scale } = event {
|
||||||
#[allow(clippy::cast_precision_loss)]
|
use crate::wayland::surfaces::display_metrics::DisplayMetrics;
|
||||||
let scale_float = scale as f32 / 120.0;
|
let scale_float = DisplayMetrics::scale_factor_from_120ths(scale);
|
||||||
info!("Fractional scale received: {scale_float} ({scale}x)");
|
info!("Fractional scale received: {scale_float} ({scale}x)");
|
||||||
state.update_scale_for_fractional_scale_object(proxy, scale);
|
state.update_scale_for_fractional_scale_object(proxy, scale);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use layer_shika_domain::dimensions::{
|
||||||
LogicalSize as DomainLogicalSize, PhysicalSize as DomainPhysicalSize,
|
LogicalSize as DomainLogicalSize, PhysicalSize as DomainPhysicalSize,
|
||||||
ScaleFactor as DomainScaleFactor,
|
ScaleFactor as DomainScaleFactor,
|
||||||
};
|
};
|
||||||
|
use layer_shika_domain::errors::Result as DomainResult;
|
||||||
use layer_shika_domain::surface_dimensions::SurfaceDimensions;
|
use layer_shika_domain::surface_dimensions::SurfaceDimensions;
|
||||||
use log::info;
|
use log::info;
|
||||||
use slint::PhysicalSize;
|
use slint::PhysicalSize;
|
||||||
|
|
@ -40,6 +41,11 @@ impl DisplayMetrics {
|
||||||
self.surface.scale_factor().value()
|
self.surface.scale_factor().value()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn scale_factor_typed(&self) -> DomainScaleFactor {
|
||||||
|
self.surface.scale_factor()
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn output_size(&self) -> PhysicalSize {
|
pub const fn output_size(&self) -> PhysicalSize {
|
||||||
self.output_size
|
self.output_size
|
||||||
|
|
@ -53,11 +59,28 @@ impl DisplayMetrics {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn surface_dimensions(&self) -> &SurfaceDimensions {
|
||||||
|
&self.surface
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn has_fractional_scale(&self) -> bool {
|
pub const fn has_fractional_scale(&self) -> bool {
|
||||||
self.has_fractional_scale
|
self.has_fractional_scale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn calculate_dimensions(
|
||||||
|
&self,
|
||||||
|
logical_width: u32,
|
||||||
|
logical_height: u32,
|
||||||
|
) -> DomainResult<SurfaceDimensions> {
|
||||||
|
SurfaceDimensions::calculate(logical_width, logical_height, self.scale_factor())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale_factor_from_120ths(scale_120ths: u32) -> f32 {
|
||||||
|
DomainScaleFactor::from_120ths(scale_120ths).value()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
#[allow(clippy::cast_precision_loss)]
|
||||||
pub fn update_scale_factor(&mut self, scale_120ths: u32) -> f32 {
|
pub fn update_scale_factor(&mut self, scale_120ths: u32) -> f32 {
|
||||||
let new_scale = DomainScaleFactor::from_120ths(scale_120ths);
|
let new_scale = DomainScaleFactor::from_120ths(scale_120ths);
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ impl EventContext {
|
||||||
self.display_metrics.borrow().scale_factor()
|
self.display_metrics.borrow().scale_factor()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
|
||||||
pub fn update_scale_factor(&mut self, scale_120ths: u32) -> f32 {
|
pub fn update_scale_factor(&mut self, scale_120ths: u32) -> f32 {
|
||||||
let new_scale_factor = self
|
let new_scale_factor = self
|
||||||
.display_metrics
|
.display_metrics
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::errors::{LayerShikaError, Result};
|
use crate::errors::{LayerShikaError, Result};
|
||||||
use crate::rendering::egl::context::EGLContext;
|
use crate::rendering::egl::context::EGLContext;
|
||||||
use crate::rendering::femtovg::{popup_window::PopupWindow, renderable_window::RenderableWindow};
|
use crate::rendering::femtovg::{popup_window::PopupWindow, renderable_window::RenderableWindow};
|
||||||
use crate::wayland::surfaces::display_metrics::SharedDisplayMetrics;
|
use crate::wayland::surfaces::display_metrics::{DisplayMetrics, SharedDisplayMetrics};
|
||||||
use layer_shika_domain::dimensions::{LogicalSize as DomainLogicalSize, ScaleFactor as DomainScaleFactor};
|
use layer_shika_domain::dimensions::LogicalSize as DomainLogicalSize;
|
||||||
use layer_shika_domain::surface_dimensions::SurfaceDimensions;
|
use layer_shika_domain::surface_dimensions::SurfaceDimensions;
|
||||||
use layer_shika_domain::value_objects::popup_config::PopupConfig;
|
use layer_shika_domain::value_objects::popup_config::PopupConfig;
|
||||||
use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode;
|
use layer_shika_domain::value_objects::popup_positioning_mode::PopupPositioningMode;
|
||||||
|
|
@ -179,15 +179,8 @@ impl PopupManager {
|
||||||
self.state.borrow().display_metrics.borrow().output_size()
|
self.state.borrow().display_metrics.borrow().output_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
|
|
||||||
pub fn update_scale_factor(&self, scale_factor: f32) {
|
pub fn update_scale_factor(&self, scale_factor: f32) {
|
||||||
self.scale_factor.set(scale_factor);
|
self.scale_factor.set(scale_factor);
|
||||||
let scale_120ths = (scale_factor * 120.0) as u32;
|
|
||||||
self.state
|
|
||||||
.borrow()
|
|
||||||
.display_metrics
|
|
||||||
.borrow_mut()
|
|
||||||
.update_scale_factor(scale_120ths);
|
|
||||||
|
|
||||||
for popup in self.state.borrow().popups.values() {
|
for popup in self.state.borrow().popups.values() {
|
||||||
popup.window.set_scale_factor(scale_factor);
|
popup.window.set_scale_factor(scale_factor);
|
||||||
|
|
@ -246,7 +239,12 @@ impl PopupManager {
|
||||||
);
|
);
|
||||||
|
|
||||||
let popup_logical_size = DomainLogicalSize::from_raw(params.width, params.height);
|
let popup_logical_size = DomainLogicalSize::from_raw(params.width, params.height);
|
||||||
let domain_scale = DomainScaleFactor::from_raw(scale_factor);
|
let domain_scale = self
|
||||||
|
.state
|
||||||
|
.borrow()
|
||||||
|
.display_metrics
|
||||||
|
.borrow()
|
||||||
|
.scale_factor_typed();
|
||||||
let popup_dimensions = SurfaceDimensions::from_logical(popup_logical_size, domain_scale);
|
let popup_dimensions = SurfaceDimensions::from_logical(popup_logical_size, domain_scale);
|
||||||
|
|
||||||
let popup_config = PopupConfig::new(
|
let popup_config = PopupConfig::new(
|
||||||
|
|
@ -490,8 +488,7 @@ impl PopupManager {
|
||||||
|
|
||||||
if let Some(popup_key) = self.find_popup_key_by_fractional_scale_id(&fractional_scale_id) {
|
if let Some(popup_key) = self.find_popup_key_by_fractional_scale_id(&fractional_scale_id) {
|
||||||
if let Some(popup_window) = self.get_popup_window(popup_key) {
|
if let Some(popup_window) = self.get_popup_window(popup_key) {
|
||||||
let new_scale = DomainScaleFactor::from_120ths(scale_120ths);
|
let new_scale_factor = DisplayMetrics::scale_factor_from_120ths(scale_120ths);
|
||||||
let new_scale_factor = new_scale.value();
|
|
||||||
info!("Updating popup scale factor to {new_scale_factor} ({scale_120ths}x)");
|
info!("Updating popup scale factor to {new_scale_factor} ({scale_120ths}x)");
|
||||||
popup_window.set_scale_factor(new_scale_factor);
|
popup_window.set_scale_factor(new_scale_factor);
|
||||||
popup_window.request_redraw();
|
popup_window.request_redraw();
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,11 @@ impl<W: RenderableWindow> WindowRenderer<W> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.apply_surface_dimensions(dimensions, scale_factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply_surface_dimensions(&mut self, dimensions: SurfaceDimensions, scale_factor: f32) {
|
||||||
let scaling_mode = self.determine_scaling_mode();
|
let scaling_mode = self.determine_scaling_mode();
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue