match all js keys to x11 keycodes

This commit is contained in:
Jovi Hsu 2021-11-23 11:50:27 +08:00
parent d7d503e49c
commit 5f33c9d510
5 changed files with 1963 additions and 28 deletions

View File

@ -331,8 +331,7 @@ impl PageRemote {
let handler = self.handler.clone();
let key_down = move |e: KeyboardEvent| {
e.stop_propagation();
ConsoleService::log(&format!("key down {}", e.key_code()));
handler.key_press(e.key_code(), true);
handler.key_press(e, true);
};
let handler = Box::new(key_down) as Box<dyn FnMut(_)>;
@ -347,7 +346,7 @@ impl PageRemote {
let handler = self.handler.clone();
let key_up = move |e: KeyboardEvent| {
e.stop_propagation();
handler.key_press(e.key_code(), false);
handler.key_press(e, false);
};
let handler = Box::new(key_up) as Box<dyn FnMut(_)>;
@ -359,21 +358,6 @@ impl PageRemote {
.unwrap();
cb.forget();
let handler = self.handler.clone();
let key_press = move |e: KeyboardEvent| {
e.stop_propagation();
ConsoleService::log(&format!("key press {}", e.key_code()));
};
let handler = Box::new(key_press) as Box<dyn FnMut(_)>;
let cb = Closure::wrap(handler);
window
.add_event_listener_with_callback("keypress", cb.as_ref().unchecked_ref())
.unwrap();
cb.forget();
// On a conventional mouse, buttons 1, 2, and 3 correspond to the left,
// middle, and right buttons on the mouse. On a wheel mouse, each step
// of the wheel upwards is represented by a press and release of button

View File

@ -78,7 +78,7 @@ where
.require_frame(incremental);
}
pub fn key_press(&self, key: u32, down: bool) {
pub fn key_press(&self, key: web_sys::KeyboardEvent, down: bool) {
self.inner.as_ref().lock().unwrap().key_press(key, down);
}
@ -92,12 +92,14 @@ where
}
pub trait ProtocalImpl {
fn new() -> Self;
fn new() -> Self
where
Self: Sized;
fn do_input(&mut self, input: Vec<u8>);
fn get_output(&mut self) -> Vec<ProtocalHandlerOutput>;
fn set_credential(&mut self, username: &str, password: &str);
fn set_resolution(&mut self, width: u16, height: u16);
fn key_press(&mut self, key: u32, down: bool);
fn key_press(&mut self, key: web_sys::KeyboardEvent, down: bool);
fn mouse_event(&mut self, x: u16, y: u16, button: u8);
fn require_frame(&mut self, incremental: u8);
}

View File

@ -1,2 +1,3 @@
mod des;
pub mod vnc;
mod x11keyboard;

View File

@ -1,5 +1,5 @@
use super::super::common::*;
use super::des;
use super::{super::common::*, x11keyboard};
use yew::services::ConsoleService;
const VNC_RFB33: &[u8; 12] = b"RFB 003.003\n";
@ -8,10 +8,6 @@ const VNC_RFB38: &[u8; 12] = b"RFB 003.008\n";
const VNC_VER_UNSUPPORTED: &str = "unsupported version";
const VNC_FAILED: &str = "Connection failed with unknow reason";
fn jskey_to_x11(key: u32) -> u32 {
key
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum SecurityType {
@ -167,12 +163,12 @@ impl ProtocalImpl for VncHandler {
// VNC client doen't support resolution change
}
fn key_press(&mut self, key: u32, down: bool) {
fn key_press(&mut self, key: web_sys::KeyboardEvent, down: bool) {
if self.state != VncState::Connected {
return;
}
if let ServerMessage::None = self.msg_handling {
let key = jskey_to_x11(key);
let key = x11keyboard::KeyboardUtils::get_keysym(key);
self.send_key_event(key, down);
}
}

File diff suppressed because it is too large Load Diff