-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
58 lines (45 loc) · 1.53 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <gtk/gtk.h>
#include <glib/gstdio.h>
static void
print_hello(GtkWidget *widget,
gpointer data)
{
g_print("Hello World\n");
}
static void
quit_cb(GtkWindow *window)
{
gtk_window_close(window);
}
static void
activate(GtkApplication *app,
gpointer user_data)
{
/* Construct a GtkBuilder instance and load our UI description */
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "builder.ui", NULL);
/* Connect signal handlers to the constructed widgets. */
GObject *window = gtk_builder_get_object(builder, "window");
gtk_window_set_application(GTK_WINDOW(window), app);
GObject *button = gtk_builder_get_object(builder, "button1");
g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
button = gtk_builder_get_object(builder, "button2");
g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
button = gtk_builder_get_object(builder, "quit");
g_signal_connect_swapped(button, "clicked", G_CALLBACK(quit_cb), window);
gtk_widget_set_visible(GTK_WIDGET(window), TRUE);
/* We do not need the builder any more */
g_object_unref(builder);
}
int main(int argc,
char *argv[])
{
#ifdef GTK_SRCDIR
g_chdir(GTK_SRCDIR);
#endif
GtkApplication *app = gtk_application_new("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}