From c12bd748be4117f29168951dbf8f6235a85f79ef Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 24 Sep 2022 12:43:48 +0300 Subject: [PATCH 36/36] gtk4: Implement mouse press handling for messagewin See osdn #45690 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/messagewin.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/client/gui-gtk-4.0/messagewin.c b/client/gui-gtk-4.0/messagewin.c index 0e225678bb..e11bcc35bc 100644 --- a/client/gui-gtk-4.0/messagewin.c +++ b/client/gui-gtk-4.0/messagewin.c @@ -244,26 +244,19 @@ static void meswin_dialog_row_activated_callback(GtkTreeView *view, care about right clicks on a row; this action centers on the tile associated with the event at that row (if applicable). ****************************************************************************/ -static gboolean meswin_dialog_button_press_callback(GtkWidget *widget, - GdkEvent *ev, - gpointer data) +static gboolean meswin_dialog_button_press_callback(GtkGestureClick *gesture, + int n_press, + double x, double y) { + GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); GtkTreePath *path = NULL; GtkTreeModel *model; GtkTreeIter iter; gint row; - guint button; - gdouble e_x, e_y; fc_assert_ret_val(GTK_IS_TREE_VIEW(widget), FALSE); - button = gdk_button_event_get_button(ev); - if (GDK_BUTTON_PRESS != gdk_event_get_event_type(ev) || 3 != button) { - return FALSE; - } - - gdk_event_get_position(ev, &e_x, &e_y); - if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), e_x, e_y, + if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, &path, NULL, NULL, NULL)) { return TRUE; } @@ -273,6 +266,7 @@ static gboolean meswin_dialog_button_press_callback(GtkWidget *widget, gtk_tree_model_get(model, &iter, MESWIN_COL_ID, &row, -1); meswin_goto(row); } + gtk_tree_path_free(path); return TRUE; @@ -327,6 +321,8 @@ static void meswin_dialog_init(struct meswin_dialog *pdialog) GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkTreeViewColumn *col; + GtkGesture *gesture; + GtkEventController *controller; fc_assert_ret(NULL != pdialog); @@ -354,8 +350,14 @@ static void meswin_dialog_init(struct meswin_dialog *pdialog) gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); g_signal_connect(view, "row_activated", G_CALLBACK(meswin_dialog_row_activated_callback), NULL); - g_signal_connect(view, "button-press-event", + + gesture = gtk_gesture_click_new(); + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3); + controller = GTK_EVENT_CONTROLLER(gesture); + g_signal_connect(controller, "pressed", G_CALLBACK(meswin_dialog_button_press_callback), NULL); + gtk_widget_add_controller(view, controller); + pdialog->tree_view = GTK_TREE_VIEW(view); renderer = gtk_cell_renderer_pixbuf_new(); -- 2.35.1