GDK-Win32: Enable HiDPI support for Windows

This enables HiDPI support for GTK+ on Windows, so that the
fonts and window look better on HiDPI displays.  Notes for the current
work:

-The DPI awareness enabling can be disabled if and only if an application
 manifest is not embedded in the app to enable DPI awareness AND a user
 compatibility setting is not set to limit DPI awareness for the app, via
 the envvar GDK_WIN32_DISABLE_HIDPI.  The app manifest/user setting for
 DPI awareness will always win against the envvar, and so the HiDPI items
 will be always setup in such scenarios, unless DPI awareness is disabled.

-Both automatic detection for the scaling factor and setting the scale
 factor using the GDK_SCALE envvar are supported, where the envvar takes
 precedence, which will therefore disable automatic scaling when
 resolution changes.

-I am unable to test the wintab items because I don't have such devices
 around.

https://bugzilla.gnome.org/show_bug.cgi?id=768081
This commit is contained in:
Chun-wei Fan
2016-06-27 13:16:43 +08:00
parent a64a0bc617
commit 4add92a431
13 changed files with 953 additions and 322 deletions

View File

@ -111,25 +111,27 @@ gdk_device_win32_query_state (GdkDevice *device,
GdkScreen *screen;
POINT point;
HWND hwnd, hwndc;
GdkWindowImplWin32 *impl;
screen = gdk_window_get_screen (window);
impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
hwnd = GDK_WINDOW_HWND (window);
GetCursorPos (&point);
if (root_x)
*root_x = point.x;
*root_x = point.x / impl->window_scale;
if (root_y)
*root_y = point.y;
*root_y = point.y / impl->window_scale;
ScreenToClient (hwnd, &point);
if (win_x)
*win_x = point.x;
*win_x = point.x / impl->window_scale;
if (win_y)
*win_y = point.y;
*win_y = point.y / impl->window_scale;
if (window == gdk_screen_get_root_window (screen))
{
@ -197,6 +199,7 @@ _gdk_device_win32_window_at_position (GdkDevice *device,
gboolean get_toplevel)
{
GdkWindow *window = NULL;
GdkWindowImplWin32 *impl = NULL;
POINT screen_pt, client_pt;
HWND hwnd, hwndc;
RECT rect;
@ -249,12 +252,15 @@ _gdk_device_win32_window_at_position (GdkDevice *device,
/* If we didn't hit any window at that point, return the desktop */
if (hwnd == NULL)
{
if (win_x)
*win_x = screen_pt.x + _gdk_offset_x;
if (win_y)
*win_y = screen_pt.y + _gdk_offset_y;
window = gdk_get_default_root_window ();
impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
return gdk_get_default_root_window ();
if (win_x)
*win_x = (screen_pt.x + _gdk_offset_x) / impl->window_scale;
if (win_y)
*win_y = (screen_pt.y + _gdk_offset_y) / impl->window_scale;
return window;
}
window = gdk_win32_handle_table_lookup (hwnd);
@ -262,10 +268,12 @@ _gdk_device_win32_window_at_position (GdkDevice *device,
if (window && (win_x || win_y))
{
impl = GDK_WINDOW_IMPL_WIN32 (window->impl);
if (win_x)
*win_x = client_pt.x;
*win_x = client_pt.x / impl->window_scale;
if (win_y)
*win_y = client_pt.y;
*win_y = client_pt.y / impl->window_scale;
}
return window;