Update wayland-rs to 0.30.0
This update rewrites the winit's Wayland backend using new wayland-rs 0.30 API. This fixes long standing issue with the forward compatibility of the wayland backend, meaning that future updates to the wayland protocol won't break rust code anymore. like it was before when adding new shm/enum variants into the protocol. Fixes #2560. Fixes #2164. Fixes #2128. Fixes #1760. Fixes #725.
This commit is contained in:
parent
60e91b187a
commit
2496098890
34 changed files with 3515 additions and 3458 deletions
|
|
@ -1,165 +0,0 @@
|
|||
//! Handling of various keyboard events.
|
||||
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use sctk::reexports::client::protocol::wl_keyboard::KeyState;
|
||||
|
||||
use sctk::seat::keyboard::Event as KeyboardEvent;
|
||||
|
||||
use crate::event::{ElementState, KeyboardInput, ModifiersState, WindowEvent};
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId};
|
||||
|
||||
use super::keymap;
|
||||
use super::KeyboardInner;
|
||||
|
||||
#[inline]
|
||||
pub(super) fn handle_keyboard(
|
||||
event: KeyboardEvent<'_>,
|
||||
inner: &mut KeyboardInner,
|
||||
winit_state: &mut WinitState,
|
||||
) {
|
||||
let event_sink = &mut winit_state.event_sink;
|
||||
match event {
|
||||
KeyboardEvent::Enter { surface, .. } => {
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
window_handle.has_focus.store(true, Ordering::Relaxed);
|
||||
|
||||
// Window gained focus.
|
||||
event_sink.push_window_event(WindowEvent::Focused(true), window_id);
|
||||
|
||||
// Dispatch modifers changes that we've received before getting `Enter` event.
|
||||
if let Some(modifiers) = inner.pending_modifers_state.take() {
|
||||
*inner.modifiers_state.borrow_mut() = modifiers;
|
||||
event_sink.push_window_event(WindowEvent::ModifiersChanged(modifiers), window_id);
|
||||
}
|
||||
|
||||
inner.target_window_id = Some(window_id);
|
||||
}
|
||||
KeyboardEvent::Leave { surface, .. } => {
|
||||
// Reset the id.
|
||||
inner.target_window_id = None;
|
||||
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Notify that no modifiers are being pressed.
|
||||
if !inner.modifiers_state.borrow().is_empty() {
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::ModifiersChanged(ModifiersState::empty()),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
|
||||
window_handle.has_focus.store(false, Ordering::Relaxed);
|
||||
|
||||
// Window lost focus.
|
||||
event_sink.push_window_event(WindowEvent::Focused(false), window_id);
|
||||
}
|
||||
KeyboardEvent::Key {
|
||||
rawkey,
|
||||
keysym,
|
||||
state,
|
||||
utf8,
|
||||
..
|
||||
} => {
|
||||
let window_id = match inner.target_window_id {
|
||||
Some(window_id) => window_id,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let state = match state {
|
||||
KeyState::Pressed => ElementState::Pressed,
|
||||
KeyState::Released => ElementState::Released,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let virtual_keycode = keymap::keysym_to_vkey(keysym);
|
||||
|
||||
event_sink.push_window_event(
|
||||
#[allow(deprecated)]
|
||||
WindowEvent::KeyboardInput {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
input: KeyboardInput {
|
||||
state,
|
||||
scancode: rawkey,
|
||||
virtual_keycode,
|
||||
modifiers: *inner.modifiers_state.borrow(),
|
||||
},
|
||||
is_synthetic: false,
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
|
||||
// Send ReceivedCharacter event only on ElementState::Pressed.
|
||||
if ElementState::Released == state {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(txt) = utf8 {
|
||||
for ch in txt.chars() {
|
||||
event_sink.push_window_event(WindowEvent::ReceivedCharacter(ch), window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyboardEvent::Repeat {
|
||||
rawkey,
|
||||
keysym,
|
||||
utf8,
|
||||
..
|
||||
} => {
|
||||
let window_id = match inner.target_window_id {
|
||||
Some(window_id) => window_id,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let virtual_keycode = keymap::keysym_to_vkey(keysym);
|
||||
|
||||
event_sink.push_window_event(
|
||||
#[allow(deprecated)]
|
||||
WindowEvent::KeyboardInput {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
input: KeyboardInput {
|
||||
state: ElementState::Pressed,
|
||||
scancode: rawkey,
|
||||
virtual_keycode,
|
||||
modifiers: *inner.modifiers_state.borrow(),
|
||||
},
|
||||
is_synthetic: false,
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
|
||||
if let Some(txt) = utf8 {
|
||||
for ch in txt.chars() {
|
||||
event_sink.push_window_event(WindowEvent::ReceivedCharacter(ch), window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyboardEvent::Modifiers { modifiers } => {
|
||||
let modifiers = ModifiersState::from(modifiers);
|
||||
if let Some(window_id) = inner.target_window_id {
|
||||
*inner.modifiers_state.borrow_mut() = modifiers;
|
||||
|
||||
event_sink.push_window_event(WindowEvent::ModifiersChanged(modifiers), window_id);
|
||||
} else {
|
||||
// Compositor must send modifiers after wl_keyboard::enter, however certain
|
||||
// compositors are still sending it before, so stash such events and send
|
||||
// them on wl_keyboard::enter.
|
||||
inner.pending_modifers_state = Some(modifiers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
//! Convert Wayland keys to winit keys.
|
||||
use sctk::seat::keyboard::keysyms;
|
||||
|
||||
use crate::event::VirtualKeyCode;
|
||||
|
||||
/// Convert xkb keysym into winit's VirtualKeyCode.
|
||||
pub fn keysym_to_vkey(keysym: u32) -> Option<VirtualKeyCode> {
|
||||
use sctk::seat::keyboard::keysyms;
|
||||
match keysym {
|
||||
// Numbers.
|
||||
keysyms::XKB_KEY_1 => Some(VirtualKeyCode::Key1),
|
||||
|
|
|
|||
|
|
@ -1,85 +1,235 @@
|
|||
//! Wayland keyboard handling.
|
||||
//! The keyboard input handling.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use sctk::reexports::client::delegate_dispatch;
|
||||
use sctk::reexports::client::protocol::wl_keyboard::WlKeyboard;
|
||||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle};
|
||||
|
||||
use sctk::reexports::calloop::LoopHandle;
|
||||
use sctk::seat::keyboard::{KeyEvent, KeyboardData, KeyboardDataExt, KeyboardHandler, Modifiers};
|
||||
use sctk::seat::SeatState;
|
||||
|
||||
use sctk::seat::keyboard;
|
||||
use crate::event::{ElementState, ModifiersState, WindowEvent};
|
||||
|
||||
use crate::event::ModifiersState;
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::WindowId;
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
|
||||
|
||||
mod handlers;
|
||||
mod keymap;
|
||||
|
||||
pub(crate) struct Keyboard {
|
||||
pub keyboard: WlKeyboard,
|
||||
}
|
||||
impl WinitState {
|
||||
pub fn handle_key_input(
|
||||
&mut self,
|
||||
keyboard: &WlKeyboard,
|
||||
event: KeyEvent,
|
||||
state: ElementState,
|
||||
) {
|
||||
let window_id = match *keyboard.winit_data().window_id.lock().unwrap() {
|
||||
Some(window_id) => window_id,
|
||||
None => return,
|
||||
};
|
||||
|
||||
impl Keyboard {
|
||||
pub fn new(
|
||||
seat: &Attached<WlSeat>,
|
||||
loop_handle: LoopHandle<'static, WinitState>,
|
||||
modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
) -> Option<Self> {
|
||||
let mut inner = KeyboardInner::new(modifiers_state);
|
||||
let keyboard = keyboard::map_keyboard_repeat(
|
||||
loop_handle.clone(),
|
||||
seat,
|
||||
None,
|
||||
keyboard::RepeatKind::System,
|
||||
move |event, _, mut dispatch_data| {
|
||||
let winit_state = dispatch_data.get::<WinitState>().unwrap();
|
||||
handlers::handle_keyboard(event, &mut inner, winit_state);
|
||||
let virtual_keycode = keymap::keysym_to_vkey(event.keysym);
|
||||
|
||||
let seat_state = self.seats.get(&keyboard.seat().id()).unwrap();
|
||||
let modifiers = seat_state.modifiers;
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
#[allow(deprecated)]
|
||||
WindowEvent::KeyboardInput {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
input: crate::event::KeyboardInput {
|
||||
state,
|
||||
scancode: event.raw_code,
|
||||
virtual_keycode,
|
||||
modifiers,
|
||||
},
|
||||
is_synthetic: false,
|
||||
},
|
||||
)
|
||||
.ok()?;
|
||||
window_id,
|
||||
);
|
||||
|
||||
Some(Self { keyboard })
|
||||
}
|
||||
}
|
||||
// Don't send utf8 chars on release.
|
||||
if state == ElementState::Released {
|
||||
return;
|
||||
}
|
||||
|
||||
impl Drop for Keyboard {
|
||||
fn drop(&mut self) {
|
||||
if self.keyboard.as_ref().version() >= 3 {
|
||||
self.keyboard.release();
|
||||
if let Some(txt) = event.utf8 {
|
||||
for ch in txt.chars() {
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::ReceivedCharacter(ch), window_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct KeyboardInner {
|
||||
/// Currently focused surface.
|
||||
target_window_id: Option<WindowId>,
|
||||
impl KeyboardHandler for WinitState {
|
||||
fn enter(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
keyboard: &WlKeyboard,
|
||||
surface: &WlSurface,
|
||||
_serial: u32,
|
||||
_raw: &[u32],
|
||||
_keysyms: &[u32],
|
||||
) {
|
||||
let window_id = wayland::make_wid(surface);
|
||||
|
||||
/// A pending state of modifiers.
|
||||
///
|
||||
/// This state is getting set if we've got a modifiers update
|
||||
/// before `Enter` event, which shouldn't happen in general, however
|
||||
/// some compositors are still doing so.
|
||||
pending_modifers_state: Option<ModifiersState>,
|
||||
// Mark the window as focused.
|
||||
match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().set_has_focus(true),
|
||||
None => return,
|
||||
};
|
||||
|
||||
/// Current state of modifiers keys.
|
||||
modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
// Window gained focus.
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::Focused(true), window_id);
|
||||
|
||||
*keyboard.winit_data().window_id.lock().unwrap() = Some(window_id);
|
||||
|
||||
// NOTE: GNOME still hasn't violates the specification wrt ordering of such
|
||||
// events. See https://gitlab.gnome.org/GNOME/mutter/-/issues/2231.
|
||||
let seat_state = self.seats.get_mut(&keyboard.seat().id()).unwrap();
|
||||
if std::mem::take(&mut seat_state.modifiers_pending) {
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::ModifiersChanged(seat_state.modifiers),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn leave(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
keyboard: &WlKeyboard,
|
||||
surface: &WlSurface,
|
||||
_serial: u32,
|
||||
) {
|
||||
let window_id = wayland::make_wid(surface);
|
||||
|
||||
// XXX The check whether the window exists is essential as we might get a nil surface...
|
||||
match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().set_has_focus(false),
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Notify that no modifiers are being pressed.
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::ModifiersChanged(ModifiersState::empty()),
|
||||
window_id,
|
||||
);
|
||||
|
||||
*keyboard.winit_data().window_id.lock().unwrap() = None;
|
||||
|
||||
// Window lost focus.
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::Focused(false), window_id);
|
||||
}
|
||||
|
||||
fn press_key(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
keyboard: &WlKeyboard,
|
||||
_serial: u32,
|
||||
event: KeyEvent,
|
||||
) {
|
||||
self.handle_key_input(keyboard, event, ElementState::Pressed);
|
||||
}
|
||||
|
||||
fn release_key(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
keyboard: &WlKeyboard,
|
||||
_serial: u32,
|
||||
event: KeyEvent,
|
||||
) {
|
||||
self.handle_key_input(keyboard, event, ElementState::Released);
|
||||
}
|
||||
|
||||
// FIXME(kchibisov): recent spec suggested that this event could be sent
|
||||
// without any focus to indicate modifiers for the pointer, so update
|
||||
// for will be required once https://github.com/rust-windowing/winit/issues/2768
|
||||
// wrt winit design of the event is resolved.
|
||||
fn update_modifiers(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
keyboard: &WlKeyboard,
|
||||
_serial: u32,
|
||||
modifiers: Modifiers,
|
||||
) {
|
||||
let modifiers = ModifiersState::from(modifiers);
|
||||
let mut seat_state = self.seats.get_mut(&keyboard.seat().id()).unwrap();
|
||||
seat_state.modifiers = modifiers;
|
||||
|
||||
// NOTE: part of the workaround from `fn enter`, see it above.
|
||||
let window_id = match *keyboard.winit_data().window_id.lock().unwrap() {
|
||||
Some(window_id) => window_id,
|
||||
None => {
|
||||
seat_state.modifiers_pending = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::ModifiersChanged(modifiers), window_id);
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardInner {
|
||||
fn new(modifiers_state: Rc<RefCell<ModifiersState>>) -> Self {
|
||||
/// The extension to KeyboardData used to store the `window_id`.
|
||||
pub struct WinitKeyboardData {
|
||||
/// The currently focused window surface. Could be `None` on bugged compositors, like mutter.
|
||||
window_id: Mutex<Option<WindowId>>,
|
||||
|
||||
/// The original keyboard date.
|
||||
keyboard_data: KeyboardData<WinitState>,
|
||||
}
|
||||
|
||||
impl WinitKeyboardData {
|
||||
pub fn new(seat: WlSeat) -> Self {
|
||||
Self {
|
||||
target_window_id: None,
|
||||
pending_modifers_state: None,
|
||||
modifiers_state,
|
||||
window_id: Default::default(),
|
||||
keyboard_data: KeyboardData::new(seat),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<keyboard::ModifiersState> for ModifiersState {
|
||||
fn from(mods: keyboard::ModifiersState) -> ModifiersState {
|
||||
impl KeyboardDataExt for WinitKeyboardData {
|
||||
type State = WinitState;
|
||||
|
||||
fn keyboard_data(&self) -> &KeyboardData<Self::State> {
|
||||
&self.keyboard_data
|
||||
}
|
||||
|
||||
fn keyboard_data_mut(&mut self) -> &mut KeyboardData<Self::State> {
|
||||
&mut self.keyboard_data
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WinitKeyboardDataExt {
|
||||
fn winit_data(&self) -> &WinitKeyboardData;
|
||||
|
||||
fn seat(&self) -> &WlSeat {
|
||||
self.winit_data().keyboard_data().seat()
|
||||
}
|
||||
}
|
||||
|
||||
impl WinitKeyboardDataExt for WlKeyboard {
|
||||
fn winit_data(&self) -> &WinitKeyboardData {
|
||||
self.data::<WinitKeyboardData>()
|
||||
.expect("failed to get keyboard data.")
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Modifiers> for ModifiersState {
|
||||
fn from(mods: Modifiers) -> ModifiersState {
|
||||
let mut wl_mods = ModifiersState::empty();
|
||||
wl_mods.set(ModifiersState::SHIFT, mods.shift);
|
||||
wl_mods.set(ModifiersState::CTRL, mods.ctrl);
|
||||
|
|
@ -88,3 +238,5 @@ impl From<keyboard::ModifiersState> for ModifiersState {
|
|||
wl_mods
|
||||
}
|
||||
}
|
||||
|
||||
delegate_dispatch!(WinitState: [ WlKeyboard: WinitKeyboardData] => SeatState);
|
||||
|
|
|
|||
|
|
@ -1,208 +1,234 @@
|
|||
//! Seat handling and managing.
|
||||
//! Seat handling.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use sctk::reexports::protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_pointer_constraints_v1::ZwpPointerConstraintsV1;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3;
|
||||
use fnv::FnvHashMap;
|
||||
|
||||
use sctk::reexports::client::protocol::wl_keyboard::WlKeyboard;
|
||||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::client::protocol::wl_touch::WlTouch;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle};
|
||||
use sctk::reexports::protocols::wp::relative_pointer::zv1::client::zwp_relative_pointer_v1::ZwpRelativePointerV1;
|
||||
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::ZwpTextInputV3;
|
||||
|
||||
use sctk::environment::Environment;
|
||||
use sctk::reexports::calloop::LoopHandle;
|
||||
use sctk::seat::pointer::ThemeManager;
|
||||
use sctk::seat::{SeatData, SeatListener};
|
||||
use sctk::seat::pointer::{ThemeSpec, ThemedPointer};
|
||||
use sctk::seat::{Capability as SeatCapability, SeatHandler, SeatState};
|
||||
|
||||
use super::env::WinitEnv;
|
||||
use super::event_loop::WinitState;
|
||||
use crate::event::ModifiersState;
|
||||
use crate::event::{ElementState, ModifiersState};
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
|
||||
mod keyboard;
|
||||
pub mod pointer;
|
||||
pub mod text_input;
|
||||
mod pointer;
|
||||
mod text_input;
|
||||
mod touch;
|
||||
|
||||
use keyboard::Keyboard;
|
||||
use pointer::Pointers;
|
||||
use text_input::TextInput;
|
||||
use touch::Touch;
|
||||
pub use pointer::relative_pointer::RelativePointerState;
|
||||
pub use pointer::{PointerConstraintsState, WinitPointerData, WinitPointerDataExt};
|
||||
pub use text_input::{TextInputState, ZwpTextInputV3Ext};
|
||||
|
||||
pub struct SeatManager {
|
||||
/// Listener for seats.
|
||||
_seat_listener: SeatListener,
|
||||
use keyboard::WinitKeyboardData;
|
||||
use text_input::TextInputData;
|
||||
use touch::TouchPoint;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WinitSeatState {
|
||||
/// The pointer bound on the seat.
|
||||
pointer: Option<Arc<ThemedPointer<WinitPointerData>>>,
|
||||
|
||||
/// The touch bound on the seat.
|
||||
touch: Option<WlTouch>,
|
||||
|
||||
/// The mapping from touched points to the surfaces they're present.
|
||||
touch_map: FnvHashMap<i32, TouchPoint>,
|
||||
|
||||
/// The text input bound on the seat.
|
||||
text_input: Option<Arc<ZwpTextInputV3>>,
|
||||
|
||||
/// The relative pointer bound on the seat.
|
||||
relative_pointer: Option<ZwpRelativePointerV1>,
|
||||
|
||||
/// The keyboard bound on the seat.
|
||||
keyboard_state: Option<KeyboardState>,
|
||||
|
||||
/// The current modifiers state on the seat.
|
||||
modifiers: ModifiersState,
|
||||
|
||||
/// Wether we have pending modifiers.
|
||||
modifiers_pending: bool,
|
||||
}
|
||||
|
||||
impl SeatManager {
|
||||
pub fn new(
|
||||
env: &Environment<WinitEnv>,
|
||||
loop_handle: LoopHandle<'static, WinitState>,
|
||||
theme_manager: ThemeManager,
|
||||
) -> Self {
|
||||
let relative_pointer_manager = env.get_global::<ZwpRelativePointerManagerV1>();
|
||||
let pointer_constraints = env.get_global::<ZwpPointerConstraintsV1>();
|
||||
let text_input_manager = env.get_global::<ZwpTextInputManagerV3>();
|
||||
|
||||
let mut inner = SeatManagerInner::new(
|
||||
theme_manager,
|
||||
relative_pointer_manager,
|
||||
pointer_constraints,
|
||||
text_input_manager,
|
||||
loop_handle,
|
||||
);
|
||||
|
||||
// Handle existing seats.
|
||||
for seat in env.get_all_seats() {
|
||||
let seat_data = match sctk::seat::clone_seat_data(&seat) {
|
||||
Some(seat_data) => seat_data,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
inner.process_seat_update(&seat, &seat_data);
|
||||
}
|
||||
|
||||
let seat_listener = env.listen_for_seats(move |seat, seat_data, _| {
|
||||
inner.process_seat_update(&seat, seat_data);
|
||||
});
|
||||
|
||||
impl WinitSeatState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
_seat_listener: seat_listener,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inner state of the seat manager.
|
||||
struct SeatManagerInner {
|
||||
/// Currently observed seats.
|
||||
seats: Vec<SeatInfo>,
|
||||
|
||||
/// Loop handle.
|
||||
loop_handle: LoopHandle<'static, WinitState>,
|
||||
|
||||
/// Relative pointer manager.
|
||||
relative_pointer_manager: Option<Attached<ZwpRelativePointerManagerV1>>,
|
||||
|
||||
/// Pointer constraints.
|
||||
pointer_constraints: Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
|
||||
/// Text input manager.
|
||||
text_input_manager: Option<Attached<ZwpTextInputManagerV3>>,
|
||||
|
||||
/// A theme manager.
|
||||
theme_manager: ThemeManager,
|
||||
}
|
||||
|
||||
impl SeatManagerInner {
|
||||
fn new(
|
||||
theme_manager: ThemeManager,
|
||||
relative_pointer_manager: Option<Attached<ZwpRelativePointerManagerV1>>,
|
||||
pointer_constraints: Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
text_input_manager: Option<Attached<ZwpTextInputManagerV3>>,
|
||||
loop_handle: LoopHandle<'static, WinitState>,
|
||||
) -> Self {
|
||||
Self {
|
||||
seats: Vec::new(),
|
||||
loop_handle,
|
||||
relative_pointer_manager,
|
||||
pointer_constraints,
|
||||
text_input_manager,
|
||||
theme_manager,
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle seats update from the `SeatListener`.
|
||||
pub fn process_seat_update(&mut self, seat: &Attached<WlSeat>, seat_data: &SeatData) {
|
||||
let detached_seat = seat.detach();
|
||||
|
||||
let position = self.seats.iter().position(|si| si.seat == detached_seat);
|
||||
let index = position.unwrap_or_else(|| {
|
||||
self.seats.push(SeatInfo::new(detached_seat));
|
||||
self.seats.len() - 1
|
||||
});
|
||||
|
||||
let seat_info = &mut self.seats[index];
|
||||
|
||||
// Pointer handling.
|
||||
if seat_data.has_pointer && !seat_data.defunct {
|
||||
if seat_info.pointer.is_none() {
|
||||
seat_info.pointer = Some(Pointers::new(
|
||||
seat,
|
||||
&self.theme_manager,
|
||||
&self.relative_pointer_manager,
|
||||
&self.pointer_constraints,
|
||||
seat_info.modifiers_state.clone(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
seat_info.pointer = None;
|
||||
}
|
||||
|
||||
// Handle keyboard.
|
||||
if seat_data.has_keyboard && !seat_data.defunct {
|
||||
if seat_info.keyboard.is_none() {
|
||||
seat_info.keyboard = Keyboard::new(
|
||||
seat,
|
||||
self.loop_handle.clone(),
|
||||
seat_info.modifiers_state.clone(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
seat_info.keyboard = None;
|
||||
}
|
||||
|
||||
// Handle touch.
|
||||
if seat_data.has_touch && !seat_data.defunct {
|
||||
if seat_info.touch.is_none() {
|
||||
seat_info.touch = Some(Touch::new(seat));
|
||||
}
|
||||
} else {
|
||||
seat_info.touch = None;
|
||||
}
|
||||
|
||||
// Handle text input.
|
||||
if let Some(text_input_manager) = self.text_input_manager.as_ref() {
|
||||
if seat_data.defunct {
|
||||
seat_info.text_input = None;
|
||||
} else if seat_info.text_input.is_none() {
|
||||
seat_info.text_input = Some(TextInput::new(seat, text_input_manager));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Resources associtated with a given seat.
|
||||
struct SeatInfo {
|
||||
/// Seat to which this `SeatInfo` belongs.
|
||||
seat: WlSeat,
|
||||
|
||||
/// A keyboard handle with its repeat rate handling.
|
||||
keyboard: Option<Keyboard>,
|
||||
|
||||
/// All pointers we're using on a seat.
|
||||
pointer: Option<Pointers>,
|
||||
|
||||
/// Touch handling.
|
||||
touch: Option<Touch>,
|
||||
|
||||
/// Text input handling aka IME.
|
||||
text_input: Option<TextInput>,
|
||||
|
||||
/// The current state of modifiers observed in keyboard handler.
|
||||
///
|
||||
/// We keep modifiers state on a seat, since it's being used by pointer events as well.
|
||||
modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
}
|
||||
|
||||
impl SeatInfo {
|
||||
pub fn new(seat: WlSeat) -> Self {
|
||||
Self {
|
||||
seat,
|
||||
keyboard: None,
|
||||
pointer: None,
|
||||
touch: None,
|
||||
relative_pointer: None,
|
||||
text_input: None,
|
||||
modifiers_state: Rc::new(RefCell::new(ModifiersState::default())),
|
||||
touch_map: Default::default(),
|
||||
keyboard_state: None,
|
||||
modifiers: ModifiersState::empty(),
|
||||
modifiers_pending: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SeatHandler for WinitState {
|
||||
fn seat_state(&mut self) -> &mut SeatState {
|
||||
&mut self.seat_state
|
||||
}
|
||||
|
||||
fn new_capability(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
queue_handle: &QueueHandle<Self>,
|
||||
seat: WlSeat,
|
||||
capability: SeatCapability,
|
||||
) {
|
||||
let seat_state = self.seats.get_mut(&seat.id()).unwrap();
|
||||
|
||||
match capability {
|
||||
SeatCapability::Touch if seat_state.touch.is_none() => {
|
||||
seat_state.touch = self.seat_state.get_touch(queue_handle, &seat).ok();
|
||||
}
|
||||
SeatCapability::Keyboard if seat_state.keyboard_state.is_none() => {
|
||||
let keyboard = self
|
||||
.seat_state
|
||||
.get_keyboard_with_repeat_with_data(
|
||||
queue_handle,
|
||||
&seat,
|
||||
WinitKeyboardData::new(seat.clone()),
|
||||
self.loop_handle.clone(),
|
||||
Box::new(|state, keyboard, event| {
|
||||
state.handle_key_input(keyboard, event, ElementState::Pressed);
|
||||
}),
|
||||
)
|
||||
.expect("failed to create keyboard with present capability.");
|
||||
|
||||
seat_state.keyboard_state = Some(KeyboardState { keyboard });
|
||||
}
|
||||
SeatCapability::Pointer if seat_state.pointer.is_none() => {
|
||||
let surface = self.compositor_state.create_surface(queue_handle);
|
||||
let surface_id = surface.id();
|
||||
let pointer_data = WinitPointerData::new(seat.clone(), surface);
|
||||
let themed_pointer = self
|
||||
.seat_state
|
||||
.get_pointer_with_theme_and_data(
|
||||
queue_handle,
|
||||
&seat,
|
||||
ThemeSpec::System,
|
||||
pointer_data,
|
||||
)
|
||||
.expect("failed to create pointer with present capability.");
|
||||
|
||||
seat_state.relative_pointer = self.relative_pointer.as_ref().map(|manager| {
|
||||
manager.get_relative_pointer(
|
||||
themed_pointer.pointer(),
|
||||
queue_handle,
|
||||
sctk::globals::GlobalData,
|
||||
)
|
||||
});
|
||||
|
||||
let themed_pointer = Arc::new(themed_pointer);
|
||||
|
||||
// Register cursor surface.
|
||||
self.pointer_surfaces
|
||||
.insert(surface_id, themed_pointer.clone());
|
||||
|
||||
seat_state.pointer = Some(themed_pointer);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if let Some(text_input_state) = seat_state
|
||||
.text_input
|
||||
.is_none()
|
||||
.then_some(self.text_input_state.as_ref())
|
||||
.flatten()
|
||||
{
|
||||
seat_state.text_input = Some(Arc::new(text_input_state.get_text_input(
|
||||
&seat,
|
||||
queue_handle,
|
||||
TextInputData::default(),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_capability(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_queue_handle: &QueueHandle<Self>,
|
||||
seat: WlSeat,
|
||||
capability: SeatCapability,
|
||||
) {
|
||||
let seat_state = self.seats.get_mut(&seat.id()).unwrap();
|
||||
|
||||
match capability {
|
||||
SeatCapability::Touch => {
|
||||
if let Some(touch) = seat_state.touch.take() {
|
||||
if touch.version() >= 3 {
|
||||
touch.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
SeatCapability::Pointer => {
|
||||
if let Some(relative_pointer) = seat_state.relative_pointer.take() {
|
||||
relative_pointer.destroy();
|
||||
}
|
||||
|
||||
if let Some(pointer) = seat_state.pointer.take() {
|
||||
let pointer_data = pointer.pointer().winit_data();
|
||||
|
||||
// Remove the cursor from the mapping.
|
||||
let surface_id = pointer_data.cursor_surface().id();
|
||||
let _ = self.pointer_surfaces.remove(&surface_id);
|
||||
|
||||
// Remove the inner locks/confines before dropping the pointer.
|
||||
pointer_data.unlock_pointer();
|
||||
pointer_data.unconfine_pointer();
|
||||
|
||||
if pointer.pointer().version() >= 3 {
|
||||
pointer.pointer().release();
|
||||
}
|
||||
}
|
||||
}
|
||||
SeatCapability::Keyboard => {
|
||||
if let Some(keyboard_state) = seat_state.keyboard_state.take() {
|
||||
if keyboard_state.keyboard.version() >= 3 {
|
||||
keyboard_state.keyboard.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if let Some(text_input) = seat_state.text_input.take() {
|
||||
text_input.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
fn new_seat(
|
||||
&mut self,
|
||||
_connection: &Connection,
|
||||
_queue_handle: &QueueHandle<Self>,
|
||||
seat: WlSeat,
|
||||
) {
|
||||
self.seats.insert(seat.id(), WinitSeatState::new());
|
||||
}
|
||||
|
||||
fn remove_seat(
|
||||
&mut self,
|
||||
_connection: &Connection,
|
||||
_queue_handle: &QueueHandle<Self>,
|
||||
seat: WlSeat,
|
||||
) {
|
||||
let _ = self.seats.remove(&seat.id());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KeyboardState {
|
||||
/// The underlying WlKeyboard.
|
||||
pub keyboard: WlKeyboard,
|
||||
}
|
||||
|
||||
sctk::delegate_seat!(WinitState);
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
//! Data which is used in pointer callbacks.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_pointer_constraints_v1::ZwpPointerConstraintsV1;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
|
||||
|
||||
use crate::event::{ModifiersState, TouchPhase};
|
||||
|
||||
/// A data being used by pointer handlers.
|
||||
pub(super) struct PointerData {
|
||||
/// Winit's surface the pointer is currently over.
|
||||
pub surface: Option<WlSurface>,
|
||||
|
||||
/// Current modifiers state.
|
||||
///
|
||||
/// This refers a state of modifiers from `WlKeyboard` on
|
||||
/// the given seat.
|
||||
pub modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
|
||||
/// Pointer constraints.
|
||||
pub pointer_constraints: Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
|
||||
pub confined_pointer: Rc<RefCell<Option<ZwpConfinedPointerV1>>>,
|
||||
pub locked_pointer: Rc<RefCell<Option<ZwpLockedPointerV1>>>,
|
||||
|
||||
/// Latest observed serial in pointer events.
|
||||
pub latest_serial: Rc<Cell<u32>>,
|
||||
|
||||
/// Latest observed serial in pointer enter events.
|
||||
pub latest_enter_serial: Rc<Cell<u32>>,
|
||||
|
||||
/// The currently accumulated axis data on a pointer.
|
||||
pub axis_data: AxisData,
|
||||
}
|
||||
|
||||
impl PointerData {
|
||||
pub fn new(
|
||||
confined_pointer: Rc<RefCell<Option<ZwpConfinedPointerV1>>>,
|
||||
locked_pointer: Rc<RefCell<Option<ZwpLockedPointerV1>>>,
|
||||
pointer_constraints: Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
surface: None,
|
||||
latest_serial: Rc::new(Cell::new(0)),
|
||||
latest_enter_serial: Rc::new(Cell::new(0)),
|
||||
confined_pointer,
|
||||
locked_pointer,
|
||||
modifiers_state,
|
||||
pointer_constraints,
|
||||
axis_data: AxisData::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Axis data.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct AxisData {
|
||||
/// Current state of the axis.
|
||||
pub axis_state: TouchPhase,
|
||||
|
||||
/// A buffer for `PixelDelta` event.
|
||||
pub axis_buffer: Option<(f32, f32)>,
|
||||
|
||||
/// A buffer for `LineDelta` event.
|
||||
pub axis_discrete_buffer: Option<(f32, f32)>,
|
||||
}
|
||||
|
||||
impl AxisData {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
axis_state: TouchPhase::Ended,
|
||||
axis_buffer: None,
|
||||
axis_discrete_buffer: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
//! Handlers for the pointers we're using.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use sctk::reexports::client::protocol::wl_pointer::{self, Event as PointerEvent};
|
||||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_v1::Event as RelativePointerEvent;
|
||||
|
||||
use sctk::seat::pointer::ThemedPointer;
|
||||
|
||||
use crate::dpi::LogicalPosition;
|
||||
use crate::event::{
|
||||
DeviceEvent, ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent,
|
||||
};
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId};
|
||||
|
||||
use super::{PointerData, WinitPointer};
|
||||
|
||||
// These values are comming from <linux/input-event-codes.h>.
|
||||
const BTN_LEFT: u32 = 0x110;
|
||||
const BTN_RIGHT: u32 = 0x111;
|
||||
const BTN_MIDDLE: u32 = 0x112;
|
||||
|
||||
#[inline]
|
||||
pub(super) fn handle_pointer(
|
||||
pointer: ThemedPointer,
|
||||
event: PointerEvent,
|
||||
pointer_data: &Rc<RefCell<PointerData>>,
|
||||
winit_state: &mut WinitState,
|
||||
seat: WlSeat,
|
||||
) {
|
||||
let event_sink = &mut winit_state.event_sink;
|
||||
let mut pointer_data = pointer_data.borrow_mut();
|
||||
match event {
|
||||
PointerEvent::Enter {
|
||||
surface,
|
||||
surface_x,
|
||||
surface_y,
|
||||
serial,
|
||||
..
|
||||
} => {
|
||||
pointer_data.latest_serial.replace(serial);
|
||||
pointer_data.latest_enter_serial.replace(serial);
|
||||
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
pointer_data.surface = Some(surface);
|
||||
|
||||
// Notify window that pointer entered the surface.
|
||||
let winit_pointer = WinitPointer {
|
||||
pointer,
|
||||
confined_pointer: Rc::downgrade(&pointer_data.confined_pointer),
|
||||
locked_pointer: Rc::downgrade(&pointer_data.locked_pointer),
|
||||
pointer_constraints: pointer_data.pointer_constraints.clone(),
|
||||
latest_serial: pointer_data.latest_serial.clone(),
|
||||
latest_enter_serial: pointer_data.latest_enter_serial.clone(),
|
||||
seat,
|
||||
};
|
||||
window_handle.pointer_entered(winit_pointer);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::CursorEntered {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
|
||||
let position = LogicalPosition::new(surface_x, surface_y).to_physical(scale_factor);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::CursorMoved {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
position,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEvent::Leave { surface, serial } => {
|
||||
pointer_data.surface = None;
|
||||
pointer_data.latest_serial.replace(serial);
|
||||
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Notify a window that pointer is no longer observing it.
|
||||
let winit_pointer = WinitPointer {
|
||||
pointer,
|
||||
confined_pointer: Rc::downgrade(&pointer_data.confined_pointer),
|
||||
locked_pointer: Rc::downgrade(&pointer_data.locked_pointer),
|
||||
pointer_constraints: pointer_data.pointer_constraints.clone(),
|
||||
latest_serial: pointer_data.latest_serial.clone(),
|
||||
latest_enter_serial: pointer_data.latest_enter_serial.clone(),
|
||||
seat,
|
||||
};
|
||||
window_handle.pointer_left(winit_pointer);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::CursorLeft {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEvent::Motion {
|
||||
surface_x,
|
||||
surface_y,
|
||||
..
|
||||
} => {
|
||||
let surface = match pointer_data.surface.as_ref() {
|
||||
Some(surface) => surface,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let window_id = wayland::make_wid(surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let position = LogicalPosition::new(surface_x, surface_y).to_physical(scale_factor);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::CursorMoved {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
position,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEvent::Button {
|
||||
button,
|
||||
state,
|
||||
serial,
|
||||
..
|
||||
} => {
|
||||
pointer_data.latest_serial.replace(serial);
|
||||
let window_id = match pointer_data.surface.as_ref().map(wayland::make_wid) {
|
||||
Some(window_id) => window_id,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let state = match state {
|
||||
wl_pointer::ButtonState::Pressed => ElementState::Pressed,
|
||||
wl_pointer::ButtonState::Released => ElementState::Released,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let button = match button {
|
||||
BTN_LEFT => MouseButton::Left,
|
||||
BTN_RIGHT => MouseButton::Right,
|
||||
BTN_MIDDLE => MouseButton::Middle,
|
||||
button => MouseButton::Other(button as u16),
|
||||
};
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::MouseInput {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
state,
|
||||
button,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEvent::Axis { axis, value, .. } => {
|
||||
let surface = match pointer_data.surface.as_ref() {
|
||||
Some(surface) => surface,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let window_id = wayland::make_wid(surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if pointer.as_ref().version() < 5 {
|
||||
let (mut x, mut y) = (0.0, 0.0);
|
||||
|
||||
// Old seat compatibility.
|
||||
match axis {
|
||||
// Wayland sign convention is the inverse of winit.
|
||||
wl_pointer::Axis::VerticalScroll => y -= value as f32,
|
||||
wl_pointer::Axis::HorizontalScroll => x -= value as f32,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let delta = LogicalPosition::new(x as f64, y as f64).to_physical(scale_factor);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::MouseWheel {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
delta: MouseScrollDelta::PixelDelta(delta),
|
||||
phase: TouchPhase::Moved,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
} else {
|
||||
let (mut x, mut y) = pointer_data.axis_data.axis_buffer.unwrap_or((0.0, 0.0));
|
||||
match axis {
|
||||
// Wayland sign convention is the inverse of winit.
|
||||
wl_pointer::Axis::VerticalScroll => y -= value as f32,
|
||||
wl_pointer::Axis::HorizontalScroll => x -= value as f32,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
pointer_data.axis_data.axis_buffer = Some((x, y));
|
||||
|
||||
pointer_data.axis_data.axis_state = match pointer_data.axis_data.axis_state {
|
||||
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
|
||||
_ => TouchPhase::Started,
|
||||
}
|
||||
}
|
||||
}
|
||||
PointerEvent::AxisDiscrete { axis, discrete } => {
|
||||
let (mut x, mut y) = pointer_data
|
||||
.axis_data
|
||||
.axis_discrete_buffer
|
||||
.unwrap_or((0., 0.));
|
||||
|
||||
match axis {
|
||||
// Wayland sign convention is the inverse of winit.
|
||||
wl_pointer::Axis::VerticalScroll => y -= discrete as f32,
|
||||
wl_pointer::Axis::HorizontalScroll => x -= discrete as f32,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
pointer_data.axis_data.axis_discrete_buffer = Some((x, y));
|
||||
|
||||
pointer_data.axis_data.axis_state = match pointer_data.axis_data.axis_state {
|
||||
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
|
||||
_ => TouchPhase::Started,
|
||||
}
|
||||
}
|
||||
PointerEvent::AxisSource { .. } => (),
|
||||
PointerEvent::AxisStop { .. } => {
|
||||
pointer_data.axis_data.axis_state = TouchPhase::Ended;
|
||||
}
|
||||
PointerEvent::Frame => {
|
||||
let axis_buffer = pointer_data.axis_data.axis_buffer.take();
|
||||
let axis_discrete_buffer = pointer_data.axis_data.axis_discrete_buffer.take();
|
||||
|
||||
let surface = match pointer_data.surface.as_ref() {
|
||||
Some(surface) => surface,
|
||||
None => return,
|
||||
};
|
||||
let window_id = wayland::make_wid(surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let window_event = if let Some((x, y)) = axis_discrete_buffer {
|
||||
WindowEvent::MouseWheel {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
delta: MouseScrollDelta::LineDelta(x, y),
|
||||
phase: pointer_data.axis_data.axis_state,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
}
|
||||
} else if let Some((x, y)) = axis_buffer {
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let delta = LogicalPosition::new(x, y).to_physical(scale_factor);
|
||||
|
||||
WindowEvent::MouseWheel {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
delta: MouseScrollDelta::PixelDelta(delta),
|
||||
phase: pointer_data.axis_data.axis_state,
|
||||
modifiers: *pointer_data.modifiers_state.borrow(),
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
event_sink.push_window_event(window_event, window_id);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(super) fn handle_relative_pointer(event: RelativePointerEvent, winit_state: &mut WinitState) {
|
||||
if let RelativePointerEvent::RelativeMotion {
|
||||
dx_unaccel,
|
||||
dy_unaccel,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
winit_state.event_sink.push_device_event(
|
||||
DeviceEvent::MouseMotion {
|
||||
delta: (dx_unaccel, dy_unaccel),
|
||||
},
|
||||
DeviceId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,343 +1,491 @@
|
|||
//! All pointer related handling.
|
||||
//! The pointer events.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use sctk::reexports::client::delegate_dispatch;
|
||||
use sctk::reexports::client::protocol::wl_pointer::WlPointer;
|
||||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1;
|
||||
use sctk::reexports::protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_v1::ZwpRelativePointerV1;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_pointer_constraints_v1::{ZwpPointerConstraintsV1, Lifetime};
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
|
||||
use sctk::reexports::protocols::unstable::pointer_constraints::v1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle, Dispatch};
|
||||
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_confined_pointer_v1::ZwpConfinedPointerV1;
|
||||
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1;
|
||||
use sctk::reexports::protocols::wp::pointer_constraints::zv1::client::zwp_pointer_constraints_v1::{Lifetime, ZwpPointerConstraintsV1};
|
||||
use sctk::reexports::client::globals::{BindError, GlobalList};
|
||||
|
||||
use sctk::seat::pointer::{ThemeManager, ThemedPointer};
|
||||
use sctk::window::Window;
|
||||
use sctk::compositor::SurfaceData;
|
||||
use sctk::globals::GlobalData;
|
||||
use sctk::seat::pointer::{PointerData, PointerDataExt};
|
||||
use sctk::seat::pointer::{PointerEvent, PointerEventKind, PointerHandler};
|
||||
use sctk::seat::SeatState;
|
||||
use sctk::shell::xdg::frame::FrameClick;
|
||||
|
||||
use crate::event::ModifiersState;
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::window::WinitFrame;
|
||||
use crate::window::CursorIcon;
|
||||
use crate::dpi::{LogicalPosition, PhysicalPosition};
|
||||
use crate::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent};
|
||||
|
||||
mod data;
|
||||
mod handlers;
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId, WindowId};
|
||||
|
||||
use data::PointerData;
|
||||
pub mod relative_pointer;
|
||||
|
||||
/// A proxy to Wayland pointer, which serves requests from a `WindowHandle`.
|
||||
pub struct WinitPointer {
|
||||
pointer: ThemedPointer,
|
||||
impl PointerHandler for WinitState {
|
||||
fn pointer_frame(
|
||||
&mut self,
|
||||
connection: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
pointer: &WlPointer,
|
||||
events: &[PointerEvent],
|
||||
) {
|
||||
let seat = pointer.winit_data().seat();
|
||||
let seat_state = self.seats.get(&seat.id()).unwrap();
|
||||
let modifiers = seat_state.modifiers;
|
||||
|
||||
/// Create confined pointers.
|
||||
pointer_constraints: Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId));
|
||||
|
||||
/// Cursor to handle confine requests.
|
||||
confined_pointer: Weak<RefCell<Option<ZwpConfinedPointerV1>>>,
|
||||
for event in events {
|
||||
let surface = &event.surface;
|
||||
|
||||
/// Cursor to handle locked requests.
|
||||
locked_pointer: Weak<RefCell<Option<ZwpLockedPointerV1>>>,
|
||||
// The parent surface.
|
||||
let parent_surface = match event.surface.data::<SurfaceData>() {
|
||||
Some(data) => data.parent_surface().unwrap_or(surface),
|
||||
None => continue,
|
||||
};
|
||||
|
||||
/// Latest observed serial in pointer events.
|
||||
/// used by Window::start_interactive_move()
|
||||
latest_serial: Rc<Cell<u32>>,
|
||||
let window_id = wayland::make_wid(parent_surface);
|
||||
|
||||
/// Latest observed serial in pointer enter events.
|
||||
/// used by Window::set_cursor()
|
||||
latest_enter_serial: Rc<Cell<u32>>,
|
||||
// Ensure that window exists.
|
||||
let mut window = match self.windows.get_mut().get_mut(&window_id) {
|
||||
Some(window) => window.lock().unwrap(),
|
||||
None => continue,
|
||||
};
|
||||
|
||||
/// Seat.
|
||||
seat: WlSeat,
|
||||
}
|
||||
let scale_factor = window.scale_factor();
|
||||
let position: PhysicalPosition<f64> =
|
||||
LogicalPosition::new(event.position.0, event.position.1).to_physical(scale_factor);
|
||||
|
||||
impl PartialEq for WinitPointer {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
*self.pointer == *other.pointer
|
||||
}
|
||||
}
|
||||
match event.kind {
|
||||
// Pointer movements on decorations.
|
||||
PointerEventKind::Enter { .. } | PointerEventKind::Motion { .. }
|
||||
if parent_surface != surface =>
|
||||
{
|
||||
if let Some(icon) =
|
||||
window.frame_point_moved(surface, event.position.0, event.position.1)
|
||||
{
|
||||
if let Some(pointer) = seat_state.pointer.as_ref() {
|
||||
let surface = pointer
|
||||
.pointer()
|
||||
.data::<WinitPointerData>()
|
||||
.unwrap()
|
||||
.cursor_surface();
|
||||
let scale_factor =
|
||||
surface.data::<SurfaceData>().unwrap().scale_factor();
|
||||
|
||||
impl Eq for WinitPointer {}
|
||||
let _ = pointer.set_cursor(
|
||||
connection,
|
||||
icon,
|
||||
self.shm.wl_shm(),
|
||||
surface,
|
||||
scale_factor,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
PointerEventKind::Leave { .. } if parent_surface != surface => {
|
||||
window.frame_point_left();
|
||||
}
|
||||
ref kind @ PointerEventKind::Press { button, serial, .. }
|
||||
| ref kind @ PointerEventKind::Release { button, serial, .. }
|
||||
if parent_surface != surface =>
|
||||
{
|
||||
let click = match wayland_button_to_winit(button) {
|
||||
MouseButton::Left => FrameClick::Normal,
|
||||
MouseButton::Right => FrameClick::Alternate,
|
||||
_ => continue,
|
||||
};
|
||||
let pressed = matches!(kind, PointerEventKind::Press { .. });
|
||||
|
||||
impl WinitPointer {
|
||||
/// Set the cursor icon.
|
||||
///
|
||||
/// Providing `None` will hide the cursor.
|
||||
pub fn set_cursor(&self, cursor_icon: Option<CursorIcon>) {
|
||||
let cursor_icon = match cursor_icon {
|
||||
Some(cursor_icon) => cursor_icon,
|
||||
None => {
|
||||
// Hide the cursor.
|
||||
// WlPointer::set_cursor() expects the serial of the last *enter*
|
||||
// event (compare to to start_interactive_move()).
|
||||
(*self.pointer).set_cursor(self.latest_enter_serial.get(), None, 0, 0);
|
||||
return;
|
||||
}
|
||||
};
|
||||
// Emulate click on the frame.
|
||||
window.frame_click(
|
||||
click,
|
||||
pressed,
|
||||
seat,
|
||||
serial,
|
||||
window_id,
|
||||
&mut self.window_compositor_updates,
|
||||
);
|
||||
}
|
||||
// Regular events on the main surface.
|
||||
PointerEventKind::Enter { .. } => {
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::CursorEntered { device_id }, window_id);
|
||||
|
||||
let cursors: &[&str] = match cursor_icon {
|
||||
CursorIcon::Alias => &["link"],
|
||||
CursorIcon::Arrow => &["arrow"],
|
||||
CursorIcon::Cell => &["plus"],
|
||||
CursorIcon::Copy => &["copy"],
|
||||
CursorIcon::Crosshair => &["crosshair"],
|
||||
CursorIcon::Default => &["left_ptr"],
|
||||
CursorIcon::Hand => &["hand2", "hand1"],
|
||||
CursorIcon::Help => &["question_arrow"],
|
||||
CursorIcon::Move => &["move"],
|
||||
CursorIcon::Grab => &["openhand", "grab"],
|
||||
CursorIcon::Grabbing => &["closedhand", "grabbing"],
|
||||
CursorIcon::Progress => &["progress"],
|
||||
CursorIcon::AllScroll => &["all-scroll"],
|
||||
CursorIcon::ContextMenu => &["context-menu"],
|
||||
if let Some(pointer) = seat_state.pointer.as_ref().map(Arc::downgrade) {
|
||||
window.pointer_entered(pointer);
|
||||
}
|
||||
|
||||
CursorIcon::NoDrop => &["no-drop", "circle"],
|
||||
CursorIcon::NotAllowed => &["crossed_circle"],
|
||||
// Set the currently focused surface.
|
||||
pointer.winit_data().inner.lock().unwrap().surface = Some(window_id);
|
||||
|
||||
// Resize cursors
|
||||
CursorIcon::EResize => &["right_side"],
|
||||
CursorIcon::NResize => &["top_side"],
|
||||
CursorIcon::NeResize => &["top_right_corner"],
|
||||
CursorIcon::NwResize => &["top_left_corner"],
|
||||
CursorIcon::SResize => &["bottom_side"],
|
||||
CursorIcon::SeResize => &["bottom_right_corner"],
|
||||
CursorIcon::SwResize => &["bottom_left_corner"],
|
||||
CursorIcon::WResize => &["left_side"],
|
||||
CursorIcon::EwResize => &["h_double_arrow"],
|
||||
CursorIcon::NsResize => &["v_double_arrow"],
|
||||
CursorIcon::NwseResize => &["bd_double_arrow", "size_fdiag"],
|
||||
CursorIcon::NeswResize => &["fd_double_arrow", "size_bdiag"],
|
||||
CursorIcon::ColResize => &["split_h", "h_double_arrow"],
|
||||
CursorIcon::RowResize => &["split_v", "v_double_arrow"],
|
||||
CursorIcon::Text => &["text", "xterm"],
|
||||
CursorIcon::VerticalText => &["vertical-text"],
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::CursorMoved {
|
||||
device_id,
|
||||
position,
|
||||
modifiers,
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEventKind::Leave { .. } => {
|
||||
if let Some(pointer) = seat_state.pointer.as_ref().map(Arc::downgrade) {
|
||||
window.pointer_left(pointer);
|
||||
}
|
||||
|
||||
CursorIcon::Wait => &["watch"],
|
||||
// Remove the active surface.
|
||||
pointer.winit_data().inner.lock().unwrap().surface = None;
|
||||
|
||||
CursorIcon::ZoomIn => &["zoom-in"],
|
||||
CursorIcon::ZoomOut => &["zoom-out"],
|
||||
};
|
||||
self.events_sink
|
||||
.push_window_event(WindowEvent::CursorLeft { device_id }, window_id);
|
||||
}
|
||||
PointerEventKind::Motion { .. } => {
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::CursorMoved {
|
||||
device_id,
|
||||
position,
|
||||
modifiers,
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
ref kind @ PointerEventKind::Press { button, serial, .. }
|
||||
| ref kind @ PointerEventKind::Release { button, serial, .. } => {
|
||||
// Update the last button serial.
|
||||
pointer
|
||||
.winit_data()
|
||||
.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.latest_button_serial = serial;
|
||||
|
||||
let serial = Some(self.latest_enter_serial.get());
|
||||
for cursor in cursors {
|
||||
if self.pointer.set_cursor(cursor, serial).is_ok() {
|
||||
return;
|
||||
let button = wayland_button_to_winit(button);
|
||||
let state = if matches!(kind, PointerEventKind::Press { .. }) {
|
||||
ElementState::Pressed
|
||||
} else {
|
||||
ElementState::Released
|
||||
};
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::MouseInput {
|
||||
device_id,
|
||||
state,
|
||||
button,
|
||||
modifiers,
|
||||
},
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
PointerEventKind::Axis {
|
||||
horizontal,
|
||||
vertical,
|
||||
..
|
||||
} => {
|
||||
// Get the current phase.
|
||||
let mut pointer_data = pointer.winit_data().inner.lock().unwrap();
|
||||
|
||||
let has_discrete_scroll = horizontal.discrete != 0 || vertical.discrete != 0;
|
||||
|
||||
// Figure out what to do about start/ended phases here.
|
||||
//
|
||||
// Figure out how to deal with `Started`. Also the `Ended` is not guaranteed
|
||||
// to be sent for mouse wheels.
|
||||
let phase = if horizontal.stop || vertical.stop {
|
||||
TouchPhase::Ended
|
||||
} else {
|
||||
match pointer_data.phase {
|
||||
// Descrete scroll only results in moved events.
|
||||
_ if has_discrete_scroll => TouchPhase::Moved,
|
||||
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
|
||||
_ => TouchPhase::Started,
|
||||
}
|
||||
};
|
||||
|
||||
// Update the phase.
|
||||
pointer_data.phase = phase;
|
||||
|
||||
// Mice events have both pixel and discrete delta's at the same time. So prefer
|
||||
// the descrite values if they are present.
|
||||
let delta = if has_discrete_scroll {
|
||||
// XXX Wayland sign convention is the inverse of winit.
|
||||
MouseScrollDelta::LineDelta(
|
||||
(-horizontal.discrete) as f32,
|
||||
(-vertical.discrete) as f32,
|
||||
)
|
||||
} else {
|
||||
// XXX Wayland sign convention is the inverse of winit.
|
||||
MouseScrollDelta::PixelDelta(
|
||||
LogicalPosition::new(-horizontal.absolute, -vertical.absolute)
|
||||
.to_physical(scale_factor),
|
||||
)
|
||||
};
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::MouseWheel {
|
||||
device_id,
|
||||
delta,
|
||||
phase,
|
||||
modifiers,
|
||||
},
|
||||
window_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
warn!("Failed to set cursor to {:?}", cursor_icon);
|
||||
}
|
||||
|
||||
/// Confine the pointer to a surface.
|
||||
pub fn confine(&self, surface: &WlSurface) {
|
||||
let pointer_constraints = match &self.pointer_constraints {
|
||||
Some(pointer_constraints) => pointer_constraints,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let confined_pointer = match self.confined_pointer.upgrade() {
|
||||
Some(confined_pointer) => confined_pointer,
|
||||
// A pointer is gone.
|
||||
None => return,
|
||||
};
|
||||
|
||||
*confined_pointer.borrow_mut() = Some(init_confined_pointer(
|
||||
pointer_constraints,
|
||||
surface,
|
||||
&self.pointer,
|
||||
));
|
||||
}
|
||||
|
||||
/// Tries to unconfine the pointer if the current pointer is confined.
|
||||
pub fn unconfine(&self) {
|
||||
let confined_pointer = match self.confined_pointer.upgrade() {
|
||||
Some(confined_pointer) => confined_pointer,
|
||||
// A pointer is gone.
|
||||
None => return,
|
||||
};
|
||||
|
||||
let mut confined_pointer = confined_pointer.borrow_mut();
|
||||
|
||||
if let Some(confined_pointer) = confined_pointer.take() {
|
||||
confined_pointer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lock(&self, surface: &WlSurface) {
|
||||
let pointer_constraints = match &self.pointer_constraints {
|
||||
Some(pointer_constraints) => pointer_constraints,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let locked_pointer = match self.locked_pointer.upgrade() {
|
||||
Some(locked_pointer) => locked_pointer,
|
||||
// A pointer is gone.
|
||||
None => return,
|
||||
};
|
||||
|
||||
*locked_pointer.borrow_mut() = Some(init_locked_pointer(
|
||||
pointer_constraints,
|
||||
surface,
|
||||
&self.pointer,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn unlock(&self) {
|
||||
let locked_pointer = match self.locked_pointer.upgrade() {
|
||||
Some(locked_pointer) => locked_pointer,
|
||||
// A pointer is gone.
|
||||
None => return,
|
||||
};
|
||||
|
||||
let mut locked_pointer = locked_pointer.borrow_mut();
|
||||
|
||||
if let Some(locked_pointer) = locked_pointer.take() {
|
||||
locked_pointer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cursor_position(&self, surface_x: u32, surface_y: u32) {
|
||||
let locked_pointer = match self.locked_pointer.upgrade() {
|
||||
Some(locked_pointer) => locked_pointer,
|
||||
// A pointer is gone.
|
||||
None => return,
|
||||
};
|
||||
|
||||
let locked_pointer = locked_pointer.borrow_mut();
|
||||
if let Some(locked_pointer) = locked_pointer.as_ref() {
|
||||
locked_pointer.set_cursor_position_hint(surface_x.into(), surface_y.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drag_window(&self, window: &Window<WinitFrame>) {
|
||||
// WlPointer::setart_interactive_move() expects the last serial of *any*
|
||||
// pointer event (compare to set_cursor()).
|
||||
window.start_interactive_move(&self.seat, self.latest_serial.get());
|
||||
}
|
||||
}
|
||||
|
||||
/// A pointer wrapper for easy releasing and managing pointers.
|
||||
pub(super) struct Pointers {
|
||||
/// A pointer itself.
|
||||
pointer: ThemedPointer,
|
||||
#[derive(Debug)]
|
||||
pub struct WinitPointerData {
|
||||
/// The surface associated with this pointer, which is used for icons.
|
||||
cursor_surface: WlSurface,
|
||||
|
||||
/// A relative pointer handler.
|
||||
relative_pointer: Option<ZwpRelativePointerV1>,
|
||||
/// The inner winit data associated with the pointer.
|
||||
inner: Mutex<WinitPointerDataInner>,
|
||||
|
||||
/// Confined pointer.
|
||||
confined_pointer: Rc<RefCell<Option<ZwpConfinedPointerV1>>>,
|
||||
|
||||
/// Locked pointer.
|
||||
locked_pointer: Rc<RefCell<Option<ZwpLockedPointerV1>>>,
|
||||
/// The data required by the sctk.
|
||||
sctk_data: PointerData,
|
||||
}
|
||||
|
||||
impl Pointers {
|
||||
pub(super) fn new(
|
||||
seat: &Attached<WlSeat>,
|
||||
theme_manager: &ThemeManager,
|
||||
relative_pointer_manager: &Option<Attached<ZwpRelativePointerManagerV1>>,
|
||||
pointer_constraints: &Option<Attached<ZwpPointerConstraintsV1>>,
|
||||
modifiers_state: Rc<RefCell<ModifiersState>>,
|
||||
) -> Self {
|
||||
let confined_pointer = Rc::new(RefCell::new(None));
|
||||
let locked_pointer = Rc::new(RefCell::new(None));
|
||||
|
||||
let pointer_data = Rc::new(RefCell::new(PointerData::new(
|
||||
confined_pointer.clone(),
|
||||
locked_pointer.clone(),
|
||||
pointer_constraints.clone(),
|
||||
modifiers_state,
|
||||
)));
|
||||
|
||||
let pointer_seat = seat.detach();
|
||||
let pointer = theme_manager.theme_pointer_with_impl(
|
||||
seat,
|
||||
move |event, pointer, mut dispatch_data| {
|
||||
let winit_state = dispatch_data.get::<WinitState>().unwrap();
|
||||
handlers::handle_pointer(
|
||||
pointer,
|
||||
event,
|
||||
&pointer_data,
|
||||
winit_state,
|
||||
pointer_seat.clone(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Setup relative_pointer if it's available.
|
||||
let relative_pointer = relative_pointer_manager
|
||||
.as_ref()
|
||||
.map(|relative_pointer_manager| {
|
||||
init_relative_pointer(relative_pointer_manager, &pointer)
|
||||
});
|
||||
|
||||
impl WinitPointerData {
|
||||
pub fn new(seat: WlSeat, surface: WlSurface) -> Self {
|
||||
Self {
|
||||
cursor_surface: surface,
|
||||
inner: Mutex::new(WinitPointerDataInner::default()),
|
||||
sctk_data: PointerData::new(seat),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lock_pointer(
|
||||
&self,
|
||||
pointer_constraints: &PointerConstraintsState,
|
||||
surface: &WlSurface,
|
||||
pointer: &WlPointer,
|
||||
queue_handle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
if inner.locked_pointer.is_none() {
|
||||
inner.locked_pointer = Some(pointer_constraints.lock_pointer(
|
||||
surface,
|
||||
pointer,
|
||||
None,
|
||||
Lifetime::Persistent,
|
||||
queue_handle,
|
||||
GlobalData,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlock_pointer(&self) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
if let Some(locked_pointer) = inner.locked_pointer.take() {
|
||||
locked_pointer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn confine_pointer(
|
||||
&self,
|
||||
pointer_constraints: &PointerConstraintsState,
|
||||
surface: &WlSurface,
|
||||
pointer: &WlPointer,
|
||||
queue_handle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
self.inner.lock().unwrap().confined_pointer = Some(pointer_constraints.confine_pointer(
|
||||
surface,
|
||||
pointer,
|
||||
relative_pointer,
|
||||
confined_pointer,
|
||||
locked_pointer,
|
||||
None,
|
||||
Lifetime::Persistent,
|
||||
queue_handle,
|
||||
GlobalData,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn unconfine_pointer(&self) {
|
||||
let inner = self.inner.lock().unwrap();
|
||||
if let Some(confined_pointer) = inner.confined_pointer.as_ref() {
|
||||
confined_pointer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/// Seat associated with this pointer.
|
||||
pub fn seat(&self) -> &WlSeat {
|
||||
self.sctk_data.seat()
|
||||
}
|
||||
|
||||
/// The WlSurface used to set cursor theme.
|
||||
pub fn cursor_surface(&self) -> &WlSurface {
|
||||
&self.cursor_surface
|
||||
}
|
||||
|
||||
/// Active window.
|
||||
pub fn focused_window(&self) -> Option<WindowId> {
|
||||
self.inner.lock().unwrap().surface
|
||||
}
|
||||
|
||||
/// Last button serial.
|
||||
pub fn latest_button_serial(&self) -> u32 {
|
||||
self.inner.lock().unwrap().latest_button_serial
|
||||
}
|
||||
|
||||
/// Last enter serial.
|
||||
pub fn latest_enter_serial(&self) -> u32 {
|
||||
self.sctk_data.latest_enter_serial().unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn set_locked_cursor_position(&self, surface_x: f64, surface_y: f64) {
|
||||
let inner = self.inner.lock().unwrap();
|
||||
if let Some(locked_pointer) = inner.locked_pointer.as_ref() {
|
||||
locked_pointer.set_cursor_position_hint(surface_x, surface_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Pointers {
|
||||
impl Drop for WinitPointerData {
|
||||
fn drop(&mut self) {
|
||||
// Drop relative pointer.
|
||||
if let Some(relative_pointer) = self.relative_pointer.take() {
|
||||
relative_pointer.destroy();
|
||||
}
|
||||
self.cursor_surface.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// Drop confined pointer.
|
||||
if let Some(confined_pointer) = self.confined_pointer.borrow_mut().take() {
|
||||
confined_pointer.destroy();
|
||||
}
|
||||
impl PointerDataExt for WinitPointerData {
|
||||
fn pointer_data(&self) -> &PointerData {
|
||||
&self.sctk_data
|
||||
}
|
||||
}
|
||||
|
||||
// Drop lock ponter.
|
||||
if let Some(locked_pointer) = self.locked_pointer.borrow_mut().take() {
|
||||
#[derive(Debug)]
|
||||
pub struct WinitPointerDataInner {
|
||||
/// The associated locked pointer.
|
||||
locked_pointer: Option<ZwpLockedPointerV1>,
|
||||
|
||||
/// The associated confined pointer.
|
||||
confined_pointer: Option<ZwpConfinedPointerV1>,
|
||||
|
||||
/// Serial of the last button event.
|
||||
latest_button_serial: u32,
|
||||
|
||||
/// Currently focused window.
|
||||
surface: Option<WindowId>,
|
||||
|
||||
/// Current axis phase.
|
||||
phase: TouchPhase,
|
||||
}
|
||||
|
||||
impl Drop for WinitPointerDataInner {
|
||||
fn drop(&mut self) {
|
||||
if let Some(locked_pointer) = self.locked_pointer.take() {
|
||||
locked_pointer.destroy();
|
||||
}
|
||||
|
||||
// Drop the pointer itself in case it's possible.
|
||||
if self.pointer.as_ref().version() >= 3 {
|
||||
self.pointer.release();
|
||||
if let Some(confined_pointer) = self.confined_pointer.take() {
|
||||
confined_pointer.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn init_relative_pointer(
|
||||
relative_pointer_manager: &ZwpRelativePointerManagerV1,
|
||||
pointer: &WlPointer,
|
||||
) -> ZwpRelativePointerV1 {
|
||||
let relative_pointer = relative_pointer_manager.get_relative_pointer(pointer);
|
||||
relative_pointer.quick_assign(move |_, event, mut dispatch_data| {
|
||||
let winit_state = dispatch_data.get::<WinitState>().unwrap();
|
||||
handlers::handle_relative_pointer(event, winit_state);
|
||||
});
|
||||
|
||||
relative_pointer.detach()
|
||||
impl Default for WinitPointerDataInner {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
surface: None,
|
||||
locked_pointer: None,
|
||||
confined_pointer: None,
|
||||
latest_button_serial: 0,
|
||||
phase: TouchPhase::Ended,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn init_confined_pointer(
|
||||
pointer_constraints: &Attached<ZwpPointerConstraintsV1>,
|
||||
surface: &WlSurface,
|
||||
pointer: &WlPointer,
|
||||
) -> ZwpConfinedPointerV1 {
|
||||
let confined_pointer =
|
||||
pointer_constraints.confine_pointer(surface, pointer, None, Lifetime::Persistent);
|
||||
/// Convert the Wayland button into winit.
|
||||
fn wayland_button_to_winit(button: u32) -> MouseButton {
|
||||
// These values are comming from <linux/input-event-codes.h>.
|
||||
const BTN_LEFT: u32 = 0x110;
|
||||
const BTN_RIGHT: u32 = 0x111;
|
||||
const BTN_MIDDLE: u32 = 0x112;
|
||||
|
||||
confined_pointer.quick_assign(move |_, _, _| {});
|
||||
|
||||
confined_pointer.detach()
|
||||
match button {
|
||||
BTN_LEFT => MouseButton::Left,
|
||||
BTN_RIGHT => MouseButton::Right,
|
||||
BTN_MIDDLE => MouseButton::Middle,
|
||||
button => MouseButton::Other(button as u16),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn init_locked_pointer(
|
||||
pointer_constraints: &Attached<ZwpPointerConstraintsV1>,
|
||||
surface: &WlSurface,
|
||||
pointer: &WlPointer,
|
||||
) -> ZwpLockedPointerV1 {
|
||||
let locked_pointer =
|
||||
pointer_constraints.lock_pointer(surface, pointer, None, Lifetime::Persistent);
|
||||
|
||||
locked_pointer.quick_assign(move |_, _, _| {});
|
||||
|
||||
locked_pointer.detach()
|
||||
pub trait WinitPointerDataExt {
|
||||
fn winit_data(&self) -> &WinitPointerData;
|
||||
}
|
||||
|
||||
impl WinitPointerDataExt for WlPointer {
|
||||
fn winit_data(&self) -> &WinitPointerData {
|
||||
self.data::<WinitPointerData>()
|
||||
.expect("failed to get pointer data.")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PointerConstraintsState {
|
||||
pointer_constraints: ZwpPointerConstraintsV1,
|
||||
}
|
||||
|
||||
impl PointerConstraintsState {
|
||||
pub fn new(
|
||||
globals: &GlobalList,
|
||||
queue_handle: &QueueHandle<WinitState>,
|
||||
) -> Result<Self, BindError> {
|
||||
let pointer_constraints = globals.bind(queue_handle, 1..=1, GlobalData)?;
|
||||
Ok(Self {
|
||||
pointer_constraints,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for PointerConstraintsState {
|
||||
type Target = ZwpPointerConstraintsV1;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.pointer_constraints
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpPointerConstraintsV1, GlobalData, WinitState> for PointerConstraintsState {
|
||||
fn event(
|
||||
_state: &mut WinitState,
|
||||
_proxy: &ZwpPointerConstraintsV1,
|
||||
_event: <ZwpPointerConstraintsV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpLockedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
|
||||
fn event(
|
||||
_state: &mut WinitState,
|
||||
_proxy: &ZwpLockedPointerV1,
|
||||
_event: <ZwpLockedPointerV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpConfinedPointerV1, GlobalData, WinitState> for PointerConstraintsState {
|
||||
fn event(
|
||||
_state: &mut WinitState,
|
||||
_proxy: &ZwpConfinedPointerV1,
|
||||
_event: <ZwpConfinedPointerV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
delegate_dispatch!(WinitState: [ WlPointer: WinitPointerData] => SeatState);
|
||||
delegate_dispatch!(WinitState: [ZwpPointerConstraintsV1: GlobalData] => PointerConstraintsState);
|
||||
delegate_dispatch!(WinitState: [ZwpLockedPointerV1: GlobalData] => PointerConstraintsState);
|
||||
delegate_dispatch!(WinitState: [ZwpConfinedPointerV1: GlobalData] => PointerConstraintsState);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
//! Relative pointer.
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
use sctk::reexports::client::globals::{BindError, GlobalList};
|
||||
use sctk::reexports::client::{delegate_dispatch, Dispatch};
|
||||
use sctk::reexports::client::{Connection, QueueHandle};
|
||||
use sctk::reexports::protocols::wp::relative_pointer::zv1::{
|
||||
client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1,
|
||||
client::zwp_relative_pointer_v1::{self, ZwpRelativePointerV1},
|
||||
};
|
||||
|
||||
use sctk::globals::GlobalData;
|
||||
|
||||
use crate::event::DeviceEvent;
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
|
||||
/// Wrapper around the relative pointer.
|
||||
pub struct RelativePointerState {
|
||||
manager: ZwpRelativePointerManagerV1,
|
||||
}
|
||||
|
||||
impl RelativePointerState {
|
||||
/// Create new relative pointer manager.
|
||||
pub fn new(
|
||||
globals: &GlobalList,
|
||||
queue_handle: &QueueHandle<WinitState>,
|
||||
) -> Result<Self, BindError> {
|
||||
let manager = globals.bind(queue_handle, 1..=1, GlobalData)?;
|
||||
Ok(Self { manager })
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for RelativePointerState {
|
||||
type Target = ZwpRelativePointerManagerV1;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.manager
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpRelativePointerManagerV1, GlobalData, WinitState> for RelativePointerState {
|
||||
fn event(
|
||||
_state: &mut WinitState,
|
||||
_proxy: &ZwpRelativePointerManagerV1,
|
||||
_event: <ZwpRelativePointerManagerV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpRelativePointerV1, GlobalData, WinitState> for RelativePointerState {
|
||||
fn event(
|
||||
state: &mut WinitState,
|
||||
_proxy: &ZwpRelativePointerV1,
|
||||
event: <ZwpRelativePointerV1 as wayland_client::Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
if let zwp_relative_pointer_v1::Event::RelativeMotion {
|
||||
dx_unaccel,
|
||||
dy_unaccel,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
state.events_sink.push_device_event(
|
||||
DeviceEvent::MouseMotion {
|
||||
delta: (dx_unaccel, dy_unaccel),
|
||||
},
|
||||
super::DeviceId,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate_dispatch!(WinitState: [ZwpRelativePointerV1: GlobalData] => RelativePointerState);
|
||||
delegate_dispatch!(WinitState: [ZwpRelativePointerManagerV1: GlobalData] => RelativePointerState);
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
//! Handling of IME events.
|
||||
|
||||
use sctk::reexports::client::Main;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_v3::{
|
||||
Event as TextInputEvent, ZwpTextInputV3,
|
||||
};
|
||||
|
||||
use crate::event::{Ime, WindowEvent};
|
||||
use crate::platform_impl::wayland;
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
|
||||
use super::{Preedit, TextInputHandler, TextInputInner, ZwpTextInputV3Ext};
|
||||
|
||||
#[inline]
|
||||
pub(super) fn handle_text_input(
|
||||
text_input: Main<ZwpTextInputV3>,
|
||||
inner: &mut TextInputInner,
|
||||
event: TextInputEvent,
|
||||
winit_state: &mut WinitState,
|
||||
) {
|
||||
let event_sink = &mut winit_state.event_sink;
|
||||
match event {
|
||||
TextInputEvent::Enter { surface } => {
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
inner.target_window_id = Some(window_id);
|
||||
|
||||
// Enable text input on that surface.
|
||||
if window_handle.ime_allowed.get() {
|
||||
text_input.enable();
|
||||
text_input.set_content_type_by_purpose(window_handle.ime_purpose.get());
|
||||
text_input.commit();
|
||||
event_sink.push_window_event(WindowEvent::Ime(Ime::Enabled), window_id);
|
||||
}
|
||||
|
||||
// Notify a window we're currently over about text input handler.
|
||||
let text_input_handler = TextInputHandler {
|
||||
text_input: text_input.detach(),
|
||||
};
|
||||
window_handle.text_input_entered(text_input_handler);
|
||||
}
|
||||
TextInputEvent::Leave { surface } => {
|
||||
// Always issue a disable.
|
||||
text_input.disable();
|
||||
text_input.commit();
|
||||
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
|
||||
let window_handle = match winit_state.window_map.get_mut(&window_id) {
|
||||
Some(window_handle) => window_handle,
|
||||
None => return,
|
||||
};
|
||||
|
||||
inner.target_window_id = None;
|
||||
|
||||
// Remove text input handler from the window we're leaving.
|
||||
let text_input_handler = TextInputHandler {
|
||||
text_input: text_input.detach(),
|
||||
};
|
||||
window_handle.text_input_left(text_input_handler);
|
||||
event_sink.push_window_event(WindowEvent::Ime(Ime::Disabled), window_id);
|
||||
}
|
||||
TextInputEvent::PreeditString {
|
||||
text,
|
||||
cursor_begin,
|
||||
cursor_end,
|
||||
} => {
|
||||
let text = text.unwrap_or_default();
|
||||
let cursor_begin = usize::try_from(cursor_begin)
|
||||
.ok()
|
||||
.and_then(|idx| text.is_char_boundary(idx).then_some(idx));
|
||||
let cursor_end = usize::try_from(cursor_end)
|
||||
.ok()
|
||||
.and_then(|idx| text.is_char_boundary(idx).then_some(idx));
|
||||
|
||||
inner.pending_preedit = Some(Preedit {
|
||||
text,
|
||||
cursor_begin,
|
||||
cursor_end,
|
||||
});
|
||||
}
|
||||
TextInputEvent::CommitString { text } => {
|
||||
// Update currenly commited string and reset previous preedit.
|
||||
inner.pending_preedit = None;
|
||||
inner.pending_commit = Some(text.unwrap_or_default());
|
||||
}
|
||||
TextInputEvent::Done { .. } => {
|
||||
let window_id = match inner.target_window_id {
|
||||
Some(window_id) => window_id,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
// Clear preedit at the start of `Done`.
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||
window_id,
|
||||
);
|
||||
|
||||
// Send `Commit`.
|
||||
if let Some(text) = inner.pending_commit.take() {
|
||||
event_sink.push_window_event(WindowEvent::Ime(Ime::Commit(text)), window_id);
|
||||
}
|
||||
|
||||
// Send preedit.
|
||||
if let Some(preedit) = inner.pending_preedit.take() {
|
||||
let cursor_range = preedit
|
||||
.cursor_begin
|
||||
.map(|b| (b, preedit.cursor_end.unwrap_or(b)));
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Ime(Ime::Preedit(preedit.text, cursor_range)),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,174 @@
|
|||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3;
|
||||
use sctk::reexports::protocols::unstable::text_input::v3::client::zwp_text_input_v3::{
|
||||
use std::ops::Deref;
|
||||
|
||||
use sctk::globals::GlobalData;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle};
|
||||
|
||||
use sctk::reexports::client::delegate_dispatch;
|
||||
use sctk::reexports::client::globals::{BindError, GlobalList};
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::reexports::client::Dispatch;
|
||||
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_manager_v3::ZwpTextInputManagerV3;
|
||||
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::Event as TextInputEvent;
|
||||
use sctk::reexports::protocols::wp::text_input::zv3::client::zwp_text_input_v3::{
|
||||
ContentHint, ContentPurpose, ZwpTextInputV3,
|
||||
};
|
||||
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::WindowId;
|
||||
use crate::event::{Ime, WindowEvent};
|
||||
use crate::platform_impl::wayland;
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::window::ImePurpose;
|
||||
|
||||
mod handlers;
|
||||
|
||||
/// A handler for text input that we're advertising for `WindowHandle`.
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub struct TextInputHandler {
|
||||
text_input: ZwpTextInputV3,
|
||||
pub struct TextInputState {
|
||||
text_input_manager: ZwpTextInputManagerV3,
|
||||
}
|
||||
|
||||
trait ZwpTextInputV3Ext {
|
||||
impl TextInputState {
|
||||
pub fn new(
|
||||
globals: &GlobalList,
|
||||
queue_handle: &QueueHandle<WinitState>,
|
||||
) -> Result<Self, BindError> {
|
||||
let text_input_manager = globals.bind(queue_handle, 1..=1, GlobalData)?;
|
||||
Ok(Self { text_input_manager })
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TextInputState {
|
||||
type Target = ZwpTextInputManagerV3;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.text_input_manager
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpTextInputManagerV3, GlobalData, WinitState> for TextInputState {
|
||||
fn event(
|
||||
_state: &mut WinitState,
|
||||
_proxy: &ZwpTextInputManagerV3,
|
||||
_event: <ZwpTextInputManagerV3 as Proxy>::Event,
|
||||
_data: &GlobalData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ZwpTextInputV3, TextInputData, WinitState> for TextInputState {
|
||||
fn event(
|
||||
state: &mut WinitState,
|
||||
text_input: &ZwpTextInputV3,
|
||||
event: <ZwpTextInputV3 as Proxy>::Event,
|
||||
data: &TextInputData,
|
||||
_conn: &Connection,
|
||||
_qhandle: &QueueHandle<WinitState>,
|
||||
) {
|
||||
let windows = state.windows.get_mut();
|
||||
let mut text_input_data = data.inner.lock().unwrap();
|
||||
match event {
|
||||
TextInputEvent::Enter { surface } => {
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
text_input_data.surface = Some(surface);
|
||||
|
||||
let mut window = match windows.get(&window_id) {
|
||||
Some(window) => window.lock().unwrap(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
if window.ime_allowed() {
|
||||
text_input.enable();
|
||||
text_input.set_content_type_by_purpose(window.ime_purpose());
|
||||
text_input.commit();
|
||||
state
|
||||
.events_sink
|
||||
.push_window_event(WindowEvent::Ime(Ime::Enabled), window_id);
|
||||
}
|
||||
|
||||
window.text_input_entered(text_input);
|
||||
}
|
||||
TextInputEvent::Leave { surface } => {
|
||||
text_input_data.surface = None;
|
||||
|
||||
// Always issue a disable.
|
||||
text_input.disable();
|
||||
text_input.commit();
|
||||
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
|
||||
// XXX this check is essential, because `leave` could have a
|
||||
// refence to nil surface...
|
||||
let mut window = match windows.get(&window_id) {
|
||||
Some(window) => window.lock().unwrap(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
window.text_input_left(text_input);
|
||||
|
||||
state
|
||||
.events_sink
|
||||
.push_window_event(WindowEvent::Ime(Ime::Disabled), window_id);
|
||||
}
|
||||
TextInputEvent::PreeditString {
|
||||
text,
|
||||
cursor_begin,
|
||||
cursor_end,
|
||||
} => {
|
||||
let text = text.unwrap_or_default();
|
||||
let cursor_begin = usize::try_from(cursor_begin)
|
||||
.ok()
|
||||
.and_then(|idx| text.is_char_boundary(idx).then_some(idx));
|
||||
let cursor_end = usize::try_from(cursor_end)
|
||||
.ok()
|
||||
.and_then(|idx| text.is_char_boundary(idx).then_some(idx));
|
||||
|
||||
text_input_data.pending_preedit = Some(Preedit {
|
||||
text,
|
||||
cursor_begin,
|
||||
cursor_end,
|
||||
})
|
||||
}
|
||||
TextInputEvent::CommitString { text } => {
|
||||
text_input_data.pending_preedit = None;
|
||||
text_input_data.pending_commit = text;
|
||||
}
|
||||
TextInputEvent::Done { .. } => {
|
||||
let window_id = match text_input_data.surface.as_ref() {
|
||||
Some(surface) => wayland::make_wid(surface),
|
||||
None => return,
|
||||
};
|
||||
|
||||
// Clear preedit at the start of `Done`.
|
||||
state.events_sink.push_window_event(
|
||||
WindowEvent::Ime(Ime::Preedit(String::new(), None)),
|
||||
window_id,
|
||||
);
|
||||
|
||||
// Send `Commit`.
|
||||
if let Some(text) = text_input_data.pending_commit.take() {
|
||||
state
|
||||
.events_sink
|
||||
.push_window_event(WindowEvent::Ime(Ime::Commit(text)), window_id);
|
||||
}
|
||||
|
||||
// Send preedit.
|
||||
if let Some(preedit) = text_input_data.pending_preedit.take() {
|
||||
let cursor_range = preedit
|
||||
.cursor_begin
|
||||
.map(|b| (b, preedit.cursor_end.unwrap_or(b)));
|
||||
|
||||
state.events_sink.push_window_event(
|
||||
WindowEvent::Ime(Ime::Preedit(preedit.text, cursor_range)),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
TextInputEvent::DeleteSurroundingText { .. } => {
|
||||
// Not handled.
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ZwpTextInputV3Ext {
|
||||
fn set_content_type_by_purpose(&self, purpose: ImePurpose);
|
||||
}
|
||||
|
||||
|
|
@ -32,81 +183,30 @@ impl ZwpTextInputV3Ext for ZwpTextInputV3 {
|
|||
}
|
||||
}
|
||||
|
||||
impl TextInputHandler {
|
||||
#[inline]
|
||||
pub fn set_ime_position(&self, x: i32, y: i32) {
|
||||
self.text_input.set_cursor_rectangle(x, y, 0, 0);
|
||||
self.text_input.commit();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_content_type_by_purpose(&self, purpose: ImePurpose) {
|
||||
self.text_input.set_content_type_by_purpose(purpose);
|
||||
self.text_input.commit();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_input_allowed(&self, allowed: Option<ImePurpose>) {
|
||||
if let Some(purpose) = allowed {
|
||||
self.text_input.set_content_type_by_purpose(purpose);
|
||||
self.text_input.enable();
|
||||
} else {
|
||||
self.text_input.disable();
|
||||
}
|
||||
|
||||
self.text_input.commit();
|
||||
}
|
||||
/// The Data associated with the text input.
|
||||
#[derive(Default)]
|
||||
pub struct TextInputData {
|
||||
inner: std::sync::Mutex<TextInputDataInner>,
|
||||
}
|
||||
|
||||
/// A wrapper around text input to automatically destroy the object on `Drop`.
|
||||
pub struct TextInput {
|
||||
text_input: Attached<ZwpTextInputV3>,
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct TextInputDataInner {
|
||||
/// The `WlSurface` we're performing input to.
|
||||
surface: Option<WlSurface>,
|
||||
|
||||
impl TextInput {
|
||||
pub fn new(seat: &Attached<WlSeat>, text_input_manager: &ZwpTextInputManagerV3) -> Self {
|
||||
let text_input = text_input_manager.get_text_input(seat);
|
||||
let mut text_input_inner = TextInputInner::new();
|
||||
text_input.quick_assign(move |text_input, event, mut dispatch_data| {
|
||||
let winit_state = dispatch_data.get::<WinitState>().unwrap();
|
||||
handlers::handle_text_input(text_input, &mut text_input_inner, event, winit_state);
|
||||
});
|
||||
|
||||
let text_input: Attached<ZwpTextInputV3> = text_input.into();
|
||||
|
||||
Self { text_input }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TextInput {
|
||||
fn drop(&mut self) {
|
||||
self.text_input.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
struct TextInputInner {
|
||||
/// Currently focused surface.
|
||||
target_window_id: Option<WindowId>,
|
||||
|
||||
/// Pending commit event which will be dispatched on `text_input_v3::Done`.
|
||||
/// The commit to submit on `done`.
|
||||
pending_commit: Option<String>,
|
||||
|
||||
/// Pending preedit event which will be dispatched on `text_input_v3::Done`.
|
||||
/// The preedit to submit on `done`.
|
||||
pending_preedit: Option<Preedit>,
|
||||
}
|
||||
|
||||
/// The state of the preedit.
|
||||
struct Preedit {
|
||||
text: String,
|
||||
cursor_begin: Option<usize>,
|
||||
cursor_end: Option<usize>,
|
||||
}
|
||||
|
||||
impl TextInputInner {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
target_window_id: None,
|
||||
pending_commit: None,
|
||||
pending_preedit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
delegate_dispatch!(WinitState: [ZwpTextInputManagerV3: GlobalData] => TextInputState);
|
||||
delegate_dispatch!(WinitState: [ZwpTextInputV3: TextInputData] => TextInputState);
|
||||
|
|
|
|||
|
|
@ -1,144 +0,0 @@
|
|||
//! Various handlers for touch events.
|
||||
|
||||
use sctk::reexports::client::protocol::wl_touch::Event as TouchEvent;
|
||||
|
||||
use crate::dpi::LogicalPosition;
|
||||
use crate::event::{TouchPhase, WindowEvent};
|
||||
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId};
|
||||
|
||||
use super::{TouchInner, TouchPoint};
|
||||
|
||||
/// Handle WlTouch events.
|
||||
#[inline]
|
||||
pub(super) fn handle_touch(
|
||||
event: TouchEvent,
|
||||
inner: &mut TouchInner,
|
||||
winit_state: &mut WinitState,
|
||||
) {
|
||||
let event_sink = &mut winit_state.event_sink;
|
||||
|
||||
match event {
|
||||
TouchEvent::Down {
|
||||
surface, id, x, y, ..
|
||||
} => {
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let position = LogicalPosition::new(x, y);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Touch(crate::event::Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Started,
|
||||
location: position.to_physical(scale_factor),
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
|
||||
// For `TouchEvent::Up` we don't receive a position, so we're tracking active
|
||||
// touch points. Update either a known touch id or register a new one.
|
||||
if let Some(i) = inner.touch_points.iter().position(|p| p.id == id) {
|
||||
inner.touch_points[i].position = position;
|
||||
} else {
|
||||
inner
|
||||
.touch_points
|
||||
.push(TouchPoint::new(surface, position, id));
|
||||
}
|
||||
}
|
||||
TouchEvent::Up { id, .. } => {
|
||||
let touch_point = match inner.touch_points.iter().find(|p| p.id == id) {
|
||||
Some(touch_point) => touch_point,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let location = touch_point.position.to_physical(scale_factor);
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Touch(crate::event::Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Ended,
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
TouchEvent::Motion { id, x, y, .. } => {
|
||||
let touch_point = match inner.touch_points.iter_mut().find(|p| p.id == id) {
|
||||
Some(touch_point) => touch_point,
|
||||
None => return,
|
||||
};
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
touch_point.position = LogicalPosition::new(x, y);
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let location = touch_point.position.to_physical(scale_factor);
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Touch(crate::event::Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Moved,
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
TouchEvent::Frame => (),
|
||||
TouchEvent::Cancel => {
|
||||
for touch_point in inner.touch_points.drain(..) {
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let window_handle = match winit_state.window_map.get(&window_id) {
|
||||
Some(w) => w,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let scale_factor = window_handle.scale_factor();
|
||||
let location = touch_point.position.to_physical(scale_factor);
|
||||
|
||||
event_sink.push_window_event(
|
||||
WindowEvent::Touch(crate::event::Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Cancelled,
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: touch_point.id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
@ -3,76 +3,197 @@
|
|||
use sctk::reexports::client::protocol::wl_seat::WlSeat;
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::reexports::client::protocol::wl_touch::WlTouch;
|
||||
use sctk::reexports::client::Attached;
|
||||
use sctk::reexports::client::{Connection, Proxy, QueueHandle};
|
||||
|
||||
use sctk::seat::touch::{TouchData, TouchHandler};
|
||||
|
||||
use crate::dpi::LogicalPosition;
|
||||
use crate::event::{Touch, TouchPhase, WindowEvent};
|
||||
|
||||
use crate::platform_impl::wayland::event_loop::WinitState;
|
||||
use crate::platform_impl::wayland::state::WinitState;
|
||||
use crate::platform_impl::wayland::{self, DeviceId};
|
||||
|
||||
mod handlers;
|
||||
impl TouchHandler for WinitState {
|
||||
fn down(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
touch: &WlTouch,
|
||||
_: u32,
|
||||
_: u32,
|
||||
surface: WlSurface,
|
||||
id: i32,
|
||||
position: (f64, f64),
|
||||
) {
|
||||
let window_id = wayland::make_wid(&surface);
|
||||
let scale_factor = match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().scale_factor(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
/// Wrapper around touch to handle release.
|
||||
pub struct Touch {
|
||||
/// Proxy to touch.
|
||||
touch: WlTouch,
|
||||
}
|
||||
let location = LogicalPosition::<f64>::from(position);
|
||||
|
||||
impl Touch {
|
||||
pub fn new(seat: &Attached<WlSeat>) -> Self {
|
||||
let touch = seat.get_touch();
|
||||
let mut inner = TouchInner::new();
|
||||
let seat_state = self.seats.get_mut(&touch.seat().id()).unwrap();
|
||||
|
||||
touch.quick_assign(move |_, event, mut dispatch_data| {
|
||||
let winit_state = dispatch_data.get::<WinitState>().unwrap();
|
||||
handlers::handle_touch(event, &mut inner, winit_state);
|
||||
});
|
||||
// Update the state of the point.
|
||||
seat_state
|
||||
.touch_map
|
||||
.insert(id, TouchPoint { surface, location });
|
||||
|
||||
Self {
|
||||
touch: touch.detach(),
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Started,
|
||||
location: location.to_physical(scale_factor),
|
||||
force: None,
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
|
||||
fn up(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
touch: &WlTouch,
|
||||
_: u32,
|
||||
_: u32,
|
||||
id: i32,
|
||||
) {
|
||||
let seat_state = self.seats.get_mut(&touch.seat().id()).unwrap();
|
||||
|
||||
// Remove the touch point.
|
||||
let touch_point = match seat_state.touch_map.remove(&id) {
|
||||
Some(touch_point) => touch_point,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let scale_factor = match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().scale_factor(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Ended,
|
||||
location: touch_point.location.to_physical(scale_factor),
|
||||
force: None,
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
|
||||
fn motion(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
touch: &WlTouch,
|
||||
_: u32,
|
||||
id: i32,
|
||||
position: (f64, f64),
|
||||
) {
|
||||
let seat_state = self.seats.get_mut(&touch.seat().id()).unwrap();
|
||||
|
||||
// Remove the touch point.
|
||||
let mut touch_point = match seat_state.touch_map.get_mut(&id) {
|
||||
Some(touch_point) => touch_point,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let scale_factor = match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().scale_factor(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
touch_point.location = LogicalPosition::<f64>::from(position);
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Cancelled,
|
||||
location: touch_point.location.to_physical(scale_factor),
|
||||
force: None,
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
|
||||
fn cancel(&mut self, _: &Connection, _: &QueueHandle<Self>, touch: &WlTouch) {
|
||||
let seat_state = self.seats.get_mut(&touch.seat().id()).unwrap();
|
||||
|
||||
for (id, touch_point) in seat_state.touch_map.drain() {
|
||||
let window_id = wayland::make_wid(&touch_point.surface);
|
||||
let scale_factor = match self.windows.get_mut().get(&window_id) {
|
||||
Some(window) => window.lock().unwrap().scale_factor(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
let location = touch_point.location.to_physical(scale_factor);
|
||||
|
||||
self.events_sink.push_window_event(
|
||||
WindowEvent::Touch(Touch {
|
||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
||||
DeviceId,
|
||||
)),
|
||||
phase: TouchPhase::Cancelled,
|
||||
location,
|
||||
force: None,
|
||||
id: id as u64,
|
||||
}),
|
||||
window_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn shape(
|
||||
&mut self,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
_: &WlTouch,
|
||||
_: i32,
|
||||
_: f64,
|
||||
_: f64,
|
||||
) {
|
||||
// Blank.
|
||||
}
|
||||
|
||||
fn orientation(&mut self, _: &Connection, _: &QueueHandle<Self>, _: &WlTouch, _: i32, _: f64) {
|
||||
// Blank.
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Touch {
|
||||
fn drop(&mut self) {
|
||||
if self.touch.as_ref().version() >= 3 {
|
||||
self.touch.release();
|
||||
}
|
||||
/// The state of the touch point.
|
||||
#[derive(Debug)]
|
||||
pub struct TouchPoint {
|
||||
/// The surface on which the point is present.
|
||||
pub surface: WlSurface,
|
||||
|
||||
/// The location of the point on the surface.
|
||||
pub location: LogicalPosition<f64>,
|
||||
}
|
||||
|
||||
pub trait TouchDataExt {
|
||||
fn seat(&self) -> &WlSeat;
|
||||
}
|
||||
|
||||
impl TouchDataExt for WlTouch {
|
||||
fn seat(&self) -> &WlSeat {
|
||||
self.data::<TouchData>()
|
||||
.expect("failed to get touch data.")
|
||||
.seat()
|
||||
}
|
||||
}
|
||||
|
||||
/// The data used by touch handlers.
|
||||
pub(super) struct TouchInner {
|
||||
/// Current touch points.
|
||||
touch_points: Vec<TouchPoint>,
|
||||
}
|
||||
|
||||
impl TouchInner {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
touch_points: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Location of touch press.
|
||||
pub(super) struct TouchPoint {
|
||||
/// A surface where the touch point is located.
|
||||
surface: WlSurface,
|
||||
|
||||
/// Location of the touch point.
|
||||
position: LogicalPosition<f64>,
|
||||
|
||||
/// Id.
|
||||
id: i32,
|
||||
}
|
||||
|
||||
impl TouchPoint {
|
||||
pub fn new(surface: WlSurface, position: LogicalPosition<f64>, id: i32) -> Self {
|
||||
Self {
|
||||
surface,
|
||||
position,
|
||||
id,
|
||||
}
|
||||
}
|
||||
}
|
||||
sctk::delegate_touch!(WinitState);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue