Skip to content

Commit

Permalink
controller: Allow user to decide upon holding last joystick input whe…
Browse files Browse the repository at this point in the history
…n window is hidden
  • Loading branch information
rafaellehmkuhl committed Feb 1, 2024
1 parent 8528c72 commit b48776c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/stores/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useControllerStore = defineStore('controller', () => {
const availableAxesActions = allAvailableAxes
const availableButtonActions = allAvailableButtons
const enableForwarding = ref(true)
const holdLastInputWhenWindowHidden = useStorage('cockpit-hold-last-joystick-input-when-window-hidden', false)

const protocolMapping = computed<JoystickProtocolActionsMapping>({
get() {
Expand Down Expand Up @@ -99,6 +100,10 @@ export const useControllerStore = defineStore('controller', () => {
// Disable joystick forwarding if the window/tab is not visible (using VueUse)
const windowVisibility = useDocumentVisibility()
watch(windowVisibility, (value) => {
// Disable this failcheck if the user explicitly wants to hold the last input when the window is hidden
// This can be considered unsafe, as the user might not be aware of the joystick input being forwarded to the vehicle
if (holdLastInputWhenWindowHidden.value) return

if (value === 'hidden') {
console.warn('Window/tab hidden. Disabling joystick forwarding.')
enableForwarding.value = false
Expand Down Expand Up @@ -320,6 +325,7 @@ export const useControllerStore = defineStore('controller', () => {
return {
registerControllerUpdateCallback,
enableForwarding,
holdLastInputWhenWindowHidden,
joysticks,
protocolMapping,
protocolMappings,
Expand Down
5 changes: 5 additions & 0 deletions src/views/ConfigurationJoystickView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
</div>
</div>
</div>
<v-switch
v-model="controllerStore.holdLastInputWhenWindowHidden"
label="Hold last joystick input when window is hidden (tab changed or window minimized)"
class="m-2 text-slate-800"
/>
</div>
</template>
</BaseConfigurationView>
Expand Down

0 comments on commit b48776c

Please sign in to comment.