From 7a8ae1a795b7cdf6341e49ba7b613e8fdbc03814 Mon Sep 17 00:00:00 2001 From: Vo1 Date: Tue, 14 Sep 2021 20:36:06 +0200 Subject: [PATCH] Screen index and offset support --- src/OnTopReplica/StartupOptions/Factory.cs | 3 +++ src/OnTopReplica/StartupOptions/Options.cs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/OnTopReplica/StartupOptions/Factory.cs b/src/OnTopReplica/StartupOptions/Factory.cs index d977c30..770a1b8 100644 --- a/src/OnTopReplica/StartupOptions/Factory.cs +++ b/src/OnTopReplica/StartupOptions/Factory.cs @@ -67,6 +67,9 @@ namespace OnTopReplica.StartupOptions { private static void ParseCommandLine(string[] args, Options options) { var cmdOptions = new NDesk.Options.OptionSet() + .Add("screen=", "ScreenIndex to display on.", id => { + options.ScreenIndex = id; + }) .Add("windowId=", "Window handle ({HWND}) to be cloned.", id => { options.WindowId = new IntPtr(id); options.WindowTitle = null; diff --git a/src/OnTopReplica/StartupOptions/Options.cs b/src/OnTopReplica/StartupOptions/Options.cs index 03d8a51..d230809 100644 --- a/src/OnTopReplica/StartupOptions/Options.cs +++ b/src/OnTopReplica/StartupOptions/Options.cs @@ -5,7 +5,8 @@ using System.Text; using System.Drawing; using System.IO; using OnTopReplica.WindowSeekers; - +using System.Windows.Forms; + namespace OnTopReplica.StartupOptions { /// @@ -19,7 +20,9 @@ namespace OnTopReplica.StartupOptions { DisableChrome = false; MustBeVisible = false; Fullscreen = false; - } + } + + public int ScreenIndex = 0; #region Position and size @@ -97,6 +100,12 @@ namespace OnTopReplica.StartupOptions { #region Application + private void setFormLocation(Form form, Screen screen) { + Point start = StartLocation ?? default(Point); + Point loc = new Point(start.X + screen.WorkingArea.Location.X, start.Y + screen.WorkingArea.Location.Y); + form.Location = loc; + } + public void Apply(MainForm form) { Log.Write("Applying command line launch parameters"); @@ -160,6 +169,9 @@ namespace OnTopReplica.StartupOptions { form.ClientSize = StartSize.Value; } + if (ScreenIndex != 0) { + setFormLocation(form, Screen.AllScreens[ScreenIndex]); + } //Other features if (EnableClickForwarding) { form.ClickForwardingEnabled = true;