register mouseup globally.

This commit is contained in:
Miroslav Šedivý 2022-09-15 21:58:51 +02:00
parent cc6722fee2
commit a6698a3ef2

View File

@ -11,7 +11,6 @@
@wheel.stop.prevent="onWheel" @wheel.stop.prevent="onWheel"
@mousemove.stop.prevent="onMouseMove" @mousemove.stop.prevent="onMouseMove"
@mousedown.stop.prevent="onMouseDown" @mousedown.stop.prevent="onMouseDown"
@mouseup.stop.prevent="onMouseUp"
@mouseenter.stop.prevent="onMouseEnter" @mouseenter.stop.prevent="onMouseEnter"
@mouseleave.stop.prevent="onMouseLeave" @mouseleave.stop.prevent="onMouseLeave"
@dragenter.stop.prevent="onDragEnter" @dragenter.stop.prevent="onDragEnter"
@ -116,6 +115,9 @@
} }
mounted() { mounted() {
// register mouseup globally as user can release mouse button outside of overlay
window.addEventListener('mouseup', this.onMouseUp, true)
// get canvas overlay context // get canvas overlay context
const ctx = this._overlay.getContext('2d') const ctx = this._overlay.getContext('2d')
if (ctx != null) { if (ctx != null) {
@ -183,6 +185,8 @@
} }
beforeDestroy() { beforeDestroy() {
window.removeEventListener('mouseup', this.onMouseUp, true)
// Guacamole Keyboard does not provide destroy functions // Guacamole Keyboard does not provide destroy functions
this.webrtc.removeListener('cursor-position', this.onCursorPosition) this.webrtc.removeListener('cursor-position', this.onCursorPosition)
@ -319,7 +323,11 @@
} }
} }
isMouseDown = false
onMouseDown(e: MouseEvent) { onMouseDown(e: MouseEvent) {
this.isMouseDown = true
if (!this.isControling) { if (!this.isControling) {
this.implicitControlRequest(e) this.implicitControlRequest(e)
return return
@ -336,6 +344,10 @@
} }
onMouseUp(e: MouseEvent) { onMouseUp(e: MouseEvent) {
// only if we are the one who started the mouse down
if (!this.isMouseDown) return
this.isMouseDown = false
if (!this.isControling) { if (!this.isControling) {
this.implicitControlRequest(e) this.implicitControlRequest(e)
return return