Skip to content

Commit

Permalink
ei: Handle scroll events
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Apr 25, 2024
1 parent 6e9ef79 commit 0e844b3
Showing 1 changed file with 72 additions and 7 deletions.
79 changes: 72 additions & 7 deletions src/backend/libei/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn disconnected(
impl InputBackend for EiInput {
type Device = request::Device;
type KeyboardKeyEvent = request::KeyboardKey;
type PointerAxisEvent = request::ScrollDelta; // XXX?
type PointerAxisEvent = ScrollEvent;
type PointerButtonEvent = request::Button;
type PointerMotionEvent = request::PointerMotion;
type PointerMotionAbsoluteEvent = request::PointerMotionAbsolute;
Expand Down Expand Up @@ -190,21 +190,74 @@ impl input::KeyboardKeyEvent<EiInput> for request::KeyboardKey {
}
}

impl input::PointerAxisEvent<EiInput> for request::ScrollDelta {
fn amount(&self, _axis: input::Axis) -> Option<f64> {
todo!()
pub enum ScrollEvent {
Delta(request::ScrollDelta),
Cancel(request::ScrollCancel),
Discrete(request::ScrollDiscrete),
Stop(request::ScrollStop),
}

impl input::Event<EiInput> for ScrollEvent {
fn time(&self) -> u64 {
match self {
Self::Delta(evt) => evt.time(),
Self::Cancel(evt) => evt.time(),
Self::Discrete(evt) => evt.time(),
Self::Stop(evt) => evt.time(),
}
}

fn device(&self) -> request::Device {
match self {
Self::Delta(evt) => evt.device(),
Self::Cancel(evt) => evt.device(),
Self::Discrete(evt) => evt.device(),
Self::Stop(evt) => evt.device(),
}
}
}

impl input::PointerAxisEvent<EiInput> for ScrollEvent {
fn amount(&self, axis: input::Axis) -> Option<f64> {
match self {
Self::Delta(evt) => match axis {
input::Axis::Horizontal if evt.dx != 0.0 => Some(evt.dx.into()),
input::Axis::Vertical if evt.dy != 0.0 => Some(evt.dy.into()),
_ => None,
},
// Same as Mutter
Self::Cancel(evt) => match axis {
input::Axis::Horizontal if evt.x => Some(0.01),
input::Axis::Vertical if evt.y => Some(0.01),
_ => None,
},
Self::Discrete(_evt) => None,
Self::Stop(evt) => match axis {
input::Axis::Horizontal if evt.x => Some(0.0),
input::Axis::Vertical if evt.y => Some(0.0),
_ => None,
},
}
}

fn amount_v120(&self, axis: input::Axis) -> Option<f64> {
todo!()
match self {
Self::Discrete(evt) => match axis {
input::Axis::Horizontal if evt.discrete_dx != 0 => Some(evt.discrete_dx.into()),
input::Axis::Vertical if evt.discrete_dy != 0 => Some(evt.discrete_dy.into()),
_ => None,
},
_ => None,
}
}

fn source(&self) -> input::AxisSource {
todo!()
// Mutter seems to also use wheel for all the scroll events
input::AxisSource::Wheel
}

fn relative_direction(&self, _axis: input::Axis) -> input::AxisRelativeDirection {
todo!()
input::AxisRelativeDirection::Identical
}
}

Expand Down Expand Up @@ -421,6 +474,18 @@ fn convert_request(request: EisRequest) -> Option<InputEvent<EiInput>> {
EisRequest::PointerMotion(event) => Some(InputEvent::PointerMotion { event }),
EisRequest::PointerMotionAbsolute(event) => Some(InputEvent::PointerMotionAbsolute { event }),
EisRequest::Button(event) => Some(InputEvent::PointerButton { event }),
EisRequest::ScrollDelta(event) => Some(InputEvent::PointerAxis {
event: ScrollEvent::Delta(event),
}),
EisRequest::ScrollStop(event) => Some(InputEvent::PointerAxis {
event: ScrollEvent::Stop(event),
}),
EisRequest::ScrollCancel(event) => Some(InputEvent::PointerAxis {
event: ScrollEvent::Cancel(event),
}),
EisRequest::ScrollDiscrete(event) => Some(InputEvent::PointerAxis {
event: ScrollEvent::Discrete(event),
}),
_ => None,
}
}
Expand Down

0 comments on commit 0e844b3

Please sign in to comment.