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

Windows: create a window which fits selected resolution better #306

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

Conversation

danie1kr
Copy link

try to get a window which is closer to the selected resolution. Still 2 pixels off horizontally, but better than what windows creates.

try to get a window which is closer to the selected resolution. Still 2 pixels off horizontally, but better than what windows creates.
@danie1kr danie1kr changed the title Update win32drv.c Windows: create a window which fits selected resolution better Feb 12, 2024
@kisvegabor
Copy link
Member

As it might affect existing projects I wouldn't touch this part.
However I would be happy to merge lvgl/lvgl#5639 if it's approved by @MouriNaruto.

@danie1kr
Copy link
Author

Sure, I understand. Actually, I moved from lv_drivers to pure lvgl when I fixed this.

@MouriNaruto
Copy link
Contributor

I don't think you have read the implementation carefully. The current 8.x implementation will apply the real size in WM_CREATE message.

RECT calculated_window_size;
calculated_window_size.left = 0;
calculated_window_size.right = MulDiv(
context->display_hor_res * WIN32DRV_MONITOR_ZOOM,
context->display_dpi,
USER_DEFAULT_SCREEN_DPI);
calculated_window_size.top = 0;
calculated_window_size.bottom = MulDiv(
context->display_ver_res * WIN32DRV_MONITOR_ZOOM,
context->display_dpi,
USER_DEFAULT_SCREEN_DPI);
AdjustWindowRectEx(
&calculated_window_size,
WINDOW_STYLE,
FALSE,
WINDOW_EX_STYLE);
OffsetRect(
&calculated_window_size,
-calculated_window_size.left,
-calculated_window_size.top);
SetWindowPos(
hWnd,
NULL,
0,
0,
calculated_window_size.right,
calculated_window_size.bottom,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
lv_win32_register_touch_window(hWnd, 0);
lv_win32_enable_child_window_dpi_message(hWnd);
break;

I don't use AdjustWindowRect when creating window because it's not reliable.

image
First, AdjustWindowRect document said that to specify an extended window style, use the AdjustWindowRectEx function.

image
Second, AdjustWindowRectEx document said that this API is not DPI aware, and should not be used if the calling thread is per-monitor DPI aware. For the DPI-aware version of this API, see AdjustWindowsRectExForDPI.

Also, AdjustWindowsRectExForDPI is not reliable for enabling the DWM composition which is forced beginning with Windows 8. Especially the Windows 10 frameless-style window which is the DWM hacking.

So, this is why I chose only to pass the raw window size before. Because we need to let WM_CREATE message know the raw value for postprocessing. But for 8.x implementation is simplified because 8.x's driver only provides the simulator mode.

Kenji Mouri

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.

3 participants