Skip to content

Commit

Permalink
fix: set scale at the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent 7150c3b commit ba8084b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
8 changes: 6 additions & 2 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,12 @@ async fn run_instance<A, E, C>(

while let Some(event) = event_receiver.next().await {
match event {
IcedLayerEvent::RequestRefresh { width, height } => {
state.update_view_port(width, height);
IcedLayerEvent::RequestRefresh {
width,
height,
fractal_scale,
} => {
state.update_view_port(width, height, fractal_scale);
let ps = state.physical_size();
let width = ps.width;
let height = ps.height;
Expand Down
3 changes: 2 additions & 1 deletion iced_layershell/src/application/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ where
self.window_scale_factor
}

pub fn update_view_port(&mut self, width: u32, height: u32) {
pub fn update_view_port(&mut self, width: u32, height: u32, scale: f64) {
self.window_scale_factor = scale;
self.viewport = Viewport::with_physical_size(
iced::Size::new(width, height),
self.current_wayland_scale() * self.scale_factor,
Expand Down
18 changes: 12 additions & 6 deletions iced_layershell/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ pub enum IcedLayerEvent<Message: 'static, INFO: Clone> {
RequestRefreshWithWrapper {
width: u32,
height: u32,
fractal_scale: f64,
wrapper: WindowWrapper,
is_created: bool,
info: Option<INFO>,
},
RequestRefresh {
width: u32,
height: u32,
fractal_scale: f64,
},
Window(WindowEvent),
NormalUpdate,
Expand All @@ -131,12 +133,16 @@ impl<Message: 'static, INFO: Clone> From<(Option<Id>, IcedLayerEvent<Message, IN
impl<Message: 'static, INFO: Clone> From<&DispatchMessage> for IcedLayerEvent<Message, INFO> {
fn from(value: &DispatchMessage) -> Self {
match value {
DispatchMessage::RequestRefresh { width, height, .. } => {
IcedLayerEvent::RequestRefresh {
width: *width,
height: *height,
}
}
DispatchMessage::RequestRefresh {
width,
height,
scale_float,
..
} => IcedLayerEvent::RequestRefresh {
width: *width,
height: *height,
fractal_scale: *scale_float,
},
DispatchMessage::MouseEnter {
surface_x: x,
surface_y: y,
Expand Down
4 changes: 4 additions & 0 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ where
DispatchMessage::RequestRefresh {
width,
height,
scale_float,
is_created,
..
} => {
Expand All @@ -268,6 +269,7 @@ where
IcedLayerEvent::RequestRefreshWithWrapper {
width: *width,
height: *height,
fractal_scale: *scale_float,
wrapper: unit.gen_wrapper(),
is_created: *is_created,
info: unit.get_binding().cloned(),
Expand Down Expand Up @@ -502,6 +504,7 @@ async fn run_instance<A, E, C>(
IcedLayerEvent::RequestRefreshWithWrapper {
width,
height,
fractal_scale,
wrapper,
is_created,
info,
Expand All @@ -515,6 +518,7 @@ async fn run_instance<A, E, C>(
let window = window_manager.insert(
id,
(width, height),
fractal_scale,
Arc::new(wrapper),
&application,
&mut compositor,
Expand Down
8 changes: 6 additions & 2 deletions iced_layershell/src/multi_window/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ impl<A: Application> State<A>
where
A::Theme: DefaultStyle,
{
pub fn new(id: window::Id, application: &A, (width, height): (u32, u32)) -> Self {
pub fn new(
id: window::Id,
application: &A,
(width, height): (u32, u32),
wayland_scale_factor: f64,
) -> Self {
let scale_factor = application.scale_factor(id);
let theme = application.theme();
let appearance = application.style(&theme);

let wayland_scale_factor = 1.0;
let viewport = Viewport::with_physical_size(
iced_core::Size::new(width, height),
wayland_scale_factor * scale_factor,
Expand Down
3 changes: 2 additions & 1 deletion iced_layershell/src/multi_window/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ where
&mut self,
id: IcedId,
size: (u32, u32),
fractal_scale: f64,
window: Arc<WindowWrapper>,
application: &A,
compositor: &mut C,
) -> &mut Window<A, C> {
let layerid = window.id();
let state = State::new(id, application, size);
let state = State::new(id, application, size, fractal_scale);
let physical_size = state.physical_size();
let surface = compositor.create_surface(window, physical_size.width, physical_size.height);
let renderer = compositor.create_renderer();
Expand Down
8 changes: 4 additions & 4 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ pub(crate) enum DispatchMessageInner {
RequestRefresh {
width: u32,
height: u32,
is_created: bool,
scale_float: f64,
is_created: bool,
},
PreferredScale {
scale_u32: u32,
Expand Down Expand Up @@ -323,8 +323,8 @@ pub enum DispatchMessage {
RequestRefresh {
width: u32,
height: u32,
is_created: bool,
scale_float: f64,
is_created: bool,
},
/// fractal scale handle
PreferredScale { scale_u32: u32, scale_float: f64 },
Expand Down Expand Up @@ -401,13 +401,13 @@ impl From<DispatchMessageInner> for DispatchMessage {
DispatchMessageInner::RequestRefresh {
width,
height,
is_created,
scale_float,
is_created,
} => DispatchMessage::RequestRefresh {
width,
height,
is_created,
scale_float,
is_created,
},
DispatchMessageInner::Axis {
time,
Expand Down
1 change: 0 additions & 1 deletion layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,6 @@ impl<T: 'static> WindowState<T> {
becreated: true,
wl_output: None,
binding: info,

scale: 120,
});
}
Expand Down

0 comments on commit ba8084b

Please sign in to comment.