remove InputFunc
This commit is contained in:
parent
9651666d41
commit
a12f24bf16
@ -29,7 +29,8 @@ pub struct ConnInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum MessageInput {
|
enum MessageInput {
|
||||||
InputFunc(Box<dyn Send + FnMut()>),
|
Mouse((MouseEvent, i32)),
|
||||||
|
Key((KeyEvent, bool)),
|
||||||
BlockOn,
|
BlockOn,
|
||||||
BlockOff,
|
BlockOff,
|
||||||
PrivacyOn,
|
PrivacyOn,
|
||||||
@ -340,8 +341,18 @@ impl Connection {
|
|||||||
loop {
|
loop {
|
||||||
match receiver.recv_timeout(std::time::Duration::from_millis(500)) {
|
match receiver.recv_timeout(std::time::Duration::from_millis(500)) {
|
||||||
Ok(v) => match v {
|
Ok(v) => match v {
|
||||||
MessageInput::InputFunc(mut f) => {
|
MessageInput::Mouse((msg, id)) => {
|
||||||
f();
|
handle_mouse(&msg, id);
|
||||||
|
}
|
||||||
|
MessageInput::Key((mut msg, press)) => {
|
||||||
|
if press {
|
||||||
|
msg.down = true;
|
||||||
|
}
|
||||||
|
handle_key(&msg);
|
||||||
|
if press {
|
||||||
|
msg.down = false;
|
||||||
|
handle_key(&msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MessageInput::BlockOn => {
|
MessageInput::BlockOn => {
|
||||||
if crate::platform::block_input(true) {
|
if crate::platform::block_input(true) {
|
||||||
@ -653,6 +664,16 @@ impl Connection {
|
|||||||
s.send((Instant::now(), Arc::new(msg_out))).ok();
|
s.send((Instant::now(), Arc::new(msg_out))).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn input_mouse(&self, msg: MouseEvent, conn_id: i32) {
|
||||||
|
self.tx_input.send(MessageInput::Mouse((msg, conn_id))).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn input_key(&self, msg: KeyEvent, press: bool) {
|
||||||
|
self.tx_input.send(MessageInput::Key((msg, press))).ok();
|
||||||
|
}
|
||||||
|
|
||||||
async fn on_message(&mut self, msg: Message) -> bool {
|
async fn on_message(&mut self, msg: Message) -> bool {
|
||||||
if let Some(message::Union::login_request(lr)) = msg.union {
|
if let Some(message::Union::login_request(lr)) = msg.union {
|
||||||
if let Some(o) = lr.option.as_ref() {
|
if let Some(o) = lr.option.as_ref() {
|
||||||
@ -771,15 +792,10 @@ impl Connection {
|
|||||||
match msg.union {
|
match msg.union {
|
||||||
Some(message::Union::mouse_event(me)) => {
|
Some(message::Union::mouse_event(me)) => {
|
||||||
if self.keyboard {
|
if self.keyboard {
|
||||||
let conn_id = self.inner.id();
|
self.input_mouse(me, self.inner.id());
|
||||||
self.tx_input
|
|
||||||
.send(MessageInput::InputFunc(Box::new(move || {
|
|
||||||
handle_mouse(&me, conn_id)
|
|
||||||
})))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(message::Union::key_event(mut me)) => {
|
Some(message::Union::key_event(me)) => {
|
||||||
if self.keyboard {
|
if self.keyboard {
|
||||||
// handle all down as press
|
// handle all down as press
|
||||||
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which
|
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which
|
||||||
@ -790,32 +806,17 @@ impl Connection {
|
|||||||
me.press
|
me.press
|
||||||
};
|
};
|
||||||
if is_press {
|
if is_press {
|
||||||
if let Some(key_event::Union::unicode(_)) = me.union {
|
match me.union {
|
||||||
self.tx_input
|
Some(key_event::Union::unicode(_))
|
||||||
.send(MessageInput::InputFunc(Box::new(move || {
|
| Some(key_event::Union::seq(_)) => {
|
||||||
handle_key(&me)
|
self.input_key(me, false);
|
||||||
})))
|
}
|
||||||
.ok();
|
_ => {
|
||||||
} else if let Some(key_event::Union::seq(_)) = me.union {
|
self.input_key(me, true);
|
||||||
self.tx_input
|
}
|
||||||
.send(MessageInput::InputFunc(Box::new(move || {
|
|
||||||
handle_key(&me)
|
|
||||||
})))
|
|
||||||
.ok();
|
|
||||||
} else {
|
|
||||||
self.tx_input
|
|
||||||
.send(MessageInput::InputFunc(Box::new(move || {
|
|
||||||
me.down = true;
|
|
||||||
handle_key(&me);
|
|
||||||
me.down = false;
|
|
||||||
handle_key(&me);
|
|
||||||
})))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.tx_input
|
self.input_key(me, false);
|
||||||
.send(MessageInput::InputFunc(Box::new(move || handle_key(&me))))
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user