From b3e099f4abd67ee8ad73cbb1689d9f2c93bc0efa Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Tue, 25 Feb 2020 02:28:02 +0200 Subject: [PATCH 1/5] * Source/NSScreen.m (screens): add initial description of new logic around screens (back, windows and menus) as comment. --- Source/NSScreen.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Source/NSScreen.m b/Source/NSScreen.m index 77850e7ba..c073635ca 100644 --- a/Source/NSScreen.m +++ b/Source/NSScreen.m @@ -73,6 +73,31 @@ static NSMutableArray *screenArray = nil; DESTROY(screenArray); } +/* + Display server's `screenList` method (back) returns `screens` array that + contains monitor list. If XRandR is supported, item at index 0 contains + monitor marked as "primary" (XRandR). Primary monitor can be set + programmatically or with `xrandr` utility. + + Apple documentation says that this method should return array of + NSScreen objects with "main screen" (screen where main menu resides) object + at index 0. In our implementation main menu follows key window. + Thus "main screen" (Apple) is not always "primary" (XRandR). + + It may have some advantages: in +screen mathod we know actually configured + "main screen" - XRandR's "primary" and we can determine Apples "main screen" + by asking main menu window for its screen. In this way we have (at least for x11 + with XRandR support) flexibility to decide at AppKit level wich is the true main + screen (main menu's or XRandR primary). + + Note that when key window crosses screens several events take place: + - screenArray resets ([NSScreen resetScreens] call from back); + - NSWindowDidChangeScreenNotification is sent (back); + - every NSWindow recalculates its coordiantes and screen is reassigned - retain + count to screen is decremented, finally old screenArray is deallocated; + - first call to [NSScreen screens] constructs new screenArray - "main menu" is + placed at index 0; +*/ /** * Returns an NSArray containing NSScreen instances representing all of the * screen devices attached to the computer. From f460e3f87540e4134c0c3f740034d86a4030a719 Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Wed, 26 Feb 2020 02:05:34 +0200 Subject: [PATCH 2/5] * Source/NSWindow.m (sendEvent:): removed usage of extra local variables in GSAppKitWindowMoved code block. --- ChangeLog | 5 +++++ Source/NSWindow.m | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd4d3c700..4e1c5a96e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-02-26 Sergii Stoian + + * Source/NSWindow.m (sendEvent:): removed usage of extra local variables + in GSAppKitWindowMoved code block. + 2020-02-23 Sergii Stoian * Source/NSWindow.m diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 77e4d46ac..de82b41c6 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -4175,12 +4175,10 @@ checkCursorRectanglesExited(NSView *theView, NSEvent *theEvent, NSPoint lastPoi { case GSAppKitWindowMoved: { - NSScreen *oldScreen; - NSScreen *newScreen; - oldScreen = _screen; + NSScreen *oldScreen = _screen; + _frame.origin.x = (CGFloat)[theEvent data1]; _frame.origin.y = (CGFloat)[theEvent data2]; - newScreen = [self screen]; NSDebugLLog(@"Moving", @"Move event: %d %@", (int)_windowNum, NSStringFromPoint(_frame.origin)); if (_autosaveName != nil) @@ -4189,7 +4187,7 @@ checkCursorRectanglesExited(NSView *theView, NSEvent *theEvent, NSPoint lastPoi } [nc postNotificationName: NSWindowDidMoveNotification object: self]; - if (newScreen != oldScreen) + if ([self screen] != oldScreen) { [nc postNotificationName: NSWindowDidChangeScreenNotification object: self]; From 96a3579e9802a8a048a31aba592f52b90cc28ea8 Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Thu, 5 Mar 2020 02:21:26 +0200 Subject: [PATCH 3/5] * Source/NSWindow.m (applicationDidChangeScreenParameters:): Call backend's `placewindow::` directly because our origin in OpenStep coordinates might left unchanged and `setFrame:display:` has check for it. --- ChangeLog | 7 +++++++ Source/NSWindow.m | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e06438212..7e52cce06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-03-05 Sergii Stoian + + * Source/NSWindow.m (applicationDidChangeScreenParameters:): + Call backend's `placewindow::` directly because our origin in OpenStep + coordinates might left unchanged and `setFrame:display:` has check + for it. + 2020-02-28 Sergii Stoian * Source/NSWindow.m (center): always center window on main screen - diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 4694ea15e..ffc780e56 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -2737,10 +2737,24 @@ titleWithRepresentedFilename(NSString *representedFilename) newFrame.origin.y += newScreenFrame.size.height - oldScreenFrame.size.height; // Screen X origin change. Screen width change shouldn't affect our frame. newFrame.origin.x += newScreenFrame.origin.x - oldScreenFrame.origin.x; - [self setFrame: newFrame display: NO]; - if (_autosaveName != nil) + + if (_windowNum) { - [self saveFrameUsingName: _autosaveName]; + /* Call backend's `placewindow::` directly because our origin in OpenStep + coordinates might left unchanged and `setFrame:display:` has check + for it. */ + [GSServerForWindow(self) placewindow: newFrame : _windowNum]; + if (_autosaveName != nil) + { + [self saveFrameUsingName: _autosaveName]; + } + [self display]; + } + else + { + _frame = newFrame; + newFrame.origin = NSZeroPoint; + [_wv setFrame: newFrame]; } } From 3f85f86f3bd9c044b20a244def0aab2b31020379 Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Thu, 5 Mar 2020 12:25:56 +0200 Subject: [PATCH 4/5] * Source/NSScreen.m: remove +screen comment - not ready yet. --- ChangeLog | 4 ++-- Source/NSScreen.m | 25 ------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e52cce06..9c7648125 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,8 +2,8 @@ * Source/NSWindow.m (applicationDidChangeScreenParameters:): Call backend's `placewindow::` directly because our origin in OpenStep - coordinates might left unchanged and `setFrame:display:` has check - for it. + coordinates might left unchanged and `setFrame:display:` has check + for it. 2020-02-28 Sergii Stoian diff --git a/Source/NSScreen.m b/Source/NSScreen.m index c073635ca..77850e7ba 100644 --- a/Source/NSScreen.m +++ b/Source/NSScreen.m @@ -73,31 +73,6 @@ static NSMutableArray *screenArray = nil; DESTROY(screenArray); } -/* - Display server's `screenList` method (back) returns `screens` array that - contains monitor list. If XRandR is supported, item at index 0 contains - monitor marked as "primary" (XRandR). Primary monitor can be set - programmatically or with `xrandr` utility. - - Apple documentation says that this method should return array of - NSScreen objects with "main screen" (screen where main menu resides) object - at index 0. In our implementation main menu follows key window. - Thus "main screen" (Apple) is not always "primary" (XRandR). - - It may have some advantages: in +screen mathod we know actually configured - "main screen" - XRandR's "primary" and we can determine Apples "main screen" - by asking main menu window for its screen. In this way we have (at least for x11 - with XRandR support) flexibility to decide at AppKit level wich is the true main - screen (main menu's or XRandR primary). - - Note that when key window crosses screens several events take place: - - screenArray resets ([NSScreen resetScreens] call from back); - - NSWindowDidChangeScreenNotification is sent (back); - - every NSWindow recalculates its coordiantes and screen is reassigned - retain - count to screen is decremented, finally old screenArray is deallocated; - - first call to [NSScreen screens] constructs new screenArray - "main menu" is - placed at index 0; -*/ /** * Returns an NSArray containing NSScreen instances representing all of the * screen devices attached to the computer. From a61aa9f68f9b1d5499b47cffb6738e5758614bdd Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Thu, 5 Mar 2020 23:27:31 +0200 Subject: [PATCH 5/5] * Source/NSWindow.m (_applyFrame:): new helper method to do actual resizing and repositionning. (setFrame:display:): use _applyFrame method. (applicationDidChangeScreenParameters:): use _applyFrame: method. --- ChangeLog | 10 ++++++---- Source/NSWindow.m | 49 +++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c7648125..89670be27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,11 @@ 2020-03-05 Sergii Stoian - * Source/NSWindow.m (applicationDidChangeScreenParameters:): - Call backend's `placewindow::` directly because our origin in OpenStep - coordinates might left unchanged and `setFrame:display:` has check - for it. + * Source/NSWindow.m (_applyFrame:): new helper method to do actual + resizing. + (setFrame:display:): use _applyFrame method. + (applicationDidChangeScreenParameters:): Use _applyFrame: because our + origin in OpenStep coordinates might be unchanged and `setFrame:display:` + has check for it. 2020-02-28 Sergii Stoian diff --git a/Source/NSWindow.m b/Source/NSWindow.m index ffc780e56..31335febd 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -2227,6 +2227,20 @@ titleWithRepresentedFilename(NSString *representedFilename) [self setFrame: r display: YES]; } +- (void) _applyFrame: (NSRect )frameRect +{ + if (_windowNum) + { + [GSServerForWindow(self) placewindow: frameRect : _windowNum]; + } + else + { + _frame = frameRect; + frameRect.origin = NSZeroPoint; + [_wv setFrame: frameRect]; + } +} + - (void) setFrame: (NSRect)frameRect display: (BOOL)flag { if (_maximumSize.width > 0 && frameRect.size.width > _maximumSize.width) @@ -2265,14 +2279,7 @@ titleWithRepresentedFilename(NSString *representedFilename) * Now we can tell the graphics context to do the actual resizing. * We will recieve an event to tell us when the resize is done. */ - if (_windowNum) - [GSServerForWindow(self) placewindow: frameRect : _windowNum]; - else - { - _frame = frameRect; - frameRect.origin = NSZeroPoint; - [_wv setFrame: frameRect]; - } + [self _applyFrame: frameRect]; if (flag) [self display]; @@ -2495,7 +2502,7 @@ titleWithRepresentedFilename(NSString *representedFilename) } - (void) update -{ +{ [nc postNotificationName: NSWindowDidUpdateNotification object: self]; } @@ -2738,23 +2745,15 @@ titleWithRepresentedFilename(NSString *representedFilename) // Screen X origin change. Screen width change shouldn't affect our frame. newFrame.origin.x += newScreenFrame.origin.x - oldScreenFrame.origin.x; - if (_windowNum) + /* Call backend's `placewindow::` directly because our origin in OpenStep + coordinates might be unchanged and `setFrame:display:` has check + for it. */ + [self _applyFrame: newFrame]; + [self display]; + + if (_autosaveName != nil) { - /* Call backend's `placewindow::` directly because our origin in OpenStep - coordinates might left unchanged and `setFrame:display:` has check - for it. */ - [GSServerForWindow(self) placewindow: newFrame : _windowNum]; - if (_autosaveName != nil) - { - [self saveFrameUsingName: _autosaveName]; - } - [self display]; - } - else - { - _frame = newFrame; - newFrame.origin = NSZeroPoint; - [_wv setFrame: newFrame]; + [self saveFrameUsingName: _autosaveName]; } }