Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhyub committed Dec 26, 2023
1 parent 6f5d585 commit 3fc70ff
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 50 deletions.
55 changes: 31 additions & 24 deletions src/frontends/wayland/src/input_method_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use std::error::Error;
use std::os::fd::{FromRawFd, OwnedFd};
use std::time::{Duration, Instant};

use wayland_client::{event_enum, protocol::wl_keyboard::{Event as KeyEvent, KeyState, WlKeyboard, REQ_RELEASE_SINCE}, DispatchData, Display, Filter, GlobalManager, Main, EventQueue};
use wayland_client::{
event_enum,
protocol::wl_keyboard::{Event as KeyEvent, KeyState, WlKeyboard, REQ_RELEASE_SINCE},
DispatchData, Display, EventQueue, Filter, GlobalManager, Main,
};

use wayland_protocols::unstable::input_method::v1::client::{
zwp_input_method_context_v1::{Event as ImCtxEvent, ZwpInputMethodContextV1},
Expand All @@ -18,7 +22,7 @@ use xkbcommon::xkb::{
Context, Keycode, Keymap, CONTEXT_NO_FLAGS, KEYMAP_COMPILE_NO_FLAGS, KEYMAP_FORMAT_TEXT_V1,
};

use crate::{RepeatInfo, PressState};
use crate::{PressState, RepeatInfo};

event_enum! {
Events |
Expand Down Expand Up @@ -162,7 +166,7 @@ impl KimeContext {
KEYMAP_FORMAT_TEXT_V1,
KEYMAP_COMPILE_NO_FLAGS,
)
.unwrap_or(None);
.unwrap_or(None);
}
} else {
unsafe {
Expand Down Expand Up @@ -191,17 +195,17 @@ impl KimeContext {
// IME. Start waiting for the key hold timer event.
match self.repeat_state {
Some((info, ref mut press_state))
if !press_state.is_pressing(key) =>
{
let duration = Duration::from_millis(info.delay as u64);
self.timer.set_timeout(&duration).unwrap();
*press_state = PressState::Pressing {
pressed_at: Instant::now(),
is_repeating: false,
key,
wayland_time: time,
}
if !press_state.is_pressing(key) =>
{
let duration = Duration::from_millis(info.delay as u64);
self.timer.set_timeout(&duration).unwrap();
*press_state = PressState::Pressing {
pressed_at: Instant::now(),
is_repeating: false,
key,
wayland_time: time,
}
}
_ => {}
}
}
Expand Down Expand Up @@ -273,14 +277,14 @@ impl KimeContext {
}

if let Some((
info,
PressState::Pressing {
pressed_at,
ref mut is_repeating,
key,
wayland_time,
},
)) = self.repeat_state
info,
PressState::Pressing {
pressed_at,
ref mut is_repeating,
key,
wayland_time,
},
)) = self.repeat_state
{
if !*is_repeating {
if self
Expand Down Expand Up @@ -368,7 +372,11 @@ impl KimeContext {
}
}

pub fn run(display: &Display, event_queue: &mut EventQueue, globals: &GlobalManager) -> Result<(), Box<dyn Error>> {
pub fn run(
display: &Display,
event_queue: &mut EventQueue,
globals: &GlobalManager,
) -> Result<(), Box<dyn Error>> {
let im_filter = Filter::new(|ev, _filter, mut data| {
let ctx = KimeContext::new_data(&mut data);
match ev {
Expand All @@ -386,8 +394,7 @@ pub fn run(display: &Display, event_queue: &mut EventQueue, globals: &GlobalMana
}
});

let im = globals
.instantiate_exact::<ZwpInputMethodV1>(1)?;
let im = globals.instantiate_exact::<ZwpInputMethodV1>(1)?;
im.assign(im_filter);

let mut timer = TimerFd::new(ClockId::Monotonic).expect("Initialize timer");
Expand Down
58 changes: 32 additions & 26 deletions src/frontends/wayland/src/input_method_v2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::error::Error;
use std::time::{Duration, Instant};

use wayland_client::{event_enum, protocol::{wl_keyboard::KeyState, wl_seat::WlSeat}, DispatchData, Display, Filter, GlobalManager, Main, EventQueue};
use wayland_client::{
event_enum,
protocol::{wl_keyboard::KeyState, wl_seat::WlSeat},
DispatchData, Display, EventQueue, Filter, GlobalManager, Main,
};

use wayland_protocols::misc::zwp_input_method_v2::client::{
zwp_input_method_keyboard_grab_v2::{Event as KeyEvent, ZwpInputMethodKeyboardGrabV2},
Expand All @@ -18,7 +22,7 @@ use kime_engine_cffi::*;
use mio::{unix::SourceFd, Events as MioEvents, Interest, Poll, Token};
use mio_timerfd::{ClockId, TimerFd};

use crate::{RepeatInfo, PressState};
use crate::{PressState, RepeatInfo};

event_enum! {
Events |
Expand Down Expand Up @@ -228,17 +232,17 @@ impl KimeContext {
// IME. Start waiting for the key hold timer event.
match self.repeat_state {
Some((info, ref mut press_state))
if !press_state.is_pressing(key) =>
{
let duration = Duration::from_millis(info.delay as u64);
self.timer.set_timeout(&duration).unwrap();
*press_state = PressState::Pressing {
pressed_at: Instant::now(),
is_repeating: false,
key,
wayland_time: time,
};
}
if !press_state.is_pressing(key) =>
{
let duration = Duration::from_millis(info.delay as u64);
self.timer.set_timeout(&duration).unwrap();
*press_state = PressState::Pressing {
pressed_at: Instant::now(),
is_repeating: false,
key,
wayland_time: time,
};
}
_ => {}
}
}
Expand Down Expand Up @@ -309,14 +313,14 @@ impl KimeContext {
}

if let Some((
info,
PressState::Pressing {
pressed_at,
ref mut is_repeating,
key,
wayland_time,
},
)) = self.repeat_state
info,
PressState::Pressing {
pressed_at,
ref mut is_repeating,
key,
wayland_time,
},
)) = self.repeat_state
{
if !*is_repeating {
// Start repeat
Expand All @@ -343,11 +347,13 @@ impl KimeContext {
}
}

pub fn run(display: &Display, event_queue: &mut EventQueue, globals: &GlobalManager) -> Result<(), Box<dyn Error>> {
let im_manager = globals
.instantiate_exact::<ZwpInputMethodManagerV2>(1)?;
let vk_manager = globals
.instantiate_exact::<ZwpVirtualKeyboardManagerV1>(1)?;
pub fn run(
display: &Display,
event_queue: &mut EventQueue,
globals: &GlobalManager,
) -> Result<(), Box<dyn Error>> {
let im_manager = globals.instantiate_exact::<ZwpInputMethodManagerV2>(1)?;
let vk_manager = globals.instantiate_exact::<ZwpVirtualKeyboardManagerV1>(1)?;
let seat = globals.instantiate_exact::<WlSeat>(1).expect("Load Seat");

let filter = Filter::new(|ev, _filter, mut data| {
Expand Down

0 comments on commit 3fc70ff

Please sign in to comment.