Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CTRL + wheel to zoom on desktop #71

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/client.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/client/ClientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class ClientController {
[Message.POINTER]: NOP,
[Message.BLUR]: NOP,
[Message.KEYBOARD]: NOP,
[Message.WHEEL]: NOP,

// TODO: This could be more... elegant...
[Message.FULL]: () => {
Expand Down Expand Up @@ -330,6 +331,21 @@ class ClientController {
this.socket.emit(Message.KEYBOARD, data);
});
});

// Forward wheel events
window.addEventListener(
'wheel',
(event) => {
if (event.ctrlKey) {
event.preventDefault();
// Extract only the properties we care about
const { type, clientX, clientY, deltaY, deltaMode } = event;
const data = { type, clientX, clientY, deltaY, deltaMode };
this.socket.emit(Message.WHEEL, data);
}
},
{ capture: true }
);
}

/**
Expand Down
18 changes: 17 additions & 1 deletion src/server/ServerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ServerController {
[Message.POINTER]: this.pointerEvent.bind(this),
[Message.BLUR]: () => this.view.group.clearInputsFromView(this.view.id),
[Message.KEYBOARD]: this.keyboardEvent.bind(this),
[Message.WHEEL]: this.wheelEvent.bind(this),

// For user-defined behavior
[Message.DISPATCH]: (data) => {
Expand Down Expand Up @@ -242,12 +243,27 @@ class ServerController {
*/
keyboardEvent(event) {
event.target = this.view.group;
event.view = this.view.group;
event.view = this.view;
event.group = this.view.group;
event.device = this.device;
this.view.group.gestureController.handleKeyboardEvent(event);
}

/**
* Forwards a wheel event to the message handler as a pinch event.
*
* @param {WheelEvent} event - The event to forward.
*/
wheelEvent(event) {
const { clientX, clientY } = event;
const target = this.view.group;
const view = this.view;
const group = this.view.group;
const device = this.device;
const scale = 1 - event.deltaY * 0.01;
this.application.messageHandler.scale({ x: clientX, y: clientY, target, view, group, device }, { scale });
}

/**
* Updates the model and informs all other views when a user resizes their
* window.
Expand Down
1 change: 1 addition & 0 deletions src/shared/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Message = {
/** @const */ POINTER: 'pointer',
/** @const */ BLUR: 'blur',
/** @const */ KEYBOARD: 'keyboard',
/** @const */ WHEEL: 'wheel',

// Page event related
/** @const */ IMG_LOAD: 'image-loaded',
Expand Down