15817
|
1 #include <string.h>
|
|
2 #include <sys/types.h>
|
|
3
|
|
4 #include "gnt.h"
|
|
5 #include "gntbox.h"
|
|
6 #include "gntmenu.h"
|
|
7 #include "gntstyle.h"
|
|
8 #include "gntwm.h"
|
|
9 #include "gntwindow.h"
|
|
10 #include "gntlabel.h"
|
|
11
|
|
12 #include "blist.h"
|
|
13
|
|
14 #define TYPE_S (s_get_gtype())
|
|
15
|
|
16 typedef struct _S
|
|
17 {
|
|
18 GntWM inherit;
|
|
19 } S;
|
|
20
|
|
21 typedef struct _SClass
|
|
22 {
|
|
23 GntWMClass inherit;
|
|
24 } SClass;
|
|
25
|
|
26 GType s_get_gtype(void);
|
|
27 void gntwm_init(GntWM **wm);
|
|
28
|
|
29 static void (*org_new_window)(GntWM *wm, GntWidget *win);
|
|
30
|
|
31 static void
|
|
32 envelope_buddylist(GntWidget *win)
|
|
33 {
|
|
34 int w, h;
|
|
35 gnt_widget_get_size(win, &w, &h);
|
|
36 wresize(win->window, h, w + 1);
|
|
37 mvwvline(win->window, 0, w, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL), h);
|
|
38 touchwin(win->window);
|
|
39 }
|
|
40
|
|
41 static void
|
|
42 envelope_normal_window(GntWidget *win)
|
|
43 {
|
|
44 int w, h;
|
|
45
|
|
46 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT))
|
|
47 return;
|
|
48
|
|
49 gnt_widget_get_size(win, &w, &h);
|
|
50 wbkgdset(win->window, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL));
|
|
51 mvwprintw(win->window, 0, w - 4, "[X]");
|
|
52 }
|
|
53
|
|
54 static void
|
|
55 s_decorate_window(GntWM *wm, GntWidget *win)
|
|
56 {
|
|
57 const char *name;
|
|
58
|
|
59 name = gnt_widget_get_name(win);
|
|
60 if (name && strcmp(name, "buddylist") == 0) {
|
|
61 envelope_buddylist(win);
|
|
62 } else {
|
|
63 envelope_normal_window(win);
|
|
64 }
|
|
65 }
|
|
66
|
|
67 static void
|
|
68 s_window_update(GntWM *wm, GntNode *node)
|
|
69 {
|
|
70 s_decorate_window(wm, node->me);
|
|
71 }
|
|
72
|
|
73 static void
|
|
74 s_new_window(GntWM *wm, GntWidget *win)
|
|
75 {
|
|
76 int x, y, w, h;
|
|
77 int maxx, maxy;
|
|
78 const char *name;
|
|
79 gboolean blist = FALSE;
|
|
80
|
|
81 if (!GNT_IS_MENU(win)) {
|
|
82 getmaxyx(stdscr, maxy, maxx);
|
|
83
|
|
84 gnt_widget_get_position(win, &x, &y);
|
|
85 gnt_widget_get_size(win, &w, &h);
|
|
86
|
|
87 name = gnt_widget_get_name(win);
|
|
88
|
|
89 if (name && strcmp(name, "buddylist") == 0) {
|
|
90 /* The buddylist doesn't have no border nor nothing! */
|
|
91 x = 0;
|
|
92 y = 0;
|
|
93 h = maxy - 1;
|
|
94 blist = TRUE;
|
|
95
|
|
96 gnt_box_set_toplevel(GNT_BOX(win), FALSE);
|
|
97 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_CAN_TAKE_FOCUS);
|
|
98
|
|
99 gnt_widget_set_position(win, x, y);
|
|
100 mvwin(win->window, y, x);
|
|
101
|
|
102 gnt_widget_set_size(win, -1, h + 2); /* XXX: Why is the +2 needed here? -- sadrul */
|
|
103 } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) {
|
|
104 const char *title = GNT_BOX(win)->title;
|
|
105 if (title == NULL || !g_hash_table_lookup(wm->positions, title)) {
|
|
106 /* In the middle of the screen */
|
|
107 x = (maxx - w) / 2;
|
|
108 y = (maxy - h) / 2;
|
|
109
|
|
110 gnt_widget_set_position(win, x, y);
|
|
111 mvwin(win->window, y, x);
|
|
112 }
|
|
113 }
|
|
114 }
|
|
115 org_new_window(wm, win);
|
|
116
|
|
117 if (blist)
|
|
118 gnt_wm_raise_window(wm, win);
|
|
119 }
|
|
120
|
|
121 static GntWidget *
|
|
122 find_widget(GntWM *wm, const char *wname)
|
|
123 {
|
|
124 const GList *iter = wm->list;
|
|
125 for (; iter; iter = iter->next) {
|
|
126 GntWidget *widget = iter->data;
|
|
127 const char *name = gnt_widget_get_name(widget);
|
|
128 if (name && strcmp(name, wname) == 0) {
|
|
129 return widget;
|
|
130 }
|
|
131 }
|
|
132 return NULL;
|
|
133 }
|
|
134
|
|
135 static gboolean
|
|
136 s_mouse_clicked(GntWM *wm, GntMouseEvent event, int cx, int cy, GntWidget *widget)
|
|
137 {
|
|
138 int x, y, w, h;
|
|
139
|
|
140 if (!widget)
|
|
141 return FALSE;
|
|
142 /* This might be a place to bring up a context menu */
|
|
143
|
|
144 if (event != GNT_LEFT_MOUSE_DOWN ||
|
|
145 GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_NO_BORDER))
|
|
146 return FALSE;
|
|
147
|
|
148 gnt_widget_get_position(widget, &x, &y);
|
|
149 gnt_widget_get_size(widget, &w, &h);
|
|
150
|
|
151 if (cy == y && cx == x + w - 3) {
|
|
152 gnt_widget_destroy(widget);
|
|
153 return TRUE;
|
|
154 }
|
|
155
|
|
156 return FALSE;
|
|
157 }
|
|
158
|
|
159 static gboolean
|
|
160 toggle_buddylist(GntBindable *bindable, GList *null)
|
|
161 {
|
|
162 GntWM *wm = GNT_WM(bindable);
|
|
163 GntWidget *blist = find_widget(wm, "buddylist");
|
|
164 if (blist)
|
|
165 gnt_widget_destroy(blist);
|
|
166 else
|
15822
|
167 purple_blist_show();
|
15817
|
168 return TRUE;
|
|
169 }
|
|
170
|
|
171 static void
|
|
172 s_class_init(SClass *klass)
|
|
173 {
|
|
174 GntWMClass *pclass = GNT_WM_CLASS(klass);
|
|
175
|
|
176 org_new_window = pclass->new_window;
|
|
177
|
|
178 pclass->new_window = s_new_window;
|
|
179 pclass->decorate_window = s_decorate_window;
|
|
180 pclass->window_update = s_window_update;
|
|
181 pclass->mouse_clicked = s_mouse_clicked;
|
|
182
|
|
183 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-buddylist",
|
|
184 toggle_buddylist, "\033" "b", NULL);
|
|
185 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
|
|
186 GNTDEBUG;
|
|
187 }
|
|
188
|
|
189 void gntwm_init(GntWM **wm)
|
|
190 {
|
|
191 *wm = g_object_new(TYPE_S, NULL);
|
|
192 }
|
|
193
|
|
194 GType s_get_gtype(void)
|
|
195 {
|
|
196 static GType type = 0;
|
|
197
|
|
198 if(type == 0) {
|
|
199 static const GTypeInfo info = {
|
|
200 sizeof(SClass),
|
|
201 NULL, /* base_init */
|
|
202 NULL, /* base_finalize */
|
|
203 (GClassInitFunc)s_class_init,
|
|
204 NULL,
|
|
205 NULL, /* class_data */
|
|
206 sizeof(S),
|
|
207 0, /* n_preallocs */
|
|
208 NULL, /* instance_init */
|
|
209 NULL
|
|
210 };
|
|
211
|
|
212 type = g_type_register_static(GNT_TYPE_WM,
|
|
213 "GntS",
|
|
214 &info, 0);
|
|
215 }
|
|
216
|
|
217 return type;
|
|
218 }
|
|
219
|