+#if TARGET_API_MAC_CARBON
+ MoveWindowStructure (FRAME_MAC_WINDOW (f), f->left_pos, f->top_pos);
+ /* If the title bar is completely outside the screen, adjust the
+ position. */
+ ConstrainWindowToScreen (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn,
+ kWindowConstrainMoveRegardlessOfFit
+ | kWindowConstrainAllowPartial, NULL, NULL);
+ x_real_positions (f, &f->left_pos, &f->top_pos);
+#else
+ {
+ Rect inner, outer, screen_rect, dummy;
+ RgnHandle region = NewRgn ();
+
+ mac_get_window_bounds (f, &inner, &outer);
+ f->x_pixels_diff = inner.left - outer.left;
+ f->y_pixels_diff = inner.top - outer.top;
+ MoveWindow (FRAME_MAC_WINDOW (f), f->left_pos + f->x_pixels_diff,
+ f->top_pos + f->y_pixels_diff, false);
+
+ /* If the title bar is completely outside the screen, adjust the
+ position. The variable `outer' holds the title bar rectangle.
+ The variable `inner' holds slightly smaller one than `outer',
+ so that the calculation of overlapping may not become too
+ strict. */
+ GetWindowRegion (FRAME_MAC_WINDOW (f), kWindowTitleBarRgn, region);
+ outer = (*region)->rgnBBox;
+ DisposeRgn (region);
+ inner = outer;
+ InsetRect (&inner, 8, 8);
+ screen_rect = qd.screenBits.bounds;
+ screen_rect.top += GetMBarHeight ();
+
+ if (!SectRect (&inner, &screen_rect, &dummy))
+ {
+ if (inner.right <= screen_rect.left)
+ f->left_pos = screen_rect.left;
+ else if (inner.left >= screen_rect.right)
+ f->left_pos = screen_rect.right - (outer.right - outer.left);
+
+ if (inner.bottom <= screen_rect.top)
+ f->top_pos = screen_rect.top;
+ else if (inner.top >= screen_rect.bottom)
+ f->top_pos = screen_rect.bottom - (outer.bottom - outer.top);
+
+ MoveWindow (FRAME_MAC_WINDOW (f), f->left_pos + f->x_pixels_diff,
+ f->top_pos + f->y_pixels_diff, false);
+ }
+ }
+#endif