Skip to content

Commit

Permalink
11917 - Change "move to display" shortcuts and remove it from GlobalS…
Browse files Browse the repository at this point in the history
…hortcuts (Closes #346, #323)
  • Loading branch information
Ferllings committed Aug 19, 2024
1 parent 16477e0 commit 6c8767e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 32 deletions.
53 changes: 26 additions & 27 deletions src/browsers/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {app, BrowserWindow, shell, Menu, MenuItem, globalShortcut, screen} = require('electron')
const {app, BrowserWindow, shell, Menu, MenuItem, screen} = require('electron')
const path = require('path')
const url = require('url')

Expand Down Expand Up @@ -49,31 +49,6 @@ module.exports = (dirname, store) => {
// Open the DevTools.
// mainWindow.webContents.openDevTools()

if (process.platform === 'darwin') { // MacOS only, native on Window
// Move the window to the previous monitor
globalShortcut.register('Command+Shift+Left', () => {
const pos = mainWindow.getBounds()
const currentScreen = screen.getDisplayNearestPoint(pos)
const allScreens = screen.getAllDisplays()
const monitorIndex = allScreens.findIndex(monitor => monitor.id === currentScreen.id)

const nextIndex = (monitorIndex==0)?allScreens.length-1:monitorIndex-1
const nextMonitor = allScreens[nextIndex]
displayOnScreen(mainWindow, nextMonitor)
});

// Move the window to the next monitor
globalShortcut.register('Command+Shift+Right', () => {
const pos = mainWindow.getBounds()
const currentScreen = screen.getDisplayNearestPoint(pos)
const allScreens = screen.getAllDisplays()
const monitorIndex = allScreens.findIndex(monitor => monitor.id === currentScreen.id)

const nextIndex = (monitorIndex==allScreens.length-1)?0:monitorIndex+1
const nextMonitor = allScreens[nextIndex]
displayOnScreen(mainWindow, nextMonitor)
});
}

mainWindow.on('close', function () {
if (mainWindow) {
Expand Down Expand Up @@ -160,10 +135,34 @@ module.exports = (dirname, store) => {
win.setPosition(winX, winY)
}

let movePreviousMonitor = () => {
const pos = mainWindow.getBounds()
const currentScreen = screen.getDisplayNearestPoint(pos)
const allScreens = screen.getAllDisplays()
const monitorIndex = allScreens.findIndex(monitor => monitor.id === currentScreen.id)

const nextIndex = (monitorIndex==0)?allScreens.length-1:monitorIndex-1
const nextMonitor = allScreens[nextIndex]
displayOnScreen(mainWindow, nextMonitor)
}

let moveNextMonitor = () => {
const pos = mainWindow.getBounds()
const currentScreen = screen.getDisplayNearestPoint(pos)
const allScreens = screen.getAllDisplays()
const monitorIndex = allScreens.findIndex(monitor => monitor.id === currentScreen.id)

const nextIndex = (monitorIndex==allScreens.length-1)?0:monitorIndex+1
const nextMonitor = allScreens[nextIndex]
displayOnScreen(mainWindow, nextMonitor)
}

return {
init: init,
getWindow: getWindow,
changeZoom: changeZoom,
changeSize: changeSize
changeSize: changeSize,
movePreviousMonitor: movePreviousMonitor,
moveNextMonitor: moveNextMonitor
}
}
28 changes: 25 additions & 3 deletions src/menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Menu } = require('electron')
const isDev = ('NODE_ENV' in process.env && process.env.NODE_ENV === 'dev')
const isMacOS = process.platform === 'darwin'
const { installUpdate } = require('./update.js')

module.exports = (browsers, mainController, store) => {
Expand Down Expand Up @@ -199,9 +200,13 @@ module.exports = (browsers, mainController, store) => {
}
]
},
{
label: i18n.menuT('Window'),
submenu: [],
visible: isMacOS // MacOS only, native on Window
},
{
label: i18n.menuT('Development'),

submenu: [
{
label: i18n.menuT('Reload'),
Expand All @@ -212,7 +217,7 @@ module.exports = (browsers, mainController, store) => {
},
{
label: i18n.menuT('Open Developer Tools'),
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
accelerator: isMacOS ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.openDevTools({mode: 'detach'})
}
Expand All @@ -225,7 +230,7 @@ module.exports = (browsers, mainController, store) => {
/* On macOS, cut/copy/paste doesn't work by default unless the options
are added to the edit menu, or some custom clipboard API implementation is
used. On Windows and Linux, these work out of the box...so only add on macOS */
if (process.platform === 'darwin') {
if (isMacOS) {
menuTemplate[1].submenu.push(
{
type: 'separator'
Expand All @@ -243,6 +248,23 @@ module.exports = (browsers, mainController, store) => {
selector: 'paste:'
}
)

menuTemplate[3].submenu.push(
{
label: i18n.menuT('Move to previous monitor'),
accelerator: 'Ctrl+Alt+Left',
click () {
main.movePreviousMonitor()
}
},
{
label: i18n.menuT('Move to next monitor'),
accelerator: 'Ctrl+Alt+Right',
click () {
main.moveNextMonitor()
}
},
)
}

const menu = Menu.buildFromTemplate(menuTemplate);
Expand Down
4 changes: 3 additions & 1 deletion src/views/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"Zoom Out": "Zoom Out",
"Development": "Development",
"Reload": "Reload",
"Open Developer Tools": "Open Developer Tools"
"Open Developer Tools": "Open Developer Tools",
"Move to previous monitor": "Move to previous monitor",
"Move to next monitor": "Move to next monitor"
},
"Main": {
"lang": "en-us",
Expand Down
4 changes: 3 additions & 1 deletion src/views/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"Zoom Out": "Zoom arrière",
"Development": "Développement",
"Reload": "Recharger",
"Open Developer Tools": "Ouvrir les outils de développement"
"Open Developer Tools": "Ouvrir les outils de développement",
"Move to previous monitor": "Déplacer sur écran précédent",
"Move to next monitor": "Déplacer sur écran suivant"
},
"Main": {
"lang": "fr",
Expand Down

0 comments on commit 6c8767e

Please sign in to comment.