From 8d0f8a62ea7ab596d16a57cfc7bd345365eb6382 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 15 Jan 2023 13:35:21 +0000 Subject: [PATCH 1/3] Emulate discrete scrolling for zooming --- src/Widgets/SourceView.vala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index 13de21ee10..9cb7617aa6 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -38,6 +38,8 @@ namespace Scratch.Widgets { private SourceGutterRenderer git_diff_gutter_renderer; private const uint THROTTLE_MS = 400; + private double total_delta = 0; + private const double SCROLL_THRESHOLD = 1.0; public signal void style_changed (Gtk.SourceStyleScheme style); public signal void selection_changed (Gtk.TextIter start_iter, Gtk.TextIter end_iter); @@ -126,11 +128,17 @@ namespace Scratch.Widgets { granite_settings.notify["prefers-color-scheme"].connect (restore_settings); scroll_event.connect ((key_event) => { - if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y < 0) { - ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_in (); - return true; - } else if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y > 0) { - ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_out (); + var handled = false; + if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { + total_delta += key_event.delta_y; + if (total_delta < -SCROLL_THRESHOLD) { + ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_in (); + total_delta = 0.0; + } else if (total_delta > SCROLL_THRESHOLD) { + ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_out (); + total_delta = 0.0; + } + return true; } From 11cea3028ba888184d4640039e0667239ad9e808 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 15 Jan 2023 19:00:29 +0000 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Activate action not window function call Co-authored-by: Danielle Foré --- src/Widgets/SourceView.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index 9cb7617aa6..a88b0e86d3 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -132,10 +132,10 @@ namespace Scratch.Widgets { if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { total_delta += key_event.delta_y; if (total_delta < -SCROLL_THRESHOLD) { - ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_in (); + GLib.Application.get_default ().activate_action (MainWindow.ACTION_PREFIX + MainWindow.ACTION_ZOOM_IN, null); total_delta = 0.0; } else if (total_delta > SCROLL_THRESHOLD) { - ((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_out (); + GLib.Application.get_default ().activate_action (MainWindow.ACTION_PREFIX + MainWindow.ACTION_ZOOM_OUT, null); total_delta = 0.0; } From 87c0dedad559d2040719884976cad10ef91df197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 15 Jan 2023 13:57:08 -0800 Subject: [PATCH 3/3] Use get_action_group --- src/Widgets/SourceView.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala index a88b0e86d3..9bfabf0e69 100644 --- a/src/Widgets/SourceView.vala +++ b/src/Widgets/SourceView.vala @@ -132,10 +132,10 @@ namespace Scratch.Widgets { if (Gdk.ModifierType.CONTROL_MASK in key_event.state) { total_delta += key_event.delta_y; if (total_delta < -SCROLL_THRESHOLD) { - GLib.Application.get_default ().activate_action (MainWindow.ACTION_PREFIX + MainWindow.ACTION_ZOOM_IN, null); + get_action_group (MainWindow.ACTION_GROUP).activate_action (MainWindow.ACTION_ZOOM_IN, null); total_delta = 0.0; } else if (total_delta > SCROLL_THRESHOLD) { - GLib.Application.get_default ().activate_action (MainWindow.ACTION_PREFIX + MainWindow.ACTION_ZOOM_OUT, null); + get_action_group (MainWindow.ACTION_GROUP).activate_action (MainWindow.ACTION_ZOOM_OUT, null); total_delta = 0.0; }