diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 427a59133c..9894d831ec 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -197,7 +197,7 @@ class IframeBoss: if current_layout_mode() is 'flow': flow_scroll_by_page(backwards) else: - paged_scroll_by_page(backwards, True) + paged_scroll_by_page(backwards, data.all_pages_on_screen) def change_font_size(self, data): if data.base_font_size? and data.base_font_size != opts.base_font_size: diff --git a/src/pyj/read_book/paged_mode.pyj b/src/pyj/read_book/paged_mode.pyj index f7c886cddc..35f76c3197 100644 --- a/src/pyj/read_book/paged_mode.pyj +++ b/src/pyj/read_book/paged_mode.pyj @@ -446,7 +446,10 @@ def progress_frac(frac): def onwheel(evt): if evt.deltaY: backward = evt.deltaY < 0 - x = previous_col_location() if backward else next_col_location() + if opts.paged_wheel_scrolls_by_screen: + x = previous_screen_location() if backward else next_screen_location() + else: + x = previous_col_location() if backward else next_col_location() if x is -1: get_boss().send_message('next_spine_item', previous=backward) else: diff --git a/src/pyj/read_book/prefs/main.pyj b/src/pyj/read_book/prefs/main.pyj index 30d40df08d..53806ac07c 100644 --- a/src/pyj/read_book/prefs/main.pyj +++ b/src/pyj/read_book/prefs/main.pyj @@ -12,6 +12,7 @@ from read_book.prefs.colors import commit_colors, create_colors_panel from read_book.prefs.fonts import commit_fonts, create_fonts_panel from read_book.prefs.head_foot import commit_head_foot, create_head_foot_panel from read_book.prefs.keyboard import commit_keyboard, create_keyboard_panel +from read_book.prefs.scrolling import commit_scrolling, create_scrolling_panel from read_book.prefs.layout import commit_layout, create_layout_panel from read_book.prefs.misc import commit_misc, create_misc_panel from read_book.prefs.user_stylesheet import ( @@ -71,6 +72,7 @@ class Prefs: create_item(_('Page layout'), def():self.show_panel('layout');, _('Page margins and number of pages per screen')), create_item(_('Styles'), def():self.show_panel('user_stylesheet');, _('Style rules for text and background image')), create_item(_('Headers and footers'), def():self.show_panel('head_foot');, _('Customize the headers and footers')), + create_item(_('Scrolling behavior'), def():self.show_panel('scrolling');, _('Control how the viewer scrolls')), create_item(_('Keyboard shortcuts'), def():self.show_panel('keyboard');, _('Customize the keyboard shortcuts')), ] if runtime.is_standalone_viewer: @@ -129,6 +131,13 @@ class Prefs: def close_keyboard(self): commit_keyboard(self.onchange, self.container) + def display_scrolling(self, container): + document.getElementById(self.title_id).textContent = _('Scrolling behavior') + create_scrolling_panel(container, self.onclose) + + def close_scrolling(self): + commit_scrolling(self.onchange, self.container) + def create_prefs_panel(container, close_func, on_change): Prefs(container, close_func, on_change) diff --git a/src/pyj/read_book/prefs/scrolling.pyj b/src/pyj/read_book/prefs/scrolling.pyj new file mode 100644 index 0000000000..62964cacfa --- /dev/null +++ b/src/pyj/read_book/prefs/scrolling.pyj @@ -0,0 +1,59 @@ +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2016, Kovid Goyal +from __python__ import bound_methods, hash_literals + +from elementmaker import E +from gettext import gettext as _ + +from book_list.globals import get_session_data +from dom import unique_id +from widgets import create_button +from session import defaults + +CONTAINER = unique_id('standalone-scrolling-settings') + + +def restore_defaults(): + container = get_container() + for control in container.querySelectorAll('input[name]'): + control.checked = defaults[control.getAttribute('name')] + + +def get_container(): + return document.getElementById(CONTAINER) + + +def create_scrolling_panel(container): + container.appendChild(E.div(id=CONTAINER, style='margin: 1rem')) + container = container.lastChild + sd = get_session_data() + + def cb(name, text): + ans = E.input(type='checkbox', name=name) + if sd.get(name): + ans.checked = True + return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text)) + + container.appendChild(E.div(style='margin-top:1ex', _( + 'Control how mouse based scrolling works in paged mode'))) + container.appendChild(cb( + 'paged_wheel_scrolls_by_screen', _('Mouse wheel scrolls by screen fulls instead of pages'))) + container.appendChild(cb( + 'paged_margin_clicks_scroll_by_screen', _('Clicking on the margins scrolls by screen fulls instead of pages'))) + + container.appendChild(E.div( + style='margin-top: 1rem', create_button(_('Restore defaults'), action=restore_defaults) + )) + + +develop = create_scrolling_panel + + +def commit_scrolling(onchange): + sd = get_session_data() + container = get_container() + for control in container.querySelectorAll('input[name]'): + name = control.getAttribute('name') + val = control.checked + sd.set(name, None if val is defaults[name] else val) + onchange() diff --git a/src/pyj/read_book/settings.pyj b/src/pyj/read_book/settings.pyj index e06842d750..2e925bf732 100644 --- a/src/pyj/read_book/settings.pyj +++ b/src/pyj/read_book/settings.pyj @@ -16,8 +16,9 @@ def update_settings(settings): opts.base_font_size = max(8, min(settings.base_font_size or 16, 64)) opts.user_stylesheet = settings.user_stylesheet or '' opts.hide_tooltips = settings.hide_tooltips - opts.cover_preserve_aspect_ratio = settings.cover_preserve_aspect_ratio + opts.cover_preserve_aspect_ratio = v'!!settings.cover_preserve_aspect_ratio' opts.bg_image_fade = settings.bg_image_fade or 'transparent' + opts.paged_wheel_scrolls_by_screen = v'!!settings.paged_wheel_scrolls_by_screen' update_settings() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 8c61239a4b..a66385100b 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -225,12 +225,14 @@ class View: def left_margin_clicked(self, event): if event.button is 0: event.preventDefault(), event.stopPropagation() - self.iframe_wrapper.send_message('next_screen', backwards=True) + sd = get_session_data() + self.iframe_wrapper.send_message('next_screen', backwards=True, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen')) def right_margin_clicked(self, event): if event.button is 0: event.preventDefault(), event.stopPropagation() - self.iframe_wrapper.send_message('next_screen', backwards=False) + sd = get_session_data() + self.iframe_wrapper.send_message('next_screen', backwards=False, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen')) def top_margin_clicked(self, event): if event.button is 0: @@ -584,6 +586,7 @@ class View: 'keyboard_shortcuts': sd.get('keyboard_shortcuts'), 'hide_tooltips': sd.get('hide_tooltips'), 'cover_preserve_aspect_ratio': sd.get('cover_preserve_aspect_ratio'), + 'paged_wheel_scrolls_by_screen': sd.get('paged_wheel_scrolls_by_screen'), } def show_name(self, name, initial_position=None): diff --git a/src/pyj/session.pyj b/src/pyj/session.pyj index b029876b2f..707dddfa0c 100644 --- a/src/pyj/session.pyj +++ b/src/pyj/session.pyj @@ -49,6 +49,8 @@ defaults = { 'standalone_font_settings': {}, 'standalone_misc_settings': {}, 'standalone_recently_opened': v'[]', + 'paged_wheel_scrolls_by_screen': False, + 'paged_margin_clicks_scroll_by_screen': True, } is_local_setting = {