Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Apr 3, 2024
1 parent db0e021 commit cd06fba
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions LightBulb.PlatformInterop/GlobalHotKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public partial class GlobalHotKey
public static GlobalHotKey? TryRegister(int virtualKey, int modifiers, Action callback)
{
var handle = Interlocked.Increment(ref _lastHotKeyHandle);

if (
!NativeMethods.RegisterHotKey(
WndProcSponge.Default.Handle,
Expand Down
22 changes: 11 additions & 11 deletions LightBulb.PlatformInterop/Internal/NativeMethods.User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ internal static partial class NativeMethods
private const string User32 = "user32.dll";

[DllImport(User32, SetLastError = true)]
public static extern bool GetMonitorInfo(nint hMonitor, ref MonitorInfoEx lpmi);

public static extern bool EnumDisplayMonitors(
nint hdc,
nint lprcClip,
EnumMonitorsProc lpfnEnum,
nint dwData
);

[DllImport(User32, SetLastError = true)]
public static extern ushort RegisterClassEx(ref WndClassEx lpwcx);
public static extern nint MonitorFromWindow(nint hWnd, uint dwFlags);

[DllImport(User32, SetLastError = true)]
public static extern bool UnregisterClass(string lpClassName, IntPtr hInstance);
public static extern bool GetMonitorInfo(nint hMonitor, ref MonitorInfoEx lpmi);

[DllImport(User32, SetLastError = true)]
public static extern nint MonitorFromWindow(nint hWnd, uint dwFlags);
public static extern ushort RegisterClassEx(ref WndClassEx lpwcx);

[DllImport(User32, SetLastError = true)]
public static extern bool EnumDisplayMonitors(
nint hdc,
nint lprcClip,
EnumMonitorsProc lpfnEnum,
nint dwData
);
public static extern bool UnregisterClass(string lpClassName, IntPtr hInstance);

[DllImport(User32, SetLastError = true)]
public static extern nint CreateWindowEx(
Expand Down
8 changes: 6 additions & 2 deletions LightBulb.PlatformInterop/Internal/WndClassEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ namespace LightBulb.PlatformInterop.Internal;
[StructLayout(LayoutKind.Sequential)]
internal readonly record struct WndClassEx
{
public WndClassEx() => Size = (uint)Marshal.SizeOf(this);
public WndClassEx()
{
Size = (uint)Marshal.SizeOf(this);
Instance = Marshal.GetHINSTANCE(typeof(WndClassEx).Module);
}

public uint Size { get; }
public uint Style { get; init; }
public required WndProc WndProc { get; init; }
public int ClassExtra { get; init; }
public int WindowExtra { get; init; }
public nint Instance { get; init; }
public nint Instance { get; }
public nint Icon { get; init; }
public nint Cursor { get; init; }
public nint Background { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion LightBulb.PlatformInterop/Internal/WndProcMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace LightBulb.PlatformInterop.Internal;

internal readonly record struct WndProcMessage(uint Id, nint WParam, nint LParam)
{
public T DeserializeLParam<T>() =>
public T GetLParam<T>() =>
(T?)Marshal.PtrToStructure(LParam, typeof(T))
?? throw new InvalidOperationException(
$"Failed to deserialize WndProc message's lParam to {typeof(T)}."
Expand Down
4 changes: 1 addition & 3 deletions LightBulb.PlatformInterop/Internal/WndProcSponge.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using LightBulb.PlatformInterop.Utils;

namespace LightBulb.PlatformInterop.Internal;
Expand Down Expand Up @@ -71,8 +70,7 @@ internal partial class WndProcSponge
var classInfo = new WndClassEx
{
ClassName = ClassName,
WndProc = wndProc,
Instance = Marshal.GetHINSTANCE(typeof(WndProcSponge).Module)
WndProc = wndProc
};

var classHandle = NativeMethods.RegisterClassEx(ref classInfo);
Expand Down
2 changes: 1 addition & 1 deletion LightBulb.PlatformInterop/PowerSettingNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class PowerSettingNotification(nint handle, Guid powerSettingId,
m =>
{
// Filter out other power events
if (m.DeserializeLParam<PowerBroadcastSetting>().PowerSettingId != powerSettingId)
if (m.GetLParam<PowerBroadcastSetting>().PowerSettingId != powerSettingId)
return;
callback();
Expand Down
2 changes: 1 addition & 1 deletion LightBulb.PlatformInterop/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public bool IsFullScreen()
if (TryGetRect() is not { } windowRect)
return false;

// Calculate absolute window client rect (not relative to the window)
// Calculate the absolute window client rect (not relative to the window)
var windowClientRect = TryGetClientRect() ?? Rect.Empty;

var absoluteWindowClientRect = new Rect(
Expand Down

0 comments on commit cd06fba

Please sign in to comment.