aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Third2021-06-12 19:04:02 +0100
committerAlan Third2021-07-24 16:35:46 +0100
commit94b447098599cbf3f31fb26cebf12ef08f59bf62 (patch)
treea2e9d969f87418eaf8a43108d4636ff350d71b1e
parent6f4f66d0da005786b9d0fe8b47c43f14e8cd4d5e (diff)
downloademacs-94b447098599cbf3f31fb26cebf12ef08f59bf62.tar.gz
emacs-94b447098599cbf3f31fb26cebf12ef08f59bf62.zip
Move parent frame setting code into EmacsWindow
* src/nsterm.m (ns_make_frame_visible): (ns_set_parent_frame): ([EmacsWindow initWithEmacsFrame:fullscreen:screen:]): Use new method. ([EmacsWindow setParentChildRelationships]): New method.
-rw-r--r--src/nsterm.h1
-rw-r--r--src/nsterm.m186
2 files changed, 99 insertions, 88 deletions
diff --git a/src/nsterm.h b/src/nsterm.h
index 28155cdc0cb..b55dc53cc2c 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -418,6 +418,7 @@ typedef id instancetype;
418 418
419- (instancetype)initWithEmacsFrame:(struct frame *)f; 419- (instancetype)initWithEmacsFrame:(struct frame *)f;
420- (instancetype)initWithEmacsFrame:(struct frame *)f fullscreen:(BOOL)fullscreen screen:(NSScreen *)screen; 420- (instancetype)initWithEmacsFrame:(struct frame *)f fullscreen:(BOOL)fullscreen screen:(NSScreen *)screen;
421- (void)setParentChildRelationships;
421- (NSInteger)borderWidth; 422- (NSInteger)borderWidth;
422- (BOOL)restackWindow:(NSWindow *)win above:(BOOL)above; 423- (BOOL)restackWindow:(NSWindow *)win above:(BOOL)above;
423- (void)setAppearance; 424- (void)setAppearance;
diff --git a/src/nsterm.m b/src/nsterm.m
index 8aa8ff821fd..d721377c581 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1453,7 +1453,7 @@ ns_make_frame_visible (struct frame *f)
1453 if (!FRAME_VISIBLE_P (f)) 1453 if (!FRAME_VISIBLE_P (f))
1454 { 1454 {
1455 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); 1455 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1456 NSWindow *window = [view window]; 1456 EmacsWindow *window = (EmacsWindow *)[view window];
1457 1457
1458 SET_FRAME_VISIBLE (f, 1); 1458 SET_FRAME_VISIBLE (f, 1);
1459 ns_raise_frame (f, ! FRAME_NO_FOCUS_ON_MAP (f)); 1459 ns_raise_frame (f, ! FRAME_NO_FOCUS_ON_MAP (f));
@@ -1476,11 +1476,8 @@ ns_make_frame_visible (struct frame *f)
1476 relationship, so reinstate it. */ 1476 relationship, so reinstate it. */
1477 if ([window parentWindow] == nil && FRAME_PARENT_FRAME (f) != NULL) 1477 if ([window parentWindow] == nil && FRAME_PARENT_FRAME (f) != NULL)
1478 { 1478 {
1479 NSWindow *parent = [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window];
1480
1481 block_input (); 1479 block_input ();
1482 [parent addChildWindow: window 1480 [window setParentChildRelationships];
1483 ordered: NSWindowAbove];
1484 unblock_input (); 1481 unblock_input ();
1485 1482
1486 /* If the parent frame moved while the child frame was 1483 /* If the parent frame moved while the child frame was
@@ -1806,7 +1803,6 @@ ns_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_val
1806 -------------------------------------------------------------------------- */ 1803 -------------------------------------------------------------------------- */
1807{ 1804{
1808 struct frame *p = NULL; 1805 struct frame *p = NULL;
1809 NSWindow *parent, *child;
1810 1806
1811 NSTRACE ("ns_set_parent_frame"); 1807 NSTRACE ("ns_set_parent_frame");
1812 1808
@@ -1819,72 +1815,11 @@ ns_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_val
1819 error ("Invalid specification of `parent-frame'"); 1815 error ("Invalid specification of `parent-frame'");
1820 } 1816 }
1821 1817
1822 if (p != FRAME_PARENT_FRAME (f)) 1818 fset_parent_frame (f, new_value);
1823 {
1824 block_input ();
1825 child = [FRAME_NS_VIEW (f) window];
1826
1827#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
1828 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1829#endif
1830 1819
1831 if ([child parentWindow] != nil) 1820 block_input ();
1832 { 1821 [(EmacsWindow *)[FRAME_NS_VIEW (f) window] setParentChildRelationships];
1833#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 1822 unblock_input ();
1834 parent = [child parentWindow];
1835#endif
1836
1837 [[child parentWindow] removeChildWindow:child];
1838#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
1839#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
1840 if ([child respondsToSelector:@selector(setAccessibilitySubrole:)])
1841#endif
1842 [child setAccessibilitySubrole:NSAccessibilityStandardWindowSubrole];
1843#endif
1844#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
1845 if (NILP (new_value))
1846 {
1847 NSTRACE ("child setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary");
1848 [child setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
1849 // if current parent in fullscreen and no new parent make child fullscreen
1850 while (parent) {
1851 if (([parent styleMask] & NSWindowStyleMaskFullScreen) != 0)
1852 {
1853 [view toggleFullScreen:child];
1854 break;
1855 }
1856 // check all parents
1857 parent = [parent parentWindow];
1858 }
1859 }
1860#endif
1861 }
1862
1863 if (!NILP (new_value))
1864 {
1865#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
1866 // child frame must not be in fullscreen
1867 if ([view fsIsNative] && [view isFullscreen])
1868 [view toggleFullScreen:child];
1869 NSTRACE ("child setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary");
1870 [child setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
1871#endif
1872 parent = [FRAME_NS_VIEW (p) window];
1873
1874 [parent addChildWindow: child
1875 ordered: NSWindowAbove];
1876#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
1877#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
1878 if ([child respondsToSelector:@selector(setAccessibilitySubrole:)])
1879#endif
1880 [child setAccessibilitySubrole:NSAccessibilityFloatingWindowSubrole];
1881#endif
1882 }
1883
1884 unblock_input ();
1885
1886 fset_parent_frame (f, new_value);
1887 }
1888} 1823}
1889 1824
1890void 1825void
@@ -7594,7 +7529,7 @@ not_in_argv (NSString *arg)
7594 NSWindowCollectionBehavior b = [win collectionBehavior]; 7529 NSWindowCollectionBehavior b = [win collectionBehavior];
7595 if (ns_use_native_fullscreen) 7530 if (ns_use_native_fullscreen)
7596 { 7531 {
7597 if ([win parentWindow]) 7532 if (FRAME_PARENT_FRAME (emacsframe))
7598 { 7533 {
7599 b &= ~NSWindowCollectionBehaviorFullScreenPrimary; 7534 b &= ~NSWindowCollectionBehaviorFullScreenPrimary;
7600 b |= NSWindowCollectionBehaviorFullScreenAuxiliary; 7535 b |= NSWindowCollectionBehaviorFullScreenAuxiliary;
@@ -8356,22 +8291,7 @@ not_in_argv (NSString *arg)
8356 [self setTitlebarAppearsTransparent:FRAME_NS_TRANSPARENT_TITLEBAR (f)]; 8291 [self setTitlebarAppearsTransparent:FRAME_NS_TRANSPARENT_TITLEBAR (f)];
8357#endif 8292#endif
8358 8293
8359 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 8294 [self setParentChildRelationships];
8360#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
8361 if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
8362#endif
8363 if (FRAME_PARENT_FRAME (f))
8364 [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
8365 else
8366 [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
8367#endif
8368
8369 if (FRAME_PARENT_FRAME (f) != NULL)
8370 {
8371 NSWindow *parent = [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window];
8372 [parent addChildWindow:self
8373 ordered:NSWindowAbove];
8374 }
8375 8295
8376 if (FRAME_Z_GROUP (f) != z_group_none) 8296 if (FRAME_Z_GROUP (f) != z_group_none)
8377 [self setLevel:NSNormalWindowLevel + (FRAME_Z_GROUP_BELOW (f) ? -1 : 1)]; 8297 [self setLevel:NSNormalWindowLevel + (FRAME_Z_GROUP_BELOW (f) ? -1 : 1)];
@@ -8452,6 +8372,96 @@ not_in_argv (NSString *arg)
8452} 8372}
8453 8373
8454 8374
8375- (void)setParentChildRelationships
8376 /* After certain operations, for example making a frame visible or
8377 resetting the NSWindow through modifying the undecorated status,
8378 the parent/child relationship may be broken. We can also use
8379 this method to set them, as long as the frame struct already has
8380 the correct relationship set. */
8381{
8382 NSTRACE ("[EmacsWindow setParentChildRelationships]");
8383
8384 Lisp_Object frame, tail;
8385 EmacsView *ourView = (EmacsView *)[self delegate];
8386 struct frame *ourFrame = ourView->emacsframe;
8387 struct frame *parentFrame = FRAME_PARENT_FRAME (ourFrame);
8388 EmacsWindow *oldParentWindow = (EmacsWindow *)[self parentWindow];
8389
8390
8391#ifdef NS_IMPL_COCOA
8392 /* We have to set the accesibility subroles and/or the collection
8393 behaviors early otherwise child windows may not go fullscreen as
8394 expected later. */
8395
8396#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
8397 if ([child respondsToSelector:@selector(setAccessibilitySubrole:)])
8398#endif
8399 /* Set the accessibilty subroles. */
8400 if (parentFrame)
8401 [self setAccessibilitySubrole:NSAccessibilityFloatingWindowSubrole];
8402 else
8403 [self setAccessibilitySubrole:NSAccessibilityStandardWindowSubrole];
8404
8405#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
8406 [ourView updateCollectionBehavior];
8407#endif
8408#endif
8409
8410
8411 /* Check if we have an incorrectly set parent. */
8412 if ((! parentFrame && oldParentWindow)
8413 || (parentFrame && oldParentWindow
8414 && ((EmacsView *)[oldParentWindow delegate])->emacsframe != parentFrame))
8415 {
8416 [[self parentWindow] removeChildWindow:self];
8417
8418#ifdef NS_IMPL_COCOA
8419#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
8420 if ([ourView respondsToSelector:@selector (toggleFullScreen)]
8421#endif
8422 /* If we are the descendent of a fullscreen window and we
8423 have no new parent, go fullscreen. */
8424 {
8425 NSWindow *parent = (NSWindow *)oldParentWindow;
8426 while (parent)
8427 {
8428 if (([parent styleMask] & NSWindowStyleMaskFullScreen) != 0)
8429 {
8430 [ourView toggleFullScreen:self];
8431 break;
8432 }
8433 parent = [parent parentWindow];
8434 }
8435 }
8436#endif
8437 }
8438
8439 if (parentFrame)
8440 {
8441 NSWindow *parentWindow = [FRAME_NS_VIEW (parentFrame) window];
8442
8443#ifdef NS_IMPL_COCOA
8444#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
8445 if ([ourView respondsToSelector:@selector (toggleFullScreen)]
8446#endif
8447 /* Child frames must not be fullscreen. */
8448 if ([ourView fsIsNative] && [ourView isFullscreen])
8449 [ourView toggleFullScreen:self];
8450#endif
8451
8452 [parentWindow addChildWindow:self
8453 ordered:NSWindowAbove];
8454 }
8455
8456 /* Check our child windows are configured correctly. */
8457 FOR_EACH_FRAME (tail, frame)
8458 {
8459 if (FRAME_PARENT_FRAME (XFRAME (frame)) == ourFrame)
8460 [(EmacsWindow *)[FRAME_NS_VIEW (XFRAME (frame)) window] setParentChildRelationships];
8461 }
8462}
8463
8464
8455/* It seems the only way to reorder child frames is by removing them 8465/* It seems the only way to reorder child frames is by removing them
8456 from the parent and then reattaching them in the correct order. */ 8466 from the parent and then reattaching them in the correct order. */
8457 8467