At last, merge the putty-gtk2 branch back into the trunk!
[u/mdw/putty] / mac / macpgen.c
index 2b1a3a7..f8765c4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: macpgen.c,v 1.3 2003/02/16 14:27:37 ben Exp $ */
+/* $Id$ */
 /*
  * Copyright (c) 1999, 2003 Ben Harris
  * All rights reserved.
@@ -71,6 +71,7 @@ static void mac_event(EventRecord *);
 static void mac_contentclick(WindowPtr, EventRecord *);
 static void mac_growwindow(WindowPtr, EventRecord *);
 static void mac_activatewindow(WindowPtr, EventRecord *);
+static void mac_suspendresume(EventRecord *);
 static void mac_updatewindow(WindowPtr);
 static void mac_keypress(EventRecord *);
 static int mac_windowtype(WindowPtr);
@@ -204,12 +205,33 @@ static void mac_eventloop(void) {
     Boolean gotevent;
     EventRecord event;
     RgnHandle cursrgn;
+    Point mousenow, mousethen;
+    KeyState *ks;
+    WindowPtr front;
 
     cursrgn = NewRgn();
+    GetMouse(&mousethen);
     for (;;) {
        mac_adjustcursor(cursrgn);
        gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, cursrgn);
        mac_adjustcursor(cursrgn);
+       front = mac_frontwindow();
+       if (front != NULL) {
+           ks = mac_windowkey(front);
+           if (ks->collecting_entropy) {
+               GetMouse(&mousenow);
+               if (mousenow.h != mousethen.h || mousenow.v != mousethen.v) {
+                   ks->entropy[ks->entropy_got++] = *(unsigned *)&mousenow;
+                   ks->entropy[ks->entropy_got++] = TickCount();
+                   if (ks->entropy_got >= ks->entropy_required)
+                       ks->collecting_entropy = 0;
+                   SetControlValue(ks->progress, ks->entropy_got);
+                   mousethen = mousenow;
+               }
+               SetEmptyRgn(cursrgn);
+           }
+       }
+           
        if (gotevent)
            mac_event(&event);
        if (borednow)
@@ -289,6 +311,13 @@ static void mac_event(EventRecord *event) {
         }
         break;
 #endif
+      case osEvt:
+       switch ((event->message & osEvtMessageMask) >> 24) {
+         case suspendResumeMessage:
+           mac_suspendresume(event);
+           break;
+       }
+       break;
       case kHighLevelEvent:
        AEProcessAppleEvent(event); /* errors? */
        break;
@@ -417,6 +446,27 @@ static void mac_closewindow(WindowPtr window)
     }
 }
 
+static void mac_suspendresume(EventRecord *event)
+{
+    WindowPtr front;
+    EventRecord fakeevent;
+
+    /*
+     * We're called either before we're suspended or after we're
+     * resumed, so we're the front application at this point.
+     */
+    front = FrontWindow();
+    if (front != NULL) {
+       fakeevent.what = activateEvt;
+       fakeevent.message = (UInt32)front;
+       fakeevent.when = event->when;
+       fakeevent.where = event->where;
+       fakeevent.modifiers =
+           (event->message & resumeFlag) ? activeFlag : 0;
+       mac_activatewindow(front, &fakeevent);
+    }
+}
+
 static void mac_zoomwindow(WindowPtr window, short part) {
 
     /* FIXME: do something */