fixed bug - careet in notepad and menu start OS

This commit is contained in:
2026-08-08 23:00:37 +05:00
parent ba0748920b
commit 5ecc46f7a3
4 changed files with 113 additions and 33 deletions
@@ -0,0 +1,41 @@
using System.Runtime.InteropServices;
namespace CursorLang.Interop;
/// <summary>
/// Сведения о вводе в активном приложении: какое окно держит фокус клавиатуры
/// и где находится каретка.
/// </summary>
internal static class ForegroundInputNative
{
[StructLayout(LayoutKind.Sequential)]
internal struct GuiThreadInfo
{
public int cbSize;
public uint flags;
public IntPtr hwndActive;
public IntPtr hwndFocus;
public IntPtr hwndCapture;
public IntPtr hwndMenuOwner;
public IntPtr hwndMoveSize;
public IntPtr hwndCaret;
public PopupWindowNative.Rect rcCaret;
}
[DllImport("user32.dll")]
private static extern bool GetGUIThreadInfo(uint idThread, ref GuiThreadInfo lpgui);
/// <summary>
/// Состояние ввода потока переднего плана.
/// </summary>
/// <remarks>
/// Нулевой идентификатор потока не случаен: у современных приложений окно
/// верхнего уровня и окно ввода живут в разных потоках, и спрашивать нужно
/// именно про передний план целиком.
/// </remarks>
internal static bool TryGetInfo(out GuiThreadInfo info)
{
info = new GuiThreadInfo { cbSize = Marshal.SizeOf<GuiThreadInfo>() };
return GetGUIThreadInfo(0, ref info);
}
}