Finalized command line parser implementation.

Window seeking by class implemented and /visible parameter added to CLI (picks only visible windows).
Settings updated to include "restore size and position". GUI and logic updated.
Fixed chrome toggling (form size and position doesn't change when switching).
This commit is contained in:
Lorenz Cuno Klopfenstein 2010-10-15 21:36:03 +02:00
parent 295b40ece9
commit cecbc76c67
17 changed files with 186 additions and 64 deletions

View file

@ -52,6 +52,8 @@
this.quarterToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.quarterToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.fullscreenToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.fullscreenToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.restorePositionAndSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dockToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dockToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.disabledToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.disabledToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.topLeftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.topLeftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -269,53 +271,68 @@
this.halfToolStripMenuItem1, this.halfToolStripMenuItem1,
this.quarterToolStripMenuItem1, this.quarterToolStripMenuItem1,
this.toolStripSeparator3, this.toolStripSeparator3,
this.fullscreenToolStripMenuItem1}); this.fullscreenToolStripMenuItem1,
this.toolStripSeparator2,
this.restorePositionAndSizeToolStripMenuItem});
this.menuResize.Name = "menuResize"; this.menuResize.Name = "menuResize";
this.menuResize.OwnerItem = this.resizeToolStripMenuItem; this.menuResize.OwnerItem = this.resizeToolStripMenuItem;
this.menuResize.Size = new System.Drawing.Size(165, 120); this.menuResize.Size = new System.Drawing.Size(218, 170);
this.menuResize.Opening += new System.ComponentModel.CancelEventHandler(this.Menu_Resize_opening); this.menuResize.Opening += new System.ComponentModel.CancelEventHandler(this.Menu_Resize_opening);
// //
// doubleToolStripMenuItem1 // doubleToolStripMenuItem1
// //
this.doubleToolStripMenuItem1.Name = "doubleToolStripMenuItem1"; this.doubleToolStripMenuItem1.Name = "doubleToolStripMenuItem1";
this.doubleToolStripMenuItem1.Size = new System.Drawing.Size(164, 22); this.doubleToolStripMenuItem1.Size = new System.Drawing.Size(217, 22);
this.doubleToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitDouble; this.doubleToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitDouble;
this.doubleToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Double); this.doubleToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Double);
// //
// fitToWindowToolStripMenuItem1 // fitToWindowToolStripMenuItem1
// //
this.fitToWindowToolStripMenuItem1.Name = "fitToWindowToolStripMenuItem1"; this.fitToWindowToolStripMenuItem1.Name = "fitToWindowToolStripMenuItem1";
this.fitToWindowToolStripMenuItem1.Size = new System.Drawing.Size(164, 22); this.fitToWindowToolStripMenuItem1.Size = new System.Drawing.Size(217, 22);
this.fitToWindowToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitOriginal; this.fitToWindowToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitOriginal;
this.fitToWindowToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_FitToWindow); this.fitToWindowToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_FitToWindow);
// //
// halfToolStripMenuItem1 // halfToolStripMenuItem1
// //
this.halfToolStripMenuItem1.Name = "halfToolStripMenuItem1"; this.halfToolStripMenuItem1.Name = "halfToolStripMenuItem1";
this.halfToolStripMenuItem1.Size = new System.Drawing.Size(164, 22); this.halfToolStripMenuItem1.Size = new System.Drawing.Size(217, 22);
this.halfToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitHalf; this.halfToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitHalf;
this.halfToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Half); this.halfToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Half);
// //
// quarterToolStripMenuItem1 // quarterToolStripMenuItem1
// //
this.quarterToolStripMenuItem1.Name = "quarterToolStripMenuItem1"; this.quarterToolStripMenuItem1.Name = "quarterToolStripMenuItem1";
this.quarterToolStripMenuItem1.Size = new System.Drawing.Size(164, 22); this.quarterToolStripMenuItem1.Size = new System.Drawing.Size(217, 22);
this.quarterToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitQuarter; this.quarterToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitQuarter;
this.quarterToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Quarter); this.quarterToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Quarter);
// //
// toolStripSeparator3 // toolStripSeparator3
// //
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(161, 6); this.toolStripSeparator3.Size = new System.Drawing.Size(214, 6);
// //
// fullscreenToolStripMenuItem1 // fullscreenToolStripMenuItem1
// //
this.fullscreenToolStripMenuItem1.Image = global::OnTopReplica.Properties.Resources.fullscreen; this.fullscreenToolStripMenuItem1.Image = global::OnTopReplica.Properties.Resources.fullscreen;
this.fullscreenToolStripMenuItem1.Name = "fullscreenToolStripMenuItem1"; this.fullscreenToolStripMenuItem1.Name = "fullscreenToolStripMenuItem1";
this.fullscreenToolStripMenuItem1.Size = new System.Drawing.Size(164, 22); this.fullscreenToolStripMenuItem1.Size = new System.Drawing.Size(217, 22);
this.fullscreenToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitFullscreen; this.fullscreenToolStripMenuItem1.Text = global::OnTopReplica.Strings.MenuFitFullscreen;
this.fullscreenToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Fullscreen); this.fullscreenToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Resize_Fullscreen);
// //
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(214, 6);
//
// restorePositionAndSizeToolStripMenuItem
//
this.restorePositionAndSizeToolStripMenuItem.Name = "restorePositionAndSizeToolStripMenuItem";
this.restorePositionAndSizeToolStripMenuItem.Size = new System.Drawing.Size(217, 22);
this.restorePositionAndSizeToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuRecall;
this.restorePositionAndSizeToolStripMenuItem.ToolTipText = global::OnTopReplica.Strings.MenuRecallTT;
this.restorePositionAndSizeToolStripMenuItem.Click += new System.EventHandler(this.Menu_Resize_RecallPosition_click);
//
// dockToolStripMenuItem // dockToolStripMenuItem
// //
this.dockToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.dockToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -337,7 +354,7 @@
this.disabledToolStripMenuItem.Checked = true; this.disabledToolStripMenuItem.Checked = true;
this.disabledToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; this.disabledToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.disabledToolStripMenuItem.Name = "disabledToolStripMenuItem"; this.disabledToolStripMenuItem.Name = "disabledToolStripMenuItem";
this.disabledToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.disabledToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.disabledToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosDisabled; this.disabledToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosDisabled;
this.disabledToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_Disable); this.disabledToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_Disable);
// //
@ -345,7 +362,7 @@
// //
this.topLeftToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_topleft; this.topLeftToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_topleft;
this.topLeftToolStripMenuItem.Name = "topLeftToolStripMenuItem"; this.topLeftToolStripMenuItem.Name = "topLeftToolStripMenuItem";
this.topLeftToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.topLeftToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.topLeftToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosTopLeft; this.topLeftToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosTopLeft;
this.topLeftToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_TopLeft); this.topLeftToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_TopLeft);
// //
@ -353,7 +370,7 @@
// //
this.topRightToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_topright; this.topRightToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_topright;
this.topRightToolStripMenuItem.Name = "topRightToolStripMenuItem"; this.topRightToolStripMenuItem.Name = "topRightToolStripMenuItem";
this.topRightToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.topRightToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.topRightToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosTopRight; this.topRightToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosTopRight;
this.topRightToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_TopRight); this.topRightToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_TopRight);
// //
@ -361,7 +378,7 @@
// //
this.centerToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_center; this.centerToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_center;
this.centerToolStripMenuItem.Name = "centerToolStripMenuItem"; this.centerToolStripMenuItem.Name = "centerToolStripMenuItem";
this.centerToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.centerToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.centerToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosCenter; this.centerToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosCenter;
this.centerToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_Center); this.centerToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_Center);
// //
@ -369,7 +386,7 @@
// //
this.bottomLeftToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_bottomleft; this.bottomLeftToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_bottomleft;
this.bottomLeftToolStripMenuItem.Name = "bottomLeftToolStripMenuItem"; this.bottomLeftToolStripMenuItem.Name = "bottomLeftToolStripMenuItem";
this.bottomLeftToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.bottomLeftToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.bottomLeftToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosBottomLeft; this.bottomLeftToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosBottomLeft;
this.bottomLeftToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_BottomLeft); this.bottomLeftToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_BottomLeft);
// //
@ -377,7 +394,7 @@
// //
this.bottomRightToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_bottomright; this.bottomRightToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.pos_bottomright;
this.bottomRightToolStripMenuItem.Name = "bottomRightToolStripMenuItem"; this.bottomRightToolStripMenuItem.Name = "bottomRightToolStripMenuItem";
this.bottomRightToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.bottomRightToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.bottomRightToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosBottomRight; this.bottomRightToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuPosBottomRight;
this.bottomRightToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_BottomRight); this.bottomRightToolStripMenuItem.Click += new System.EventHandler(this.Menu_Position_BottomRight);
// //
@ -594,6 +611,8 @@
private System.Windows.Forms.ToolStripMenuItem enableClickthroughToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem enableClickthroughToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem centerToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem centerToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem disabledToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem disabledToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem restorePositionAndSizeToolStripMenuItem;
} }
} }

View file

@ -21,7 +21,9 @@ namespace OnTopReplica {
Panel _sidePanelContainer; Panel _sidePanelContainer;
//Managers //Managers
BaseWindowSeeker _windowSeeker = new TaskWindowSeeker(); BaseWindowSeeker _windowSeeker = new TaskWindowSeeker {
SkipNotVisibleWindows = true
};
MessagePumpManager _msgPumpManager = new MessagePumpManager(); MessagePumpManager _msgPumpManager = new MessagePumpManager();
UpdateManager _updateManager = new UpdateManager(); UpdateManager _updateManager = new UpdateManager();

View file

@ -68,22 +68,18 @@ namespace OnTopReplica {
} }
set { set {
if (!value) { if (!value) {
Location = new Point {
X = Location.X + SystemInformation.FrameBorderSize.Width,
Y = Location.Y + SystemInformation.FrameBorderSize.Height
};
FormBorderStyle = FormBorderStyle.None; FormBorderStyle = FormBorderStyle.None;
if (IsChromeVisible) {
Location = new Point {
X = Location.X + SystemInformation.FrameBorderSize.Width,
Y = Location.Y + SystemInformation.FrameBorderSize.Height
};
}
} }
else if(value) { else if(value) {
Location = new Point {
X = Location.X - SystemInformation.FrameBorderSize.Width,
Y = Location.Y - SystemInformation.FrameBorderSize.Height
};
FormBorderStyle = FormBorderStyle.SizableToolWindow; FormBorderStyle = FormBorderStyle.SizableToolWindow;
if (!IsChromeVisible) {
Location = new Point {
X = Location.X - SystemInformation.FrameBorderSize.Width,
Y = Location.Y - SystemInformation.FrameBorderSize.Height
};
}
} }
Program.Platform.OnFormStateChange(this); Program.Platform.OnFormStateChange(this);

View file

@ -109,6 +109,8 @@ namespace OnTopReplica {
private void Menu_Resize_opening(object sender, CancelEventArgs e) { private void Menu_Resize_opening(object sender, CancelEventArgs e) {
if (!_thumbnailPanel.IsShowingThumbnail) if (!_thumbnailPanel.IsShowingThumbnail)
e.Cancel = true; e.Cancel = true;
restorePositionAndSizeToolStripMenuItem.Checked = Settings.Default.RestoreSizeAndPosition;
} }
private void Menu_Resize_Double(object sender, EventArgs e) { private void Menu_Resize_Double(object sender, EventArgs e) {
@ -131,6 +133,10 @@ namespace OnTopReplica {
IsFullscreen = true; IsFullscreen = true;
} }
private void Menu_Resize_RecallPosition_click(object sender, EventArgs e) {
Settings.Default.RestoreSizeAndPosition = !Settings.Default.RestoreSizeAndPosition;
}
private void Menu_Position_Opening(object sender, EventArgs e) { private void Menu_Position_Opening(object sender, EventArgs e) {
disabledToolStripMenuItem.Checked = (PositionLock == null); disabledToolStripMenuItem.Checked = (PositionLock == null);
topLeftToolStripMenuItem.Checked = (PositionLock == ScreenPosition.TopLeft); topLeftToolStripMenuItem.Checked = (PositionLock == ScreenPosition.TopLeft);

View file

@ -137,6 +137,7 @@
<Compile Include="Native\HT.cs" /> <Compile Include="Native\HT.cs" />
<Compile Include="Pair.cs" /> <Compile Include="Pair.cs" />
<Compile Include="WindowSeekers\BaseWindowSeeker.cs" /> <Compile Include="WindowSeekers\BaseWindowSeeker.cs" />
<Compile Include="WindowSeekers\ByClassWindowSeeker.cs" />
<Compile Include="WindowSeekers\ByTitleWindowSeeker.cs" /> <Compile Include="WindowSeekers\ByTitleWindowSeeker.cs" />
<Compile Include="WindowSeekers\TaskWindowSeeker.cs" /> <Compile Include="WindowSeekers\TaskWindowSeeker.cs" />
<None Include="Native\ITaskBarList.cs" /> <None Include="Native\ITaskBarList.cs" />

View file

@ -16,6 +16,7 @@
<EnableSecurityDebugging>false</EnableSecurityDebugging> <EnableSecurityDebugging>false</EnableSecurityDebugging>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>/windowClass="OperaWindowClass"</StartArguments> <StartArguments>
</StartArguments>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View file

@ -82,6 +82,8 @@ namespace OnTopReplica {
while (_languageChangeCode != null); while (_languageChangeCode != null);
//Persist settings //Persist settings
Settings.Default.RestoreLastPosition = reloadLocation;
Settings.Default.RestoreLastSize = reloadSize;
Settings.Default.Save(); Settings.Default.Save();
} }

View file

@ -132,25 +132,37 @@ namespace OnTopReplica.Properties {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("False")]
public string Setting { public bool RestoreSizeAndPosition {
get { get {
return ((string)(this["Setting"])); return ((bool)(this["RestoreSizeAndPosition"]));
} }
set { set {
this["Setting"] = value; this["RestoreSizeAndPosition"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
public string Setting1 { public global::System.Drawing.Size RestoreLastSize {
get { get {
return ((string)(this["Setting1"])); return ((global::System.Drawing.Size)(this["RestoreLastSize"]));
} }
set { set {
this["Setting1"] = value; this["RestoreLastSize"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0, 0")]
public global::System.Drawing.Point RestoreLastPosition {
get {
return ((global::System.Drawing.Point)(this["RestoreLastPosition"]));
}
set {
this["RestoreLastPosition"] = value;
} }
} }
} }

View file

@ -29,11 +29,14 @@
<Setting Name="FullscreenAlwaysOnTop" Type="System.Boolean" Scope="User"> <Setting Name="FullscreenAlwaysOnTop" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>
</Setting> </Setting>
<Setting Name="Setting" Type="System.String" Scope="User"> <Setting Name="RestoreSizeAndPosition" Type="System.Boolean" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)">False</Value>
</Setting> </Setting>
<Setting Name="Setting1" Type="System.String" Scope="User"> <Setting Name="RestoreLastSize" Type="System.Drawing.Size" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)">0, 0</Value>
</Setting>
<Setting Name="RestoreLastPosition" Type="System.Drawing.Point" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting> </Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View file

@ -47,7 +47,7 @@
this.labelInstruction.AutoSize = true; this.labelInstruction.AutoSize = true;
this.labelInstruction.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelInstruction.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelInstruction.ForeColor = System.Drawing.SystemColors.HotTrack; this.labelInstruction.ForeColor = System.Drawing.SystemColors.HotTrack;
this.labelInstruction.Location = new System.Drawing.Point(12, 9); this.labelInstruction.Location = new System.Drawing.Point(12, 10);
this.labelInstruction.Name = "labelInstruction"; this.labelInstruction.Name = "labelInstruction";
this.labelInstruction.Size = new System.Drawing.Size(112, 21); this.labelInstruction.Size = new System.Drawing.Size(112, 21);
this.labelInstruction.TabIndex = 1; this.labelInstruction.TabIndex = 1;

View file

@ -3,12 +3,13 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Drawing; using System.Drawing;
using System.ComponentModel; using System.ComponentModel;
using OnTopReplica.Properties;
namespace OnTopReplica.StartupOptions { namespace OnTopReplica.StartupOptions {
class Factory { class Factory {
static Factory() { static Factory() {
//Custom type conversions //Custom type conversion attributes
TypeDescriptor.AddAttributes(typeof(Size), new TypeConverterAttribute(typeof(SizeConverter))); TypeDescriptor.AddAttributes(typeof(Size), new TypeConverterAttribute(typeof(SizeConverter)));
TypeDescriptor.AddAttributes(typeof(ScreenPosition), new TypeConverterAttribute(typeof(ScreenPositionConverter))); TypeDescriptor.AddAttributes(typeof(ScreenPosition), new TypeConverterAttribute(typeof(ScreenPositionConverter)));
TypeDescriptor.AddAttributes(typeof(Rectangle), new TypeConverterAttribute(typeof(RectangleConverter))); TypeDescriptor.AddAttributes(typeof(Rectangle), new TypeConverterAttribute(typeof(RectangleConverter)));
@ -17,11 +18,20 @@ namespace OnTopReplica.StartupOptions {
public static Options CreateOptions(string[] args) { public static Options CreateOptions(string[] args) {
var options = new Options(); var options = new Options();
LoadSettings(options);
ParseCommandLine(args, options); ParseCommandLine(args, options);
return options; return options;
} }
private static void LoadSettings(Options options) {
if (Settings.Default.RestoreSizeAndPosition) {
options.StartLocation = Settings.Default.RestoreLastPosition;
options.StartSize = Settings.Default.RestoreLastSize;
}
}
private static void ParseCommandLine(string[] args, Options options) { private static void ParseCommandLine(string[] args, Options options) {
var cmdOptions = new NDesk.Options.OptionSet() var cmdOptions = new NDesk.Options.OptionSet()
.Add<long>("windowId=", "Window handle ({HWND}) to be cloned.", id => { .Add<long>("windowId=", "Window handle ({HWND}) to be cloned.", id => {
@ -33,6 +43,9 @@ namespace OnTopReplica.StartupOptions {
.Add<string>("windowClass=", "{CLASS} of the window to be cloned.", s => { .Add<string>("windowClass=", "{CLASS} of the window to be cloned.", s => {
options.WindowClass = s; options.WindowClass = s;
}) })
.Add("v|visible", "If set, only clones windows that are visible.", s => {
options.MustBeVisible = true;
})
.Add<Size>("size=", "Target {SIZE} of the cloned thumbnail.", s => { .Add<Size>("size=", "Target {SIZE} of the cloned thumbnail.", s => {
options.StartSize = s; options.StartSize = s;
}) })
@ -50,10 +63,10 @@ namespace OnTopReplica.StartupOptions {
.Add<byte>("o|opacity=", "Opacity of the window (0-255).", opacity => { .Add<byte>("o|opacity=", "Opacity of the window (0-255).", opacity => {
options.Opacity = opacity; options.Opacity = opacity;
}) })
.Add("cf|clickForward", "Enables click forwarding.", s => { .Add("clickForwarding", "Enables click forwarding.", s => {
options.EnableClickForwarding = true; options.EnableClickForwarding = true;
}) })
.Add("noch|chromeOff", "Disables the window's chrome (border).", s => { .Add("chromeOff", "Disables the window's chrome (border).", s => {
options.DisableChrome = true; options.DisableChrome = true;
}) })
.Add("h|help|?", "Show command line help.", s => { .Add("h|help|?", "Show command line help.", s => {

View file

@ -16,6 +16,7 @@ namespace OnTopReplica.StartupOptions {
Status = CliStatus.Ok; Status = CliStatus.Ok;
Opacity = 255; Opacity = 255;
DisableChrome = false; DisableChrome = false;
MustBeVisible = false;
} }
#region Position and size #region Position and size
@ -38,6 +39,8 @@ namespace OnTopReplica.StartupOptions {
public Rectangle? Region { get; set; } public Rectangle? Region { get; set; }
public bool MustBeVisible { get; set; }
#endregion #endregion
#region Options #region Options
@ -96,14 +99,21 @@ namespace OnTopReplica.StartupOptions {
} }
else if (WindowTitle != null) { else if (WindowTitle != null) {
var seeker = new ByTitleWindowSeeker(WindowTitle) { var seeker = new ByTitleWindowSeeker(WindowTitle) {
OwnerHandle = form.Handle OwnerHandle = form.Handle,
SkipNotVisibleWindows = MustBeVisible
}; };
seeker.Refresh(); seeker.Refresh();
handle = seeker.Windows.FirstOrDefault(); handle = seeker.Windows.FirstOrDefault();
} }
else if (WindowClass != null) { else if (WindowClass != null) {
//TODO var seeker = new ByClassWindowSeeker(WindowClass) {
OwnerHandle = form.Handle,
SkipNotVisibleWindows = MustBeVisible
};
seeker.Refresh();
handle = seeker.Windows.FirstOrDefault();
} }
if (handle != null) { if (handle != null) {
form.SetThumbnail(handle, Region); form.SetThumbnail(handle, Region);

View file

@ -6,29 +6,41 @@ using System.Drawing;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace OnTopReplica.StartupOptions { namespace OnTopReplica.StartupOptions {
class SizeConverter : TypeConverter { class SizeConverter : TypeConverter {
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
if (value != null) { if (value != null) {
var sVal = value.ToString(); var sVal = value.ToString();
return Convert(sVal); return StringToSize(sVal);
} }
else else
return base.ConvertFrom(context, culture, value); return base.ConvertFrom(context, culture, value);
} }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
return sourceType == typeof(string); return (sourceType == typeof(string) || sourceType == typeof(Size));
} }
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) {
return destinationType == typeof(Size); return (destinationType == typeof(Size) || destinationType == typeof(string));
} }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
if (value != null && destinationType == typeof(Size)) { if (value == null)
return base.ConvertTo(context, culture, value, destinationType);
if (destinationType == typeof(Size)) {
var sVal = value.ToString(); var sVal = value.ToString();
return Convert(sVal); return StringToSize(sVal);
}
else if (destinationType == typeof(string)) {
if (value is Size) {
Size sValue = (Size)value;
return string.Format("{0}, {1}", sValue.Width, sValue.Height);
}
return value.ToString();
} }
else else
return base.ConvertTo(context, culture, value, destinationType); return base.ConvertTo(context, culture, value, destinationType);
@ -37,7 +49,7 @@ namespace OnTopReplica.StartupOptions {
static Regex _sizeRegex = new Regex("^\\D*(?<x>\\d*)\\s*,\\s*(?<y>\\d*)\\D*$", static Regex _sizeRegex = new Regex("^\\D*(?<x>\\d*)\\s*,\\s*(?<y>\\d*)\\D*$",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline); RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);
private Size Convert(string s) { private Size StringToSize(string s) {
var match = _sizeRegex.Match(s); var match = _sizeRegex.Match(s);
var x = match.Groups["x"]; var x = match.Groups["x"];
@ -53,4 +65,5 @@ namespace OnTopReplica.StartupOptions {
} }
} }
} }

View file

@ -39,6 +39,9 @@ namespace OnTopReplica.WindowSeekers {
if (hwnd == OwnerHandle) if (hwnd == OwnerHandle)
return true; return true;
if (SkipNotVisibleWindows && !WindowManagerMethods.IsWindowVisible(hwnd))
return true;
//Extract basic properties //Extract basic properties
string title = WindowMethods.GetWindowText(hwnd); string title = WindowMethods.GetWindowText(hwnd);
@ -67,6 +70,11 @@ namespace OnTopReplica.WindowSeekers {
/// </remarks> /// </remarks>
public IntPtr OwnerHandle { get; set; } public IntPtr OwnerHandle { get; set; }
/// <summary>
/// Gets or sets whether not visible windows should be skipped.
/// </summary>
public bool SkipNotVisibleWindows { get; set; }
} }
} }

View file

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using OnTopReplica.Native;
namespace OnTopReplica.WindowSeekers {
/// <summary>
/// Seeks a single window by matching its window class.
/// </summary>
/// <remarks>
/// Class matching is exact and case-sensititve.
/// </remarks>
class ByClassWindowSeeker : BaseWindowSeeker {
public ByClassWindowSeeker(string className) {
if (className == null)
throw new ArgumentNullException();
ClassName = className;
}
public string ClassName { get; private set; }
protected override bool InspectWindow(IntPtr hwnd, string title, ref bool terminate) {
var wndClass = WindowMethods.GetWindowClass(hwnd);
if (ClassName.Equals(wndClass, StringComparison.CurrentCulture)) {
return true;
}
return false;
}
}
}

View file

@ -20,15 +20,13 @@ namespace OnTopReplica.WindowSeekers {
if (string.IsNullOrEmpty(title)) if (string.IsNullOrEmpty(title))
return false; return false;
if (WindowManagerMethods.IsWindowVisible(hwnd)) { if ((long)WindowManagerMethods.GetParent(hwnd) == 0) {
if ((long)WindowManagerMethods.GetParent(hwnd) == 0) { bool hasOwner = (long)WindowManagerMethods.GetWindow(hwnd, WindowManagerMethods.GetWindowMode.GW_OWNER) != 0;
bool hasOwner = (long)WindowManagerMethods.GetWindow(hwnd, WindowManagerMethods.GetWindowMode.GW_OWNER) != 0; WindowMethods.WindowExStyles exStyle = (WindowMethods.WindowExStyles)WindowMethods.GetWindowLong(hwnd, WindowMethods.WindowLong.ExStyle);
WindowMethods.WindowExStyles exStyle = (WindowMethods.WindowExStyles)WindowMethods.GetWindowLong(hwnd, WindowMethods.WindowLong.ExStyle);
if (((exStyle & WindowMethods.WindowExStyles.ToolWindow) == 0 && !hasOwner) || //unowned non-tool window if (((exStyle & WindowMethods.WindowExStyles.ToolWindow) == 0 && !hasOwner) || //unowned non-tool window
((exStyle & WindowMethods.WindowExStyles.AppWindow) == WindowMethods.WindowExStyles.AppWindow && hasOwner)) { //owned application window ((exStyle & WindowMethods.WindowExStyles.AppWindow) == WindowMethods.WindowExStyles.AppWindow && hasOwner)) { //owned application window
return true; return true;
}
} }
} }

View file

@ -31,11 +31,14 @@
<setting name="FullscreenAlwaysOnTop" serializeAs="String"> <setting name="FullscreenAlwaysOnTop" serializeAs="String">
<value>False</value> <value>False</value>
</setting> </setting>
<setting name="Setting" serializeAs="String"> <setting name="RestoreSizeAndPosition" serializeAs="String">
<value /> <value>False</value>
</setting> </setting>
<setting name="Setting1" serializeAs="String"> <setting name="RestoreLastSize" serializeAs="String">
<value /> <value>0, 0</value>
</setting>
<setting name="RestoreLastPosition" serializeAs="String">
<value>0, 0</value>
</setting> </setting>
</OnTopReplica.Properties.Settings> </OnTopReplica.Properties.Settings>
</userSettings> </userSettings>