Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/config.c
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/config.c	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/config.c	(working copy)
@@ -1541,6 +1541,11 @@
 #endif
 	}
 
+        s = ctrl_getset(b, "Connection", "wakeup",
+                        "Wakeup options");
+        ctrl_checkbox(s, "Attempt to reconnect on system wakeup", 'w', HELPCTX(connection_wakeupreconnect),
+                dlg_stdcheckbox_handler, I(offsetof(Config,wakeup_reconnect)));
+
 	/*
 	 * A sub-panel Connection/Data, containing options that
 	 * decide on data to send to the server.
Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/putty.h
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/putty.h	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/putty.h	(working copy)
@@ -409,6 +409,7 @@
     int ping_interval;		       /* in seconds */
     int tcp_nodelay;
     int tcp_keepalives;
+    int wakeup_reconnect;
     /* Proxy options */
     char proxy_exclude_list[512];
     int proxy_dns;
Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/settings.c
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/settings.c	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/settings.c	(working copy)
@@ -274,6 +274,7 @@
     write_setting_i(sesskey, "PingInterval", cfg->ping_interval / 60);	/* minutes */
     write_setting_i(sesskey, "PingIntervalSecs", cfg->ping_interval % 60);	/* seconds */
     write_setting_i(sesskey, "TCPNoDelay", cfg->tcp_nodelay);
+    write_setting_i(sesskey, "WakeupReconnect", cfg->wakeup_reconnect);
     write_setting_i(sesskey, "TCPKeepalives", cfg->tcp_keepalives);
     write_setting_s(sesskey, "TerminalType", cfg->termtype);
     write_setting_s(sesskey, "TerminalSpeed", cfg->termspeed);
@@ -496,6 +497,7 @@
     }
     gppi(sesskey, "TCPNoDelay", 1, &cfg->tcp_nodelay);
     gppi(sesskey, "TCPKeepalives", 0, &cfg->tcp_keepalives);
+    gppi(sesskey, "WakeupReconnect", 0, &cfg->wakeup_reconnect);
     gpps(sesskey, "TerminalType", "xterm", cfg->termtype,
 	 sizeof(cfg->termtype));
     gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed,
Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/version.c
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/version.c	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/version.c	(working copy)
@@ -25,7 +25,7 @@
 
 #else
 
-char ver[] = "Unidentified build, " __DATE__ " " __TIME__;
+char ver[] = "PuTTY + wakeup (warp13.co.uk), " __DATE__ " " __TIME__;
 char sshver[] = "PuTTY-Local: " __DATE__ " " __TIME__;
 
 #endif
Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/window.c
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/window.c	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/window.c	(working copy)
@@ -187,6 +187,8 @@
 
 static UINT wm_mousewheel = WM_MOUSEWHEEL;
 
+static time_t last_reconnect = 0;
+
 /* Dummy routine, only required in plink. */
 void ldisc_update(void *frontend, int echo, int edit)
 {
@@ -2899,6 +2901,32 @@
 	    sfree(c);
 	}
 	return 0;
+      case WM_POWERBROADCAST:
+        if(cfg.wakeup_reconnect) {
+          switch(wParam) {
+            case PBT_APMRESUMESUSPEND:
+            case PBT_APMRESUMEAUTOMATIC:
+            case PBT_APMRESUMECRITICAL:
+            case PBT_APMQUERYSUSPENDFAILED:
+              if(session_closed && !back) {
+				time_t tnow = time(NULL);
+                if(last_reconnect && (tnow - last_reconnect) < 5)
+				  Sleep(1000);
+
+			    last_reconnect = tnow;
+                logevent(NULL, "Woken up from suspend, reconnecting. . .");
+                start_backend();
+              }
+              break;
+            case PBT_APMSUSPEND:
+              if(!session_closed && back) {
+                logevent(NULL, "Suspend detected! Disconnecting cleanly!");
+                close_session();
+              }
+              break;
+          }
+        }
+        break;
       default:
 	if (message == wm_mousewheel || message == WM_MOUSEWHEEL) {
 	    int shift_pressed=0, control_pressed=0;
Index: C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/winhelp.h
===================================================================
--- C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/winhelp.h	(revision 6566)
+++ C:/Documents and Settings/Chris/My Documents/Dev/putty/wc/windows/winhelp.h	(working copy)
@@ -73,6 +73,7 @@
 #define WINHELP_CTX_connection_nodelay "connection.nodelay"
 #define WINHELP_CTX_connection_ipversion "connection.ipversion"
 #define WINHELP_CTX_connection_tcpkeepalive "connection.tcpkeepalive"
+#define WINHELP_CTX_connection_wakeupreconnect "connection.wakeupreconnect"
 #define WINHELP_CTX_proxy_type "proxy.type"
 #define WINHELP_CTX_proxy_main "proxy.main"
 #define WINHELP_CTX_proxy_exclude "proxy.exclude"
