RGFW icon indicating copy to clipboard operation
RGFW copied to clipboard

Monitor scale values seem to be wrong.

Open jarroddavis68 opened this issue 1 year ago • 10 comments

When I created a window that is set to scale to monitor DPI, the 800x600 window was way too big. My 4k monitor is scaled at 150%, with a DPI of 144, thus the scale factor would be 1.5, but it returns 2.76 thus the window scale is larger than it should be.

In my own code I get 144 dpi, 1.5 scale (dividing 144/96.0). I resize by this value and the window is sized appropriately for the DPI.

I'm on win64, using opengl.

jarroddavis68 avatar Sep 30 '24 06:09 jarroddavis68

Thank you for telling me. I'll be looking into this asap.

ColleagueRiley avatar Oct 01 '24 00:10 ColleagueRiley

Thank you for telling me. I'll be looking into this asap.

np.

Also, a few of the routines at the top do not have RGFWDEF on it so they won't get exported. I use this with Delphi so every update I have to remember to go in and add them.

jarroddavis68 avatar Oct 01 '24 00:10 jarroddavis68

Also, a few of the routines at the top do not have RGFWDEF on it so they won't get exported. I use this with Delphi so every update I have to remember to go in and add them.

Thanks, the RGFWDEF issue should be fixed now! Let me know if you find any more issues.

ColleagueRiley avatar Oct 01 '24 01:10 ColleagueRiley

Thanks, the RGFWDEF issue should be fixed now! Let me know if you find any more issues.

Coolness. Thanks.

jarroddavis68 avatar Oct 01 '24 01:10 jarroddavis68

I'm not sure where the 2.76 scale is coming from, based on my tests the scale was always 1 because DPIAware was not enabled. It's now enabled via SetProcessDPIAware. Let me know if the issue still occurs.

ColleagueRiley avatar Oct 06 '24 01:10 ColleagueRiley

Sadly, I'm getting the same value. The window is scaled by 2.76 rather than 1.5.

https://github.com/user-attachments/assets/e345405b-042a-4378-8835-1a5d9cfd0d56

jarroddavis68 avatar Oct 07 '24 06:10 jarroddavis68

if you change GetDpiForMonitor(src, MDT_ANGULAR_DPI, &x, &y) to GetDpiForMonitor(src, MDT_EFFECTIVE_DPI, &x, &y) then I get correct scaling values on my device.

However the automatic scale_to_depi does not seem to no work, nor directly calling RGFW_window_scaleToMonitor().

But if I do:

  LArea.w := Round(LMonitor.scaleX * LWindow.r.w);
  LArea.h := Round(LMonitor.scaleY * LWindow.r.h);
  RGFW_window_resize(LWindow, LArea);

then it works. But this is what RGFW_window_scaleToMonitor is doing. So not sure what's going on else where.

Reference: https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-monitor_dpi_type

jarroddavis68 avatar Oct 07 '24 08:10 jarroddavis68

I was getting the proper values on my side. Although based on the documentation, that makes sense.

I'm not sure why the scale function isn't working, I'll look into it later today.

ColleagueRiley avatar Oct 07 '24 11:10 ColleagueRiley

RGFW_window_scaleToMonitor doesn't work because the code looks something like this

((u32)scale) * width, (u32)scale would == 1

I'm changing it to look like this

(u32)(scale * (float)width)

Rather than rounding the value.

ColleagueRiley avatar Oct 07 '24 19:10 ColleagueRiley

Ok, yea, that worked. The only remaining issues is the centering is off, I think centering is being calc first, then the window is resized. Centering should be calc after the resize to take into account the scaled window size.

jarroddavis68 avatar Oct 07 '24 19:10 jarroddavis68

Hmm, just so you know, RGFW_CENTER|RGFW_SCALE_TO_MONITO will not center the window and explained above. I just pulled the latest and the dpi is correct, but centering it still wrong. I have not looked at the code, and just going off what I think that is happening, the window is scaled after its centered and not taking the scale size into consideration. I can work around it, but just letting you know.

jarroddavis68 avatar Oct 08 '24 00:10 jarroddavis68

@jarroddavis68 yea I moved it and it should be fixed now. I can double check the code though.

ColleagueRiley avatar Oct 08 '24 00:10 ColleagueRiley

Ahh yes, working now. Many thanks!

jarroddavis68 avatar Oct 08 '24 01:10 jarroddavis68

Thank you for bringing up the issue. I've been planning on revisiting the monitor code for a while.

ColleagueRiley avatar Oct 08 '24 01:10 ColleagueRiley

Oh forgot to mention that this is how i'm using RGFW in Delphi. Using the new clang based toolchain in C++ Builder I can create and object .o and link then directly into Delphi. I recently added RGFW to the growing list. https://github.com/tinyBigGAMES/CPas

jarroddavis68 avatar Oct 08 '24 07:10 jarroddavis68