comparison console/libgnt/test/wm.c @ 13960:a06f7495af6f

[gaim-migrate @ 16513] It is possible to have multiple gnt-applications sharing the same screen. To try this, 'make WM' in console/libgnt/test. It will have a small 'Command' entry. You can give a command like './focus.so' (or one of the other examples). The applications can also be executed standalone. This required some tinkering to the Makefile. I am not sure whether there is an easier way of doing it. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 17 Jul 2006 22:27:26 +0000
parents
children 0a0d2a1fd2bc
comparison
equal deleted inserted replaced
13959:2ae35c0cf616 13960:a06f7495af6f
1 #include <gmodule.h>
2
3 #include <gnt.h>
4 #include <gntbox.h>
5 #include <gntentry.h>
6 #include <gntlabel.h>
7
8 static gboolean
9 key_pressed(GntEntry *entry, const char *text, gpointer null)
10 {
11 if (*text != '\r')
12 return FALSE;
13
14 {
15 const char *cmd;
16 void *handle;
17 void (*func)();
18
19 cmd = gnt_entry_get_text(entry);
20 handle = g_module_open(cmd, G_MODULE_BIND_LOCAL);
21 if (handle && g_module_symbol(handle, "main", (gpointer)&func))
22 {
23 gnt_entry_clear(entry);
24 func();
25 }
26 else
27 {
28 GntWidget *widget = gnt_vbox_new(FALSE);
29 gnt_box_set_toplevel(GNT_BOX(widget), TRUE);
30 gnt_box_set_title(GNT_BOX(widget), "Error");
31 gnt_box_add_widget(GNT_BOX(widget), gnt_label_new("Could not execute."));
32
33 gnt_widget_show(widget);
34 }
35 }
36
37 return TRUE;
38 }
39
40 int main()
41 {
42 GntWidget *window, *entry;
43
44 freopen(".error", "w", stderr);
45
46 gnt_init();
47
48 window = gnt_hbox_new(FALSE);
49
50 gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Command"));
51
52 entry = gnt_entry_new(NULL);
53 g_signal_connect(G_OBJECT(entry), "key_pressed", G_CALLBACK(key_pressed), NULL);
54 gnt_box_add_widget(GNT_BOX(window), entry);
55
56 gnt_widget_set_position(window, 0, getmaxy(stdscr) - 2);
57 gnt_widget_show(window);
58
59 gnt_main();
60
61 gnt_quit();
62
63 return 0;
64 }
65