Merged in regner/eve-o-preview/feature_track_client_windows (pull request #1)

Adding a feature to track and save the location of client windows
This commit is contained in:
Ulf Hammarqvist
2014-12-09 20:07:45 +01:00
6 changed files with 178 additions and 24 deletions

View File

@@ -63,14 +63,15 @@ namespace PreviewToy
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.zoom_anchor_lable = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.panel3 = new System.Windows.Forms.Panel();
this.zoom_anchor_lable = new System.Windows.Forms.Label();
this.panel5 = new System.Windows.Forms.Panel();
this.previews_check_listbox = new System.Windows.Forms.CheckedListBox();
this.label1 = new System.Windows.Forms.Label();
this.panel4 = new System.Windows.Forms.Panel();
this.aero_status_label = new System.Windows.Forms.Label();
this.option_track_client_windows = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.previewToyMainBindingSource)).BeginInit();
this.flowLayoutPanel1.SuspendLayout();
this.panel1.SuspendLayout();
@@ -85,7 +86,7 @@ namespace PreviewToy
this.option_hide_active.AutoSize = true;
this.option_hide_active.Checked = true;
this.option_hide_active.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_hide_active.Location = new System.Drawing.Point(3, 3);
this.option_hide_active.Location = new System.Drawing.Point(3, 26);
this.option_hide_active.Name = "option_hide_active";
this.option_hide_active.Size = new System.Drawing.Size(184, 17);
this.option_hide_active.TabIndex = 1;
@@ -98,7 +99,7 @@ namespace PreviewToy
this.option_hide_all_if_not_right_type.AutoSize = true;
this.option_hide_all_if_not_right_type.Checked = true;
this.option_hide_all_if_not_right_type.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_hide_all_if_not_right_type.Location = new System.Drawing.Point(3, 49);
this.option_hide_all_if_not_right_type.Location = new System.Drawing.Point(3, 72);
this.option_hide_all_if_not_right_type.Name = "option_hide_all_if_not_right_type";
this.option_hide_all_if_not_right_type.Size = new System.Drawing.Size(242, 17);
this.option_hide_all_if_not_right_type.TabIndex = 2;
@@ -111,7 +112,7 @@ namespace PreviewToy
this.option_unique_layout.AutoSize = true;
this.option_unique_layout.Checked = true;
this.option_unique_layout.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_unique_layout.Location = new System.Drawing.Point(3, 72);
this.option_unique_layout.Location = new System.Drawing.Point(3, 95);
this.option_unique_layout.Name = "option_unique_layout";
this.option_unique_layout.Size = new System.Drawing.Size(185, 17);
this.option_unique_layout.TabIndex = 3;
@@ -138,7 +139,7 @@ namespace PreviewToy
this.option_always_on_top.AutoSize = true;
this.option_always_on_top.Checked = true;
this.option_always_on_top.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_always_on_top.Location = new System.Drawing.Point(3, 26);
this.option_always_on_top.Location = new System.Drawing.Point(3, 49);
this.option_always_on_top.Name = "option_always_on_top";
this.option_always_on_top.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.option_always_on_top.Size = new System.Drawing.Size(137, 17);
@@ -152,7 +153,7 @@ namespace PreviewToy
this.option_show_thumbnail_frames.AutoSize = true;
this.option_show_thumbnail_frames.Checked = true;
this.option_show_thumbnail_frames.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_show_thumbnail_frames.Location = new System.Drawing.Point(99, 195);
this.option_show_thumbnail_frames.Location = new System.Drawing.Point(99, 218);
this.option_show_thumbnail_frames.Name = "option_show_thumbnail_frames";
this.option_show_thumbnail_frames.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.option_show_thumbnail_frames.Size = new System.Drawing.Size(127, 17);
@@ -211,7 +212,7 @@ namespace PreviewToy
this.option_show_overlay.AutoSize = true;
this.option_show_overlay.Checked = true;
this.option_show_overlay.CheckState = System.Windows.Forms.CheckState.Checked;
this.option_show_overlay.Location = new System.Drawing.Point(3, 195);
this.option_show_overlay.Location = new System.Drawing.Point(3, 218);
this.option_show_overlay.Name = "option_show_overlay";
this.option_show_overlay.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.option_show_overlay.Size = new System.Drawing.Size(90, 17);
@@ -329,6 +330,7 @@ namespace PreviewToy
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Controls.Add(this.option_track_client_windows);
this.flowLayoutPanel1.Controls.Add(this.option_hide_active);
this.flowLayoutPanel1.Controls.Add(this.option_always_on_top);
this.flowLayoutPanel1.Controls.Add(this.option_hide_all_if_not_right_type);
@@ -344,13 +346,14 @@ namespace PreviewToy
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(252, 349);
this.flowLayoutPanel1.TabIndex = 25;
this.flowLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel1_Paint);
//
// panel1
//
this.panel1.Controls.Add(this.option_sync_size);
this.panel1.Controls.Add(this.option_sync_size_x);
this.panel1.Controls.Add(this.option_sync_size_y);
this.panel1.Location = new System.Drawing.Point(3, 95);
this.panel1.Location = new System.Drawing.Point(3, 118);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(246, 26);
this.panel1.TabIndex = 26;
@@ -362,20 +365,11 @@ namespace PreviewToy
this.panel2.Controls.Add(this.zoom_anchor_lable);
this.panel2.Controls.Add(this.option_zoom_on_hover);
this.panel2.Controls.Add(this.option_zoom_factor);
this.panel2.Location = new System.Drawing.Point(3, 127);
this.panel2.Location = new System.Drawing.Point(3, 150);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(246, 62);
this.panel2.TabIndex = 27;
//
// zoom_anchor_lable
//
this.zoom_anchor_lable.AutoSize = true;
this.zoom_anchor_lable.Location = new System.Drawing.Point(134, 31);
this.zoom_anchor_lable.Name = "zoom_anchor_lable";
this.zoom_anchor_lable.Size = new System.Drawing.Size(41, 13);
this.zoom_anchor_lable.TabIndex = 30;
this.zoom_anchor_lable.Text = "Anchor";
//
// label2
//
this.label2.AutoSize = true;
@@ -401,11 +395,20 @@ namespace PreviewToy
this.panel3.Size = new System.Drawing.Size(60, 57);
this.panel3.TabIndex = 28;
//
// zoom_anchor_lable
//
this.zoom_anchor_lable.AutoSize = true;
this.zoom_anchor_lable.Location = new System.Drawing.Point(134, 31);
this.zoom_anchor_lable.Name = "zoom_anchor_lable";
this.zoom_anchor_lable.Size = new System.Drawing.Size(41, 13);
this.zoom_anchor_lable.TabIndex = 30;
this.zoom_anchor_lable.Text = "Anchor";
//
// panel5
//
this.panel5.Controls.Add(this.previews_check_listbox);
this.panel5.Controls.Add(this.label1);
this.panel5.Location = new System.Drawing.Point(3, 218);
this.panel5.Location = new System.Drawing.Point(3, 241);
this.panel5.Name = "panel5";
this.panel5.Size = new System.Drawing.Size(246, 100);
this.panel5.TabIndex = 31;
@@ -433,7 +436,7 @@ namespace PreviewToy
//
this.panel4.Controls.Add(this.aero_status_label);
this.panel4.Controls.Add(this.forum_url);
this.panel4.Location = new System.Drawing.Point(3, 324);
this.panel4.Location = new System.Drawing.Point(3, 347);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(246, 21);
this.panel4.TabIndex = 30;
@@ -447,6 +450,17 @@ namespace PreviewToy
this.aero_status_label.TabIndex = 0;
this.aero_status_label.Text = "label4";
//
// option_track_client_windows
//
this.option_track_client_windows.AutoSize = true;
this.option_track_client_windows.Location = new System.Drawing.Point(3, 3);
this.option_track_client_windows.Name = "option_track_client_windows";
this.option_track_client_windows.Size = new System.Drawing.Size(127, 17);
this.option_track_client_windows.TabIndex = 32;
this.option_track_client_windows.Text = "Track client locations";
this.option_track_client_windows.UseVisualStyleBackColor = true;
this.option_track_client_windows.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// PreviewToyHandler
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -514,6 +528,7 @@ namespace PreviewToy
private Panel panel4;
private Label aero_status_label;
private Panel panel5;
private CheckBox option_track_client_windows;
}

View File

@@ -27,6 +27,7 @@ namespace PreviewToy
private Dictionary<String, Dictionary<String, Point>> unique_layouts;
private Dictionary<String, Point> flat_layout;
private Dictionary<String, ClientLocation> client_layout;
private bool is_initialized;
@@ -34,6 +35,28 @@ namespace PreviewToy
Dictionary<string, string> xml_bad_to_ok_chars;
[DllImport("user32.dll")]
private static extern int GetWindowRect(IntPtr hwnd, out Rect rect);
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
private struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
private struct ClientLocation
{
public int X;
public int Y;
public int Width;
public int Height;
}
public enum zoom_anchor_t
{
NW = 0,
@@ -66,6 +89,7 @@ namespace PreviewToy
unique_layouts = new Dictionary<String, Dictionary<String, Point>>();
flat_layout = new Dictionary<String, Point>();
client_layout = new Dictionary<String, ClientLocation>();
ignoring_size_sync = new Stopwatch();
ignoring_size_sync.Start();
@@ -122,6 +146,8 @@ namespace PreviewToy
option_show_overlay.Checked = Properties.Settings.Default.show_overlay;
option_track_client_windows.Checked = Properties.Settings.Default.track_client_windows;
// disable/enable zoom suboptions
option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover;
foreach (var kv in zoom_anchor_button_map)
@@ -163,11 +189,14 @@ namespace PreviewToy
previews_check_listbox.BeginUpdate();
previews_check_listbox.Items.Add(previews[process.MainWindowHandle]);
previews_check_listbox.EndUpdate();
refresh_client_window_locations(process);
}
else if (previews.ContainsKey(process.MainWindowHandle)) //or update the preview titles
else if (previews.ContainsKey(process.MainWindowHandle) && process.MainWindowTitle != previews[process.MainWindowHandle].Text) //or update the preview titles
{
previews[process.MainWindowHandle].SetLabel(process.MainWindowTitle);
refresh_client_window_locations(process);
}
if (process.MainWindowHandle == DwmApi.GetForegroundWindow())
@@ -202,6 +231,20 @@ namespace PreviewToy
}
private void refresh_client_window_locations(Process process)
{
if (Properties.Settings.Default.track_client_windows && client_layout.ContainsKey(process.MainWindowTitle))
{
MoveWindow(
process.MainWindowHandle,
client_layout[process.MainWindowTitle].X,
client_layout[process.MainWindowTitle].Y,
client_layout[process.MainWindowTitle].Width,
client_layout[process.MainWindowTitle].Height,
true);
}
}
private string remove_nonconform_xml_characters(string entry)
{
@@ -256,6 +299,21 @@ namespace PreviewToy
flat_layout[ParseXElement(el)] = new Point(Convert.ToInt32(el.Element("x").Value), Convert.ToInt32(el.Element("y").Value));
}
}
if (File.Exists("client_layout.xml"))
{
XElement rootElement = XElement.Load("client_layout.xml");
foreach (var el in rootElement.Elements())
{
ClientLocation clientLocation = new ClientLocation();
clientLocation.X = Convert.ToInt32(el.Element("x").Value);
clientLocation.Y = Convert.ToInt32(el.Element("y").Value);
clientLocation.Width = Convert.ToInt32(el.Element("width").Value);
clientLocation.Height = Convert.ToInt32(el.Element("height").Value);
client_layout[ParseXElement(el)] = clientLocation;
}
}
}
private void store_layout()
@@ -288,7 +346,7 @@ namespace PreviewToy
XElement el2 = new XElement("flat_layout");
foreach (var clientKV in flat_layout)
{
if (clientKV.Key == "" || clientKV.Key == "..." )
if (clientKV.Key == "" || clientKV.Key == "...")
{
continue;
}
@@ -299,6 +357,23 @@ namespace PreviewToy
}
el2.Save("flat_layout.xml");
XElement el3 = new XElement("client_layout");
foreach (var clientKV in client_layout)
{
if (clientKV.Key == "" || clientKV.Key == "...")
{
continue;
}
XElement layout = MakeXElement(clientKV.Key);
layout.Add(new XElement("x", clientKV.Value.X));
layout.Add(new XElement("y", clientKV.Value.Y));
layout.Add(new XElement("width", clientKV.Value.Width));
layout.Add(new XElement("height", clientKV.Value.Height));
el3.Add(layout);
}
el3.Save("client_layout.xml");
}
private void handle_unique_layout(Preview preview, String last_known_active_window)
@@ -326,8 +401,39 @@ namespace PreviewToy
}
private void update_client_locations()
{
Process[] processes = Process.GetProcessesByName("ExeFile");
List<IntPtr> processHandles = new List<IntPtr>();
foreach (Process process in processes)
{
Rect rect = new Rect();
GetWindowRect(process.MainWindowHandle, out rect);
int left = Math.Abs(rect.Left);
int right = Math.Abs(rect.Right);
int client_width = Math.Abs(left - right);
int top = Math.Abs(rect.Top);
int bottom = Math.Abs(rect.Bottom);
int client_height = Math.Abs(top - bottom);
ClientLocation clientLocation = new ClientLocation();
clientLocation.X = rect.Left;
clientLocation.Y = rect.Top;
clientLocation.Width = client_width;
clientLocation.Height = client_height;
client_layout[process.MainWindowTitle] = clientLocation;
}
}
public void preview_did_switch()
{
update_client_locations();
store_layout(); //todo: check if it actually changed ...
foreach (KeyValuePair<IntPtr, Preview> entry in previews)
{
@@ -669,5 +775,17 @@ namespace PreviewToy
refresh_thumbnails();
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.track_client_windows = option_track_client_windows.Checked;
Properties.Settings.Default.Save();
refresh_thumbnails();
}
}
}

View File

@@ -120,6 +120,9 @@
<metadata name="previewToyMainBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>182</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18047
// Runtime Version:4.0.30319.34014
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -12,7 +12,7 @@ namespace PreviewToy.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -190,5 +190,17 @@ namespace PreviewToy.Properties {
this["zoom_anchor"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool track_client_windows {
get {
return ((bool)(this["track_client_windows"]));
}
set {
this["track_client_windows"] = value;
}
}
}
}

View File

@@ -44,5 +44,8 @@
<Setting Name="zoom_anchor" Type="System.Byte" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="track_client_windows" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -49,6 +49,9 @@
<setting name="zoom_anchor" serializeAs="String">
<value>0</value>
</setting>
<setting name="track_client_windows" serializeAs="String">
<value>False</value>
</setting>
</PreviewToy.Properties.Settings>
</userSettings>
</configuration>