comparison console/libgnt/gntmain.c @ 13850:0e1e59770cb0

[gaim-migrate @ 16308] This is my first commit here. So don't yell at me if things get borked. Also, I haven't looked at the auto-thingies yet. So don't puke at the Makefiles. Files in console/libgnt/ are for the 'Gaim/GObjectified Ncurses Toolkit' library. Files in console/ uses libgaim and libgnt. Currently, only the buddylist-ui is 'functional', ie. the buddy-list updates when someone logs on or logs off. It still needs a lot of work. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 22 Jun 2006 08:33:54 +0000
parents
children c1e3f7c75c3f
comparison
equal deleted inserted replaced
13849:8d1c55309e3c 13850:0e1e59770cb0
1 #include "gnt.h"
2 #include "gntkeys.h"
3 #include "gntcolors.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <locale.h>
7
8 static GList *focus_list;
9 static int max_x;
10 static int max_y;
11
12 void gnt_screen_take_focus(GntWidget *widget)
13 {
14 focus_list = g_list_prepend(focus_list, widget);
15 }
16
17 void gnt_screen_remove_widget(GntWidget *widget)
18 {
19 focus_list = g_list_remove(focus_list, widget);
20 if (focus_list)
21 gnt_widget_draw(focus_list->data);
22 }
23
24 static gboolean
25 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
26 {
27 char buffer[256];
28
29 int rd = read(0, buffer, sizeof(buffer) - 1);
30 if (rd < 0)
31 {
32 endwin();
33 printf("ERROR!\n");
34 exit(1);
35 }
36 else if (rd == 0)
37 {
38 endwin();
39 printf("EOF\n");
40 exit(1);
41 }
42
43 buffer[rd] = 0;
44
45 if (focus_list)
46 {
47 gboolean ret = FALSE;
48 /*g_signal_emit_by_name(focus_list->data, "key_pressed", buffer, &ret);*/
49 ret = gnt_widget_key_pressed(focus_list->data, buffer);
50 }
51
52 if (buffer[0] == 27)
53 {
54 /* Some special key has been pressed */
55 if (strcmp(buffer+1, GNT_KEY_POPUP) == 0)
56 {
57 /*printf("popup\n");*/
58 }
59 else
60 {
61 /*printf("Unknown: %s\n", buffer+1);*/
62 }
63 }
64 else
65 {
66 if (buffer[0] == 'q')
67 {
68 endwin();
69 exit(1);
70 }
71 /*printf("%s\n", buffer);*/
72 }
73 refresh();
74
75 return TRUE;
76 }
77
78 void gnt_init()
79 {
80 GIOChannel *channel = g_io_channel_unix_new(0);
81
82 g_io_channel_set_encoding(channel, NULL, NULL);
83 g_io_channel_set_buffered(channel, FALSE);
84 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL );
85
86 int result = g_io_add_watch(channel,
87 (G_IO_IN | G_IO_HUP | G_IO_ERR),
88 io_invoke, NULL);
89
90 setlocale(LC_ALL, "");
91 initscr();
92 start_color();
93 /*use_default_colors();*/
94 gnt_init_colors();
95
96 max_x = getmaxx(stdscr);
97 max_y = getmaxy(stdscr);
98
99 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
100 noecho();
101 refresh();
102 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
103 g_type_init();
104 }
105
106 void gnt_main()
107 {
108 GMainLoop *loop = g_main_new(FALSE);
109 g_main_run(loop);
110 }
111