[ghex] tab: Implement middle-click-to-close gesture
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] tab: Implement middle-click-to-close gesture
- Date: Thu, 5 May 2022 18:40:45 +0000 (UTC)
commit eebf66bb2b2bca20ba8f41c3d049821cca68611b
Author: Logan Rathbone <poprocks gmail com>
Date: Tue May 3 18:21:30 2022 -0400
tab: Implement middle-click-to-close gesture
src/ghex-notebook-tab.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/src/ghex-notebook-tab.c b/src/ghex-notebook-tab.c
index 79e4e51..5c1657e 100644
--- a/src/ghex-notebook-tab.c
+++ b/src/ghex-notebook-tab.c
@@ -79,14 +79,9 @@ ghex_notebook_tab_document_changed_cb (HexDocument *doc,
}
static void
-ghex_notebook_tab_close_click_cb (GtkButton *button,
- gpointer user_data)
+emit_close_request (GHexNotebookTab *self)
{
- GHexNotebookTab *self = GHEX_NOTEBOOK_TAB(user_data);
-
- g_signal_emit(self,
- signals[CLOSE_REQUEST],
- 0); /* GQuark detail (just set to 0 if unknown) */
+ g_signal_emit (self, signals[CLOSE_REQUEST], 0);
}
@@ -97,6 +92,7 @@ ghex_notebook_tab_init (GHexNotebookTab *self)
{
GtkWidget *widget = GTK_WIDGET (self);
GtkLayoutManager *layout_manager;
+ GtkGesture *gesture;
/* Set spacing between label and close button. */
@@ -119,10 +115,22 @@ ghex_notebook_tab_init (GHexNotebookTab *self)
gtk_widget_set_parent (self->label, widget);
gtk_widget_set_parent (self->close_btn, widget);
+ /* Setup middle click gesture */
+
+ gesture = gtk_gesture_click_new ();
+
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE(gesture),
+ GDK_BUTTON_MIDDLE);
+
+ g_signal_connect_swapped (gesture, "pressed",
+ G_CALLBACK(emit_close_request), self);
+
+ gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER(gesture));
+
/* SIGNALS */
- g_signal_connect (self->close_btn, "clicked",
- G_CALLBACK(ghex_notebook_tab_close_click_cb), self);
+ g_signal_connect_swapped (self->close_btn, "clicked",
+ G_CALLBACK(emit_close_request), self);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]