From 7683d71d5eabd70722bd3f1e2d90294af0e196de Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 29 Nov 2023 17:56:00 +0100 Subject: [PATCH] WIP: OK > the button responds when clicked --- src/ui/application.c | 45 +------------------------------------------- src/ui/window.c | 29 ++++++++-------------------- 2 files changed, 9 insertions(+), 65 deletions(-) diff --git a/src/ui/application.c b/src/ui/application.c index 2d41c5f..c36052f 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -149,48 +149,5 @@ GemGraphClientApplication *gem_graph_client_application_new( NULL); } -/* button-event.c - * - * Compile: cc -ggdb button-event.c -o button-event $(pkg-config --cflags --libs gtk4) - * Run: ./button-event - * - * Author: Mohammed Sadiq - * - * SPDX-License-Identifier: LGPL-2.1-or-later OR CC0-1.0 - */ - -#include - -static gboolean -gesture_released_cb (GtkWidget *widget) -{ - g_warning ("do something"); - - return GDK_EVENT_STOP; -} - -static void -app_activated_cb (GtkApplication *app) -{ - GtkGesture *gesture; - GtkWindow *window; - GtkWidget *box, *label; - - window = GTK_WINDOW (gtk_application_window_new (app)); - gtk_window_set_default_size (window, 400, 300); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - label = gtk_label_new ("Hello"); - gtk_box_append (GTK_BOX (box), label); - gtk_window_set_child (window, box); - - gesture = gtk_gesture_click_new (); - - g_signal_connect_object (gesture, "released", - G_CALLBACK (gesture_released_cb), - box, G_CONNECT_SWAPPED); - gtk_widget_add_controller (label, GTK_EVENT_CONTROLLER (gesture)); - - gtk_window_present (window); -} +/* https://docs.gtk.org/gtk4/input-handling.html */ diff --git a/src/ui/window.c b/src/ui/window.c index a3ba2c8..107a698 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -245,38 +245,25 @@ GtkWidget *create_tree_label(void) #include -static gboolean -gesture_released_cb (GtkWidget *widget) +static void +print_hello (GtkWidget *widget, + gpointer data) { - g_warning ("do something"); - - printf("Hello ! I'm the button <> I've been clicked !!!\n"); - - return GDK_EVENT_STOP; + printf("Yes. I'm the new button <-> I've been clicked !!!\n"); +// return GDK_EVENT_STOP; } GtkWidget *create_tree_button(void) { - GtkGesture *gesture; GtkWidget *button; - const char *text = "Hello ! I'm the button"; + const char *text = "Hello ! I'm the new button. Click me !"; button = gtk_button_new_with_label(text); gtk_box_append(GTK_BOX(window->runlib_objects), button); gtk_widget_show(button); - gesture = gtk_gesture_click_new (); - GdkDevice *xxx = gtk_gesture_get_device (gesture); // printf("%s\n", xxx.class.name); - - if (gesture) printf("Hello ! I'm the button <> I'm being clicked !!! \n"); - //GtkGestureClick::pressed - - g_signal_connect_object (gesture, "released", - G_CALLBACK (gesture_released_cb), - GTK_BOX(window->runlib_objects), G_CONNECT_SWAPPED); - //Use G_CALLBACK() to cast the callback function to a GCallback. - - gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (gesture)); + g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); + //g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window); tree_c_test();