From 64e87d0d27cf9cb2539987ac9b2b0d99225ded84 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sun, 16 Oct 2016 01:20:10 -0400 Subject: [PATCH] Quick full screen (#803) * Add pseudo quick full screen * Record window size before entering full screen * Restore window size when leaving full screen * Toggle menu items for quick full screen * Remove redundant filters * Add accelerators for Linux * Only save window state when not full screen --- app/index.js | 39 ++++++++++++++++++++++++++++++++++++++- app/menu.js | 23 +++++++++++++++++++++++ lib/actions/ui.js | 24 ++++++++++++++++++++++++ lib/constants/ui.js | 2 ++ lib/index.js | 8 ++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 0b8b7515..47df02d7 100644 --- a/app/index.js +++ b/app/index.js @@ -3,6 +3,7 @@ const {resolve} = require('path'); // Packages const {parse: parseUrl} = require('url'); +const electron = require('electron'); const {app, BrowserWindow, shell, Menu} = require('electron'); const {gitDescribe} = require('git-describe'); const uuid = require('uuid'); @@ -247,6 +248,40 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { win.maximize(); }); + const findMenuItem = (items, id) => items.filter(item => item.id === id)[0]; + + const getMenuItem = id => findMenuItem(Menu.getApplicationMenu().items, id); + + const getSubmenuItem = (menuItem, id) => findMenuItem(menuItem.submenu.items, id); + + let isQuickFullScreenEnabled = false; + + const toggleQuickFullScreenMenuItems = isQuickFullScreen => { + const windowMenu = getMenuItem('WINDOW'); + const enterQuickFullScreenMenu = getSubmenuItem(windowMenu, 'ENTER_QUICK_FULL_SCREEN'); + const leaveQuickFullScreenMenu = getSubmenuItem(windowMenu, 'LEAVE_QUICK_FULL_SCREEN'); + enterQuickFullScreenMenu.visible = !isQuickFullScreen; + leaveQuickFullScreenMenu.visible = isQuickFullScreen; + isQuickFullScreenEnabled = isQuickFullScreen; + }; + + rpc.on('enter quick full screen', () => { + toggleQuickFullScreenMenuItems(true); + app.config.window.recordState(win); + const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize; + win.setSize(width, height); + win.center(); + }); + + rpc.on('leave quick full screen', () => { + toggleQuickFullScreenMenuItems(false); + const winSet = app.config.window.get(); + const [width, height] = winSet.size; + win.setSize(width, height); + const [x, y] = winSet.position; + win.setPosition(x, y); + }); + rpc.on('resize', ({uid, cols, rows}) => { const session = sessions.get(uid); session.resize({cols, rows}); @@ -325,7 +360,9 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { // the window can be closed by the browser process itself win.on('close', () => { - app.config.window.recordState(win); + if (!isQuickFullScreenEnabled) { + app.config.window.recordState(win); + } windowSet.delete(win); rpc.destroy(); deleteSessions(); diff --git a/app/menu.js b/app/menu.js index 73bc00f2..f4d4bc06 100644 --- a/app/menu.js +++ b/app/menu.js @@ -254,6 +254,7 @@ module.exports = ({createWindow, updatePlugins}) => { }; const windowMenu = { + id: 'WINDOW', role: 'window', submenu: [ { @@ -312,6 +313,28 @@ module.exports = ({createWindow, updatePlugins}) => { }, { role: 'togglefullscreen' + }, + { + id: 'ENTER_QUICK_FULL_SCREEN', + label: 'Enter Quick Full Screen', + accelerator: isMac ? 'Cmd+Enter' : 'Ctrl+Shift+Enter', + visible: true, + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.rpc.emit('enter quick full screen req'); + } + } + }, + { + id: 'LEAVE_QUICK_FULL_SCREEN', + label: 'Leave Quick Full Screen', + accelerator: isMac ? 'Cmd+Enter' : 'Ctrl+Shift+Enter', + visible: false, + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.rpc.emit('leave quick full screen req'); + } + } } ] }; diff --git a/lib/actions/ui.js b/lib/actions/ui.js index 84cb627b..2f5f1869 100644 --- a/lib/actions/ui.js +++ b/lib/actions/ui.js @@ -23,6 +23,8 @@ import { UI_MOVE_PREV_PANE, UI_SHOW_PREFERENCES, UI_WINDOW_MOVE, + UI_ENTER_QUICK_FULL_SCREEN, + UI_LEAVE_QUICK_FULL_SCREEN, UI_OPEN_FILE } from '../constants/ui'; @@ -30,6 +32,28 @@ import {setActiveGroup} from './term-groups'; const {stat} = window.require('fs'); +export function enterQuickFullScreen() { + return dispatch => { + dispatch({ + type: UI_ENTER_QUICK_FULL_SCREEN, + effect() { + rpc.emit('enter quick full screen'); + } + }); + }; +} + +export function leaveQuickFullScreen() { + return dispatch => { + dispatch({ + type: UI_LEAVE_QUICK_FULL_SCREEN, + effect() { + rpc.emit('leave quick full screen'); + } + }); + }; +} + export function increaseFontSize() { return (dispatch, getState) => { dispatch({ diff --git a/lib/constants/ui.js b/lib/constants/ui.js index c6d737bb..366aac1b 100644 --- a/lib/constants/ui.js +++ b/lib/constants/ui.js @@ -12,4 +12,6 @@ export const UI_SHOW_PREFERENCES = 'UI_SHOW_PREFERENCES'; export const UI_WINDOW_MOVE = 'UI_WINDOW_MOVE'; export const UI_WINDOW_MAXIMIZE = 'UI_WINDOW_MAXIMIZE'; export const UI_WINDOW_UNMAXIMIZE = 'UI_WINDOW_UNMAXIMIZE'; +export const UI_ENTER_QUICK_FULL_SCREEN = 'UI_ENTER_QUICK_FULL_SCREEN'; +export const UI_LEAVE_QUICK_FULL_SCREEN = 'UI_LEAVE_QUICK_FULL_SCREEN'; export const UI_OPEN_FILE = 'UI_OPEN_FILE'; diff --git a/lib/index.js b/lib/index.js index 55908f4d..5d5bb0d8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -80,6 +80,14 @@ rpc.on('split request vertical', () => { store_.dispatch(termGroupActions.requestVerticalSplit()); }); +rpc.on('enter quick full screen req', () => { + store_.dispatch(uiActions.enterQuickFullScreen()); +}); + +rpc.on('leave quick full screen req', () => { + store_.dispatch(uiActions.leaveQuickFullScreen()); +}); + rpc.on('reset fontSize req', () => { store_.dispatch(uiActions.resetFontSize()); });