mcabber/src/screen.c
changeset 711 75dde88f1884
parent 709 5aa66101807b
child 712 e1639629c87b
equal deleted inserted replaced
710:0311d7e2bb1c 711:75dde88f1884
    64   char    cleared;  // For ex, user has issued a /clear command...
    64   char    cleared;  // For ex, user has issued a /clear command...
    65   struct list_head list;
    65   struct list_head list;
    66 } window_entry_t;
    66 } window_entry_t;
    67 
    67 
    68 
    68 
    69 static WINDOW *rosterWnd, *chatWnd, *inputWnd;
    69 static WINDOW *rosterWnd, *chatWnd, *inputWnd, *logWnd;
    70 static WINDOW *logWnd, *logWnd_border;
    70 static WINDOW *mainstatusWnd, *chatstatusWnd;
    71 static PANEL *rosterPanel, *chatPanel, *inputPanel;
    71 static PANEL *rosterPanel, *chatPanel, *inputPanel;
    72 static PANEL *logPanel, *logPanel_border;
    72 static PANEL *mainstatusPanel, *chatstatusPanel;
       
    73 static PANEL *logPanel;
    73 static int maxY, maxX;
    74 static int maxY, maxX;
    74 static window_entry_t *currentWindow;
    75 static window_entry_t *currentWindow;
    75 
    76 
    76 static int roster_hidden;
    77 static int roster_hidden;
    77 static int chatmode;
    78 static int chatmode;
    96 static int scr_WindowWidth(WINDOW * win)
    97 static int scr_WindowWidth(WINDOW * win)
    97 {
    98 {
    98   int x, y;
    99   int x, y;
    99   getmaxyx(win, y, x);
   100   getmaxyx(win, y, x);
   100   return x;
   101   return x;
   101 }
       
   102 
       
   103 static void scr_draw_box(WINDOW * win, int y, int x, int height, int width,
       
   104                          int Color, chtype box, chtype border)
       
   105 {
       
   106   int i, j;
       
   107 
       
   108   wattrset(win, COLOR_PAIR(Color));
       
   109   for (i = 0; i < height; i++) {
       
   110     wmove(win, y + i, x);
       
   111     for (j = 0; j < width; j++)
       
   112       if (!i && !j)
       
   113 	waddch(win, border | ACS_ULCORNER);
       
   114       else if (i == height - 1 && !j)
       
   115 	waddch(win, border | ACS_LLCORNER);
       
   116       else if (!i && j == width - 1)
       
   117 	waddch(win, box | ACS_URCORNER);
       
   118       else if (i == height - 1 && j == width - 1)
       
   119 	waddch(win, box | ACS_LRCORNER);
       
   120       else if (!i)
       
   121 	waddch(win, border | ACS_HLINE);
       
   122       else if (i == height - 1)
       
   123 	waddch(win, box | ACS_HLINE);
       
   124       else if (!j)
       
   125 	waddch(win, border | ACS_VLINE);
       
   126       else if (j == width - 1)
       
   127 	waddch(win, box | ACS_VLINE);
       
   128       else
       
   129 	waddch(win, box | ' ');
       
   130   }
       
   131 }
   102 }
   132 
   103 
   133 static int FindColor(const char *name)
   104 static int FindColor(const char *name)
   134 {
   105 {
   135   if (!strcmp(name, "default"))
   106   if (!strcmp(name, "default"))
   157 static void ParseColors(void)
   128 static void ParseColors(void)
   158 {
   129 {
   159   const char *colors[8] = {
   130   const char *colors[8] = {
   160     "", "",
   131     "", "",
   161     "general",
   132     "general",
       
   133     "status",
   162     "newmsg",
   134     "newmsg",
   163     "rosterselect",
   135     "rosterselect",
   164     "rosternormal",
   136     "rosternormal",
   165     NULL
   137     NULL
   166   };
   138   };
   167 
   139 
   168   char *tmp = g_new(char, 512);
   140   char *tmp = g_new(char, 512);
   169   const char *color;
   141   const char *color;
   170   const char *background   = settings_opt_get("color_background");
   142   const char *background   = settings_opt_get("color_background");
   171   const char *backselected = settings_opt_get("color_backselected");
   143   const char *backselected = settings_opt_get("color_backselected");
       
   144   const char *backstatus   = settings_opt_get("color_backstatus");
   172   int i = 0;
   145   int i = 0;
   173 
   146 
   174   // Default values
   147   // Default values
   175   if (!background)   background   = "blue";
   148   if (!background)   background   = "black";
   176   if (!backselected) backselected = "cyan";
   149   if (!backselected) backselected = "cyan";
       
   150   if (!backstatus)   backstatus   = "blue";
   177 
   151 
   178   while (colors[i]) {
   152   while (colors[i]) {
   179     snprintf(tmp, 512, "color_%s", colors[i]);
   153     snprintf(tmp, 512, "color_%s", colors[i]);
   180     color = settings_opt_get(tmp);
   154     color = settings_opt_get(tmp);
   181 
   155 
   184       init_pair(1, COLOR_BLACK, COLOR_WHITE);
   158       init_pair(1, COLOR_BLACK, COLOR_WHITE);
   185       break;
   159       break;
   186     case 2:
   160     case 2:
   187       init_pair(2, COLOR_WHITE, COLOR_BLACK);
   161       init_pair(2, COLOR_WHITE, COLOR_BLACK);
   188       break;
   162       break;
   189     case 3:
   163     case COLOR_GENERAL:
   190       init_pair(3, ((color) ? FindColor(color) : COLOR_WHITE),
   164       init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE),
   191                 FindColor(background));
   165                 FindColor(background));
   192       break;
   166       break;
   193     case 4:
   167     case COLOR_STATUS:
   194       init_pair(4, ((color) ? FindColor(color) : COLOR_RED),
   168       init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE),
       
   169                 FindColor(backstatus));
       
   170       break;
       
   171     case COLOR_NMSG:
       
   172       init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED),
   195                 FindColor(background));
   173                 FindColor(background));
   196       break;
   174       break;
   197     case 5:
   175     case COLOR_BD_DESSEL:
   198       init_pair(5, ((color) ? FindColor(color) : COLOR_BLACK),
   176       init_pair(i+1, ((color) ? FindColor(color) : COLOR_BLUE),
   199                 FindColor(backselected));
   177                 FindColor(backselected));
   200       break;
   178       break;
   201     case 6:
   179     case COLOR_BD_DES:
   202       init_pair(6, ((color) ? FindColor(color) : COLOR_MAGENTA),
   180       init_pair(i+1, ((color) ? FindColor(color) : COLOR_GREEN),
   203                 FindColor(background));
   181                 FindColor(background));
   204       break;
   182       break;
   205     }
   183     }
   206     i++;
   184     i++;
   207   }
   185   }
   591 
   569 
   592   if (fullinit) {
   570   if (fullinit) {
   593     /* Create windows */
   571     /* Create windows */
   594     rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, 0, 0);
   572     rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, 0, 0);
   595     chatWnd   = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, 0, Roster_Width);
   573     chatWnd   = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, 0, Roster_Width);
   596     logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0);
   574     logWnd    = newwin(Log_Win_Height-2, maxX, CHAT_WIN_HEIGHT+1, 0);
   597     logWnd    = newwin(Log_Win_Height-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
   575     chatstatusWnd = newwin(1, maxX, CHAT_WIN_HEIGHT, 0);
       
   576     mainstatusWnd = newwin(1, maxX, maxY-2, 0);
   598     inputWnd  = newwin(1, maxX, maxY-1, 0);
   577     inputWnd  = newwin(1, maxX, maxY-1, 0);
   599     if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) {
   578     if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) {
   600       scr_TerminateCurses();
   579       scr_TerminateCurses();
   601       fprintf(stderr, "Cannot create windows!\n");
   580       fprintf(stderr, "Cannot create windows!\n");
   602       exit(EXIT_FAILURE);
   581       exit(EXIT_FAILURE);
   603     }
   582     }
   604     wbkgd(rosterWnd,      COLOR_PAIR(COLOR_GENERAL));
   583     wbkgd(rosterWnd,      COLOR_PAIR(COLOR_GENERAL));
   605     wbkgd(chatWnd,        COLOR_PAIR(COLOR_GENERAL));
   584     wbkgd(chatWnd,        COLOR_PAIR(COLOR_GENERAL));
   606     wbkgd(logWnd_border,  COLOR_PAIR(COLOR_GENERAL));
       
   607     wbkgd(logWnd,         COLOR_PAIR(COLOR_GENERAL));
   585     wbkgd(logWnd,         COLOR_PAIR(COLOR_GENERAL));
       
   586     wbkgd(chatstatusWnd,  COLOR_PAIR(COLOR_STATUS));
       
   587     wbkgd(mainstatusWnd,  COLOR_PAIR(COLOR_STATUS));
   608   } else {
   588   } else {
   609     /* Resize/move windows */
   589     /* Resize/move windows */
   610     wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width);
   590     wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width);
   611     wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width);
   591     wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width);
   612     mvwin(chatWnd, 0, Roster_Width);
   592     mvwin(chatWnd, 0, Roster_Width);
   613 
   593 
   614     wresize(logWnd_border, Log_Win_Height, maxX);
   594     wresize(logWnd, Log_Win_Height-2, maxX);
   615     wresize(logWnd, Log_Win_Height-2, maxX-2);
   595     mvwin(logWnd, CHAT_WIN_HEIGHT+1, 0);
   616     mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
   596 
   617     mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
   597     // Resize & move chat status window
   618 
   598     wresize(chatstatusWnd, 1, maxX);
       
   599     mvwin(chatstatusWnd, CHAT_WIN_HEIGHT, 0);
       
   600     // Resize & move main status window
       
   601     wresize(mainstatusWnd, 1, maxX);
       
   602     mvwin(mainstatusWnd, maxY-2, 0);
       
   603     // Resize & move input line window
   619     wresize(inputWnd, 1, maxX);
   604     wresize(inputWnd, 1, maxX);
   620     mvwin(inputWnd, maxY-1, 0);
   605     mvwin(inputWnd, maxY-1, 0);
   621 
   606 
   622     werase(chatWnd);
   607     werase(chatWnd);
   623   }
   608   }
   625   /* Draw/init windows */
   610   /* Draw/init windows */
   626 
   611 
   627   mvwprintw(chatWnd, 0, 0, "Thanks for using mcabber.\n");
   612   mvwprintw(chatWnd, 0, 0, "Thanks for using mcabber.\n");
   628   mvwprintw(chatWnd, 1, 0, "http://www.lilotux.net/~mikael/mcabber/");
   613   mvwprintw(chatWnd, 1, 0, "http://www.lilotux.net/~mikael/mcabber/");
   629 
   614 
   630   // - Draw/clear the log window
       
   631   scr_draw_box(logWnd_border, 0, 0, Log_Win_Height, maxX, COLOR_GENERAL, 0, 0);
       
   632   // Auto-scrolling in log window
   615   // Auto-scrolling in log window
   633   scrollok(logWnd, TRUE);
   616   scrollok(logWnd, TRUE);
   634 
   617 
   635 
   618 
   636   if (fullinit) {
   619   if (fullinit) {
   639     nodelay(inputWnd, TRUE);
   622     nodelay(inputWnd, TRUE);
   640 
   623 
   641     // Create panels
   624     // Create panels
   642     rosterPanel = new_panel(rosterWnd);
   625     rosterPanel = new_panel(rosterWnd);
   643     chatPanel   = new_panel(chatWnd);
   626     chatPanel   = new_panel(chatWnd);
   644     logPanel_border = new_panel(logWnd_border);
       
   645     logPanel    = new_panel(logWnd);
   627     logPanel    = new_panel(logWnd);
       
   628     chatstatusPanel = new_panel(chatstatusWnd);
       
   629     mainstatusPanel = new_panel(mainstatusWnd);
   646     inputPanel  = new_panel(inputWnd);
   630     inputPanel  = new_panel(inputWnd);
   647 
   631 
   648     if (utf8_mode)
   632     if (utf8_mode)
   649       scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!");
   633       scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!");
   650   } else {
   634   } else {
   651     // Update panels
   635     // Update panels
   652     replace_panel(rosterPanel, rosterWnd);
   636     replace_panel(rosterPanel, rosterWnd);
   653     replace_panel(chatPanel, chatWnd);
   637     replace_panel(chatPanel, chatWnd);
   654     replace_panel(logPanel, logWnd);
   638     replace_panel(logPanel, logWnd);
   655     replace_panel(logPanel_border, logWnd_border);
   639     replace_panel(chatstatusPanel, chatstatusWnd);
       
   640     replace_panel(mainstatusPanel, mainstatusWnd);
   656     replace_panel(inputPanel, inputWnd);
   641     replace_panel(inputPanel, inputWnd);
   657   }
   642   }
   658 
   643 
   659   // We'll need to redraw the roster
   644   // We'll need to redraw the roster
   660   update_roster = TRUE;
   645   update_roster = TRUE;