mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 04:55:39 +02:00
#289, 1. add command option -dpi_sensitive_call=0, 2. reject sudden window dpi change
This commit is contained in:
parent
63cd6db0e9
commit
818b8c50bd
4 changed files with 37 additions and 3 deletions
|
@ -39,6 +39,7 @@ namespace PersistentWindows.Common.Models
|
|||
public RECT ScreenPosition { get; set; }
|
||||
public WindowPlacement WindowPlacement { get; set; }
|
||||
public bool NeedUpdateWindowPlacement { get; set; } //non-persistent data used for tmp argument passing only
|
||||
public uint Dpi { get; set; }
|
||||
|
||||
// window z-order
|
||||
public bool IsTopMost { get; set; }
|
||||
|
|
|
@ -2008,7 +2008,7 @@ namespace PersistentWindows.Common
|
|||
{
|
||||
if (debugWindows.Contains(hWnd))
|
||||
{
|
||||
string log = string.Format("Captured {0,-8} at ({1}, {2}) of size {3} x {4} {5} fullscreen:{6} minimized:{7}",
|
||||
string log = string.Format("Captured {0,-8} at ({1}, {2}) of size {3} x {4} {5} fullscreen:{6} minimized:{7}, dpi:{8}",
|
||||
curDisplayMetrics,
|
||||
curDisplayMetrics.ScreenPosition.Left,
|
||||
curDisplayMetrics.ScreenPosition.Top,
|
||||
|
@ -2016,7 +2016,8 @@ namespace PersistentWindows.Common
|
|||
curDisplayMetrics.ScreenPosition.Height,
|
||||
curDisplayMetrics.Title,
|
||||
curDisplayMetrics.IsFullScreen,
|
||||
curDisplayMetrics.IsMinimized
|
||||
curDisplayMetrics.IsMinimized,
|
||||
curDisplayMetrics.Dpi
|
||||
);
|
||||
Log.Event(log);
|
||||
|
||||
|
@ -2423,6 +2424,8 @@ namespace PersistentWindows.Common
|
|||
RECT screenPosition = new RECT();
|
||||
User32.GetWindowRect(hwnd, ref screenPosition);
|
||||
|
||||
uint dpi = User32.GetDpiForWindow(hwnd);
|
||||
|
||||
bool isMinimized = IsMinimized(hwnd);
|
||||
|
||||
IntPtr realHwnd = hwnd;
|
||||
|
@ -2460,6 +2463,7 @@ namespace PersistentWindows.Common
|
|||
WindowPlacement = windowPlacement,
|
||||
NeedUpdateWindowPlacement = false,
|
||||
ScreenPosition = screenPosition,
|
||||
Dpi = dpi,
|
||||
|
||||
IsTopMost = IsWindowTopMost(hwnd),
|
||||
NeedClearTopMost = false,
|
||||
|
@ -2592,13 +2596,24 @@ namespace PersistentWindows.Common
|
|||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
if (!prevDisplayMetrics.EqualPlacement(curDisplayMetrics))
|
||||
{
|
||||
curDisplayMetrics.NeedUpdateWindowPlacement = true;
|
||||
moved = true;
|
||||
}
|
||||
else if (!prevDisplayMetrics.ScreenPosition.Equals(curDisplayMetrics.ScreenPosition))
|
||||
else*/ if (!prevDisplayMetrics.ScreenPosition.Equals(curDisplayMetrics.ScreenPosition))
|
||||
{
|
||||
if (prevDisplayMetrics.Dpi > 0 && curDisplayMetrics.Dpi != prevDisplayMetrics.Dpi)
|
||||
{
|
||||
if (curDisplayMetrics.ScreenPosition.Width * curDisplayMetrics.Dpi == prevDisplayMetrics.ScreenPosition.Width * prevDisplayMetrics.Dpi)
|
||||
if (curDisplayMetrics.ScreenPosition.Height * curDisplayMetrics.Dpi == prevDisplayMetrics.ScreenPosition.Height * prevDisplayMetrics.Dpi)
|
||||
{
|
||||
// workaround #289
|
||||
Log.Error($"ignore sudden scale ratio change for {GetWindowTitle(hwnd)}, prev DPI {prevDisplayMetrics.Dpi}, prev location {prevDisplayMetrics.ScreenPosition}, cur DPI {curDisplayMetrics.Dpi}, cur location {curDisplayMetrics.ScreenPosition}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
moved = true;
|
||||
}
|
||||
else if (!curDisplayMetrics.IsMinimized && prevDisplayMetrics.IsMinimized)
|
||||
|
|
|
@ -493,6 +493,10 @@ namespace PersistentWindows.Common.WinApiBridge
|
|||
[DllImport("user32.dll")]
|
||||
public static extern bool IsWindowOnCurrentVirtualDesktop(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern uint GetDpiForWindow(IntPtr hWnd);
|
||||
|
||||
public static bool DpiSenstiveCall = true;
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetProcessDpiAwarenessContext(int dpi_awareness_cxt);
|
||||
[DllImport("user32.dll")]
|
||||
|
@ -508,11 +512,22 @@ namespace PersistentWindows.Common.WinApiBridge
|
|||
if (os_version.Version.Major < 10)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
// windows 11 workaround for #289
|
||||
if (os_version.Version.Build > 22000)
|
||||
if (dpi_awareness_cxt == DPI_AWARENESS_CONTEXT_UNAWARE)
|
||||
return 0;
|
||||
|
||||
if (dpi_awareness_cxt == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
|
||||
return 0;
|
||||
if (dpi_awareness_cxt == DPI_AWARENESS_CONTEXT_UNAWARE)
|
||||
//dpi_awareness_cxt = DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
|
||||
//dpi_awareness_cxt = DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED;
|
||||
dpi_awareness_cxt = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE;
|
||||
*/
|
||||
if (!DpiSenstiveCall)
|
||||
return 0;
|
||||
|
||||
//valid API since win10 1607
|
||||
return SetThreadDpiAwarenessContext(dpi_awareness_cxt);
|
||||
}
|
||||
|
|
|
@ -147,6 +147,9 @@ namespace PersistentWindows.SystrayShell
|
|||
case "-delay_auto_capture":
|
||||
delay_auto_capture = 1;
|
||||
break;
|
||||
case "-dpi_sensitive_call=0":
|
||||
User32.DpiSenstiveCall = false;
|
||||
break;
|
||||
case "-redirect_appdata":
|
||||
redirect_appdata = true;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue