Editor should come up on the monitor with the foreground window. Defaults to primary monitor if there is no foreground window.

This commit is contained in:
Bret Anderson
2019-09-08 01:47:12 -07:00
parent 5f5402aa0a
commit e562b29ecd
7 changed files with 206 additions and 185 deletions

View File

@@ -155,7 +155,7 @@ namespace FancyZonesEditor.Models
internal delegate int PersistZoneSet(
[MarshalAs(UnmanagedType.LPWStr)] string activeKey,
[MarshalAs(UnmanagedType.LPWStr)] string key,
uint monitor,
ushort layoutId,
int zoneCount,
[MarshalAs(UnmanagedType.LPArray)] int[] zoneArray);
@@ -205,18 +205,15 @@ namespace FancyZonesEditor.Models
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
// args[1] = registry key value of currently active ZoneSet
// args[2] = id of layout to load at startup
string uniqueId = args[1];
// TODO: multimon
double height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
double width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
var key = width.ToString() + "_" + height.ToString();
uint monitor = 0;
if (args.Length > 3)
{
monitor = uint.Parse(args[4]);
}
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
persistZoneSet(uniqueId, key, _id, zoneCount, zoneArray);
persistZoneSet(uniqueId, monitor, _id, zoneCount, zoneArray);
}
}

View File

@@ -23,11 +23,25 @@ namespace FancyZonesEditor
{
public Settings()
{
Rect workArea = System.Windows.SystemParameters.WorkArea;
_workArea = System.Windows.SystemParameters.WorkArea;
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
_defaultModels = new List<LayoutModel>(5);
_focusModel = new CanvasLayoutModel("Focus", c_focusModelId, (int)workArea.Width, (int)workArea.Height);
_focusModel = new CanvasLayoutModel("Focus", c_focusModelId, (int)_workArea.Width, (int)_workArea.Height);
_defaultModels.Add(_focusModel);
_columnsModel = new GridLayoutModel("Columns", c_columnsModelId);
@@ -46,7 +60,7 @@ namespace FancyZonesEditor
_priorityGridModel = new GridLayoutModel("Priority Grid", c_priorityGridModelId);
_defaultModels.Add(_priorityGridModel);
_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);
_spacing = (int)Registry.GetValue(FullRegistryPath, "Spacing", 16);
@@ -134,6 +148,12 @@ namespace FancyZonesEditor
}
private bool _isCtrlKeyPressed;
public Rect WorkArea
{
get { return _workArea; }
}
private Rect _workArea;
// UpdateLayoutModels
// Update the five default layouts based on the new ZoneCount
private void UpdateLayoutModels()