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

Adapt GetSystemMetrics call to be DPI dependent #1209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShahzaibIbrahim
Copy link

@ShahzaibIbrahim ShahzaibIbrahim commented May 3, 2024

NOTE: these changes affect only Windows

What it does

Writing GetSystemMetrics method in Widget class so that the child controls can use it to get System Metrics to be DPI dependent. There are some visible affected areas (before and after zooming to 200 from 100) for which screenshots are attached.

The OS.getSystemMetrics call had a slight issue in some of the controls i.e. Combo, List and Table. The values returned for scroll i.e. OS.SM_CXVSCROLL were independent of DPI. So moving the shell from smaller zoom level to higher zoom level we can see the visible difference in the scroll bar which is not visible in the latter part.

Combo
List
Table

HOW TO TEST (Windows only!)

  • Run the ControlExample
  • Add these lines in your vm arguments
    -Dswt.autoScale=quarter
    -Dswt.autoScale.updateOnRuntime=true
  • Open the SWT Controls view
  • Switch to the tab "Combo"/"List"/"Table"
  • Change the size to 50x50 from Size section
  • Move the window from 100 to 200 zoom level monitor
  • See if the scroll bar is still visible

EXPECTED BEHAVIOUR

None of the widgets should look out of order when changing the zoom level.

Contributes to #62 and #127:

Copy link
Contributor

github-actions bot commented May 3, 2024

Test Results

   418 files  ±0     418 suites  ±0   8m 41s ⏱️ -43s
 4 121 tests ±0   4 113 ✅ ±0   8 💤 ±0  0 ❌ ±0 
16 313 runs  ±0  16 221 ✅ ±0  92 💤 ±0  0 ❌ ±0 

Results for commit 20e1399. ± Comparison against base commit 08473c2.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this PR changes (all?) calls to OS.GetSystemMetrics for a call to a new intermediate method in Widget: why not simply change OS.GetSystemMetrics and put the new logic in there?

The request for changes is only because of the change in Table.

@fedejeanne
Copy link
Contributor

@ShahzaibIbrahim please also improve the commit message:

  • Remove the links from the first line (they are in the body anyway)
  • Add the text "Fixes" or "Contributes to" appropriately for the linked issues

@ShahzaibIbrahim
Copy link
Author

I see that this PR changes (all?) calls to OS.GetSystemMetrics for a call to a new intermediate method in Widget: why not simply change OS.GetSystemMetrics and put the new logic in there?

Not all calls, just the child of all widgets, also these are OS related calls, we can't really change the implementation of it. That's why created one intermediate call for all of them.

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One call is still wrong (look at the parameter)

@fedejeanne fedejeanne changed the title Contributes to #62 and #127: Adapt GetSystemMetrics call to be DPI dependent Adapt GetSystemMetrics call to be DPI dependent May 6, 2024
Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing my findings. I took a deeper look and found some other stuff I would like your input on:

  1. I noticed there are still some calls inside the widgets and the win32 package that are not using the new method, namely these 3 on top
    image
    The first one (in the OS class) is probably OK because it asks for the value of SM_IMMENABLED which I assume is the same regardless of the current DPI settings (please confirm/rebut)
  2. What would happen if one removes the if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) in the new method and always calls OS.GetSystemMetricsForDpi(...)? Would the application crash in older Windows versions?

NOTE: The request for changes is only because point nr 1.

@ShahzaibIbrahim
Copy link
Author

  1. What would happen if one removes the if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) in the new method and always calls OS.GetSystemMetricsForDpi(...)? Would the application crash in older Windows versions?

I am not sure if the applications crashes in older version, and also can't test it but looking at the usage for dpi dependent OS calls, this check is always used which makes me think that it may have some affects on older windows versions.

@fedejeanne fedejeanne dismissed their stale review May 15, 2024 13:07

Requested changes were addressed

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing my change requests, @ShahzaibIbrahim . Would it be possible to rebase in origin/master so I can checkout your PR and take a deeper look at it?

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look better now, I see that all the widgets go through the new method now ✔️

image

Since there has been some changes since the beginning of this PR, I would like to validate the behavior of the code myself. Some brief "How to test" and also "Expected (observable?) behavior" sections in the description of this PR would help.

Writing GetSystemMetrics method in Widget class so that the child
controls can use it to get System Metrics to be DPI dependent

Contributes to:
eclipse-platform#62 &
eclipse-platform#127
@fedejeanne
Copy link
Contributor

@ShahzaibIbrahim thank you for adding a How to test. I tested in Windows 10 and I see no difference before and after this PR.

Before (Table, size 100x100)

Zoom = 100
image

Zoom = 200
image

After

Zoom = 100
image

Zoom = 200
image

Maybe I'm testing it wrong?

@ShahzaibIbrahim
Copy link
Author

Maybe I'm testing it wrong?

No you have tested it correctly. I just forgot to mention that you need to add these vm arguments while running the example.

-Dswt.autoScale=quarter
-Dswt.autoScale.updateOnRuntime=true

@fedejeanne
Copy link
Contributor

I tested it again and I still see no difference between before and after this PR. Moreover, the status before this PR looks OK (I see both scroll bars when moving to the monitor with zoom = 200. Can you please confirm?

Before (Table size 100x100)

Zoom = 100
image

Zoom = 200
According to the initial description of the bug, this image should show a missing horizontal scrollbar, right?

image

After (Table size 100x100)

Zoom = 100
image

Zoom = 200
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants