Implement wheel scrolling

This commit is contained in:
Kovid Goyal 2016-11-29 10:00:49 +05:30
parent 5ee4458e04
commit 11182b3682
5 changed files with 32 additions and 13 deletions

View File

@ -228,7 +228,8 @@ class CharGrid:
self.screen.mark_as_dirty()
def scroll(self, amt, upwards=True):
amt = {'line': 1, 'page': self.screen.lines - 1, 'full': self.screen.historybuf.count}[amt]
if not isinstance(amt, int):
amt = {'line': 1, 'page': self.screen.lines - 1, 'full': self.screen.historybuf.count}[amt]
if not upwards:
amt *= -1
y = max(0, min(self.scrolled_by + amt, self.screen.historybuf.count))

View File

@ -45,6 +45,7 @@ type_map = {
'cursor_opacity': to_opacity,
'repaint_delay': int,
'window_border_width': float,
'wheel_scroll_multiplier': float,
}
for name in 'foreground background cursor active_border_color inactive_border_color selection_foreground selection_background'.split():

View File

@ -30,6 +30,9 @@ font_size 11.0
# Number of lines of history to keep in memory for scrolling back
scrollback_lines 2000
# Wheel scroll multiplier (modify the amount scrolled by the mouse wheel)
wheel_scroll_multiplier 5.0
# Delay (in milliseconds) between screen updates. Decreasing it, increases fps
# at the cost of more CPU usage. The default value yields ~50fps which is more
# that sufficient for most uses.

View File

@ -332,12 +332,12 @@ class TabManager(Thread):
def on_mouse_move(self, window, xpos, ypos):
w = self.window_for_pos(*glfw.glfwGetCursorPos(window))
if w is not None:
w.on_mouse_move(xpos, ypos)
w.on_mouse_move(window, xpos, ypos)
def on_mouse_scroll(self, window, x, y):
w = self.window_for_pos(*glfw.glfwGetCursorPos(window))
if w is not None:
w.on_mouse_scroll(x, y)
w.on_mouse_scroll(window, x, y)
# GUI thread API {{{
def render(self):

View File

@ -10,7 +10,7 @@ from functools import partial
import glfw
import glfw_constants
from .char_grid import CharGrid
from .constants import wakeup, tab_manager, appname, WindowGeometry, queue_action
from .constants import wakeup, tab_manager, appname, WindowGeometry
from .fast_data_types import (
BRACKETED_PASTE_START, BRACKETED_PASTE_END, Screen, read_bytes_dump, read_bytes
)
@ -124,12 +124,20 @@ class Window:
self.paste_from_selection()
return
def on_mouse_move(self, x, y):
def on_mouse_move(self, window, x, y):
if self.char_grid.current_selection.in_progress:
self.char_grid.update_drag(None, max(0, x - self.geometry.left), max(0, y - self.geometry.top))
def on_mouse_scroll(self, x, y):
pass
def on_mouse_scroll(self, window, x, y):
ignore_mouse_mode = (
glfw.glfwGetKey(window, glfw_constants.GLFW_KEY_LEFT_SHIFT) == glfw_constants.GLFW_PRESS or
glfw.glfwGetKey(window, glfw_constants.GLFW_KEY_RIGHT_SHIFT) == glfw_constants.GLFW_PRESS or
not self.screen.mouse_button_tracking_enabled())
if ignore_mouse_mode:
s = int(round(y * self.opts.wheel_scroll_multiplier))
if abs(s) > 0:
self.char_grid.scroll(abs(s), s > 0)
glfw.glfwPostEmptyEvent()
# actions {{{
@ -150,22 +158,28 @@ class Window:
self.paste(text)
def scroll_line_up(self):
queue_action(self.char_grid.scroll, 'line', True)
self.char_grid.scroll('line', True)
glfw.glfwPostEmptyEvent()
def scroll_line_down(self):
queue_action(self.char_grid.scroll, 'line', False)
self.char_grid.scroll('line', False)
glfw.glfwPostEmptyEvent()
def scroll_page_up(self):
queue_action(self.char_grid.scroll, 'page', True)
self.char_grid.scroll('page', True)
glfw.glfwPostEmptyEvent()
def scroll_page_down(self):
queue_action(self.char_grid.scroll, 'page', False)
self.char_grid.scroll('page', False)
glfw.glfwPostEmptyEvent()
def scroll_home(self):
queue_action(self.char_grid.scroll, 'full', True)
self.char_grid.scroll('full', True)
glfw.glfwPostEmptyEvent()
def scroll_end(self):
queue_action(self.char_grid.scroll, 'full', False)
self.char_grid.scroll('full', False)
glfw.glfwPostEmptyEvent()
# }}}
def dump_commands(self, *a):