aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/wayland/events.rs
diff options
context:
space:
mode:
authorVictor Berger <victor.berger@m4x.org>2015-12-13 13:13:20 +0100
committerVictor Berger <victor.berger@m4x.org>2015-12-22 14:36:41 +0100
commit0792557f4bc05125f0181729a6adbaf1aa52ec27 (patch)
tree5ec91790f77500f72e78886f1d71cbd5ea8218e4 /src/api/wayland/events.rs
parent6294d3c7ddc303913c83fd74d14c7a801d496c9e (diff)
downloadglutin-0792557f4bc05125f0181729a6adbaf1aa52ec27.tar.gz
glutin-0792557f4bc05125f0181729a6adbaf1aa52ec27.zip
api/wayland: pointer events support.
Diffstat (limited to 'src/api/wayland/events.rs')
-rw-r--r--src/api/wayland/events.rs91
1 files changed, 89 insertions, 2 deletions
diff --git a/src/api/wayland/events.rs b/src/api/wayland/events.rs
index 86f0575..6a7a2e7 100644
--- a/src/api/wayland/events.rs
+++ b/src/api/wayland/events.rs
@@ -1,10 +1,97 @@
+use std::collections::HashSet;
+
use Event as GlutinEvent;
+use ElementState;
+use MouseButton;
+use MouseScrollDelta;
use wayland_client::Event as WaylandEvent;
use wayland_client::ProxyId;
+use wayland_client::wayland::WaylandProtocolEvent as WPE;
+use wayland_client::wayland::seat::{WlSeat, WlSeatEvent, WlPointerEvent,
+ WlPointerButtonState,
+ WlPointerAxis, WlSeatCapability};
+
+use super::context::WaylandFocuses;
-pub fn translate_event(evt: WaylandEvent) -> Option<(GlutinEvent, ProxyId)> {
- match evt {
+pub fn translate_event(
+ evt: WaylandEvent,
+ focuses: &mut WaylandFocuses,
+ known_surfaces: &HashSet<ProxyId>,
+ seat: Option<&WlSeat>,
+) -> Option<(GlutinEvent, ProxyId)> {
+ let WaylandEvent::Wayland(wayland_evt) = evt;
+ match wayland_evt {
+ WPE::WlSeat(_, seat_evt) => match seat_evt {
+ WlSeatEvent::Capabilities(cap) => {
+ if cap.contains(WlSeatCapability::Pointer) && focuses.pointer.is_none() {
+ if let Some(seat) = seat {
+ focuses.pointer = Some(seat.get_pointer());
+ }
+ }
+ None
+ },
+ _ => None
+ },
+ WPE::WlPointer(_, pointer_evt) => match pointer_evt {
+ WlPointerEvent::Enter(_, surface, x, y) => {
+ if known_surfaces.contains(&surface) {
+ focuses.pointer_on = Some(surface);
+ focuses.pointer_at = Some((x, y));
+ Some((GlutinEvent::MouseMoved((x as i32, y as i32)), surface))
+ } else {
+ None
+ }
+ }
+ WlPointerEvent::Leave(_, _) => {
+ focuses.pointer_on = None;
+ focuses.pointer_at = None;
+ None
+ }
+ WlPointerEvent::Motion(_, x, y) => {
+ if let Some(surface) = focuses.pointer_on {
+ focuses.pointer_at = Some((x, y));
+ Some((GlutinEvent::MouseMoved((x as i32, y as i32)), surface))
+ } else {
+ None
+ }
+ }
+ WlPointerEvent::Button(_, _, button, state) => {
+ if let Some(surface) = focuses.pointer_on {
+ Some((GlutinEvent::MouseInput(
+ match state {
+ WlPointerButtonState::Pressed => ElementState::Pressed,
+ WlPointerButtonState::Released => ElementState::Released
+ },
+ match button {
+ 0x110 => MouseButton::Left,
+ 0x111 => MouseButton::Right,
+ 0x112 => MouseButton::Middle,
+ // TODO figure out the translation ?
+ _ => return None
+ }
+ ), surface))
+ } else {
+ None
+ }
+ }
+ WlPointerEvent::Axis(_, axis, amplitude) => {
+ if let Some(surface) = focuses.pointer_on {
+ Some((GlutinEvent::MouseWheel(
+ match axis {
+ WlPointerAxis::VerticalScroll => {
+ MouseScrollDelta::PixelDelta(amplitude as f32, 0.0)
+ }
+ WlPointerAxis::HorizontalScroll => {
+ MouseScrollDelta::PixelDelta(0.0, amplitude as f32)
+ }
+ }
+ ), surface))
+ } else {
+ None
+ }
+ }
+ },
_ => None
}
} \ No newline at end of file