-
Notifications
You must be signed in to change notification settings - Fork 180
Scale cursor width by monitor specific zoom #2471
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
Scale cursor width by monitor specific zoom #2471
Conversation
e13d50f
to
38cac4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change currently introduces a regression:
I tested the change and printed out the old and new values for comparison. Turns out that the new method call always writes 0
to the passed buffer and, in particular, the method call always returns false
, such that the size is not taken into account.
One example consequence is that if I set a high OS cursor size (like 10), the cursor is still 1 pixel wide. For example, in a console window it used to look like this (with OS cursor size 10):
And now it looks like this:
Note that the documentation of the used method states that it cannot be called with SPI_GETCARETWIDTH
as done here but will always return 0
in that case: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfofordpi#remarks
38cac4f
to
ac7d9d5
Compare
@HeikoKlare Turns out SystemParametersInfo doesn't work with SPI_GETCARETWIDTH : https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfofordpi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal should be to make sure this doesn't cause any regression.
If I understand correctly, there was actually a bug that this PR now resolves: before, the cursor width was not scaled according to the monitor. So, e.g., a Windows setting of cursor size 10 would have resulted in pixel-width 10 for the cursor on both a 100% and 150% monitor whereas now on the 150% monitor the width will be 15 pixels.
So would be good to have that properly documented in the commit and PR messages.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
Outdated
Show resolved
Hide resolved
3f54b85
to
3e7a9fb
Compare
3e7a9fb
to
83de15b
Compare
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
Outdated
Show resolved
Hide resolved
83de15b
to
bb94992
Compare
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) { | ||
return new Rectangle (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels()); | ||
int widthInPixels = getSystemCaretWidthInPixelsForCurrentMonitor(); | ||
if (widthInPixels != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this now a change in behavior? It also uses getWidthInPixels()
in case the width value delivered by SystemParameterInfo
is zero and not only if the return value of that method is zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use -1 then? Since -1 cannot be a width. I thoughtof using null first but then we need to have type Integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used OptionalInt instead.
bb94992
to
fc727a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks and works good. Thank you!
This commit adapts the scaling of Cursor width with respect to the monitor zoom since the OS call OS.SystemParametersInfo returns the caret width for the primary zoom at startup.
fc727a9
to
6d39102
Compare
This PR fixes a bug where the cursor width was not scaled according to monitor DPI settings. Previously, the cursor width was applied as a fixed pixel value retrieved from OS.SystemParametersInfo which returns the caret width for the primary zoom at startup, resulting in inconsistent appearance across monitors.
Fix
The cursor width now scales correctly with the monitor’s DPI setting, ensuring consistent visual size across different display scales.