win32: window, IME and monitor fixes from GTK 3

Backported from GTK 3:

- frameless windows maximize without covering the taskbar
- IME windows follow the scale
- monitor info and selection names without overflow or leak
- opacity on child windows is ignored quietly

Upstream commits:

- c61764b0f9 (Руслан Ижбулатов)
- c073a062b6 (Chun-wei Fan)
- ba6522d3f2 (Vasiliy Nuzha)
- 41026987be (Руслан Ижбулатов)
- 6dede1a0b7 (Руслан Ижбулатов)
This commit is contained in:
Daemonratte 2026-10-18 10:41:33 +02:00
commit bd3df5bec1
4 changed files with 46 additions and 13 deletions

View file

@ -91,7 +91,7 @@ enum_monitor (HMONITOR hmonitor,
monitor = _gdk_monitors + *index;
monitor_info.cbSize = sizeof (MONITORINFOEX);
monitor_info.cbSize = sizeof (MONITORINFOEXA2);
GetMonitorInfoA (hmonitor, (MONITORINFO *) &monitor_info);
#ifndef MONITORINFOF_PRIMARY
@ -529,10 +529,11 @@ gdk_display_request_selection_notification (GdkDisplay *display,
{
static HWND hwndViewer = NULL;
gboolean ret = FALSE;
gchar *selection_name = gdk_atom_name (selection);
GDK_NOTE (DND,
g_print ("gdk_display_request_selection_notification (..., %s)",
gdk_atom_name (selection)));
selection_name));
if (selection == GDK_SELECTION_CLIPBOARD ||
selection == GDK_SELECTION_PRIMARY)
@ -550,6 +551,8 @@ gdk_display_request_selection_notification (GdkDisplay *display,
ret = FALSE;
}
g_free (selection_name);
GDK_NOTE (DND, g_print (" -> %s\n", ret ? "TRUE" : "FALSE"));
return ret;
}

View file

@ -3596,8 +3596,36 @@ gdk_event_translate (MSG *msg,
}
else
{
/* Apparently, this is just a very big number (bigger than any widget
* could realistically be) to make sure the window is as big as
* possible when maximized.
*/
mmi->ptMaxTrackSize.x = 30000;
mmi->ptMaxTrackSize.y = 30000;
/* A window without a frame would be maximized over the whole
* monitor, taskbar included. Windows wants the maximized position
* and size as if the window were on the primary monitor, so only
* the taskbar of the nearest monitor is taken into account.
*/
if ((GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) &
(WS_BORDER | WS_THICKFRAME)) == 0)
{
HMONITOR nearest_monitor;
MONITORINFO nearest_info;
nearest_monitor = MonitorFromWindow (GDK_WINDOW_HWND (window),
MONITOR_DEFAULTTONEAREST);
nearest_info.cbSize = sizeof (nearest_info);
if (GetMonitorInfoA (nearest_monitor, &nearest_info))
{
mmi->ptMaxPosition.x = nearest_info.rcWork.left - nearest_info.rcMonitor.left;
mmi->ptMaxPosition.y = nearest_info.rcWork.top - nearest_info.rcMonitor.top;
mmi->ptMaxSize.x = nearest_info.rcWork.right - nearest_info.rcWork.left;
mmi->ptMaxSize.y = nearest_info.rcWork.bottom - nearest_info.rcWork.top;
}
}
}
if (impl->hint_flags & (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE))

View file

@ -3983,9 +3983,8 @@ gdk_window_set_opacity (GdkWindow *window,
PFN_SetLayeredWindowAttributes setLayeredWindowAttributes = NULL;
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (WINDOW_IS_TOPLEVEL (window));
if (GDK_WINDOW_DESTROYED (window))
if (!WINDOW_IS_TOPLEVEL (window) || GDK_WINDOW_DESTROYED (window))
return;
if (opacity < 0)

View file

@ -825,6 +825,7 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
COMPOSITIONFORM cf;
HWND hwnd;
HIMC himc;
guint scale;
g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
@ -840,10 +841,11 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
if (!himc)
return;
scale = gdk_window_get_scale_factor (context_ime->client_window);
get_window_position (context_ime->client_window, &wx, &wy);
cf.dwStyle = CFS_POINT;
cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
cf.ptCurrentPos.y = wy + context_ime->cursor_location.y;
cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale;
cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y) * scale;
ImmSetCompositionWindow (himc, &cf);
ImmReleaseContext (hwnd, himc);
@ -1019,6 +1021,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
{
gint wx = 0, wy = 0;
CANDIDATEFORM cf;
guint scale = gdk_window_get_scale_factor (context_ime->client_window);
get_window_position (context_ime->client_window, &wx, &wy);
/* FIXME! */
@ -1031,17 +1034,17 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent,
gdk_win32_window_get_impl_hwnd (gdk_window_get_toplevel
(context_ime->client_window));
GetWindowRect (hwnd_top, &rc);
pt.x = wx;
pt.y = wy;
pt.x = wx * scale;
pt.y = wy * scale;
ClientToScreen (hwnd_top, &pt);
wx = pt.x - rc.left;
wy = pt.y - rc.top;
wx = (pt.x - rc.left) / scale;
wy = (pt.y - rc.top) / scale;
}
cf.dwIndex = 0;
cf.dwStyle = CFS_CANDIDATEPOS;
cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
cf.ptCurrentPos.y = wy + context_ime->cursor_location.y
+ context_ime->cursor_location.height;
cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale;
cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y
+ context_ime->cursor_location.height) * scale;
ImmSetCandidateWindow (himc, &cf);
if ((msg->lParam & GCS_COMPSTR))