mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
implement inactive cursors for overlay.
This commit is contained in:
parent
5ee38f217e
commit
0480a0d512
@ -17,6 +17,7 @@
|
|||||||
"
|
"
|
||||||
:cursorDraw="cursorDrawFunction"
|
:cursorDraw="cursorDrawFunction"
|
||||||
:implicitControl="state.control.implicit_hosting && state.sessions[state.session_id].profile.can_host"
|
:implicitControl="state.control.implicit_hosting && state.sessions[state.session_id].profile.can_host"
|
||||||
|
:inactiveCursors="true"
|
||||||
@implicitControlRequest="connection.websocket.send('control/request')"
|
@implicitControlRequest="connection.websocket.send('control/request')"
|
||||||
@implicitControlRelease="connection.websocket.send('control/release')"
|
@implicitControlRelease="connection.websocket.send('control/release')"
|
||||||
@updateKeyboardModifiers="updateKeyboardModifiers($event)"
|
@updateKeyboardModifiers="updateKeyboardModifiers($event)"
|
||||||
|
@ -43,8 +43,11 @@
|
|||||||
|
|
||||||
const WHEEL_STEP = 53 // Delta threshold for a mouse wheel step
|
const WHEEL_STEP = 53 // Delta threshold for a mouse wheel step
|
||||||
const WHEEL_LINE_HEIGHT = 19
|
const WHEEL_LINE_HEIGHT = 19
|
||||||
|
|
||||||
const CANVAS_SCALE = 2
|
const CANVAS_SCALE = 2
|
||||||
|
|
||||||
|
const INACTIVE_CURSOR_INTERVAL = 250 // ms
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
name: 'neko-overlay',
|
name: 'neko-overlay',
|
||||||
})
|
})
|
||||||
@ -79,6 +82,9 @@
|
|||||||
@Prop()
|
@Prop()
|
||||||
private readonly implicitControl!: boolean
|
private readonly implicitControl!: boolean
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
private readonly inactiveCursors!: boolean
|
||||||
|
|
||||||
get cursor(): string {
|
get cursor(): string {
|
||||||
if (!this.isControling || !this.cursorImage) {
|
if (!this.isControling || !this.cursorImage) {
|
||||||
return 'auto'
|
return 'auto'
|
||||||
@ -143,6 +149,12 @@
|
|||||||
this.webrtc.removeListener('cursor-image', this.onCursorImage)
|
this.webrtc.removeListener('cursor-image', this.onCursorImage)
|
||||||
this.webrtc.removeListener('disconnected', this.canvasClear)
|
this.webrtc.removeListener('disconnected', this.canvasClear)
|
||||||
this.cursorElement.onload = null
|
this.cursorElement.onload = null
|
||||||
|
|
||||||
|
// stop inactive cursor interval if exists
|
||||||
|
if (this.inactiveCursorInterval !== null) {
|
||||||
|
window.clearInterval(this.inactiveCursorInterval)
|
||||||
|
this.inactiveCursorInterval = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getMousePos(clientX: number, clientY: number) {
|
getMousePos(clientX: number, clientY: number) {
|
||||||
@ -154,7 +166,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMousePos(e: MouseEvent) {
|
sendMousePos(e: MouseEvent) {
|
||||||
const pos = this.getMousePos(e.clientX, e.clientY)
|
const pos = this.getMousePos(e.clientX, e.clientY)
|
||||||
this.webrtc.send('mousemove', pos)
|
this.webrtc.send('mousemove', pos)
|
||||||
Vue.set(this, 'cursorPosition', pos)
|
Vue.set(this, 'cursorPosition', pos)
|
||||||
@ -195,7 +207,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setMousePos(e)
|
this.sendMousePos(e)
|
||||||
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const firstScroll = now - this.wheelDate > 250
|
const firstScroll = now - this.wheelDate > 250
|
||||||
@ -249,12 +261,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMouseMove(e: MouseEvent) {
|
onMouseMove(e: MouseEvent) {
|
||||||
// TODO: Send less events if not controlling.
|
if (this.isControling) {
|
||||||
//if (!this.isControling) {
|
this.sendMousePos(e)
|
||||||
// return
|
} else if (this.inactiveCursors) {
|
||||||
//}
|
this.saveInactiveMousePos(e)
|
||||||
|
}
|
||||||
this.setMousePos(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseDown(e: MouseEvent) {
|
onMouseDown(e: MouseEvent) {
|
||||||
@ -263,7 +274,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setMousePos(e)
|
this.sendMousePos(e)
|
||||||
this.webrtc.send('mousedown', { key: e.button + 1 })
|
this.webrtc.send('mousedown', { key: e.button + 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +284,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setMousePos(e)
|
this.sendMousePos(e)
|
||||||
this.webrtc.send('mouseup', { key: e.button + 1 })
|
this.webrtc.send('mouseup', { key: e.button + 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +336,39 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// inactive cursor position
|
||||||
|
//
|
||||||
|
|
||||||
|
private inactiveCursorInterval: number | null = null
|
||||||
|
private inactiveCursorPosition: CursorPosition | null = null
|
||||||
|
|
||||||
|
@Watch('focused')
|
||||||
|
@Watch('isControling')
|
||||||
|
@Watch('inactiveCursors')
|
||||||
|
restartInactiveCursorInterval() {
|
||||||
|
// clear interval if exists
|
||||||
|
if (this.inactiveCursorInterval !== null) {
|
||||||
|
window.clearInterval(this.inactiveCursorInterval)
|
||||||
|
this.inactiveCursorInterval = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.inactiveCursors && this.focused && !this.isControling) {
|
||||||
|
this.inactiveCursorInterval = window.setInterval(this.sendInactiveMousePos.bind(this), INACTIVE_CURSOR_INTERVAL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveInactiveMousePos(e: MouseEvent) {
|
||||||
|
const pos = this.getMousePos(e.clientX, e.clientY)
|
||||||
|
Vue.set(this, 'inactiveCursorPosition', pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendInactiveMousePos() {
|
||||||
|
if (this.inactiveCursorPosition != null) {
|
||||||
|
this.webrtc.send('mousemove', this.inactiveCursorPosition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// keyboard modifiers
|
// keyboard modifiers
|
||||||
//
|
//
|
||||||
@ -464,7 +508,7 @@
|
|||||||
|
|
||||||
if (isControling && this.reqMouseDown) {
|
if (isControling && this.reqMouseDown) {
|
||||||
this.updateKeyboardModifiers(this.reqMouseDown)
|
this.updateKeyboardModifiers(this.reqMouseDown)
|
||||||
this.setMousePos(this.reqMouseDown)
|
this.sendMousePos(this.reqMouseDown)
|
||||||
this.webrtc.send('mousedown', { key: this.reqMouseDown.button + 1 })
|
this.webrtc.send('mousedown', { key: this.reqMouseDown.button + 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user