Created
December 19, 2009 10:04
-
-
Save bert/260034 to your computer and use it in GitHub Desktop.
How to use and process GTK enter or leave signals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Demonstration of a minimal implementation of a button with enter and leave signals. | |
Requires: | |
gtk+-2.0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* \file enter_and_leave_signals_demo.c | |
* | |
* \brief Demonstration of a minimal implementation of a button with enter and | |
* leave signals. | |
*/ | |
#include <gtk/gtk.h> | |
static gboolean | |
enter (GtkWidget *ebox, GdkEventCrossing *event) | |
{ | |
g_print ("Gotcha!\n"); | |
return FALSE; | |
} | |
static gboolean | |
leave (GtkWidget *ebox, GdkEventCrossing *event) | |
{ | |
g_print ("Oops!\n"); | |
return FALSE; | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
GtkWidget *window; | |
GtkWidget *button; | |
/* Initialise gtk. */ | |
gtk_init (&argc, &argv); | |
/* Create a window. */ | |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
/* Set event masks for notify of signals. */ | |
gtk_widget_set_events (GTK_WINDOW (window), GDK_ENTER_NOTIFY_MASK); | |
gtk_widget_add_events (GTK_WINDOW (window), GDK_LEAVE_NOTIFY_MASK); | |
/* Add a quit signal to the window. */ | |
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); | |
/* Create a button with a label. */ | |
button = gtk_button_new_with_label ("Don't Click Me"); | |
/* Add the button to the window. */ | |
gtk_container_add (GTK_CONTAINER (window), button); | |
/* Connect signal handlers to the button. */ | |
g_signal_connect (button, "enter-notify-event", G_CALLBACK (enter), NULL); | |
g_signal_connect (button, "leave-notify-event", G_CALLBACK (leave), NULL); | |
/* Show all widgets. */ | |
gtk_widget_show_all (window); | |
/* Return to the main loop. */ | |
gtk_main (); | |
/* We are done. */ | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFLAGS = -Wall -g `pkg-config --cflags gtk+-2.0` | |
LDFLAGS = `pkg-config --libs gtk+-2.0` | |
enter_and_leave_signals_demo: enter_and_leave_signals_demo.c | |
$(CC) -o enter_and_leave_signals_demo enter_and_leave_signals_demo.c $(CFLAGS) $(LDFLAGS) | |
clean: | |
rm -f *~ | |
rm -f *.o | |
rm -f enter_and_leave_signals_demo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment