comparison mcabber/src/screen.c @ 157:409ff07d9fe2

[/trunk] Changeset 169 by mikael * Improve resize handling.
author mikael
date Sun, 01 May 2005 20:15:50 +0000
parents 8630b7cae87b
children ba51d1737086
comparison
equal deleted inserted replaced
156:439b750d99fa 157:409ff07d9fe2
316 // Refresh the window 316 // Refresh the window
317 scr_UpdateWindow(win_entry); 317 scr_UpdateWindow(win_entry);
318 318
319 // Finished :) 319 // Finished :)
320 update_panels(); 320 update_panels();
321 doupdate(); 321 // doupdate(); (update_roster should be enough?)
322 } else { 322 } else {
323 top_panel(chatPanel); 323 top_panel(chatPanel);
324 currentWindow = win_entry; // == NULL (current window empty) 324 currentWindow = win_entry; // == NULL (current window empty)
325 } 325 }
326 326
436 endwin(); 436 endwin();
437 return; 437 return;
438 } 438 }
439 439
440 // scr_DrawMainWindow() 440 // scr_DrawMainWindow()
441 // Set fullinit to TRUE to also create panels 441 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize.
442 // 442 //
443 // I think it could be improved a _lot_ but I'm really not an ncurses 443 // I think it could be improved a _lot_ but I'm really not an ncurses
444 // expert... :-\ Mikael. 444 // expert... :-\ Mikael.
445 // 445 //
446 void scr_DrawMainWindow(unsigned int fullinit) 446 void scr_DrawMainWindow(unsigned int fullinit)
447 { 447 {
448 int l; 448 int l;
449 449
450 /* Create windows */ 450 if (fullinit) {
451 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); 451 /* Create windows */
452 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); 452 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
453 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); 453 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
454 logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); 454 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
455 inputWnd = newwin(1, maxX, maxY-1, 0); 455 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
456 inputWnd = newwin(1, maxX, maxY-1, 0);
457 } else {
458 /* Resize windows */
459 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH);
460 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH);
461
462 wresize(logWnd_border, LOG_WIN_HEIGHT, maxX);
463 wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2);
464 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
465 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
466
467 wresize(inputWnd, 1, maxX);
468 mvwin(inputWnd, maxY-1, 0);
469 }
456 470
457 /* Draw/init windows */ 471 /* Draw/init windows */
458 472
459 // - Clear roster and draw vertical line 473 // - Clear roster and draw vertical line
460 scr_clear_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WIDTH, 474 scr_clear_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WIDTH,
468 mvwprintw(chatWnd, 0, 0, "This is the status window"); 482 mvwprintw(chatWnd, 0, 0, "This is the status window");
469 483
470 // - Draw/clear the log window 484 // - Draw/clear the log window
471 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); 485 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
472 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); 486 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
487 // Auto-scrolling in log window
473 scrollok(logWnd, TRUE); 488 scrollok(logWnd, TRUE);
474 489
475 // Enable keypad (+ special keys)
476 keypad(inputWnd, TRUE);
477 490
478 if (fullinit) { 491 if (fullinit) {
492 // Enable keypad (+ special keys)
493 keypad(inputWnd, TRUE);
494
479 // Create panels 495 // Create panels
480 rosterPanel = new_panel(rosterWnd); 496 rosterPanel = new_panel(rosterWnd);
481 chatPanel = new_panel(chatWnd); 497 chatPanel = new_panel(chatWnd);
482 logPanel_border = new_panel(logWnd_border); 498 logPanel_border = new_panel(logWnd_border);
483 logPanel = new_panel(logWnd); 499 logPanel = new_panel(logWnd);
484 inputPanel = new_panel(inputWnd); 500 inputPanel = new_panel(inputWnd);
501 } else {
502 // Update panels
503 replace_panel(rosterPanel, rosterWnd);
504 replace_panel(chatPanel, chatWnd);
505 replace_panel(logPanel, logWnd);
506 replace_panel(logPanel_border, logWnd_border);
507 replace_panel(inputPanel, inputWnd);
508 wprintw(logWnd, "This is a test\n");
485 } 509 }
486 510
487 // We'll need to redraw the roster 511 // We'll need to redraw the roster
488 update_roster = TRUE; 512 update_roster = TRUE;
489 return; 513 return;
490 } 514 }
491 515
492 // scr_Resize() 516 // scr_Resize()
493 // Function called when the window is resized. 517 // Function called when the window is resized.
494 // - Recreate windows 518 // - Resize windows
495 // - Update panels
496 // - Rewrap lines in each buddy buffer 519 // - Rewrap lines in each buddy buffer
497 void scr_Resize() 520 void scr_Resize()
498 { 521 {
499 WINDOW *w_roster, *w_chat, *w_log, *w_log_bord, *w_input;
500
501 struct list_head *pos, *n; 522 struct list_head *pos, *n;
502 window_entry_t *search_entry; 523 window_entry_t *search_entry;
503 int x, y, lines, cols; 524 int x, y, lines, cols;
504 525
505 // First, update the global variables 526 // First, update the global variables
506 getmaxyx(stdscr, maxY, maxX); 527 getmaxyx(stdscr, maxY, maxX);
507 // Make sure the cursor stays inside the window 528 // Make sure the cursor stays inside the window
508 check_offset(0); 529 check_offset(0);
509 530
510 // Backup pointers 531 // Resize windows and update panels
511 w_roster = rosterWnd;
512 w_chat = chatWnd;
513 w_log = logWnd;
514 w_log_bord = logWnd_border;
515 w_input = inputWnd;
516
517 // Recreate windows
518 scr_DrawMainWindow(FALSE); 532 scr_DrawMainWindow(FALSE);
519
520 // Replace windows for panels
521 replace_panel(rosterPanel, rosterWnd);
522 replace_panel(chatPanel, chatWnd);
523 replace_panel(logPanel, logWnd);
524 replace_panel(logPanel_border, logWnd_border);
525 replace_panel(inputPanel, inputWnd);
526
527 // Destroy old windows
528 delwin(w_roster);
529 delwin(w_chat);
530 delwin(w_log);
531 delwin(w_log_bord);
532 delwin(w_input);
533 533
534 // Resize all buddy windows 534 // Resize all buddy windows
535 x = ROSTER_WIDTH; 535 x = ROSTER_WIDTH;
536 y = 0; 536 y = 0;
537 lines = CHAT_WIN_HEIGHT; 537 lines = CHAT_WIN_HEIGHT;
538 cols = maxX - ROSTER_WIDTH; 538 cols = maxX - ROSTER_WIDTH;
539 539
540 list_for_each_safe(pos, n, &window_list) { 540 list_for_each_safe(pos, n, &window_list) {
541 search_entry = window_entry(pos); 541 search_entry = window_entry(pos);
542 if (search_entry->win) { 542 if (search_entry->win) {
543 WINDOW *w_buddy = search_entry->win; 543 // Resize buddy window (no need to move it)
544 // Create new window 544 wresize(search_entry->win, lines, cols);
545 search_entry->win = newwin(lines, cols, y, x);
546 scr_clear_box(search_entry->win, 0, 0, lines, cols, COLOR_GENERAL); 545 scr_clear_box(search_entry->win, 0, 0, lines, cols, COLOR_GENERAL);
547 // If a panel exists, replace the old window with the new 546 // If a panel exists, replace the old window with the new
548 if (search_entry->panel) { 547 if (search_entry->panel) {
549 replace_panel(search_entry->panel, search_entry->win); 548 replace_panel(search_entry->panel, search_entry->win);
550 } 549 }
551 // Redo line wrapping 550 // Redo line wrapping
552 hbuf_rebuild(&search_entry->hbuf, 551 hbuf_rebuild(&search_entry->hbuf,
553 maxX - scr_WindowWidth(rosterWnd) - 14); 552 maxX - scr_WindowWidth(rosterWnd) - 14);
554 // Delete old buddy window
555 delwin(w_buddy);
556 } 553 }
557 } 554 }
558 555
559 // Refresh current buddy window 556 // Refresh current buddy window
560 if (chatmode) { 557 if (chatmode)
561 usleep(100);
562 scr_ShowBuddyWindow(); 558 scr_ShowBuddyWindow();
563 }
564 // NCurses is very bad wrt memory (can lead to segfaults) so let's slow
565 // things down...
566 usleep(200);
567 } 559 }
568 560
569 // scr_DrawRoster() 561 // scr_DrawRoster()
570 // Actually, display the buddylist on the screen. 562 // Actually, display the buddylist on the screen.
571 void scr_DrawRoster(void) 563 void scr_DrawRoster(void)
940 time_t timestamp; 932 time_t timestamp;
941 char *buffer; 933 char *buffer;
942 va_list ap; 934 va_list ap;
943 935
944 do { 936 do {
945 buffer = (char *) calloc(1, 1024); 937 buffer = (char *) calloc(1, 1024);
946 } while (!buffer); 938 } while (!buffer);
947 939
948 timestamp = time(NULL); 940 timestamp = time(NULL);
949 strftime(buffer, 64, "[%H:%M:%S] ", localtime(&timestamp)); 941 strftime(buffer, 64, "[%H:%M:%S] ", localtime(&timestamp));
950 wprintw(logWnd, "\n%s", buffer); 942 wprintw(logWnd, "\n%s", buffer);
1215 chatmode = FALSE; 1207 chatmode = FALSE;
1216 if (current_buddy) 1208 if (current_buddy)
1217 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); 1209 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
1218 top_panel(chatPanel); 1210 top_panel(chatPanel);
1219 top_panel(inputPanel); 1211 top_panel(inputPanel);
1212 update_panels();
1220 break; 1213 break;
1221 case 12: // Ctrl-l 1214 case 12: // Ctrl-l
1222 case KEY_RESIZE: 1215 case KEY_RESIZE:
1223 scr_Resize(); 1216 scr_Resize();
1224 break; 1217 break;
1225 default: 1218 default:
1226 scr_LogPrint("Unkown key=%d", key); 1219 scr_LogPrint("Unkown key=%d", key);
1227 } 1220 }
1228 } 1221 }
1229 if (completion_started && key != 9) 1222 if (completion_started && key != 9 && key != KEY_RESIZE)
1230 scr_end_current_completion(); 1223 scr_end_current_completion();
1231 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); 1224 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset);
1232 wclrtoeol(inputWnd); 1225 wclrtoeol(inputWnd);
1233 if (*ptr_inputline) { 1226 if (*ptr_inputline) {
1234 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); 1227 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset);
1235 } 1228 }
1236 update_panels(); 1229 if (!update_roster) {
1237 doupdate(); 1230 //update_panels();
1231 doupdate();
1232 }
1238 return 0; 1233 return 0;
1239 } 1234 }