correct cursor position, fix clipboard input

This commit is contained in:
Jovi Hsu 2021-11-29 15:50:38 +08:00
parent bfc9968d21
commit 88e415bd44
2 changed files with 7 additions and 6 deletions

View File

@ -200,7 +200,8 @@ impl Component for PageVnc {
{self.button_connect_view()}
<components::ws::WebsocketCtx
weak_link=websocket onrecv=recv_msg/>
<canvas id="remote-canvas" ref=self.canvas.clone()></canvas>
<canvas id="remote-canvas" ref=self.canvas.clone()
tabIndex=1></canvas>
<components::clipboard::Clipboard
weak_link=clipboard onsubmit=clipboard_update/>
{self.error_msg.clone()}
@ -369,7 +370,7 @@ impl PageVnc {
}
fn bind_mouse_and_key(&mut self, canvas: &HtmlCanvasElement) {
let window = web_sys::window().unwrap();
let _window = web_sys::window().unwrap();
let handler = self.handler.clone();
let key_down = move |e: KeyboardEvent| {
e.prevent_default();
@ -381,7 +382,7 @@ impl PageVnc {
let cb = Closure::wrap(handler);
window
canvas
.add_event_listener_with_callback("keydown", cb.as_ref().unchecked_ref())
.unwrap();
cb.forget();
@ -397,7 +398,7 @@ impl PageVnc {
let cb = Closure::wrap(handler);
window
canvas
.add_event_listener_with_callback("keyup", cb.as_ref().unchecked_ref())
.unwrap();
cb.forget();

View File

@ -17,8 +17,8 @@ impl MouseUtils {
event: web_sys::MouseEvent,
et: MouseEventType,
) -> (u16, u16, u8) {
let x: u16 = event.client_x().try_into().unwrap_or(0);
let y: u16 = event.client_y().try_into().unwrap_or(0);
let x: u16 = event.offset_x().try_into().unwrap_or(0);
let y: u16 = event.offset_y().try_into().unwrap_or(0);
let mask: u8 = (event.button() << 1).try_into().unwrap_or(0);
match et {