]>
Commit | Line | Data |
---|---|---|
1 | #include <gtk/gtk.h> | |
2 | ||
3 | static void print_hello(GtkWidget *widget __attribute__((unused)), | |
4 | gpointer data __attribute__((unused))) { | |
5 | g_print("Hello World\n"); | |
6 | } | |
7 | ||
8 | static void activate(GtkApplication *app, | |
9 | gpointer user_data __attribute__((unused))) { | |
10 | ||
11 | GtkWidget *window = gtk_application_window_new(app); | |
12 | gtk_window_set_title(GTK_WINDOW(window), "Window"); | |
13 | gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); | |
14 | ||
15 | GtkWidget *button_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); | |
16 | gtk_container_add(GTK_CONTAINER(window), button_box); | |
17 | ||
18 | GtkWidget *button = gtk_button_new_with_label("Hello World"); | |
19 | g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL); | |
20 | g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), | |
21 | window); | |
22 | gtk_container_add(GTK_CONTAINER(button_box), button); | |
23 | ||
24 | gtk_widget_show_all(window); | |
25 | } | |
26 | ||
27 | int main(int argc, char **argv) { | |
28 | ||
29 | GtkApplication *app = | |
30 | gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); | |
31 | g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); | |
32 | int status = g_application_run(G_APPLICATION(app), argc, argv); | |
33 | g_object_unref(app); | |
34 | ||
35 | return status; | |
36 | } |