add implicit control.

This commit is contained in:
Miroslav Šedivý 2020-12-02 10:45:23 +01:00
parent a268bddc57
commit 8bfe0c4f67
2 changed files with 64 additions and 26 deletions

View File

@ -9,6 +9,9 @@
:isControling="controlling"
:scrollSensitivity="state.control.scroll.sensitivity"
:scrollInvert="state.control.scroll.inverse"
:implicitControl="true"
@implicit-control-request="websocket.send('control/request')"
@implicit-control-release="websocket.send('control/release')"
/>
</div>
</div>

View File

@ -26,7 +26,7 @@
</style>
<script lang="ts">
import { Vue, Component, Ref, Prop } from 'vue-property-decorator'
import { Vue, Component, Ref, Prop, Watch } from 'vue-property-decorator'
import GuacamoleKeyboard from './utils/guacamole-keyboard'
import { NekoWebRTC } from './internal/webrtc'
@ -58,10 +58,18 @@
@Prop()
private readonly isControling!: boolean
@Prop()
private readonly implicitControl!: boolean
mounted() {
// Initialize Guacamole Keyboard
this.keyboard.onkeydown = (key: number) => {
if (!this.focused || !this.isControling) {
if (!this.focused) {
return true
}
if (!this.isControling) {
this.implicitControlRequest()
return true
}
@ -69,7 +77,12 @@
return false
}
this.keyboard.onkeyup = (key: number) => {
if (!this.focused || !this.isControling) {
if (!this.focused) {
return
}
if (!this.isControling) {
this.implicitControlRequest()
return
}
@ -93,6 +106,7 @@
onWheel(e: WheelEvent) {
if (!this.isControling) {
this.implicitControlRequest()
return
}
@ -113,6 +127,7 @@
onMouseMove(e: MouseEvent) {
if (!this.isControling) {
this.implicitControlRequest()
return
}
@ -121,6 +136,7 @@
onMouseDown(e: MouseEvent) {
if (!this.isControling) {
this.implicitControlRequest()
return
}
@ -130,6 +146,7 @@
onMouseUp(e: MouseEvent) {
if (!this.isControling) {
this.implicitControlRequest()
return
}
@ -138,25 +155,27 @@
}
onMouseEnter(e: MouseEvent) {
if (!this.isControling) {
return
}
this._overlay.focus()
this.focused = true
if (!this.isControling) {
this.implicitControlRequest()
// TODO: Refactor
//syncKeyboardModifierState({
// capsLock: e.getModifierState('CapsLock'),
// numLock: e.getModifierState('NumLock'),
// scrollLock: e.getModifierState('ScrollLock'),
//})
this._overlay.focus()
this.focused = true
}
}
onMouseLeave(e: MouseEvent) {
if (!this.isControling) {
return
}
this._overlay.blur()
this.focused = false
if (this.isControling) {
this.keyboard.reset()
this.implicitControlRelease()
// TODO: Refactor
//setKeyboardModifierState({
@ -164,10 +183,26 @@
// numLock: e.getModifierState('NumLock'),
// scrollLock: e.getModifierState('ScrollLock'),
//})
}
}
this.keyboard.reset()
this._overlay.blur()
this.focused = false
isRequesting = false
@Watch('isControling')
onControlChange(isControling: boolean) {
this.isRequesting = false
}
implicitControlRequest() {
if (!this.isRequesting && this.implicitControl) {
this.isRequesting = true
this.$emit('implicit-control-request')
}
}
implicitControlRelease() {
if (this.implicitControl) {
this.$emit('implicit-control-release')
}
}
}
</script>