diff --git a/CHANGES b/CHANGES
index 855bcebfc02332fa81cd9f84813db1ae5c85e264..c59447e6393b00d98ba978d27bec0740fd130890 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,11 @@ CHANGES SINCE FLTK 1.0.10
 
 	- Added support for AIX (static library only).
 
+	- Added support for SunOS 4.x
+
+	- Now process WIN32 WM_ACTIVATEAPP message to reset the
+	  key and button states in Fl::e_state.
+
 	- Fl_has_idle only tested N-1 callbacks and missed one.
 
 	- Restored WM_SYNCPAINT handling under WIN32; this fixed
diff --git a/configh.in b/configh.in
index b6e4c75076da0d985ea556de691b02595f9637e6..92bbb52950812b8b175059f4c831f72a038f7204 100644
--- a/configh.in
+++ b/configh.in
@@ -1,5 +1,5 @@
 /*
- * "$Id: configh.in,v 1.11.2.8 2001/02/12 15:12:14 easysw Exp $"
+ * "$Id: configh.in,v 1.11.2.9 2001/04/27 14:39:27 easysw Exp $"
  *
  * Configuration file for the Fast Light Tool Kit (FLTK).
  * @configure_input@
@@ -137,7 +137,7 @@
 #define HAVE_VSPRINTF 0
 
 /*
- * String functions...
+ * String functions and headers...
  */
 
 #define HAVE_STRINGS_H 0
@@ -151,6 +151,14 @@
 
 #define HAVE_SYS_SELECT_H 0
 
+/*
+ * HAVE_SYS_STDTYPES_H:
+ *
+ * Whether or not we have the <sys/stdtypes.h> header file.
+ */
+
+#define HAVE_SYS_STDTYPES_H 0
+
 /*
  * USE_POLL:
  *
@@ -160,5 +168,5 @@
 #define USE_POLL 0
 
 /*
- * End of "$Id: configh.in,v 1.11.2.8 2001/02/12 15:12:14 easysw Exp $".
+ * End of "$Id: configh.in,v 1.11.2.9 2001/04/27 14:39:27 easysw Exp $".
  */
diff --git a/configure.in b/configure.in
index 4548be8a682b6fd2cb430fab9df6ef0ee8977ca2..9aa955e23d008638a57e56af5430c85f812c1821 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,7 @@
 dnl -*- sh -*-
 dnl the "configure" script is made from this by running GNU "autoconf"
 dnl
-dnl "$Id: configure.in,v 1.33.2.27 2001/04/25 13:34:43 easysw Exp $"
+dnl "$Id: configure.in,v 1.33.2.28 2001/04/27 14:39:27 easysw Exp $"
 dnl
 dnl Configuration script for the Fast Light Tool Kit (FLTK).
 dnl
@@ -136,6 +136,7 @@ fi
 
 AC_HEADER_DIRENT
 AC_CHECK_HEADER(sys/select.h)
+AC_CHECK_HEADER(sys/stdtypes.h)
 AC_CHECK_FUNC(scandir,
     if test "$uname" = SunOS -o "$uname" = QNX; then
         echo Not using $uname scandir emulation function.
@@ -371,5 +372,5 @@ AC_CONFIG_HEADER(config.h:configh.in)
 AC_OUTPUT(makeinclude)
 
 dnl
-dnl End of "$Id: configure.in,v 1.33.2.27 2001/04/25 13:34:43 easysw Exp $".
+dnl End of "$Id: configure.in,v 1.33.2.28 2001/04/27 14:39:27 easysw Exp $".
 dnl
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index a83e6307eac6cdb3f0e71319497baa621243f663..b16f1b92be4d0a1e3517880f700abe22ab04011b 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -1,5 +1,5 @@
 //
-// "$Id: Fl_win32.cxx,v 1.33.2.33 2001/04/22 16:54:23 spitzak Exp $"
+// "$Id: Fl_win32.cxx,v 1.33.2.34 2001/04/27 14:39:27 easysw Exp $"
 //
 // WIN32-specific code for the Fast Light Tool Kit (FLTK).
 //
@@ -418,8 +418,6 @@ static Fl_Window* resize_bug_fix;
 
 static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-
-#if 1
   // Matt: When dragging a full window, MSWindows on 'slow'
   // machines can lose track of the window refresh area. It sends some kind
   // of panic message to the desktop that in turn sends this message on to
@@ -434,7 +432,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
       cnt = 0;
     } else cnt = 1;
   } else if (uMsg == WM_PAINT) cnt = 0;
-#endif
 
   fl_msg.message = uMsg;
 
@@ -510,6 +507,30 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
     }
     break;
 
+  case WM_ACTIVATEAPP:
+    // From eric@vfx.sel.sony.com, we should process WM_ACTIVATEAPP
+    // messages to restore the correct state of the shift/ctrl/alt/lock
+    // keys...  Added control, shift, alt, and meta keys, mouse buttons,
+    // and changed to use GetAsyncKeyState...
+    if (!wParam)
+    {
+      ulong state = 0;
+      if (GetAsyncKeyState(VK_CAPITAL)) state |= FL_CAPS_LOCK;
+      if (GetAsyncKeyState(VK_NUMLOCK)) state |= FL_NUM_LOCK;
+      if (GetAsyncKeyState(VK_SCROLL)) state |= FL_SCROLL_LOCK;
+      if (GetAsyncKeyState(VK_CONTROL)) state |= FL_CTRL;
+      if (GetAsyncKeyState(VK_SHIFT)) state |= FL_SHIFT;
+      if (GetAsyncKeyState(VK_MENU)) state |= FL_ALT;
+      if (GetAsyncKeyState(VK_LWIN) ||
+          GetAsyncKeyState(VK_RWIN)) state |= FL_META;
+      if (GetAsyncKeyState(VK_LBUTTON)) state |= FL_BUTTON1;
+      if (GetAsyncKeyState(VK_MBUTTON)) state |= FL_BUTTON2;
+      if (GetAsyncKeyState(VK_RBUTTON)) state |= FL_BUTTON3;
+      Fl::e_state = state;
+      return 0;
+    }
+    break;
+
   case WM_KEYDOWN:
   case WM_SYSKEYDOWN:
   case WM_KEYUP:
@@ -955,5 +976,5 @@ void Fl_Window::make_current() {
 }
 
 //
-// End of "$Id: Fl_win32.cxx,v 1.33.2.33 2001/04/22 16:54:23 spitzak Exp $".
+// End of "$Id: Fl_win32.cxx,v 1.33.2.34 2001/04/27 14:39:27 easysw Exp $".
 //
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 2b83932dbb2573a57beeababd415f3e6e145205c..8905e0f406f19819dd831af5c928fb8f9c546fee 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -1,5 +1,5 @@
 //
-// "$Id: Fl_x.cxx,v 1.24.2.23 2001/01/22 15:13:40 easysw Exp $"
+// "$Id: Fl_x.cxx,v 1.24.2.24 2001/04/27 14:39:27 easysw Exp $"
 //
 // X specific code for the Fast Light Tool Kit (FLTK).
 //
@@ -69,23 +69,38 @@ static int maxfd;
 
 static int nfds = 0;
 static int fd_array_size = 0;
-static struct FD {
+struct FD {
 #if !USE_POLL
   int fd;
   short events;
 #endif
   void (*cb)(int, void*);
   void* arg;
-} *fd = 0;
+};
+
+static FD *fd = 0;
 
 void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) {
   remove_fd(n,events);
   int i = nfds++;
   if (i >= fd_array_size) {
+    FD *temp;
     fd_array_size = 2*fd_array_size+1;
-    fd = (FD*)realloc(fd, fd_array_size*sizeof(FD));
+
+    if (!fd) temp = (FD*)malloc(fd_array_size*sizeof(FD));
+    else temp = (FD*)realloc(fd, fd_array_size*sizeof(FD));
+
+    if (!temp) return;
+    fd = temp;
+
 #if USE_POLL
-    pollfds = (pollfd*)realloc(pollfds, fd_array_size*sizeof(pollfd));
+    pollfd *tpoll;
+
+    if (!pollfds) tpoll = (pollfd*)malloc(fd_array_size*sizeof(pollfd));
+    else tpoll = (pollfd*)realloc(pollfds, fd_array_size*sizeof(pollfd));
+
+    if (!tpoll) return;
+    pollfds = tpoll;
 #endif
   }
   fd[i].cb = cb;
@@ -903,5 +918,5 @@ void Fl_Window::make_current() {
 #endif
 
 //
-// End of "$Id: Fl_x.cxx,v 1.24.2.23 2001/01/22 15:13:40 easysw Exp $".
+// End of "$Id: Fl_x.cxx,v 1.24.2.24 2001/04/27 14:39:27 easysw Exp $".
 //
diff --git a/src/vsnprintf.c b/src/vsnprintf.c
index 6774bcf568bfd65579b7393c46fbcc4eaab45bb3..e60b3b16f8ffcabe27607d58ac26037c25010e64 100644
--- a/src/vsnprintf.c
+++ b/src/vsnprintf.c
@@ -1,5 +1,5 @@
 /*
- * "$Id: vsnprintf.c,v 1.3.2.4 2001/01/22 15:13:41 easysw Exp $"
+ * "$Id: vsnprintf.c,v 1.3.2.5 2001/04/27 14:39:27 easysw Exp $"
  *
  * vsnprintf() function for the Fast Light Tool Kit (FLTK).
  *
@@ -41,12 +41,16 @@
 #include <stdarg.h>
 #include <config.h>
 
-#if !HAVE_VSNPRINTF
+#ifdef HAVE_SYS_STDTYPES_H
+#  include <sys/stdtypes.h>
+#endif /* HAVE_SYS_STDTYPES_H */
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if !HAVE_VSNPRINTF
+
 int vsnprintf(char* str, size_t size, const char* fmt, va_list ap) {
   const char* e = str+size-1;
   char* p = str;
@@ -124,13 +128,13 @@ int snprintf(char* str, size_t size, const char* fmt, ...) {
   return ret;
 }
 
-#ifdef __cplusplus
-}
 #endif
 
+#ifdef __cplusplus
+}
 #endif
 
 /*
- * End of "$Id: vsnprintf.c,v 1.3.2.4 2001/01/22 15:13:41 easysw Exp $".
+ * End of "$Id: vsnprintf.c,v 1.3.2.5 2001/04/27 14:39:27 easysw Exp $".
  */