Add ctrl+alt+del

This commit is contained in:
Jovi Hsu 2022-10-08 07:06:58 +00:00
parent 67275f6be8
commit 8517df753b
5 changed files with 46 additions and 6 deletions

View File

@ -71,8 +71,7 @@
#clipboardtxt {
position: relative;
width: 100%;
top: 25%;
width: 90%;
margin: auto;
overflow: auto;
resize: none;

View File

@ -33,13 +33,19 @@
<body>
<div id="vnc_status" style="position: relative; height: auto;" class="horizontal-centre vertical-centre"></div>
<div id="canvas" class="horizontal-centre vertical-centre"><canvas id="vnc-canvas" tabIndex=1></canvas></div>
<div id="canvas" class="horizontal-centre vertical-centre">
<canvas id="vnc-canvas" tabIndex=1></canvas>
<button type="button" id="ctrlaltdel" style="display: inline; position:absolute; right: 10px; top: 10px;">Send
CtrlAltDel</button>
</div>
<div class="clipboardback">
<div class="clipboard">
<button id="clipboardbtn">clipboard</button>
<div id="clipboardbox" class="horizontal-centre vertical-centre">
<div><textarea id="clipboardtxt" rows="20"></textarea></div>
<div><button id="clipboardsend">Send</button></div>
<div style="position: relative; top: 50%; transform: translateY(-50%);">
<div><textarea id="clipboardtxt" rows="30"></textarea></div>
<div><button id="clipboardsend">Send</button></div>
</div>
</div>
</div>
</div>

View File

@ -3,7 +3,9 @@ use std::rc::Rc;
use crate::vnc::{ImageData, MouseEventType, Vnc};
use wasm_bindgen::prelude::*;
use wasm_bindgen::{Clamped, JsCast};
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement, KeyboardEvent, MouseEvent};
use web_sys::{
CanvasRenderingContext2d, HtmlButtonElement, HtmlCanvasElement, KeyboardEvent, MouseEvent,
};
struct Canvas {
canvas: HtmlCanvasElement,
ctx: CanvasRenderingContext2d,
@ -67,6 +69,26 @@ impl Canvas {
.unwrap();
cb.forget();
let handler = vnc.clone();
let ctrl_alt_del_btn = web_sys::window()
.unwrap()
.document()
.unwrap()
.get_element_by_id("ctrlaltdel")
.unwrap()
.dyn_into::<HtmlButtonElement>()
.map_err(|_| ())
.unwrap();
let ctrl_alt_del = move || {
handler.ctrl_alt_del();
};
let handler = Box::new(ctrl_alt_del) as Box<dyn FnMut()>;
let cb = Closure::wrap(handler);
ctrl_alt_del_btn.set_onclick(Some(cb.as_ref().unchecked_ref()));
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

@ -68,6 +68,10 @@ impl Vnc {
self.inner.lock().unwrap().mouse_event(mouse, et);
}
pub fn ctrl_alt_del(&self) {
self.inner.lock().unwrap().ctrl_alt_del();
}
pub fn close(&self) {
self.inner.lock().unwrap().close();
}

View File

@ -181,6 +181,15 @@ impl Vnc {
self.send_key_event(key, down);
}
pub fn ctrl_alt_del(&mut self) {
self.send_key_event(x11keyboard::XK_Control_L, true);
self.send_key_event(x11keyboard::XK_Alt_L, true);
self.send_key_event(x11keyboard::XK_Delete, true);
self.send_key_event(x11keyboard::XK_Control_L, false);
self.send_key_event(x11keyboard::XK_Alt_L, false);
self.send_key_event(x11keyboard::XK_Delete, false);
}
pub fn mouse_event(&mut self, mouse: web_sys::MouseEvent, et: MouseEventType) {
if self.state != VncState::Connected {
return;