mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 14:59:16 +08:00
[Peek]Prevent activation when user is typing (#33299)
* prevent Peek activation when user is typing * fix spellcheck
This commit is contained in:
parent
d3aa5028aa
commit
3e07b9b8f4
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@ -149,6 +149,7 @@ Cangjie
|
||||
CANRENAME
|
||||
CAPTUREBLT
|
||||
CAPTURECHANGED
|
||||
CARETBLINKING
|
||||
CAtl
|
||||
cch
|
||||
CCHDEVICENAME
|
||||
|
@ -3,12 +3,14 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Peek.Common.Models;
|
||||
using Peek.UI.Extensions;
|
||||
using SHDocVw;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.UI.Shell;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
using IServiceProvider = Peek.Common.Models.IServiceProvider;
|
||||
|
||||
namespace Peek.UI.Helpers
|
||||
@ -27,7 +29,12 @@ namespace Peek.UI.Helpers
|
||||
|
||||
private static IShellItemArray? GetItemsInternal(HWND foregroundWindowHandle, bool onlySelectedFiles)
|
||||
{
|
||||
if (foregroundWindowHandle.IsDesktopWindow())
|
||||
// If the caret is visible, we assume the user is typing and we don't want to interfere with that
|
||||
if (CaretVisible(foregroundWindowHandle))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (foregroundWindowHandle.IsDesktopWindow())
|
||||
{
|
||||
return GetItemsFromDesktop(foregroundWindowHandle, onlySelectedFiles);
|
||||
}
|
||||
@ -104,5 +111,21 @@ namespace Peek.UI.Helpers
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the caret is visible in the specified window.
|
||||
/// </summary>
|
||||
private static bool CaretVisible(HWND hwnd)
|
||||
{
|
||||
GUITHREADINFO guiThreadInfo = new() { cbSize = (uint)Marshal.SizeOf<GUITHREADINFO>() };
|
||||
|
||||
// Get information for the foreground thread
|
||||
if (PInvoke.GetGUIThreadInfo(0, ref guiThreadInfo))
|
||||
{
|
||||
return guiThreadInfo.hwndActive == hwnd && (guiThreadInfo.flags & GUITHREADINFO_FLAGS.GUI_CARETBLINKING) != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,5 @@ GetWindowRect
|
||||
SET_WINDOW_POS_FLAGS
|
||||
SetWindowPos
|
||||
GetWindowPlacement
|
||||
SetWindowPlacement
|
||||
SetWindowPlacement
|
||||
GetGUIThreadInfo
|
Loading…
Reference in New Issue
Block a user