diff options
| author | Alan Third | 2021-07-17 11:23:42 +0100 |
|---|---|---|
| committer | Alan Third | 2021-07-24 16:35:46 +0100 |
| commit | 93b18cc3b7206b1a3fb9389a0f70f4fb2f3ab06f (patch) | |
| tree | f9efb14ed65768b71dac3a6083cabc69fc429017 | |
| parent | dee3be733c33845343c7a8f59e9f8f827748ac5d (diff) | |
| download | emacs-93b18cc3b7206b1a3fb9389a0f70f4fb2f3ab06f.tar.gz emacs-93b18cc3b7206b1a3fb9389a0f70f4fb2f3ab06f.zip | |
Simplify NS sizing and positioning code
* src/nsterm.m (ns_set_offset): Unify the two branches into one, most
of the code is the same.
(ns_set_window_size): Use the provided tools to calculate the window
size instead of doing it ourselves.
| -rw-r--r-- | src/nsterm.m | 99 |
1 files changed, 38 insertions, 61 deletions
diff --git a/src/nsterm.m b/src/nsterm.m index 984464be41e..f888961fcf6 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -1634,52 +1634,35 @@ ns_set_offset (struct frame *f, int xoff, int yoff, int change_grav) | |||
| 1634 | 1634 | ||
| 1635 | block_input (); | 1635 | block_input (); |
| 1636 | 1636 | ||
| 1637 | if (FRAME_PARENT_FRAME (f)) | 1637 | /* If there is no parent frame then just convert to screen |
| 1638 | { | 1638 | coordinates, UNLESS we have negative values, in which case I |
| 1639 | /* Convert the parent frame's view rectangle into screen | 1639 | think it's best to position from the bottom and right of the |
| 1640 | coords. */ | 1640 | current screen rather than the main screen or whole display. */ |
| 1641 | EmacsView *parentView = FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)); | ||
| 1642 | NSRect parentRect = [parentView convertRect:[parentView frame] | ||
| 1643 | toView:nil]; | ||
| 1644 | parentRect = [[parentView window] convertRectToScreen:parentRect]; | ||
| 1645 | 1641 | ||
| 1646 | if (f->size_hint_flags & XNegative) | 1642 | NSRect parentRect = ns_parent_window_rect (f); |
| 1647 | topLeft.x = NSMaxX (parentRect) - NSWidth (windowFrame) + xoff; | ||
| 1648 | else | ||
| 1649 | topLeft.x = NSMinX (parentRect) + xoff; | ||
| 1650 | 1643 | ||
| 1651 | if (f->size_hint_flags & YNegative) | 1644 | if (f->size_hint_flags & XNegative) |
| 1652 | topLeft.y = NSMinY (parentRect) + NSHeight (windowFrame) - yoff; | 1645 | topLeft.x = NSMaxX (parentRect) - NSWidth (windowFrame) + xoff; |
| 1653 | else | 1646 | else if (FRAME_PARENT_FRAME (f)) |
| 1654 | topLeft.y = NSMaxY (parentRect) - yoff; | 1647 | topLeft.x = NSMinX (parentRect) + xoff; |
| 1655 | } | ||
| 1656 | else | 1648 | else |
| 1657 | { | 1649 | topLeft.x = xoff; |
| 1658 | /* If there is no parent frame then just convert to screen | ||
| 1659 | coordinates, UNLESS we have negative values, in which case I | ||
| 1660 | think it's best to position from the bottom and right of the | ||
| 1661 | current screen rather than the main screen or whole | ||
| 1662 | display. */ | ||
| 1663 | NSRect screenFrame = [[[view window] screen] frame]; | ||
| 1664 | |||
| 1665 | if (f->size_hint_flags & XNegative) | ||
| 1666 | topLeft.x = NSMaxX (screenFrame) - NSWidth (windowFrame) + xoff; | ||
| 1667 | else | ||
| 1668 | topLeft.x = xoff; | ||
| 1669 | 1650 | ||
| 1670 | if (f->size_hint_flags & YNegative) | 1651 | if (f->size_hint_flags & YNegative) |
| 1671 | topLeft.y = NSMinY (screenFrame) + NSHeight (windowFrame) - yoff; | 1652 | topLeft.y = NSMinY (parentRect) + NSHeight (windowFrame) - yoff; |
| 1672 | else | 1653 | else if (FRAME_PARENT_FRAME (f)) |
| 1673 | topLeft.y = NSMaxY ([[[NSScreen screens] objectAtIndex:0] frame]) - yoff; | 1654 | topLeft.y = NSMaxY (parentRect) - yoff; |
| 1655 | else | ||
| 1656 | topLeft.y = NSMaxY ([[[NSScreen screens] objectAtIndex:0] frame]) - yoff; | ||
| 1674 | 1657 | ||
| 1675 | #ifdef NS_IMPL_GNUSTEP | 1658 | #ifdef NS_IMPL_GNUSTEP |
| 1676 | /* Don't overlap the menu. | 1659 | /* Don't overlap the menu. |
| 1677 | 1660 | ||
| 1678 | FIXME: Surely there's a better way than just hardcoding 100 | 1661 | FIXME: Surely there's a better way than just hardcoding 100 in |
| 1679 | in here? */ | 1662 | here? */ |
| 1680 | topLeft.x = 100; | 1663 | if (topLeft.x < 100) |
| 1664 | topLeft.x = 100; | ||
| 1681 | #endif | 1665 | #endif |
| 1682 | } | ||
| 1683 | 1666 | ||
| 1684 | NSTRACE_POINT ("setFrameTopLeftPoint", topLeft); | 1667 | NSTRACE_POINT ("setFrameTopLeftPoint", topLeft); |
| 1685 | [[view window] setFrameTopLeftPoint:topLeft]; | 1668 | [[view window] setFrameTopLeftPoint:topLeft]; |
| @@ -1702,40 +1685,34 @@ ns_set_window_size (struct frame *f, | |||
| 1702 | { | 1685 | { |
| 1703 | EmacsView *view = FRAME_NS_VIEW (f); | 1686 | EmacsView *view = FRAME_NS_VIEW (f); |
| 1704 | NSWindow *window = [view window]; | 1687 | NSWindow *window = [view window]; |
| 1705 | NSRect wr = [window frame]; | 1688 | NSRect frameRect; |
| 1706 | int orig_height = wr.size.height; | ||
| 1707 | 1689 | ||
| 1708 | NSTRACE ("ns_set_window_size"); | 1690 | NSTRACE ("ns_set_window_size"); |
| 1709 | 1691 | ||
| 1710 | if (view == nil) | 1692 | if (view == nil) |
| 1711 | return; | 1693 | return; |
| 1712 | 1694 | ||
| 1713 | NSTRACE_RECT ("current", wr); | 1695 | NSTRACE_RECT ("current", [window frame]); |
| 1714 | NSTRACE_MSG ("Width:%d Height:%d", width, height); | 1696 | NSTRACE_MSG ("Width:%d Height:%d", width, height); |
| 1715 | NSTRACE_MSG ("Font %d x %d", FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); | 1697 | NSTRACE_MSG ("Font %d x %d", FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); |
| 1716 | 1698 | ||
| 1717 | block_input (); | 1699 | block_input (); |
| 1718 | 1700 | ||
| 1719 | wr.size.width = width + f->border_width; | 1701 | frameRect = [window frameRectForContentRect:NSMakeRect (0, 0, width, height)]; |
| 1720 | wr.size.height = height; | 1702 | |
| 1721 | if (! [view isFullscreen]) | 1703 | /* Set the origin so the top left of the frame doesn't move. */ |
| 1722 | wr.size.height += FRAME_NS_TITLEBAR_HEIGHT (f) | 1704 | frameRect.origin = [window frame].origin; |
| 1723 | + FRAME_TOOLBAR_HEIGHT (f); | 1705 | frameRect.origin.y += NSHeight ([view frame]) - height; |
| 1724 | 1706 | ||
| 1725 | /* Do not try to constrain to this screen. We may have multiple | 1707 | if (f->output_data.ns->zooming) |
| 1726 | screens, and want Emacs to span those. Constraining to screen | 1708 | f->output_data.ns->zooming = 0; |
| 1727 | prevents that, and that is not nice to the user. */ | 1709 | |
| 1728 | if (f->output_data.ns->zooming) | 1710 | /* Usually it seems safe to delay changing the frame size, but when a |
| 1729 | f->output_data.ns->zooming = 0; | 1711 | series of actions are taken with no redisplay between them then we |
| 1730 | else | 1712 | can end up using old values so don't delay here. */ |
| 1731 | wr.origin.y += orig_height - wr.size.height; | 1713 | change_frame_size (f, width, height, false, NO, false); |
| 1732 | 1714 | ||
| 1733 | /* Usually it seems safe to delay changing the frame size, but when a | 1715 | [window setFrame:frameRect display:NO]; |
| 1734 | series of actions are taken with no redisplay between them then we | ||
| 1735 | can end up using old values so don't delay here. */ | ||
| 1736 | change_frame_size (f, width, height, false, NO, false); | ||
| 1737 | |||
| 1738 | [window setFrame:wr display:NO]; | ||
| 1739 | 1716 | ||
| 1740 | unblock_input (); | 1717 | unblock_input (); |
| 1741 | } | 1718 | } |