comparison mcabber/src/screen.c @ 518:9480a76471b6

Update Log_Win_Height when refreshing the screen It allows live modification of the 'log_win_height' option. The log window height is reduced when the screen height is reduced too much, too.
author Mikael Berthe <mikael@lilotux.net>
date Mon, 14 Nov 2005 18:34:57 +0100
parents 180f0a6e4ac9
children cc8c969ab6e5
comparison
equal deleted inserted replaced
517:d8f4a0fc77d3 518:9480a76471b6
202 } 202 }
203 } 203 }
204 204
205 void scr_InitCurses(void) 205 void scr_InitCurses(void)
206 { 206 {
207 int requested_lwh;
208 initscr(); 207 initscr();
209 raw(); 208 raw();
210 noecho(); 209 noecho();
211 nonl(); 210 nonl();
212 intrflush(stdscr, FALSE); 211 intrflush(stdscr, FALSE);
216 215
217 ParseColors(); 216 ParseColors();
218 217
219 getmaxyx(stdscr, maxY, maxX); 218 getmaxyx(stdscr, maxY, maxX);
220 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT; 219 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT;
221 220 // Note scr_DrawMainWindow() should be called early after scr_InitCurses()
222 requested_lwh = settings_opt_get_int("log_win_height"); 221 // to update Log_Win_Height and set max{X,Y}
223 if (requested_lwh > 0) { 222
224 if (maxY > requested_lwh + 3)
225 Log_Win_Height = requested_lwh + 2;
226 else
227 Log_Win_Height = ((maxY > 5) ? (maxY - 2) : 3);
228 } else if (requested_lwh < 0) {
229 Log_Win_Height = 3;
230 }
231
232 if (maxY < Log_Win_Height+2) {
233 if (maxY < 5) {
234 Log_Win_Height = 3;
235 maxY = Log_Win_Height+2;
236 } else {
237 Log_Win_Height = maxY - 2;
238 }
239 }
240 inputLine[0] = 0; 223 inputLine[0] = 0;
241 ptr_inputline = inputLine; 224 ptr_inputline = inputLine;
242 225
243 setlocale(LC_CTYPE, ""); 226 setlocale(LC_CTYPE, "");
244 utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0); 227 utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0);
569 // 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
570 // expert... :-\ Mikael. 553 // expert... :-\ Mikael.
571 // 554 //
572 void scr_DrawMainWindow(unsigned int fullinit) 555 void scr_DrawMainWindow(unsigned int fullinit)
573 { 556 {
557 int requested_lwh;
558
559 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT;
560 requested_lwh = settings_opt_get_int("log_win_height");
561 if (requested_lwh > 0) {
562 if (maxY > requested_lwh + 3)
563 Log_Win_Height = requested_lwh + 2;
564 else
565 Log_Win_Height = ((maxY > 5) ? (maxY - 2) : 3);
566 } else if (requested_lwh < 0) {
567 Log_Win_Height = 3;
568 }
569
570 if (maxY < Log_Win_Height+2) {
571 if (maxY < 5) {
572 Log_Win_Height = 3;
573 maxY = Log_Win_Height+2;
574 } else {
575 Log_Win_Height = maxY - 2;
576 }
577 }
578
574 if (fullinit) { 579 if (fullinit) {
575 /* Create windows */ 580 /* Create windows */
576 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); 581 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
577 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); 582 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
578 logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0); 583 logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0);
651 window_entry_t *search_entry; 656 window_entry_t *search_entry;
652 int x, y, lines, cols; 657 int x, y, lines, cols;
653 658
654 // First, update the global variables 659 // First, update the global variables
655 getmaxyx(stdscr, maxY, maxX); 660 getmaxyx(stdscr, maxY, maxX);
656 if (maxY < Log_Win_Height+2) 661 // scr_DrawMainWindow() will take care of maxY and Log_Win_Height
657 maxY = Log_Win_Height+2; 662
658 // Make sure the cursor stays inside the window 663 // Make sure the cursor stays inside the window
659 check_offset(0); 664 check_offset(0);
660 665
661 // Resize windows and update panels 666 // Resize windows and update panels
662 scr_DrawMainWindow(FALSE); 667 scr_DrawMainWindow(FALSE);