changeset 2231:387cea2a1a81

Fix resizing with --enable-sigwinch
author Mikael Berthe <mikael@lilotux.net>
date Sun, 15 Nov 2015 17:03:41 +0100
parents f5659f0f9db8
children c06488852cdc
files mcabber/mcabber/main.c mcabber/mcabber/screen.c mcabber/mcabber/screen.h
diffstat 3 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/main.c	Wed Nov 11 10:06:46 2015 +0100
+++ b/mcabber/mcabber/main.c	Sun Nov 15 17:03:41 2015 +0100
@@ -63,7 +63,12 @@
 # define WAIT_ANY -1
 #endif
 
-static unsigned int terminate_ui;
+#ifdef USE_SIGWINCH
+void sigwinch_resize(void);
+static bool sigwinch;
+#endif
+
+static bool terminate_ui;
 GMainContext *main_context;
 
 static struct termios *backup_termios;
@@ -123,8 +128,7 @@
     mcabber_terminate("Killed by SIGHUP");
 #ifdef USE_SIGWINCH
   } else if (signum == SIGWINCH) {
-    if (scr_curses_status())
-      ungetch(KEY_RESIZE);
+    sigwinch = TRUE;
 #endif
   } else {
     scr_LogPrint(LPRINT_LOGNORM, "Caught signal: %d", signum);
@@ -555,6 +559,12 @@
     while(!terminate_ui) {
       if (g_main_context_iteration(main_context, TRUE) == FALSE)
         keyboard_activity();
+#ifdef USE_SIGWINCH
+      if (sigwinch) {
+        sigwinch_resize();
+        sigwinch = FALSE;
+      }
+#endif
       if (update_roster)
         scr_draw_roster();
       scr_do_update();
--- a/mcabber/mcabber/screen.c	Wed Nov 11 10:06:46 2015 +0100
+++ b/mcabber/mcabber/screen.c	Sun Nov 15 17:03:41 2015 +0100
@@ -1864,11 +1864,11 @@
     hbuf_rebuild(&wbp->bd->hbuf, new_chatwidth);
 }
 
-//  scr_Resize()
+//  scr_resize()
 // Function called when the window is resized.
 // - Resize windows
 // - Rewrap lines in each buddy buffer
-void scr_Resize(void)
+void scr_resize(void)
 {
   struct dimensions dim;
 
@@ -1903,6 +1903,16 @@
     scr_show_buddy_window();
 }
 
+#ifdef USE_SIGWINCH
+void sigwinch_resize(void)
+{
+  struct winsize size;
+  if (ioctl(STDIN_FILENO, TIOCGWINSZ, &size) != -1)
+    resizeterm(size.ws_row, size.ws_col);
+  scr_resize();
+}
+#endif
+
 //  scr_update_chat_status(forceupdate)
 // Redraw the buddy status bar.
 // Set forceupdate to TRUE if update_panels() must be called.
@@ -2307,7 +2317,7 @@
 
   if (roster_hidden != old_roster_status) {
     // Recalculate windows size and redraw
-    scr_Resize();
+    scr_resize();
     redrawwin(stdscr);
   }
 }
@@ -3775,7 +3785,7 @@
   scr_check_auto_away(TRUE);
   keypad(inputWnd, TRUE);
   parse_colors();
-  scr_Resize();
+  scr_resize();
   redrawwin(stdscr);
 }
 
@@ -4450,14 +4460,7 @@
         scr_handle_CtrlC();
         break;
     case KEY_RESIZE:
-#ifdef USE_SIGWINCH
-        {
-          struct winsize size;
-          if (ioctl(STDIN_FILENO, TIOCGWINSZ, &size) != -1)
-            resizeterm(size.ws_row, size.ws_col);
-        }
-#endif
-        scr_Resize();
+        scr_resize();
         break;
     default:
         display_char = TRUE;
--- a/mcabber/mcabber/screen.h	Wed Nov 11 10:06:46 2015 +0100
+++ b/mcabber/mcabber/screen.h	Sun Nov 15 17:03:41 2015 +0100
@@ -107,6 +107,7 @@
 void scr_init_settings(void);
 void scr_terminate_curses(void);
 gboolean scr_curses_status(void);
+void scr_resize(void);
 void scr_draw_main_window(unsigned int fullinit);
 void scr_draw_roster(void);
 void scr_update_main_status(int forceupdate);