Skip to content

Commit

Permalink
feat(console) add shortcuts for common keyboard combinations #381
Browse files Browse the repository at this point in the history
  • Loading branch information
edlerd committed Jun 9, 2023
1 parent 491ba41 commit 18acc38
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
43 changes: 34 additions & 9 deletions src/lib/spice/src/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,45 @@ function handle_keyup(e)
e.preventDefault();
}

function send_key(sc, keyCode)
{
var msg = new Messages.SpiceMiniData();
var key = new Messages.SpiceMsgcKeyDown();

key.code = keyCode;
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_DOWN, key);
sc.inputs.send_msg(msg);

key.code = 0x80|keyCode;
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_UP, key);
sc.inputs.send_msg(msg);
}

function sendCtrlAltDel(sc)
{
if (sc && sc.inputs && sc.inputs.state === "ready"){
var key = new Messages.SpiceMsgcKeyDown();
var msg = new Messages.SpiceMiniData();

update_modifier(true, KeyNames.KEY_LCtrl, sc);
update_modifier(true, KeyNames.KEY_Alt, sc);
send_key(sc, KeyNames.KEY_KP_Decimal);
if(Ctrl_state == false) update_modifier(false, KeyNames.KEY_LCtrl, sc);
if(Alt_state == false) update_modifier(false, KeyNames.KEY_Alt, sc);
}
}

key.code = KeyNames.KEY_KP_Decimal;
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_DOWN, key);
sc.inputs.send_msg(msg);
msg.build_msg(Constants.SPICE_MSGC_INPUTS_KEY_UP, key);
sc.inputs.send_msg(msg);
function sendAltF4(sc)
{
if (sc && sc.inputs && sc.inputs.state === "ready"){
update_modifier(true, KeyNames.KEY_Alt, sc);
send_key(sc, KeyNames.KEY_F4);
if(Alt_state == false) update_modifier(false, KeyNames.KEY_Alt, sc);
}
}

if(Ctrl_state == false) update_modifier(false, KeyNames.KEY_LCtrl, sc);
function sendAltTab(sc)
{
if (sc && sc.inputs && sc.inputs.state === "ready"){
update_modifier(true, KeyNames.KEY_Alt, sc);
send_key(sc, KeyNames.KEY_Tab);
if(Alt_state == false) update_modifier(false, KeyNames.KEY_Alt, sc);
}
}
Expand Down Expand Up @@ -295,4 +318,6 @@ export {
handle_keydown,
handle_keyup,
sendCtrlAltDel,
sendAltTab,
sendAltF4,
};
44 changes: 37 additions & 7 deletions src/pages/instances/InstanceConsole.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { FC, useState } from "react";
import { Button, RadioInput } from "@canonical/react-components";
import {
Button,
ContextualMenu,
RadioInput,
} from "@canonical/react-components";
import { Notification } from "types/notification";
import NotificationRowLegacy from "components/NotificationRowLegacy";
import InstanceGraphicConsole from "./InstanceGraphicConsole";
Expand All @@ -9,6 +13,11 @@ import { failure, info } from "context/notify";
import EmptyState from "components/EmptyState";
import SubmitButton from "components/SubmitButton";
import { useInstanceStart } from "util/instanceStart";
import {
sendAltF4,
sendAltTab,
sendCtrlAltDel,
} from "../../lib/spice/src/inputs";

interface Props {
instance: LxdInstance;
Expand Down Expand Up @@ -68,12 +77,33 @@ const InstanceConsole: FC<Props> = ({ instance }) => {
/>
</div>
{isGraphic && isRunning && (
<Button
className="u-no-margin--bottom"
onClick={() => handleFullScreen()}
>
<span>Fullscreen</span>
</Button>
<div>
<Button
className="u-no-margin--bottom"
onClick={() => handleFullScreen()}
>
<span>Fullscreen</span>
</Button>
<ContextualMenu
hasToggleIcon
toggleLabel="Shortcuts"
toggleClassName="u-no-margin--bottom"
links={[
{
children: "Send Ctrl + Alt + Del",
onClick: () => sendCtrlAltDel(window.spice_connection),
},
{
children: "Send Alt + TAB",
onClick: () => sendAltTab(window.spice_connection),
},
{
children: "Send Alt + F4",
onClick: () => sendAltF4(window.spice_connection),
},
]}
/>
</div>
)}
</div>
)}
Expand Down

0 comments on commit 18acc38

Please sign in to comment.