mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 02:06:36 +02:00
## Summary of the Pull Request - #39572 updated check-spelling but ignored: > 🐣 Breaking Changes [Code Scanning action requires a Code Scanning Ruleset](https://github.com/check-spelling/check-spelling/wiki/Breaking-Change:-Code-Scanning-action-requires-a-Code-Scanning-Ruleset) If you use SARIF reporting, then instead of the workflow yielding an ❌ when it fails, it will rely on [github-advanced-security 🤖](https://github.com/apps/github-advanced-security) to report the failure. You will need to adjust your checks for PRs. This means that check-spelling hasn't been properly doing its job 😦. I'm sorry, I should have pushed a thing to this repo earlier,... Anyway, as with most refreshes, this comes with a number of fixes, some are fixes for typos that snuck in before the 0.0.25 upgrade, some are for things that snuck in after, some are based on new rules in spell-check-this, and some are hand written patterns based on running through this repository a few times. About the 🐣 **breaking change**: someone needs to create a ruleset for this repository (see [Code Scanning action requires a Code Scanning Ruleset: Sample ruleset ](https://github.com/check-spelling/check-spelling/wiki/Breaking-Change:-Code-Scanning-action-requires-a-Code-Scanning-Ruleset#sample-ruleset)). The alternative to adding a ruleset is to change the condition to not use sarif for this repository. In general, I think the github integration from sarif is prettier/more helpful, so I think that it's the better choice. You can see an example of it working in: - https://github.com/check-spelling-sandbox/PowerToys/pull/23 --------- Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com> Co-authored-by: Mike Griese <migrie@microsoft.com> Co-authored-by: Dustin L. Howett <dustin@howett.net>
145 lines
5.3 KiB
C#
145 lines
5.3 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.ComponentModel;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using MouseJump.Common.Models.Drawing;
|
|
using MouseJump.Common.NativeMethods;
|
|
using static MouseJump.Common.NativeMethods.Core;
|
|
using static MouseJump.Common.NativeMethods.User32;
|
|
|
|
namespace MouseJump.Common.Helpers;
|
|
|
|
public static class MouseHelper
|
|
{
|
|
/// <summary>
|
|
/// Calculates where to move the cursor to by projecting a point from
|
|
/// the preview image onto the desktop and using that as the target location.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The preview image origin is (0, 0) but the desktop origin may be non-zero,
|
|
/// or even negative if the primary monitor is not the at the top-left of the
|
|
/// entire desktop rectangle, so results may contain negative coordinates.
|
|
/// </remarks>
|
|
public static PointInfo GetJumpLocation(PointInfo previewLocation, SizeInfo previewSize, RectangleInfo desktopBounds)
|
|
{
|
|
return previewLocation
|
|
.Scale(previewSize.ScaleToFitRatio(desktopBounds.Size))
|
|
.Offset(desktopBounds.Location);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the current position of the cursor.
|
|
/// </summary>
|
|
public static PointInfo GetCursorPosition()
|
|
{
|
|
var lpPoint = new LPPOINT(new POINT(0, 0));
|
|
var result = User32.GetCursorPos(lpPoint);
|
|
if (!result)
|
|
{
|
|
throw new Win32Exception(
|
|
Marshal.GetLastWin32Error());
|
|
}
|
|
|
|
var point = lpPoint.ToStructure();
|
|
lpPoint.Free();
|
|
|
|
return new PointInfo(
|
|
point.x, point.y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Moves the cursor to the specified location.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See https://github.com/mikeclayton/FancyMouse/pull/3
|
|
/// </remarks>
|
|
public static void SetCursorPosition(PointInfo location)
|
|
{
|
|
// set the new cursor position *twice* - the cursor sometimes end up in
|
|
// the wrong place if we try to cross the dead space between non-aligned
|
|
// monitors - e.g. when trying to move the cursor from (a) to (b) we can
|
|
// *sometimes* - for no clear reason - end up at (c) instead.
|
|
//
|
|
// +----------------+
|
|
// |(c) (b) |
|
|
// | |
|
|
// | |
|
|
// | |
|
|
// +---------+ |
|
|
// | (a) | |
|
|
// +---------+----------------+
|
|
//
|
|
// setting the position again seems to fix this and moves the
|
|
// cursor to the expected location (b)
|
|
var target = location.ToPoint();
|
|
for (var i = 0; i < 2; i++)
|
|
{
|
|
var result = User32.SetCursorPos(target.X, target.Y);
|
|
if (!result)
|
|
{
|
|
throw new Win32Exception(
|
|
Marshal.GetLastWin32Error());
|
|
}
|
|
|
|
var current = MouseHelper.GetCursorPosition();
|
|
if ((current.X == target.X) || (current.Y == target.Y))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
// temporary workaround for issue #1273
|
|
MouseHelper.SimulateMouseMovementEvent(location);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends an input simulating an absolute mouse move to the new location.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See https://github.com/microsoft/PowerToys/issues/24523
|
|
/// https://github.com/microsoft/PowerToys/pull/24527
|
|
/// </remarks>
|
|
private static void SimulateMouseMovementEvent(PointInfo location)
|
|
{
|
|
var inputs = new User32.INPUT[]
|
|
{
|
|
new(
|
|
type: INPUT_TYPE.INPUT_MOUSE,
|
|
data: new INPUT.DUMMYUNIONNAME(
|
|
mi: new MOUSEINPUT(
|
|
dx: (int)MouseHelper.CalculateAbsoluteCoordinateX(location.X),
|
|
dy: (int)MouseHelper.CalculateAbsoluteCoordinateY(location.Y),
|
|
mouseData: 0,
|
|
dwFlags: MOUSE_EVENT_FLAGS.MOUSEEVENTF_MOVE | MOUSE_EVENT_FLAGS.MOUSEEVENTF_ABSOLUTE,
|
|
time: 0,
|
|
dwExtraInfo: ULONG_PTR.Null))),
|
|
};
|
|
var result = User32.SendInput(
|
|
(UINT)inputs.Length,
|
|
new LPINPUT(inputs),
|
|
INPUT.Size * inputs.Length);
|
|
if (result != inputs.Length)
|
|
{
|
|
throw new Win32Exception(
|
|
Marshal.GetLastWin32Error());
|
|
}
|
|
}
|
|
|
|
private static decimal CalculateAbsoluteCoordinateX(decimal x)
|
|
{
|
|
// If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535.
|
|
// see https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput
|
|
return (x * 65535) / User32.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CXSCREEN);
|
|
}
|
|
|
|
private static decimal CalculateAbsoluteCoordinateY(decimal y)
|
|
{
|
|
// If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535.
|
|
// see https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput
|
|
return (y * 65535) / User32.GetSystemMetrics(SYSTEM_METRICS_INDEX.SM_CYSCREEN);
|
|
}
|
|
}
|