diff options
Diffstat (limited to 'testing/toxic/main.c')
-rw-r--r-- | testing/toxic/main.c | 126 |
1 files changed, 88 insertions, 38 deletions
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 45760b1c..42657e88 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -17,13 +17,12 @@ extern ToxWindow new_prompt(); | |||
17 | extern ToxWindow new_friendlist(); | 17 | extern ToxWindow new_friendlist(); |
18 | 18 | ||
19 | extern int friendlist_onFriendAdded(int num); | 19 | extern int friendlist_onFriendAdded(int num); |
20 | 20 | extern void disable_chatwin(int f_num); | |
21 | extern int add_req(uint8_t* public_key); // XXX | 21 | extern int add_req(uint8_t* public_key); // XXX |
22 | 22 | ||
23 | #define TOXWINDOWS_MAX_NUM 32 | 23 | char WINDOW_STATUS[MAX_WINDOW_SLOTS]; // Holds status of chat windows |
24 | 24 | static ToxWindow windows[MAX_WINDOW_SLOTS]; | |
25 | static ToxWindow windows[TOXWINDOWS_MAX_NUM]; | 25 | int w_num; |
26 | static int w_num; | ||
27 | static int w_active; | 26 | static int w_active; |
28 | static ToxWindow* prompt; | 27 | static ToxWindow* prompt; |
29 | 28 | ||
@@ -115,6 +114,16 @@ static void init_tox() { | |||
115 | m_callback_userstatus(on_statuschange); | 114 | m_callback_userstatus(on_statuschange); |
116 | } | 115 | } |
117 | 116 | ||
117 | void init_window_status() { | ||
118 | int i; | ||
119 | for (i = 0; i < N_DEFAULT_WINS; i++) | ||
120 | WINDOW_STATUS[i] = i; | ||
121 | |||
122 | int j; | ||
123 | for (j = N_DEFAULT_WINS; j < MAX_WINDOW_SLOTS; j++) | ||
124 | WINDOW_STATUS[j] = -1; | ||
125 | } | ||
126 | |||
118 | int add_window(ToxWindow w) { | 127 | int add_window(ToxWindow w) { |
119 | if(w_num == TOXWINDOWS_MAX_NUM) | 128 | if(w_num == TOXWINDOWS_MAX_NUM) |
120 | return -1; | 129 | return -1; |
@@ -133,6 +142,21 @@ int add_window(ToxWindow w) { | |||
133 | return w_num - 1; | 142 | return w_num - 1; |
134 | } | 143 | } |
135 | 144 | ||
145 | /* Deletes window w and cleans up */ | ||
146 | void del_window(ToxWindow *w, int f_num) { | ||
147 | delwin(w->window); | ||
148 | int i; | ||
149 | for (i = N_DEFAULT_WINS; i < MAX_WINDOW_SLOTS; i++) { | ||
150 | if (WINDOW_STATUS[i] == f_num) { | ||
151 | WINDOW_STATUS[i] = -1; | ||
152 | disable_chatwin(f_num); | ||
153 | break; | ||
154 | } | ||
155 | } | ||
156 | clear(); | ||
157 | refresh(); | ||
158 | } | ||
159 | |||
136 | int focus_window(int num) { | 160 | int focus_window(int num) { |
137 | if(num >= w_num || num < 0) | 161 | if(num >= w_num || num < 0) |
138 | return -1; | 162 | return -1; |
@@ -143,7 +167,6 @@ int focus_window(int num) { | |||
143 | 167 | ||
144 | static void init_windows() { | 168 | static void init_windows() { |
145 | w_num = 0; | 169 | w_num = 0; |
146 | w_active = 0; | ||
147 | 170 | ||
148 | if(add_window(new_prompt()) == -1 || add_window(new_friendlist()) == -1) { | 171 | if(add_window(new_prompt()) == -1 || add_window(new_friendlist()) == -1) { |
149 | fprintf(stderr, "add_window() failed.\n"); | 172 | fprintf(stderr, "add_window() failed.\n"); |
@@ -151,7 +174,6 @@ static void init_windows() { | |||
151 | endwin(); | 174 | endwin(); |
152 | exit(1); | 175 | exit(1); |
153 | } | 176 | } |
154 | |||
155 | prompt = &windows[0]; | 177 | prompt = &windows[0]; |
156 | } | 178 | } |
157 | 179 | ||
@@ -238,7 +260,6 @@ static void load_data(char *path) { | |||
238 | 260 | ||
239 | static void draw_bar() { | 261 | static void draw_bar() { |
240 | static int odd = 0; | 262 | static int odd = 0; |
241 | size_t i; | ||
242 | 263 | ||
243 | attron(COLOR_PAIR(4)); | 264 | attron(COLOR_PAIR(4)); |
244 | mvhline(LINES - 2, 0, '_', COLS); | 265 | mvhline(LINES - 2, 0, '_', COLS); |
@@ -250,28 +271,26 @@ static void draw_bar() { | |||
250 | printw(" TOXIC 1.0 |"); | 271 | printw(" TOXIC 1.0 |"); |
251 | attroff(COLOR_PAIR(4) | A_BOLD); | 272 | attroff(COLOR_PAIR(4) | A_BOLD); |
252 | 273 | ||
253 | for(i=0; i<w_num; i++) { | 274 | int i; |
254 | if(i == w_active) { | 275 | for (i = 0; i < (MAX_WINDOW_SLOTS-1); i++) { |
255 | attron(A_BOLD); | 276 | if (WINDOW_STATUS[i] != -1) { |
256 | } | 277 | if (i == w_active) |
257 | 278 | attron(A_BOLD); | |
258 | odd = (odd+1) % 10; | 279 | |
259 | 280 | odd = (odd+1) % 10; | |
260 | if(windows[i].blink && (odd < 5)) { | 281 | if(windows[i].blink && (odd < 5)) { |
261 | attron(COLOR_PAIR(3)); | 282 | attron(COLOR_PAIR(3)); |
262 | } | 283 | } |
263 | 284 | ||
264 | printw(" %s", windows[i].title); | 285 | printw(" %s", windows[i].title); |
265 | 286 | if(windows[i].blink && (odd < 5)) { | |
266 | if(windows[i].blink && (odd < 5)) { | 287 | attron(COLOR_PAIR(3)); |
267 | attron(COLOR_PAIR(3)); | 288 | } |
268 | } | 289 | if(i == w_active) { |
269 | 290 | attroff(A_BOLD); | |
270 | if(i == w_active) { | 291 | } |
271 | attroff(A_BOLD); | ||
272 | } | 292 | } |
273 | } | 293 | } |
274 | |||
275 | refresh(); | 294 | refresh(); |
276 | } | 295 | } |
277 | 296 | ||
@@ -280,6 +299,42 @@ void prepare_window(WINDOW* w) { | |||
280 | wresize(w, LINES-2, COLS); | 299 | wresize(w, LINES-2, COLS); |
281 | } | 300 | } |
282 | 301 | ||
302 | /* Shows next window when tab or back-tab is pressed */ | ||
303 | void set_active_window(int ch) { | ||
304 | int f_inf = 0; | ||
305 | int max = MAX_WINDOW_SLOTS-1; | ||
306 | if (ch == '\t') { | ||
307 | int i = (w_active + 1) % max; | ||
308 | while (true) { | ||
309 | if (WINDOW_STATUS[i] != -1) { | ||
310 | w_active = i; | ||
311 | return; | ||
312 | } | ||
313 | i = (i + 1) % max; | ||
314 | if (f_inf++ > max) { // infinite loop check | ||
315 | endwin(); | ||
316 | clear(); | ||
317 | exit(2); | ||
318 | } | ||
319 | } | ||
320 | }else { | ||
321 | int i = w_active - 1; | ||
322 | if (i < 0) i = max; | ||
323 | while (true) { | ||
324 | if (WINDOW_STATUS[i] != -1) { | ||
325 | w_active = i; | ||
326 | return; | ||
327 | } | ||
328 | if (--i < 0) i = max; | ||
329 | if (f_inf++ > max) { | ||
330 | endwin(); | ||
331 | clear(); | ||
332 | exit(2); | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | } | ||
337 | |||
283 | int main(int argc, char* argv[]) { | 338 | int main(int argc, char* argv[]) { |
284 | int ch; | 339 | int ch; |
285 | int i = 0; | 340 | int i = 0; |
@@ -312,8 +367,7 @@ int main(int argc, char* argv[]) { | |||
312 | "defaulting to 'data' for a keyfile...\n"); | 367 | "defaulting to 'data' for a keyfile...\n"); |
313 | attroff(COLOR_PAIR(3) | A_BOLD); | 368 | attroff(COLOR_PAIR(3) | A_BOLD); |
314 | } | 369 | } |
315 | 370 | ||
316 | |||
317 | while(true) { | 371 | while(true) { |
318 | // Update tox. | 372 | // Update tox. |
319 | do_tox(); | 373 | do_tox(); |
@@ -327,18 +381,14 @@ int main(int argc, char* argv[]) { | |||
327 | 381 | ||
328 | // Handle input. | 382 | // Handle input. |
329 | ch = getch(); | 383 | ch = getch(); |
330 | if(ch == '\t') { | 384 | if(ch == '\t' || ch == KEY_BTAB) |
331 | w_active = (w_active + 1) % w_num; | 385 | set_active_window(ch); |
332 | } | 386 | else if(ch != ERR) { |
333 | else if(ch == KEY_BTAB) { | 387 | a->onKey(a, ch); |
334 | w_active = (w_active + w_num - 1) % w_num; | ||
335 | } | 388 | } |
336 | else if(ch != ERR) { | 389 | else if(ch != ERR) { |
337 | a->onKey(a, ch); | 390 | a->onKey(a, ch); |
338 | } | 391 | } |
339 | |||
340 | } | 392 | } |
341 | |||
342 | return 0; | 393 | return 0; |
343 | } | 394 | } |
344 | |||