mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-22 01:51:20 -08:00
Compare commits
3
Commits
main
...
hannah/keybinds
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9f13e90a2 | ||
|
|
518cdd3e39 | ||
|
|
1962c164c7 |
No files matched your search
@@ -605,6 +605,29 @@ settings-stay_aligned-debug-label = Debugging
|
||||
settings-stay_aligned-debug-description = Please include your settings when reporting problems about Stay Aligned.
|
||||
settings-stay_aligned-debug-copy-label = Copy settings to clipboard
|
||||
|
||||
settings-keybinds = Keybind settings
|
||||
settings-keybinds_ = ''
|
||||
settings-keybinds-description = Change keybinds for various shortcuts
|
||||
keybind_config-keybind_name = Keybind
|
||||
keybind_config-keybind_value = Combination
|
||||
keybind_config-keybind_delay = Delay before trigger (s)
|
||||
settings-keybinds_full-reset = Full Reset
|
||||
settings-keybinds_yaw-reset = Yaw Reset
|
||||
settings-keybinds_mounting-reset = Mounting Reset
|
||||
settings-keybinds_feet-mounting-reset = Feet Mounting Reset
|
||||
settings-keybinds_pause-tracking = Pause Tracking
|
||||
settings-keybinds_record-keybind = Click to record
|
||||
settings-keybinds_now-recording = Recording…
|
||||
settings-keybinds_reset-button = Reset
|
||||
settings-keybinds_reset-all-button = Reset all
|
||||
settings-keybinds-wayland-description = You appear to be using wayland, Please change your shortcuts in your system settings.
|
||||
settings-keybinds-wayland-open-system-settings-button = Open system settings
|
||||
settings-sidebar-keybinds = Keybinds
|
||||
settings-keybinds-recorder-modal-title = Assign keybind for
|
||||
settings-keybinds-recorder-modal-reset-button = Reset
|
||||
settings-keybinds-recorder-modal-unbind-button = Unbind
|
||||
settings-keybinds-recorder-modal-done-button = Done
|
||||
|
||||
## FK/Tracking settings
|
||||
settings-general-fk_settings = Tracking settings
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import { QuizSlimeSetQuestion } from './components/onboarding/pages/quiz/SlimeSe
|
||||
import { QuizUsageQuestion } from './components/onboarding/pages/quiz/UsageQuestion';
|
||||
import { QuizRuntimeQuestion } from './components/onboarding/pages/quiz/RuntimeQuestion';
|
||||
import { QuizMocapPosQuestion } from './components/onboarding/pages/quiz/MocapPreferencesQuestions';
|
||||
import { KeybindSettings } from './components/settings/pages/KeybindSettings';
|
||||
import { ElectronContextC, provideElectron } from './hooks/electron';
|
||||
import { AppLocalizationProvider } from './i18n/config';
|
||||
import { openUrl } from './hooks/crossplatform';
|
||||
@@ -145,6 +146,7 @@ function Layout() {
|
||||
<Route path="interface" element={<InterfaceSettings />} />
|
||||
<Route path="interface/home" element={<HomeScreenSettings />} />
|
||||
<Route path="advanced" element={<AdvancedSettings />} />
|
||||
<Route path="keybinds" element={<KeybindSettings />} />
|
||||
</Route>
|
||||
<Route
|
||||
path="/onboarding"
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { useState, forwardRef, useRef } from 'react';
|
||||
import { Typography } from './Typography';
|
||||
import classNames from 'classnames';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
|
||||
const excludedKeys = [' ', 'SPACE', 'META'];
|
||||
const maxKeybindLength = 4;
|
||||
|
||||
export const KeybindRecorder = forwardRef<
|
||||
HTMLInputElement,
|
||||
{
|
||||
keys: string[];
|
||||
onKeysChange: (v: string[]) => void;
|
||||
error?: string;
|
||||
}
|
||||
>(function KeybindRecorder({ keys, onKeysChange, error }) {
|
||||
const [localKeys, setLocalKeys] = useState<string[]>(keys);
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
const [oldKeys, setOldKeys] = useState<string[]>([]);
|
||||
const [invalidSlot, setInvalidSlot] = useState<number | null>(null);
|
||||
const [errorText, setErrorText] = useState<string>('');
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const displayKeys = isRecording ? localKeys : keys;
|
||||
const activeIndex = isRecording ? displayKeys.length : -1;
|
||||
const displayError = errorText || error;
|
||||
|
||||
const { clearErrors } = useFormContext();
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
e.preventDefault();
|
||||
const key = e.key.toUpperCase();
|
||||
const errorMsg = excludedKeys.includes(key)
|
||||
? `Cannot use ${key}!`
|
||||
: displayKeys.includes(key)
|
||||
? `${key} is a Duplicate Key!`
|
||||
: null;
|
||||
if (errorMsg) {
|
||||
setErrorText(errorMsg);
|
||||
setInvalidSlot(activeIndex);
|
||||
setTimeout(() => {
|
||||
setInvalidSlot(null);
|
||||
}, 350);
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayKeys.length < maxKeybindLength) {
|
||||
const updatedKeys = [...displayKeys, key];
|
||||
setLocalKeys(updatedKeys);
|
||||
onKeysChange(updatedKeys);
|
||||
if (updatedKeys.length == maxKeybindLength) {
|
||||
inputRef.current?.blur();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnBlur = () => {
|
||||
setIsRecording(false);
|
||||
if (displayKeys.length < maxKeybindLength - 2 || error) {
|
||||
onKeysChange(oldKeys);
|
||||
setLocalKeys(oldKeys);
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnFocus = () => {
|
||||
clearErrors('keybinds');
|
||||
const initialKeys: string[] = [];
|
||||
setOldKeys(keys);
|
||||
setLocalKeys(initialKeys);
|
||||
onKeysChange(initialKeys);
|
||||
setIsRecording(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full justify-center items-center flex flex-col gap-2">
|
||||
<div className="flex gap-2 p-2 items-center rounded-lg relative">
|
||||
<input
|
||||
autoFocus
|
||||
ref={inputRef}
|
||||
className="opacity-0 absolute cursor-pointer w-full"
|
||||
onFocus={handleOnFocus}
|
||||
onBlur={handleOnBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
/>
|
||||
<div className="flex flex-grow gap-2 justify-center h-full">
|
||||
{Array.from({ length: maxKeybindLength }).map((_, i) => {
|
||||
const key = displayKeys[i];
|
||||
const isActive = isRecording && i === activeIndex;
|
||||
const isInvalid = invalidSlot === i;
|
||||
return (
|
||||
<div key={i} className="flex flex-row">
|
||||
<div
|
||||
className={classNames(
|
||||
'flex p-2 rounded-lg min-w-[50px] min-h-[50px] text-main-title justify-center items-center bg-background-80 mobile:text-sm',
|
||||
{
|
||||
'keyslot-invalid ring-2 ring-status-critical': isInvalid,
|
||||
'keyslot-animate ring-2 ring-accent':
|
||||
isActive && !isInvalid,
|
||||
'ring-accent': !isInvalid && !isInvalid,
|
||||
}
|
||||
)}
|
||||
>
|
||||
{key ?? ''}
|
||||
</div>
|
||||
<div className="flex pl-2 text-main-title justify-center items-center mobile:text-sm">
|
||||
{i < maxKeybindLength - 1 ? '+' : ''}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{displayError && (
|
||||
<div className="isInvalid keyslot-invalid">
|
||||
<Typography color="text-status-critical">{`${errorText} ${error}`}</Typography>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import { BaseModal } from './BaseModal';
|
||||
import {
|
||||
Controller,
|
||||
Control,
|
||||
useFormContext,
|
||||
FieldValues,
|
||||
FieldPath,
|
||||
} from 'react-hook-form';
|
||||
import { KeybindRecorder } from './KeybindRecorder';
|
||||
import { Typography } from './Typography';
|
||||
import { Button } from './Button';
|
||||
import './KeybindRow.scss';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
|
||||
export function KeybindRecorderModal<T extends FieldValues = FieldValues>({
|
||||
id,
|
||||
control,
|
||||
name,
|
||||
isVisisble,
|
||||
onClose,
|
||||
onUnbind,
|
||||
onSubmit,
|
||||
}: {
|
||||
id?: string;
|
||||
control: Control<T>;
|
||||
name: FieldPath<T>;
|
||||
isVisisble: boolean;
|
||||
onClose: () => void;
|
||||
onUnbind: () => void;
|
||||
onSubmit: () => void;
|
||||
}) {
|
||||
const { l10n } = useLocalization();
|
||||
const keybindlocalization = 'settings-keybinds_' + id;
|
||||
const {
|
||||
formState: { errors },
|
||||
resetField,
|
||||
handleSubmit,
|
||||
} = useFormContext();
|
||||
|
||||
return (
|
||||
<BaseModal
|
||||
isOpen={isVisisble}
|
||||
onRequestClose={onClose}
|
||||
appendClasses="w-full max-w-xl"
|
||||
>
|
||||
<div className="flex flex-col gap-3 w-full justify-between h-full">
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-keybinds-recorder-modal-title')}{' '}
|
||||
{l10n.getString(keybindlocalization)}
|
||||
</Typography>
|
||||
<Controller
|
||||
control={control}
|
||||
name={name}
|
||||
render={({ field }) => (
|
||||
<KeybindRecorder
|
||||
keys={field.value ?? []}
|
||||
onKeysChange={field.onChange}
|
||||
ref={field.ref}
|
||||
error={errors.keybinds?.message as string}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<div className="flex flex-row justify-between w-full">
|
||||
<div className="flex flex-row justify-start gap-4">
|
||||
<Button
|
||||
id="settings-keybinds-recorder-modal-reset-button"
|
||||
variant="tertiary"
|
||||
onClick={() => {
|
||||
resetField(name);
|
||||
handleSubmit(onSubmit)();
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
id="settings-keybinds-recorder-modal-unbind-button"
|
||||
variant="tertiary"
|
||||
onClick={() => {
|
||||
onUnbind();
|
||||
handleSubmit(onSubmit)();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row justify-end">
|
||||
<Button
|
||||
id="settings-keybinds-recorder-modal-done-button"
|
||||
variant="primary"
|
||||
onClick={handleSubmit(onSubmit)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BaseModal>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
.keybind-row {
|
||||
display: grid;
|
||||
grid-column: 1 / -1;
|
||||
grid-template-columns: subgrid;
|
||||
height: auto;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
@keyframes keyslot {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: scale(1.08);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes shake {
|
||||
0% {
|
||||
transform: translate(1px, 1px) rotate(0deg);
|
||||
}
|
||||
10% {
|
||||
transform: translate(-1px, -2px) rotate(-1deg);
|
||||
}
|
||||
20% {
|
||||
transform: translate(-3px, 0px) rotate(1deg);
|
||||
}
|
||||
30% {
|
||||
transform: translate(3px, 2px) rotate(0deg);
|
||||
}
|
||||
40% {
|
||||
transform: translate(1px, -1px) rotate(1deg);
|
||||
}
|
||||
50% {
|
||||
transform: translate(-1px, 2px) rotate(-1deg);
|
||||
}
|
||||
60% {
|
||||
transform: translate(-3px, 1px) rotate(0deg);
|
||||
}
|
||||
70% {
|
||||
transform: translate(3px, 1px) rotate(-1deg);
|
||||
}
|
||||
80% {
|
||||
transform: translate(-1px, -1px) rotate(1deg);
|
||||
}
|
||||
90% {
|
||||
transform: translate(1px, 2px) rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: translate(1px, -2px) rotate(-1deg);
|
||||
}
|
||||
}
|
||||
|
||||
.keyslot-animate {
|
||||
animation: keyslot 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.keyslot-invalid {
|
||||
animation: shake 0.35s ease;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { Typography } from './Typography';
|
||||
import './KeybindRow.scss';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Control,
|
||||
FieldPath,
|
||||
FieldValues,
|
||||
UseFormGetValues,
|
||||
} from 'react-hook-form';
|
||||
import { NumberSelector } from './NumberSelector';
|
||||
import { useLocaleConfig } from '@/i18n/config';
|
||||
|
||||
function KeyBindKeyList({ keybind }: { keybind: string[] }) {
|
||||
if (keybind.length <= 1) {
|
||||
return (
|
||||
<div className="flex h-full text-section-title items-center justifiy-center">
|
||||
Click to edit keybind
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return keybind.map((key, i) => {
|
||||
return (
|
||||
<div key={i} className="flex flex-row">
|
||||
<div className="flex flex-wrap p-2 rounded-lg min-w-[50px] text-standard-bold justify-center items-center bg-background-80 mobile:text-sm">
|
||||
{key ?? ''}
|
||||
</div>
|
||||
<div className="flex justify-center items-center text-section-title mobile:text-sm gap-2 pl-3">
|
||||
{i < keybind.length - 1 ? '+' : ''}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function KeybindsRow<T extends FieldValues = FieldValues>({
|
||||
id,
|
||||
control,
|
||||
index,
|
||||
getValue,
|
||||
openKeybindRecorderModal,
|
||||
}: {
|
||||
id?: string;
|
||||
control: Control<T>;
|
||||
index: number;
|
||||
getValue: UseFormGetValues<any>;
|
||||
openKeybindRecorderModal: (index: number) => void;
|
||||
}) {
|
||||
const [binding, setBinding] = useState<string[]>();
|
||||
const { currentLocales } = useLocaleConfig();
|
||||
const secondsFormat = new Intl.NumberFormat(currentLocales, {
|
||||
style: 'unit',
|
||||
unit: 'second',
|
||||
unitDisplay: 'narrow',
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
|
||||
const handleOpenModal = () => {
|
||||
openKeybindRecorderModal(index);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setBinding(getValue(`keybinds.${index}.binding`));
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="keybind-row bg-background-60 rounded-xl h-full keybinds-small:flex keybinds-small:flex-col keybinds-small:justify-center keybinds-small:items-center p-2">
|
||||
<label className="text-sm font-medium text-background-10 keybinds-small:flex keybinds-small:py-2 keybinds-small:justify-center keybinds-small:align-middle">
|
||||
<Typography id={`settings-keybinds_${id}`} />
|
||||
</label>
|
||||
<div
|
||||
className="flex gap-2 h-full items-center rounded-lg bg-background-70 hover:bg-background-50 w-full"
|
||||
onClick={handleOpenModal}
|
||||
>
|
||||
<div className="flex flex-grow gap-2 justify-center p-2 h-[50px]">
|
||||
{binding != null && <KeyBindKeyList keybind={binding} />}
|
||||
</div>
|
||||
</div>
|
||||
<NumberSelector
|
||||
control={control}
|
||||
name={`keybinds.${index}.delay` as FieldPath<T>}
|
||||
valueLabelFormat={(value) => secondsFormat.format(value)}
|
||||
min={0}
|
||||
max={10}
|
||||
step={0.2}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -57,60 +57,62 @@ export function NumberSelector<T extends FieldValues = FieldValues>({
|
||||
<Controller
|
||||
control={control}
|
||||
name={name}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<div className="flex flex-col gap-1 w-full">
|
||||
<Typography bold>{label}</Typography>
|
||||
<div className="flex gap-5 bg-background-60 p-2 rounded-lg">
|
||||
<div className="flex gap-1">
|
||||
{doubleStep !== undefined && (
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<div className="flex flex-col gap-1 w-full">
|
||||
{label?.length != 0 ? <Typography bold>{label}</Typography> : <></>}
|
||||
<div className="flex gap-5 bg-background-60 p-2 rounded-lg">
|
||||
<div className="flex gap-1">
|
||||
{doubleStep !== undefined && (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, false))}
|
||||
disabled={doubleStepFn(value, false) < min || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(-doubleStep)
|
||||
: '--'}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, false))}
|
||||
disabled={doubleStepFn(value, false) < min || disabled}
|
||||
onClick={() => onChange(stepFn(value, false))}
|
||||
disabled={stepFn(value, false) < min || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(-doubleStep)
|
||||
: '--'}
|
||||
-
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(stepFn(value, false))}
|
||||
disabled={stepFn(value, false) < min || disabled}
|
||||
>
|
||||
-
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex flex-grow justify-center text-center items-center w-10 text-standard">
|
||||
{valueLabelFormat ? valueLabelFormat(value) : value}
|
||||
</div>
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(stepFn(value, true))}
|
||||
disabled={stepFn(value, true) > max || disabled}
|
||||
>
|
||||
+
|
||||
</Button>
|
||||
{doubleStep !== undefined && (
|
||||
</div>
|
||||
<div className="flex flex-grow justify-center text-center items-center w-10 text-standard">
|
||||
{valueLabelFormat ? valueLabelFormat(value) : value}
|
||||
</div>
|
||||
<div className="flex gap-1">
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, true))}
|
||||
disabled={doubleStepFn(value, true) > max || disabled}
|
||||
onClick={() => onChange(stepFn(value, true))}
|
||||
disabled={stepFn(value, true) > max || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(doubleStep)
|
||||
: '++'}
|
||||
+
|
||||
</Button>
|
||||
)}
|
||||
{doubleStep !== undefined && (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
rounded
|
||||
onClick={() => onChange(doubleStepFn(value, true))}
|
||||
disabled={doubleStepFn(value, true) > max || disabled}
|
||||
>
|
||||
{showButtonWithNumber
|
||||
? decimalFormat.format(doubleStep)
|
||||
: '++'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export function ResetSettingIcon({ size = 24 }: { size?: number }) {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
height={size}
|
||||
viewBox="0 -960 960 960"
|
||||
width={size}
|
||||
fill="#00000"
|
||||
>
|
||||
<path d="M520-330v-60h160v60H520Zm60 210v-50h-60v-60h60v-50h60v160h-60Zm100-50v-60h160v60H680Zm40-110v-160h60v50h60v60h-60v50h-60Zm111-280h-83q-26-88-99-144t-169-56q-117 0-198.5 81.5T200-480q0 72 32.5 132t87.5 98v-110h80v240H160v-80h94q-62-50-98-122.5T120-480q0-75 28.5-140.5t77-114q48.5-48.5 114-77T480-840q129 0 226.5 79.5T831-560Z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -4,21 +4,19 @@ import { BaseModal } from '@/components/commons/BaseModal';
|
||||
import { CheckboxInternal } from '@/components/commons/Checkbox';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
import { useElectron } from '@/hooks/electron';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import { RpcMessage, InstalledInfoResponseT } from 'solarxr-protocol';
|
||||
import { useConfig } from '@/hooks/config';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { useAppContext } from '@/hooks/app';
|
||||
|
||||
export function UdevRulesModal() {
|
||||
const { config, setConfig } = useConfig();
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
const electron = useElectron();
|
||||
const [udevContent, setUdevContent] = useState('');
|
||||
const [isUdevInstalledResponse, setIsUdevInstalledResponse] = useState(true);
|
||||
const [showUdevWarning, setShowUdevWarning] = useState(false);
|
||||
const [dontShowThisSession, setDontShowThisSession] = useState(false);
|
||||
const [dontShowAgain, setDontShowAgain] = useState(false);
|
||||
const { l10n } = useLocalization();
|
||||
const { installInfo } = useAppContext();
|
||||
|
||||
const handleUdevContent = async () => {
|
||||
if (electron.isElectron) {
|
||||
@@ -38,28 +36,14 @@ export function UdevRulesModal() {
|
||||
if (!config) throw 'Invalid state!';
|
||||
if (electron.isElectron) {
|
||||
const isLinux = electron.data().os.type === 'linux';
|
||||
const udevMissing = !isUdevInstalledResponse;
|
||||
const udevMissing = !installInfo?.isUdevInstalled;
|
||||
const notHiddenGlobally = !config.dontShowUdevModal;
|
||||
const notHiddenThisSession = !dontShowThisSession;
|
||||
const shouldShow =
|
||||
isLinux && udevMissing && notHiddenGlobally && notHiddenThisSession;
|
||||
setShowUdevWarning(shouldShow);
|
||||
}
|
||||
}, [config, isUdevInstalledResponse, dontShowThisSession]);
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.InstalledInfoRequest,
|
||||
new InstalledInfoResponseT()
|
||||
);
|
||||
}, []);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.InstalledInfoResponse,
|
||||
({ isUdevInstalled }: InstalledInfoResponseT) => {
|
||||
setIsUdevInstalledResponse(isUdevInstalled);
|
||||
}
|
||||
);
|
||||
}, [config, dontShowThisSession]);
|
||||
|
||||
const handleModalClose = () => {
|
||||
if (!config) throw 'Invalid State!';
|
||||
@@ -72,7 +56,7 @@ export function UdevRulesModal() {
|
||||
};
|
||||
|
||||
return (
|
||||
<BaseModal isOpen={showUdevWarning} appendClasses={'w-full max-w-2xl'}>
|
||||
<BaseModal isOpen={showUdevWarning} appendClasses="w-full max-w-2xl">
|
||||
<div className="flex w-full h-full flex-col gap-4">
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-col gap-2">
|
||||
|
||||
@@ -58,6 +58,10 @@ export function SettingSelectorMobile() {
|
||||
label: l10n.getString('settings-sidebar-advanced'),
|
||||
value: { url: '/settings/advanced' },
|
||||
},
|
||||
{
|
||||
label: l10n.getString('settings-sidebar-keybinds'),
|
||||
value: { url: '/settings/keybinds' },
|
||||
},
|
||||
{
|
||||
label: l10n.getString('navbar-onboarding'),
|
||||
value: { url: '/onboarding/home' },
|
||||
|
||||
@@ -73,6 +73,13 @@ export function SettingsSidebar() {
|
||||
scrollTo="gestureControl"
|
||||
id="settings-sidebar-gesture_control"
|
||||
/>
|
||||
{
|
||||
<SettingsLink
|
||||
to="/settings/keybinds"
|
||||
scrollTo="keybinds"
|
||||
id="settings-sidebar-keybinds"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3">
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
.keybind-settings {
|
||||
display: grid;
|
||||
|
||||
grid-template:
|
||||
'n v d ' auto
|
||||
'k k k ' auto
|
||||
'b . . ' auto
|
||||
/ 1fr 1fr 90px;
|
||||
|
||||
grid-template-columns: subgrid;
|
||||
grid-template-rows: subgrid;
|
||||
|
||||
align-items: left;
|
||||
gap: 10px;
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
import { KeybindRecorderModal } from '@/components/commons/KeybindRecorderModal';
|
||||
import {
|
||||
SettingsPageLayout,
|
||||
SettingsPagePaneLayout,
|
||||
} from '@/components/settings/SettingsPageLayout';
|
||||
import { WrenchIcon } from '@/components/commons/icon/WrenchIcons';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import './KeybindSettings.scss';
|
||||
import { Button } from '@/components/commons/Button';
|
||||
import { KeybindsRow } from '@/components/commons/KeybindsRow';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
ChangeKeybindRequestT,
|
||||
KeybindRequestT,
|
||||
KeybindResponseT,
|
||||
KeybindT,
|
||||
OpenUriRequestT,
|
||||
RpcMessage,
|
||||
} from 'solarxr-protocol';
|
||||
import {
|
||||
FieldPath,
|
||||
FormProvider,
|
||||
useFieldArray,
|
||||
useForm,
|
||||
} from 'react-hook-form';
|
||||
import { useAppContext } from '@/hooks/app';
|
||||
import { useElectron } from '@/hooks/electron';
|
||||
|
||||
export type KeybindForm = {
|
||||
keybinds: {
|
||||
id: number;
|
||||
name: string;
|
||||
binding: string[];
|
||||
delay: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
export function KeybindSettings() {
|
||||
const electron = useElectron();
|
||||
const { l10n } = useLocalization();
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||
const [defaultKeybindsState, setDefaultKeybindsState] = useState<KeybindForm>(
|
||||
{
|
||||
keybinds: [],
|
||||
}
|
||||
);
|
||||
const currentIndex = useRef<number | null>(null);
|
||||
const { installInfo } = useAppContext();
|
||||
|
||||
const methods = useForm<KeybindForm>({
|
||||
defaultValues: defaultKeybindsState,
|
||||
});
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
setValue,
|
||||
getValues,
|
||||
setError,
|
||||
clearErrors,
|
||||
resetField,
|
||||
} = methods;
|
||||
|
||||
const { fields } = useFieldArray({
|
||||
control,
|
||||
name: 'keybinds',
|
||||
});
|
||||
|
||||
const onSubmit = () => {
|
||||
const value = getValues();
|
||||
if (checkDuplicates(value)) {
|
||||
return;
|
||||
}
|
||||
clearErrors('keybinds');
|
||||
|
||||
value.keybinds.forEach((kb) => {
|
||||
const changeKeybindRequest = new ChangeKeybindRequestT();
|
||||
|
||||
const keybind = new KeybindT();
|
||||
keybind.keybindId = kb.id;
|
||||
keybind.keybindNameId = kb.name;
|
||||
keybind.keybindValue = kb.binding.join('+');
|
||||
keybind.keybindDelay = kb.delay;
|
||||
|
||||
changeKeybindRequest.keybind = keybind;
|
||||
|
||||
sendRPCPacket(RpcMessage.ChangeKeybindRequest, changeKeybindRequest);
|
||||
setIsOpen(false);
|
||||
});
|
||||
};
|
||||
|
||||
const checkDuplicates = (value: KeybindForm) => {
|
||||
const normalized = value.keybinds
|
||||
.filter((kb) => kb.binding.length > 0)
|
||||
.map((kb) => JSON.stringify([...kb.binding].sort()));
|
||||
|
||||
const unique = new Set(normalized);
|
||||
|
||||
if (unique.size !== normalized.length) {
|
||||
setError('keybinds', {
|
||||
type: 'manual',
|
||||
message: 'Duplicate keybind combinations are not allowed',
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleOpenSystemSettingsButton = () => {
|
||||
sendRPCPacket(RpcMessage.OpenUriRequest, new OpenUriRequestT());
|
||||
};
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.KeybindResponse,
|
||||
({ keybind, defaultKeybinds }: KeybindResponseT) => {
|
||||
if (!keybind) return;
|
||||
|
||||
const mappedDefaults = defaultKeybinds.map((kb) => ({
|
||||
id: kb.keybindId,
|
||||
name: typeof kb.keybindNameId === 'string' ? kb.keybindNameId : '',
|
||||
binding:
|
||||
typeof kb.keybindValue === 'string' ? kb.keybindValue.split('+') : [],
|
||||
delay: kb.keybindDelay,
|
||||
}));
|
||||
|
||||
setDefaultKeybindsState({ keybinds: mappedDefaults });
|
||||
reset({ keybinds: mappedDefaults });
|
||||
|
||||
const mapped = keybind.map((kb) => ({
|
||||
id: kb.keybindId,
|
||||
name: typeof kb.keybindNameId === 'string' ? kb.keybindNameId : '',
|
||||
binding:
|
||||
typeof kb.keybindValue === 'string' ? kb.keybindValue.split('+') : [],
|
||||
delay: kb.keybindDelay,
|
||||
}));
|
||||
|
||||
mapped.forEach((keybind, index) => {
|
||||
setValue(`keybinds.${index}.binding`, keybind.binding);
|
||||
setValue(`keybinds.${index}.delay`, keybind.delay);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
const handleOpenRecorderModal = (index: number) => {
|
||||
currentIndex.current = index;
|
||||
if (currentIndex !== null) {
|
||||
setIsOpen(true);
|
||||
}
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
if (currentIndex.current != null) {
|
||||
resetField(`keybinds.${currentIndex.current}.binding`);
|
||||
}
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
const createKeybindRows = (): ReactNode => {
|
||||
return fields.map((field, index) => {
|
||||
return (
|
||||
<div className="keybind-row" key={index}>
|
||||
<KeybindsRow
|
||||
id={typeof field.name === 'string' ? field.name : ''}
|
||||
control={control}
|
||||
index={index}
|
||||
getValue={getValues}
|
||||
openKeybindRecorderModal={handleOpenRecorderModal}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.KeybindRequest, new KeybindRequestT());
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<SettingsPageLayout>
|
||||
<SettingsPagePaneLayout icon={<WrenchIcon />} id="keybinds">
|
||||
<div className="flex flex-col gap-2">
|
||||
<Typography variant="main-title" id="settings-keybinds" />
|
||||
<div className="flex flex-col pt-2 pb-4">
|
||||
{l10n
|
||||
.getString('settings-keybinds-description')
|
||||
.split('\n')
|
||||
.map((line, i) => (
|
||||
<Typography key={i}>{line}</Typography>
|
||||
))}
|
||||
</div>
|
||||
{!installInfo?.isWayland ? (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Typography id="settings-keybinds-wayland-description" />
|
||||
<div>
|
||||
<Button
|
||||
id="settings-keybinds-wayland-open-system-settings-button"
|
||||
className="flex flex-col"
|
||||
onClick={handleOpenSystemSettingsButton}
|
||||
variant="primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
electron.isElectron &&
|
||||
electron.data().os.type !== 'windows' && (
|
||||
<>
|
||||
<FormProvider {...methods}>
|
||||
<div className="keybind-settings">
|
||||
<Typography
|
||||
id="keybind_config-keybind_name"
|
||||
variant="section-title"
|
||||
/>
|
||||
<Typography
|
||||
id="keybind_config-keybind_value"
|
||||
variant="section-title"
|
||||
/>
|
||||
<Typography
|
||||
id="keybind_config-keybind_delay"
|
||||
variant="section-title"
|
||||
/>
|
||||
{createKeybindRows()}
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
id="settings-keybinds_reset-all-button"
|
||||
onClick={() => {
|
||||
reset(defaultKeybindsState);
|
||||
handleSubmit(onSubmit)();
|
||||
}}
|
||||
variant="primary"
|
||||
/>
|
||||
</div>
|
||||
<KeybindRecorderModal
|
||||
id={
|
||||
currentIndex.current != null
|
||||
? fields[currentIndex.current].name
|
||||
: ''
|
||||
}
|
||||
control={control}
|
||||
name={
|
||||
(currentIndex.current != null
|
||||
? `keybinds.${currentIndex.current}.binding`
|
||||
: '') as FieldPath<KeybindForm>
|
||||
}
|
||||
isVisisble={isOpen}
|
||||
onClose={onClose}
|
||||
onUnbind={() => {
|
||||
if (currentIndex.current != null)
|
||||
setValue(
|
||||
`keybinds.${currentIndex.current}.binding`,
|
||||
[]
|
||||
);
|
||||
}}
|
||||
onSubmit={onSubmit}
|
||||
/>
|
||||
</FormProvider>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</SettingsPagePaneLayout>
|
||||
</SettingsPageLayout>
|
||||
);
|
||||
}
|
||||
+23
-2
@@ -5,6 +5,7 @@ import {
|
||||
ResetResponseT,
|
||||
RpcMessage,
|
||||
StartDataFeedT,
|
||||
InstalledInfoResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { handleResetSounds } from '@/sounds/sounds';
|
||||
import { useConfig } from './config';
|
||||
@@ -18,11 +19,17 @@ import { DEFAULT_LOCALE, LangContext } from '@/i18n/config';
|
||||
|
||||
export interface AppContext {
|
||||
currentFirmwareRelease: FirmwareRelease | null;
|
||||
installInfo: InstalledInfoResponseT | null;
|
||||
}
|
||||
|
||||
export function useProvideAppContext(): AppContext {
|
||||
const { useRPCPacket, sendDataFeedPacket, useDataFeedPacket, isConnected } =
|
||||
useWebsocketAPI();
|
||||
const {
|
||||
useRPCPacket,
|
||||
sendRPCPacket,
|
||||
sendDataFeedPacket,
|
||||
useDataFeedPacket,
|
||||
isConnected,
|
||||
} = useWebsocketAPI();
|
||||
const { changeLocales } = useContext(LangContext);
|
||||
const { config } = useConfig();
|
||||
const { dataFeedConfig } = useDataFeedConfig();
|
||||
@@ -34,6 +41,8 @@ export function useProvideAppContext(): AppContext {
|
||||
const [currentFirmwareRelease, setCurrentFirmwareRelease] =
|
||||
useState<FirmwareRelease | null>(null);
|
||||
|
||||
const [installInfo, setInstallInfo] = useState<InstalledInfoResponseT | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (isConnected) {
|
||||
const startDataFeed = new StartDataFeedT();
|
||||
@@ -70,6 +79,17 @@ export function useProvideAppContext(): AppContext {
|
||||
};
|
||||
}, [config?.uuid]);
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.InstalledInfoRequest, new InstalledInfoResponseT());
|
||||
}, []);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.InstalledInfoResponse,
|
||||
({ isUdevInstalled, isWayland }: InstalledInfoResponseT) => {
|
||||
setInstallInfo(new InstalledInfoResponseT(isUdevInstalled, isWayland));
|
||||
}
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
changeLocales([config?.lang || DEFAULT_LOCALE]);
|
||||
}, []);
|
||||
@@ -85,6 +105,7 @@ export function useProvideAppContext(): AppContext {
|
||||
|
||||
return {
|
||||
currentFirmwareRelease,
|
||||
installInfo,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ const config = {
|
||||
lg: '1300px',
|
||||
xl: '1600px',
|
||||
tall: { raw: '(min-height: 860px)' },
|
||||
'keybinds-small': { raw: 'not (min-width: 1230px)' },
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
|
||||
@@ -83,6 +83,8 @@ dependencies {
|
||||
implementation("com.mayakapps.kache:kache:2.1.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
|
||||
|
||||
implementation("com.github.HannahPadd:DbusGlobalShortcutsWayland:v0.1.0")
|
||||
|
||||
api("com.github.loucass003:EspflashKotlin:v0.11.0")
|
||||
|
||||
// Allow the use of reflection
|
||||
|
||||
@@ -2,51 +2,49 @@ package dev.slimevr
|
||||
|
||||
import com.melloware.jintellitype.HotkeyListener
|
||||
import com.melloware.jintellitype.JIntellitype
|
||||
import dev.hannah.portals.PortalManager
|
||||
import dev.hannah.portals.globalShortcuts.Shortcut
|
||||
import dev.hannah.portals.globalShortcuts.ShortcutTuple
|
||||
import dev.slimevr.config.KeybindingsConfig
|
||||
import dev.slimevr.tracking.trackers.TrackerUtils
|
||||
import io.eiren.util.OperatingSystem
|
||||
import io.eiren.util.OperatingSystem.Companion.currentPlatform
|
||||
import io.eiren.util.ann.AWTThread
|
||||
import io.eiren.util.logging.LogManager
|
||||
import solarxr_protocol.rpc.KeybindId
|
||||
|
||||
enum class Keybinds(val id: Int, val keybindName: String, val description: String, val keybind: String) {
|
||||
FULL_RESET(KeybindId.FULL_RESET, "FULL_RESET", "Full Reset", "CTRL+ALT+SHIFT+Y"),
|
||||
MOUNTING_RESET(KeybindId.MOUNTING_RESET, "MOUNTING_RESET", "Mounting Reset", "CTRL+ALT+SHIFT+I"),
|
||||
PAUSE_TRACKING(KeybindId.PAUSE_TRACKING, "PAUSE_TRACKING", "Pause Tracking", "CTRL+ALT+SHIFT+O"),
|
||||
YAW_RESET(KeybindId.YAW_RESET, "YAW_RESET", "Yaw Reset", "CTRL+ALT+SHIFT+U"),
|
||||
FEET_MOUNTING_RESET(KeybindId.FEET_MOUNTING_RESET, "FEET_MOUNTING_RESET", "Feet Mounting Reset", "CTRL+ALT+SHIFT+P"),
|
||||
;
|
||||
|
||||
override fun toString(): String = keybindName
|
||||
|
||||
companion object {
|
||||
private val byId = Keybinds.entries.associateBy { it.id }
|
||||
private val byName = Keybinds.entries.associateBy { it.keybindName }
|
||||
|
||||
fun getById(value: Int): Keybinds? = byId[value]
|
||||
fun getByName(name: String): Keybinds? = byName[name]
|
||||
}
|
||||
}
|
||||
|
||||
class Keybinding @AWTThread constructor(val server: VRServer) : HotkeyListener {
|
||||
val config: KeybindingsConfig = server.configManager.vrConfig.keybindings
|
||||
|
||||
init {
|
||||
if (currentPlatform != OperatingSystem.WINDOWS) {
|
||||
LogManager
|
||||
.info(
|
||||
"[Keybinding] Currently only supported on Windows. Keybindings will be disabled.",
|
||||
)
|
||||
} else {
|
||||
if (currentPlatform == OperatingSystem.WINDOWS) {
|
||||
try {
|
||||
if (JIntellitype.getInstance() != null) {
|
||||
JIntellitype.getInstance().addHotKeyListener(this)
|
||||
|
||||
val fullResetBinding = config.fullResetBinding
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(FULL_RESET, fullResetBinding)
|
||||
LogManager.info("[Keybinding] Bound full reset to $fullResetBinding")
|
||||
|
||||
val yawResetBinding = config.yawResetBinding
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(YAW_RESET, yawResetBinding)
|
||||
LogManager.info("[Keybinding] Bound yaw reset to $yawResetBinding")
|
||||
|
||||
val mountingResetBinding = config.mountingResetBinding
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(MOUNTING_RESET, mountingResetBinding)
|
||||
LogManager.info("[Keybinding] Bound reset mounting to $mountingResetBinding")
|
||||
|
||||
val feetMountingResetBinding = config.feetMountingResetBinding
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(FEET_MOUNTING_RESET, feetMountingResetBinding)
|
||||
LogManager.info("[Keybinding] Bound feet reset mounting to $feetMountingResetBinding")
|
||||
|
||||
val pauseTrackingBinding = config.pauseTrackingBinding
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(PAUSE_TRACKING, pauseTrackingBinding)
|
||||
LogManager.info("[Keybinding] Bound pause tracking to $pauseTrackingBinding")
|
||||
config.keybinds.forEach { (i, keybind) ->
|
||||
JIntellitype.getInstance()
|
||||
.registerHotKey(keybind.id, keybind.binding)
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
LogManager
|
||||
@@ -55,42 +53,97 @@ class Keybinding @AWTThread constructor(val server: VRServer) : HotkeyListener {
|
||||
)
|
||||
}
|
||||
}
|
||||
if (currentPlatform == OperatingSystem.LINUX) {
|
||||
val portalManager = PortalManager(SLIMEVR_IDENTIFIER)
|
||||
val shortcutsList = Keybinds.entries.map {
|
||||
ShortcutTuple(it.name, Shortcut(it.description, it.keybind).shortcut)
|
||||
}.toMutableList()
|
||||
|
||||
val globalShortcutsHandler = portalManager.globalShortcutsRequest(shortcutsList)
|
||||
Runtime.getRuntime().addShutdownHook(
|
||||
Thread {
|
||||
println("Closing connection")
|
||||
globalShortcutsHandler.close()
|
||||
},
|
||||
)
|
||||
|
||||
val onShortcut: (id: String) -> Unit = { shortcutId ->
|
||||
val keybind = Keybinds.getByName(shortcutId)
|
||||
if (keybind != null) {
|
||||
val delay = config.keybinds[keybind]?.delay?.toLong() ?: 0L
|
||||
when (keybind) {
|
||||
Keybinds.FULL_RESET -> {
|
||||
server.scheduleResetTrackersFull(keybind.keybindName, delay)
|
||||
}
|
||||
|
||||
Keybinds.YAW_RESET -> {
|
||||
server.scheduleResetTrackersYaw(keybind.keybindName, delay)
|
||||
}
|
||||
|
||||
Keybinds.MOUNTING_RESET -> {
|
||||
server.scheduleResetTrackersMounting(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
)
|
||||
}
|
||||
|
||||
Keybinds.FEET_MOUNTING_RESET -> {
|
||||
server.scheduleResetTrackersMounting(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
TrackerUtils.feetsBodyParts,
|
||||
)
|
||||
}
|
||||
|
||||
Keybinds.PAUSE_TRACKING -> {
|
||||
server.scheduleTogglePauseTracking(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globalShortcutsHandler.onShortcutActivated = onShortcut
|
||||
}
|
||||
}
|
||||
|
||||
@AWTThread
|
||||
override fun onHotKey(identifier: Int) {
|
||||
when (identifier) {
|
||||
FULL_RESET -> server.scheduleResetTrackersFull(RESET_SOURCE_NAME, config.fullResetDelay)
|
||||
val keybind = Keybinds.getById(identifier) ?: return
|
||||
val delay = config.keybinds[keybind]?.delay?.toLong() ?: 0L
|
||||
when (keybind) {
|
||||
Keybinds.FULL_RESET -> {
|
||||
server.scheduleResetTrackersFull(keybind.keybindName, delay)
|
||||
}
|
||||
|
||||
YAW_RESET -> server.scheduleResetTrackersYaw(RESET_SOURCE_NAME, config.yawResetDelay)
|
||||
Keybinds.YAW_RESET -> {
|
||||
server.scheduleResetTrackersYaw(keybind.keybindName, delay)
|
||||
}
|
||||
|
||||
MOUNTING_RESET -> server.scheduleResetTrackersMounting(
|
||||
RESET_SOURCE_NAME,
|
||||
config.mountingResetDelay,
|
||||
)
|
||||
Keybinds.MOUNTING_RESET -> {
|
||||
server.scheduleResetTrackersMounting(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
TrackerUtils.feetsBodyParts,
|
||||
)
|
||||
}
|
||||
|
||||
FEET_MOUNTING_RESET -> server.scheduleResetTrackersMounting(
|
||||
RESET_SOURCE_NAME,
|
||||
config.feetMountingResetDelay,
|
||||
TrackerUtils.feetsBodyParts,
|
||||
)
|
||||
Keybinds.FEET_MOUNTING_RESET -> {
|
||||
server.scheduleResetTrackersMounting(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
TrackerUtils.feetsBodyParts,
|
||||
)
|
||||
}
|
||||
|
||||
PAUSE_TRACKING ->
|
||||
server
|
||||
.scheduleTogglePauseTracking(
|
||||
RESET_SOURCE_NAME,
|
||||
config.pauseTrackingDelay,
|
||||
)
|
||||
Keybinds.PAUSE_TRACKING -> {
|
||||
server.scheduleTogglePauseTracking(
|
||||
keybind.keybindName,
|
||||
delay,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val RESET_SOURCE_NAME = "Keybinding"
|
||||
|
||||
private const val FULL_RESET = 1
|
||||
private const val YAW_RESET = 2
|
||||
private const val MOUNTING_RESET = 3
|
||||
private const val FEET_MOUNTING_RESET = 4
|
||||
private const val PAUSE_TRACKING = 5
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import dev.slimevr.games.vrchat.VRCConfigHandler
|
||||
import dev.slimevr.games.vrchat.VRCConfigHandlerStub
|
||||
import dev.slimevr.games.vrchat.VRChatConfigManager
|
||||
import dev.slimevr.guards.ServerGuards
|
||||
import dev.slimevr.keybind.KeybindHandler
|
||||
import dev.slimevr.osc.OSCHandler
|
||||
import dev.slimevr.osc.OSCRouter
|
||||
import dev.slimevr.osc.VMCHandler
|
||||
@@ -128,6 +129,8 @@ class VRServer @JvmOverloads constructor(
|
||||
|
||||
val networkProfileChecker: NetworkProfileChecker
|
||||
|
||||
val keybindHandler: KeybindHandler
|
||||
|
||||
val serverGuards = ServerGuards()
|
||||
|
||||
init {
|
||||
@@ -144,6 +147,7 @@ class VRServer @JvmOverloads constructor(
|
||||
vrcConfigManager = VRChatConfigManager(this, vrcConfigHandlerProvider(this))
|
||||
networkProfileChecker = networkProfileProvider(this)
|
||||
trackingChecklistManager = TrackingChecklistManager(this)
|
||||
keybindHandler = KeybindHandler(this)
|
||||
protocolAPI = ProtocolAPI(this)
|
||||
val computedTrackers = humanPoseManager.computedTrackers
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
package dev.slimevr.config;
|
||||
|
||||
public class KeybindingsConfig {
|
||||
|
||||
private String fullResetBinding = "CTRL+ALT+SHIFT+Y";
|
||||
|
||||
private String yawResetBinding = "CTRL+ALT+SHIFT+U";
|
||||
|
||||
private String mountingResetBinding = "CTRL+ALT+SHIFT+I";
|
||||
|
||||
private String feetMountingResetBinding = "CTRL+ALT+SHIFT+P";
|
||||
|
||||
private String pauseTrackingBinding = "CTRL+ALT+SHIFT+O";
|
||||
|
||||
private long fullResetDelay = 0L;
|
||||
|
||||
private long yawResetDelay = 0L;
|
||||
|
||||
private long mountingResetDelay = 0L;
|
||||
|
||||
private long feetMountingResetDelay = 0L;
|
||||
|
||||
private long pauseTrackingDelay = 0L;
|
||||
|
||||
|
||||
public KeybindingsConfig() {
|
||||
}
|
||||
|
||||
public String getFullResetBinding() {
|
||||
return fullResetBinding;
|
||||
}
|
||||
|
||||
public String getYawResetBinding() {
|
||||
return yawResetBinding;
|
||||
}
|
||||
|
||||
public String getMountingResetBinding() {
|
||||
return mountingResetBinding;
|
||||
}
|
||||
|
||||
public String getFeetMountingResetBinding() {
|
||||
return feetMountingResetBinding;
|
||||
}
|
||||
|
||||
public String getPauseTrackingBinding() {
|
||||
return pauseTrackingBinding;
|
||||
}
|
||||
|
||||
public long getFullResetDelay() {
|
||||
return fullResetDelay;
|
||||
}
|
||||
|
||||
public void setFullResetDelay(long delay) {
|
||||
fullResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getYawResetDelay() {
|
||||
return yawResetDelay;
|
||||
}
|
||||
|
||||
public void setYawResetDelay(long delay) {
|
||||
yawResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getMountingResetDelay() {
|
||||
return mountingResetDelay;
|
||||
}
|
||||
|
||||
public void setMountingResetDelay(long delay) {
|
||||
mountingResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getFeetMountingResetDelay() {
|
||||
return feetMountingResetDelay;
|
||||
}
|
||||
|
||||
public void setFeetMountingResetDelay(long delay) {
|
||||
feetMountingResetDelay = delay;
|
||||
}
|
||||
|
||||
public long getPauseTrackingDelay() {
|
||||
return pauseTrackingDelay;
|
||||
}
|
||||
|
||||
public void setPauseTrackingDelay(long delay) {
|
||||
pauseTrackingDelay = delay;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.Keybinds
|
||||
|
||||
data class KeybindData(
|
||||
var id: Int,
|
||||
var name: String,
|
||||
var binding: String,
|
||||
var delay: Float,
|
||||
)
|
||||
|
||||
class KeybindingsConfig {
|
||||
val keybinds: MutableMap<Keybinds, KeybindData> = Keybinds.entries
|
||||
.associateWith { KeybindData(it.id, it.keybindName, it.keybind, 0f) }
|
||||
.toMutableMap()
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.slimevr.keybind
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.config.KeybindingsConfig
|
||||
import solarxr_protocol.rpc.KeybindT
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
class KeybindHandler(val vrServer: VRServer) {
|
||||
private val listeners: MutableList<KeybindListener> = CopyOnWriteArrayList()
|
||||
var keybinds: MutableList<KeybindT> = mutableListOf()
|
||||
var defaultKeybinds: MutableList<KeybindT> = mutableListOf()
|
||||
|
||||
init {
|
||||
createKeybinds()
|
||||
}
|
||||
|
||||
fun addListener(listener: KeybindListener) {
|
||||
this.listeners.add(listener)
|
||||
}
|
||||
|
||||
fun removeListener(listener: KeybindListener) {
|
||||
listeners.removeIf { listener == it }
|
||||
}
|
||||
|
||||
private fun createKeybinds() {
|
||||
keybinds.clear()
|
||||
defaultKeybinds.clear()
|
||||
vrServer.configManager.vrConfig.keybindings.keybinds.forEach { (i, keybind) ->
|
||||
keybinds.add(
|
||||
KeybindT().apply {
|
||||
keybindId = keybind.id
|
||||
keybindNameId = keybind.name
|
||||
keybindValue = keybind.binding
|
||||
keybindDelay = keybind.delay
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
val binds = KeybindingsConfig().keybinds
|
||||
binds.forEach { (i, keybind) ->
|
||||
defaultKeybinds.add(
|
||||
KeybindT().apply {
|
||||
keybindId = keybind.id
|
||||
keybindNameId = keybind.name
|
||||
keybindValue = keybind.binding
|
||||
keybindDelay = keybind.delay
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateKeybinds() {
|
||||
createKeybinds()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.slimevr.keybind
|
||||
|
||||
interface KeybindListener {
|
||||
fun sendKeybind()
|
||||
fun onKeybindUpdate()
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import dev.slimevr.protocol.rpc.autobone.RPCAutoBoneHandler
|
||||
import dev.slimevr.protocol.rpc.firmware.RPCFirmwareUpdateHandler
|
||||
import dev.slimevr.protocol.rpc.games.vrchat.RPCVRChatHandler
|
||||
import dev.slimevr.protocol.rpc.installinfo.RPCInstallInfoHandler
|
||||
import dev.slimevr.protocol.rpc.keybinds.RPCKeybindHandler
|
||||
import dev.slimevr.protocol.rpc.openuri.RPCOpenUriHandler
|
||||
import dev.slimevr.protocol.rpc.reset.RPCResetHandler
|
||||
import dev.slimevr.protocol.rpc.serial.RPCProvisioningHandler
|
||||
import dev.slimevr.protocol.rpc.serial.RPCSerialHandler
|
||||
@@ -54,6 +56,14 @@ class RPCHandler(private val api: ProtocolAPI) : ProtocolHandler<RpcMessageHeade
|
||||
RPCTrackingChecklistHandler(this, api)
|
||||
RPCUserHeightCalibration(this, api)
|
||||
RPCInstallInfoHandler(this, api)
|
||||
RPCOpenUriHandler(this, api)
|
||||
try {
|
||||
RPCKeybindHandler(this, api)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
|
||||
registerPacketListener(
|
||||
RpcMessage.AssignTrackerRequest,
|
||||
|
||||
+3
-2
@@ -32,12 +32,13 @@ class RPCInstallInfoHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
LogManager.warning("Server couldn't verify if udev is installed")
|
||||
return
|
||||
}
|
||||
val response = udevResponse.contains("slime")
|
||||
val isUdevInstalled = udevResponse.contains("slime")
|
||||
val isWayland = System.getenv("XDG_SESSION_TYPE").lowercase().contains("wayland")
|
||||
val fbb = FlatBufferBuilder(1024)
|
||||
val outbound = this.rpcHandler.createRPCMessage(
|
||||
fbb,
|
||||
RpcMessage.InstalledInfoResponse,
|
||||
createInstalledInfoResponse(fbb, response, false),
|
||||
createInstalledInfoResponse(fbb, isUdevInstalled, isWayland),
|
||||
)
|
||||
fbb.finish(outbound)
|
||||
conn.send(fbb.dataBuffer())
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package dev.slimevr.protocol.rpc.keybinds
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import dev.slimevr.Keybinds
|
||||
import dev.slimevr.config.KeybindData
|
||||
import dev.slimevr.keybind.KeybindListener
|
||||
import dev.slimevr.protocol.GenericConnection
|
||||
import dev.slimevr.protocol.ProtocolAPI
|
||||
import dev.slimevr.protocol.rpc.RPCHandler
|
||||
import jdk.internal.joptsimple.internal.Messages.message
|
||||
import solarxr_protocol.rpc.ChangeKeybindRequest
|
||||
import solarxr_protocol.rpc.KeybindId
|
||||
import solarxr_protocol.rpc.KeybindRequest
|
||||
import solarxr_protocol.rpc.KeybindResponse
|
||||
import solarxr_protocol.rpc.KeybindResponseT
|
||||
import solarxr_protocol.rpc.KeybindT
|
||||
import solarxr_protocol.rpc.RpcMessage
|
||||
import solarxr_protocol.rpc.RpcMessageHeader
|
||||
|
||||
class RPCKeybindHandler(
|
||||
var rpcHandler: RPCHandler,
|
||||
var api: ProtocolAPI,
|
||||
) : KeybindListener {
|
||||
|
||||
val keybindingConfig = api.server.configManager.vrConfig.keybindings
|
||||
|
||||
init {
|
||||
this.api.server.keybindHandler.addListener(this)
|
||||
|
||||
rpcHandler.registerPacketListener(RpcMessage.KeybindRequest, ::onKeybindRequest)
|
||||
rpcHandler.registerPacketListener(RpcMessage.ChangeKeybindRequest, ::onChangeKeybindRequest)
|
||||
}
|
||||
|
||||
// TODO: Figure out a way to "refresh" the keybind array here.
|
||||
private fun buildKeybindResponse(fbb: FlatBufferBuilder): Int = KeybindResponse.pack(
|
||||
fbb,
|
||||
KeybindResponseT().apply {
|
||||
keybind = api.server.keybindHandler.keybinds.toTypedArray()
|
||||
defaultKeybinds = api.server.keybindHandler.defaultKeybinds.toTypedArray()
|
||||
},
|
||||
)
|
||||
|
||||
private fun onKeybindRequest(conn: GenericConnection, messageHeader: RpcMessageHeader) {
|
||||
val fbb = FlatBufferBuilder(32)
|
||||
val response = buildKeybindResponse(fbb)
|
||||
val outbound = rpcHandler.createRPCMessage(
|
||||
fbb,
|
||||
RpcMessage.KeybindResponse,
|
||||
response,
|
||||
)
|
||||
fbb.finish(outbound)
|
||||
conn.send(fbb.dataBuffer())
|
||||
}
|
||||
|
||||
private fun onChangeKeybindRequest(conn: GenericConnection, messageHeader: RpcMessageHeader) {
|
||||
val req = (messageHeader.message(ChangeKeybindRequest()) as ChangeKeybindRequest).unpack()
|
||||
|
||||
val keybind = Keybinds.getById(req.keybind.keybindId) ?: return
|
||||
|
||||
keybindingConfig.keybinds[keybind] = KeybindData(
|
||||
req.keybind.keybindId,
|
||||
req.keybind.keybindNameId,
|
||||
req.keybind.keybindValue,
|
||||
req.keybind.keybindDelay,
|
||||
)
|
||||
|
||||
api.server.configManager.saveConfig()
|
||||
api.server.keybindHandler.updateKeybinds()
|
||||
}
|
||||
|
||||
override fun onKeybindUpdate() {
|
||||
}
|
||||
|
||||
override fun sendKeybind() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.slimevr.protocol.rpc.openuri
|
||||
|
||||
import dev.hannah.portals.PortalManager
|
||||
import dev.slimevr.SLIMEVR_IDENTIFIER
|
||||
import dev.slimevr.protocol.GenericConnection
|
||||
import dev.slimevr.protocol.ProtocolAPI
|
||||
import dev.slimevr.protocol.rpc.RPCHandler
|
||||
import solarxr_protocol.rpc.RpcMessage
|
||||
import solarxr_protocol.rpc.RpcMessageHeader
|
||||
|
||||
class RPCOpenUriHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
|
||||
|
||||
init {
|
||||
rpcHandler.registerPacketListener(RpcMessage.OpenUriRequest, ::onOpenUriRequest)
|
||||
}
|
||||
|
||||
fun onOpenUriRequest(conn: GenericConnection, messageHeader: RpcMessageHeader?) {
|
||||
val portalManager = PortalManager(SLIMEVR_IDENTIFIER)
|
||||
portalManager.openGlobalShortcutsSettings()
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ tasks.withType<Javadoc> {
|
||||
allprojects {
|
||||
repositories {
|
||||
// Use jcenter for resolving dependencies.
|
||||
// You can declare any Maven/Ivy/file repository here.
|
||||
mavenCentral()
|
||||
maven(url = "https://jitpack.io")
|
||||
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
|
||||
@@ -74,7 +73,7 @@ tasks.shadowJar {
|
||||
exclude(dependency("com.fazecast:jSerialComm:.*"))
|
||||
exclude(dependency("net.java.dev.jna:.*:.*"))
|
||||
exclude(dependency("com.google.flatbuffers:flatbuffers-java:.*"))
|
||||
|
||||
exclude(dependency("com.github.HannahPadd:DbusGlobalShortcutsWayland:v0.1.0"))
|
||||
exclude(project(":solarxr-protocol"))
|
||||
}
|
||||
archiveBaseName.set("slimevr")
|
||||
|
||||
Reference in new issue
Block a user