Skip to content

Commit

Permalink
chore: try to fix scroll problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 22, 2024
1 parent f53925e commit 4881b17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
11 changes: 6 additions & 5 deletions iced_layershell/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<Message: 'static, INFO: Clone> From<&DispatchMessage> for IcedLayerEvent<Me
DispatchMessage::Axis {
horizontal,
vertical,
scale,
..
} => {
if horizontal.stop && vertical.stop {
Expand All @@ -223,13 +224,13 @@ impl<Message: 'static, INFO: Clone> From<&DispatchMessage> for IcedLayerEvent<Me
let has_scroll = vertical.discrete != 0 || horizontal.discrete != 0;
if has_scroll {
return IcedLayerEvent::Window(WindowEvent::Axis {
x: -horizontal.discrete as f32,
y: -vertical.discrete as f32,
x: (-horizontal.discrete as f64 * scale) as f32,
y: (-vertical.discrete as f64 * scale) as f32,
});
}
IcedLayerEvent::Window(WindowEvent::Axis {
x: -horizontal.absolute as f32,
y: -vertical.absolute as f32,
IcedLayerEvent::Window(WindowEvent::PixelDelta {
x: (-horizontal.absolute as f64 * scale) as f32,
y: (-vertical.absolute as f64 * scale) as f32,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion iced_sessionlock/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<Message: 'static> From<&DispatchMessage> for IcedSessionLockEvent<Message>
y: -vertical.discrete as f32,
});
}
IcedSessionLockEvent::Window(WindowEvent::Axis {
IcedSessionLockEvent::Window(WindowEvent::PixelDelta {
x: -horizontal.absolute as f32,
y: -vertical.absolute as f32,
})
Expand Down
4 changes: 4 additions & 0 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub(crate) enum DispatchMessageInner {
surface_y: f64,
},
Axis {
scale: f64,
time: u32,
horizontal: AxisScroll,
vertical: AxisScroll,
Expand Down Expand Up @@ -276,6 +277,7 @@ pub enum DispatchMessage {
},
/// About the scroll
Axis {
scale: f64,
time: u32,
horizontal: AxisScroll,
vertical: AxisScroll,
Expand Down Expand Up @@ -410,11 +412,13 @@ impl From<DispatchMessageInner> for DispatchMessage {
is_created,
},
DispatchMessageInner::Axis {
scale,
time,
horizontal,
vertical,
source,
} => DispatchMessage::Axis {
scale,
time,
horizontal,
vertical,
Expand Down
13 changes: 13 additions & 0 deletions layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,15 @@ impl<T> Dispatch<wl_pointer::WlPointer, ()> for WindowState<T> {
_conn: &Connection,
_qhandle: &wayland_client::QueueHandle<Self>,
) {
let Some(surface_id) = state.surface_id() else {
return;
};
let Some(scale) = state
.get_unit_with_id(surface_id)
.map(|unit| unit.scale_float())
else {
return;
};
match event {
wl_pointer::Event::Axis { time, axis, value } => match axis {
WEnum::Value(axis) => {
Expand All @@ -1374,6 +1383,7 @@ impl<T> Dispatch<wl_pointer::WlPointer, ()> for WindowState<T> {
state.message.push((
state.surface_id(),
DispatchMessageInner::Axis {
scale,
time,
horizontal,
vertical,
Expand All @@ -1398,6 +1408,7 @@ impl<T> Dispatch<wl_pointer::WlPointer, ()> for WindowState<T> {
state.message.push((
state.surface_id(),
DispatchMessageInner::Axis {
scale,
time,
horizontal,
vertical,
Expand All @@ -1414,6 +1425,7 @@ impl<T> Dispatch<wl_pointer::WlPointer, ()> for WindowState<T> {
WEnum::Value(source) => state.message.push((
state.surface_id(),
DispatchMessageInner::Axis {
scale,
horizontal: AxisScroll::default(),
vertical: AxisScroll::default(),
source: Some(source),
Expand Down Expand Up @@ -1442,6 +1454,7 @@ impl<T> Dispatch<wl_pointer::WlPointer, ()> for WindowState<T> {
state.message.push((
state.surface_id(),
DispatchMessageInner::Axis {
scale,
time: 0,
horizontal,
vertical,
Expand Down

0 comments on commit 4881b17

Please sign in to comment.