* Source/NSWindow.m (sendEvent:): set current screen to ivar and

send WindowDidChangeScreen notification if window was moved to other
  screen.

* Source/NSScreen.m (mainScreen): returns screen of main menu if no
  key window exists. With this implementation default screen (screen at
  index 0 in screens array) should never be returned.

* Source/NSMenu.m (initWithTitle:): observe WindowDidBecomeKey and
  WindowDidChangeScreen notifications.
  (windowDidChangeScreen:): new method to handle observed notification
  added above. Moves menu to screen of key window for both cases: when
  key window moved to or activated on different screen.
This commit is contained in:
Sergii Stoian 2020-02-12 01:46:17 +02:00
parent b4ca06582e
commit 2a1b9d4d54
4 changed files with 71 additions and 0 deletions

View file

@ -1,3 +1,19 @@
2020-02-12 Sergii Stoian <stoyan255@gmail.com>
* Source/NSWindow.m (sendEvent:): set current screen to ivar and
send WindowDidChangeScreen notification if window was moved to other
screen.
* Source/NSScreen.m (mainScreen): returns screen of main menu if no
key window exists. With this implementation default screen (screen at
index 0 in screens array) should never be returned.
* Source/NSMenu.m (initWithTitle:): observe WindowDidBecomeKey and
WindowDidChangeScreen notifications.
(windowDidChangeScreen:): new method to handle observed notification
added above. Moves menu to screen of key window for both cases: when
key window moved to or activated on different screen.
2020-02-09 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSFontDescriptor.m: Correct key for encoding and decoding.

View file

@ -712,6 +712,15 @@ static BOOL menuBarVisible = YES;
name: NSEnqueuedMenuMoveName
object: self];
[nc addObserver: self
selector: @selector(windowDidChangeScreen:)
name: NSWindowDidBecomeKeyNotification
object: nil];
[nc addObserver: self
selector: @selector(windowDidChangeScreen:)
name: NSWindowDidChangeScreenNotification
object: nil];
return self;
}
@ -1860,6 +1869,36 @@ static BOOL menuBarVisible = YES;
}
}
- (void) windowDidChangeScreen: (NSNotification*)notification
{
NSWindow *window = [notification object];
NSRect frame;
NSRect oldScreenFrame;
NSRect newScreenFrame;
NSPoint offset;
if (window == _aWindow
|| [window isKeyWindow] == NO
|| [_aWindow screen] == [window screen]
|| [_aWindow isVisible] == NO)
return;
oldScreenFrame = [[_aWindow screen] frame];
newScreenFrame = [[window screen] frame];
frame = [_aWindow frame];
// Keep left offset fixed
offset.x = frame.origin.x - oldScreenFrame.origin.x;
frame.origin.x = newScreenFrame.origin.x + offset.x;
// Keep top offset fixed
offset.y = NSMaxY(oldScreenFrame) - NSMaxY(frame);
frame.origin.y = NSMaxY(newScreenFrame) - offset.y - frame.size.height;
// setFrame: changes _screen value.
[_aWindow setFrame: frame display: NO];
}
- (BOOL) isTransient
{
return _menu.transient;

View file

@ -122,6 +122,11 @@ static NSMutableArray *screenArray = nil;
NSWindow *keyWindow;
keyWindow = [NSApp keyWindow];
if (keyWindow == nil)
{
keyWindow = [[NSApp mainMenu] window];
}
if (keyWindow != nil)
{
return [keyWindow screen];

View file

@ -4180,6 +4180,17 @@ checkCursorRectanglesExited(NSView *theView, NSEvent *theEvent, NSPoint lastPoi
}
[nc postNotificationName: NSWindowDidMoveNotification
object: self];
// Check if window moved to an other screen
{
NSScreen *newScreen = [self _screenForFrame: _frame];
if (newScreen != _screen)
{
ASSIGN(_screen, newScreen);
[nc postNotificationName: NSWindowDidChangeScreenNotification
object: self];
}
}
break;
case GSAppKitWindowResized: