[Peek]Prevent activation when user is typing (#33299)

* prevent Peek activation when user is typing

* fix spellcheck
This commit is contained in:
Davide Giacometti
2024-06-12 15:54:55 +02:00
committed by GitHub
parent d3aa5028aa
commit 3e07b9b8f4
3 changed files with 27 additions and 2 deletions

View File

@@ -149,6 +149,7 @@ Cangjie
CANRENAME CANRENAME
CAPTUREBLT CAPTUREBLT
CAPTURECHANGED CAPTURECHANGED
CARETBLINKING
CAtl CAtl
cch cch
CCHDEVICENAME CCHDEVICENAME

View File

@@ -3,12 +3,14 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Runtime.InteropServices;
using Peek.Common.Models; using Peek.Common.Models;
using Peek.UI.Extensions; using Peek.UI.Extensions;
using SHDocVw; using SHDocVw;
using Windows.Win32; using Windows.Win32;
using Windows.Win32.Foundation; using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell; using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging;
using IServiceProvider = Peek.Common.Models.IServiceProvider; using IServiceProvider = Peek.Common.Models.IServiceProvider;
namespace Peek.UI.Helpers namespace Peek.UI.Helpers
@@ -27,7 +29,12 @@ namespace Peek.UI.Helpers
private static IShellItemArray? GetItemsInternal(HWND foregroundWindowHandle, bool onlySelectedFiles) 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); return GetItemsFromDesktop(foregroundWindowHandle, onlySelectedFiles);
} }
@@ -104,5 +111,21 @@ namespace Peek.UI.Helpers
return null; 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;
}
} }
} }

View File

@@ -19,4 +19,5 @@ GetWindowRect
SET_WINDOW_POS_FLAGS SET_WINDOW_POS_FLAGS
SetWindowPos SetWindowPos
GetWindowPlacement GetWindowPlacement
SetWindowPlacement SetWindowPlacement
GetGUIThreadInfo