Skip to content

Commit

Permalink
try adding mouse actions to touchpad to see if a separate element is …
Browse files Browse the repository at this point in the history
…really needed
  • Loading branch information
Nerwyn committed Dec 9, 2024
1 parent 17325bb commit aabbecb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dist/universal-remote-card.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/classes/remote-mousepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ export class RemoteMousepad extends RemoteTouchpad {
Math.abs(Math.abs(this.deltaX ?? 0) - Math.abs(this.deltaY ?? 0)) >
sensitivity
) {
clearTimeout(this.holdTimer);
this.holdMove = true;
this.sendAction(`${this.getMultiPrefix()}mouse_action`);
if (this.holdTimer) {
clearTimeout(this.holdTimer);
this.holdTimer = undefined;
this.holdMove = true;
this.sendAction(`${this.getMultiPrefix()}mouse_action`);
}
}
}

Expand Down
63 changes: 41 additions & 22 deletions src/classes/remote-touchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,55 @@ export class RemoteTouchpad extends BaseRemoteElement {
this.setDeltaXY(e);
const totalDeltaX = (this.currentX ?? 0) - this.initialX;
const totalDeltaY = (this.currentY ?? 0) - this.initialY;
console.log(`INITIAL: ${this.initialX},${this.initialY}`);
console.log(`CURRENT: ${this.currentX},${this.currentY}`);
console.log(`TOTAL DELTA: ${totalDeltaX},${totalDeltaY}`);

// Only consider significant enough movement
const sensitivity = 2;
if (
Math.abs(Math.abs(totalDeltaX) - Math.abs(totalDeltaY)) >
sensitivity
this.renderTemplate(this.config.mouse_action?.action ?? 'none') !=
'none' ||
((this.targetTouches?.length ?? 0) > 1 &&
this.renderTemplate(
this.config.multi_mouse_action?.action ?? 'none',
) != 'none')
) {
if (Math.abs(totalDeltaX) > Math.abs(totalDeltaY)) {
// Sliding horizontally
this.direction = totalDeltaX < 0 ? 'left' : 'right';
} else {
// Sliding vertically
this.direction = totalDeltaY < 0 ? 'up' : 'down';
}
console.log(this.direction);
if (!this.holdMove) {
this.fireHapticEvent('light');
this.sendAction(
`${this.getMultiPrefix()}tap_action`,
this.getActions(),
);
this.holdMove = true;

if (
this.holdMove ||
Math.abs(
Math.abs(this.deltaX ?? 0) - Math.abs(this.deltaY ?? 0),
) > sensitivity
) {
if (this.holdTimer) {
clearTimeout(this.holdTimer);
this.holdTimer = undefined;
this.setHoldTimer();
this.holdMove = true;
this.sendAction(`${this.getMultiPrefix()}mouse_action`);
}
}
} else {
if (
Math.abs(Math.abs(totalDeltaX) - Math.abs(totalDeltaY)) >
sensitivity
) {
if (Math.abs(totalDeltaX) > Math.abs(totalDeltaY)) {
// Sliding horizontally
this.direction = totalDeltaX < 0 ? 'left' : 'right';
} else {
// Sliding vertically
this.direction = totalDeltaY < 0 ? 'up' : 'down';
}
if (!this.holdMove) {
this.fireHapticEvent('light');
this.sendAction(
`${this.getMultiPrefix()}tap_action`,
this.getActions(),
);
this.holdMove = true;

if (this.holdTimer) {
clearTimeout(this.holdTimer);
this.holdTimer = undefined;
this.setHoldTimer();
}
}
}
}
Expand Down

0 comments on commit aabbecb

Please sign in to comment.