From 5af14ce88752b560cb5640550749de30b7843a42 Mon Sep 17 00:00:00 2001 From: David Edler Date: Mon, 18 Mar 2024 16:34:58 +0100 Subject: [PATCH] fix(terminal) forward scroll event from vm to parent container. fixes #700 Signed-off-by: David Edler --- src/lib/spice/src/inputs.js | 2 ++ src/lib/spice/src/resize.js | 4 ++-- .../instances/InstanceGraphicConsole.tsx | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/spice/src/inputs.js b/src/lib/spice/src/inputs.js index c0046bbbf..e96697f14 100644 --- a/src/lib/spice/src/inputs.js +++ b/src/lib/spice/src/inputs.js @@ -164,6 +164,8 @@ function handle_mousewheel(e) this.sc.inputs.send_msg(msg); e.preventDefault(); + + window.dispatchEvent(new CustomEvent("spice-wheel", { detail: { wheelEvent: e } })); } function handle_keydown(e) diff --git a/src/lib/spice/src/resize.js b/src/lib/spice/src/resize.js index 36454bde6..2e8875f4c 100644 --- a/src/lib/spice/src/resize.js +++ b/src/lib/spice/src/resize.js @@ -48,9 +48,9 @@ function resize_helper(sc) var height = window.innerHeight - wrapper.getBoundingClientRect().top; - /* leave a margin at the bottom when not in full screen */ + /* leave a margin at the bottom (and reserve status bar height) when not in full screen */ if (!isFullScreen) { - height = height - 20; + height = height - 65; } /* minimum height constraint */ diff --git a/src/pages/instances/InstanceGraphicConsole.tsx b/src/pages/instances/InstanceGraphicConsole.tsx index 573e45feb..fab98364a 100644 --- a/src/pages/instances/InstanceGraphicConsole.tsx +++ b/src/pages/instances/InstanceGraphicConsole.tsx @@ -16,6 +16,12 @@ declare global { } } +interface SpiceWheelEvent extends CustomEvent { + detail: { + wheelEvent: WheelEvent; + }; +} + interface Props { instance: LxdInstance; onMount: (handler: () => void) => void; @@ -42,7 +48,7 @@ const InstanceGraphicConsole: FC = ({ }; const handleResize = () => { - updateMaxHeight("spice-wrapper", undefined, 10); + updateMaxHeight("spice-wrapper"); SpiceHtml5.handle_resize(); }; @@ -109,6 +115,17 @@ const InstanceGraphicConsole: FC = ({ useEventListener("resize", handleResize); useEffect(handleResize, [notify.notification?.message]); + useEventListener("spice-wheel", (e) => { + if (!spiceRef.current?.parentElement || !Object.hasOwn(e, "detail")) { + return; + } + const wheelEvent = (e as SpiceWheelEvent).detail.wheelEvent; + spiceRef.current.parentElement.scrollBy( + wheelEvent.deltaX, + wheelEvent.deltaY, + ); + }); + useEffect(() => { notify.clear(); const websocketPromise = openVgaConsole();