Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvements #97

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 206 additions & 201 deletions .editorconfig

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
<Import Project="$(SolutionPropertiesLocation)\SolutionProperties.targets" />

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
<PackageReference Include="SharpVectors.Wpf" Version="1.8.2" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.7.30" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="SharpVectors.Wpf" Version="1.8.3" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.9.28" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal async Task HwndHook_ClipboardUpdateMsg_PublishesClipboardChangedEvent()

var handled = false;
testeeService.HwndHook(WinHandle, 0x031D, default, default, ref handled);
await Task.Delay(505);
await Task.Delay(600);

clipboardChangedEvent.Received(1).Publish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Tum4ik.JustClipboardManager/Ioc/Wrappers/IClipboard.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Windows;
using YT.IIGen.Attributes;
using Tum4ik.StinimGen.Attributes;

namespace Tum4ik.JustClipboardManager.Ioc.Wrappers;

[IIFor(typeof(Clipboard), "ClipboardWrapper")]
[IIFor(typeof(Clipboard), WrapperClassName = "ClipboardWrapper")]
internal partial interface IClipboard
{
}
4 changes: 2 additions & 2 deletions Tum4ik.JustClipboardManager/Ioc/Wrappers/IEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using YT.IIGen.Attributes;
using Tum4ik.StinimGen.Attributes;

namespace Tum4ik.JustClipboardManager.Ioc.Wrappers;

[IIFor(typeof(Environment), "EnvironmentWrapper")]
[IIFor(typeof(Environment), WrapperClassName = "EnvironmentWrapper")]
internal partial interface IEnvironment
{
}
6 changes: 3 additions & 3 deletions Tum4ik.JustClipboardManager/Ioc/Wrappers/IFile.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.IO;
using YT.IIGen.Attributes;
using System.IO;
using Tum4ik.StinimGen.Attributes;

namespace Tum4ik.JustClipboardManager.Ioc.Wrappers;

[IIFor(typeof(File), "FileWrapper")]
[IIFor(typeof(File), WrapperClassName = "FileWrapper")]
internal partial interface IFile
{
}
4 changes: 2 additions & 2 deletions Tum4ik.JustClipboardManager/Ioc/Wrappers/IPath.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.IO;
using YT.IIGen.Attributes;
using Tum4ik.StinimGen.Attributes;

namespace Tum4ik.JustClipboardManager.Ioc.Wrappers;

[IIFor(typeof(Path), "PathWrapper")]
[IIFor(typeof(Path), WrapperClassName = "PathWrapper")]
internal partial interface IPath
{
}
4 changes: 2 additions & 2 deletions Tum4ik.JustClipboardManager/Ioc/Wrappers/IProcess.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Diagnostics;
using YT.IIGen.Attributes;
using Tum4ik.StinimGen.Attributes;

namespace Tum4ik.JustClipboardManager.Ioc.Wrappers;

[IIFor(typeof(Process), "ProcessWrapper")]
[IIFor(typeof(Process), WrapperClassName = "ProcessWrapper")]
internal partial interface IProcess
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@
namespace Tum4ik.JustClipboardManager.Services.PInvokeWrappers;
internal interface IKernel32DllService
{
/// <summary>
/// Adds a character string to the global atom table and returns a unique value (an atom) identifying the string.
/// </summary>
/// <param name="lpString">
/// The null-terminated string to be added. The string can have a maximum size of 255 bytes.
/// Strings that differ only in case are considered identical. The case of the first string of this name
/// added to the table is preserved and returned by the GlobalGetAtomName function.
/// </param>
/// <returns>
/// If the function succeeds, the return value is the newly created atom.
/// If the function fails, the return value is zero.
/// </returns>
/// <inheritdoc cref="PInvoke.GlobalAddAtom(string)"/>
ushort GlobalAddAtom(string lpString) => PInvoke.GlobalAddAtom(lpString);

/// <summary>
/// Decrements the reference count of a global string atom. If the atom's reference count reaches zero,
/// removes the string associated with the atom from the global atom table.
/// </summary>
/// <param name="nAtom">The atom and character string to be deleted.</param>
/// <returns>The function always returns (ATOM) 0.</returns>
/// <inheritdoc cref="PInvoke.GlobalDeleteAtom(ushort)"/>
ushort GlobalDeleteAtom(ushort nAtom) => PInvoke.GlobalDeleteAtom(nAtom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Tum4ik.JustClipboardManager.Services.PInvokeWrappers;
internal interface IOleaccDllService
{
/// <inheritdoc cref="PInvoke.AccessibleObjectFromWindow(HWND, uint, in Guid, out void*)"/>
unsafe int AccessibleObjectFromWindow(nint hwnd, OBJECT_IDENTIFIER dwId, Guid riid, out object ppvObject)
{
var result = PInvoke.AccessibleObjectFromWindow((HWND) hwnd, (uint) dwId, riid, out var ppv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@ namespace Tum4ik.JustClipboardManager.Services.PInvokeWrappers;

internal interface ISHCoreDllService
{
/// <summary>
/// Queries the dots per inch (dpi) of a display.
/// </summary>
/// <param name="hmonitor">Handle of the monitor being queried.</param>
/// <param name="dpiType">The type of DPI being queried.</param>
/// <param name="dpiX">
/// The value of the DPI along the X axis. This value always refers to the horizontal edge,
/// even when the screen is rotated.
/// </param>
/// <param name="dpiY">
/// The value of the DPI along the Y axis. This value always refers to the vertical edge,
/// even when the screen is rotated.
/// </param>
/// <returns>True if operation succeeds, otherwise - false.</returns>
/// <inheritdoc cref="PInvoke.GetDpiForMonitor(HMONITOR, MONITOR_DPI_TYPE, out uint, out uint)"/>
bool GetDpiForMonitor(nint hmonitor, MONITOR_DPI_TYPE dpiType, out uint dpiX, out uint dpiY)
{
var result = PInvoke.GetDpiForMonitor((HMONITOR)hmonitor, dpiType, out dpiX, out dpiY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,201 +10,56 @@
namespace Tum4ik.JustClipboardManager.Services.PInvokeWrappers;
internal interface IUser32DllService
{
/// <summary>
/// Retrieves the position of the mouse cursor, in screen coordinates.
/// </summary>
/// <param name="lpPoint">
/// A pointer to a <see cref="Point"/> structure that receives the screen coordinates of the cursor.
/// </param>
/// <returns>Returns true if successful or false otherwise.</returns>
/// <inheritdoc cref="PInvoke.GetCursorPos(out Point)"/>
bool GetCursorPos(out Point lpPoint) => PInvoke.GetCursorPos(out lpPoint);

/// <summary>
/// Changes the size, position, and Z order of a child, pop-up, or top-level window. These windows are ordered
/// according to their appearance on the screen. The topmost window receives the highest rank and is the first
/// window in the Z order.
/// </summary>
/// <param name="hWnd">A handle to the window.</param>
/// <param name="hWndInsertAfter">
/// A handle to the window to precede the positioned window in the Z order. This parameter must be a window handle
/// or one of the following values.
/// </param>
/// <param name="X">The new position of the left side of the window, in client coordinates.</param>
/// <param name="Y">The new position of the top of the window, in client coordinates.</param>
/// <param name="cx">The new width of the window, in pixels.</param>
/// <param name="cy">The new height of the window, in pixels.</param>
/// <param name="uFlags">The window sizing and positioning flags.</param>
/// <returns>
/// If the function succeeds, the return value is true.
/// If the function fails, the return value is false.
/// </returns>
/// <inheritdoc cref="PInvoke.SetWindowPos(HWND, HWND, int, int, int, int, SET_WINDOW_POS_FLAGS)"/>
bool SetWindowPos(nint hWnd, nint hWndInsertAfter, int X, int Y, int cx, int cy, SET_WINDOW_POS_FLAGS uFlags)
=> PInvoke.SetWindowPos((HWND) hWnd, (HWND) hWndInsertAfter, X, Y, cx, cy, uFlags);

/// <summary>
/// Sets the specified window's show state.
/// </summary>
/// <param name="hWnd">A handle to the window.</param>
/// <param name="nCmdShow">Controls how the window is to be shown.</param>
/// <returns>
/// If the window was previously visible, the return value is nonzero.
/// If the window was previously hidden, the return value is zero.
/// </returns>
/// <inheritdoc cref="PInvoke.ShowWindow(HWND, SHOW_WINDOW_CMD)"/>
bool ShowWindow(nint hWnd, SHOW_WINDOW_CMD nCmdShow) => PInvoke.ShowWindow((HWND) hWnd, nCmdShow);

/// <summary>
/// Retrieves a handle to the foreground window (the window with which the user is currently working). The system
/// assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
/// </summary>
/// <returns>
/// C++ ( Type: Type: HWND )<br /> The return value is a handle to the foreground window. The foreground window
/// can be NULL in certain circumstances, such as when a window is losing activation.
/// </returns>
/// <inheritdoc cref="PInvoke.GetForegroundWindow"/>
nint GetForegroundWindow() => PInvoke.GetForegroundWindow();

/// <summary>
/// Retrieves a handle to the display monitor that contains a specified point.
/// </summary>
/// <param name="pt">Specifies the point of interest in virtual-screen coordinates.</param>
/// <param name="dwFlags">
/// Determines the function's return value if the point is not contained within any display monitor.
/// This parameter can be one of the values.
/// </param>
/// <returns>
/// If the point is contained by a display monitor, the return value is a handle to that display monitor.
/// If the point is not contained by a display monitor,
/// the return value depends on the value of <see cref="dwFlags"/>.
/// </returns>
/// <inheritdoc cref="PInvoke.MonitorFromPoint(Point, MONITOR_FROM_FLAGS)"/>
nint MonitorFromPoint(Point pt, MONITOR_FROM_FLAGS dwFlags) => PInvoke.MonitorFromPoint(pt, dwFlags);

/// <summary>
/// Retrieves a handle to the display monitor that has the largest area of intersection with the bounding rectangle
/// of a specified window.
/// </summary>
/// <param name="hwnd">A handle to the window of interest.</param>
/// <param name="dwFlags">
/// Determines the function's return value if the window does not intersect any display monitor.
/// </param>
/// <returns>
/// If the window intersects one or more display monitor rectangles, the return value is an HMONITOR handle to
/// the display monitor that has the largest area of intersection with the window.
/// If the window does not intersect a display monitor, the return value depends on the value of dwFlags.
/// </returns>
/// <remarks>
/// If the window is currently minimized, MonitorFromWindow uses the rectangle of the window before it was minimized.
/// </remarks>
/// <inheritdoc cref="PInvoke.MonitorFromWindow(HWND, MONITOR_FROM_FLAGS)"/>
nint MonitorFromWindow(nint hwnd, MONITOR_FROM_FLAGS dwFlags) => PInvoke.MonitorFromWindow((HWND) hwnd, dwFlags);

/// <summary>
/// Retrieves information about a display monitor.
/// </summary>
/// <param name="hMonitor">A handle to the display monitor of interest.</param>
/// <param name="monitorInfo">Information about the specified display monitor.</param>
/// <returns>
/// If the function succeeds, the return value is true.
/// If the function fails, the return value is false.
/// </returns>
/// <inheritdoc cref="PInvoke.GetMonitorInfo(HMONITOR, ref MONITORINFO)"/>
bool GetMonitorInfo(nint hMonitor, out MONITORINFO monitorInfo)
{
monitorInfo = new MONITORINFO();
monitorInfo.cbSize = (uint) Marshal.SizeOf(monitorInfo);
return PInvoke.GetMonitorInfo((HMONITOR) hMonitor, ref monitorInfo);
}

/// <summary>
/// Defines a system-wide hot key.
/// </summary>
/// <param name="hWnd">
/// A handle to the window that will receive WM_HOTKEY messages generated by the hot key.
/// If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread
/// and must be processed in the message loop.
/// </param>
/// <param name="id">
/// The identifier of the hot key. If the hWnd parameter is NULL,
/// then the hot key is associated with the current thread rather than with a particular window.
/// </param>
/// <param name="modifiers">The keys that must be pressed in combination with the <see cref="key"/>.</param>
/// <param name="key">The key code of the hot key.</param>
/// <returns>
/// If the function succeeds, the return value is true.
/// If the function fails, the return value is false.
/// </returns>
/// <inheritdoc cref="PInvoke.RegisterHotKey(HWND, int, HOT_KEY_MODIFIERS, uint)"/>
bool RegisterHotKey(nint hWnd, int id, ModifierKeys modifiers, Key key)
{
var vk = (uint) KeyInterop.VirtualKeyFromKey(key);
return PInvoke.RegisterHotKey((HWND) hWnd, id, (HOT_KEY_MODIFIERS) modifiers, vk);
}

/// <summary>
/// Frees a hot key previously registered by the calling thread.
/// </summary>
/// <param name="hWnd">
/// A handle to the window associated with the hot key to be freed.
/// This parameter should be NULL if the hot key is not associated with a window.
/// </param>
/// <param name="id">The identifier of the hot key to be freed.</param>
/// <returns>
/// If the function succeeds, the return value is true.
/// If the function fails, the return value is false.
/// </returns>
/// <inheritdoc cref="PInvoke.UnregisterHotKey(HWND, int)"/>
bool UnregisterHotKey(nint hWnd, int id) => PInvoke.UnregisterHotKey((HWND) hWnd, id);

/// <summary>
/// Places the given window in the system-maintained clipboard format listener list.
/// </summary>
/// <param name="hwnd">A handle to the window to be placed in the clipboard format listener list.</param>
/// <returns>Returns TRUE if successful, FALSE otherwise</returns>
/// <inheritdoc cref="PInvoke.AddClipboardFormatListener(HWND)"/>
bool AddClipboardFormatListener(nint hwnd) => PInvoke.AddClipboardFormatListener((HWND) hwnd);

/// <summary>
/// Removes the given window from the system-maintained clipboard format listener list.
/// </summary>
/// <param name="hwnd">A handle to the window to remove from the clipboard format listener list.</param>
/// <returns>Returns TRUE if successful, FALSE otherwise.</returns>
/// <inheritdoc cref="PInvoke.RemoveClipboardFormatListener(HWND)"/>
bool RemoveClipboardFormatListener(nint hwnd) => PInvoke.RemoveClipboardFormatListener((HWND) hwnd);

/// <summary>
/// Synthesizes keystrokes, mouse motions, and button clicks.
/// </summary>
/// <param name="pInputs">
/// An array of <see cref="INPUT"/> structures.
/// Each structure represents an event to be inserted into the keyboard or mouse input stream.
/// </param>
/// <param name="cbSize">
/// The size, in bytes, of an <see cref="INPUT"/> structure.
/// If cbSize is not the size of an <see cref="INPUT"/> structure, the function fails.
/// </param>
/// <returns>
/// The function returns the number of events that it successfully inserted into the keyboard or mouse input stream.
/// If the function returns zero, the input was already blocked by another thread.
/// </returns>
uint SendInput(INPUT[] pInputs, int cbSize) => PInvoke.SendInput(/*cInputs,*/ pInputs, cbSize);

/// <summary>
/// Brings the thread that created the specified window into the foreground and activates the window.
/// Keyboard input is directed to the window, and various visual cues are changed for the user.
/// The system assigns a slightly higher priority to the thread that created the foreground window
/// than it does to other threads.
/// </summary>
/// <param name="hWnd">A handle to the window that should be activated and brought to the foreground.</param>
/// <returns>
/// If the window was brought to the foreground, the return value is true.
/// If the window was not brought to the foreground, the return value is false.
/// </returns>
/// <inheritdoc cref="PInvoke.SendInput(Span{INPUT}, int)"/>
uint SendInput(INPUT[] pInputs, int cbSize) => PInvoke.SendInput(pInputs, cbSize);

Check warning on line 57 in Tum4ik.JustClipboardManager/Services/PInvokeWrappers/IUser32DllService.cs

View check run for this annotation

Codecov / codecov/patch

Tum4ik.JustClipboardManager/Services/PInvokeWrappers/IUser32DllService.cs#L57

Added line #L57 was not covered by tests

/// <inheritdoc cref="PInvoke.SetForegroundWindow(HWND)"/>
bool SetForegroundWindow(nint hWnd) => PInvoke.SetForegroundWindow((HWND) hWnd);

/// <summary>
/// Sets the keyboard focus to the specified window.
/// The window must be attached to the calling thread's message queue.
/// </summary>
/// <param name="hWnd">
/// A handle to the window that will receive the keyboard input. If this parameter is NULL, keystrokes are ignored.
/// </param>
/// <returns>
/// If the function succeeds, the return value is the handle to the window that previously had the keyboard focus.
/// If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue,
/// the return value is NULL.
/// </returns>
/// <inheritdoc cref="PInvoke.SetFocus(HWND)"/>
nint SetFocus(nint hWnd) => PInvoke.SetFocus((HWND) hWnd);
}

Expand Down
Loading
Loading