[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 22/46] list-view: Use event controllers for pointer and key events
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 22/46] list-view: Use event controllers for pointer and key events
- Date: Mon, 16 Aug 2021 09:44:40 +0000 (UTC)
commit 75412d321920a0fc9ad2fa72a9ae2a52a1eba3be
Author: Ernestas Kulik <ernestask gnome org>
Date: Tue Jul 10 15:05:50 2018 +0300
list-view: Use event controllers for pointer and key events
Rebased and ammended by António Fernandes <antoniof gnome org>
(Some style changes in the original have been extracted into
the next commit, for ease of review).
src/nautilus-list-view-private.h | 2 +
src/nautilus-list-view.c | 132 +++++++++++++++------------------------
2 files changed, 54 insertions(+), 80 deletions(-)
---
diff --git a/src/nautilus-list-view-private.h b/src/nautilus-list-view-private.h
index 9d4cbad42..c874c38f7 100644
--- a/src/nautilus-list-view-private.h
+++ b/src/nautilus-list-view-private.h
@@ -75,5 +75,7 @@ struct NautilusListViewDetails {
GtkGesture *tree_view_drag_gesture;
GtkGesture *tree_view_multi_press_gesture;
+ GtkEventController *motion_controller;
+ GtkEventController *key_controller;
};
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 0ee93f640..c5771617e 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -317,30 +317,24 @@ nautilus_list_view_did_not_drag (NautilusListView *view,
gtk_tree_path_free (path);
}
-static gboolean
-on_motion_notify (GtkWidget *widget,
- GdkEvent *event,
- gpointer callback_data)
+static void
+on_event_controller_motion_motion (GtkEventControllerMotion *controller,
+ double x,
+ double y,
+ gpointer user_data)
{
NautilusListView *view;
- gdouble x;
- gdouble y;
-
- view = NAUTILUS_LIST_VIEW (callback_data);
-
- /* Remove after switching to GTK+ 4. */
- if (gdk_event_get_window (event) != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)))
- {
- return GDK_EVENT_PROPAGATE;
- }
+ GtkWidget *widget;
- g_assert (gdk_event_get_coords (event, &x, &y));
+ view = user_data;
if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
{
GtkTreePath *old_hover_path;
+ widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
old_hover_path = view->details->hover_path;
+
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
x, y,
&view->details->hover_path,
@@ -363,18 +357,15 @@ on_motion_notify (GtkWidget *widget,
gtk_tree_path_free (old_hover_path);
}
}
-
- return GDK_EVENT_PROPAGATE;
}
-static gboolean
-on_leave_notify (GtkWidget *widget,
- GdkEvent *event,
- gpointer callback_data)
+static void
+on_event_controller_motion_leave (GtkEventControllerMotion *controller,
+ gpointer user_data)
{
NautilusListView *view;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = user_data;
if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
view->details->hover_path != NULL)
@@ -382,30 +373,26 @@ on_leave_notify (GtkWidget *widget,
gtk_tree_path_free (view->details->hover_path);
view->details->hover_path = NULL;
}
-
- return GDK_EVENT_PROPAGATE;
}
-static gboolean
-on_enter_notify (GtkWidget *widget,
- GdkEvent *event,
- gpointer callback_data)
+static void
+on_event_controller_motion_enter (GtkEventControllerMotion *controller,
+ double x,
+ double y,
+ gpointer user_data)
{
NautilusListView *view;
+ GtkWidget *widget;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = user_data;
if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
{
- gdouble x;
- gdouble y;
-
if (view->details->hover_path != NULL)
{
gtk_tree_path_free (view->details->hover_path);
}
-
- g_assert (gdk_event_get_coords (event, &x, &y));
+ widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
x, y,
@@ -417,8 +404,6 @@ on_enter_notify (GtkWidget *widget,
gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
}
}
-
- return GDK_EVENT_PROPAGATE;
}
static void
@@ -889,27 +874,23 @@ on_tree_view_multi_press_gesture_released (GtkGestureMultiPress *gesture,
}
static gboolean
-key_press_callback (GtkWidget *widget,
- GdkEvent *event,
- gpointer callback_data)
+on_event_controller_key_key_pressed (GtkEventControllerKey *controller,
+ unsigned int keyval,
+ unsigned int keycode,
+ GdkModifierType state,
+ gpointer user_data)
{
+ GtkWidget *widget;
NautilusFilesView *view;
GtkTreeView *tree_view;
- guint keyval;
- GdkModifierType state;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
+ view = NAUTILUS_FILES_VIEW (user_data);
tree_view = GTK_TREE_VIEW (widget);
NAUTILUS_LIST_VIEW (view)->details->last_event_button_x = -1;
NAUTILUS_LIST_VIEW (view)->details->last_event_button_y = -1;
- if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval)))
- {
- g_return_val_if_reached (GDK_EVENT_PROPAGATE);
- }
- gdk_event_get_state (event, &state);
-
if (keyval == GDK_KEY_F10)
{
if ((state & GDK_CONTROL_MASK) != 0)
@@ -990,36 +971,6 @@ key_press_callback (GtkWidget *widget,
return GDK_EVENT_PROPAGATE;
}
-static gboolean
-on_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
-{
- GdkEventType event_type;
-
- event_type = gdk_event_get_event_type (event);
-
- /* TODO: Replace motion events with motion controllers. */
- if (event_type == GDK_MOTION_NOTIFY)
- {
- return on_motion_notify (widget, event, user_data);
- }
- else if (event_type == GDK_ENTER_NOTIFY)
- {
- return on_enter_notify (widget, event, user_data);
- }
- else if (event_type == GDK_LEAVE_NOTIFY)
- {
- return on_leave_notify (widget, event, user_data);
- }
- else if (event_type == GDK_KEY_PRESS)
- {
- return key_press_callback (widget, event, user_data);
- }
-
- return GDK_EVENT_PROPAGATE;
-}
-
static void
subdirectory_done_loading_callback (NautilusDirectory *directory,
NautilusListView *view)
@@ -2126,6 +2077,7 @@ create_and_set_up_tree_view (NautilusListView *view)
gchar **default_column_order, **default_visible_columns;
GtkWidget *content_widget;
GtkGesture *longpress_gesture;
+ GtkEventController *controller;
content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
@@ -2192,8 +2144,26 @@ create_and_set_up_tree_view (NautilusListView *view)
g_signal_connect (view->details->tree_view_multi_press_gesture, "released",
G_CALLBACK (on_tree_view_multi_press_gesture_released), view);
- g_signal_connect_object (view->details->tree_view, "event",
- G_CALLBACK (on_event), view, 0);
+ controller = gtk_event_controller_motion_new (GTK_WIDGET (view->details->tree_view));
+ view->details->motion_controller = controller;
+
+ gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+
+ g_signal_connect (controller, "enter",
+ G_CALLBACK (on_event_controller_motion_enter), view);
+ g_signal_connect (controller, "leave",
+ G_CALLBACK (on_event_controller_motion_leave), view);
+ g_signal_connect (controller, "motion",
+ G_CALLBACK (on_event_controller_motion_motion), view);
+
+ controller = gtk_event_controller_key_new (GTK_WIDGET (view->details->tree_view));
+ view->details->key_controller = controller;
+
+ gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_BUBBLE);
+
+ g_signal_connect (controller, "key-pressed",
+ G_CALLBACK (on_event_controller_key_key_pressed), view);
+
g_signal_connect_object (view->details->tree_view, "test-expand-row",
G_CALLBACK (test_expand_row_callback), view, 0);
g_signal_connect_object (view->details->tree_view, "row-expanded",
@@ -3717,6 +3687,8 @@ nautilus_list_view_dispose (GObject *object)
g_clear_object (&list_view->details->tree_view_drag_gesture);
g_clear_object (&list_view->details->tree_view_multi_press_gesture);
+ g_clear_object (&list_view->details->motion_controller);
+ g_clear_object (&list_view->details->key_controller);
G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]