"click" event on a GtkSpinEntry
Hi all, I want to catch a click/button-press event *only* on the entry part of a GtkSpinButton. Put in other words I want to filter out events happening on the up and down buttons of a spin entry. I tried several strategies until actually finding a working approach. The implementation though is too hackish for my taste: #define WHEEL_MASK (GDK_BUTTON1_MOTION_MASK|GDK_BUTTON3_MOTION_MASK) static gboolean button_press_event_callback(GtkSpinButton *spin, GdkEventButton *event) { if ((gdk_window_get_events(event->window) & WHEEL_MASK) > 0) { ... } } I found sperimentally that the event mask of the up and down GdkWindows are different from the GdkWindow of the entry and I'm leveraging this fact to filter out the unwanted events. This anyway could be an implementation detail so this behavior can potentially be changed in the future. Is there a more reliable way to accomplish the same result? Ciao. -- Nicola ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: "click" event on a GtkSpinEntry
Hi Nicola, This isn't pretty but it works. There is a good read about the spin button at https://blog.gtk.org/author/ebassi/ with Tim Bader on April 25, 2017. I don't know if you have seen that. My first try was just to get the GdkWindow of the spin button but that gave me the main window. No help there. Noticed that the cursor changed with the mouse movement so I went with that. Probably even more hackish than your solution. Eric /* gcc -Wall click1.c -o click1 `pkg-config --cflags --libs gtk+-3.0` Tested with Ubuntu16.04 and GTK3.18 */ #include static gboolean button_press(GtkWidget *spin, GdkEvent *event, gpointer data) { GdkCursor *cursor=gdk_window_get_cursor(event->button.window); if(cursor!=NULL) g_print("Text Entry Clicked\n"); return FALSE; } int main(int argc, char *argv[]) { gtk_init (&argc, &argv); GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Click"); gtk_window_set_default_size(GTK_WINDOW(window), 200, 50); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); GtkWidget *spin=gtk_spin_button_new_with_range(0, 10, 1); gtk_widget_set_hexpand(spin, TRUE); gtk_widget_add_events(spin, GDK_BUTTON_PRESS_MASK); g_signal_connect(spin, "button-press-event", G_CALLBACK(button_press), NULL); GtkWidget *grid=gtk_grid_new(); gtk_container_set_border_width(GTK_CONTAINER(grid), 10); gtk_grid_attach(GTK_GRID(grid), spin, 0, 0, 1, 1); gtk_container_add(GTK_CONTAINER(window), grid); gtk_widget_show_all(window); gtk_main(); return 0; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: "click" event on a GtkSpinEntry
Il Tue, 22 Aug 2017 15:10:44 -0400 cecas...@aol.com scrisse: > ... > There is a good read about the spin button at > > https://blog.gtk.org/author/ebassi/ > > with Tim Bader on April 25, 2017. I don't know if you have seen that. Hi Eric, no, I did not see that... it would have saved me some reverse engineering time. > My first try was just to get the GdkWindow of the spin button > but that gave me the main window. No help there. Yes, that was my second attempt too. My first one was to check for the presence of the spin callback. I was using g_main_context_find_source_by_user_data() with the instance as user_data but I soon discovered the argument of that callback is wrapped by gdk_threads_add_timeout() [1] [2], so I gave up. [1] https://git.gnome.org/browse/gtk+/tree/gtk/gtkspinbutton.c#n769 [2] https://git.gnome.org/browse/gtk+/tree/gdk/gdk.c?h=3.22.19#n929 > Noticed that > the cursor changed with the mouse movement so I went with that. > Probably even more hackish than your solution. That is really smart and dirty! Yes, the hackishness level is still quite high. Many thanks for the suggestions, really appreciated. It seems the solution requires a macgyverism after all. Ciao. -- Nicola ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list