Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ wayland-protocols = { version = "0.28" , features = ["client", "unstable_protoco
wayland-cursor = "0.28"
calloop = { version = "0.6.1", optional = true }
byteorder = "1.0"
smallvec = "1"

[features]
default = ["frames", "calloop"]
Expand Down
23 changes: 12 additions & 11 deletions src/seat/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
};

use byteorder::{ByteOrder, NativeEndian};
use smallvec::SmallVec;

pub use wayland_client::protocol::wl_keyboard::KeyState;
use wayland_client::{
Expand Down Expand Up @@ -70,17 +71,17 @@ pub enum Error {
}

/// Events received from a mapped keyboard
pub enum Event<'a> {
pub enum Event {
/// The keyboard focus has entered a surface
Enter {
/// serial number of the event
serial: u32,
/// surface that was entered
surface: wl_surface::WlSurface,
/// raw values of the currently pressed keys
rawkeys: &'a [u32],
rawkeys: SmallVec<[u32; 2]>,
/// interpreted symbols of the currently pressed keys
keysyms: &'a [u32],
keysyms: SmallVec<[u32; 2]>,
},
/// The keyboard focus has left a surface
Leave {
Expand Down Expand Up @@ -142,7 +143,7 @@ pub fn map_keyboard<F>(
callback: F,
) -> Result<wl_keyboard::WlKeyboard, Error>
where
F: FnMut(Event<'_>, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>) + 'static,
F: FnMut(Event, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>) + 'static,
{
let has_kbd = super::with_seat_data(seat, |data| data.has_keyboard).unwrap_or(false);
let keyboard = if has_kbd {
Expand Down Expand Up @@ -191,7 +192,7 @@ pub fn map_keyboard_repeat<F, Data: 'static>(
callback: F,
) -> Result<(wl_keyboard::WlKeyboard, calloop::Source<RepeatSource>), Error>
where
F: FnMut(Event<'_>, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>) + 'static,
F: FnMut(Event, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>) + 'static,
{
let has_kbd = super::with_seat_data(seat, |data| data.has_keyboard).unwrap_or(false);
let keyboard = if has_kbd {
Expand Down Expand Up @@ -264,7 +265,7 @@ fn rate_to_gap(rate: i32) -> Option<NonZeroU32> {
* Classic handling
*/

type KbdCallback = dyn FnMut(Event<'_>, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>);
type KbdCallback = dyn FnMut(Event, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>);

#[cfg(feature = "calloop")]
struct RepeatDetails {
Expand Down Expand Up @@ -393,10 +394,10 @@ impl KbdHandler {
dispatch_data: wayland_client::DispatchData,
) {
let mut state = self.state.borrow_mut();
let rawkeys = keys.chunks_exact(4).map(NativeEndian::read_u32).collect::<Vec<_>>();
let keys: Vec<u32> = rawkeys.iter().map(|k| state.get_one_sym_raw(*k)).collect();
let rawkeys = keys.chunks_exact(4).map(NativeEndian::read_u32).collect::<SmallVec<_>>();
let keysyms = rawkeys.iter().map(|k| state.get_one_sym_raw(*k)).collect();
(&mut *self.callback.borrow_mut())(
Event::Enter { serial, surface, rawkeys: &rawkeys, keysyms: &keys },
Event::Enter { serial, surface, rawkeys, keysyms },
object,
dispatch_data,
);
Expand Down Expand Up @@ -552,7 +553,7 @@ pub struct RepeatSource {

#[cfg(feature = "calloop")]
impl calloop::EventSource for RepeatSource {
type Event = Event<'static>;
type Event = Event;
type Metadata = wl_keyboard::WlKeyboard;
type Ret = ();

Expand All @@ -563,7 +564,7 @@ impl calloop::EventSource for RepeatSource {
mut callback: F,
) -> std::io::Result<()>
where
F: FnMut(Event<'static>, &mut wl_keyboard::WlKeyboard),
F: FnMut(Event, &mut wl_keyboard::WlKeyboard),
{
let current_repeat = &self.current_repeat;
let state = &self.state;
Expand Down