diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2019-04-10 16:24:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-10 16:24:28 +0300 |
commit | c86356ed4a456c7efca6e04256b69a01dc07f3ac (patch) | |
tree | f7b081d448c2cacf8a4465d2c9aacfb006c7b0ff | |
parent | 287aa8b1e30a075e39abdc20dc8fbe35f0acc5e8 (diff) | |
parent | f4e5a6b047667a908c0f1418dfe82578b157eb36 (diff) |
Merge pull request #543 from xamarin/backport-pr-542-to-release-8.0
[release-8.0] Fix issues around (re)storing the main IDE window position when hiding/showing it
4 files changed, 49 insertions, 17 deletions
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 7dfdbb217f..97a8063b12 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -622,16 +622,14 @@ namespace MonoDevelop.MacIntegration ApplicationEvents.Reopen += delegate (object sender, ApplicationEventArgs e) { if (Ide.WelcomePage.WelcomePageService.HasWindowImplementation && !(IdeApp.Workbench.RootWindow?.Visible ?? false)) { if (IdeApp.Workbench.RootWindow != null) { - IdeApp.Workbench.RootWindow.Visible = false; + IdeApp.Workbench.Hide (); } Ide.WelcomePage.WelcomePageService.ShowWelcomeWindow (new Ide.WelcomePage.WelcomeWindowShowOptions (true)); e.Handled = true; } else if (IdeApp.Workbench != null && IdeApp.Workbench.RootWindow != null) { IdeApp.Workbench.RootWindow.Deiconify (); - IdeApp.Workbench.RootWindow.Visible = true; - - IdeApp.Workbench.RootWindow.Present (); + IdeApp.Workbench.Present (); e.Handled = true; } }; @@ -765,7 +763,7 @@ namespace MonoDevelop.MacIntegration { args.RetVal = true; if (await IdeApp.Workspace.Close ()) { - IdeApp.Workbench.RootWindow.Visible = false; + IdeApp.Workbench.Hide (); } } 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; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs index 71b5ef3f78..e6adc00629 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs @@ -125,13 +125,13 @@ namespace MonoDevelop.Ide.Gui } } - internal void Realize (string workbenchMemento) + internal void Realize () { Counters.Initialization.Trace ("Realizing Root Window"); RootWindow.Realize (); Counters.Initialization.Trace ("Loading memento"); - var memento = PropertyService.Get (workbenchMemento, new Properties ()); + var memento = IdeApp.Preferences.WorkbenchMemento.Value; Counters.Initialization.Trace ("Setting memento"); workbench.Memento = memento; @@ -155,6 +155,10 @@ namespace MonoDevelop.Ide.Gui LayoutChanged (this, EventArgs.Empty); hasEverBeenShown = true; + } else if (!RootWindow.Visible) { + // restore memento if the root window has been hidden before + var memento = IdeApp.Preferences.WorkbenchMemento.Value; + workbench.Memento = memento; } } @@ -163,6 +167,18 @@ namespace MonoDevelop.Ide.Gui if (!RootWindow.Visible) Show (); } + + internal void Hide () + { + if (RootWindow.Visible) { + IdeApp.Preferences.WorkbenchMemento.Value = (Properties)workbench.Memento; + // FIXME: On mac the window can not be hidden while in fullscreen, we should unllscreen first and then hide + if (Platform.IsMac && DesktopService.GetIsFullscreen (RootWindow)) { + return; + } + RootWindow.Hide (); + } + } internal async Task<bool> Close () { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs index 72127a6068..90452e195c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs @@ -257,7 +257,7 @@ namespace MonoDevelop.Ide monitor.Step (1); Counters.Initialization.Trace ("Realizing Workbench Window"); - workbench.Realize ("SharpDevelop.Workbench.WorkbenchMemento"); + workbench.Realize (); monitor.Step (1); MessageService.RootWindow = workbench.RootWindow; |