Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate FancyZones data persisting from Registry to JSON file #1194

Merged
merged 32 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f20cecd
Migrate FancyZones data persisting from Registry to JSON file
stefansjfw Jan 29, 2020
06adfe4
Address PR comment: Remove redundant check
stefansjfw Feb 1, 2020
89a656b
Addres PR comment: Remove unused Dpi and add CmdArgs enum
stefansjfw Feb 1, 2020
eb3172e
Address PR comment: Make methods const and inline
stefansjfw Feb 1, 2020
b66771c
Address PR comments: Expose GenerateUniqueId function and use const r…
vldmr11080 Feb 2, 2020
a2efd29
Address PR comment: Use lamdba as callback
stefansjfw Feb 2, 2020
e1424da
Address PR comment: Move GenerateUniqueId to ZoneWindowUtils namespace
vldmr11080 Feb 2, 2020
20f9c32
Address PR comment: Use regular comparison instead of std::wstring::c…
vldmr11080 Feb 2, 2020
0fcdb3a
Address PR comment: Use std::wstring_view for tmp file paths
vldmr11080 Feb 2, 2020
fc511da
Address PR comment: Use scoped lock when accessing member data
vldmr11080 Feb 2, 2020
64360b0
Address PR comment: Remove typedefs to increase code readability
vldmr11080 Feb 2, 2020
fe4e0e1
Address PR comment: removed nullptr checks with corresponding tests
SeraphimaZykova Feb 3, 2020
83c1e05
Address PR comment: Move ZoneSet object instead of copying
vldmr11080 Feb 3, 2020
2517a14
Address PR comment: Make FancyZonesData instance const where possible
stefansjfw Feb 3, 2020
466b734
Remove unnecessary gutter variable during calculating zone coordinates
vldmr11080 Feb 3, 2020
a25b4b2
Remove uneeded subclass
stefansjfw Feb 3, 2020
0c557b0
Avoid unnecessary copying and reserve space for vector if possible
vldmr11080 Feb 3, 2020
8910faf
Save FancyZones data after exiting editor
vldmr11080 Feb 4, 2020
b79d74c
App zone history (#18)
SeraphimaZykova Feb 5, 2020
3be9e05
Rename JSON file
stefansjfw Feb 5, 2020
b3d94cd
Remove AppZoneHistory migration
stefansjfw Feb 5, 2020
1365c71
Move parsing of ZoneWindow independent temp files outside of it
vldmr11080 Feb 5, 2020
0a8e75e
Unit tests update (#19)
SeraphimaZykova Feb 6, 2020
6282002
Use single zone count information
stefansjfw Feb 6, 2020
e501f60
Remove uneeded tests
stefansjfw Feb 6, 2020
8906bdc
Remove one more test
stefansjfw Feb 6, 2020
720fff3
Remove uneeded line
stefansjfw Feb 6, 2020
3d5aea5
Address PR comments - Missing whitespace
stefansjfw Feb 6, 2020
485227c
Update zoneset data for new virtual desktops (#21)
SeraphimaZykova Feb 6, 2020
c991263
Introduce Blank zone set (used to indicate that no layout applied yet…
vldmr11080 Feb 6, 2020
4415582
Fix unit tests to match modifications in implementation
vldmr11080 Feb 6, 2020
5c70bdb
Fix applying layouts on startup (second monitor)
stefansjfw Feb 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/settings_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace PTSettingsHelper {

std::wstring get_module_save_folder_location(std::wstring_view powertoy_name);

void save_module_settings(std::wstring_view powertoy_name, json::JsonObject& settings);
json::JsonObject load_module_settings(std::wstring_view powertoy_name);
void save_general_settings(const json::JsonObject& settings);
Expand Down
3 changes: 0 additions & 3 deletions src/modules/fancyzones/dll/FancyZonesModule.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>gdiplus.lib;dwmapi.lib;shlwapi.lib;uxtheme.lib;shcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>fancyzones.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -96,7 +95,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>gdiplus.lib;dwmapi.lib;shlwapi.lib;uxtheme.lib;shcore.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>fancyzones.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -121,7 +119,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="fancyzones.def" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="fancyzones.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\lib\fancyzones.rc" />
Expand Down
76 changes: 4 additions & 72 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <interface/lowlevel_keyboard_event_data.h>
#include <interface/win_hook_event_data.h>
#include <lib/ZoneSet.h>
#include <lib/RegistryHelpers.h>

#include <lib/resource.h>
#include <lib/trace.h>
Expand Down Expand Up @@ -33,76 +32,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
return TRUE;
}

// This function is exported and called from FancyZonesEditor.exe to save a layout from the editor.
STDAPI PersistZoneSet(
PCWSTR activeKey, // Registry key holding ActiveZoneSet
PCWSTR resolutionKey, // Registry key to persist ZoneSet to
HMONITOR monitor,
WORD layoutId, // LayoutModel Id
int zoneCount, // Number of zones in zones
int zones[]) // Array of zones serialized in left/top/right/bottom chunks
{
// See if we have already persisted this layout we can update.
UUID id{GUID_NULL};
if (wil::unique_hkey key{ RegistryHelpers::OpenKey(resolutionKey) })
{
ZoneSetPersistedData data{};
DWORD dataSize = sizeof(data);
wchar_t value[256]{};
DWORD valueLength = ARRAYSIZE(value);
DWORD i = 0;
while (RegEnumValueW(key.get(), i++, value, &valueLength, nullptr, nullptr, reinterpret_cast<BYTE*>(&data), &dataSize) == ERROR_SUCCESS)
{
if (data.LayoutId == layoutId)
{
if (data.ZoneCount == zoneCount)
{
CLSIDFromString(value, &id);
break;
}
}
valueLength = ARRAYSIZE(value);
dataSize = sizeof(data);
}
}

if (id == GUID_NULL)
{
// No existing layout found so let's create a new one.
UuidCreate(&id);
}

if (id != GUID_NULL)
{
winrt::com_ptr<IZoneSet> zoneSet = MakeZoneSet(
ZoneSetConfig(
id,
layoutId,
MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY),
resolutionKey));

for (int i = 0; i < zoneCount; i++)
{
const int baseIndex = i * 4;
const int left = zones[baseIndex];
const int top = zones[baseIndex+1];
const int right = zones[baseIndex+2];
const int bottom = zones[baseIndex+3];
zoneSet->AddZone(MakeZone({ left, top, right, bottom }));
}
zoneSet->Save();

wil::unique_cotaskmem_string zoneSetId;
if (SUCCEEDED_LOG(StringFromCLSID(id, &zoneSetId)))
{
RegistryHelpers::SetString(activeKey, L"ActiveZoneSetId", zoneSetId.get());
}

return S_OK;
}
return E_FAIL;
}

class FancyZonesModule : public PowertoyModuleIface
{
public:
Expand Down Expand Up @@ -147,7 +76,7 @@ class FancyZonesModule : public PowertoyModuleIface
if (!m_app)
{
Trace::FancyZones::EnableFancyZones(true);
m_app = MakeFancyZones(reinterpret_cast<HINSTANCE>(&__ImageBase), m_settings.get());
m_app = MakeFancyZones(reinterpret_cast<HINSTANCE>(&__ImageBase), m_settings);
if (m_app)
{
m_app->Run();
Expand Down Expand Up @@ -200,12 +129,15 @@ class FancyZonesModule : public PowertoyModuleIface
{
app_name = GET_RESOURCE_STRING(IDS_FANCYZONES);
m_settings = MakeFancyZonesSettings(reinterpret_cast<HINSTANCE>(&__ImageBase), FancyZonesModule::get_name());
JSONHelpers::FancyZonesDataInstance().LoadFancyZonesData();
}

private:
void Disable(bool const traceEvent)
{
if (m_app) {
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
fancyZonesData.SaveFancyZonesData();
if (traceEvent)
{
Trace::FancyZones::EnableFancyZones(false);
Expand Down
4 changes: 0 additions & 4 deletions src/modules/fancyzones/dll/fancyzones.def

This file was deleted.

34 changes: 12 additions & 22 deletions src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,36 @@ public partial class App : Application
{
public Settings ZoneSettings { get; }

private ushort _idInitial = 0;

public App()
{
ZoneSettings = new Settings();
}

private void OnStartup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 1)
LayoutModel foundModel = null;

foreach (LayoutModel model in ZoneSettings.DefaultModels)
{
ushort.TryParse(e.Args[1], out _idInitial);
if (model.Type == Settings.ActiveZoneSetLayoutType)
{
// found match
foundModel = model;
break;
}
}

LayoutModel foundModel = null;

if (_idInitial != 0)
if (foundModel == null)
{
foreach (LayoutModel model in ZoneSettings.DefaultModels)
foreach (LayoutModel model in Settings.CustomModels)
{
if (model.Id == _idInitial)
if ("{" + model.Guid.ToString().ToUpper() + "}" == Settings.ActiveZoneSetUUid.ToUpper())
{
// found match
foundModel = model;
break;
}
}

if (foundModel == null)
{
foreach (LayoutModel model in ZoneSettings.CustomModels)
{
if (model.Id == _idInitial)
{
// found match
foundModel = model;
break;
}
}
}
}

if (foundModel == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public partial class EditorOverlay : Window

private readonly Settings _settings = ((App)Application.Current).ZoneSettings;
private LayoutPreview _layoutPreview;

private UserControl _editor;

private static MainWindow _mainWindow = new MainWindow();

public Int32Rect[] GetZoneRects()
{
if (_editor != null)
Expand Down Expand Up @@ -79,27 +82,23 @@ private void OnLoaded(object sender, RoutedEventArgs e)

public void ShowLayoutPicker()
{
DataContext = null;

_editor = null;
_layoutPreview = new LayoutPreview
{
IsActualSize = true,
Opacity = 0.5,
};

Content = _layoutPreview;

MainWindow window = new MainWindow
{
Owner = this,
ShowActivated = true,
Topmost = true,
};
window.Show();
_mainWindow.Owner = this;
_mainWindow.ShowActivated = true;
_mainWindow.Topmost = true;
_mainWindow.Show();

// window is set to topmost to make sure it shows on top of PowerToys settings page
// we can reset topmost flag now
window.Topmost = false;
_mainWindow.Topmost = false;
}

// These event handlers are used to track the current state of the Shift and Ctrl keys on the keyboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -194,6 +195,9 @@
<PackageReference Include="MahApps.Metro">
<Version>2.0.0-alpha0455</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>4.6.0</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -208,4 +212,4 @@
<Resource Include="images\Merge.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
18 changes: 7 additions & 11 deletions src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public partial class MainWindow : MetroWindow
public const int MaxZones = 40;
private readonly Settings _settings = ((App)Application.Current).ZoneSettings;
private static readonly string _defaultNamePrefix = "Custom Layout ";
private bool _editing = false;

public int WrapPanelItemSize { get; set; } = 262;

Expand Down Expand Up @@ -67,7 +66,7 @@ private void NewCustomLayoutButton_Click(object sender, RoutedEventArgs e)
{
WindowLayout window = new WindowLayout();
window.Show();
Close();
Hide();
}

private void LayoutItem_Click(object sender, MouseButtonEventArgs e)
Expand Down Expand Up @@ -95,12 +94,11 @@ private void EditLayout_Click(object sender, RoutedEventArgs e)
}

model.IsSelected = false;
_editing = true;
Close();
Hide();

bool isPredefinedLayout = Settings.IsPredefinedLayout(model);

if (!_settings.CustomModels.Contains(model) || isPredefinedLayout)
if (!Settings.CustomModels.Contains(model) || isPredefinedLayout)
{
if (isPredefinedLayout)
{
Expand All @@ -110,7 +108,7 @@ private void EditLayout_Click(object sender, RoutedEventArgs e)
}

int maxCustomIndex = 0;
foreach (LayoutModel customModel in _settings.CustomModels)
foreach (LayoutModel customModel in Settings.CustomModels)
{
string name = customModel.Name;
if (name.StartsWith(_defaultNamePrefix))
Expand Down Expand Up @@ -165,10 +163,8 @@ private void Apply_Click(object sender, RoutedEventArgs e)

private void OnClosing(object sender, EventArgs e)
{
if (!_editing)
{
EditorOverlay.Current.Close();
}
LayoutModel.SerializeDeletedCustomZoneSets();
EditorOverlay.Current.Close();
}

private void OnInitialized(object sender, EventArgs e)
Expand All @@ -178,7 +174,7 @@ private void OnInitialized(object sender, EventArgs e)

private void SetSelectedItem()
{
foreach (LayoutModel model in _settings.CustomModels)
foreach (LayoutModel model in Settings.CustomModels)
{
if (model.IsSelected)
{
Expand Down
Loading