From 754e1650452e85b98a01f1f04edf5cc965a8879e Mon Sep 17 00:00:00 2001 From: Grigorii Shartsev Date: Thu, 23 Mar 2023 00:27:26 +0100 Subject: [PATCH 1/2] fix: add CommandOrControl + Plus hotkey for zoomIn without SHIFT Fix: #74 Signed-off-by: Grigorii Shartsev --- src/app/app.menu.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/app/app.menu.js b/src/app/app.menu.js index 6aa21496b..900b90247 100644 --- a/src/app/app.menu.js +++ b/src/app/app.menu.js @@ -93,6 +93,13 @@ function setupMenu() { { type: 'separator' }, { role: 'resetZoom' }, { role: 'zoomIn' }, + // By default zoomIn works by "CommandOrControl + +" ("CommandOrControl + SHIFT + =") + // Hidden menu item adds zoomIn without SHIFT + { + role: 'zoomIn', + accelerator: 'CommandOrControl+=', + visible: false, + }, { role: 'zoomOut' }, { type: 'separator' }, { role: 'togglefullscreen' }, From 9a3532a0ee5be38875e6ffca04e585a3c4c44c6b Mon Sep 17 00:00:00 2001 From: Grigorii Shartsev Date: Fri, 24 Mar 2023 14:52:58 +0100 Subject: [PATCH 2/2] feat: add zoom with mouse wheel Signed-off-by: Grigorii Shartsev --- src/app/applyWheelZoom.js | 38 ++++++++++++++++++++++++++++++++++++++ src/talk/talk.window.js | 3 +++ 2 files changed, 41 insertions(+) create mode 100644 src/app/applyWheelZoom.js diff --git a/src/app/applyWheelZoom.js b/src/app/applyWheelZoom.js new file mode 100644 index 000000000..fe3d98e85 --- /dev/null +++ b/src/app/applyWheelZoom.js @@ -0,0 +1,38 @@ +/* + * @copyright Copyright (c) 2023 Grigorii Shartsev + * + * @author Grigorii Shartsev + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/** + * Enable zooming window by mouse wheel + * + * @param {import('electron').BrowserWindow} browserWindow - Browser window + */ +export function applyWheelZoom(browserWindow) { + browserWindow.webContents.on('zoom-changed', (event, zoomDirection) => { + const zoom = browserWindow.webContents.getZoomLevel() + // 0.5 level delta seems to be equivalent of "CTRL+" (zoomIn) and CTRL- (zoomOut) commands + const zoomDelta = 0.5 * (zoomDirection === 'in' ? 1 : -1) + const newZoom = zoom + zoomDelta + // Undocumented default limits for zoom level is [-8, 9] or [~23.25%, 515.97%] + if (newZoom >= -8 && newZoom <= 9) { + browserWindow.webContents.setZoomLevel(zoom + zoomDelta) + } + }) +} diff --git a/src/talk/talk.window.js b/src/talk/talk.window.js index a815d239e..0bbf8f524 100644 --- a/src/talk/talk.window.js +++ b/src/talk/talk.window.js @@ -24,6 +24,7 @@ const { windowOpenExternalLinkHandler, willNavigateExternalLinkHandler, } = require('../app/externalLinkHandlers.js') +const { applyWheelZoom } = require('../app/applyWheelZoom.js') /** * @return {import('electron').BrowserWindow} @@ -64,6 +65,8 @@ function createTalkWindow() { window.show() }) + applyWheelZoom(window) + window.loadURL(TALK_WINDOW_WEBPACK_ENTRY) return window