Improve disabling autoscroll

Add the SHIFT + PAGE_UP keypress
Fix catching mouse scroll UP on some systems
This commit is contained in:
Philipp Hörist 2018-03-24 02:36:22 +01:00
parent 9314a0543b
commit af2c66b50b
1 changed files with 28 additions and 10 deletions

View File

@ -596,9 +596,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
valid, entries = self.keymap.get_entries_for_keyval(event.keyval) valid, entries = self.keymap.get_entries_for_keyval(event.keyval)
keycode = entries[0].keycode keycode = entries[0].keycode
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and keycode in ( if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and keycode in (
self.keycode_c, self.keycode_ins)) or ( self.keycode_c, self.keycode_ins)):
event.get_state() & Gdk.ModifierType.SHIFT_MASK and \ return False
event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up)):
if event.get_state() & Gdk.ModifierType.SHIFT_MASK and \
event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
self._on_scroll(None, event.keyval)
return False return False
self.parent_win.notebook.event(event) self.parent_win.notebook.event(event)
return True return True
@ -1224,6 +1227,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if pos != Gtk.PositionType.BOTTOM: if pos != Gtk.PositionType.BOTTOM:
return return
# Remove all events and set autoscroll True # Remove all events and set autoscroll True
app.log('autoscroll').info('Autoscroll enabled')
self.conv_textview.autoscroll = True self.conv_textview.autoscroll = True
if self.resource: if self.resource:
jid = self.contact.get_full_jid() jid = self.contact.get_full_jid()
@ -1253,12 +1257,26 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.redraw_after_event_removed(jid) self.redraw_after_event_removed(jid)
def _on_scroll(self, widget, event): def _on_scroll(self, widget, event):
if not self.conv_textview.autoscroll:
# autoscroll is already disabled
return
if widget is None:
# call from _conv_textview_key_press_event()
# SHIFT + Gdk.KEY_Page_Up
if event != Gdk.KEY_Page_Up:
return
else:
# On scrolliung UP disable autoscroll # On scrolliung UP disable autoscroll
# has_direction is on some systems always False
# so we cant use it
has_direction, direction = event.get_scroll_direction() has_direction, direction = event.get_scroll_direction()
if has_direction and direction == Gdk.ScrollDirection.UP: if direction != Gdk.ScrollDirection.UP:
return
# Check if we have a Scrollbar # Check if we have a Scrollbar
adjustment = self.conv_scrolledwindow.get_vadjustment() adjustment = self.conv_scrolledwindow.get_vadjustment()
if adjustment.get_upper() != adjustment.get_page_size(): if adjustment.get_upper() != adjustment.get_page_size():
app.log('autoscroll').info('Autoscroll disabled')
self.conv_textview.autoscroll = False self.conv_textview.autoscroll = False
def on_conversation_vadjustment_changed(self, adjustment): def on_conversation_vadjustment_changed(self, adjustment):