[gnome-builder] libide/sourceview: implement ctrl+scroll for zoom
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/sourceview: implement ctrl+scroll for zoom
- Date: Thu, 21 Jul 2022 05:31:10 +0000 (UTC)
commit 8a68ee2259e5dab79bc7bf59d8e313741f058bad
Author: Christian Hergert <chergert redhat com>
Date: Wed Jul 20 22:30:59 2022 -0700
libide/sourceview: implement ctrl+scroll for zoom
src/libide/sourceview/ide-source-view.c | 49 +++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
---
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 17348ce0e..642977010 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -573,6 +573,45 @@ ide_source_view_zoom_one_action (GtkWidget *widget,
ide_source_view_set_font_scale (self, 1);
}
+static void
+ide_source_view_zoom (IdeSourceView *self,
+ int amount)
+{
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ if (amount == 0)
+ self->font_scale = 0;
+ else
+ self->font_scale += amount;
+
+ ide_source_view_update_css (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FONT_SCALE]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_LEVEL]);
+}
+
+static gboolean
+on_scroll_scrolled_cb (GtkEventControllerScroll *scroll,
+ double dx,
+ double dy,
+ IdeSourceView *self)
+{
+ GdkModifierType mods;
+
+ g_assert (GTK_IS_EVENT_CONTROLLER_SCROLL (scroll));
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ mods = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
+
+ if ((mods & GDK_CONTROL_MASK) != 0)
+ {
+ ide_source_view_zoom (self, dy < 0 ? 1 : -1);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
ide_source_view_push_snippet (GtkSourceView *source_view,
GtkSourceSnippet *snippet,
@@ -796,6 +835,7 @@ ide_source_view_init (IdeSourceView *self)
GtkStyleContext *style_context;
GtkEventController *click;
GtkEventController *focus;
+ GtkEventController *scroll;
g_signal_connect (self,
"notify::buffer",
@@ -832,6 +872,15 @@ ide_source_view_init (IdeSourceView *self)
self);
gtk_widget_add_controller (GTK_WIDGET (self), focus);
+ /* Setup ctrl+scroll zoom */
+ scroll = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
+ gtk_event_controller_set_propagation_phase (scroll, GTK_PHASE_CAPTURE);
+ g_signal_connect (scroll,
+ "scroll",
+ G_CALLBACK (on_scroll_scrolled_cb),
+ self);
+ gtk_widget_add_controller (GTK_WIDGET (self), scroll);
+
/* This is sort of a layer vioaltion, but it's helpful for us to
* get the system font name and manage it invisibly.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]