changeset 157:409ff07d9fe2

[/trunk] Changeset 169 by mikael * Improve resize handling.
author mikael
date Sun, 01 May 2005 20:15:50 +0000
parents 439b750d99fa
children bcf52f41ba37
files mcabber/src/TODO mcabber/src/screen.c
diffstat 2 files changed, 53 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Sun May 01 14:49:51 2005 +0000
+++ b/mcabber/src/TODO	Sun May 01 20:15:50 2005 +0000
@@ -4,10 +4,15 @@
 * Presence notification is always accepted.
 * I have seen a segfault, but don't know how to reproduce it...
   Seems to be due to a disconnection from the server.
+* Check with strdup and efence (jabglue). J'me comprends...
+* Check if it crashes when resized too small...
 
 
 TODO:
 
+* Command line history (^P/^N)
+* External commands for events
+* Read history
 * Display status
 * show (how?) we can scroll in roster if not all buddies are displayed
 * Get timestamp for offline messages
@@ -16,10 +21,11 @@
 * Pending message not displayed if buddy outside Contact window,
   maybe we could show it someway (maybe just a flag?).
 * Add a function in hbuf ~previous_persistent(hbuf *top) (to avoid loosing the
-  top variable).
+  top variable on a resize).
 
 * Commands! :-)
   - /roster <hide_offline|show_offline|top|bottom>
+    + next_message (Ctrl-q?)
   - /group <expand|shrink|toggle>
   - /say blabla
   - /say_to <jid> blabla
@@ -37,11 +43,8 @@
   - /search <\<jid\>|name>
   - /clear
   - /help
-* Command line history (^P/^N)
-* External commands for events
 * Multi-lines
 * Handle message type "error"
-* Read history
 * Shortcut to jump to next message received (shift-tab?)
 * File transfer? :)
 * Conferences :))
--- a/mcabber/src/screen.c	Sun May 01 14:49:51 2005 +0000
+++ b/mcabber/src/screen.c	Sun May 01 20:15:50 2005 +0000
@@ -318,7 +318,7 @@
 
     // Finished :)
     update_panels();
-    doupdate();
+    // doupdate();    (update_roster should be enough?)
   } else {
     top_panel(chatPanel);
     currentWindow = win_entry;  // == NULL  (current window empty)
@@ -438,7 +438,7 @@
 }
 
 //  scr_DrawMainWindow()
-// Set fullinit to TRUE to also create panels
+// Set fullinit to TRUE to also create panels.  Set it to FALSE for a resize.
 //
 // I think it could be improved a _lot_ but I'm really not an ncurses
 // expert... :-\   Mikael.
@@ -447,12 +447,26 @@
 {
   int l;
 
-  /* Create windows */
-  rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
-  chatWnd   = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
-  logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
-  logWnd    = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1);
-  inputWnd  = newwin(1, maxX, maxY-1, 0);
+  if (fullinit) {
+    /* Create windows */
+    rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
+    chatWnd   = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
+    logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
+    logWnd    = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
+    inputWnd  = newwin(1, maxX, maxY-1, 0);
+  } else {
+    /* Resize windows */
+    wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH);
+    wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH);
+
+    wresize(logWnd_border, LOG_WIN_HEIGHT, maxX);
+    wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2);
+    mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
+    mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
+
+    wresize(inputWnd, 1, maxX);
+    mvwin(inputWnd, maxY-1, 0);
+  }
 
   /* Draw/init windows */
 
@@ -470,18 +484,28 @@
   // - Draw/clear the log window
   scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
   wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
+  // Auto-scrolling in log window
   scrollok(logWnd, TRUE);
 
-  // Enable keypad (+ special keys)
-  keypad(inputWnd, TRUE);
 
   if (fullinit) {
+    // Enable keypad (+ special keys)
+    keypad(inputWnd, TRUE);
+
     // Create panels
     rosterPanel = new_panel(rosterWnd);
     chatPanel   = new_panel(chatWnd);
     logPanel_border = new_panel(logWnd_border);
     logPanel    = new_panel(logWnd);
     inputPanel  = new_panel(inputWnd);
+  } else {
+    // Update panels
+    replace_panel(rosterPanel, rosterWnd);
+    replace_panel(chatPanel, chatWnd);
+    replace_panel(logPanel, logWnd);
+    replace_panel(logPanel_border, logWnd_border);
+    replace_panel(inputPanel, inputWnd);
+    wprintw(logWnd, "This is a test\n");
   }
 
   // We'll need to redraw the roster
@@ -491,13 +515,10 @@
 
 //  scr_Resize()
 // Function called when the window is resized.
-// - Recreate windows
-// - Update panels
+// - Resize windows
 // - Rewrap lines in each buddy buffer
 void scr_Resize()
 {
-  WINDOW *w_roster, *w_chat, *w_log, *w_log_bord, *w_input;
-
   struct list_head *pos, *n;
   window_entry_t *search_entry;
   int x, y, lines, cols;
@@ -507,30 +528,9 @@
   // Make sure the cursor stays inside the window
   check_offset(0);
 
-  // Backup pointers
-  w_roster    = rosterWnd;
-  w_chat      = chatWnd;
-  w_log       = logWnd;
-  w_log_bord  = logWnd_border;
-  w_input     = inputWnd;
-
-  // Recreate windows
+  // Resize windows and update panels
   scr_DrawMainWindow(FALSE);
 
-  // Replace windows for panels
-  replace_panel(rosterPanel, rosterWnd);
-  replace_panel(chatPanel, chatWnd);
-  replace_panel(logPanel, logWnd);
-  replace_panel(logPanel_border, logWnd_border);
-  replace_panel(inputPanel, inputWnd);
-
-  // Destroy old windows
-  delwin(w_roster);
-  delwin(w_chat);
-  delwin(w_log);
-  delwin(w_log_bord);
-  delwin(w_input);
-
   // Resize all buddy windows
   x = ROSTER_WIDTH;
   y = 0;
@@ -540,9 +540,8 @@
   list_for_each_safe(pos, n, &window_list) {
     search_entry = window_entry(pos);
     if (search_entry->win) {
-      WINDOW *w_buddy = search_entry->win;
-      // Create new window
-      search_entry->win = newwin(lines, cols, y, x);
+      // Resize buddy window (no need to move it)
+      wresize(search_entry->win, lines, cols);
       scr_clear_box(search_entry->win, 0, 0, lines, cols, COLOR_GENERAL);
       // If a panel exists, replace the old window with the new
       if (search_entry->panel) {
@@ -551,19 +550,12 @@
       // Redo line wrapping
       hbuf_rebuild(&search_entry->hbuf,
               maxX - scr_WindowWidth(rosterWnd) - 14);
-      // Delete old buddy window
-      delwin(w_buddy);
     }
   }
 
   // Refresh current buddy window
-  if (chatmode) {
-    usleep(100);
+  if (chatmode)
     scr_ShowBuddyWindow();
-  }
-  // NCurses is very bad wrt memory (can lead to segfaults) so let's slow
-  // things down...
-  usleep(200);
 }
 
 //  scr_DrawRoster()
@@ -942,7 +934,7 @@
   va_list ap;
 
   do {
-  buffer = (char *) calloc(1, 1024);
+    buffer = (char *) calloc(1, 1024);
   } while (!buffer);
 
   timestamp = time(NULL);
@@ -1217,6 +1209,7 @@
             buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
           top_panel(chatPanel);
           top_panel(inputPanel);
+          update_panels();
           break;
       case 12:  // Ctrl-l
       case KEY_RESIZE:
@@ -1226,14 +1219,16 @@
           scr_LogPrint("Unkown key=%d", key);
     }
   }
-  if (completion_started && key != 9)
+  if (completion_started && key != 9 && key != KEY_RESIZE)
     scr_end_current_completion();
   mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset);
   wclrtoeol(inputWnd);
   if (*ptr_inputline) {
     wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset);
   }
-  update_panels();
-  doupdate();
+  if (!update_roster) {
+    //update_panels();
+    doupdate();
+  }
   return 0;
 }