[FancyZones] Restore size of zoned windows (#4463)

* Started work

* I can't debug anything, cleaning

* Added settings, [[Not Tested]]

Not even compiled

* Tested, the most basic features work

* Refactor, add RestoreSize

* Added DPI awareness

* Fixed a potential issue with resizing zoned windows

* Fixup: Potentially unsafe memory-layout of std::pair replaced with std::array

* Fixup: Use .data() instead of a pointer

* Further refactoring

* Integrated Win+Arrow keys with the Restore size feature

* Fixed an issue where window's on-screen position is not restored properly

* Fixed a bug pointed out by Enrico
This commit is contained in:
Ivan Stošić 2020-07-01 15:36:05 +02:00 committed by GitHub
parent 16528888df
commit 4c08b591f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 235 additions and 25 deletions

View File

@ -46,8 +46,24 @@ namespace DPIAware
UINT dpi_x, dpi_y;
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
{
width = width * dpi_x / DEFAULT_DPI;
height = height * dpi_y / DEFAULT_DPI;
width = width * static_cast<int>(dpi_x) / DEFAULT_DPI;
height = height * static_cast<int>(dpi_y) / DEFAULT_DPI;
}
}
void InverseConvert(HMONITOR monitor_handle, int& width, int& height)
{
if (monitor_handle == NULL)
{
const POINT ptZero = { 0, 0 };
monitor_handle = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
}
UINT dpi_x, dpi_y;
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
{
width = width * DEFAULT_DPI / static_cast<int>(dpi_x);
height = height * DEFAULT_DPI / static_cast<int>(dpi_y);
}
}

View File

@ -8,6 +8,7 @@ namespace DPIAware
HRESULT GetScreenDPIForWindow(HWND hwnd, UINT& dpi_x, UINT& dpi_y);
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi_x, UINT& dpi_y);
void Convert(HMONITOR monitor_handle, int& width, int& height);
void InverseConvert(HMONITOR monitor_handle, int& width, int& height);
void EnableDPIAwarenessForThisProcess();
enum AwarenessLevel

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.FancyzonesRestoreSize = new BoolProperty();
this.UseCursorposEditorStartupscreen = new BoolProperty(ConfigDefaults.DefaultUseCursorposEditorStartupscreen);
this.FancyzonesShowOnAllMonitors = new BoolProperty();
this.FancyzonesZoneHighlightColor = new StringProperty(ConfigDefaults.DefaultFancyZonesZoneHighlightColor);
@ -58,6 +59,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
[JsonPropertyName("fancyzones_appLastZone_moveWindows")]
public BoolProperty FancyzonesAppLastZoneMoveWindows { get; set; }
[JsonPropertyName("fancyzones_restoreSize")]
public BoolProperty FancyzonesRestoreSize { get; set; }
[JsonPropertyName("use_cursorpos_editor_startupscreen")]
public BoolProperty UseCursorposEditorStartupscreen { get; set; }

View File

@ -599,4 +599,7 @@
<data name="FancyZones_HotkeyEditorControl_TextBox.ToolTipService.ToolTip" xml:space="preserve">
<value>Only shortcuts with the following hotkeys are valid: Win, Ctrl, Alt, Shift.</value>
</data>
<data name="FancyZones_RestoreSize.Content" xml:space="preserve">
<value>Restore the original size of windows when unsnapping</value>
</data>
</root>

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._restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
this._showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
this._makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
@ -82,6 +83,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _displayChangemoveWindows;
private bool _zoneSetChangeMoveWindows;
private bool _appLastZoneMoveWindows;
private bool _restoreSize;
private bool _useCursorPosEditorStartupScreen;
private bool _showOnAllMonitors;
private bool _makeDraggedWindowTransparent;
@ -241,6 +243,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool RestoreSize
{
get
{
return _restoreSize;
}
set
{
if (value != _restoreSize)
{
_restoreSize = value;
Settings.Properties.FancyzonesRestoreSize.Value = value;
RaisePropertyChanged();
}
}
}
public bool UseCursorPosEditorStartupScreen
{
get

View File

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

View File

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

View File

@ -937,7 +937,20 @@ bool FancyZones::OnSnapHotkey(DWORD vkCode) noexcept
{
// Single monitor environment.
std::unique_lock writeLock(m_lock);
return m_windowMoveHandler.MoveWindowIntoZoneByDirection(window, vkCode, true /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
if (m_settings->GetSettings()->restoreSize)
{
bool moved = m_windowMoveHandler.MoveWindowIntoZoneByDirection(window, vkCode, false /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
if (!moved)
{
RestoreWindowOrigin(window);
RestoreWindowSize(window);
}
return true;
}
else
{
return m_windowMoveHandler.MoveWindowIntoZoneByDirection(window, vkCode, true /* cycle through zones */, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
}
}
}
}

View File

@ -36,7 +36,7 @@ private:
PCWSTR name;
bool* value;
int resourceId;
} m_configBools[10 /* 11 */] = { // "Turning FLASHING_ZONE option off"
} m_configBools[11 /* 12 */] = { // "Turning FLASHING_ZONE option off"
{ L"fancyzones_shiftDrag", &m_settings.shiftDrag, IDS_SETTING_DESCRIPTION_SHIFTDRAG },
{ L"fancyzones_mouseSwitch", &m_settings.mouseSwitch, IDS_SETTING_DESCRIPTION_MOUSESWITCH },
{ L"fancyzones_overrideSnapHotkeys", &m_settings.overrideSnapHotkeys, IDS_SETTING_DESCRIPTION_OVERRIDE_SNAP_HOTKEYS },
@ -46,6 +46,7 @@ private:
{ L"fancyzones_displayChange_moveWindows", &m_settings.displayChange_moveWindows, IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS },
{ L"fancyzones_zoneSetChange_moveWindows", &m_settings.zoneSetChange_moveWindows, IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS },
{ L"fancyzones_appLastZone_moveWindows", &m_settings.appLastZone_moveWindows, IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS },
{ L"fancyzones_restoreSize", &m_settings.restoreSize, IDS_SETTING_DESCRIPTION_RESTORESIZE },
{ L"use_cursorpos_editor_startupscreen", &m_settings.use_cursorpos_editor_startupscreen, IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN },
{ L"fancyzones_show_on_all_monitors", &m_settings.showZonesOnAllMonitors, IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS},
{ L"fancyzones_makeDraggedWindowTransparent", &m_settings.makeDraggedWindowTransparent, IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT},

View File

@ -1,6 +1,8 @@
#pragma once
#define MULTI_ZONE_STAMP L"FancyZones_zones"
#define RESTORE_SIZE_STAMP L"FancyZones_RestoreSize"
#define RESTORE_ORIGIN_STAMP L"FancyZones_RestoreOrigin"
#include <common/settings_objects.h>
struct Settings
@ -14,6 +16,7 @@ struct Settings
bool overrideSnapHotkeys = false;
bool moveWindowAcrossMonitors = false;
bool appLastZone_moveWindows = false;
bool restoreSize = false;
bool use_cursorpos_editor_startupscreen = true;
bool showZonesOnAllMonitors = false;
bool makeDraggedWindowTransparent = true;

View File

@ -4,6 +4,7 @@
#include <common/notifications.h>
#include <common/notifications/fancyzones_notifications.h>
#include <common/window_helpers.h>
#include <common/dpi_aware.h>
#include "lib/Settings.h"
#include "lib/ZoneWindow.h"
@ -297,6 +298,18 @@ void WindowMoveHandlerPrivate::MoveSizeEnd(HWND window, POINT const& ptScreen, c
{
::RemoveProp(window, MULTI_ZONE_STAMP);
if (m_settings->GetSettings()->restoreSize)
{
if (WindowMoveHandlerUtils::IsCursorTypeIndicatingSizeEvent())
{
::RemoveProp(window, RESTORE_SIZE_STAMP);
}
else
{
RestoreWindowSize(window);
}
}
auto monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
if (monitor)
{

View File

@ -303,6 +303,7 @@ ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND windowZone, const std::v
if (!sizeEmpty)
{
SaveWindowSizeAndOrigin(window);
SizeWindowToRect(window, size);
StampWindow(window, bitmask);
}
@ -700,3 +701,4 @@ winrt::com_ptr<IZoneSet> MakeZoneSet(ZoneSetConfig const& config) noexcept
{
return winrt::make_self<ZoneSet>(config);
}

View File

@ -19,6 +19,7 @@ BEGIN
IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR "Zone highlight color (Default #008CFF)"
IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN "Follow mouse cursor instead of focus when launching editor in a multi screen environment"
IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS "Move newly created windows to their last known zone"
IDS_SETTING_DESCRIPTION_RESTORESIZE "Restore the original size of windows when unsnapping"
IDS_SETTING_LAUNCH_EDITOR_LABEL "Zone configuration"
IDS_SETTING_LAUNCH_EDITOR_BUTTON "Edit zones"
IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION "To launch the zone editor, select the Edit zones button below or press the zone editor hotkey anytime"

View File

@ -25,15 +25,16 @@
#define IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR 111
#define IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR 112
#define IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS 113
#define IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN 114
#define IDS_SETTING_DESCRIPTION 115
#define IDS_SETTING_LAUNCH_EDITOR_LABEL 116
#define IDS_SETTING_LAUNCH_EDITOR_BUTTON 117
#define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 118
#define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 119
#define IDS_SETTING_EXCLUDED_APPS_DESCRIPTION 120
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 121
#define IDS_FANCYZONES 122
#define IDS_CANT_DRAG_ELEVATED 123
#define IDS_CANT_DRAG_ELEVATED_LEARN_MORE 124
#define IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN 125
#define IDS_SETTING_DESCRIPTION_RESTORESIZE 114
#define IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN 115
#define IDS_SETTING_DESCRIPTION 116
#define IDS_SETTING_LAUNCH_EDITOR_LABEL 117
#define IDS_SETTING_LAUNCH_EDITOR_BUTTON 118
#define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 119
#define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 120
#define IDS_SETTING_EXCLUDED_APPS_DESCRIPTION 121
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 122
#define IDS_FANCYZONES 123
#define IDS_CANT_DRAG_ELEVATED 124
#define IDS_CANT_DRAG_ELEVATED_LEARN_MORE 125
#define IDS_CANT_DRAG_ELEVATED_DIALOG_DONT_SHOW_AGAIN 126

View File

@ -184,6 +184,7 @@ void Trace::SettingsChanged(const Settings& settings) noexcept
TraceLoggingBoolean(settings.overrideSnapHotkeys, "OverrideSnapHotKeys"),
TraceLoggingBoolean(settings.moveWindowAcrossMonitors, "MoveWindowAcrossMonitors"),
TraceLoggingBoolean(settings.appLastZone_moveWindows, "MoveWindowsToLastZoneOnAppOpening"),
TraceLoggingBoolean(settings.restoreSize, "RestoreSize"),
TraceLoggingBoolean(settings.use_cursorpos_editor_startupscreen, "UseCursorPosOnEditorStartup"),
TraceLoggingBoolean(settings.showZonesOnAllMonitors, "ShowZonesOnAllMonitors"),
TraceLoggingBoolean(settings.makeDraggedWindowTransparent, "MakeDraggedWindowTransparent"),

View File

@ -1,5 +1,6 @@
#include "pch.h"
#include "util.h"
#include "Settings.h"
#include <common/common.h>
#include <common/dpi_aware.h>
@ -173,3 +174,84 @@ bool IsInterestingWindow(HWND window, const std::vector<std::wstring>& excludedA
}
return true;
}
void SaveWindowSizeAndOrigin(HWND window) noexcept
{
HANDLE handle = GetPropW(window, RESTORE_SIZE_STAMP);
if (handle)
{
// Size already set, skip
return;
}
RECT rect;
if (GetWindowRect(window, &rect))
{
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
int originX = rect.left;
int originY = rect.top;
DPIAware::InverseConvert(MonitorFromWindow(window, MONITOR_DEFAULTTONULL), width, height);
DPIAware::InverseConvert(MonitorFromWindow(window, MONITOR_DEFAULTTONULL), originX, originY);
std::array<int, 2> windowSizeData = { width, height };
std::array<int, 2> windowOriginData = { originX, originY };
HANDLE rawData;
memcpy(&rawData, windowSizeData.data(), sizeof rawData);
SetPropW(window, RESTORE_SIZE_STAMP, rawData);
memcpy(&rawData, windowOriginData.data(), sizeof rawData);
SetPropW(window, RESTORE_ORIGIN_STAMP, rawData);
}
}
void RestoreWindowSize(HWND window) noexcept
{
auto windowSizeData = GetPropW(window, RESTORE_SIZE_STAMP);
if (windowSizeData)
{
std::array<int, 2> windowSize;
memcpy(windowSize.data(), &windowSizeData, sizeof windowSize);
// {width, height}
DPIAware::Convert(MonitorFromWindow(window, MONITOR_DEFAULTTONULL), windowSize[0], windowSize[1]);
RECT rect;
if (GetWindowRect(window, &rect))
{
rect.right = rect.left + windowSize[0];
rect.bottom = rect.top + windowSize[1];
SizeWindowToRect(window, rect);
}
::RemoveProp(window, RESTORE_SIZE_STAMP);
}
}
void RestoreWindowOrigin(HWND window) noexcept
{
auto windowOriginData = GetPropW(window, RESTORE_ORIGIN_STAMP);
if (windowOriginData)
{
std::array<int, 2> windowOrigin;
memcpy(windowOrigin.data(), &windowOriginData, sizeof windowOrigin);
// {width, height}
DPIAware::Convert(MonitorFromWindow(window, MONITOR_DEFAULTTONULL), windowOrigin[0], windowOrigin[1]);
RECT rect;
if (GetWindowRect(window, &rect))
{
int xOffset = windowOrigin[0] - rect.left;
int yOffset = windowOrigin[1] - rect.top;
rect.left += xOffset;
rect.right += xOffset;
rect.top += yOffset;
rect.bottom += yOffset;
SizeWindowToRect(window, rect);
}
::RemoveProp(window, RESTORE_ORIGIN_STAMP);
}
}

View File

@ -120,4 +120,7 @@ UINT GetDpiForMonitor(HMONITOR monitor) noexcept;
void OrderMonitors(std::vector<std::pair<HMONITOR, RECT>>& monitorInfo);
void SizeWindowToRect(HWND window, RECT rect) noexcept;
bool IsInterestingWindow(HWND window, const std::vector<std::wstring>& excludedApps) noexcept;
bool IsInterestingWindow(HWND window, const std::vector<std::wstring>& excludedApps) noexcept;
void SaveWindowSizeAndOrigin(HWND window) noexcept;
void RestoreWindowSize(HWND window) noexcept;
void RestoreWindowOrigin(HWND window) noexcept;

View File

@ -74,6 +74,7 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toggle(L"fancyzones_displayChange_moveWindows", IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS, settings.displayChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_zoneSetChange_moveWindows", IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS, settings.zoneSetChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_restoreSize", IDS_SETTING_DESCRIPTION_RESTORESIZE, settings.restoreSize);
ptSettings.add_bool_toggle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toggle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toggle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);
@ -119,6 +120,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.zoneColor = L"#abafee",
.zoneBorderColor = L"FAFAFA",
@ -148,6 +150,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"#abafee",
@ -177,6 +180,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
@ -208,6 +212,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
@ -239,6 +244,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
@ -280,6 +286,7 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toggle(L"fancyzones_displayChange_moveWindows", IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS, settings.displayChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_zoneSetChange_moveWindows", IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS, settings.zoneSetChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_restoreSize", IDS_SETTING_DESCRIPTION_RESTORESIZE, settings.restoreSize);
ptSettings.add_bool_toggle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toggle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toggle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);

View File

@ -34,6 +34,7 @@ namespace FancyZonesUnitTests
Assert::AreEqual(expected.overrideSnapHotkeys, actual.overrideSnapHotkeys);
Assert::AreEqual(expected.moveWindowAcrossMonitors, actual.moveWindowAcrossMonitors);
Assert::AreEqual(expected.appLastZone_moveWindows, actual.appLastZone_moveWindows);
Assert::AreEqual(expected.restoreSize, actual.restoreSize);
Assert::AreEqual(expected.use_cursorpos_editor_startupscreen, actual.use_cursorpos_editor_startupscreen);
Assert::AreEqual(expected.showZonesOnAllMonitors, actual.showZonesOnAllMonitors);
Assert::AreEqual(expected.makeDraggedWindowTransparent, actual.makeDraggedWindowTransparent);
@ -111,6 +112,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -147,6 +149,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -177,6 +180,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = m_defaultSettings.overrideSnapHotkeys,
.moveWindowAcrossMonitors = m_defaultSettings.moveWindowAcrossMonitors,
.appLastZone_moveWindows = m_defaultSettings.appLastZone_moveWindows,
.restoreSize = m_defaultSettings.restoreSize,
.use_cursorpos_editor_startupscreen = m_defaultSettings.use_cursorpos_editor_startupscreen,
.showZonesOnAllMonitors = m_defaultSettings.showZonesOnAllMonitors,
.makeDraggedWindowTransparent = m_defaultSettings.makeDraggedWindowTransparent,
@ -220,6 +224,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -250,6 +255,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -281,6 +287,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -313,6 +320,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -426,6 +434,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = false,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
@ -447,6 +456,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
@ -563,6 +573,7 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toggle(L"fancyzones_displayChange_moveWindows", IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS, settings.displayChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_zoneSetChange_moveWindows", IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS, settings.zoneSetChange_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toggle(L"fancyzones_restoreSize", IDS_SETTING_DESCRIPTION_RESTORESIZE, settings.restoreSize);
ptSettings.add_bool_toggle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toggle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toggle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);
@ -591,6 +602,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_overrideSnapHotkeys", expected.overrideSnapHotkeys);
values.add_property(L"fancyzones_moveWindowAcrossMonitors", expected.moveWindowAcrossMonitors);
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"fancyzones_restoreSize", expected.restoreSize);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHighlightColor);
@ -626,6 +638,7 @@ namespace FancyZonesUnitTests
m_ptSettings->add_bool_toggle(L"fancyzones_displayChange_moveWindows", IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS, expected.displayChange_moveWindows);
m_ptSettings->add_bool_toggle(L"fancyzones_zoneSetChange_moveWindows", IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS, expected.zoneSetChange_moveWindows);
m_ptSettings->add_bool_toggle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, expected.appLastZone_moveWindows);
m_ptSettings->add_bool_toggle(L"fancyzones_restoreSize", IDS_SETTING_DESCRIPTION_RESTORESIZE, expected.restoreSize);
m_ptSettings->add_bool_toggle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, expected.use_cursorpos_editor_startupscreen);
m_ptSettings->add_bool_toggle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, expected.showZonesOnAllMonitors);
m_ptSettings->add_bool_toggle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, expected.makeDraggedWindowTransparent);
@ -694,6 +707,7 @@ namespace FancyZonesUnitTests
.overrideSnapHotkeys = false,
.moveWindowAcrossMonitors = false,
.appLastZone_moveWindows = true,
.restoreSize = false,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,

View File

@ -309,7 +309,8 @@ namespace PowerToysTests
Assert.AreNotEqual(toggleValues[3], GetPropertyValue<bool>(savedProps, "fancyzones_moveWindowAcrossMonitors"));
Assert.AreNotEqual(toggleValues[4], GetPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
Assert.AreNotEqual(toggleValues[5], GetPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
Assert.AreNotEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
Assert.AreNotEqual(toggleValues[6], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
Assert.AreNotEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_restoreSize"));
Assert.AreNotEqual(toggleValues[8], GetPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
Assert.AreNotEqual(toggleValues[9], GetPropertyValue<bool>(savedProps, "fancyzones_show_on_all_monitors"));
Assert.AreNotEqual(toggleValues[10], GetPropertyValue<bool>(savedProps, "fancyzones_makeDraggedWindowTransparent"));
@ -348,7 +349,8 @@ namespace PowerToysTests
Assert.AreEqual(toggleValues[3], GetPropertyValue<bool>(savedProps, "fancyzones_moveWindowAcrossMonitors"));
Assert.AreEqual(toggleValues[4], GetPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
Assert.AreEqual(toggleValues[5], GetPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
Assert.AreEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
Assert.AreEqual(toggleValues[6], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
Assert.AreEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_restoreSize"));
Assert.AreEqual(toggleValues[8], GetPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
Assert.AreEqual(toggleValues[9], GetPropertyValue<bool>(savedProps, "fancyzones_show_on_all_monitors"));
Assert.AreEqual(toggleValues[10], GetPropertyValue<bool>(savedProps, "fancyzones_makeDraggedWindowTransparent"));

View File

@ -14,13 +14,13 @@ namespace PowerToysTests
{
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
protected const string AppPath = "C:\\Program Files\\PowerToys\\PowerToys.exe";
protected static WindowsDriver<WindowsElement> session;
protected static bool isPowerToysLaunched = false;
protected static WindowsElement trayButton;
protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
protected static string _appHistoryPath = _settingsFolderPath + "\\app-zone-history.json";
@ -30,7 +30,7 @@ namespace PowerToysTests
protected const string _defaultSettings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_mouseSwitch\":{\"value\":false},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_moveWindowAcrossMonitors\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}";
protected const string _defaultZoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
public static void Setup(TestContext context, bool isLaunchRequired = true)
{
@ -52,7 +52,7 @@ namespace PowerToysTests
{
LaunchPowerToys();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
@ -176,7 +176,7 @@ namespace PowerToysTests
}
}
private static bool CheckPowerToysLaunched()
private static bool CheckPowerToysLaunched()
{
bool isLaunched = false;
try
@ -190,7 +190,7 @@ namespace PowerToysTests
{
//PowerToys not found
}
return isLaunched;
}