Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 8  →  ?path2? @ 9
File deleted
\ No newline at end of file
/trunk/Widow/WindowRescale.cs
/trunk/Widow/MainForm.cs
@@ -25,7 +25,7 @@
 
public RuleEditForm RuleEditForm { get; set; }
 
public WindowRescale WindowRescale { get; set; }
public WindowManipulation WindowManipulation { get; set; }
 
public AboutForm AboutForm { get; set; }
 
@@ -46,7 +46,7 @@
 
LoadWindows().ContinueWith(task =>
{
WindowRescale = new WindowRescale(this, Windows) {OnWindowCreate = Settings.Default.OnWindowCreate};
WindowManipulation = new WindowManipulation(this, Windows, Settings.Default);
});
}
 
@@ -145,7 +145,7 @@
{
Settings.Default.OnWindowCreate = ((ToolStripMenuItem) sender).Checked;
 
WindowRescale.OnWindowCreate = Settings.Default.OnWindowCreate;
WindowManipulation.OnWindowCreate = Settings.Default.OnWindowCreate;
}
 
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
@@ -157,7 +157,7 @@
 
private void ApplyNowToolStripMenuItem_Click(object sender, EventArgs e)
{
WindowRescale.Apply();
WindowManipulation.Apply();
}
 
private void OnEveryToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
@@ -172,8 +172,8 @@
Settings.Default.ApplyEveryTimeEnabled = toolStripMenuItem.Checked;
Settings.Default.ApplyEveryTime = time.ToString(CultureInfo.InvariantCulture);
 
WindowRescale.ApplyEveryTime = time;
WindowRescale.ApplyEveryTimeEnabled = toolStripMenuItem.Checked;
WindowManipulation.ApplyEveryTime = time;
WindowManipulation.ApplyEveryTimeEnabled = toolStripMenuItem.Checked;
}
 
#endregion
/trunk/Widow/Properties/Settings.Designer.cs
@@ -13,7 +13,7 @@
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
/trunk/Widow/RuleEditForm.Designer.cs
@@ -35,6 +35,10 @@
this.refreshButton = new System.Windows.Forms.Button();
this.desktopWindowsListBox = new System.Windows.Forms.ListBox();
this.addButton = new System.Windows.Forms.Button();
this.ignoreLeftCheckBox = new System.Windows.Forms.CheckBox();
this.ignoreTopCheckBox = new System.Windows.Forms.CheckBox();
this.ignoreWidthCheckBox = new System.Windows.Forms.CheckBox();
this.ignoreHeightCheckBox = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox7.SuspendLayout();
@@ -84,7 +88,7 @@
this.groupBox2.Controls.Add(this.groupBox3);
this.groupBox2.Location = new System.Drawing.Point(382, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(127, 302);
this.groupBox2.Size = new System.Drawing.Size(190, 302);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Settings";
@@ -109,10 +113,11 @@
//
// groupBox6
//
this.groupBox6.Controls.Add(this.ignoreHeightCheckBox);
this.groupBox6.Controls.Add(this.WindowHeight);
this.groupBox6.Location = new System.Drawing.Point(6, 243);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(114, 50);
this.groupBox6.Size = new System.Drawing.Size(178, 50);
this.groupBox6.TabIndex = 4;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "Height";
@@ -127,10 +132,11 @@
//
// groupBox5
//
this.groupBox5.Controls.Add(this.ignoreWidthCheckBox);
this.groupBox5.Controls.Add(this.WindowWidth);
this.groupBox5.Location = new System.Drawing.Point(6, 187);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(114, 50);
this.groupBox5.Size = new System.Drawing.Size(178, 50);
this.groupBox5.TabIndex = 3;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "Width";
@@ -145,10 +151,11 @@
//
// groupBox4
//
this.groupBox4.Controls.Add(this.ignoreTopCheckBox);
this.groupBox4.Controls.Add(this.WindowTop);
this.groupBox4.Location = new System.Drawing.Point(6, 131);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(114, 50);
this.groupBox4.Size = new System.Drawing.Size(178, 50);
this.groupBox4.TabIndex = 2;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Top";
@@ -163,10 +170,11 @@
//
// groupBox3
//
this.groupBox3.Controls.Add(this.ignoreLeftCheckBox);
this.groupBox3.Controls.Add(this.WindowLeft);
this.groupBox3.Location = new System.Drawing.Point(6, 75);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(114, 50);
this.groupBox3.Size = new System.Drawing.Size(178, 50);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Left";
@@ -219,17 +227,61 @@
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.AddButton_Click);
//
// ignoreLeftCheckBox
//
this.ignoreLeftCheckBox.AutoSize = true;
this.ignoreLeftCheckBox.Location = new System.Drawing.Point(114, 21);
this.ignoreLeftCheckBox.Name = "ignoreLeftCheckBox";
this.ignoreLeftCheckBox.Size = new System.Drawing.Size(56, 17);
this.ignoreLeftCheckBox.TabIndex = 1;
this.ignoreLeftCheckBox.Text = "Ignore";
this.ignoreLeftCheckBox.UseVisualStyleBackColor = true;
this.ignoreLeftCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged);
//
// ignoreTopCheckBox
//
this.ignoreTopCheckBox.AutoSize = true;
this.ignoreTopCheckBox.Location = new System.Drawing.Point(114, 21);
this.ignoreTopCheckBox.Name = "ignoreTopCheckBox";
this.ignoreTopCheckBox.Size = new System.Drawing.Size(56, 17);
this.ignoreTopCheckBox.TabIndex = 2;
this.ignoreTopCheckBox.Text = "Ignore";
this.ignoreTopCheckBox.UseVisualStyleBackColor = true;
this.ignoreTopCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged);
//
// ignoreWidthCheckBox
//
this.ignoreWidthCheckBox.AutoSize = true;
this.ignoreWidthCheckBox.Location = new System.Drawing.Point(114, 22);
this.ignoreWidthCheckBox.Name = "ignoreWidthCheckBox";
this.ignoreWidthCheckBox.Size = new System.Drawing.Size(56, 17);
this.ignoreWidthCheckBox.TabIndex = 2;
this.ignoreWidthCheckBox.Text = "Ignore";
this.ignoreWidthCheckBox.UseVisualStyleBackColor = true;
this.ignoreWidthCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged);
//
// ignoreHeightCheckBox
//
this.ignoreHeightCheckBox.AutoSize = true;
this.ignoreHeightCheckBox.Location = new System.Drawing.Point(114, 21);
this.ignoreHeightCheckBox.Name = "ignoreHeightCheckBox";
this.ignoreHeightCheckBox.Size = new System.Drawing.Size(56, 17);
this.ignoreHeightCheckBox.TabIndex = 2;
this.ignoreHeightCheckBox.Text = "Ignore";
this.ignoreHeightCheckBox.UseVisualStyleBackColor = true;
this.ignoreHeightCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged);
//
// RuleEditForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(524, 362);
this.ClientSize = new System.Drawing.Size(584, 362);
this.Controls.Add(this.groupBox8);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(540, 400);
this.MinimumSize = new System.Drawing.Size(540, 400);
this.MaximumSize = new System.Drawing.Size(600, 400);
this.MinimumSize = new System.Drawing.Size(600, 400);
this.Name = "RuleEditForm";
this.Text = "Rule Editor";
this.groupBox1.ResumeLayout(false);
@@ -269,5 +321,9 @@
private System.Windows.Forms.Button addButton;
private System.Windows.Forms.Button removeButton;
private System.Windows.Forms.Button refreshButton;
private System.Windows.Forms.CheckBox ignoreHeightCheckBox;
private System.Windows.Forms.CheckBox ignoreWidthCheckBox;
private System.Windows.Forms.CheckBox ignoreTopCheckBox;
private System.Windows.Forms.CheckBox ignoreLeftCheckBox;
}
}
/trunk/Widow/RuleEditForm.cs
@@ -126,9 +126,13 @@
if (listBox.SelectedIndex == -1)
{
WindowName.Text = string.Empty;
ignoreLeftCheckBox.Checked = false;
WindowLeft.Text = string.Empty;
ignoreTopCheckBox.Checked = false;
WindowTop.Text = string.Empty;
ignoreWidthCheckBox.Checked = false;
WindowWidth.Text = string.Empty;
ignoreHeightCheckBox.Checked = false;
WindowHeight.Text = string.Empty;
return;
}
@@ -141,9 +145,13 @@
}
 
WindowName.Text = window.Name;
ignoreLeftCheckBox.Checked = window.IgnoreLeft;
WindowLeft.Text = window.Left.ToString();
ignoreTopCheckBox.Checked = window.IgnoreTop;
WindowTop.Text = window.Top.ToString();
ignoreWidthCheckBox.Checked = window.IgnoreWidth;
WindowWidth.Text = window.Width.ToString();
ignoreHeightCheckBox.Checked = window.IgnoreHeight;
WindowHeight.Text = window.Height.ToString();
}
 
@@ -258,6 +266,38 @@
}
}
 
private void OnIgnoreWindowSettings_CheckedChanged(object sender, EventArgs e)
{
var selectedWindow = (Window) windowRulesListBox.SelectedItem;
 
if (selectedWindow == null)
{
ignoreLeftCheckBox.Checked = false;
ignoreTopCheckBox.Checked = false;
ignoreWidthCheckBox.Checked = false;
ignoreHeightCheckBox.Checked = false;
 
return;
}
 
var checkBox = (CheckBox) sender;
switch (checkBox.Name)
{
case nameof(ignoreHeightCheckBox):
selectedWindow.IgnoreHeight = checkBox.Checked;
break;
case nameof(ignoreWidthCheckBox):
selectedWindow.IgnoreWidth = checkBox.Checked;
break;
case nameof(ignoreTopCheckBox):
selectedWindow.IgnoreTop = checkBox.Checked;
break;
case nameof(ignoreLeftCheckBox):
selectedWindow.IgnoreLeft = checkBox.Checked;
break;
}
}
 
#endregion
 
#region Private Methods
/trunk/Widow/Widow.csproj
@@ -58,7 +58,7 @@
<Compile Include="AboutForm.Designer.cs">
<DependentUpon>AboutForm.cs</DependentUpon>
</Compile>
<Compile Include="WindowRescale.cs" />
<Compile Include="WindowManipulation.cs" />
<Compile Include="Constants.cs" />
<Compile Include="DesktopWindow.cs" />
<Compile Include="Helpers.cs" />
@@ -105,7 +105,7 @@
</Compile>
<None Include="app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<Generator>PublicSettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
/trunk/Widow/WindowManipulation.cs
@@ -0,0 +1,160 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Widow.Properties;
 
namespace Widow
{
public class WindowManipulation : IDisposable
{
#region Public Enums, Properties and Fields
 
public bool OnWindowCreate { get; set; }
 
public int ApplyEveryTime { get; set; }
 
public bool ApplyEveryTimeEnabled { get; set; }
 
#endregion
 
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
 
private MainForm Form { get; }
 
private Windows.Windows Windows { get; }
 
private CancellationTokenSource CancellationTokenSource { get; set; }
 
private Task ApplyEveryTask { get; }
 
#endregion
 
#region Constructors, Destructors and Finalizers
 
public WindowManipulation()
{
CancellationTokenSource = new CancellationTokenSource();
ApplyEveryTask = ApplyEvery(CancellationTokenSource.Token);
}
 
public WindowManipulation(MainForm mainForm) : this()
{
Form = mainForm;
 
Form.WindowCreated += Form_WindowCreated;
}
 
public WindowManipulation(MainForm mainForm, Windows.Windows windows) : this(mainForm)
{
Windows = windows;
}
 
public WindowManipulation(MainForm mainForm, Windows.Windows windows, Settings settings) : this(mainForm,
windows)
{
OnWindowCreate = settings.OnWindowCreate;
ApplyEveryTimeEnabled = settings.ApplyEveryTimeEnabled;
if (int.TryParse(settings.ApplyEveryTime, out var time))
{
ApplyEveryTime = time;
}
}
 
public void Dispose()
{
Form.WindowCreated -= Form_WindowCreated;
CancellationTokenSource.Cancel();
ApplyEveryTask.Wait();
CancellationTokenSource.Dispose();
CancellationTokenSource = null;
}
 
#endregion
 
#region Event Handlers
 
private void Form_WindowCreated(object sender, WindowCreatedEventArgs e)
{
if (!OnWindowCreate)
{
return;
}
 
if (!Windows.Contains(e.Name))
{
return;
}
 
Apply();
}
 
#endregion
 
#region Public Methods
 
public void Apply()
{
foreach (var window in Windows.Window)
{
var hWnd = Helpers.FindWindowByTitle(window.Name);
if (hWnd == IntPtr.Zero)
{
continue;
}
 
if (!Natives.GetWindowRect(hWnd, out var rect))
{
continue;
}
 
var left = window.Left;
if (window.IgnoreLeft)
{
left = rect.Left;
}
 
var top = window.Top;
if (window.IgnoreTop)
{
top = rect.Top;
}
 
var width = window.Width;
if (window.IgnoreWidth)
{
width = rect.Left - rect.Right;
}
 
var height = window.Height;
if (window.IgnoreHeight)
{
height = rect.Top - rect.Bottom;
}
 
Natives.MoveWindow(hWnd, left, top, width, height, true);
}
}
 
#endregion
 
#region Private Methods
 
private async Task ApplyEvery(CancellationToken cancellationToken)
{
do
{
if (!ApplyEveryTimeEnabled)
{
await Task.Delay(1000, cancellationToken);
continue;
}
 
await Task.Delay(ApplyEveryTime, cancellationToken);
 
Apply();
} while (!cancellationToken.IsCancellationRequested);
}
 
#endregion
}
}
/trunk/Windows/Window.cs
@@ -26,6 +26,22 @@
}
}
 
[XmlElement(ElementName = "IgnoreWidth")]
public bool IgnoreWidth
{
get => _ignoreWidth;
set
{
if (value == _ignoreWidth)
{
return;
}
 
_ignoreWidth = value;
OnPropertyChanged();
}
}
 
[XmlElement(ElementName = "Width")]
public int Width
{
@@ -42,6 +58,22 @@
}
}
 
[XmlElement(ElementName = "IgnoreHeight")]
public bool IgnoreHeight
{
get => _ignoreHeight;
set
{
if (value == _ignoreHeight)
{
return;
}
 
_ignoreHeight = value;
OnPropertyChanged();
}
}
 
[XmlElement(ElementName = "Height")]
public int Height
{
@@ -58,6 +90,22 @@
}
}
 
[XmlElement(ElementName = "IgnoreLeft")]
public bool IgnoreLeft
{
get => _ignoreLeft;
set
{
if (value == _ignoreLeft)
{
return;
}
 
_ignoreLeft = value;
OnPropertyChanged();
}
}
 
[XmlElement(ElementName = "Left")]
public int Left
{
@@ -74,6 +122,22 @@
}
}
 
[XmlElement(ElementName = "IgnoreTop")]
public bool IgnoreTop
{
get => _ignoreTop;
set
{
if (value == _ignoreTop)
{
return;
}
 
_ignoreTop = value;
OnPropertyChanged();
}
}
 
[XmlElement(ElementName = "Top")]
public int Top
{
@@ -96,6 +160,14 @@
 
private int _height;
 
private bool _ignoreHeight;
 
private bool _ignoreLeft;
 
private bool _ignoreTop;
 
private bool _ignoreWidth;
 
private int _left;
 
private string _name;
/trunk/Windows/Windows.cs
@@ -1,5 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;
using Windows.Annotations;
@@ -7,12 +11,12 @@
namespace Windows
{
[XmlRoot(Namespace = "urn:widow-windows-schema", ElementName = "Windows")]
public class Windows : INotifyPropertyChanged
public class Windows : INotifyPropertyChanged, IDisposable
{
#region Public Enums, Properties and Fields
 
[XmlElement(ElementName = "Window")]
public List<Window> Window
public ObservableCollection<Window> Window
{
get => _window;
set
@@ -22,7 +26,15 @@
return;
}
 
_window.CollectionChanged -= _window_CollectionChanged;
_window = value;
_windows.Clear();
foreach (var window in value)
{
_windows.Add(window.Name);
}
 
_window.CollectionChanged += _window_CollectionChanged;
OnPropertyChanged();
}
}
@@ -31,8 +43,10 @@
 
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
 
private List<Window> _window = new List<Window>();
private ObservableCollection<Window> _window = new ObservableCollection<Window>();
 
private HashSet<string> _windows = new HashSet<string>();
 
#endregion
 
#region Constructors, Destructors and Finalizers
@@ -40,8 +54,14 @@
[UsedImplicitly]
public Windows()
{
_window.CollectionChanged += _window_CollectionChanged;
}
 
public void Dispose()
{
Window.CollectionChanged -= _window_CollectionChanged;
}
 
#endregion
 
#region Interface
@@ -50,6 +70,45 @@
 
#endregion
 
#region Event Handlers
 
private void _window_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
{
foreach (var window in e.OldItems.OfType<Window>())
{
if (_windows.Contains(window.Name))
{
_windows.Remove(window.Name);
}
}
}
 
 
if (e.NewItems != null)
{
foreach (var window in e.NewItems.OfType<Window>())
{
if (!_windows.Contains(window.Name))
{
_windows.Add(window.Name);
}
}
}
}
 
#endregion
 
#region Public Methods
 
public bool Contains(string name)
{
return _windows.Contains(name);
}
 
#endregion
 
#region Private Methods
 
[NotifyPropertyChangedInvocator]