Skip to content

Commit

Permalink
feat: handle base scale in base lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent 1e37743 commit 54c436b
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 29 deletions.
15 changes: 11 additions & 4 deletions iced_layershell/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ impl From<WEnum<KeyState>> for IcedKeyState {

#[derive(Debug, Clone)]
pub enum WindowEvent {
ScaleChanged(u32),
ScaleChanged {
scale_int: u32,
scale_float: f64,
},
CursorEnter {
x: f64,
y: f64,
Expand Down Expand Up @@ -186,9 +189,13 @@ impl<Message: 'static, INFO: Clone> From<&DispatchMessage> for IcedLayerEvent<Me
})
}

DispatchMessage::PrefredScale(scale) => {
IcedLayerEvent::Window(WindowEvent::ScaleChanged(*scale))
}
DispatchMessage::PreferredScale {
scale_int,
scale_float,
} => IcedLayerEvent::Window(WindowEvent::ScaleChanged {
scale_int: *scale_int,
scale_float: *scale_float,
}),

DispatchMessage::KeyboardInput {
event,
Expand Down
1 change: 1 addition & 0 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ where
width,
height,
is_created,
..
} => {
let Some(unit) = ev.get_mut_unit_with_id(sended_id.unwrap()) else {
break 'outside;
Expand Down
17 changes: 12 additions & 5 deletions iced_sessionlock/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl From<WEnum<KeyState>> for IcedKeyState {

#[derive(Debug, Clone)]
pub enum WindowEvent {
ScaleChanged(u32),
ScaleChanged {
scale_int: u32,
scale_float: f64,
},
CursorEnter {
x: f64,
y: f64,
Expand Down Expand Up @@ -114,7 +117,7 @@ impl<Message: 'static> From<(Option<Id>, IcedSessionLockEvent<Message>)>
impl<Message: 'static> From<&DispatchMessage> for IcedSessionLockEvent<Message> {
fn from(value: &DispatchMessage) -> Self {
match value {
DispatchMessage::RequestRefresh { width, height } => {
DispatchMessage::RequestRefresh { width, height, .. } => {
IcedSessionLockEvent::RequestRefresh {
width: *width,
height: *height,
Expand Down Expand Up @@ -168,9 +171,13 @@ impl<Message: 'static> From<&DispatchMessage> for IcedSessionLockEvent<Message>
y: *y,
})
}
DispatchMessage::PrefredScale(scale) => {
IcedSessionLockEvent::Window(WindowEvent::ScaleChanged(*scale))
}
DispatchMessage::PreferredScale {
scale_float,
scale_int,
} => IcedSessionLockEvent::Window(WindowEvent::ScaleChanged {
scale_int: *scale_int,
scale_float: *scale_float,
}),
DispatchMessage::KeyboardInput {
event,
is_synthetic,
Expand Down
2 changes: 1 addition & 1 deletion iced_sessionlock/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ where
SessionLockEvent::BindProvide(_, _) => {}
SessionLockEvent::RequestMessages(message) => 'outside: {
match message {
DispatchMessage::RequestRefresh { width, height } => {
DispatchMessage::RequestRefresh { width, height, .. } => {
event_sender
.start_send(MultiWindowIcedSessionLockEvent(
id,
Expand Down
19 changes: 16 additions & 3 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ pub(crate) enum DispatchMessageInner {
width: u32,
height: u32,
is_created: bool,
scale_float: f64,
},
PreferredScale {
scale_int: u32,
scale_float: f64,
},
PrefredScale(u32),
XdgInfoChanged(XdgInfoChangedType),
}

Expand Down Expand Up @@ -320,9 +324,10 @@ pub enum DispatchMessage {
width: u32,
height: u32,
is_created: bool,
scale_float: f64,
},
/// fractal scale handle
PrefredScale(u32),
PreferredScale { scale_int: u32, scale_float: f64 },
}

impl From<DispatchMessageInner> for DispatchMessage {
Expand Down Expand Up @@ -397,10 +402,12 @@ impl From<DispatchMessageInner> for DispatchMessage {
width,
height,
is_created,
scale_float,
} => DispatchMessage::RequestRefresh {
width,
height,
is_created,
scale_float,
},
DispatchMessageInner::Axis {
time,
Expand All @@ -423,7 +430,13 @@ impl From<DispatchMessageInner> for DispatchMessage {
event,
is_synthetic,
},
DispatchMessageInner::PrefredScale(scale) => DispatchMessage::PrefredScale(scale),
DispatchMessageInner::PreferredScale {
scale_int,
scale_float,
} => DispatchMessage::PreferredScale {
scale_int,
scale_float,
},
DispatchMessageInner::RefreshSurface { .. } => unimplemented!(),
DispatchMessageInner::XdgInfoChanged(_) => unimplemented!(),
}
Expand Down
32 changes: 29 additions & 3 deletions layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ use wayland_protocols_misc::zwp_virtual_keyboard_v1::client::{
zwp_virtual_keyboard_v1::ZwpVirtualKeyboardV1,
};

use std::f64;
use std::time::Duration;

use sctk::reexports::{
Expand Down Expand Up @@ -359,6 +360,8 @@ pub struct WindowStateUnit<T> {
wl_output: Option<WlOutput>,
binding: Option<T>,
becreated: bool,

scale: u32,
}

impl<T> WindowStateUnit<T> {
Expand Down Expand Up @@ -536,6 +539,14 @@ impl<T> WindowStateUnit<T> {
self.wl_surface.damage(0, 0, width, height);
self.wl_surface.commit();
}

pub fn scale_u32(&self) -> u32 {
self.scale
}

pub fn scale_float(&self) -> f64 {
self.scale as f64 / 120.
}
}

/// main state, store the main information
Expand Down Expand Up @@ -1657,9 +1668,13 @@ impl<T> Dispatch<wp_fractional_scale_v1::WpFractionalScaleV1, ()> for WindowStat
else {
return;
};
state
.message
.push((Some(id), DispatchMessageInner::PrefredScale(scale)));
state.message.push((
Some(id),
DispatchMessageInner::PreferredScale {
scale_int: scale,
scale_float: scale as f64 / 120.,
},
));
}
}
}
Expand Down Expand Up @@ -1815,6 +1830,7 @@ impl<T: 'static> WindowState<T> {
binding: None,
becreated: false,
wl_output: None,
scale: 120,
});
} else {
let displays = self.outputs.clone();
Expand Down Expand Up @@ -1870,6 +1886,7 @@ impl<T: 'static> WindowState<T> {
binding: None,
becreated: false,
wl_output: Some(output_display.clone()),
scale: 120,
});
}
self.message.clear();
Expand Down Expand Up @@ -1996,6 +2013,7 @@ impl<T: 'static> WindowState<T> {
width: *width,
height: *height,
is_created: self.units[index].becreated,
scale_float: self.units[index].scale_float(),
}),
&mut self,
Some(*unit_index),
Expand Down Expand Up @@ -2071,6 +2089,7 @@ impl<T: 'static> WindowState<T> {
binding: None,
becreated: false,
wl_output: Some(output_display.clone()),
scale: 120,
});
}
_ => {
Expand All @@ -2095,6 +2114,7 @@ impl<T: 'static> WindowState<T> {
width: unit.size.0,
height: unit.size.1,
is_created: unit.becreated,
scale_float: unit.scale_float(),
},
),
&mut self,
Expand All @@ -2111,6 +2131,7 @@ impl<T: 'static> WindowState<T> {
width: unit.size.0,
height: unit.size.1,
is_created: unit.becreated,
scale_float: unit.scale_float(),
},
),
&mut self,
Expand Down Expand Up @@ -2212,6 +2233,7 @@ impl<T: 'static> WindowState<T> {
width: unit.size.0,
height: unit.size.1,
is_created: unit.becreated,
scale_float: unit.scale_float(),
},
),
&mut self,
Expand All @@ -2227,6 +2249,7 @@ impl<T: 'static> WindowState<T> {
width: unit.size.0,
height: unit.size.1,
is_created: unit.becreated,
scale_float: unit.scale_float(),
}),
&mut self,
Some(id),
Expand Down Expand Up @@ -2346,6 +2369,7 @@ impl<T: 'static> WindowState<T> {
becreated: true,
wl_output: output.cloned(),
binding: info,
scale: 120,
});
}
ReturnData::NewPopUp((
Expand Down Expand Up @@ -2398,6 +2422,8 @@ impl<T: 'static> WindowState<T> {
becreated: true,
wl_output: None,
binding: info,

scale: 120,
});
}
_ => {}
Expand Down
3 changes: 2 additions & 1 deletion sessionlockev/examples/simplelock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ fn main() {
SessionLockEvent::RequestMessages(DispatchMessage::RequestRefresh {
width,
height,
scale_float,
}) => {
println!("{width}, {height}");
println!("{width}, {height}, {scale_float}");
ReturnData::None
}
SessionLockEvent::RequestMessages(DispatchMessage::MouseButton { .. }) => {
Expand Down
32 changes: 26 additions & 6 deletions sessionlockev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ pub(crate) enum DispatchMessageInner {
RequestRefresh {
width: u32,
height: u32,
scale_float: f64,
},
PreferredScale {
scale_float: f64,
scale_int: u32,
},
PrefredScale(u32),
}

/// This tell the DispatchMessage by dispatch
Expand Down Expand Up @@ -259,9 +263,13 @@ pub enum DispatchMessage {
RequestRefresh {
width: u32,
height: u32,
scale_float: f64,
},
/// fractal scale handle
PrefredScale(u32),
PreferredScale {
scale_float: f64,
scale_int: u32,
},
}

impl From<DispatchMessageInner> for DispatchMessage {
Expand Down Expand Up @@ -334,9 +342,15 @@ impl From<DispatchMessageInner> for DispatchMessage {
DispatchMessage::TouchCancel { id, x, y }
}

DispatchMessageInner::RequestRefresh { width, height } => {
DispatchMessage::RequestRefresh { width, height }
}
DispatchMessageInner::RequestRefresh {
width,
height,
scale_float,
} => DispatchMessage::RequestRefresh {
width,
height,
scale_float,
},
DispatchMessageInner::Axis {
time,
horizontal,
Expand All @@ -358,7 +372,13 @@ impl From<DispatchMessageInner> for DispatchMessage {
event,
is_synthetic,
},
DispatchMessageInner::PrefredScale(scale) => DispatchMessage::PrefredScale(scale),
DispatchMessageInner::PreferredScale {
scale_float,
scale_int,
} => DispatchMessage::PreferredScale {
scale_float,
scale_int,
},
DispatchMessageInner::RefreshSurface { .. } => unimplemented!(),
}
}
Expand Down
Loading

0 comments on commit 54c436b

Please sign in to comment.