comparison mcabber/src/screen.c @ 701:6c100adfbfb6

Add setting "roster_width" (variable buddylist width)
author Mikael Berthe <mikael@lilotux.net>
date Wed, 15 Feb 2006 22:31:19 +0100
parents ee03b56b93ee
children b26a0bde4cdb
comparison
equal deleted inserted replaced
700:3f3c5765a459 701:6c100adfbfb6
41 #include "list.h" 41 #include "list.h"
42 42
43 #define window_entry(n) list_entry(n, window_entry_t, list) 43 #define window_entry(n) list_entry(n, window_entry_t, list)
44 44
45 #define DEFAULT_LOG_WIN_HEIGHT (5+2) 45 #define DEFAULT_LOG_WIN_HEIGHT (5+2)
46 #define DEFAULT_ROSTER_WIDTH 24
46 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) 47 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height)
47 48
48 char *LocaleCharSet = "C"; 49 char *LocaleCharSet = "C";
49 50
50 static unsigned short int Log_Win_Height; 51 static unsigned short int Log_Win_Height;
52 static unsigned short int Roster_Width;
51 53
52 static inline void check_offset(int); 54 static inline void check_offset(int);
53 55
54 LIST_HEAD(window_list); 56 LIST_HEAD(window_list);
55 57
297 window_entry_t *tmp; 299 window_entry_t *tmp;
298 300
299 tmp = g_new0(window_entry_t, 1); 301 tmp = g_new0(window_entry_t, 1);
300 302
301 // Dimensions 303 // Dimensions
302 x = ROSTER_WIDTH; 304 x = Roster_Width;
303 y = 0; 305 y = 0;
304 lines = CHAT_WIN_HEIGHT; 306 lines = CHAT_WIN_HEIGHT;
305 cols = maxX - ROSTER_WIDTH; 307 cols = maxX - Roster_Width;
308 if (cols < 1) cols = 1;
306 309
307 tmp->win = newwin(lines, cols, y, x); 310 tmp->win = newwin(lines, cols, y, x);
308 while (!tmp->win) { 311 while (!tmp->win) {
309 safe_usleep(250); 312 safe_usleep(250);
310 tmp->win = newwin(lines, cols, y, x); 313 tmp->win = newwin(lines, cols, y, x);
322 top_panel(chatPanel); 325 top_panel(chatPanel);
323 } 326 }
324 update_panels(); 327 update_panels();
325 328
326 // Load buddy history from file (if enabled) 329 // Load buddy history from file (if enabled)
327 hlog_read_history(title, &tmp->hbuf, maxX - ROSTER_WIDTH - PREFIX_WIDTH); 330 hlog_read_history(title, &tmp->hbuf, maxX - Roster_Width - PREFIX_WIDTH);
328 331
329 list_add_tail(&tmp->list, &window_list); 332 list_add_tail(&tmp->list, &window_list);
330 333
331 return tmp; 334 return tmp;
332 } 335 }
510 // The message must be displayed -> update top pointer 513 // The message must be displayed -> update top pointer
511 if (win_entry->cleared) 514 if (win_entry->cleared)
512 win_entry->top = g_list_last(win_entry->hbuf); 515 win_entry->top = g_list_last(win_entry->hbuf);
513 516
514 hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags, 517 hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags,
515 maxX - ROSTER_WIDTH - PREFIX_WIDTH); 518 maxX - Roster_Width - PREFIX_WIDTH);
516 519
517 if (win_entry->cleared) { 520 if (win_entry->cleared) {
518 win_entry->cleared = FALSE; 521 win_entry->cleared = FALSE;
519 if (g_list_next(win_entry->top)) 522 if (g_list_next(win_entry->top))
520 win_entry->top = g_list_next(win_entry->top); 523 win_entry->top = g_list_next(win_entry->top);
549 // I think it could be improved a _lot_ but I'm really not an ncurses 552 // I think it could be improved a _lot_ but I'm really not an ncurses
550 // expert... :-\ Mikael. 553 // expert... :-\ Mikael.
551 // 554 //
552 void scr_DrawMainWindow(unsigned int fullinit) 555 void scr_DrawMainWindow(unsigned int fullinit)
553 { 556 {
554 int requested_lwh; 557 int requested_size;
555 558
556 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT; 559 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT;
557 requested_lwh = settings_opt_get_int("log_win_height"); 560 requested_size = settings_opt_get_int("log_win_height");
558 if (requested_lwh > 0) { 561 if (requested_size > 0) {
559 if (maxY > requested_lwh + 3) 562 if (maxY > requested_size + 3)
560 Log_Win_Height = requested_lwh + 2; 563 Log_Win_Height = requested_size + 2;
561 else 564 else
562 Log_Win_Height = ((maxY > 5) ? (maxY - 2) : 3); 565 Log_Win_Height = ((maxY > 5) ? (maxY - 2) : 3);
563 } else if (requested_lwh < 0) { 566 } else if (requested_size < 0) {
564 Log_Win_Height = 3; 567 Log_Win_Height = 3;
565 } 568 }
566 569
567 if (maxY < Log_Win_Height+2) { 570 if (maxY < Log_Win_Height+2) {
568 if (maxY < 5) { 571 if (maxY < 5) {
571 } else { 574 } else {
572 Log_Win_Height = maxY - 2; 575 Log_Win_Height = maxY - 2;
573 } 576 }
574 } 577 }
575 578
579 requested_size = settings_opt_get_int("roster_width");
580 if (requested_size > 1)
581 Roster_Width = requested_size;
582 else if (requested_size == 1)
583 Roster_Width = 2;
584 else
585 Roster_Width = DEFAULT_ROSTER_WIDTH;
586
576 if (fullinit) { 587 if (fullinit) {
577 /* Create windows */ 588 /* Create windows */
578 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); 589 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, 0, 0);
579 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); 590 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, 0, Roster_Width);
580 logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0); 591 logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0);
581 logWnd = newwin(Log_Win_Height-2, maxX-2, CHAT_WIN_HEIGHT+1, 1); 592 logWnd = newwin(Log_Win_Height-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
582 inputWnd = newwin(1, maxX, maxY-1, 0); 593 inputWnd = newwin(1, maxX, maxY-1, 0);
583 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { 594 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) {
584 scr_TerminateCurses(); 595 scr_TerminateCurses();
588 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); 599 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
589 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); 600 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
590 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL)); 601 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL));
591 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); 602 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
592 } else { 603 } else {
593 /* Resize windows */ 604 /* Resize/move windows */
594 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH); 605 wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width);
595 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH); 606 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width);
607 mvwin(chatWnd, 0, Roster_Width);
596 608
597 wresize(logWnd_border, Log_Win_Height, maxX); 609 wresize(logWnd_border, Log_Win_Height, maxX);
598 wresize(logWnd, Log_Win_Height-2, maxX-2); 610 wresize(logWnd, Log_Win_Height-2, maxX-2);
599 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0); 611 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
600 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1); 612 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
663 675
664 // Resize windows and update panels 676 // Resize windows and update panels
665 scr_DrawMainWindow(FALSE); 677 scr_DrawMainWindow(FALSE);
666 678
667 // Resize all buddy windows 679 // Resize all buddy windows
668 x = ROSTER_WIDTH; 680 x = Roster_Width;
669 y = 0; 681 y = 0;
670 lines = CHAT_WIN_HEIGHT; 682 lines = CHAT_WIN_HEIGHT;
671 cols = maxX - ROSTER_WIDTH; 683 cols = maxX - Roster_Width;
684 if (cols < 1) cols = 1;
672 685
673 list_for_each_safe(pos, n, &window_list) { 686 list_for_each_safe(pos, n, &window_list) {
674 search_entry = window_entry(pos); 687 search_entry = window_entry(pos);
675 if (search_entry->win) { 688 if (search_entry->win) {
676 GList *rescue_top; 689 GList *rescue_top;
677 // Resize buddy window (no need to move it) 690 // Resize/move buddy window
678 wresize(search_entry->win, lines, cols); 691 wresize(search_entry->win, lines, cols);
692 mvwin(search_entry->win, 0, Roster_Width);
679 werase(search_entry->win); 693 werase(search_entry->win);
680 // If a panel exists, replace the old window with the new 694 // If a panel exists, replace the old window with the new
681 if (search_entry->panel) { 695 if (search_entry->panel) {
682 replace_panel(search_entry->panel, search_entry->win); 696 replace_panel(search_entry->panel, search_entry->win);
683 } 697 }
684 // Redo line wrapping 698 // Redo line wrapping
685 rescue_top = hbuf_previous_persistent(search_entry->top); 699 rescue_top = hbuf_previous_persistent(search_entry->top);
686 hbuf_rebuild(&search_entry->hbuf, 700 hbuf_rebuild(&search_entry->hbuf,
687 maxX - ROSTER_WIDTH - PREFIX_WIDTH); 701 maxX - Roster_Width - PREFIX_WIDTH);
688 if (g_list_position(g_list_first(search_entry->hbuf), 702 if (g_list_position(g_list_first(search_entry->hbuf),
689 search_entry->top) == -1) { 703 search_entry->top) == -1) {
690 search_entry->top = rescue_top; 704 search_entry->top = rescue_top;
691 } 705 }
692 } 706 }
700 // scr_DrawRoster() 714 // scr_DrawRoster()
701 // Display the buddylist (not really the roster) on the screen 715 // Display the buddylist (not really the roster) on the screen
702 void scr_DrawRoster(void) 716 void scr_DrawRoster(void)
703 { 717 {
704 static guint offset = 0; 718 static guint offset = 0;
705 char name[ROSTER_WIDTH]; 719 char *name, *rline;
706 int maxx, maxy; 720 int maxx, maxy;
707 GList *buddy; 721 GList *buddy;
708 int i, n; 722 int i, n;
709 int rOffset; 723 int rOffset;
710 enum imstatus currentstatus = jb_getstatus(); 724 enum imstatus currentstatus = jb_getstatus();
711 725
712 // We can reset update_roster 726 // We can reset update_roster
713 update_roster = FALSE; 727 update_roster = FALSE;
714 728
715 getmaxyx(rosterWnd, maxy, maxx); 729 getmaxyx(rosterWnd, maxy, maxx);
716 maxx--; // last char is for vertical border 730 maxx--; // Last char is for vertical border
717 name[ROSTER_WIDTH-7] = 0; 731
718 732 // Cleanup of roster window
719 // cleanup of roster window
720 werase(rosterWnd); 733 werase(rosterWnd);
721 // Redraw the vertical line (not very good...) 734 // Redraw the vertical line (not very good...)
722 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); 735 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
723 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) 736 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++)
724 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE); 737 mvwaddch(rosterWnd, i, Roster_Width-1, ACS_VLINE);
725 738
726 // Leave now if buddylist is empty 739 // Leave now if buddylist is empty
727 if (!buddylist) { 740 if (!buddylist) {
728 offset = 0; 741 offset = 0;
729 update_panels(); 742 update_panels();
730 doupdate(); 743 doupdate();
731 return; 744 return;
732 } 745 }
746
747 name = g_new0(char, Roster_Width);
733 748
734 // Update offset if necessary 749 // Update offset if necessary
735 // a) Try to show as many buddylist items as possible 750 // a) Try to show as many buddylist items as possible
736 i = g_list_length(buddylist) - maxy; 751 i = g_list_length(buddylist) - maxy;
737 if (i < 0) 752 if (i < 0)
740 offset = i; 755 offset = i;
741 // b) Make sure the current_buddy is visible 756 // b) Make sure the current_buddy is visible
742 i = g_list_position(buddylist, current_buddy); 757 i = g_list_position(buddylist, current_buddy);
743 if (i == -1) { // This is bad 758 if (i == -1) { // This is bad
744 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); 759 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!");
760 g_free(name);
745 return; 761 return;
746 } else if (i < offset) { 762 } else if (i < offset) {
747 offset = i; 763 offset = i;
748 } else if (i+1 > offset + maxy) { 764 } else if (i+1 > offset + maxy) {
749 offset = i + 1 - maxy; 765 offset = i + 1 - maxy;
750 } 766 }
751 767
768 rline = g_new0(char, Roster_Width+1);
769
752 buddy = buddylist; 770 buddy = buddylist;
753 rOffset = offset; 771 rOffset = offset;
754 772
755 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { 773 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
756
757 char status = '?'; 774 char status = '?';
758 char pending = ' '; 775 char pending = ' ';
759 enum imstatus budstate; 776 enum imstatus budstate;
760 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG; 777 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG;
761 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP; 778 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP;
794 status = 'C'; 811 status = 'C';
795 else 812 else
796 status = 'x'; 813 status = 'x';
797 } 814 }
798 815
799 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7); 816 if (Roster_Width > 7)
817 strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7);
818 else
819 name[0] = 0;
820
800 if (isgrp) { 821 if (isgrp) {
801 char *sep; 822 char *sep;
802 if (ishid) 823 if (ishid)
803 sep = "+++"; 824 sep = "+++";
804 else 825 else
805 sep = "---"; 826 sep = "---";
806 mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name); 827 snprintf(rline, Roster_Width, " %c%s %s", pending, sep, name);
807 } 828 } else {
808 else 829 snprintf(rline, Roster_Width, " %c[%c] %s", pending, status, name);
809 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name); 830 }
810 831
832 mvwprintw(rosterWnd, i, 0, "%s", rline);
811 i++; 833 i++;
812 } 834 }
813 835
836 g_free(rline);
837 g_free(name);
814 top_panel(inputPanel); 838 top_panel(inputPanel);
815 update_panels(); 839 update_panels();
816 doupdate(); 840 doupdate();
817 } 841 }
818 842
1768 top_panel(inputPanel); 1792 top_panel(inputPanel);
1769 update_panels(); 1793 update_panels();
1770 break; 1794 break;
1771 case 12: // Ctrl-l 1795 case 12: // Ctrl-l
1772 scr_CheckAutoAway(TRUE); 1796 scr_CheckAutoAway(TRUE);
1797 scr_Resize();
1773 redrawwin(stdscr); 1798 redrawwin(stdscr);
1799 break;
1774 case KEY_RESIZE: 1800 case KEY_RESIZE:
1775 scr_Resize(); 1801 scr_Resize();
1776 break; 1802 break;
1777 default: 1803 default:
1778 if (isprint(key)) { 1804 if (isprint(key)) {