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
59
60
61
62
63
64
65
66
67
68
|
/* Build with "gcc `pkg-config --cflags --libs gtk+-3.0` c-gnome-app.c */
#include <gtk/gtk.h>
static GtkWidget *window;
static void
on_hello_world (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
g_print ("%s\n", "Hello world!");
}
static void
on_quit (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
g_application_quit (G_APPLICATION (user_data));
}
static const GActionEntry actions[] =
{
{ "hello-world", on_hello_world },
{ "quit", on_quit }
};
static void
on_activate (GApplication *app,
gpointer user_data)
{
gtk_widget_show_all (window);
}
static void
on_startup (GApplication *app,
gpointer user_data)
{
const gchar * const hello_world_accel[] = { "<Primary>h", NULL };
const gchar * const quit_accel[] = { "<Primary>q", NULL };
g_action_map_add_action_entries (G_ACTION_MAP (app), actions,
G_N_ELEMENTS (actions), app);
window = gtk_application_window_new (GTK_APPLICATION (app));
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"app.hello-world",
hello_world_accel);
gtk_application_set_accels_for_action (GTK_APPLICATION (app),
"app.quit",
quit_accel);
}
int
main (int argc,
char *argv[])
{
GtkApplication *app;
gint status;
app = gtk_application_new ("org.example.CGnome", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
g_signal_connect (app, "startup", G_CALLBACK (on_startup), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
|