@@ -18,7 +18,7 @@ use wayland_protocols::unstable::input_method::v1::client::{
1818} ;
1919
2020use mio:: { unix:: SourceFd , Events as MioEvents , Interest , Poll , Token } ;
21- use mio_timerfd :: { ClockId , TimerFd } ;
21+ use timerfd_mio :: TimerFd ;
2222use wayland_client:: protocol:: wl_keyboard:: KeymapFormat ;
2323use xkbcommon:: xkb:: {
2424 Context , Keycode , Keymap , CONTEXT_NO_FLAGS , KEYMAP_COMPILE_NO_FLAGS , KEYMAP_FORMAT_TEXT_V1 ,
@@ -205,7 +205,7 @@ impl KimeContext {
205205 if !press_state. is_pressing ( key) =>
206206 {
207207 let duration = Duration :: from_millis ( info. delay as u64 ) ;
208- if let Err ( e) = self . timer . set_timeout ( & duration) {
208+ if let Err ( e) = self . timer . set_timeout_oneshot ( duration) {
209209 log:: warn!( "failed to set repeat timer: {}" , e) ;
210210 }
211211 * press_state = PressState :: Pressing {
@@ -228,9 +228,7 @@ impl KimeContext {
228228 } else {
229229 if let Some ( ( .., ref mut press_state) ) = self . repeat_state {
230230 if press_state. is_pressing ( key) {
231- if let Err ( e) = self . timer . disarm ( ) {
232- log:: warn!( "failed to disarm timer: {}" , e) ;
233- }
231+ let _ = self . timer . set_timeout_oneshot ( Duration :: ZERO ) ;
234232 * press_state = PressState :: NotPressing ;
235233 }
236234 }
@@ -287,6 +285,10 @@ impl KimeContext {
287285 pub fn handle_timer_ev ( & mut self ) -> std:: io:: Result < ( ) > {
288286 // Read timer, this MUST be called or timer will be broken
289287 let overrun_count = self . timer . read ( ) ?;
288+ if overrun_count == 0 {
289+ // Non-blocking read returned no expirations, skip processing
290+ return Ok ( ( ) ) ;
291+ }
290292 if overrun_count != 1 {
291293 log:: warn!( "Some timer events were not properly handled!" ) ;
292294 }
@@ -309,8 +311,8 @@ impl KimeContext {
309311 {
310312 // Start repeat
311313 log:: trace!( "Start repeating {}" , key) ;
312- let interval = & Duration :: from_secs_f64 ( 1.0 / info. rate as f64 ) ;
313- self . timer . set_timeout_interval ( interval) ?;
314+ let interval = Duration :: from_secs_f64 ( 1.0 / info. rate as f64 ) ;
315+ self . timer . set_timeout_interval ( interval, interval ) ?;
314316 * is_repeating = true ;
315317 }
316318 }
@@ -368,7 +370,7 @@ impl KimeContext {
368370 self . grab_activate = false ;
369371
370372 // Input deactivated, stop repeating
371- self . timer . disarm ( ) . unwrap ( ) ;
373+ let _ = self . timer . set_timeout_oneshot ( Duration :: ZERO ) ;
372374 if let Some ( ( _, ref mut press_state) ) = self . repeat_state {
373375 * press_state = PressState :: NotPressing
374376 }
@@ -412,7 +414,7 @@ pub fn run(
412414 let im = globals. instantiate_exact :: < ZwpInputMethodV1 > ( 1 ) ?;
413415 im. assign ( im_filter) ;
414416
415- let mut timer = TimerFd :: new ( ClockId :: Monotonic ) . expect ( "Initialize timer" ) ;
417+ let mut timer = TimerFd :: new ( ) . expect ( "Initialize timer" ) ;
416418
417419 let mut poll = Poll :: new ( ) . expect ( "Initialize epoll()" ) ;
418420 let registry = poll. registry ( ) ;
0 commit comments