mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-22 08:11:25 +00:00
Almost working. Doesn't apply on my small monitor running at 150% scaling.
This commit is contained in:
parent
e562b29ecd
commit
3836aaa9d1
@ -186,14 +186,12 @@ namespace FancyZonesEditor.Models
|
|||||||
// Scale all the zones to the DPI and then pack them up to be marshalled.
|
// Scale all the zones to the DPI and then pack them up to be marshalled.
|
||||||
int zoneCount = zones.Length;
|
int zoneCount = zones.Length;
|
||||||
var zoneArray = new int[zoneCount * 4];
|
var zoneArray = new int[zoneCount * 4];
|
||||||
var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
|
|
||||||
float dpi = graphics.DpiX / 96;
|
|
||||||
for (int i = 0; i < zones.Length; i++)
|
for (int i = 0; i < zones.Length; i++)
|
||||||
{
|
{
|
||||||
var left = (int)(zones[i].X * dpi);
|
var left = (int)(zones[i].X * Settings.Dpi);
|
||||||
var top = (int)(zones[i].Y * dpi);
|
var top = (int)(zones[i].Y * Settings.Dpi);
|
||||||
var right = left + (int)(zones[i].Width * dpi);
|
var right = left + (int)(zones[i].Width * Settings.Dpi);
|
||||||
var bottom = top + (int)(zones[i].Height * dpi);
|
var bottom = top + (int)(zones[i].Height * Settings.Dpi);
|
||||||
|
|
||||||
var index = i * 4;
|
var index = i * 4;
|
||||||
zoneArray[index] = left;
|
zoneArray[index] = left;
|
||||||
@ -202,19 +200,8 @@ namespace FancyZonesEditor.Models
|
|||||||
zoneArray[index+3] = bottom;
|
zoneArray[index+3] = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] args = Environment.GetCommandLineArgs();
|
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
|
||||||
if (args.Length > 1)
|
persistZoneSet(Settings.UniqueKey, Settings.Monitor, _id, zoneCount, zoneArray);
|
||||||
{
|
|
||||||
string uniqueId = args[1];
|
|
||||||
uint monitor = 0;
|
|
||||||
if (args.Length > 3)
|
|
||||||
{
|
|
||||||
monitor = uint.Parse(args[4]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
|
|
||||||
persistZoneSet(uniqueId, monitor, _id, zoneCount, zoneArray);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string c_registryPath = Settings.RegistryPath + "\\Layouts";
|
private static readonly string c_registryPath = Settings.RegistryPath + "\\Layouts";
|
||||||
|
@ -23,21 +23,7 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
public Settings()
|
public Settings()
|
||||||
{
|
{
|
||||||
_workArea = System.Windows.SystemParameters.WorkArea;
|
ParseCommandLineArgs();
|
||||||
string[] args = Environment.GetCommandLineArgs();
|
|
||||||
if (args.Length > 2)
|
|
||||||
{
|
|
||||||
var foregroundWindow = uint.Parse(args[3]);
|
|
||||||
var screen = System.Windows.Forms.Screen.FromHandle(new IntPtr(foregroundWindow));
|
|
||||||
|
|
||||||
var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
|
|
||||||
float dpi = graphics.DpiX / 96;
|
|
||||||
_workArea = new Rect(
|
|
||||||
screen.WorkingArea.X / dpi,
|
|
||||||
screen.WorkingArea.Y / dpi,
|
|
||||||
screen.WorkingArea.Width / dpi,
|
|
||||||
screen.WorkingArea.Height / dpi);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
|
// Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
|
||||||
_defaultModels = new List<LayoutModel>(5);
|
_defaultModels = new List<LayoutModel>(5);
|
||||||
@ -62,9 +48,9 @@ namespace FancyZonesEditor
|
|||||||
|
|
||||||
_blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
|
_blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
|
||||||
|
|
||||||
_zoneCount = (int)Registry.GetValue(FullRegistryPath, "ZoneCount", 3);
|
_zoneCount = (int)Registry.GetValue(_uniqueRegistryPath, "ZoneCount", 3);
|
||||||
_spacing = (int)Registry.GetValue(FullRegistryPath, "Spacing", 16);
|
_spacing = (int)Registry.GetValue(_uniqueRegistryPath, "Spacing", 16);
|
||||||
_showSpacing = (int)Registry.GetValue(FullRegistryPath, "ShowSpacing", 1) == 1;
|
_showSpacing = (int)Registry.GetValue(_uniqueRegistryPath, "ShowSpacing", 1) == 1;
|
||||||
|
|
||||||
UpdateLayoutModels();
|
UpdateLayoutModels();
|
||||||
}
|
}
|
||||||
@ -78,7 +64,7 @@ namespace FancyZonesEditor
|
|||||||
if (_zoneCount != value)
|
if (_zoneCount != value)
|
||||||
{
|
{
|
||||||
_zoneCount = value;
|
_zoneCount = value;
|
||||||
Registry.SetValue(FullRegistryPath, "ZoneCount", _zoneCount, RegistryValueKind.DWord);
|
Registry.SetValue(_uniqueRegistryPath, "ZoneCount", _zoneCount, RegistryValueKind.DWord);
|
||||||
UpdateLayoutModels();
|
UpdateLayoutModels();
|
||||||
FirePropertyChanged("ZoneCount");
|
FirePropertyChanged("ZoneCount");
|
||||||
}
|
}
|
||||||
@ -95,7 +81,7 @@ namespace FancyZonesEditor
|
|||||||
if (_spacing != value)
|
if (_spacing != value)
|
||||||
{
|
{
|
||||||
_spacing = value;
|
_spacing = value;
|
||||||
Registry.SetValue(FullRegistryPath, "Spacing", _spacing, RegistryValueKind.DWord);
|
Registry.SetValue(_uniqueRegistryPath, "Spacing", _spacing, RegistryValueKind.DWord);
|
||||||
FirePropertyChanged("Spacing");
|
FirePropertyChanged("Spacing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +97,7 @@ namespace FancyZonesEditor
|
|||||||
if (_showSpacing != value)
|
if (_showSpacing != value)
|
||||||
{
|
{
|
||||||
_showSpacing = value;
|
_showSpacing = value;
|
||||||
Registry.SetValue(FullRegistryPath, "ShowSpacing", _showSpacing, RegistryValueKind.DWord);
|
Registry.SetValue(_uniqueRegistryPath, "ShowSpacing", _showSpacing, RegistryValueKind.DWord);
|
||||||
FirePropertyChanged("ShowSpacing");
|
FirePropertyChanged("ShowSpacing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,6 +140,25 @@ namespace FancyZonesEditor
|
|||||||
}
|
}
|
||||||
private Rect _workArea;
|
private Rect _workArea;
|
||||||
|
|
||||||
|
public static uint Monitor
|
||||||
|
{
|
||||||
|
get { return _monitor; }
|
||||||
|
}
|
||||||
|
private static uint _monitor;
|
||||||
|
|
||||||
|
public static String UniqueKey
|
||||||
|
{
|
||||||
|
get { return _uniqueKey; }
|
||||||
|
}
|
||||||
|
private static String _uniqueKey;
|
||||||
|
private String _uniqueRegistryPath;
|
||||||
|
|
||||||
|
public static float Dpi
|
||||||
|
{
|
||||||
|
get { return _dpi; }
|
||||||
|
}
|
||||||
|
private static float _dpi;
|
||||||
|
|
||||||
// UpdateLayoutModels
|
// UpdateLayoutModels
|
||||||
// Update the five default layouts based on the new ZoneCount
|
// Update the five default layouts based on the new ZoneCount
|
||||||
private void UpdateLayoutModels()
|
private void UpdateLayoutModels()
|
||||||
@ -251,7 +256,45 @@ namespace FancyZonesEditor
|
|||||||
_priorityGridModel.ColumnPercents = _gridModel.ColumnPercents;
|
_priorityGridModel.ColumnPercents = _gridModel.ColumnPercents;
|
||||||
_priorityGridModel.CellChildMap = _gridModel.CellChildMap;
|
_priorityGridModel.CellChildMap = _gridModel.CellChildMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ParseCommandLineArgs()
|
||||||
|
{
|
||||||
|
_workArea = System.Windows.SystemParameters.WorkArea;
|
||||||
|
_monitor = 0;
|
||||||
|
_uniqueKey = "";
|
||||||
|
_dpi = 1;
|
||||||
|
|
||||||
|
string[] args = Environment.GetCommandLineArgs();
|
||||||
|
if (args.Length == 5)
|
||||||
|
{
|
||||||
|
// 1 = unique key for per-monitor settings
|
||||||
|
// 2 = layoutid used to generate current layout
|
||||||
|
// 3 = handle to foreground window (used to figure out which monitor to show on)
|
||||||
|
// 4 = handle to monitor (passed back to engine to persist data)
|
||||||
|
|
||||||
|
_uniqueKey = args[1];
|
||||||
|
_uniqueRegistryPath = FullRegistryPath + "\\" + _uniqueKey;
|
||||||
|
|
||||||
|
var foregroundWindow = new IntPtr(uint.Parse(args[3]));
|
||||||
|
var screen = System.Windows.Forms.Screen.FromHandle(foregroundWindow);
|
||||||
|
|
||||||
|
var graphics = System.Drawing.Graphics.FromHwnd(foregroundWindow);
|
||||||
|
_dpi = graphics.DpiX / 96;
|
||||||
|
_workArea = new Rect(
|
||||||
|
screen.WorkingArea.X / _dpi,
|
||||||
|
screen.WorkingArea.Y / _dpi,
|
||||||
|
screen.WorkingArea.Width / _dpi,
|
||||||
|
screen.WorkingArea.Height / _dpi);
|
||||||
|
|
||||||
|
uint monitor = 0;
|
||||||
|
if (uint.TryParse(args[4], out monitor))
|
||||||
|
{
|
||||||
|
_monitor = monitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public IList<LayoutModel> DefaultModels { get { return _defaultModels; } }
|
public IList<LayoutModel> DefaultModels { get { return _defaultModels; } }
|
||||||
public ObservableCollection<LayoutModel> CustomModels
|
public ObservableCollection<LayoutModel> CustomModels
|
||||||
|
@ -237,7 +237,7 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
m_terminateEditorEvent.reset(CreateEvent(nullptr, true, false, nullptr));
|
m_terminateEditorEvent.reset(CreateEvent(nullptr, true, false, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
const HWND foregroundWindow = GetForegroundWindow();
|
const HWND foregroundWindow = GetForegroundWindow();
|
||||||
if (const HMONITOR monitor = MonitorFromWindow(foregroundWindow, MONITOR_DEFAULTTOPRIMARY))
|
if (const HMONITOR monitor = MonitorFromWindow(foregroundWindow, MONITOR_DEFAULTTOPRIMARY))
|
||||||
{
|
{
|
||||||
std::shared_lock readLock(m_lock);
|
std::shared_lock readLock(m_lock);
|
||||||
@ -245,10 +245,10 @@ void FancyZones::ToggleEditor() noexcept
|
|||||||
if (iter != m_zoneWindowMap.end())
|
if (iter != m_zoneWindowMap.end())
|
||||||
{
|
{
|
||||||
const std::wstring params =
|
const std::wstring params =
|
||||||
iter->second->UniqueId() + L" " +
|
iter->second->UniqueId() + L" " +
|
||||||
std::to_wstring(iter->second->ActiveZoneSet()->LayoutId()) + L" " +
|
std::to_wstring(iter->second->ActiveZoneSet()->LayoutId()) + L" " +
|
||||||
std::to_wstring(reinterpret_cast<UINT_PTR>(foregroundWindow)) + L" " +
|
std::to_wstring(reinterpret_cast<UINT_PTR>(foregroundWindow)) + L" " +
|
||||||
std::to_wstring(reinterpret_cast<UINT_PTR>(monitor));
|
std::to_wstring(reinterpret_cast<UINT_PTR>(monitor));
|
||||||
|
|
||||||
SHELLEXECUTEINFO sei{ sizeof(sei) };
|
SHELLEXECUTEINFO sei{ sizeof(sei) };
|
||||||
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
|
||||||
|
Loading…
Reference in New Issue
Block a user