[FancyZones] Open window on active monitor (#4361)

* Initial design for opening window on active monitor

* Perform entire handling in DPI unaware thread

* Codestyle improvement

* Improve resizing mechanism and optimise code a bit

* Remove unneeded code, make simple helper functions inline

* Make this feature configurable

* Code optimization, improve positioning for some applications

* Retry positioning for certain applications

* Improve readability

* Address PR comments: Minor code style improvements

* Remove retries in custom positioning

* Position new toggle in settings menu
This commit is contained in:
vldmr11080
2020-07-08 10:37:42 +02:00
committed by GitHub
parent 94f66b812a
commit db229cf1bf
12 changed files with 170 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.FancyzonesDisplayChangeMoveWindows = new BoolProperty();
this.FancyzonesZoneSetChangeMoveWindows = new BoolProperty();
this.FancyzonesAppLastZoneMoveWindows = new BoolProperty();
this.FancyzonesOpenWindowOnActiveMonitor = new BoolProperty();
this.FancyzonesRestoreSize = new BoolProperty();
this.UseCursorposEditorStartupscreen = new BoolProperty(ConfigDefaults.DefaultUseCursorposEditorStartupscreen);
this.FancyzonesShowOnAllMonitors = new BoolProperty();
@@ -59,6 +60,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
[JsonPropertyName("fancyzones_appLastZone_moveWindows")]
public BoolProperty FancyzonesAppLastZoneMoveWindows { get; set; }
[JsonPropertyName("fancyzones_openWindowOnActiveMonitor")]
public BoolProperty FancyzonesOpenWindowOnActiveMonitor { get; set; }
[JsonPropertyName("fancyzones_restoreSize")]
public BoolProperty FancyzonesRestoreSize { get; set; }

View File

@@ -311,6 +311,9 @@
<data name="FancyZones_AppLastZoneMoveWindows.Content" xml:space="preserve">
<value>Move newly created windows to their last known zone</value>
</data>
<data name="FancyZones_OpenWindowOnActiveMonitor.Content" xml:space="preserve">
<value>Move newly created windows to the current active monitor</value>
</data>
<data name="FancyZones_UseCursorPosEditorStartupScreen.Content" xml:space="preserve">
<value>Follow mouse cursor instead of focus when launching editor in a multi screen environment</value>
</data>

View File

@@ -44,6 +44,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
this._displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
this._zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
this._appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
this._openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
this._restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
this._showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
@@ -83,6 +84,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _displayChangemoveWindows;
private bool _zoneSetChangeMoveWindows;
private bool _appLastZoneMoveWindows;
private bool _openWindowOnActiveMonitor;
private bool _restoreSize;
private bool _useCursorPosEditorStartupScreen;
private bool _showOnAllMonitors;
@@ -243,6 +245,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool OpenWindowOnActiveMonitor
{
get
{
return _openWindowOnActiveMonitor;
}
set
{
if (value != _openWindowOnActiveMonitor)
{
_openWindowOnActiveMonitor = value;
Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value = value;
RaisePropertyChanged();
}
}
}
public bool RestoreSize
{
get

View File

@@ -133,6 +133,11 @@
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"/>
<CheckBox x:Uid="FancyZones_OpenWindowOnActiveMonitor"
IsChecked="{ Binding Mode=TwoWay, Path=OpenWindowOnActiveMonitor}"
Margin="{StaticResource SmallTopMargin}"
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled}"/>
<CheckBox x:Uid="FancyZones_RestoreSize"
IsChecked="{ Binding Mode=TwoWay, Path=RestoreSize}"
Margin="{StaticResource SmallTopMargin}"

View File

@@ -194,6 +194,23 @@ namespace ViewModelTests
viewModel.AppLastZoneMoveWindows = true;
}
public void OpenWindowOnActiveMonitor_ShouldSetValue2True_WhenSuccessful()
{
// arrange
FancyZonesViewModel viewModel = new FancyZonesViewModel();
Assert.IsFalse(viewModel.OpenWindowOnActiveMonitor); // check if value was initialized to false.
// Assert
ShellPage.DefaultSndMSGCallback = msg =>
{
FancyZonesSettingsIPCMessage snd = JsonSerializer.Deserialize<FancyZonesSettingsIPCMessage>(msg);
Assert.IsTrue(snd.Powertoys.FancyZones.Properties.FancyzonesOpenWindowOnActiveMonitor.Value);
};
// act
viewModel.OpenWindowOnActiveMonitor = true;
}
[TestMethod]
public void RestoreSize_ShouldSetValue2True_WhenSuccessful()
{