seat.keyboard: handle repeat-info

This commit is contained in:
Victor Berger 2017-09-21 21:40:11 +02:00
parent 5241b8f79e
commit e6600dfbe9
2 changed files with 35 additions and 6 deletions

View File

@ -61,10 +61,13 @@ struct KbdInternal {
mods_state: ModifiersState, mods_state: ModifiersState,
keymap: xkb::Keymap, keymap: xkb::Keymap,
state: xkb::State, state: xkb::State,
repeat_rate: i32,
repeat_delay: i32,
} }
impl KbdInternal { impl KbdInternal {
fn new(rules: &str, model: &str, layout: &str, variant: &str, options: Option<String>) fn new(rules: &str, model: &str, layout: &str, variant: &str, options: Option<String>,
repeat_rate: i32, repeat_delay: i32)
-> Result<KbdInternal, ()> { -> Result<KbdInternal, ()> {
// we create a new contex for each keyboard because libxkbcommon is actually NOT threadsafe // we create a new contex for each keyboard because libxkbcommon is actually NOT threadsafe
// so confining it inside the KbdInternal allows us to use Rusts mutability rules to make // so confining it inside the KbdInternal allows us to use Rusts mutability rules to make
@ -90,6 +93,8 @@ impl KbdInternal {
mods_state: ModifiersState::new(), mods_state: ModifiersState::new(),
keymap: keymap, keymap: keymap,
state: state, state: state,
repeat_rate: repeat_rate,
repeat_delay: repeat_delay,
}) })
} }
@ -137,7 +142,8 @@ impl KbdInternal {
} }
fn with_focused_kbds<F>(&self, mut f: F) fn with_focused_kbds<F>(&self, mut f: F)
where F: FnMut(&wl_keyboard::WlKeyboard, &wl_surface::WlSurface) where
F: FnMut(&wl_keyboard::WlKeyboard, &wl_surface::WlSurface),
{ {
if let Some(ref surface) = self.focus { if let Some(ref surface) = self.focus {
for kbd in &self.known_kbds { for kbd in &self.known_kbds {
@ -159,7 +165,7 @@ pub enum Error {
/// Create a keyboard handler from a set of RMLVO rules /// Create a keyboard handler from a set of RMLVO rules
pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, variant: &str, pub fn create_keyboard_handler<L>(rules: &str, model: &str, layout: &str, variant: &str,
options: Option<String>, logger: L) options: Option<String>, repeat_delay: i32, repeat_rate: i32, logger: L)
-> Result<KbdHandle, Error> -> Result<KbdHandle, Error>
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
@ -169,7 +175,15 @@ where
"rules" => rules, "model" => model, "layout" => layout, "variant" => variant, "rules" => rules, "model" => model, "layout" => layout, "variant" => variant,
"options" => &options "options" => &options
); );
let internal = KbdInternal::new(rules, model, layout, variant, options).map_err(|_| { let internal = KbdInternal::new(
rules,
model,
layout,
variant,
options,
repeat_rate,
repeat_delay,
).map_err(|_| {
debug!(log, "Loading keymap failed"); debug!(log, "Loading keymap failed");
Error::BadKeymap Error::BadKeymap
})?; })?;
@ -318,14 +332,29 @@ impl KbdHandle {
self.arc.keymap_len, self.arc.keymap_len,
); );
let mut guard = self.arc.internal.lock().unwrap(); let mut guard = self.arc.internal.lock().unwrap();
if kbd.version() >= 4 {
kbd.repeat_info(guard.repeat_rate, guard.repeat_delay);
}
guard.known_kbds.push(kbd); guard.known_kbds.push(kbd);
} }
/// Change the repeat info configured for this keyboard
pub fn change_repeat_info(&self, rate: i32, delay: i32) {
let mut guard = self.arc.internal.lock().unwrap();
guard.repeat_delay = delay;
guard.repeat_rate = rate;
for kbd in &guard.known_kbds {
kbd.repeat_info(rate, delay);
}
}
/// Performs an internal cleanup of known kbds /// Performs an internal cleanup of known kbds
/// ///
/// Drops any wl_keyboard that is no longer alive /// Drops any wl_keyboard that is no longer alive
pub fn cleanup_old_kbds(&self) { pub fn cleanup_old_kbds(&self) {
let mut guard = self.arc.internal.lock().unwrap(); let mut guard = self.arc.internal.lock().unwrap();
guard.known_kbds.retain(|kbd| kbd.status() != Liveness::Dead); guard
.known_kbds
.retain(|kbd| kbd.status() != Liveness::Dead);
} }
} }

View File

@ -1,3 +1,3 @@
mod keyboard; mod keyboard;
pub use self::keyboard::{KbdHandle, Error as KbdError, create_keyboard_handler}; pub use self::keyboard::{create_keyboard_handler, Error as KbdError, KbdHandle};