From e58a50e7ed418b6c55377e4064cd149dddba9876 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 26 Aug 2019 09:38:51 +0530 Subject: [PATCH] Shortcut for toggling fullscreen --- src/pyj/read_book/globals.pyj | 1 + src/pyj/read_book/overlay.pyj | 6 ++---- src/pyj/read_book/shortcuts.pyj | 6 ++++++ src/pyj/read_book/ui.pyj | 9 ++++++++- src/pyj/read_book/view.pyj | 2 ++ src/pyj/utils.pyj | 3 ++- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/globals.pyj b/src/pyj/read_book/globals.pyj index b058c3dfa9..eed6045926 100644 --- a/src/pyj/read_book/globals.pyj +++ b/src/pyj/read_book/globals.pyj @@ -82,4 +82,5 @@ ui_operations = { 'delete_book': None, 'focus_iframe': None, 'toggle_toc': None, + 'toggle_full_screen': None, } diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 9de4363ce3..b769e2dbef 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -19,9 +19,7 @@ from read_book.prefs.main import create_prefs_panel from read_book.toc import create_toc_panel from read_book.word_actions import create_word_actions_panel from session import get_device_uuid -from utils import ( - full_screen_element, is_ios, request_full_screen, safe_set_inner_html -) +from utils import full_screen_element, is_ios, safe_set_inner_html from widgets import create_button, create_spinner @@ -278,7 +276,7 @@ class MainOverlay: # {{{ if not full_screen_element() and not is_ios: # No fullscreen on iOS, see http://caniuse.com/#search=fullscreen full_screen_actions.push( - ac(_('Full screen'), _('Enter full screen mode'), def(): request_full_screen(), self.overlay.hide();, 'full-screen') + ac(_('Full screen'), _('Enter full screen mode'), def(): self.overlay.hide(), ui_operations.toggle_full_screen();, 'full-screen') ) if full_screen_actions.length: actions_div.appendChild(E.ul(*full_screen_actions)) diff --git a/src/pyj/read_book/shortcuts.pyj b/src/pyj/read_book/shortcuts.pyj index 0bee228ad5..5b229f517a 100644 --- a/src/pyj/read_book/shortcuts.pyj +++ b/src/pyj/read_book/shortcuts.pyj @@ -186,6 +186,12 @@ SHORTCUTS = { 'ui', _('Decrease font size'), ), + + 'toggle_full_screen': desc( + v"['F11', 'Ctrl+Shift+F']", + 'ui', + _('Toggle full screen'), + ), } diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 11d0fffcab..189380951f 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -17,7 +17,7 @@ from modals import create_simple_dialog_markup, error_dialog from read_book.db import get_db from read_book.globals import ui_operations from read_book.view import View -from utils import debounce, human_readable +from utils import debounce, full_screen_element, human_readable, request_full_screen from widgets import create_button RENDER_VERSION = __RENDER_VERSION__ @@ -69,6 +69,7 @@ class ReadUI: ui_operations.delete_book = self.delete_book.bind(self) ui_operations.focus_iframe = self.focus_iframe.bind(self) ui_operations.toggle_toc = self.toggle_toc.bind(self) + ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self) def on_resize(self): self.view.on_resize() @@ -170,6 +171,12 @@ class ReadUI: def toggle_toc(self): self.view.overlay.show_toc() + def toggle_full_screen(self): + if full_screen_element(): + document.exitFullscreen() + else: + request_full_screen(document.documentElement) + def update_color_scheme(self): self.view.update_color_scheme() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index a8ad0090c6..fc70765ea6 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -241,6 +241,8 @@ class View: self.bump_font_size({'increase': True}) elif data.name is 'decrease_font_size': self.bump_font_size({'increase': False}) + elif data.name is 'toggle_full_screen': + ui_operations.toggle_full_screen() def on_selection_change(self, data): self.currently_showing.selected_text = data.text diff --git a/src/pyj/utils.pyj b/src/pyj/utils.pyj index dd1da80328..cb7a7054c6 100644 --- a/src/pyj/utils.pyj +++ b/src/pyj/utils.pyj @@ -74,8 +74,9 @@ def encode_query_with_path(query, path): def request_full_screen(elem): elem = elem or document.documentElement + options = {'navigationUI': 'hide'} if elem.requestFullScreen: - elem.requestFullScreen() + elem.requestFullScreen(options) elif elem.webkitRequestFullScreen: elem.webkitRequestFullScreen() elif elem.mozRequestFullScreen: