Skip to content

Commit

Permalink
fix(terminal) forward scroll event from vm to parent container. fixes #…
Browse files Browse the repository at this point in the history
…700

Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Mar 20, 2024
1 parent 29959d9 commit 5af14ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib/spice/src/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/spice/src/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
19 changes: 18 additions & 1 deletion src/pages/instances/InstanceGraphicConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ declare global {
}
}

interface SpiceWheelEvent extends CustomEvent {
detail: {
wheelEvent: WheelEvent;
};
}

interface Props {
instance: LxdInstance;
onMount: (handler: () => void) => void;
Expand All @@ -42,7 +48,7 @@ const InstanceGraphicConsole: FC<Props> = ({
};

const handleResize = () => {
updateMaxHeight("spice-wrapper", undefined, 10);
updateMaxHeight("spice-wrapper");
SpiceHtml5.handle_resize();
};

Expand Down Expand Up @@ -109,6 +115,17 @@ const InstanceGraphicConsole: FC<Props> = ({
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();
Expand Down

0 comments on commit 5af14ce

Please sign in to comment.