Skip to content

Commit

Permalink
fix: repeat info should also handle token (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers authored Nov 6, 2024
1 parent 9905712 commit 1d53831
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 34 additions & 1 deletion layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,12 +1151,26 @@ impl<T> Dispatch<wl_keyboard::WlKeyboard, ()> for WindowState<T> {
}
_ => unreachable!(),
},
wl_keyboard::Event::Enter { .. } => {
if let (Some(token), Some(loop_handle)) = (
keyboard_state.repeat_token.take(),
state.loop_handler.as_ref(),
) {
loop_handle.remove(token);
}
}
wl_keyboard::Event::Leave { .. } => {
keyboard_state.current_repeat = None;
state.message.push((
surface_id,
DispatchMessageInner::ModifiersChanged(ModifiersState::empty()),
));
if let (Some(token), Some(loop_handle)) = (
keyboard_state.repeat_token.take(),
state.loop_handler.as_ref(),
) {
loop_handle.remove(token);
}
}
wl_keyboard::Event::Key {
state: keystate,
Expand Down Expand Up @@ -1196,10 +1210,17 @@ impl<T> Dispatch<wl_keyboard::WlKeyboard, ()> for WindowState<T> {
}

keyboard_state.current_repeat = Some(key);

if let (Some(token), Some(loop_handle)) = (
keyboard_state.repeat_token.take(),
state.loop_handler.as_ref(),
) {
loop_handle.remove(token);
}
let timer = Timer::from_duration(delay);

if let Some(looph) = state.loop_handler.as_ref() {
looph
keyboard_state.repeat_token = looph
.insert_source(timer, move |_, _, state| {
let keyboard_state = match state.keyboard_state.as_mut() {
Some(keyboard_state) => keyboard_state,
Expand Down Expand Up @@ -1247,6 +1268,12 @@ impl<T> Dispatch<wl_keyboard::WlKeyboard, ()> for WindowState<T> {
&& Some(key) == keyboard_state.current_repeat
{
keyboard_state.current_repeat = None;
if let (Some(token), Some(loop_handle)) = (
keyboard_state.repeat_token.take(),
state.loop_handler.as_ref(),
) {
loop_handle.remove(token);
}
}
}
}
Expand Down Expand Up @@ -1275,6 +1302,12 @@ impl<T> Dispatch<wl_keyboard::WlKeyboard, ()> for WindowState<T> {
keyboard_state.repeat_info = if rate == 0 {
// Stop the repeat once we get a disable event.
keyboard_state.current_repeat = None;
if let (Some(token), Some(loop_handle)) = (
keyboard_state.repeat_token.take(),
state.loop_handler.as_ref(),
) {
loop_handle.remove(token);
}
RepeatInfo::Disable
} else {
let gap = Duration::from_micros(1_000_000 / rate as u64);
Expand Down
1 change: 1 addition & 0 deletions waycrate_xkbkeycode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ bitflags.workspace = true
wayland-client.workspace = true
wayland-backend.workspace = true
log.workspace = true
calloop.workspace = true
4 changes: 4 additions & 0 deletions waycrate_xkbkeycode/src/xkb_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use xkb::{

use crate::keyboard::{Key, KeyLocation, PhysicalKey};

use calloop::RegistrationToken;

static RESET_DEAD_KEYS: AtomicBool = AtomicBool::new(false);

pub static XKBH: LazyLock<&'static XkbCommon> = LazyLock::new(xkbcommon_handle);
Expand Down Expand Up @@ -66,6 +68,7 @@ pub struct KeyboardState {

pub xkb_context: Context,
pub repeat_info: RepeatInfo,
pub repeat_token: Option<RegistrationToken>,
pub current_repeat: Option<u32>,
}

Expand All @@ -76,6 +79,7 @@ impl KeyboardState {
xkb_context: Context::new().unwrap(),
repeat_info: RepeatInfo::default(),
current_repeat: None,
repeat_token: None,
}
}
}
Expand Down

0 comments on commit 1d53831

Please sign in to comment.