(Font Lock): Correct invalid @xref.
[bpt/emacs.git] / src / macterm.c
index b9584be..9e482a1 100644 (file)
@@ -5321,7 +5321,6 @@ x_make_frame_visible (f)
 
   XFlush (FRAME_MAC_DISPLAY (f));
 
-#if 0 /* MAC_TODO */
   /* Synchronize to ensure Emacs knows the frame is visible
      before we do anything else.  We do this loop with input not blocked
      so that incoming events are handled.  */
@@ -5365,9 +5364,6 @@ x_make_frame_visible (f)
        FRAME_SAMPLE_VISIBILITY (f);
       }
   }
-#else
-  UNBLOCK_INPUT;
-#endif /* MAC_TODO */
 }
 
 /* Change from mapped state to withdrawn state.  */
@@ -7236,40 +7232,6 @@ is_emacs_window (WindowPtr win)
   return 0;
 }
 
-static void
-do_window_activate (WindowPtr win)
-{
-  struct frame *f;
-
-  if (is_emacs_window (win))
-    {
-      f = mac_window_to_frame (win);
-
-      if (f)
-       {
-         x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f), f);
-         activate_scroll_bars (f);
-       }
-    }
-}
-
-static void
-do_window_deactivate (WindowPtr win)
-{
-  struct frame *f;
-
-  if (is_emacs_window (win))
-    {
-      f = mac_window_to_frame (win);
-
-      if (f == FRAME_MAC_DISPLAY_INFO (f)->x_focus_frame)
-       {
-         x_new_focus_frame (FRAME_MAC_DISPLAY_INFO (f), 0);
-         deactivate_scroll_bars (f);
-       }
-    }
-}
-
 static void
 do_app_resume ()
 {
@@ -8154,6 +8116,14 @@ XTread_socket (sd, expected, hold_quit)
            SInt16 part_code;
            int tool_bar_p = 0;
 
+#if USE_CARBON_EVENTS
+           /* This is needed to send mouse events like aqua window
+              buttons to the correct handler.  */
+           if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
+               != eventNotHandledErr)
+             break;
+#endif
+
            if (dpyinfo->grabbed && last_mouse_frame
                && FRAME_LIVE_P (last_mouse_frame))
              {
@@ -8169,16 +8139,9 @@ XTread_socket (sd, expected, hold_quit)
                    window_ptr = FrontWindow ();
                  }
 
-#if USE_CARBON_EVENTS
-               /* This is needed to send mouse events like aqua
-                  window buttons to the correct handler.  */
-               if (SendEventToEventTarget (eventRef, toolbox_dispatcher)
-                   != eventNotHandledErr)
-                 break;
-
                if (!is_emacs_window (window_ptr))
                  break;
-#endif
+
                part_code = FindWindow (er.where, &window_ptr);
              }
 
@@ -8424,24 +8387,38 @@ XTread_socket (sd, expected, hold_quit)
                break;
              }
 
+           if (!is_emacs_window (window_ptr))
+             break;
+           
+           f = mac_window_to_frame (window_ptr);
+
            if ((er.modifiers & activeFlag) != 0)
              {
+               /* A window has been activated */
                Point mouse_loc = er.where;
 
-               do_window_activate (window_ptr);
+               x_new_focus_frame (dpyinfo, f);
+               activate_scroll_bars (f);
 
                SetPortWindowPort (window_ptr);
                GlobalToLocal (&mouse_loc);
-               /* activateEvt counts as mouse movement,
+               /* Window-activated event counts as mouse movement,
                   so update things that depend on mouse position.  */
                note_mouse_movement (mac_window_to_frame (window_ptr),
                                     &mouse_loc);
              }
            else
              {
-               do_window_deactivate (window_ptr);
+               /* A window has been deactivated */
+               dpyinfo->grabbed = 0;
+
+               if (f == dpyinfo->x_focus_frame)
+                 {
+                   x_new_focus_frame (dpyinfo, 0);
+                   deactivate_scroll_bars (f);
+                 }
+
 
-               f = mac_window_to_frame (window_ptr);
                if (f == dpyinfo->mouse_face_mouse_frame)
                  {
                    /* If we move outside the frame, then we're
@@ -8873,8 +8850,21 @@ mac_initialize_display_info ()
   dpyinfo->color_p = TestDeviceAttribute (main_device_handle, gdDevType);
 #ifdef MAC_OSX
   /* HasDepth returns true if it is possible to have a 32 bit display,
-     but this may not be what is actually used.  Mac OSX can do better.  */
-  dpyinfo->n_planes = CGDisplayBitsPerPixel (CGMainDisplayID ());
+     but this may not be what is actually used.  Mac OSX can do better.
+     CGMainDisplayID is only available on OSX 10.2 and higher, but the
+     header for CGGetActiveDisplayList says that the first display returned
+     is the active one, so we use that.  */
+  {
+    CGDirectDisplayID disp_id[1];
+    CGDisplayCount disp_count;
+    CGDisplayErr error_code;
+
+    error_code = CGGetActiveDisplayList (1, disp_id, &disp_count);
+    if (error_code != 0)
+      error ("No display found, CGGetActiveDisplayList error %d", error_code);
+
+    dpyinfo->n_planes = CGDisplayBitsPerPixel (disp_id[0]);
+  }
 #else
   for (dpyinfo->n_planes = 32; dpyinfo->n_planes > 0; dpyinfo->n_planes >>= 1)
     if (HasDepth (main_device_handle, dpyinfo->n_planes,