diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2019-04-09 19:37:29 +0300 |
---|---|---|
committer | xamarin-jenkins <jo.shields+jenkins@xamarin.com> | 2019-04-09 19:47:25 +0300 |
commit | f4e5a6b047667a908c0f1418dfe82578b157eb36 (patch) | |
tree | 9dfa3c1bd8508d86844e9578b20d15e448e339a9 | |
parent | 29a5415dc0765bb2cd600a3e99bb925e0fbecaa4 (diff) |
[Ide] Verify final workbench bounds after showing the window
This is a workaround for a GTK bug on Mac, when the requested
bounds exceed the current screen bounds. Cocoa will adjust
the NSWindow size, but Gtk does not track it correctly, if
not resized manually.
Fixes VSTS #837468
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs index fada72120b..d547fa9259 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DefaultWorkbench.cs @@ -81,7 +81,7 @@ namespace MonoDevelop.Ide.Gui bool closeAll; bool? fullScreenState = null; - Rectangle normalBounds = new Rectangle(0, 0, MinimumWidth, MinimumHeight); + Rectangle requestedBounds = Rectangle.Empty; Gtk.Container rootWidget; CommandFrame toolbarFrame; @@ -216,9 +216,9 @@ namespace MonoDevelop.Ide.Gui { Title = BrandingService.ApplicationLongName; LoggingService.LogInfo ("Creating DefaultWorkbench"); - - WidthRequest = normalBounds.Width; - HeightRequest = normalBounds.Height; + + WidthRequest = MinimumWidth; + HeightRequest = MinimumHeight; DeleteEvent += new Gtk.DeleteEventHandler (OnClosing); BrandingService.ApplicationNameChanged += ApplicationNameChanged; @@ -663,7 +663,7 @@ namespace MonoDevelop.Ide.Gui if (GdkWindow.State == 0 || Platform.IsMac) { memento.Bounds = new Rectangle (x, y, width, height); } else { - memento.Bounds = normalBounds; + memento.Bounds = requestedBounds; } memento.WindowState = GdkWindow.State; memento.FullScreen = FullScreen; @@ -673,8 +673,12 @@ namespace MonoDevelop.Ide.Gui if (value != null) { WorkbenchMemento memento = new WorkbenchMemento ((Properties)value); - normalBounds = memento.Bounds; - DesktopService.PlaceWindow (this, normalBounds.X, normalBounds.Y, normalBounds.Width, normalBounds.Height); + requestedBounds = memento.Bounds; + if (requestedBounds.Width < MinimumWidth) + requestedBounds.Width = MinimumWidth; + if (requestedBounds.Height < MinimumHeight) + requestedBounds.Height = MinimumHeight; + DesktopService.PlaceWindow (this, requestedBounds.X, requestedBounds.Y, requestedBounds.Width, requestedBounds.Height); // HACK: don't restore Gdk.WindowState.Maximized on OS X, because there's a bug in // GdkWindow.State that means it doesn't reflect the real state, it only reflects values set @@ -754,10 +758,24 @@ namespace MonoDevelop.Ide.Gui protected override void OnShown () { base.OnShown (); - if (fullScreenState != null && fullScreenState != DesktopService.GetIsFullscreen (this)) { - DesktopService.SetIsFullscreen (this, (bool) fullScreenState); + bool isFullscreen = DesktopService.GetIsFullscreen (this); + if (fullScreenState != null && fullScreenState != isFullscreen) { + isFullscreen = (bool)fullScreenState; + DesktopService.SetIsFullscreen (this, isFullscreen); fullScreenState = null; } + if (Platform.IsMac && !isFullscreen) { + // HACK: GTK bug, macOS will limit the NSWindow size to the target screen size + // even if a bigger size has been requested. However although Gtk and Cocoa + // will report the limited size correctly, Gtk will still continue using + // the requested (invalid) size internally, resulting a pointer event offset + // by the difference of current and requested sizes. Resizing the Gtk window + // to the current new size, solves this problem. + // NOTE: this bug does not occur in fillscreen mode + GetSize (out int width, out int height); + if (requestedBounds.Width > width || requestedBounds.Height > height) + Resize (width, height); + } } bool closing; |