Skip to content

Commit 3e896b5

Browse files
committed
Do not use hook & unhook to check window moving
1 parent aefd18a commit 3e896b5

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

Flow.Launcher.Infrastructure/QuickSwitch/QuickSwitch.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ public static class QuickSwitch
5959

6060
private static readonly SemaphoreSlim _navigationLock = new(1, 1);
6161

62-
private static HWINEVENTHOOK _moveSizeHook = HWINEVENTHOOK.Null;
62+
// Note: Here we do not start & stop the timer beacause when there are many dialog windows
63+
// Unhooking and hooking will take too much time which can make window position weird
64+
// So we start & stop the timer when we find a file dialog window
65+
/*private static HWINEVENTHOOK _moveSizeHook = HWINEVENTHOOK.Null;
6366
6467
private static HWND _hookedDialogWindowHandle = HWND.Null;
65-
private static readonly object _hookedDialogWindowHandleLock = new();
68+
private static readonly object _hookedDialogWindowHandleLock = new();*/
6669

6770
private static bool _isInitialized = false;
6871

@@ -163,8 +166,12 @@ private static unsafe void InvokeShowQuickSwitchWindow()
163166
if (_settings.ShowQuickSwitchWindow)
164167
{
165168
ShowQuickSwitchWindow?.Invoke(_dialogWindowHandle.Value);
169+
_dragMoveTimer?.Start();
166170

167-
lock (_hookedDialogWindowHandleLock)
171+
// Note: Here we do not start & stop the timer beacause when there are many dialog windows
172+
// Unhooking and hooking will take too much time which can make window position weird
173+
// So we start & stop the timer when we find a file dialog window
174+
/*lock (_hookedDialogWindowHandleLock)
168175
{
169176
var needHook = _hookedDialogWindowHandle == HWND.Null ||
170177
_hookedDialogWindowHandle != _dialogWindowHandle;
@@ -191,7 +198,7 @@ private static unsafe void InvokeShowQuickSwitchWindow()
191198
}
192199
193200
_hookedDialogWindowHandle = _dialogWindowHandle;
194-
}
201+
}*/
195202
}
196203
}
197204

@@ -205,8 +212,12 @@ private static void InvokeResetQuickSwitchWindow()
205212
{
206213
// Reset quick switch window
207214
ResetQuickSwitchWindow?.Invoke();
215+
_dragMoveTimer?.Stop();
208216

209-
lock (_hookedDialogWindowHandleLock)
217+
// Note: Here we do not start & stop the timer beacause when there are many dialog windows
218+
// Unhooking and hooking will take too much time which can make window position weird
219+
// So we start & stop the timer when we find a file dialog window
220+
/*lock (_hookedDialogWindowHandleLock)
210221
{
211222
if (!_moveSizeHook.IsNull)
212223
{
@@ -215,14 +226,15 @@ private static void InvokeResetQuickSwitchWindow()
215226
}
216227
217228
_hookedDialogWindowHandle = HWND.Null;
218-
}
229+
}*/
219230
}
220231

221232
private static void InvokeHideQuickSwitchWindow()
222233
{
223234
// Neither quick switch window nor file dialog window is foreground
224235
// Hide quick switch window until the file dialog window is brought to the foreground
225236
HideQuickSwitchWindow?.Invoke();
237+
_dragMoveTimer?.Stop();
226238
}
227239

228240
#endregion
@@ -354,7 +366,10 @@ uint dwmsEventTime
354366
}
355367
}
356368

357-
private static void MoveSizeCallBack(
369+
// Note: Here we do not start & stop the timer beacause when there are many dialog windows
370+
// Unhooking and hooking will take too much time which can make window position weird
371+
// So we start & stop the timer when we find a file dialog window
372+
/*private static void MoveSizeCallBack(
358373
HWINEVENTHOOK hWinEventHook,
359374
uint eventType,
360375
HWND hwnd,
@@ -377,7 +392,7 @@ uint dwmsEventTime
377392
break;
378393
}
379394
}
380-
}
395+
}*/
381396

382397
private static void DestroyChangeCallback(
383398
HWINEVENTHOOK hWinEventHook,
@@ -619,11 +634,11 @@ public static void Dispose()
619634
PInvoke.UnhookWinEvent(_locationChangeHook);
620635
_locationChangeHook = HWINEVENTHOOK.Null;
621636
}
622-
if (!_moveSizeHook.IsNull)
637+
/*if (!_moveSizeHook.IsNull)
623638
{
624639
PInvoke.UnhookWinEvent(_moveSizeHook);
625640
_moveSizeHook = HWINEVENTHOOK.Null;
626-
}
641+
}*/
627642
if (!_destroyChangeHook.IsNull)
628643
{
629644
PInvoke.UnhookWinEvent(_destroyChangeHook);

0 commit comments

Comments
 (0)