diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 706656be..7155e33e 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -332,6 +332,7 @@ class Terminal(Gtk.VBox): self.vte.connect('key-press-event', self.on_keypress) self.vte.connect('button-press-event', self.on_buttonpress) + self.vte.connect('scroll-event', self.on_mousewheel) self.vte.connect('popup-menu', self.popup_menu) srcvtetargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE)] @@ -834,6 +835,28 @@ class Terminal(Gtk.VBox): return(False) + def on_mousewheel(self, widget, event): + """Handler for modifier + mouse wheel scroll events""" + SMOOTH_SCROLL_UP = event.direction == Gdk.ScrollDirection.SMOOTH and event.delta_y <= 0. + SMOOTH_SCROLL_DOWN = event.direction == Gdk.ScrollDirection.SMOOTH and event.delta_y > 0. + if event.state & Gdk.ModifierType.CONTROL_MASK == Gdk.ModifierType.CONTROL_MASK: + # Ctrl + mouse wheel up/down + if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP: + self.zoom_in() + return (True) + elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN: + self.zoom_out() + return (True) + if event.state & Gdk.ModifierType.SHIFT_MASK == Gdk.ModifierType.SHIFT_MASK: + # Shift + mouse wheel up/down + if event.direction == Gdk.ScrollDirection.UP or SMOOTH_SCROLL_UP: + self.scroll_by_page(-1) + return (True) + elif event.direction == Gdk.ScrollDirection.DOWN or SMOOTH_SCROLL_DOWN: + self.scroll_by_page(1) + return (True) + return(False) + def popup_menu(self, widget, event=None): """Display the context menu""" menu = TerminalPopupMenu(self)