Screen sync add custom multiplier and rate settings (#32)

* screen sync add custom multiplier and rate settings.

* fix rate.

* add to page.
This commit is contained in:
Miroslav Šedivý 2023-04-28 19:39:11 +02:00 committed by GitHub
parent 551a68d613
commit 8df29744b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 10 deletions

View File

@ -202,7 +202,11 @@
rate: 30, rate: 30,
}, },
configurations: [], configurations: [],
sync: false, sync: {
enabled: false,
multiplier: 0,
rate: 30,
},
}, },
session_id: null, session_id: null,
sessions: {}, sessions: {},
@ -453,6 +457,12 @@
} }
} }
public setScreenSync(enabled: boolean = true, multiplier: number = 0, rate: number = 60) {
Vue.set(this.state.screen.sync, 'enabled', enabled)
Vue.set(this.state.screen.sync, 'multiplier', multiplier)
Vue.set(this.state.screen.sync, 'rate', rate)
}
public setCursorDrawFunction(fn?: CursorDrawFunction) { public setCursorDrawFunction(fn?: CursorDrawFunction) {
Vue.set(this, 'cursorDrawFunction', fn) Vue.set(this, 'cursorDrawFunction', fn)
} }
@ -599,9 +609,9 @@
this.connection.websocket.send(EVENT.KEYBOARD_MODIFIERS, modifiers) this.connection.websocket.send(EVENT.KEYBOARD_MODIFIERS, modifiers)
} }
@Watch('state.screen.sync') @Watch('state.screen.sync.enabled')
onScreenSyncChange() { onScreenSyncChange() {
if (this.state.screen.sync) { if (this.state.screen.sync.enabled) {
this.syncScreenSize() this.syncScreenSize()
window.addEventListener('resize', this.syncScreenSize) window.addEventListener('resize', this.syncScreenSize)
} else { } else {
@ -615,12 +625,13 @@
window.clearTimeout(this.syncScreenSizeTimeout) window.clearTimeout(this.syncScreenSizeTimeout)
} }
this.syncScreenSizeTimeout = window.setTimeout(() => { this.syncScreenSizeTimeout = window.setTimeout(() => {
const multiplier = this.state.screen.sync.multiplier || window.devicePixelRatio
this.syncScreenSizeTimeout = 0 this.syncScreenSizeTimeout = 0
const { offsetWidth, offsetHeight } = this._component const { offsetWidth, offsetHeight } = this._component
this.setScreenSize( this.setScreenSize(
Math.round(offsetWidth * window.devicePixelRatio), Math.round(offsetWidth * multiplier),
Math.round(offsetHeight * window.devicePixelRatio), Math.round(offsetHeight * multiplier),
60, // TODO: make it configurable? this.state.screen.sync.rate,
) )
}, SCREEN_SYNC_THROTTLE) }, SCREEN_SYNC_THROTTLE)
} }

View File

@ -91,7 +91,7 @@ export interface Keyboard {
export interface Screen { export interface Screen {
size: ScreenSize size: ScreenSize
configurations: ScreenSize[] configurations: ScreenSize[]
sync: boolean sync: ScreenSync
} }
export interface ScreenSize { export interface ScreenSize {
@ -100,6 +100,12 @@ export interface ScreenSize {
rate: number rate: number
} }
export interface ScreenSync {
enabled: boolean
multiplier: number
rate: number
}
///////////////////////////// /////////////////////////////
// Session // Session
///////////////////////////// /////////////////////////////

View File

@ -333,16 +333,48 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="middle">screen.sync</th> <th class="middle">screen.sync.enabled</th>
<td> <td>
<div class="space-between"> <div class="space-between">
<span>{{ neko.state.screen.sync }}</span> <span>{{ neko.state.screen.sync.enabled }}</span>
<button @click="neko.state.screen.sync = !neko.state.screen.sync"> <button @click="neko.state.screen.sync.enabled = !neko.state.screen.sync.enabled">
<i class="fas fa-toggle-on"></i> <i class="fas fa-toggle-on"></i>
</button> </button>
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<th rowspan="2">screen.sync.multiplier</th>
<td>{{ neko.state.screen.sync.multiplier || 'use device pixel ratio' }}</td>
</tr>
<tr>
<td>
<input
type="range"
min="0"
max="10"
:value="neko.state.screen.sync.multiplier"
@input="neko.state.screen.sync.multiplier = Number($event.target.value)"
step="0.1"
/>
</td>
</tr>
<tr>
<th rowspan="2">screen.sync.rate</th>
<td>{{ neko.state.screen.sync.rate }}</td>
</tr>
<tr>
<td>
<input
type="range"
min="5"
max="60"
:value="neko.state.screen.sync.rate"
@input="neko.state.screen.sync.rate = Number($event.target.value)"
step="5"
/>
</td>
</tr>
</template> </template>
<tr v-else> <tr v-else>
<th>screen.configurations</th> <th>screen.configurations</th>