Skip to content

Commit

Permalink
Improve input forwarding, also fix sidebar hidden on resize
Browse files Browse the repository at this point in the history
Sidebar now keeps showing if input forwarding is enabled
  • Loading branch information
R-N committed Mar 29, 2022
1 parent 85b2656 commit 03c9150
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 111 deletions.
7 changes: 7 additions & 0 deletions PiP-Tool.Native/NativeEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ public enum ShowWindowCommands
ForceMinimize = 11
}

public enum WA: int
{
INACTIVE = 0,
ACTIVE = 1,
CLICKACTIVE = 2
}

/// <summary>
/// Windows Messages
/// Defined in winuser.h from Windows SDK v6.1
Expand Down
86 changes: 86 additions & 0 deletions PiP-Tool.Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public static class NativeMethods
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

// When you don't want the ProcessId, use this overload and pass IntPtr.Zero for the second parameter
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();

Expand All @@ -82,6 +86,9 @@ public static class NativeMethods
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetFocus(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern IntPtr GetFocus();

[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);

Expand Down Expand Up @@ -178,6 +185,63 @@ public static int LParamToY(ulong lparam)
return (int)((lparam >> 32) & 0xffffffff);
}

[DllImport("user32.dll")]
public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, uint wParam, long lParam);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, uint wParam, int lParam);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetKeyboardState(byte[] lpKeyState);

[DllImport("user32.dll")]
public static extern bool SetKeyboardState(byte[] lpKeyState);

[DllImport("user32.dll")]
public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, UIntPtr dwExtraInfo);

[DllImport("user32.dll")]
public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, int dwExtraInfo);

[DllImport("user32.dll")]
public static extern IntPtr SetCursor(IntPtr handle);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetCursorPos(int x, int y);

[DllImport("user32.dll")]
public static extern IntPtr GetCursor();

[DllImport("user32.dll")]
public static extern IntPtr GetCapture();

[DllImport("user32.dll")]
public static extern bool ReleaseCapture();

[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern bool BlockInput(bool fBlockIt);


#endregion

Expand Down Expand Up @@ -223,5 +287,27 @@ public static int LParamToY(ulong lparam)
public static extern void GetDpiForMonitor(IntPtr hmonitor, MONITOR_DPI_TYPE dpiType, out int dpiX, out int dpiY);

#endregion

#region kernel32.dll

[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentThread();

[DllImport("kernel32.dll")]
public static extern uint GetCurrentThreadId();

#endregion

/*
#region coredll.dll
[DllImport("coredll.dll")]
public static extern IntPtr GetCapture();
[DllImport("coredll.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);
#endregion
*/
}
}
Loading

0 comments on commit 03c9150

Please sign in to comment.