/// Implement a keyboard for keymap translation with key repetition
///
/// This requires you to provide a callback to receive the events after they
/// have been interpreted with the keymap.
///
/// The keymap will be loaded from the provided RMLVO rules, or from the compositor
/// provided keymap if `None`.
///
/// Returns an error if xkbcommon could not be initialized, the RMLVO specification
/// contained invalid values, or if the provided seat does not have keyboard capability.
Implement a keyboard for keymap translation with key repetition
This requires you to provide a callback to receive the events after they
have been interpreted with the keymap.

The keymap will be loaded from the provided RMLVO rules, or from the compositor
provided keymap if `None`.

Returns an error if xkbcommon could not be initialized, the RMLVO specification
contained invalid values, or if the provided seat does not have keyboard capability.
Implement a keyboard for keymap translation with key repetition This requires you to provide a callback to receive the events after they have been interpreted with the keymap . The keymap will be loaded from the provided RMLVO rules or from the compositor provided keymap if ` None ` . Returns an error if xkbcommon could not be initialized the RMLVO specification contained invalid values or if the provided seat does not have keyboard capability .
pub fn map_keyboard_repeat<F, Data: 'static>(
    loop_handle: calloop::LoopHandle<Data>,
    seat: &Attached<wl_seat::WlSeat>,
    rmlvo: Option<RMLVO>,
    repeatkind: RepeatKind,
    callback: F,
) -> Result<(wl_keyboard::WlKeyboard, calloop::Source<RepeatSource>), Error>
where
    F: FnMut(Event<'_>, wl_keyboard::WlKeyboard, wayland_client::DispatchData<'_>) + 'static,
{
    let has_kbd = sctk::seat::with_seat_data(seat, |data| data.has_keyboard).unwrap_or(false);
    let keyboard = if has_kbd {
        seat.get_keyboard()
    } else {
        return Err(Error::NoKeyboard);
    };
    let state = Rc::new(RefCell::new(
        rmlvo
            .map(KbState::from_rmlvo)
            .unwrap_or_else(KbState::new)?,
    ));
    let callback = Rc::new(RefCell::new(callback));
    let repeat = match repeatkind {
        RepeatKind::System => RepeatDetails {
            locked: false,
            gap: None,
            delay: 200,
        },
        RepeatKind::Fixed { rate, delay } => {
            let gap = rate_to_gap(rate as i32);
            RepeatDetails {
                locked: true,
                gap,
                delay,
            }
        }
    };
    // Prepare the repetition handling.
    let (mut kbd_handler, source) = {
        let current_repeat = Rc::new(RefCell::new(None));
        let source = RepeatSource {
            timer: calloop::timer::Timer::new().map_err(Error::TimerError)?,
            state: state.clone(),
            current_repeat: current_repeat.clone(),
        };
        let timer_handle = source.timer.handle();
        let handler = KbdHandler {
            callback: callback.clone(),
            state,
            repeat: Some(KbdRepeat {
                timer_handle,
                current_repeat,
                details: repeat,
            }),
            group: 0,
        };
        (handler, source)
    };
    let source = loop_handle
        .insert_source(source, move |event, kbd, ddata| {
            (&mut *callback.borrow_mut())(
                event,
                kbd.clone(),
                wayland_client::DispatchData::wrap(ddata),
            )
        })
        .map_err(|e| Error::TimerError(e.error))?;
    keyboard.quick_assign(move |keyboard, event, data| {
        kbd_handler.event(keyboard.detach(), event, data)
    });
    Ok((keyboard.detach(), source))
}
pub fn map_keyboard_repeat < F , Data : ' static > ( loop_handle : calloop :: LoopHandle < Data > , seat : & Attached < wl_seat :: WlSeat > , rmlvo : Option < RMLVO > , repeatkind : RepeatKind , callback : F , ) -> Result < ( wl_keyboard :: WlKeyboard , calloop :: Source < RepeatSource > ) , Error > where F : FnMut ( Event < ' _ > , wl_keyboard :: WlKeyboard , wayland_client :: DispatchData < ' _ > ) + ' static , { let has_kbd = sctk :: seat :: with_seat_data ( seat , | data | data . has_keyboard ) . unwrap_or ( false ) ; let keyboard = if has_kbd { seat . get_keyboard ( ) } else { return Err ( Error :: NoKeyboard ) ; } ; let state = Rc :: new ( RefCell :: new ( rmlvo . map ( KbState :: from_rmlvo ) . unwrap_or_else ( KbState :: new ) ? , ) ) ; let callback = Rc :: new ( RefCell :: new ( callback ) ) ; let repeat = match repeatkind { RepeatKind :: System => RepeatDetails { locked : false , gap : None , delay : 200 , } , RepeatKind :: Fixed { rate , delay } => { let gap = rate_to_gap ( rate as i32 ) ; RepeatDetails { locked : true , gap , delay , } } } ; // Prepare the repetition handling. let ( mut kbd_handler , source ) = { let current_repeat = Rc :: new ( RefCell :: new ( None ) ) ; let source = RepeatSource { timer : calloop :: timer :: Timer :: new ( ) . map_err ( Error :: TimerError ) ? , state : state . clone ( ) , current_repeat : current_repeat . clone ( ) , } ; let timer_handle = source . timer . handle ( ) ; let handler = KbdHandler { callback : callback . clone ( ) , state , repeat : Some ( KbdRepeat { timer_handle , current_repeat , details : repeat , } ) , group : 0 , } ; ( handler , source ) } ; let source = loop_handle . insert_source ( source , move | event , kbd , ddata | { ( & mut * callback . borrow_mut ( ) ) ( event , kbd . clone ( ) , wayland_client :: DispatchData :: wrap ( ddata ) , ) } ) . map_err ( | e | Error :: TimerError ( e . error ) ) ? ; keyboard . quick_assign ( move | keyboard , event , data | { kbd_handler . event ( keyboard . detach ( ) , event , data ) } ) ; Ok ( ( keyboard . detach ( ) , source ) ) }
Implement a keyboard for keymap translation with key repetition
This requires you to provide a callback to receive the events after they
have been interpreted with the keymap.
Implement a keyboard for keymap translation with key repetition This requires you to provide a callback to receive the events after they have been interpreted with the keymap .
loop_handle
calloop::LoopHandle<Data>
seat
&Attached<wl_seat::WlSeat>
rmlvo
Option<RMLVO>
repeatkind
RepeatKind
callback
F