mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-11-17 23:14:23 +00:00
refactor: remove display metrics observer
This commit is contained in:
parent
6fb26f15d3
commit
4d724dcd71
3 changed files with 2 additions and 61 deletions
|
|
@ -1,19 +1,13 @@
|
||||||
use log::info;
|
use log::info;
|
||||||
use slint::PhysicalSize;
|
use slint::PhysicalSize;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub trait DisplayMetricsObserver {
|
|
||||||
fn on_scale_factor_changed(&self, new_scale: f32);
|
|
||||||
fn on_output_size_changed(&self, new_size: PhysicalSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DisplayMetrics {
|
pub struct DisplayMetrics {
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
output_size: PhysicalSize,
|
output_size: PhysicalSize,
|
||||||
surface_size: PhysicalSize,
|
surface_size: PhysicalSize,
|
||||||
has_fractional_scale: bool,
|
has_fractional_scale: bool,
|
||||||
observers: RefCell<Vec<Weak<dyn DisplayMetricsObserver>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DisplayMetrics {
|
impl DisplayMetrics {
|
||||||
|
|
@ -24,7 +18,6 @@ impl DisplayMetrics {
|
||||||
output_size: PhysicalSize::new(0, 0),
|
output_size: PhysicalSize::new(0, 0),
|
||||||
surface_size: PhysicalSize::new(0, 0),
|
surface_size: PhysicalSize::new(0, 0),
|
||||||
has_fractional_scale,
|
has_fractional_scale,
|
||||||
observers: RefCell::new(Vec::new()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,11 +47,6 @@ impl DisplayMetrics {
|
||||||
self.has_fractional_scale
|
self.has_fractional_scale
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_observer(&self, observer: Weak<dyn DisplayMetricsObserver>) {
|
|
||||||
self.observers.borrow_mut().push(observer);
|
|
||||||
self.cleanup_dead_observers();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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_factor = scale_120ths as f32 / 120.0;
|
let new_scale_factor = scale_120ths as f32 / 120.0;
|
||||||
|
|
@ -71,7 +59,6 @@ impl DisplayMetrics {
|
||||||
);
|
);
|
||||||
self.scale_factor = new_scale_factor;
|
self.scale_factor = new_scale_factor;
|
||||||
self.recalculate_surface_size();
|
self.recalculate_surface_size();
|
||||||
self.notify_scale_factor_changed(new_scale_factor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_scale_factor
|
new_scale_factor
|
||||||
|
|
@ -85,7 +72,6 @@ impl DisplayMetrics {
|
||||||
);
|
);
|
||||||
self.output_size = output_size;
|
self.output_size = output_size;
|
||||||
self.recalculate_surface_size();
|
self.recalculate_surface_size();
|
||||||
self.notify_output_size_changed(output_size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,34 +92,6 @@ impl DisplayMetrics {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn notify_scale_factor_changed(&self, new_scale: f32) {
|
|
||||||
self.observers.borrow_mut().retain(|observer| {
|
|
||||||
if let Some(obs) = observer.upgrade() {
|
|
||||||
obs.on_scale_factor_changed(new_scale);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn notify_output_size_changed(&self, new_size: PhysicalSize) {
|
|
||||||
self.observers.borrow_mut().retain(|observer| {
|
|
||||||
if let Some(obs) = observer.upgrade() {
|
|
||||||
obs.on_output_size_changed(new_size);
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cleanup_dead_observers(&self) {
|
|
||||||
self.observers
|
|
||||||
.borrow_mut()
|
|
||||||
.retain(|obs| obs.upgrade().is_some());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SharedDisplayMetrics = Rc<RefCell<DisplayMetrics>>;
|
pub type SharedDisplayMetrics = Rc<RefCell<DisplayMetrics>>;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
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;
|
use crate::rendering::femtovg::popup_window::PopupWindow;
|
||||||
use crate::wayland::surfaces::display_metrics::{DisplayMetricsObserver, SharedDisplayMetrics};
|
use crate::wayland::surfaces::display_metrics::SharedDisplayMetrics;
|
||||||
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;
|
||||||
use layer_shika_domain::value_objects::popup_request::{PopupHandle, PopupRequest};
|
use layer_shika_domain::value_objects::popup_request::{PopupHandle, PopupRequest};
|
||||||
|
|
@ -487,16 +487,3 @@ impl PopupManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DisplayMetricsObserver for PopupManager {
|
|
||||||
fn on_scale_factor_changed(&self, new_scale: f32) {
|
|
||||||
info!("PopupManager received scale factor change: {}", new_scale);
|
|
||||||
for popup in self.state.borrow().popups.values() {
|
|
||||||
popup.window.set_scale_factor(new_scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_output_size_changed(&self, new_size: PhysicalSize) {
|
|
||||||
info!("PopupManager received output size change: {:?}", new_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -209,10 +209,6 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_popup_manager(&mut self, popup_manager: Rc<PopupManager>) {
|
pub fn set_popup_manager(&mut self, popup_manager: Rc<PopupManager>) {
|
||||||
self.display_metrics
|
|
||||||
.borrow()
|
|
||||||
.register_observer(Rc::downgrade(&popup_manager) as _);
|
|
||||||
|
|
||||||
self.event_context.set_popup_manager(popup_manager);
|
self.event_context.set_popup_manager(popup_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue