mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 14:59:16 +08:00
[FancyZones Editor] UI fixes (#18966)
* canvas scaling * moved editor params saving * show monitor size * removed unused cmd args * separate dpi unaware thread * tests * dpi unaware monitor size * spell * early return on editor params saving error * show scaling value * changed font
This commit is contained in:
parent
81f99264b3
commit
9e0781d86c
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@ -1747,6 +1747,7 @@ robmensching
|
||||
Roboto
|
||||
roslyn
|
||||
Rothera
|
||||
roundf
|
||||
ROUNDSMALL
|
||||
royvou
|
||||
Rpc
|
||||
|
198
src/modules/fancyzones/FancyZonesLib/EditorParameters.cpp
Normal file
198
src/modules/fancyzones/FancyZonesLib/EditorParameters.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#include "pch.h"
|
||||
#include "EditorParameters.h"
|
||||
|
||||
#include <FancyZonesLib/FancyZonesWindowProperties.h>
|
||||
#include <FancyZonesLib/on_thread_executor.h>
|
||||
#include <FancyZonesLib/Settings.h>
|
||||
#include <FancyZonesLib/VirtualDesktop.h>
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
#include <common/Display/dpi_aware.h>
|
||||
#include <common/logger/logger.h>
|
||||
|
||||
|
||||
// Non-localizable strings
|
||||
namespace NonLocalizable
|
||||
{
|
||||
const wchar_t FancyZonesEditorParametersFile[] = L"editor-parameters.json";
|
||||
}
|
||||
|
||||
namespace JsonUtils
|
||||
{
|
||||
struct MonitorInfo
|
||||
{
|
||||
std::wstring monitorName;
|
||||
std::wstring virtualDesktop;
|
||||
int dpi;
|
||||
int top;
|
||||
int left;
|
||||
int workAreaWidth;
|
||||
int workAreaHeight;
|
||||
int monitorWidth;
|
||||
int monitorHeight;
|
||||
bool isSelected = false;
|
||||
|
||||
static json::JsonObject ToJson(const MonitorInfo& monitor)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::MonitorNameId, json::value(monitor.monitorName));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::VirtualDesktopId, json::value(monitor.virtualDesktop));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::Dpi, json::value(monitor.dpi));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::TopCoordinate, json::value(monitor.top));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::LeftCoordinate, json::value(monitor.left));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::WorkAreaWidth, json::value(monitor.workAreaWidth));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::WorkAreaHeight, json::value(monitor.workAreaHeight));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::MonitorWidth, json::value(monitor.monitorWidth));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::MonitorHeight, json::value(monitor.monitorHeight));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::IsSelected, json::value(monitor.isSelected));
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct EditorArgs
|
||||
{
|
||||
DWORD processId;
|
||||
bool spanZonesAcrossMonitors;
|
||||
std::vector<MonitorInfo> monitors;
|
||||
|
||||
static json::JsonObject ToJson(const EditorArgs& args)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::ProcessId, json::value(args.processId));
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::SpanZonesAcrossMonitors, json::value(args.spanZonesAcrossMonitors));
|
||||
|
||||
json::JsonArray monitors;
|
||||
for (const auto& monitor : args.monitors)
|
||||
{
|
||||
monitors.Append(MonitorInfo::ToJson(monitor));
|
||||
}
|
||||
|
||||
result.SetNamedValue(NonLocalizable::EditorParametersIds::Monitors, monitors);
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool EditorParameters::Save() noexcept
|
||||
{
|
||||
const auto virtualDesktopIdStr = FancyZonesUtils::GuidToString(VirtualDesktop::instance().GetCurrentVirtualDesktopId());
|
||||
if (!virtualDesktopIdStr)
|
||||
{
|
||||
Logger::error(L"Save editor params: no virtual desktop id");
|
||||
return false;
|
||||
}
|
||||
|
||||
OnThreadExecutor dpiUnawareThread;
|
||||
dpiUnawareThread.submit(OnThreadExecutor::task_t{ [] {
|
||||
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
|
||||
SetThreadDpiHostingBehavior(DPI_HOSTING_BEHAVIOR_MIXED);
|
||||
} }).wait();
|
||||
|
||||
const bool spanZonesAcrossMonitors = FancyZonesSettings::settings().spanZonesAcrossMonitors;
|
||||
|
||||
JsonUtils::EditorArgs argsJson;
|
||||
argsJson.processId = GetCurrentProcessId();
|
||||
argsJson.spanZonesAcrossMonitors = spanZonesAcrossMonitors;
|
||||
|
||||
if (spanZonesAcrossMonitors)
|
||||
{
|
||||
RECT combinedWorkArea;
|
||||
dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&]() {
|
||||
combinedWorkArea = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFOEX::rcWork>();
|
||||
|
||||
} }).wait();
|
||||
|
||||
RECT combinedMonitorArea = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFOEX::rcMonitor>();
|
||||
|
||||
JsonUtils::MonitorInfo monitorJson;
|
||||
monitorJson.monitorName = ZonedWindowProperties::MultiMonitorDeviceID;
|
||||
monitorJson.virtualDesktop = virtualDesktopIdStr.value();
|
||||
monitorJson.top = combinedWorkArea.top;
|
||||
monitorJson.left = combinedWorkArea.left;
|
||||
monitorJson.workAreaWidth = combinedWorkArea.right - combinedWorkArea.left;
|
||||
monitorJson.workAreaHeight = combinedWorkArea.bottom - combinedWorkArea.top;
|
||||
monitorJson.monitorWidth = combinedMonitorArea.right - combinedMonitorArea.left;
|
||||
monitorJson.monitorHeight = combinedMonitorArea.bottom - combinedMonitorArea.top;
|
||||
monitorJson.isSelected = true;
|
||||
monitorJson.dpi = 0; // unused
|
||||
|
||||
argsJson.monitors.emplace_back(std::move(monitorJson));
|
||||
}
|
||||
else
|
||||
{
|
||||
// device id map for correct device ids
|
||||
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||
|
||||
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
||||
dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&]() {
|
||||
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
||||
} }).wait();
|
||||
|
||||
HMONITOR targetMonitor{};
|
||||
if (FancyZonesSettings::settings().use_cursorpos_editor_startupscreen)
|
||||
{
|
||||
POINT currentCursorPos{};
|
||||
GetCursorPos(¤tCursorPos);
|
||||
targetMonitor = MonitorFromPoint(currentCursorPos, MONITOR_DEFAULTTOPRIMARY);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetMonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY);
|
||||
}
|
||||
|
||||
if (!targetMonitor)
|
||||
{
|
||||
Logger::error("No target monitor to open editor");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& monitorData : allMonitors)
|
||||
{
|
||||
HMONITOR monitor = monitorData.first;
|
||||
auto monitorInfo = monitorData.second;
|
||||
|
||||
JsonUtils::MonitorInfo monitorJson;
|
||||
|
||||
std::wstring deviceId = FancyZonesUtils::GetDisplayDeviceId(monitorInfo.szDevice, displayDeviceIdxMap);
|
||||
|
||||
if (monitor == targetMonitor)
|
||||
{
|
||||
monitorJson.isSelected = true; /* Is monitor selected for the main editor window opening */
|
||||
}
|
||||
|
||||
monitorJson.monitorName = FancyZonesUtils::TrimDeviceId(deviceId);
|
||||
monitorJson.virtualDesktop = virtualDesktopIdStr.value();
|
||||
|
||||
UINT dpi = 0;
|
||||
if (DPIAware::GetScreenDPIForMonitor(monitor, dpi) != S_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
monitorJson.dpi = dpi;
|
||||
monitorJson.top = monitorInfo.rcWork.top;
|
||||
monitorJson.left = monitorInfo.rcWork.left;
|
||||
monitorJson.workAreaWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
|
||||
monitorJson.workAreaHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
|
||||
|
||||
float width = static_cast<float>(monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left);
|
||||
float height = static_cast<float>(monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top);
|
||||
DPIAware::Convert(monitor, width, height);
|
||||
|
||||
monitorJson.monitorWidth = static_cast<int>(std::roundf(width));
|
||||
monitorJson.monitorHeight = static_cast<int>(std::roundf(height));
|
||||
|
||||
argsJson.monitors.emplace_back(std::move(monitorJson));
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring folderPath = PTSettingsHelper::get_module_save_folder_location(NonLocalizable::ModuleKey);
|
||||
std::wstring fileName = folderPath + L"\\" + std::wstring(NonLocalizable::FancyZonesEditorParametersFile);
|
||||
json::to_file(fileName, JsonUtils::EditorArgs::ToJson(argsJson));
|
||||
|
||||
return true;
|
||||
}
|
27
src/modules/fancyzones/FancyZonesLib/EditorParameters.h
Normal file
27
src/modules/fancyzones/FancyZonesLib/EditorParameters.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
namespace NonLocalizable
|
||||
{
|
||||
namespace EditorParametersIds
|
||||
{
|
||||
const static wchar_t* Dpi = L"dpi";
|
||||
const static wchar_t* MonitorNameId = L"monitor";
|
||||
const static wchar_t* VirtualDesktopId = L"virtual-desktop";
|
||||
const static wchar_t* TopCoordinate = L"top-coordinate";
|
||||
const static wchar_t* LeftCoordinate = L"left-coordinate";
|
||||
const static wchar_t* WorkAreaWidth = L"work-area-width";
|
||||
const static wchar_t* WorkAreaHeight = L"work-area-height";
|
||||
const static wchar_t* MonitorWidth = L"monitor-width";
|
||||
const static wchar_t* MonitorHeight = L"monitor-height";
|
||||
const static wchar_t* IsSelected = L"is-selected";
|
||||
const static wchar_t* ProcessId = L"process-id";
|
||||
const static wchar_t* SpanZonesAcrossMonitors = L"span-zones-across-monitors";
|
||||
const static wchar_t* Monitors = L"monitors";
|
||||
}
|
||||
}
|
||||
|
||||
class EditorParameters
|
||||
{
|
||||
public:
|
||||
static bool Save() noexcept;
|
||||
};
|
@ -11,6 +11,7 @@
|
||||
#include <common/utils/window.h>
|
||||
#include <common/SettingsAPI/FileWatcher.h>
|
||||
|
||||
#include <FancyZonesLib/EditorParameters.h>
|
||||
#include <FancyZonesLib/FancyZonesData.h>
|
||||
#include <FancyZonesLib/FancyZonesData/AppliedLayouts.h>
|
||||
#include <FancyZonesLib/FancyZonesData/AppZoneHistory.h>
|
||||
@ -487,124 +488,16 @@ void FancyZones::ToggleEditor() noexcept
|
||||
|
||||
m_terminateEditorEvent.reset(CreateEvent(nullptr, true, false, nullptr));
|
||||
|
||||
HMONITOR targetMonitor{};
|
||||
|
||||
const bool use_cursorpos_editor_startupscreen = FancyZonesSettings::settings().use_cursorpos_editor_startupscreen;
|
||||
if (use_cursorpos_editor_startupscreen)
|
||||
{
|
||||
POINT currentCursorPos{};
|
||||
GetCursorPos(¤tCursorPos);
|
||||
targetMonitor = MonitorFromPoint(currentCursorPos, MONITOR_DEFAULTTOPRIMARY);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetMonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY);
|
||||
}
|
||||
|
||||
if (!targetMonitor)
|
||||
if (!EditorParameters::Save())
|
||||
{
|
||||
Logger::error(L"Failed to save editor startup parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
wil::unique_cotaskmem_string virtualDesktopId;
|
||||
if (!SUCCEEDED(StringFromCLSID(VirtualDesktop::instance().GetCurrentVirtualDesktopId(), &virtualDesktopId)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Divider: /
|
||||
* Parts:
|
||||
* (1) Process id
|
||||
* (2) Span zones across monitors
|
||||
* (3) Monitor id where the Editor should be opened
|
||||
* (4) Monitors count
|
||||
*
|
||||
* Data for each monitor:
|
||||
* (5) Monitor id
|
||||
* (6) DPI
|
||||
* (7) work area left
|
||||
* (8) work area top
|
||||
* (9) work area width
|
||||
* (10) work area height
|
||||
* ...
|
||||
*/
|
||||
std::wstring params;
|
||||
const std::wstring divider = L"/";
|
||||
params += std::to_wstring(GetCurrentProcessId()) + divider; /* Process id */
|
||||
const bool spanZonesAcrossMonitors = FancyZonesSettings::settings().spanZonesAcrossMonitors;
|
||||
params += std::to_wstring(spanZonesAcrossMonitors) + divider; /* Span zones */
|
||||
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
||||
|
||||
m_dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&] {
|
||||
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
||||
} }).wait();
|
||||
|
||||
if (spanZonesAcrossMonitors)
|
||||
{
|
||||
params += FancyZonesUtils::GenerateUniqueIdAllMonitorsArea(virtualDesktopId.get()) + divider; /* Monitor id where the Editor should be opened */
|
||||
}
|
||||
|
||||
// device id map
|
||||
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||
|
||||
bool showDpiWarning = false;
|
||||
int prevDpi = -1;
|
||||
std::wstring monitorsDataStr;
|
||||
|
||||
for (auto& monitorData : allMonitors)
|
||||
{
|
||||
HMONITOR monitor = monitorData.first;
|
||||
auto monitorInfo = monitorData.second;
|
||||
|
||||
std::wstring deviceId = FancyZonesUtils::GetDisplayDeviceId(monitorInfo.szDevice, displayDeviceIdxMap);
|
||||
std::wstring monitorId = FancyZonesUtils::GenerateUniqueId(monitor, deviceId, virtualDesktopId.get());
|
||||
|
||||
if (monitor == targetMonitor && !spanZonesAcrossMonitors)
|
||||
{
|
||||
params += monitorId + divider; /* Monitor id where the Editor should be opened */
|
||||
}
|
||||
|
||||
UINT dpi = 0;
|
||||
if (DPIAware::GetScreenDPIForMonitor(monitor, dpi) != S_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spanZonesAcrossMonitors && prevDpi != -1 && prevDpi != dpi)
|
||||
{
|
||||
showDpiWarning = true;
|
||||
}
|
||||
|
||||
monitorsDataStr += std::move(monitorId) + divider; /* Monitor id */
|
||||
monitorsDataStr += std::to_wstring(dpi) + divider; /* DPI */
|
||||
monitorsDataStr += std::to_wstring(monitorInfo.rcWork.left) + divider; /* Top coordinate */
|
||||
monitorsDataStr += std::to_wstring(monitorInfo.rcWork.top) + divider; /* Left coordinate */
|
||||
monitorsDataStr += std::to_wstring(monitorInfo.rcWork.right - monitorInfo.rcWork.left) + divider; /* Width */
|
||||
monitorsDataStr += std::to_wstring(monitorInfo.rcWork.bottom - monitorInfo.rcWork.top) + divider; /* Height */
|
||||
}
|
||||
|
||||
params += std::to_wstring(allMonitors.size()) + divider; /* Monitors count */
|
||||
params += monitorsDataStr;
|
||||
|
||||
FancyZonesDataInstance().SaveFancyZonesEditorParameters(spanZonesAcrossMonitors, virtualDesktopId.get(), targetMonitor, allMonitors); /* Write parameters to json file */
|
||||
|
||||
if (showDpiWarning)
|
||||
{
|
||||
// We must show the message box in a separate thread, since this code is called from a low-level
|
||||
// keyboard hook callback, and launching messageboxes from it has unexpected side effects
|
||||
//std::thread{ [] {
|
||||
// MessageBoxW(nullptr,
|
||||
// GET_RESOURCE_STRING(IDS_SPAN_ACROSS_ZONES_WARNING).c_str(),
|
||||
// GET_RESOURCE_STRING(IDS_POWERTOYS_FANCYZONES).c_str(),
|
||||
// MB_OK | MB_ICONWARNING);
|
||||
//} }.detach();
|
||||
}
|
||||
|
||||
|
||||
SHELLEXECUTEINFO sei{ sizeof(sei) };
|
||||
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
||||
sei.lpFile = NonLocalizable::FZEditorExecutablePath;
|
||||
sei.lpParameters = params.c_str();
|
||||
sei.lpParameters = L"";
|
||||
sei.nShow = SW_SHOWDEFAULT;
|
||||
ShellExecuteEx(&sei);
|
||||
Trace::FancyZones::EditorLaunched(1);
|
||||
|
@ -3,14 +3,11 @@
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <common/Display/dpi_aware.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/SettingsAPI/settings_helpers.h>
|
||||
|
||||
#include <FancyZonesLib/JsonHelpers.h>
|
||||
#include <FancyZonesLib/ModuleConstants.h>
|
||||
#include <FancyZonesLib/FancyZonesWindowProperties.h>
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
// Non-localizable strings
|
||||
namespace NonLocalizable
|
||||
@ -18,7 +15,6 @@ namespace NonLocalizable
|
||||
const wchar_t FancyZonesSettingsFile[] = L"settings.json";
|
||||
const wchar_t FancyZonesDataFile[] = L"zones-settings.json";
|
||||
const wchar_t FancyZonesAppZoneHistoryFile[] = L"app-zone-history.json";
|
||||
const wchar_t FancyZonesEditorParametersFile[] = L"editor-parameters.json";
|
||||
}
|
||||
|
||||
FancyZonesData& FancyZonesDataInstance()
|
||||
@ -34,7 +30,6 @@ FancyZonesData::FancyZonesData()
|
||||
settingsFileName = saveFolderPath + L"\\" + std::wstring(NonLocalizable::FancyZonesSettingsFile);
|
||||
appZoneHistoryFileName = saveFolderPath + L"\\" + std::wstring(NonLocalizable::FancyZonesAppZoneHistoryFile);
|
||||
zonesSettingsFileName = saveFolderPath + L"\\" + std::wstring(NonLocalizable::FancyZonesDataFile);
|
||||
editorParametersFileName = saveFolderPath + L"\\" + std::wstring(NonLocalizable::FancyZonesEditorParametersFile);
|
||||
}
|
||||
|
||||
void FancyZonesData::ReplaceZoneSettingsFileFromOlderVersions()
|
||||
@ -72,67 +67,3 @@ void FancyZonesData::ReplaceZoneSettingsFileFromOlderVersions()
|
||||
std::filesystem::remove(zonesSettingsFileName);
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZonesData::SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor, const std::vector<std::pair<HMONITOR, MONITORINFOEX>>& allMonitors) const
|
||||
{
|
||||
JSONHelpers::EditorArgs argsJson; /* json arguments */
|
||||
argsJson.processId = GetCurrentProcessId(); /* Process id */
|
||||
argsJson.spanZonesAcrossMonitors = spanZonesAcrossMonitors; /* Span zones */
|
||||
|
||||
if (spanZonesAcrossMonitors)
|
||||
{
|
||||
auto monitorRect = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFOEX::rcWork>();
|
||||
|
||||
JSONHelpers::MonitorInfo monitorJson;
|
||||
monitorJson.monitorName = ZonedWindowProperties::MultiMonitorDeviceID;
|
||||
monitorJson.virtualDesktop = virtualDesktopId;
|
||||
monitorJson.top = monitorRect.top;
|
||||
monitorJson.left = monitorRect.left;
|
||||
monitorJson.width = monitorRect.right - monitorRect.left;
|
||||
monitorJson.height = monitorRect.bottom - monitorRect.top;
|
||||
monitorJson.isSelected = true;
|
||||
monitorJson.dpi = 0; // unused
|
||||
|
||||
argsJson.monitors.emplace_back(std::move(monitorJson)); /* add monitor data */
|
||||
}
|
||||
else
|
||||
{
|
||||
// device id map for correct device ids
|
||||
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||
|
||||
for (auto& monitorData : allMonitors)
|
||||
{
|
||||
HMONITOR monitor = monitorData.first;
|
||||
auto monitorInfo = monitorData.second;
|
||||
|
||||
JSONHelpers::MonitorInfo monitorJson;
|
||||
|
||||
std::wstring deviceId = FancyZonesUtils::GetDisplayDeviceId(monitorInfo.szDevice, displayDeviceIdxMap);
|
||||
|
||||
if (monitor == targetMonitor)
|
||||
{
|
||||
monitorJson.isSelected = true; /* Is monitor selected for the main editor window opening */
|
||||
}
|
||||
|
||||
monitorJson.monitorName = FancyZonesUtils::TrimDeviceId(deviceId); /* Monitor name */
|
||||
monitorJson.virtualDesktop = virtualDesktopId; /* Virtual desktop id */
|
||||
|
||||
UINT dpi = 0;
|
||||
if (DPIAware::GetScreenDPIForMonitor(monitor, dpi) != S_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
monitorJson.dpi = dpi; /* DPI */
|
||||
monitorJson.top = monitorInfo.rcWork.top; /* Top coordinate */
|
||||
monitorJson.left = monitorInfo.rcWork.left; /* Left coordinate */
|
||||
monitorJson.width = monitorInfo.rcWork.right - monitorInfo.rcWork.left; /* Width */
|
||||
monitorJson.height = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; /* Height */
|
||||
|
||||
argsJson.monitors.emplace_back(std::move(monitorJson)); /* add monitor data */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
json::to_file(editorParametersFileName, JSONHelpers::EditorArgs::ToJson(argsJson));
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ public:
|
||||
return settingsFileName;
|
||||
}
|
||||
|
||||
void SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor, const std::vector<std::pair<HMONITOR, MONITORINFOEX>>& allMonitors) const;
|
||||
|
||||
private:
|
||||
#if defined(UNIT_TESTS)
|
||||
friend class FancyZonesUnitTests::LayoutHotkeysUnitTests;
|
||||
@ -51,7 +49,6 @@ private:
|
||||
std::wstring settingsFileName;
|
||||
std::wstring zonesSettingsFileName;
|
||||
std::wstring appZoneHistoryFileName;
|
||||
std::wstring editorParametersFileName;
|
||||
};
|
||||
|
||||
FancyZonesData& FancyZonesDataInstance();
|
@ -35,6 +35,7 @@
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="EditorParameters.h" />
|
||||
<ClInclude Include="FancyZonesData\CustomLayouts.h" />
|
||||
<ClInclude Include="FancyZonesData\AppliedLayouts.h" />
|
||||
<ClInclude Include="FancyZonesData\AppZoneHistory.h" />
|
||||
@ -77,6 +78,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Colors.cpp" />
|
||||
<ClCompile Include="EditorParameters.cpp" />
|
||||
<ClCompile Include="FancyZonesData\AppZoneHistory.cpp">
|
||||
<PrecompiledHeaderFile>../pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
|
@ -132,6 +132,9 @@
|
||||
<ClInclude Include="FancyZonesWindowProcessing.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EditorParameters.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@ -218,6 +221,9 @@
|
||||
<ClCompile Include="LayoutConfigurator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EditorParameters.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@ -60,19 +60,6 @@ namespace NonLocalizable
|
||||
const wchar_t ZoneIndexStr[] = L"zone-index";
|
||||
const wchar_t ZoneSetUuidStr[] = L"zoneset-uuid";
|
||||
const wchar_t ZonesStr[] = L"zones";
|
||||
|
||||
// Editor arguments
|
||||
const wchar_t Dpi[] = L"dpi";
|
||||
const wchar_t MonitorNameId[] = L"monitor";
|
||||
const wchar_t VirtualDesktopId[] = L"virtual-desktop";
|
||||
const wchar_t TopCoordinate[] = L"top-coordinate";
|
||||
const wchar_t LeftCoordinate[] = L"left-coordinate";
|
||||
const wchar_t Width[] = L"width";
|
||||
const wchar_t Height[] = L"height";
|
||||
const wchar_t IsSelected[] = L"is-selected";
|
||||
const wchar_t ProcessId[] = L"process-id";
|
||||
const wchar_t SpanZonesAcrossMonitors[] = L"span-zones-across-monitors";
|
||||
const wchar_t Monitors[] = L"monitors";
|
||||
}
|
||||
|
||||
namespace BackwardsCompatibility
|
||||
@ -608,40 +595,6 @@ namespace JSONHelpers
|
||||
}
|
||||
}
|
||||
|
||||
json::JsonObject MonitorInfo::ToJson(const MonitorInfo& monitor)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::MonitorNameId, json::value(monitor.monitorName));
|
||||
result.SetNamedValue(NonLocalizable::VirtualDesktopId, json::value(monitor.virtualDesktop));
|
||||
result.SetNamedValue(NonLocalizable::Dpi, json::value(monitor.dpi));
|
||||
result.SetNamedValue(NonLocalizable::TopCoordinate, json::value(monitor.top));
|
||||
result.SetNamedValue(NonLocalizable::LeftCoordinate, json::value(monitor.left));
|
||||
result.SetNamedValue(NonLocalizable::Width, json::value(monitor.width));
|
||||
result.SetNamedValue(NonLocalizable::Height, json::value(monitor.height));
|
||||
result.SetNamedValue(NonLocalizable::IsSelected, json::value(monitor.isSelected));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
json::JsonObject EditorArgs::ToJson(const EditorArgs& args)
|
||||
{
|
||||
json::JsonObject result{};
|
||||
|
||||
result.SetNamedValue(NonLocalizable::ProcessId, json::value(args.processId));
|
||||
result.SetNamedValue(NonLocalizable::SpanZonesAcrossMonitors, json::value(args.spanZonesAcrossMonitors));
|
||||
|
||||
json::JsonArray monitors;
|
||||
for (const auto& monitor : args.monitors)
|
||||
{
|
||||
monitors.Append(MonitorInfo::ToJson(monitor));
|
||||
}
|
||||
|
||||
result.SetNamedValue(NonLocalizable::Monitors, monitors);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
json::JsonObject GetPersistFancyZonesJSON(const std::wstring& zonesSettingsFileName, const std::wstring& appZoneHistoryFileName)
|
||||
{
|
||||
auto result = json::from_file(zonesSettingsFileName);
|
||||
|
@ -88,29 +88,6 @@ namespace JSONHelpers
|
||||
using TCustomZoneSetsMap = std::unordered_map<std::wstring, FancyZonesDataTypes::CustomLayoutData>;
|
||||
using TLayoutQuickKeysMap = std::unordered_map<std::wstring, int>;
|
||||
|
||||
struct MonitorInfo
|
||||
{
|
||||
std::wstring monitorName;
|
||||
std::wstring virtualDesktop;
|
||||
int dpi;
|
||||
int top;
|
||||
int left;
|
||||
int width;
|
||||
int height;
|
||||
bool isSelected = false;
|
||||
|
||||
static json::JsonObject ToJson(const MonitorInfo& monitor);
|
||||
};
|
||||
|
||||
struct EditorArgs
|
||||
{
|
||||
DWORD processId;
|
||||
bool spanZonesAcrossMonitors;
|
||||
std::vector<MonitorInfo> monitors;
|
||||
|
||||
static json::JsonObject ToJson(const EditorArgs& args);
|
||||
};
|
||||
|
||||
json::JsonObject GetPersistFancyZonesJSON(const std::wstring& zonesSettingsFileName, const std::wstring& appZoneHistoryFileName);
|
||||
|
||||
// replace zones-settings: applied layouts
|
||||
|
@ -884,39 +884,4 @@ namespace FancyZonesUnitTests
|
||||
Assert::AreEqual((size_t)10, deviceInfoMap->size());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CLASS(EditorArgsUnitTests)
|
||||
{
|
||||
TEST_METHOD(MonitorToJson)
|
||||
{
|
||||
MonitorInfo monitor{ L"AOC2460#4&fe3a015&0&UID65793", L"{39B25DD2-130D-4B5D-8851-4791D66B1539}", 144, -10, 0, 1920, 1080, true };
|
||||
|
||||
const auto expectedStr = L"{\"monitor\": \"AOC2460#4&fe3a015&0&UID65793\", \"virtual-desktop\": \"{39B25DD2-130D-4B5D-8851-4791D66B1539}\", \"dpi\": 144, \"top-coordinate\": -10, \"left-coordinate\": 0, \"width\": 1920, \"height\": 1080, \"is-selected\": true}";
|
||||
const auto expected = json::JsonObject::Parse(expectedStr);
|
||||
|
||||
const auto actual = MonitorInfo::ToJson(monitor);
|
||||
|
||||
auto res = CustomAssert::CompareJsonObjects(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
|
||||
TEST_METHOD(EditorArgsToJson)
|
||||
{
|
||||
MonitorInfo monitor1{ L"AOC2460#4&fe3a015&0&UID65793", L"{39B25DD2-130D-4B5D-8851-4791D66B1539}", 144, -10, 0, 1920, 1080, true };
|
||||
MonitorInfo monitor2{ L"AOC2460#4&fe3a015&0&UID65793", L"{39B25DD2-130D-4B5D-8851-4791D66B1538}", 96, 0, 1920, 1920, 1080, false };
|
||||
EditorArgs args{
|
||||
1, true, std::vector<MonitorInfo>{ monitor1, monitor2 }
|
||||
};
|
||||
|
||||
const std::wstring expectedMonitor1 = L"{\"monitor\": \"AOC2460#4&fe3a015&0&UID65793\", \"virtual-desktop\": \"{39B25DD2-130D-4B5D-8851-4791D66B1539}\", \"dpi\": 144, \"top-coordinate\": -10, \"left-coordinate\": 0, \"width\": 1920, \"height\": 1080, \"is-selected\": true}";
|
||||
const std::wstring expectedMonitor2 = L"{\"monitor\": \"AOC2460#4&fe3a015&0&UID65793\", \"virtual-desktop\": \"{39B25DD2-130D-4B5D-8851-4791D66B1538}\", \"dpi\": 96, \"top-coordinate\": 0, \"left-coordinate\": 1920, \"width\": 1920, \"height\": 1080, \"is-selected\": false}";
|
||||
const std::wstring expectedStr = L"{\"process-id\": 1, \"span-zones-across-monitors\": true, \"monitors\": [" + expectedMonitor1 + L", " + expectedMonitor2 + L"]}";
|
||||
|
||||
const auto expected = json::JsonObject::Parse(expectedStr);
|
||||
const auto actual = EditorArgs::ToJson(args);
|
||||
|
||||
auto res = CustomAssert::CompareJsonObjects(expected, actual);
|
||||
Assert::IsTrue(res.first, res.second.c_str());
|
||||
}
|
||||
};
|
||||
}
|
@ -79,12 +79,14 @@ namespace FancyZonesEditor
|
||||
|
||||
_themeManager = new ThemeManager(this);
|
||||
|
||||
if (!FancyZonesEditorIO.ParseParams().Result)
|
||||
var parseResult = FancyZonesEditorIO.ParseParams();
|
||||
if (!parseResult.Result)
|
||||
{
|
||||
FancyZonesEditorIO.ParseCommandLineArguments();
|
||||
Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
|
||||
MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
|
||||
}
|
||||
|
||||
var parseResult = FancyZonesEditorIO.ParseAppliedLayouts();
|
||||
parseResult = FancyZonesEditorIO.ParseAppliedLayouts();
|
||||
if (!parseResult.Result)
|
||||
{
|
||||
Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
|
||||
|
@ -83,6 +83,8 @@ namespace FancyZonesEditor
|
||||
Preview.Width = workArea.Width;
|
||||
Preview.Height = workArea.Height;
|
||||
|
||||
_model.ScaleLayout(workAreaWidth: workArea.Width, workAreaHeight: workArea.Height);
|
||||
|
||||
UIElementCollection previewChildren = Preview.Children;
|
||||
int previewChildrenCount = previewChildren.Count;
|
||||
while (previewChildrenCount < _model.Zones.Count)
|
||||
|
@ -263,11 +263,8 @@ namespace FancyZonesEditor
|
||||
|
||||
private void RenderCanvasPreview(CanvasLayoutModel canvas)
|
||||
{
|
||||
var workArea = canvas.CanvasRect;
|
||||
if (workArea.Width == 0 || workArea.Height == 0)
|
||||
{
|
||||
workArea = App.Overlay.WorkArea;
|
||||
}
|
||||
var screenWorkArea = App.Overlay.WorkArea;
|
||||
canvas.ScaleLayout(workAreaWidth: screenWorkArea.Width, workAreaHeight: screenWorkArea.Height);
|
||||
|
||||
Viewbox viewbox = new Viewbox
|
||||
{
|
||||
@ -276,8 +273,8 @@ namespace FancyZonesEditor
|
||||
Body.Children.Add(viewbox);
|
||||
Canvas frame = new Canvas
|
||||
{
|
||||
Width = workArea.Width,
|
||||
Height = workArea.Height,
|
||||
Width = screenWorkArea.Width,
|
||||
Height = screenWorkArea.Height,
|
||||
};
|
||||
viewbox.Child = frame;
|
||||
|
||||
|
@ -111,7 +111,13 @@
|
||||
FontWeight="SemiBold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Opacity="0.6"
|
||||
Foreground="{Binding (TextElement.Foreground), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}}" />
|
||||
<TextBlock Name="ScalingText"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
Text="{Binding Scaling}"
|
||||
Margin="0,0,0,0"
|
||||
FontSize="8"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="{Binding (TextElement.Foreground), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
@ -13,9 +13,9 @@ namespace FancyZonesEditor.Utils
|
||||
{
|
||||
public string MonitorName { get; set; }
|
||||
|
||||
public string VirtualDesktopId { get; set; }
|
||||
public Size MonitorSize { get; set; }
|
||||
|
||||
public Rect UnscaledBounds { get; private set; }
|
||||
public string VirtualDesktopId { get; set; }
|
||||
|
||||
public Rect ScaledBounds { get; private set; }
|
||||
|
||||
@ -23,35 +23,24 @@ namespace FancyZonesEditor.Utils
|
||||
|
||||
public int Dpi { get; set; }
|
||||
|
||||
public Device(string monitorName, string virtualDesktopId, int dpi, Rect bounds, Rect workArea)
|
||||
public Device(string monitorName, string virtualDesktopId, int dpi, Rect workArea, Size monitorSize)
|
||||
{
|
||||
MonitorName = monitorName;
|
||||
VirtualDesktopId = virtualDesktopId;
|
||||
Dpi = dpi;
|
||||
WorkAreaRect = workArea;
|
||||
UnscaledBounds = bounds;
|
||||
ScaledBounds = bounds;
|
||||
MonitorSize = monitorSize;
|
||||
}
|
||||
|
||||
public Device(Rect bounds, Rect workArea)
|
||||
public Device(Rect workArea, Size monitorSize)
|
||||
{
|
||||
WorkAreaRect = workArea;
|
||||
UnscaledBounds = bounds;
|
||||
ScaledBounds = bounds;
|
||||
MonitorSize = monitorSize;
|
||||
}
|
||||
|
||||
public void Scale(double scaleFactor)
|
||||
{
|
||||
WorkAreaRect = new Rect(Math.Round(WorkAreaRect.X * scaleFactor), Math.Round(WorkAreaRect.Y * scaleFactor), Math.Round(WorkAreaRect.Width * scaleFactor), Math.Round(WorkAreaRect.Height * scaleFactor));
|
||||
ScaledBounds = new Rect(Math.Round(ScaledBounds.X * scaleFactor), Math.Round(ScaledBounds.Y * scaleFactor), Math.Round(ScaledBounds.Width * scaleFactor), Math.Round(ScaledBounds.Height * scaleFactor));
|
||||
}
|
||||
|
||||
public double ScaleCoordinate(double coordinate)
|
||||
{
|
||||
float dpi = Dpi != 0 ? Dpi : 96f;
|
||||
double scaleFactor = 96f / dpi;
|
||||
|
||||
return Math.Round(coordinate * scaleFactor);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -62,13 +51,11 @@ namespace FancyZonesEditor.Utils
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Virtual desktop: {0}{1}", VirtualDesktopId, Environment.NewLine);
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "DPI: {0}{1}", Dpi, Environment.NewLine);
|
||||
|
||||
string monitorSize = MonitorSize.ToString(CultureInfo.InvariantCulture);
|
||||
string workArea = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height);
|
||||
string bounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height);
|
||||
string scaledBounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", ScaledBounds.X, ScaledBounds.Y, ScaledBounds.Width, ScaledBounds.Height);
|
||||
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Monitor size: {0}{1}", monitorSize, Environment.NewLine);
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Work area: {0}{1}", workArea, Environment.NewLine);
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Unscaled bounds: {0}{1}", bounds, Environment.NewLine);
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Scaled bounds: {0}{1}", scaledBounds, Environment.NewLine);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
public Device Device { get; set; }
|
||||
|
||||
public Monitor(Rect bounds, Rect workArea)
|
||||
public Monitor(Rect workArea, Size monitorSize)
|
||||
{
|
||||
Window = new LayoutOverlayWindow();
|
||||
Settings = new LayoutSettings();
|
||||
Device = new Device(bounds, workArea);
|
||||
Device = new Device(workArea, monitorSize);
|
||||
|
||||
if (App.DebugMode)
|
||||
{
|
||||
@ -41,10 +41,10 @@ namespace FancyZonesEditor.Models
|
||||
Window.Height = workArea.Height;
|
||||
}
|
||||
|
||||
public Monitor(string monitorName, string virtualDesktop, int dpi, Rect bounds, Rect workArea)
|
||||
: this(bounds, workArea)
|
||||
public Monitor(string monitorName, string virtualDesktop, int dpi, Rect workArea, Size monitorSize)
|
||||
: this(workArea, monitorSize)
|
||||
{
|
||||
Device = new Device(monitorName, virtualDesktop, dpi, bounds, workArea);
|
||||
Device = new Device(monitorName, virtualDesktop, dpi, workArea, monitorSize);
|
||||
}
|
||||
|
||||
public void Scale(double scaleFactor)
|
||||
|
@ -2,7 +2,9 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using FancyZonesEditor.ViewModels;
|
||||
|
||||
namespace FancyZonesEditor.Utils
|
||||
@ -17,6 +19,7 @@ namespace FancyZonesEditor.Utils
|
||||
ScreenBoundsHeight = height;
|
||||
ScreenBoundsWidth = width;
|
||||
DPI = dpi;
|
||||
Scaling = string.Format(CultureInfo.InvariantCulture, format: "{0}%", arg0: (int)Math.Round(dpi * 100 / 96.0));
|
||||
Selected = selected;
|
||||
}
|
||||
|
||||
@ -44,6 +47,8 @@ namespace FancyZonesEditor.Utils
|
||||
|
||||
public int DPI { get; set; }
|
||||
|
||||
public string Scaling { get; set; }
|
||||
|
||||
public string Dimensions
|
||||
{
|
||||
get
|
||||
|
@ -85,9 +85,13 @@ namespace FancyZonesEditor.Utils
|
||||
|
||||
public int TopCoordinate { get; set; }
|
||||
|
||||
public int Width { get; set; }
|
||||
public int WorkAreaWidth { get; set; }
|
||||
|
||||
public int Height { get; set; }
|
||||
public int WorkAreaHeight { get; set; }
|
||||
|
||||
public int MonitorWidth { get; set; }
|
||||
|
||||
public int MonitorHeight { get; set; }
|
||||
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
@ -108,6 +112,11 @@ namespace FancyZonesEditor.Utils
|
||||
sb.Append("Y: ");
|
||||
sb.AppendLine(TopCoordinate.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
sb.Append("Width: ");
|
||||
sb.AppendLine(MonitorWidth.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append("Height: ");
|
||||
sb.AppendLine(MonitorHeight.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
@ -278,179 +287,6 @@ namespace FancyZonesEditor.Utils
|
||||
FancyZonesEditorParamsFile = localAppDataDir + ParamsFile;
|
||||
}
|
||||
|
||||
// All strings in this function shouldn't be localized.
|
||||
public static void ParseCommandLineArguments()
|
||||
{
|
||||
Logger.LogTrace();
|
||||
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
|
||||
if (args.Length < 2 && !App.DebugMode)
|
||||
{
|
||||
MessageBox.Show(Properties.Resources.Error_Not_Standalone_App, Properties.Resources.Error_Message_Box_Title);
|
||||
((App)Application.Current).Shutdown();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
/*
|
||||
* Divider: /
|
||||
* Parts:
|
||||
* (1) Process id
|
||||
* (2) Span zones across monitors
|
||||
* (3) Monitor id where the Editor should be opened
|
||||
* (4) Monitors count
|
||||
*
|
||||
* Data for each monitor:
|
||||
* (5) Monitor id
|
||||
* (6) DPI
|
||||
* (7) work area left
|
||||
* (8) work area top
|
||||
* (9) work area width
|
||||
* (10) work area height
|
||||
* ...
|
||||
* Using CultureInfo.InvariantCulture since this is us parsing our own data
|
||||
*/
|
||||
var argsParts = args[1].Split('/');
|
||||
|
||||
// Process ID
|
||||
App.PowerToysPID = int.Parse(argsParts[(int)CmdArgs.PowerToysPID], CultureInfo.InvariantCulture);
|
||||
|
||||
// Span zones across monitors
|
||||
App.Overlay.SpanZonesAcrossMonitors = int.Parse(argsParts[(int)CmdArgs.SpanZones], CultureInfo.InvariantCulture) == 1;
|
||||
|
||||
// Target monitor id
|
||||
string targetMonitorName = argsParts[(int)CmdArgs.TargetMonitorId];
|
||||
|
||||
if (!App.Overlay.SpanZonesAcrossMonitors)
|
||||
{
|
||||
// Test launch with custom monitors configuration
|
||||
bool isCustomMonitorConfigurationMode = targetMonitorName.StartsWith("Monitor#", StringComparison.Ordinal);
|
||||
if (isCustomMonitorConfigurationMode)
|
||||
{
|
||||
App.Overlay.Monitors.Clear();
|
||||
}
|
||||
|
||||
// Monitors count
|
||||
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount], CultureInfo.InvariantCulture);
|
||||
|
||||
// Parse the native monitor data
|
||||
List<NativeMonitorData> nativeMonitorData = new List<NativeMonitorData>();
|
||||
const int monitorArgsCount = 6;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var nativeData = default(NativeMonitorData);
|
||||
nativeData.Monitor = argsParts[(int)CmdArgs.MonitorId + (i * monitorArgsCount)];
|
||||
nativeData.Dpi = int.Parse(argsParts[(int)CmdArgs.DPI + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.LeftCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorLeft + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.TopCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorTop + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.Width = int.Parse(argsParts[(int)CmdArgs.MonitorWidth + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.Height = int.Parse(argsParts[(int)CmdArgs.MonitorHeight + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
|
||||
nativeMonitorData.Add(nativeData);
|
||||
}
|
||||
|
||||
var monitors = App.Overlay.Monitors;
|
||||
|
||||
// Update monitors data
|
||||
if (isCustomMonitorConfigurationMode)
|
||||
{
|
||||
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
||||
{
|
||||
var splittedId = nativeData.Monitor.Split('_');
|
||||
|
||||
Rect bounds = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||
|
||||
Monitor monitor = new Monitor(bounds, bounds);
|
||||
monitor.Device.MonitorName = nativeData.Monitor.Substring(0, nativeData.Monitor.LastIndexOf("_", StringComparison.Ordinal));
|
||||
monitor.Device.VirtualDesktopId = nativeData.Monitor.Substring(nativeData.Monitor.LastIndexOf("_", StringComparison.Ordinal) + 1);
|
||||
monitor.Device.Dpi = nativeData.Dpi;
|
||||
|
||||
monitors.Add(monitor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
||||
{
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||
if (nativeData.IsSelected)
|
||||
{
|
||||
targetMonitorName = nativeData.Monitor;
|
||||
}
|
||||
|
||||
var monitor = new Monitor(workArea, workArea);
|
||||
monitor.Device.MonitorName = nativeData.Monitor.Substring(0, nativeData.Monitor.LastIndexOf("_", StringComparison.Ordinal));
|
||||
monitor.Device.VirtualDesktopId = nativeData.Monitor.Substring(nativeData.Monitor.LastIndexOf("_", StringComparison.Ordinal) + 1);
|
||||
monitor.Device.Dpi = nativeData.Dpi;
|
||||
|
||||
App.Overlay.AddMonitor(monitor);
|
||||
}
|
||||
}
|
||||
|
||||
// Set active desktop
|
||||
for (int i = 0; i < monitors.Count; i++)
|
||||
{
|
||||
var monitor = monitors[i];
|
||||
|
||||
var monitorName = targetMonitorName.Substring(0, targetMonitorName.LastIndexOf("_", StringComparison.Ordinal));
|
||||
var virtualDesktop = targetMonitorName.Substring(targetMonitorName.LastIndexOf("_", StringComparison.Ordinal) + 1);
|
||||
|
||||
if (monitor.Device.MonitorName == monitorName && monitor.Device.VirtualDesktopId == virtualDesktop)
|
||||
{
|
||||
App.Overlay.CurrentDesktop = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Monitors count
|
||||
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount], CultureInfo.InvariantCulture);
|
||||
|
||||
// Parse the native monitor data
|
||||
List<NativeMonitorData> nativeMonitorData = new List<NativeMonitorData>();
|
||||
const int monitorArgsCount = 6;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var nativeData = default(NativeMonitorData);
|
||||
nativeData.Monitor = argsParts[(int)CmdArgs.MonitorId + (i * monitorArgsCount)];
|
||||
nativeData.Dpi = int.Parse(argsParts[(int)CmdArgs.DPI + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.LeftCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorLeft + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.TopCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorTop + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.Width = int.Parse(argsParts[(int)CmdArgs.MonitorWidth + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
nativeData.Height = int.Parse(argsParts[(int)CmdArgs.MonitorHeight + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||
|
||||
nativeMonitorData.Add(nativeData);
|
||||
}
|
||||
|
||||
Rect workAreaUnion = default;
|
||||
|
||||
// Update monitors data
|
||||
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
||||
{
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||
workAreaUnion = Rect.Union(workAreaUnion, workArea);
|
||||
}
|
||||
|
||||
var monitor = new Monitor(workAreaUnion, workAreaUnion);
|
||||
|
||||
var monitorName = targetMonitorName.Substring(0, targetMonitorName.LastIndexOf("_", StringComparison.Ordinal));
|
||||
var virtualDesktop = targetMonitorName.Substring(targetMonitorName.LastIndexOf("_", StringComparison.Ordinal) + 1);
|
||||
monitor.Device.MonitorName = monitorName;
|
||||
monitor.Device.VirtualDesktopId = virtualDesktop;
|
||||
|
||||
App.Overlay.Monitors.Add(monitor);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Invalid command line arguments: " + args[1], ex);
|
||||
MessageBox.Show(Properties.Resources.Error_Invalid_Arguments, Properties.Resources.Error_Message_Box_Title);
|
||||
((App)Application.Current).Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public ParsingResult ParseParams()
|
||||
{
|
||||
Logger.LogTrace();
|
||||
@ -477,14 +313,16 @@ namespace FancyZonesEditor.Utils
|
||||
|
||||
foreach (NativeMonitorData nativeData in editorParams.Monitors)
|
||||
{
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.WorkAreaWidth, nativeData.WorkAreaHeight);
|
||||
if (nativeData.IsSelected)
|
||||
{
|
||||
targetMonitorId = nativeData.Monitor;
|
||||
targetVirtualDesktop = nativeData.VirtualDesktop;
|
||||
}
|
||||
|
||||
var monitor = new Monitor(workArea, workArea);
|
||||
Size monitorSize = new Size(nativeData.MonitorWidth, nativeData.MonitorHeight);
|
||||
|
||||
var monitor = new Monitor(workArea, monitorSize);
|
||||
monitor.Device.MonitorName = nativeData.Monitor;
|
||||
monitor.Device.VirtualDesktopId = nativeData.VirtualDesktop;
|
||||
monitor.Device.Dpi = nativeData.Dpi;
|
||||
@ -512,9 +350,10 @@ namespace FancyZonesEditor.Utils
|
||||
}
|
||||
|
||||
var nativeData = editorParams.Monitors[0];
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.WorkAreaWidth, nativeData.WorkAreaHeight);
|
||||
Size monitorSize = new Size(nativeData.MonitorWidth, nativeData.MonitorHeight);
|
||||
|
||||
var monitor = new Monitor(workArea, workArea);
|
||||
var monitor = new Monitor(workArea, monitorSize);
|
||||
monitor.Device.MonitorName = nativeData.Monitor;
|
||||
monitor.Device.VirtualDesktopId = nativeData.VirtualDesktop;
|
||||
|
||||
|
@ -34,11 +34,11 @@ namespace FancyZonesEditor.ViewModels
|
||||
foreach (var monitor in App.Overlay.Monitors)
|
||||
{
|
||||
Device device = monitor.Device;
|
||||
var bounds = device.ScaledBounds;
|
||||
maxDimension = System.Math.Max(System.Math.Max(maxDimension, bounds.Height), bounds.Width);
|
||||
minDimension = System.Math.Min(System.Math.Min(minDimension, bounds.Height), bounds.Width);
|
||||
var size = device.MonitorSize;
|
||||
maxDimension = System.Math.Max(System.Math.Max(maxDimension, size.Height), size.Width);
|
||||
minDimension = System.Math.Min(System.Math.Min(minDimension, size.Height), size.Width);
|
||||
|
||||
MonitorInfoForViewModel.Add(new MonitorInfoModel(i, (int)bounds.Height, (int)bounds.Width, device.Dpi, App.Overlay.CurrentDesktop == i - 1));
|
||||
MonitorInfoForViewModel.Add(new MonitorInfoModel(i, (int)size.Height, (int)size.Width, device.Dpi, App.Overlay.CurrentDesktop == i - 1));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user