From: Rémi Bernon rbernon@codeweavers.com
Avoiding any lossy conversion. --- dlls/winewayland.drv/wayland_pointer.c | 11 +++++++++-- dlls/winewayland.drv/window.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_pointer.c b/dlls/winewayland.drv/wayland_pointer.c index df76a4e9954..1d8acaeabd2 100644 --- a/dlls/winewayland.drv/wayland_pointer.c +++ b/dlls/winewayland.drv/wayland_pointer.c @@ -659,12 +659,19 @@ clear_cursor: } }
+static void reapply_cursor_clipping(void) +{ + RECT rect; + UINT context = NtUserSetThreadDpiAwarenessContext(NTUSER_DPI_PER_MONITOR_AWARE); + if (NtUserGetClipCursor(&rect)) NtUserClipCursor(&rect); + NtUserSetThreadDpiAwarenessContext(context); +} + static void wayland_set_cursor(HWND hwnd, HCURSOR hcursor, BOOL use_hcursor) { struct wayland_pointer *pointer = &process_wayland.pointer; struct wayland_surface *surface; double scale; - RECT clip; BOOL reapply_clip = FALSE;
if ((surface = wayland_surface_lock_hwnd(hwnd))) @@ -697,7 +704,7 @@ static void wayland_set_cursor(HWND hwnd, HCURSOR hcursor, BOOL use_hcursor)
/* Reapply cursor clip since cursor visibility affects pointer constraint * behavior. */ - if (reapply_clip && NtUserGetClipCursor(&clip)) NtUserClipCursor(&clip); + if (reapply_clip) reapply_cursor_clipping(); }
/********************************************************************** diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c index cd8ca76b679..73bee46cc35 100644 --- a/dlls/winewayland.drv/window.c +++ b/dlls/winewayland.drv/window.c @@ -199,12 +199,19 @@ static void wayland_win_data_get_config(struct wayland_win_data *data, conf->managed = data->managed; }
+static void reapply_cursor_clipping(void) +{ + RECT rect; + UINT context = NtUserSetThreadDpiAwarenessContext(NTUSER_DPI_PER_MONITOR_AWARE); + if (NtUserGetClipCursor(&rect )) NtUserClipCursor(&rect); + NtUserSetThreadDpiAwarenessContext(context); +} + static void wayland_win_data_update_wayland_surface(struct wayland_win_data *data) { struct wayland_surface *surface = data->wayland_surface; HWND parent = NtUserGetAncestor(data->hwnd, GA_PARENT); BOOL visible, xdg_visible; - RECT clip; WCHAR text[1024];
TRACE("hwnd=%p\n", data->hwnd); @@ -255,8 +262,7 @@ static void wayland_win_data_update_wayland_surface(struct wayland_win_data *dat
/* Size/position changes affect the effective pointer constraint, so update * it as needed. */ - if (data->hwnd == NtUserGetForegroundWindow() && NtUserGetClipCursor(&clip)) - NtUserClipCursor(&clip); + if (data->hwnd == NtUserGetForegroundWindow()) reapply_cursor_clipping();
out: TRACE("hwnd=%p surface=%p=>%p\n", data->hwnd, data->wayland_surface, surface);
From: Rémi Bernon rbernon@codeweavers.com
Avoiding any lossy conversion. --- dlls/winex11.drv/event.c | 4 ++-- dlls/winex11.drv/mouse.c | 11 +++++------ dlls/winex11.drv/x11drv.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c index 88863e62dd1..095820596de 100644 --- a/dlls/winex11.drv/event.c +++ b/dlls/winex11.drv/event.c @@ -772,7 +772,7 @@ static BOOL X11DRV_FocusIn( HWND hwnd, XEvent *xev )
if (event->detail == NotifyPointer) return FALSE; /* when focusing in the virtual desktop window, re-apply the cursor clipping rect */ - if (is_virtual_desktop() && hwnd == NtUserGetDesktopWindow()) retry_grab_clipping_window(); + if (is_virtual_desktop() && hwnd == NtUserGetDesktopWindow()) reapply_cursor_clipping(); if (hwnd == NtUserGetDesktopWindow()) return FALSE;
x11drv_thread_data()->keymapnotify_hwnd = hwnd; @@ -780,7 +780,7 @@ static BOOL X11DRV_FocusIn( HWND hwnd, XEvent *xev ) /* when keyboard grab is released, re-apply the cursor clipping rect */ was_grabbed = keyboard_grabbed; keyboard_grabbed = event->mode == NotifyGrab || event->mode == NotifyWhileGrabbed; - if (was_grabbed > keyboard_grabbed) retry_grab_clipping_window(); + if (was_grabbed > keyboard_grabbed) reapply_cursor_clipping(); /* ignore wm specific NotifyUngrab / NotifyGrab events w.r.t focus */ if (event->mode == NotifyGrab || event->mode == NotifyUngrab) return FALSE;
diff --git a/dlls/winex11.drv/mouse.c b/dlls/winex11.drv/mouse.c index 1196986424d..dce3c888170 100644 --- a/dlls/winex11.drv/mouse.c +++ b/dlls/winex11.drv/mouse.c @@ -458,15 +458,14 @@ void ungrab_clipping_window(void) }
/*********************************************************************** - * retry_grab_clipping_window - * - * Restore the current clip rectangle. + * reapply_cursor_clipping */ -void retry_grab_clipping_window(void) +void reapply_cursor_clipping(void) { RECT rect; - NtUserGetClipCursor( &rect ); - NtUserClipCursor( &rect ); + UINT context = NtUserSetThreadDpiAwarenessContext( NTUSER_DPI_PER_MONITOR_AWARE ); + if (NtUserGetClipCursor( &rect )) NtUserClipCursor( &rect ); + NtUserSetThreadDpiAwarenessContext( context ); }
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index a221198ffbc..be76dd2609e 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -674,7 +674,7 @@ extern UINT get_win_monitor_dpi( HWND hwnd ); extern BOOL is_current_process_focused(void); extern void X11DRV_SetFocus( HWND hwnd ); extern void set_window_cursor( Window window, HCURSOR handle ); -extern void retry_grab_clipping_window(void); +extern void reapply_cursor_clipping(void); extern void ungrab_clipping_window(void); extern void move_resize_window( HWND hwnd, int dir ); extern void X11DRV_InitKeyboard( Display *display );
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/sysparams.c | 45 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 006c8820b7b..56410cbf48c 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -2102,9 +2102,10 @@ UINT get_monitor_dpi( HMONITOR monitor ) return system_dpi; }
-static RECT get_monitor_rect( struct monitor *monitor, UINT dpi ) +static RECT get_monitor_rect( struct monitor *monitor, BOOL work, UINT dpi ) { - return map_dpi_rect( monitor->rc_monitor, get_monitor_dpi( monitor->handle ), dpi ); + RECT rect = work ? monitor->rc_work : monitor->rc_monitor; + return map_dpi_rect( rect, get_monitor_dpi( monitor->handle ), dpi ); }
/********************************************************************** @@ -2285,13 +2286,14 @@ RECT get_virtual_screen_rect( UINT dpi )
LIST_FOR_EACH_ENTRY( monitor, &monitors, struct monitor, entry ) { + RECT monitor_rect; if (!is_monitor_active( monitor ) || monitor->is_clone) continue; - union_rect( &rect, &rect, &monitor->rc_monitor ); + monitor_rect = get_monitor_rect( monitor, FALSE, dpi ); + union_rect( &rect, &rect, &monitor_rect ); }
unlock_display_devices();
- if (dpi) rect = map_dpi_rect( rect, system_dpi, dpi ); return rect; }
@@ -2308,7 +2310,7 @@ static BOOL is_window_rect_full_screen( const RECT *rect, UINT dpi )
if (!is_monitor_active( monitor ) || monitor->is_clone) continue;
- monrect = get_monitor_rect( monitor, dpi ); + monrect = get_monitor_rect( monitor, FALSE, dpi ); if (rect->left <= monrect.left && rect->right >= monrect.right && rect->top <= monrect.top && rect->bottom >= monrect.bottom) { @@ -2338,7 +2340,7 @@ RECT get_display_rect( const WCHAR *display ) struct monitor *monitor; UNICODE_STRING name; RECT rect = {0}; - UINT index; + UINT index, dpi = get_thread_dpi();
RtlInitUnicodeString( &name, display ); if (!(index = get_display_index( &name ))) return rect; @@ -2347,12 +2349,12 @@ RECT get_display_rect( const WCHAR *display ) LIST_FOR_EACH_ENTRY( monitor, &monitors, struct monitor, entry ) { if (!monitor->source || monitor->source->id + 1 != index) continue; - rect = monitor->rc_monitor; + rect = get_monitor_rect( monitor, FALSE, dpi ); break; }
unlock_display_devices(); - return map_dpi_rect( rect, system_dpi, get_thread_dpi() ); + return rect; }
RECT get_primary_monitor_rect( UINT dpi ) @@ -2365,12 +2367,12 @@ RECT get_primary_monitor_rect( UINT dpi ) LIST_FOR_EACH_ENTRY( monitor, &monitors, struct monitor, entry ) { if (!is_monitor_primary( monitor )) continue; - rect = monitor->rc_monitor; + rect = get_monitor_rect( monitor, FALSE, dpi ); break; }
unlock_display_devices(); - return map_dpi_rect( rect, system_dpi, dpi ); + return rect; }
/********************************************************************** @@ -3505,7 +3507,7 @@ static BOOL should_enumerate_monitor( struct monitor *monitor, const POINT *orig if (!is_monitor_active( monitor )) return FALSE; if (monitor->is_clone) return FALSE;
- *rect = get_monitor_rect( monitor, get_thread_dpi() ); + *rect = get_monitor_rect( monitor, FALSE, get_thread_dpi() ); OffsetRect( rect, -origin->x, -origin->y ); return intersect_rect( rect, rect, limit ); } @@ -3595,7 +3597,7 @@ BOOL WINAPI NtUserEnumDisplayMonitors( HDC hdc, RECT *rect, MONITORENUMPROC proc BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info ) { struct monitor *monitor; - UINT dpi_from, dpi_to; + UINT dpi = get_thread_dpi();
if (info->cbSize != sizeof(MONITORINFOEXW) && info->cbSize != sizeof(MONITORINFO)) return FALSE;
@@ -3606,9 +3608,8 @@ BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info ) if (monitor->handle != handle) continue; if (!is_monitor_active( monitor )) continue;
- /* FIXME: map dpi */ - info->rcMonitor = monitor->rc_monitor; - info->rcWork = monitor->rc_work; + info->rcMonitor = get_monitor_rect( monitor, FALSE, dpi ); + info->rcWork = get_monitor_rect( monitor, TRUE, dpi ); info->dwFlags = is_monitor_primary( monitor ) ? MONITORINFOF_PRIMARY : 0; if (info->cbSize >= sizeof(MONITORINFOEXW)) { @@ -3619,12 +3620,6 @@ BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info ) } unlock_display_devices();
- if ((dpi_to = get_thread_dpi())) - { - dpi_from = get_monitor_dpi( handle ); - info->rcMonitor = map_dpi_rect( info->rcMonitor, dpi_from, dpi_to ); - info->rcWork = map_dpi_rect( info->rcWork, dpi_from, dpi_to ); - } TRACE( "flags %04x, monitor %s, work %s\n", (int)info->dwFlags, wine_dbgstr_rect(&info->rcMonitor), wine_dbgstr_rect(&info->rcWork)); return TRUE; @@ -3658,7 +3653,7 @@ HMONITOR monitor_from_rect( const RECT *rect, UINT flags, UINT dpi )
if (!is_monitor_active( monitor ) || monitor->is_clone) continue;
- monitor_rect = get_monitor_rect( monitor, system_dpi ); + monitor_rect = get_monitor_rect( monitor, FALSE, system_dpi ); if (intersect_rect( &intersect, &monitor_rect, &r )) { /* check for larger intersecting area */ @@ -5244,6 +5239,8 @@ BOOL WINAPI NtUserSystemParametersInfo( UINT action, UINT val, void *ptr, UINT w } case SPI_GETWORKAREA: { + UINT dpi = get_thread_dpi(); + if (!ptr) return FALSE;
spi_idx = SPI_SETWORKAREA_IDX; @@ -5256,14 +5253,14 @@ BOOL WINAPI NtUserSystemParametersInfo( UINT action, UINT val, void *ptr, UINT w LIST_FOR_EACH_ENTRY( monitor, &monitors, struct monitor, entry ) { if (!is_monitor_primary( monitor )) continue; - work_area = monitor->rc_work; + work_area = get_monitor_rect( monitor, TRUE, dpi ); break; }
unlock_display_devices(); spi_loaded[spi_idx] = TRUE; } - *(RECT *)ptr = map_dpi_rect( work_area, system_dpi, get_thread_dpi() ); + *(RECT *)ptr = work_area; ret = TRUE; TRACE("work area %s\n", wine_dbgstr_rect( &work_area )); break;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/input.c | 7 +++---- dlls/win32u/sysparams.c | 2 +- dlls/win32u/win32u_private.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c index a58a8369559..05d8eb05d12 100644 --- a/dlls/win32u/input.c +++ b/dlls/win32u/input.c @@ -2553,9 +2553,8 @@ BOOL WINAPI NtUserGetPointerInfoList( UINT32 id, POINTER_INPUT_TYPE type, UINT_P return FALSE; }
-BOOL get_clip_cursor( RECT *rect ) +BOOL get_clip_cursor( RECT *rect, UINT dpi ) { - UINT dpi; BOOL ret;
if (!rect) return FALSE; @@ -2568,7 +2567,7 @@ BOOL get_clip_cursor( RECT *rect ) } SERVER_END_REQ;
- if (ret && (dpi = get_thread_dpi())) + if (ret) { HMONITOR monitor = monitor_from_rect( rect, MONITOR_DEFAULTTOPRIMARY, 0 ); *rect = map_dpi_rect( *rect, get_monitor_dpi( monitor ), dpi ); @@ -2596,7 +2595,7 @@ BOOL process_wine_clipcursor( HWND hwnd, UINT flags, BOOL reset ) if (!grab_pointer) return TRUE;
/* we are clipping if the clip rectangle is smaller than the screen */ - get_clip_cursor( &rect ); + get_clip_cursor( &rect, 0 ); intersect_rect( &rect, &rect, &virtual_rect ); if (EqualRect( &rect, &virtual_rect )) empty = TRUE; if (empty && !(flags & SET_CURSOR_FSCLIP)) diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 56410cbf48c..23b03d858a3 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -6404,7 +6404,7 @@ ULONG_PTR WINAPI NtUserCallOneParam( ULONG_PTR arg, ULONG code ) return enum_clipboard_formats( arg );
case NtUserCallOneParam_GetClipCursor: - return get_clip_cursor( (RECT *)arg ); + return get_clip_cursor( (RECT *)arg, get_thread_dpi() );
case NtUserCallOneParam_GetCursorPos: return get_cursor_pos( (POINT *)arg ); diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 8cc4d1beed3..43cdda55e2c 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -103,7 +103,7 @@ extern BOOL set_caret_pos( int x, int y ); extern BOOL set_foreground_window( HWND hwnd, BOOL mouse ); extern void toggle_caret( HWND hwnd ); extern void update_mouse_tracking_info( HWND hwnd ); -extern BOOL get_clip_cursor( RECT *rect ); +extern BOOL get_clip_cursor( RECT *rect, UINT dpi ); extern BOOL process_wine_clipcursor( HWND hwnd, UINT flags, BOOL reset ); extern BOOL clip_fullscreen_window( HWND hwnd, BOOL reset ); extern USHORT map_scan_to_kbd_vkey( USHORT scan, HKL layout );
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/defwnd.c | 2 +- dlls/win32u/input.c | 2 +- dlls/win32u/menu.c | 2 +- dlls/win32u/sysparams.c | 5 ++--- dlls/win32u/win32u_private.h | 2 +- dlls/win32u/window.c | 10 +++++----- 6 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/dlls/win32u/defwnd.c b/dlls/win32u/defwnd.c index 95ad9481958..f549f922fd7 100644 --- a/dlls/win32u/defwnd.c +++ b/dlls/win32u/defwnd.c @@ -826,7 +826,7 @@ static void sys_command_size_move( HWND hwnd, WPARAM wparam ) mon = newmon;
info.cbSize = sizeof(info); - if (mon && get_monitor_info( mon, &info )) + if (mon && get_monitor_info( mon, &info, get_thread_dpi() )) { pt.x = max( pt.x, info.rcWork.left ); pt.x = min( pt.x, info.rcWork.right - 1 ); diff --git a/dlls/win32u/input.c b/dlls/win32u/input.c index 05d8eb05d12..5b25086cb6f 100644 --- a/dlls/win32u/input.c +++ b/dlls/win32u/input.c @@ -2520,7 +2520,7 @@ BOOL clip_fullscreen_window( HWND hwnd, BOOL reset ) if (!reset && clipping_cursor && thread_info->clipping_cursor) return FALSE; /* already clipping */
if (!(monitor = NtUserMonitorFromWindow( hwnd, MONITOR_DEFAULTTONEAREST ))) return FALSE; - if (!NtUserGetMonitorInfo( monitor, &monitor_info )) return FALSE; + if (!get_monitor_info( monitor, &monitor_info, 0 )) return FALSE; if (!grab_fullscreen) { RECT virtual_rect = NtUserGetVirtualScreenRect(); diff --git a/dlls/win32u/menu.c b/dlls/win32u/menu.c index 05eb5445395..8a3f1350004 100644 --- a/dlls/win32u/menu.c +++ b/dlls/win32u/menu.c @@ -3068,7 +3068,7 @@ static BOOL show_popup( HWND owner, HMENU hmenu, UINT id, UINT flags, pt.y = y; monitor = monitor_from_point( pt, MONITOR_DEFAULTTONEAREST, get_thread_dpi() ); info.cbSize = sizeof(info); - get_monitor_info( monitor, &info ); + get_monitor_info( monitor, &info, get_thread_dpi() );
max_height = info.rcWork.bottom - info.rcWork.top; if (menu->cyMax) max_height = min( max_height, menu->cyMax ); diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index 23b03d858a3..e465ec66af3 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -3594,10 +3594,9 @@ BOOL WINAPI NtUserEnumDisplayMonitors( HDC hdc, RECT *rect, MONITORENUMPROC proc return ret; }
-BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info ) +BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info, UINT dpi ) { struct monitor *monitor; - UINT dpi = get_thread_dpi();
if (info->cbSize != sizeof(MONITORINFOEXW) && info->cbSize != sizeof(MONITORINFO)) return FALSE;
@@ -6484,7 +6483,7 @@ ULONG_PTR WINAPI NtUserCallTwoParam( ULONG_PTR arg1, ULONG_PTR arg2, ULONG code return get_menu_info( UlongToHandle(arg1), (MENUINFO *)arg2 );
case NtUserCallTwoParam_GetMonitorInfo: - return get_monitor_info( UlongToHandle(arg1), (MONITORINFO *)arg2 ); + return get_monitor_info( UlongToHandle(arg1), (MONITORINFO *)arg2, get_thread_dpi() );
case NtUserCallTwoParam_GetSystemMetricsForDpi: return get_system_metrics_for_dpi( arg1, arg2 ); diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 43cdda55e2c..96517ef081a 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -163,7 +163,7 @@ extern LONG get_char_dimensions( HDC hdc, TEXTMETRICW *metric, int *height ); extern INT get_display_depth( UNICODE_STRING *name ); extern RECT get_display_rect( const WCHAR *display ); extern UINT get_monitor_dpi( HMONITOR monitor ); -extern BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info ); +extern BOOL get_monitor_info( HMONITOR handle, MONITORINFO *info, UINT dpi ); extern UINT get_win_monitor_dpi( HWND hwnd ); extern RECT get_primary_monitor_rect( UINT dpi ); extern DWORD get_process_layout(void); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index eed4b914331..8ca49afcd87 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -2355,7 +2355,7 @@ static BOOL get_work_rect( HWND hwnd, RECT *rect ) if (!monitor) return FALSE;
mon_info.cbSize = sizeof(mon_info); - get_monitor_info( monitor, &mon_info ); + get_monitor_info( monitor, &mon_info, get_thread_dpi() ); *rect = mon_info.rcMonitor;
style = get_window_long( hwnd, GWL_STYLE ); @@ -2508,7 +2508,7 @@ static void make_rect_onscreen( RECT *rect ) HMONITOR monitor = monitor_from_rect( rect, MONITOR_DEFAULTTONEAREST, get_thread_dpi() );
info.cbSize = sizeof(info); - if (!monitor || !get_monitor_info( monitor, &info )) return; + if (!monitor || !get_monitor_info( monitor, &info, get_thread_dpi() )) return; /* FIXME: map coordinates from rcWork to rcMonitor */ if (rect->right <= info.rcWork.left) { @@ -4019,7 +4019,7 @@ static POINT get_minimized_pos( HWND hwnd, POINT pt ) HMONITOR monitor = monitor_from_window( hwnd, MONITOR_DEFAULTTOPRIMARY, get_thread_dpi() );
mon_info.cbSize = sizeof( mon_info ); - get_monitor_info( monitor, &mon_info ); + get_monitor_info( monitor, &mon_info, get_thread_dpi() ); parent_rect = mon_info.rcWork; } else get_client_rect( parent, &parent_rect, get_thread_dpi() ); @@ -4203,7 +4203,7 @@ static UINT arrange_iconic_windows( HWND parent ) HMONITOR monitor = monitor_from_window( 0, MONITOR_DEFAULTTOPRIMARY, get_thread_dpi() );
mon_info.cbSize = sizeof( mon_info ); - get_monitor_info( monitor, &mon_info ); + get_monitor_info( monitor, &mon_info, get_thread_dpi() ); parent_rect = mon_info.rcWork; } else get_client_rect( parent, &parent_rect, get_thread_dpi() ); @@ -5035,7 +5035,7 @@ static void fix_cs_coordinates( CREATESTRUCTW *cs, INT *sw )
monitor = monitor_from_window( cs->hwndParent, MONITOR_DEFAULTTOPRIMARY, get_thread_dpi() ); mon_info.cbSize = sizeof(mon_info); - get_monitor_info( monitor, &mon_info ); + get_monitor_info( monitor, &mon_info, get_thread_dpi() );
if (is_default_coord( cs->x )) {