Skip to content

Commit e2d7a5b

Browse files
committed
do not let a stylus scribble, prevent default if a pen is detected
1 parent 8f356ba commit e2d7a5b

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

addons/gst-web-core/lib/input.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,10 +1547,10 @@ export class Input {
15471547
if (this._trackpadMode) return;
15481548
const client_dpr = window.devicePixelRatio || 1;
15491549
const dpr_for_input_coords = this.useCssScaling ? 1 : client_dpr;
1550-
const down = (event.type === 'mousedown' ? 1 : 0);
1550+
const down = (event.type === 'mousedown' || event.type === 'pointerdown' ? 1 : 0);
15511551
var mtype = "m";
15521552
let canvas = document.getElementById('videoCanvas');
1553-
if (event.type === 'mousedown' || event.type === 'mouseup') {
1553+
if (event.type === 'mousedown' || event.type === 'mouseup' || event.type === 'pointerdown' || event.type === 'pointerup' || event.type === 'pointercancel') {
15541554
if (event.button === 3) {
15551555
event.preventDefault();
15561556
} else if (event.button === 4) {
@@ -1570,7 +1570,7 @@ export class Input {
15701570
this.x = Math.round(movementX_logical * dpr_for_input_coords);
15711571
this.y = Math.round(movementY_logical * dpr_for_input_coords);
15721572

1573-
} else if (event.type === 'mousemove') {
1573+
} else if (event.type === 'mousemove' || event.type === 'pointermove') {
15741574
if (window.isManualResolutionMode && canvas) {
15751575
const canvasRect = canvas.getBoundingClientRect(); // CSS logical size
15761576
if (canvasRect.width > 0 && canvasRect.height > 0 && canvas.width > 0 && canvas.height > 0) {
@@ -1611,6 +1611,28 @@ export class Input {
16111611
this.send(toks.join(","));
16121612
}
16131613

1614+
_handlePointerDown(event) {
1615+
if (event.pointerType !== 'pen') {
1616+
return;
1617+
}
1618+
event.preventDefault();
1619+
this._mouseButtonMovement(event);
1620+
}
1621+
1622+
_handlePointerMove(event) {
1623+
if (event.pointerType !== 'pen') {
1624+
return;
1625+
}
1626+
this._mouseButtonMovement(event);
1627+
}
1628+
1629+
_handlePointerUp(event) {
1630+
if (event.pointerType !== 'pen') {
1631+
return;
1632+
}
1633+
this._mouseButtonMovement(event);
1634+
}
1635+
16141636
_handleTrackpadEvent(event) {
16151637
if (this._targetHasClass(event.target, WHITELIST_CLASS)) return;
16161638
event.preventDefault();
@@ -2290,7 +2312,10 @@ export class Input {
22902312
this.listeners_context.push(addListener(compositionTarget, 'compositionstart', this._compositionStart, this));
22912313
this.listeners_context.push(addListener(compositionTarget, 'compositionupdate', this._compositionUpdate, this));
22922314
this.listeners_context.push(addListener(compositionTarget, 'compositionend', this._compositionEnd, this));
2293-
2315+
this.listeners_context.push(addListener(this.element, 'pointerdown', this._handlePointerDown, this));
2316+
this.listeners_context.push(addListener(this.element, 'pointermove', this._handlePointerMove, this));
2317+
this.listeners_context.push(addListener(this.element, 'pointerup', this._handlePointerUp, this));
2318+
this.listeners_context.push(addListener(this.element, 'pointercancel', this._handlePointerUp, this));
22942319

22952320
if ('ontouchstart' in window) {
22962321
this.listeners_context.push(addListener(this.element, 'touchstart', this._handleTouchEvent, this, false));

0 commit comments

Comments
 (0)