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 Jan 31, 2024
1 parent 04e8d9f commit f391df0
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 @@ -39,6 +39,7 @@ export const useControllerStore = defineStore('controller', () => {
const availableAxesActions = allAvailableAxes
const availableButtonActions = allAvailableButtons
const enableForwarding = ref(true)
const holdLastInputWhenWindowHidden = ref(false)

const protocolMapping = computed<JoystickProtocolActionsMapping>({
get() {
Expand Down Expand Up @@ -98,6 +99,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 @@ -289,6 +294,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 @@ -167,6 +167,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 f391df0

Please sign in to comment.