mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
[FancyZones] "Match not found" error fix (#11840)
This commit is contained in:
parent
eeea6b3bae
commit
2dc82f31b3
@ -683,8 +683,10 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
* Data for each monitor:
|
* Data for each monitor:
|
||||||
* (5) Monitor id
|
* (5) Monitor id
|
||||||
* (6) DPI
|
* (6) DPI
|
||||||
* (7) monitor left
|
* (7) work area left
|
||||||
* (8) monitor top
|
* (8) work area top
|
||||||
|
* (9) work area width
|
||||||
|
* (10) work area height
|
||||||
* ...
|
* ...
|
||||||
*/
|
*/
|
||||||
std::wstring params;
|
std::wstring params;
|
||||||
@ -693,7 +695,10 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
const bool spanZonesAcrossMonitors = m_settings->GetSettings()->spanZonesAcrossMonitors;
|
const bool spanZonesAcrossMonitors = m_settings->GetSettings()->spanZonesAcrossMonitors;
|
||||||
params += std::to_wstring(spanZonesAcrossMonitors) + divider; /* Span zones */
|
params += std::to_wstring(spanZonesAcrossMonitors) + divider; /* Span zones */
|
||||||
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
||||||
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
|
||||||
|
m_dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&] {
|
||||||
|
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
||||||
|
} }).wait();
|
||||||
|
|
||||||
if (spanZonesAcrossMonitors)
|
if (spanZonesAcrossMonitors)
|
||||||
{
|
{
|
||||||
@ -704,8 +709,9 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||||
|
|
||||||
bool showDpiWarning = false;
|
bool showDpiWarning = false;
|
||||||
int prevDpiX = -1, prevDpiY = -1;
|
int prevDpi = -1;
|
||||||
std::wstring monitorsDataStr;
|
std::wstring monitorsDataStr;
|
||||||
|
|
||||||
for (auto& monitorData : allMonitors)
|
for (auto& monitorData : allMonitors)
|
||||||
{
|
{
|
||||||
HMONITOR monitor = monitorData.first;
|
HMONITOR monitor = monitorData.first;
|
||||||
@ -718,30 +724,30 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
{
|
{
|
||||||
params += monitorId + divider; /* Monitor id where the Editor should be opened */
|
params += monitorId + divider; /* Monitor id where the Editor should be opened */
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorsDataStr += std::move(monitorId) + divider; /* Monitor id */
|
UINT dpi = 0;
|
||||||
UINT dpiX = 0;
|
if (DPIAware::GetScreenDPIForMonitor(monitor, dpi) != S_OK)
|
||||||
UINT dpiY = 0;
|
|
||||||
if (GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY) == S_OK)
|
|
||||||
{
|
{
|
||||||
monitorsDataStr += std::to_wstring(dpiX) + divider; /* DPI */
|
continue;
|
||||||
if (spanZonesAcrossMonitors && prevDpiX != -1 && (prevDpiX != dpiX || prevDpiY != dpiY))
|
}
|
||||||
{
|
|
||||||
showDpiWarning = true;
|
if (spanZonesAcrossMonitors && prevDpi != -1 && prevDpi != dpi)
|
||||||
}
|
{
|
||||||
|
showDpiWarning = true;
|
||||||
prevDpiX = dpiX;
|
|
||||||
prevDpiY = dpiY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorsDataStr += std::to_wstring(monitorInfo.rcMonitor.left) + divider; /* Top coordinate */
|
monitorsDataStr += std::move(monitorId) + divider; /* Monitor id */
|
||||||
monitorsDataStr += std::to_wstring(monitorInfo.rcMonitor.top) + divider; /* Left coordinate */
|
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 += std::to_wstring(allMonitors.size()) + divider; /* Monitors count */
|
||||||
params += monitorsDataStr;
|
params += monitorsDataStr;
|
||||||
|
|
||||||
FancyZonesDataInstance().SaveFancyZonesEditorParameters(spanZonesAcrossMonitors, virtualDesktopId.get(), targetMonitor); /* Write parameters to json file */
|
FancyZonesDataInstance().SaveFancyZonesEditorParameters(spanZonesAcrossMonitors, virtualDesktopId.get(), targetMonitor, allMonitors); /* Write parameters to json file */
|
||||||
|
|
||||||
if (showDpiWarning)
|
if (showDpiWarning)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "CallTracer.h"
|
#include "CallTracer.h"
|
||||||
|
|
||||||
|
#include <common/Display/dpi_aware.h>
|
||||||
#include <common/utils/json.h>
|
#include <common/utils/json.h>
|
||||||
#include <FancyZonesLib/util.h>
|
#include <FancyZonesLib/util.h>
|
||||||
|
|
||||||
@ -584,7 +585,7 @@ void FancyZonesData::SaveAppZoneHistory() const
|
|||||||
JSONHelpers::SaveAppZoneHistory(appZoneHistoryFileName, appZoneHistoryMap);
|
JSONHelpers::SaveAppZoneHistory(appZoneHistoryFileName, appZoneHistoryMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesData::SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor) const
|
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 */
|
JSONHelpers::EditorArgs argsJson; /* json arguments */
|
||||||
argsJson.processId = GetCurrentProcessId(); /* Process id */
|
argsJson.processId = GetCurrentProcessId(); /* Process id */
|
||||||
@ -599,6 +600,8 @@ void FancyZonesData::SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors
|
|||||||
monitorJson.id = monitorId;
|
monitorJson.id = monitorId;
|
||||||
monitorJson.top = monitorRect.top;
|
monitorJson.top = monitorRect.top;
|
||||||
monitorJson.left = monitorRect.left;
|
monitorJson.left = monitorRect.left;
|
||||||
|
monitorJson.width = monitorRect.right - monitorRect.left;
|
||||||
|
monitorJson.height = monitorRect.bottom - monitorRect.top;
|
||||||
monitorJson.isSelected = true;
|
monitorJson.isSelected = true;
|
||||||
monitorJson.dpi = 0; // unused
|
monitorJson.dpi = 0; // unused
|
||||||
|
|
||||||
@ -606,9 +609,6 @@ void FancyZonesData::SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<std::pair<HMONITOR, MONITORINFOEX>> allMonitors;
|
|
||||||
allMonitors = FancyZonesUtils::GetAllMonitorInfo<&MONITORINFOEX::rcWork>();
|
|
||||||
|
|
||||||
// device id map for correct device ids
|
// device id map for correct device ids
|
||||||
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
std::unordered_map<std::wstring, DWORD> displayDeviceIdxMap;
|
||||||
|
|
||||||
@ -629,16 +629,18 @@ void FancyZonesData::SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors
|
|||||||
|
|
||||||
monitorJson.id = monitorId; /* Monitor id */
|
monitorJson.id = monitorId; /* Monitor id */
|
||||||
|
|
||||||
UINT dpiX = 0;
|
UINT dpi = 0;
|
||||||
UINT dpiY = 0;
|
if (DPIAware::GetScreenDPIForMonitor(monitor, dpi) != S_OK)
|
||||||
if (GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY) == S_OK)
|
|
||||||
{
|
{
|
||||||
monitorJson.dpi = dpiX; /* DPI */
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorJson.top = monitorInfo.rcMonitor.top; /* Top coordinate */
|
monitorJson.dpi = dpi; /* DPI */
|
||||||
monitorJson.left = monitorInfo.rcMonitor.left; /* Left coordinate */
|
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 */
|
argsJson.monitors.emplace_back(std::move(monitorJson)); /* add monitor data */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public:
|
|||||||
void SaveZoneSettings() const;
|
void SaveZoneSettings() const;
|
||||||
void SaveAppZoneHistory() const;
|
void SaveAppZoneHistory() const;
|
||||||
|
|
||||||
void SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor) const;
|
void SaveFancyZonesEditorParameters(bool spanZonesAcrossMonitors, const std::wstring& virtualDesktopId, const HMONITOR& targetMonitor, const std::vector<std::pair<HMONITOR, MONITORINFOEX>>& allMonitors) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(UNIT_TESTS)
|
#if defined(UNIT_TESTS)
|
||||||
|
@ -514,6 +514,8 @@ namespace JSONHelpers
|
|||||||
result.SetNamedValue(NonLocalizable::MonitorId, json::value(monitor.id));
|
result.SetNamedValue(NonLocalizable::MonitorId, json::value(monitor.id));
|
||||||
result.SetNamedValue(NonLocalizable::TopCoordinate, json::value(monitor.top));
|
result.SetNamedValue(NonLocalizable::TopCoordinate, json::value(monitor.top));
|
||||||
result.SetNamedValue(NonLocalizable::LeftCoordinate, json::value(monitor.left));
|
result.SetNamedValue(NonLocalizable::LeftCoordinate, json::value(monitor.left));
|
||||||
|
result.SetNamedValue(L"width", json::value(monitor.width));
|
||||||
|
result.SetNamedValue(L"height", json::value(monitor.height));
|
||||||
result.SetNamedValue(NonLocalizable::IsSelected, json::value(monitor.isSelected));
|
result.SetNamedValue(NonLocalizable::IsSelected, json::value(monitor.isSelected));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -75,6 +75,8 @@ namespace JSONHelpers
|
|||||||
std::wstring id;
|
std::wstring id;
|
||||||
int top;
|
int top;
|
||||||
int left;
|
int left;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
bool isSelected = false;
|
bool isSelected = false;
|
||||||
|
|
||||||
static json::JsonObject ToJson(const MonitorInfo& monitor);
|
static json::JsonObject ToJson(const MonitorInfo& monitor);
|
||||||
|
@ -21,24 +21,20 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
public int Dpi { get; set; }
|
public int Dpi { get; set; }
|
||||||
|
|
||||||
public bool Primary { get; private set; }
|
public Device(string id, int dpi, Rect bounds, Rect workArea)
|
||||||
|
|
||||||
public Device(string id, int dpi, Rect bounds, Rect workArea, bool primary)
|
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Dpi = dpi;
|
Dpi = dpi;
|
||||||
WorkAreaRect = workArea;
|
WorkAreaRect = workArea;
|
||||||
UnscaledBounds = bounds;
|
UnscaledBounds = bounds;
|
||||||
ScaledBounds = bounds;
|
ScaledBounds = bounds;
|
||||||
Primary = primary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Device(Rect bounds, Rect workArea, bool primary)
|
public Device(Rect bounds, Rect workArea)
|
||||||
{
|
{
|
||||||
WorkAreaRect = workArea;
|
WorkAreaRect = workArea;
|
||||||
UnscaledBounds = bounds;
|
UnscaledBounds = bounds;
|
||||||
ScaledBounds = bounds;
|
ScaledBounds = bounds;
|
||||||
Primary = primary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Scale(double scaleFactor)
|
public void Scale(double scaleFactor)
|
||||||
@ -61,7 +57,6 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
sb.AppendFormat(CultureInfo.InvariantCulture, "ID: {0}{1}", Id, Environment.NewLine);
|
sb.AppendFormat(CultureInfo.InvariantCulture, "ID: {0}{1}", Id, Environment.NewLine);
|
||||||
sb.AppendFormat(CultureInfo.InvariantCulture, "DPI: {0}{1}", Dpi, Environment.NewLine);
|
sb.AppendFormat(CultureInfo.InvariantCulture, "DPI: {0}{1}", Dpi, Environment.NewLine);
|
||||||
sb.AppendFormat(CultureInfo.InvariantCulture, "Is primary: {0}{1}", Primary, Environment.NewLine);
|
|
||||||
|
|
||||||
string workArea = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height);
|
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 bounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height);
|
||||||
|
@ -187,6 +187,14 @@ namespace FancyZonesEditor
|
|||||||
return model.Type != LayoutType.Custom;
|
return model.Type != LayoutType.Custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InitModels()
|
||||||
|
{
|
||||||
|
foreach (var model in DefaultModels)
|
||||||
|
{
|
||||||
|
model.InitTemplateZones();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LayoutModel UpdateSelectedLayoutModel()
|
public LayoutModel UpdateSelectedLayoutModel()
|
||||||
{
|
{
|
||||||
LayoutModel foundModel = null;
|
LayoutModel foundModel = null;
|
||||||
|
@ -18,11 +18,11 @@ namespace FancyZonesEditor.Models
|
|||||||
|
|
||||||
public Device Device { get; set; }
|
public Device Device { get; set; }
|
||||||
|
|
||||||
public Monitor(Rect bounds, Rect workArea, bool primary)
|
public Monitor(Rect bounds, Rect workArea)
|
||||||
{
|
{
|
||||||
Window = new LayoutOverlayWindow();
|
Window = new LayoutOverlayWindow();
|
||||||
Settings = new LayoutSettings();
|
Settings = new LayoutSettings();
|
||||||
Device = new Device(bounds, workArea, primary);
|
Device = new Device(bounds, workArea);
|
||||||
|
|
||||||
if (App.DebugMode)
|
if (App.DebugMode)
|
||||||
{
|
{
|
||||||
@ -41,10 +41,10 @@ namespace FancyZonesEditor.Models
|
|||||||
Window.Height = workArea.Height;
|
Window.Height = workArea.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Monitor(string id, int dpi, Rect bounds, Rect workArea, bool primary)
|
public Monitor(string id, int dpi, Rect bounds, Rect workArea)
|
||||||
: this(bounds, workArea, primary)
|
: this(bounds, workArea)
|
||||||
{
|
{
|
||||||
Device = new Device(id, dpi, bounds, workArea, primary);
|
Device = new Device(id, dpi, bounds, workArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Scale(double scaleFactor)
|
public void Scale(double scaleFactor)
|
||||||
|
@ -139,7 +139,7 @@ namespace FancyZonesEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
Monitors.Clear();
|
Monitors.Clear();
|
||||||
Monitors.Add(new Monitor(bounds, workArea, true));
|
Monitors.Add(new Monitor(bounds, workArea));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,14 +158,6 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
WorkAreas = new List<Rect>();
|
WorkAreas = new List<Rect>();
|
||||||
Monitors = new List<Monitor>();
|
Monitors = new List<Monitor>();
|
||||||
|
|
||||||
var screens = System.Windows.Forms.Screen.AllScreens;
|
|
||||||
foreach (System.Windows.Forms.Screen screen in screens)
|
|
||||||
{
|
|
||||||
Rect bounds = new Rect(screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height);
|
|
||||||
Rect workArea = new Rect(screen.WorkingArea.X, screen.WorkingArea.Y, screen.WorkingArea.Width, screen.WorkingArea.Height);
|
|
||||||
Add(bounds, workArea, screen.Primary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show()
|
public void Show()
|
||||||
@ -352,12 +344,10 @@ namespace FancyZonesEditor
|
|||||||
_mainWindow.Topmost = false;
|
_mainWindow.Topmost = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Add(Rect bounds, Rect workArea, bool primary)
|
public void AddMonitor(Monitor monitor)
|
||||||
{
|
{
|
||||||
var monitor = new Monitor(bounds, workArea, primary);
|
|
||||||
|
|
||||||
bool inserted = false;
|
bool inserted = false;
|
||||||
var workAreaRect = workArea;
|
var workAreaRect = monitor.Device.WorkAreaRect;
|
||||||
for (int i = 0; i < Monitors.Count && !inserted; i++)
|
for (int i = 0; i < Monitors.Count && !inserted; i++)
|
||||||
{
|
{
|
||||||
var rect = Monitors[i].Device.WorkAreaRect;
|
var rect = Monitors[i].Device.WorkAreaRect;
|
||||||
|
@ -56,6 +56,8 @@ namespace FancyZonesEditor.Utils
|
|||||||
DPI,
|
DPI,
|
||||||
MonitorLeft,
|
MonitorLeft,
|
||||||
MonitorTop,
|
MonitorTop,
|
||||||
|
MonitorWidth,
|
||||||
|
MonitorHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsing cmd args
|
// parsing cmd args
|
||||||
@ -69,6 +71,10 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
public int TopCoordinate { get; set; }
|
public int TopCoordinate { get; set; }
|
||||||
|
|
||||||
|
public int Width { get; set; }
|
||||||
|
|
||||||
|
public int Height { get; set; }
|
||||||
|
|
||||||
public bool IsSelected { get; set; }
|
public bool IsSelected { get; set; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -258,8 +264,10 @@ namespace FancyZonesEditor.Utils
|
|||||||
* Data for each monitor:
|
* Data for each monitor:
|
||||||
* (5) Monitor id
|
* (5) Monitor id
|
||||||
* (6) DPI
|
* (6) DPI
|
||||||
* (7) monitor left
|
* (7) work area left
|
||||||
* (8) monitor top
|
* (8) work area top
|
||||||
|
* (9) work area width
|
||||||
|
* (10) work area height
|
||||||
* ...
|
* ...
|
||||||
* Using CultureInfo.InvariantCulture since this is us parsing our own data
|
* Using CultureInfo.InvariantCulture since this is us parsing our own data
|
||||||
*/
|
*/
|
||||||
@ -285,18 +293,10 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
// Monitors count
|
// Monitors count
|
||||||
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount], CultureInfo.InvariantCulture);
|
int count = int.Parse(argsParts[(int)CmdArgs.MonitorsCount], CultureInfo.InvariantCulture);
|
||||||
if (count != App.Overlay.DesktopsCount && !isCustomMonitorConfigurationMode)
|
|
||||||
{
|
|
||||||
MessageBox.Show(Properties.Resources.Error_Invalid_Arguments, Properties.Resources.Error_Message_Box_Title);
|
|
||||||
((App)Application.Current).Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
double primaryMonitorDPI = 96f;
|
|
||||||
double minimalUsedMonitorDPI = double.MaxValue;
|
|
||||||
|
|
||||||
// Parse the native monitor data
|
// Parse the native monitor data
|
||||||
List<NativeMonitorData> nativeMonitorData = new List<NativeMonitorData>();
|
List<NativeMonitorData> nativeMonitorData = new List<NativeMonitorData>();
|
||||||
const int monitorArgsCount = 4;
|
const int monitorArgsCount = 6;
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
var nativeData = default(NativeMonitorData);
|
var nativeData = default(NativeMonitorData);
|
||||||
@ -304,23 +304,13 @@ namespace FancyZonesEditor.Utils
|
|||||||
nativeData.Dpi = int.Parse(argsParts[(int)CmdArgs.DPI + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
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.LeftCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorLeft + (i * monitorArgsCount)], CultureInfo.InvariantCulture);
|
||||||
nativeData.TopCoordinate = int.Parse(argsParts[(int)CmdArgs.MonitorTop + (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);
|
nativeMonitorData.Add(nativeData);
|
||||||
|
|
||||||
if (nativeData.LeftCoordinate == 0 && nativeData.TopCoordinate == 0)
|
|
||||||
{
|
|
||||||
primaryMonitorDPI = nativeData.Dpi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minimalUsedMonitorDPI > nativeData.Dpi)
|
|
||||||
{
|
|
||||||
minimalUsedMonitorDPI = nativeData.Dpi;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var monitors = App.Overlay.Monitors;
|
var monitors = App.Overlay.Monitors;
|
||||||
double identifyScaleFactor = minimalUsedMonitorDPI / primaryMonitorDPI;
|
|
||||||
double scaleFactor = 96f / primaryMonitorDPI;
|
|
||||||
|
|
||||||
// Update monitors data
|
// Update monitors data
|
||||||
if (isCustomMonitorConfigurationMode)
|
if (isCustomMonitorConfigurationMode)
|
||||||
@ -331,10 +321,9 @@ namespace FancyZonesEditor.Utils
|
|||||||
int width = int.Parse(splittedId[1], CultureInfo.InvariantCulture);
|
int width = int.Parse(splittedId[1], CultureInfo.InvariantCulture);
|
||||||
int height = int.Parse(splittedId[2], CultureInfo.InvariantCulture);
|
int height = int.Parse(splittedId[2], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
Rect bounds = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, width, height);
|
Rect bounds = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||||
bool isPrimary = nativeData.LeftCoordinate == 0 && nativeData.TopCoordinate == 0;
|
|
||||||
|
|
||||||
Monitor monitor = new Monitor(bounds, bounds, isPrimary);
|
Monitor monitor = new Monitor(bounds, bounds);
|
||||||
monitor.Device.Id = nativeData.MonitorId;
|
monitor.Device.Id = nativeData.MonitorId;
|
||||||
monitor.Device.Dpi = nativeData.Dpi;
|
monitor.Device.Dpi = nativeData.Dpi;
|
||||||
|
|
||||||
@ -343,31 +332,19 @@ namespace FancyZonesEditor.Utils
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (Monitor monitor in monitors)
|
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
||||||
{
|
{
|
||||||
bool matchFound = false;
|
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||||
monitor.Scale(scaleFactor);
|
if (nativeData.IsSelected)
|
||||||
|
|
||||||
double scaledBoundX = (int)(monitor.Device.UnscaledBounds.X * identifyScaleFactor);
|
|
||||||
double scaledBoundY = (int)(monitor.Device.UnscaledBounds.Y * identifyScaleFactor);
|
|
||||||
|
|
||||||
foreach (NativeMonitorData nativeData in nativeMonitorData)
|
|
||||||
{
|
{
|
||||||
// Can't do an exact match since the rounding algorithm used by the framework is different from ours
|
targetMonitorName = nativeData.MonitorId;
|
||||||
if (scaledBoundX >= (nativeData.LeftCoordinate - 1) && scaledBoundX <= (nativeData.LeftCoordinate + 1) &&
|
|
||||||
scaledBoundY >= (nativeData.TopCoordinate - 1) && scaledBoundY <= (nativeData.TopCoordinate + 1))
|
|
||||||
{
|
|
||||||
monitor.Device.Id = nativeData.MonitorId;
|
|
||||||
monitor.Device.Dpi = nativeData.Dpi;
|
|
||||||
matchFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchFound == false)
|
var monitor = new Monitor(workArea, workArea);
|
||||||
{
|
monitor.Device.Id = nativeData.MonitorId;
|
||||||
MessageBox.Show(string.Format(Properties.Resources.Error_Monitor_Match_Not_Found, monitor.Device.UnscaledBounds.ToString()));
|
monitor.Device.Dpi = nativeData.Dpi;
|
||||||
}
|
|
||||||
|
App.Overlay.AddMonitor(monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,68 +390,25 @@ namespace FancyZonesEditor.Utils
|
|||||||
|
|
||||||
if (!App.Overlay.SpanZonesAcrossMonitors)
|
if (!App.Overlay.SpanZonesAcrossMonitors)
|
||||||
{
|
{
|
||||||
// Monitors count
|
|
||||||
if (editorParams.Monitors.Count != App.Overlay.DesktopsCount)
|
|
||||||
{
|
|
||||||
MessageBox.Show(Properties.Resources.Error_Invalid_Arguments, Properties.Resources.Error_Message_Box_Title);
|
|
||||||
((App)Application.Current).Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
string targetMonitorName = string.Empty;
|
string targetMonitorName = string.Empty;
|
||||||
|
|
||||||
double primaryMonitorDPI = 96f;
|
|
||||||
double minimalUsedMonitorDPI = double.MaxValue;
|
|
||||||
foreach (NativeMonitorData nativeData in editorParams.Monitors)
|
foreach (NativeMonitorData nativeData in editorParams.Monitors)
|
||||||
{
|
{
|
||||||
if (nativeData.LeftCoordinate == 0 && nativeData.TopCoordinate == 0)
|
Rect workArea = new Rect(nativeData.LeftCoordinate, nativeData.TopCoordinate, nativeData.Width, nativeData.Height);
|
||||||
{
|
|
||||||
primaryMonitorDPI = nativeData.Dpi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minimalUsedMonitorDPI > nativeData.Dpi)
|
|
||||||
{
|
|
||||||
minimalUsedMonitorDPI = nativeData.Dpi;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nativeData.IsSelected)
|
if (nativeData.IsSelected)
|
||||||
{
|
{
|
||||||
targetMonitorName = nativeData.MonitorId;
|
targetMonitorName = nativeData.MonitorId;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var monitors = App.Overlay.Monitors;
|
var monitor = new Monitor(workArea, workArea);
|
||||||
double identifyScaleFactor = minimalUsedMonitorDPI / primaryMonitorDPI;
|
monitor.Device.Id = nativeData.MonitorId;
|
||||||
double scaleFactor = 96f / primaryMonitorDPI;
|
monitor.Device.Dpi = nativeData.Dpi;
|
||||||
|
|
||||||
// Update monitors data
|
App.Overlay.AddMonitor(monitor);
|
||||||
foreach (Monitor monitor in monitors)
|
|
||||||
{
|
|
||||||
bool matchFound = false;
|
|
||||||
monitor.Scale(scaleFactor);
|
|
||||||
|
|
||||||
double scaledBoundX = (int)(monitor.Device.UnscaledBounds.X * identifyScaleFactor);
|
|
||||||
double scaledBoundY = (int)(monitor.Device.UnscaledBounds.Y * identifyScaleFactor);
|
|
||||||
|
|
||||||
foreach (NativeMonitorData nativeData in editorParams.Monitors)
|
|
||||||
{
|
|
||||||
// Can't do an exact match since the rounding algorithm used by the framework is different from ours
|
|
||||||
if (scaledBoundX >= (nativeData.LeftCoordinate - 1) && scaledBoundX <= (nativeData.LeftCoordinate + 1) &&
|
|
||||||
scaledBoundY >= (nativeData.TopCoordinate - 1) && scaledBoundY <= (nativeData.TopCoordinate + 1))
|
|
||||||
{
|
|
||||||
monitor.Device.Id = nativeData.MonitorId;
|
|
||||||
monitor.Device.Dpi = nativeData.Dpi;
|
|
||||||
matchFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matchFound == false)
|
|
||||||
{
|
|
||||||
MessageBox.Show(string.Format(Properties.Resources.Error_Monitor_Match_Not_Found, monitor.Device.UnscaledBounds.ToString()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set active desktop
|
// Set active desktop
|
||||||
|
var monitors = App.Overlay.Monitors;
|
||||||
for (int i = 0; i < monitors.Count; i++)
|
for (int i = 0; i < monitors.Count; i++)
|
||||||
{
|
{
|
||||||
var monitor = monitors[i];
|
var monitor = monitors[i];
|
||||||
@ -485,31 +419,6 @@ namespace FancyZonesEditor.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Update monitors data
|
|
||||||
foreach (Monitor monitor in App.Overlay.Monitors)
|
|
||||||
{
|
|
||||||
bool matchFound = false;
|
|
||||||
foreach (NativeMonitorData nativeData in editorParams.Monitors)
|
|
||||||
{
|
|
||||||
// Can't do an exact match since the rounding algorithm used by the framework is different from ours
|
|
||||||
if (monitor.Device.UnscaledBounds.X >= (nativeData.LeftCoordinate - 1) && monitor.Device.UnscaledBounds.X <= (nativeData.LeftCoordinate + 1) &&
|
|
||||||
monitor.Device.UnscaledBounds.Y >= (nativeData.TopCoordinate - 1) && monitor.Device.UnscaledBounds.Y <= (nativeData.TopCoordinate + 1))
|
|
||||||
{
|
|
||||||
monitor.Device.Id = nativeData.MonitorId;
|
|
||||||
monitor.Device.Dpi = nativeData.Dpi;
|
|
||||||
matchFound = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matchFound == false)
|
|
||||||
{
|
|
||||||
MessageBox.Show(string.Format(Properties.Resources.Error_Monitor_Match_Not_Found, monitor.Device.UnscaledBounds.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user