comparison mcabber/src/screen.c @ 1133:9dd28a56128f

Do not create one panel per contact Use a single panel for the chat mode, this is much more memory-efficient, and faster.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 03 Feb 2007 18:06:34 +0100
parents 73e6ca0a03a9
children 5d7c05932b13
comparison
equal deleted inserted replaced
1132:1650056b96fc 1133:9dd28a56128f
66 struct dimensions { 66 struct dimensions {
67 int l; 67 int l;
68 int c; 68 int c;
69 }; 69 };
70 70
71 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd; 71 static WINDOW *rosterWnd, *chatWnd, *activechatWnd, *inputWnd, *logWnd;
72 static WINDOW *mainstatusWnd, *chatstatusWnd; 72 static WINDOW *mainstatusWnd, *chatstatusWnd;
73 static PANEL *rosterPanel, *chatPanel, *inputPanel; 73 static PANEL *rosterPanel, *chatPanel, *activechatPanel, *inputPanel;
74 static PANEL *mainstatusPanel, *chatstatusPanel; 74 static PANEL *mainstatusPanel, *chatstatusPanel;
75 static PANEL *logPanel; 75 static PANEL *logPanel;
76 static int maxY, maxX; 76 static int maxY, maxX;
77 static int prev_chatwidth; 77 static int prev_chatwidth;
78 static winbuf *statusWindow; 78 static winbuf *statusWindow;
410 g_free(buffer); 410 g_free(buffer);
411 } 411 }
412 g_free(btext); 412 g_free(btext);
413 } 413 }
414 414
415 // scr_CreateBuddyPanel(title, dontshow) 415 // scr_new_buddy(title, dontshow)
416 // Note: title (aka winId) can be NULL for special buffers 416 // Note: title (aka winId) can be NULL for special buffers
417 static winbuf *scr_CreateBuddyPanel(const char *title, int dont_show) 417 //static winbuf *scr_CreateBuddyPanel(const char *title, int dont_show)
418 { 418 static winbuf *scr_new_buddy(const char *title, int dont_show)
419 int x; 419 {
420 int y;
421 int lines;
422 int cols;
423 winbuf *tmp; 420 winbuf *tmp;
424 421
425 tmp = g_new0(winbuf, 1); 422 tmp = g_new0(winbuf, 1);
426 423
427 // Dimensions 424 tmp->win = activechatWnd;
428 if (roster_win_on_right) 425 tmp->panel = activechatPanel;
429 x = 0;
430 else
431 x = Roster_Width;
432 if (log_win_on_top)
433 y = Log_Win_Height-1;
434 else
435 y = 0;
436
437 lines = CHAT_WIN_HEIGHT;
438 cols = maxX - Roster_Width;
439 if (cols < 1)
440 cols = 1;
441
442 tmp->win = newwin(lines, cols, y, x);
443 while (!tmp->win) {
444 safe_usleep(250);
445 tmp->win = newwin(lines, cols, y, x);
446 }
447 wbkgd(tmp->win, get_color(COLOR_GENERAL));
448 tmp->panel = new_panel(tmp->win);
449 426
450 if (!dont_show) { 427 if (!dont_show) {
451 currentWindow = tmp; 428 currentWindow = tmp;
452 } else { 429 } else {
453 if (currentWindow) 430 if (currentWindow)
602 win_entry = scr_SearchWindow(winId, special); 579 win_entry = scr_SearchWindow(winId, special);
603 580
604 if (!win_entry) { 581 if (!win_entry) {
605 if (special) { 582 if (special) {
606 if (!statusWindow) { 583 if (!statusWindow) {
607 statusWindow = scr_CreateBuddyPanel(NULL, FALSE); 584 statusWindow = scr_new_buddy(NULL, FALSE);
608 statusWindow->hbuf = statushbuf; 585 statusWindow->hbuf = statushbuf;
609 } 586 }
610 win_entry = statusWindow; 587 win_entry = statusWindow;
611 } else { 588 } else {
612 win_entry = scr_CreateBuddyPanel(winId, FALSE); 589 win_entry = scr_new_buddy(winId, FALSE);
613 } 590 }
614 } 591 }
615 592
616 top_panel(win_entry->panel); 593 top_panel(win_entry->panel);
617 currentWindow = win_entry; 594 currentWindow = win_entry;
698 675
699 // If the window entry doesn't exist yet, let's create it. 676 // If the window entry doesn't exist yet, let's create it.
700 if (!win_entry) { 677 if (!win_entry) {
701 if (special) { 678 if (special) {
702 if (!statusWindow) { 679 if (!statusWindow) {
703 statusWindow = scr_CreateBuddyPanel(NULL, dont_show); 680 statusWindow = scr_new_buddy(NULL, dont_show);
704 statusWindow->hbuf = statushbuf; 681 statusWindow->hbuf = statushbuf;
705 } 682 }
706 win_entry = statusWindow; 683 win_entry = statusWindow;
707 } else { 684 } else {
708 win_entry = scr_CreateBuddyPanel(winId, dont_show); 685 win_entry = scr_new_buddy(winId, dont_show);
709 } 686 }
710 } 687 }
711 688
712 // The message must be displayed -> update top pointer 689 // The message must be displayed -> update top pointer
713 if (win_entry->cleared) 690 if (win_entry->cleared)
841 winbufhash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); 818 winbufhash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
842 /* Create windows */ 819 /* Create windows */
843 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, chat_y_pos, roster_x_pos); 820 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, chat_y_pos, roster_x_pos);
844 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos, 821 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos,
845 chat_x_pos); 822 chat_x_pos);
823 activechatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos,
824 chat_x_pos);
846 logWnd = newwin(Log_Win_Height-2, maxX, log_y_pos, 0); 825 logWnd = newwin(Log_Win_Height-2, maxX, log_y_pos, 0);
847 chatstatusWnd = newwin(1, maxX, chatstatus_y_pos, 0); 826 chatstatusWnd = newwin(1, maxX, chatstatus_y_pos, 0);
848 mainstatusWnd = newwin(1, maxX, maxY-2, 0); 827 mainstatusWnd = newwin(1, maxX, maxY-2, 0);
849 inputWnd = newwin(1, maxX, maxY-1, 0); 828 inputWnd = newwin(1, maxX, maxY-1, 0);
850 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { 829 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) {
852 fprintf(stderr, "Cannot create windows!\n"); 831 fprintf(stderr, "Cannot create windows!\n");
853 exit(EXIT_FAILURE); 832 exit(EXIT_FAILURE);
854 } 833 }
855 wbkgd(rosterWnd, get_color(COLOR_GENERAL)); 834 wbkgd(rosterWnd, get_color(COLOR_GENERAL));
856 wbkgd(chatWnd, get_color(COLOR_GENERAL)); 835 wbkgd(chatWnd, get_color(COLOR_GENERAL));
836 wbkgd(activechatWnd, get_color(COLOR_GENERAL));
857 wbkgd(logWnd, get_color(COLOR_GENERAL)); 837 wbkgd(logWnd, get_color(COLOR_GENERAL));
858 wbkgd(chatstatusWnd, get_color(COLOR_STATUS)); 838 wbkgd(chatstatusWnd, get_color(COLOR_STATUS));
859 wbkgd(mainstatusWnd, get_color(COLOR_STATUS)); 839 wbkgd(mainstatusWnd, get_color(COLOR_STATUS));
860 } else { 840 } else {
861 /* Resize/move windows */ 841 /* Resize/move windows */
899 nodelay(inputWnd, TRUE); 879 nodelay(inputWnd, TRUE);
900 880
901 // Create panels 881 // Create panels
902 rosterPanel = new_panel(rosterWnd); 882 rosterPanel = new_panel(rosterWnd);
903 chatPanel = new_panel(chatWnd); 883 chatPanel = new_panel(chatWnd);
884 activechatPanel = new_panel(activechatWnd);
904 logPanel = new_panel(logWnd); 885 logPanel = new_panel(logWnd);
905 chatstatusPanel = new_panel(chatstatusWnd); 886 chatstatusPanel = new_panel(chatstatusWnd);
906 mainstatusPanel = new_panel(mainstatusWnd); 887 mainstatusPanel = new_panel(mainstatusWnd);
907 inputPanel = new_panel(inputWnd); 888 inputPanel = new_panel(inputWnd);
908 889