[nautilus/wip/antoniof/experimental-gtk4-build: 19/52] Scroll-event for ZOOM
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/experimental-gtk4-build: 19/52] Scroll-event for ZOOM
- Date: Fri, 31 Dec 2021 23:58:45 +0000 (UTC)
commit 74c39160eea9fa7f9dedcb2cba439453fa60a9d8
Author: António Fernandes <antoniof gnome org>
Date: Mon Dec 20 16:53:36 2021 +0000
Scroll-event for ZOOM
src/nautilus-files-view.c | 84 +++++++++++++++--------------------------------
1 file changed, 27 insertions(+), 57 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 05066e732..0398f6d95 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -9127,73 +9127,37 @@ nautilus_files_view_set_property (GObject *object,
/* handle Ctrl+Scroll, which will cause a zoom-in/out */
static gboolean
-on_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+on_scroll (GtkEventControllerScroll *scroll,
+ gdouble dx,
+ gdouble dy,
+ gpointer user_data)
{
NautilusFilesView *directory_view;
- static gdouble total_delta_y = 0;
GdkModifierType state;
+ GdkEvent *event;
GdkScrollDirection direction;
- gdouble delta_x, delta_y;
- directory_view = NAUTILUS_FILES_VIEW (widget);
-
- if (gdk_event_get_event_type (event) != GDK_SCROLL)
- {
- return GDK_EVENT_PROPAGATE;
- }
-
- if (!gdk_event_get_state (event, &state))
- {
- return GDK_EVENT_PROPAGATE;
- }
+ directory_view = NAUTILUS_FILES_VIEW (user_data);
+ state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (scroll));
if (!(state & GDK_CONTROL_MASK))
{
return GDK_EVENT_PROPAGATE;
}
- if (gdk_event_get_scroll_direction (event, &direction))
+ event = gtk_event_controller_get_current_event (GTK_EVENT_CONTROLLER (scroll));
+ direction = gdk_scroll_event_get_direction (event);
+ if (direction == GDK_SCROLL_UP)
{
- if (direction == GDK_SCROLL_UP)
- {
- /* Zoom In */
- nautilus_files_view_bump_zoom_level (directory_view, 1);
- return GDK_EVENT_STOP;
- }
- else if (direction == GDK_SCROLL_DOWN)
- {
- /* Zoom Out */
- nautilus_files_view_bump_zoom_level (directory_view, -1);
- return GDK_EVENT_STOP;
- }
+ /* Zoom In */
+ nautilus_files_view_bump_zoom_level (directory_view, 1);
+ return GDK_EVENT_STOP;
}
-
- if (gdk_event_get_scroll_deltas (event, &delta_x, &delta_y))
+ else if (direction == GDK_SCROLL_DOWN)
{
- /* try to emulate a normal scrolling event by summing deltas */
- total_delta_y += delta_y;
-
- if (total_delta_y >= 1)
- {
- total_delta_y = 0;
- /* emulate scroll down */
- nautilus_files_view_bump_zoom_level (directory_view, -1);
- return GDK_EVENT_STOP;
- }
- else if (total_delta_y <= -1)
- {
- total_delta_y = 0;
- /* emulate scroll up */
- nautilus_files_view_bump_zoom_level (directory_view, 1);
- return GDK_EVENT_STOP;
- }
- else
- {
- /* eat event */
- return GDK_EVENT_STOP;
- }
+ /* Zoom Out */
+ nautilus_files_view_bump_zoom_level (directory_view, -1);
+ return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
@@ -9517,6 +9481,7 @@ nautilus_files_view_init (NautilusFilesView *view)
#endif
NautilusDirectory *scripts_directory;
NautilusDirectory *templates_directory;
+ GtkEventController *controller;
gchar *templates_uri;
#if 0 && NAUTILUS_CLIPBOARD_NEEDS_GTK4_REIMPLEMENTATION
GtkClipboard *clipboard;
@@ -9617,10 +9582,15 @@ nautilus_files_view_init (NautilusFilesView *view)
GTK_POLICY_AUTOMATIC);
gtk_widget_show (priv->scrolled_window);
- g_signal_connect_swapped (priv->scrolled_window,
- "event",
- G_CALLBACK (on_event),
- view);
+ controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL |
+ GTK_EVENT_CONTROLLER_SCROLL_DISCRETE);
+ gtk_widget_add_controller (priv->scrolled_window, controller);
+ gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+ g_signal_connect (controller,
+ "scroll",
+ G_CALLBACK (on_scroll),
+ view);
+
g_signal_connect_swapped (priv->scrolled_window,
"popup-menu",
G_CALLBACK (popup_menu_callback),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]