From 2cc401594da99ad1080a76231ea3715cc7afbe19 Mon Sep 17 00:00:00 2001 From: Drakulix Date: Sat, 15 Apr 2017 22:02:44 +0200 Subject: [PATCH] Add pointer button event passing --- src/backend/libinput.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index fcb5729..6a34800 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -1,7 +1,7 @@ //! Implementation of input backend trait for types provided by `libinput` use backend::SeatInternal; -use backend::input::{InputBackend, InputHandler, Seat, SeatCapabilities}; +use backend::input::{InputBackend, InputHandler, Seat, SeatCapabilities, MouseButton}; use input::{Libinput, Device, Seat as LibinputSeat, DeviceCapability}; use input::event::*; @@ -214,7 +214,16 @@ impl InputBackend for LibinputInputBackend { } }, PointerEvent::Button(button_event) => { - + if let Some(ref mut handler) = self.handler { + let device_seat = button_event.device().seat(); + let desc = self.seats.get_mut(&device_seat).expect("Recieved pointer event of non existing Seat"); + handler.on_pointer_button(&desc.seat, button_event.time(), match button_event.button() { + 0x110 => MouseButton::Left, + 0x111 => MouseButton::Right, + 0x112 => MouseButton::Middle, + x => MouseButton::Other(x as u8), + }, button_event.button_state().into()); + } } } }, @@ -244,3 +253,12 @@ impl From<::input::event::pointer::AxisSource> for ::backend::input::AxisSource } } } + +impl From<::input::event::pointer::ButtonState> for ::backend::input::MouseButtonState { + fn from(libinput: ::input::event::pointer::ButtonState) -> Self { + match libinput { + ::input::event::pointer::ButtonState::Pressed => ::backend::input::MouseButtonState::Pressed, + ::input::event::pointer::ButtonState::Released => ::backend::input::MouseButtonState::Released, + } + } +}