Widow – Diff between revs 12 and 14

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 12 Rev 14
Line 9... Line 9...
9   9  
10 namespace Widow 10 namespace Widow
11 { 11 {
12 public class WindowManipulation : IDisposable 12 public class WindowManipulation : IDisposable
13 { -  
14 #region Public Events & Delegates -  
15   -  
16 public event EventHandler<WindowManipulatedEventArgs> WindowManipulated; -  
17   -  
18 #endregion -  
19   13 {
Line 20... Line 14...
20 #region Public Enums, Properties and Fields 14 #region Public Enums, Properties and Fields
Line 21... Line 15...
21   15  
Line 35... Line 29...
35   29  
Line 36... Line 30...
36 private CancellationTokenSource CancellationTokenSource { get; set; } 30 private CancellationTokenSource CancellationTokenSource { get; set; }
Line 37... Line 31...
37   31  
Line 38... Line 32...
38 private Task ApplyEveryTask { get; } 32 private Task ApplyEveryTask { get; }
Line 39... Line 33...
39   33  
Line 40... Line 34...
40 private BufferBlock<Window> WindowsBufferBlock { get; } 34 private BufferBlock<WindowModification> WindowsBufferBlock { get; }
Line 41... Line 35...
41   35  
Line 42... Line 36...
42 private ActionBlock<Window> WindowsActionBlock { get; } 36 private ActionBlock<WindowModification> WindowsActionBlock { get; }
43   37  
44 private IDisposable WindowsLink { get; set; } 38 private IDisposable WindowsLink { get; set; }
45   39  
46 #endregion 40 #endregion
47   41  
Line 48... Line 42...
48 #region Constructors, Destructors and Finalizers 42 #region Constructors, Destructors and Finalizers
49   43  
Line 102... Line 96...
102 if (!OnWindowCreate) 96 if (!OnWindowCreate)
103 { 97 {
104 return; 98 return;
105 } 99 }
Line -... Line 100...
-   100  
106   101 var @class = Helpers.GetWindowClass(e.Handle);
107 if (!WindowsToManipulate.TryGetWindow(e.Title, out _)) 102 if (!WindowsToManipulate.TryGetWindow(new WindowHash(e.Title, @class), out _))
108 { 103 {
109 return; 104 return;
Line 110... Line 105...
110 } 105 }
Line 116... Line 111...
116   111  
Line 117... Line 112...
117 #region Public Methods 112 #region Public Methods
118   113  
119 public async Task Apply() 114 public async Task Apply()
120 { 115 {
121 var windows = new List<Window>(); 116 var windows = new List<WindowModification>();
122 foreach (var hWnd in Helpers.EnumerateWindows()) 117 foreach (var hWnd in Helpers.FindWindows((wnd, param) => true))
-   118 {
-   119 var windowTitle = Helpers.GetWindowTitle(hWnd);
-   120  
-   121 if (string.IsNullOrEmpty(windowTitle))
-   122 {
Line -... Line 123...
-   123 continue;
123 { 124 }
124 var title = Helpers.GetWindowTitle(hWnd); 125  
125   126 var windowClass = Helpers.GetWindowClass(hWnd);
126 if (string.IsNullOrEmpty(title)) 127 if (string.IsNullOrEmpty(windowClass))
Line -... Line 128...
-   128 {
127 { 129 continue;
128 continue; 130 }
129 } 131  
130   132 var windowHash = new WindowHash(windowTitle, windowClass);
Line 131... Line 133...
131 if (!WindowsToManipulate.TryGetWindow(title, out var window)) 133 if (!WindowsToManipulate.TryGetWindow(windowHash, out var window))
132 { 134 {
Line 133... Line 135...
133 continue; 135 continue;
134 } 136 }
Line 135... Line 137...
135   137  
Line 136... Line 138...
136 windows.Add(window); 138 windows.Add(new WindowModification(hWnd, window));
Line 137... Line 139...
137 } 139 }
138   140  
139 await Task.WhenAll(windows.Select(window => WindowsBufferBlock.SendAsync(window))); 141 await Task.WhenAll(windows.Select(modification => WindowsBufferBlock.SendAsync(modification)));
140 } 142 }
141   -  
142 #endregion -  
143   -  
144 #region Private Methods 143  
145   -  
146 private void ManipulateWindows(Window window) -  
147 { -  
148 foreach (var hWnd in Helpers.FindWindowsWithText(window.Title)) -  
149 { -  
150 if (hWnd == IntPtr.Zero) -  
151 { -  
152 continue; -  
153 } -  
154   -  
155 if (!Natives.GetWindowRect(hWnd, out var rect)) 144 #endregion
Line 156... Line -...
156 { -  
157 continue; 145  
158 } 146 #region Private Methods
159   147  
160 var left = window.Left; 148 private static void ManipulateWindows(WindowModification modification)
Line 161... Line 149...
161 if (window.IgnoreLeft) 149 {
162 { 150 if (modification.Handle == IntPtr.Zero)
163 left = rect.Left; 151 {
164 } 152 return;
165   153 }
Line 166... Line 154...
166 var top = window.Top; 154  
167 if (window.IgnoreTop) 155 if (!Natives.GetWindowRect(modification.Handle, out var rect))
168 { 156 {
169 top = rect.Top; 157 return;
170 } 158 }
Line 171... Line 159...
171   159  
-   160 var left = modification.Window.Left;
-   161 if (modification.Window.IgnoreLeft)
-   162 {
-   163 left = rect.Left;
Line -... Line 164...
-   164 }
172 var width = window.Width; 165  
-   166 var top = modification.Window.Top;
-   167 if (modification.Window.IgnoreTop)
173 if (window.IgnoreWidth) 168 {
-   169 top = rect.Top;
-   170 }
174 { 171  
Line 175... Line 172...
175 width = rect.Left - rect.Right; 172 var width = modification.Window.Width;
176 } 173 if (modification.Window.IgnoreWidth)
177   174 {