From a53650d9da55a9a7ca522c38e3dc08f1f0c4a3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 12:57:20 +0400 Subject: [PATCH 1/9] gdk/win32: annotate filter callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- gdk/win32/gdkdisplay-win32.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c index a544bf3827..3028045746 100644 --- a/gdk/win32/gdkdisplay-win32.c +++ b/gdk/win32/gdkdisplay-win32.c @@ -51,8 +51,8 @@ static int debug_indent = 0; /** * gdk_win32_display_add_filter: * @display: a `GdkWin32Display` - * @function: filter callback - * @data: data to pass to filter callback + * @function: (scope notified): filter callback + * @data: (closure): data to pass to filter callback * * Adds an event filter to @window, allowing you to intercept messages * before they reach GDK. This is a low-level operation and makes it @@ -136,8 +136,8 @@ _gdk_win32_message_filter_unref (GdkWin32Display *display, /** * gdk_win32_display_remove_filter: * @display: A `GdkWin32Display` - * @function: previously-added filter function - * @data: user data for previously-added filter function + * @function: (scope notified): previously-added filter function + * @data: (closure): user data for previously-added filter function * * Remove a filter previously added with gdk_win32_display_add_filter(). */ From 180dd5fb7f53f48b2a3fef57b19f1ac2fb4074a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 15:32:55 +0400 Subject: [PATCH 2/9] gdk/win32: deprecate gdk_win32_surface_is_win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function isn't used by Gtk itself anymore, and does not help much. It creates extra issues for bindings, as it doesn't fit well with code doing the same job for other objects. Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 12 ++++++++++-- gdk/win32/gdkwin32misc.h | 5 ++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index 6fc15f3815..e461b0e916 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -4242,10 +4242,18 @@ gdk_win32_surface_lookup_for_display (GdkDisplay *display, return (GdkSurface*) gdk_win32_handle_table_lookup (anid); } +/** + * gdk_win32_surface_is_win32: + * @surface: a `GdkSurface` + * + * Returns: %TRUE if the @surface is a win32 implemented surface. + * + * Deprecated: 4.8: Use `GDK_IS_WIN32_SURFACE` instead. + */ gboolean -gdk_win32_surface_is_win32 (GdkSurface *window) +gdk_win32_surface_is_win32 (GdkSurface *surface) { - return GDK_IS_WIN32_SURFACE (window); + return GDK_IS_WIN32_SURFACE (surface); } static gboolean diff --git a/gdk/win32/gdkwin32misc.h b/gdk/win32/gdkwin32misc.h index 3582e81572..bfa356a453 100644 --- a/gdk/win32/gdkwin32misc.h +++ b/gdk/win32/gdkwin32misc.h @@ -68,9 +68,8 @@ G_BEGIN_DECLS #define XBUTTON2 2 #endif -/* Return true if the GdkSurface is a win32 implemented window */ -GDK_AVAILABLE_IN_ALL -gboolean gdk_win32_surface_is_win32 (GdkSurface *window); +GDK_DEPRECATED_IN_4_8_FOR(GDK_IS_WIN32_SURFACE) +gboolean gdk_win32_surface_is_win32 (GdkSurface *surface); GDK_AVAILABLE_IN_ALL HWND gdk_win32_surface_get_impl_hwnd (GdkSurface *window); From a75de5fb909b613f4e00fc3c026350bdbe90be06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 16:17:15 +0400 Subject: [PATCH 3/9] gdk/win32: correct gdk_win32_surface_get_handle return type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The associated surface window handle is a HWND, not a HGDIOBJ. Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 2 +- gdk/win32/gdkwin32misc.h | 2 +- tests/dummy-headers/windows.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index e461b0e916..bd4183eb0b 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -4621,7 +4621,7 @@ gdk_win32_surface_class_init (GdkWin32SurfaceClass *klass) impl_class->compute_size = _gdk_win32_surface_compute_size; } -HGDIOBJ +HWND gdk_win32_surface_get_handle (GdkSurface *window) { if (!GDK_IS_WIN32_SURFACE (window)) diff --git a/gdk/win32/gdkwin32misc.h b/gdk/win32/gdkwin32misc.h index bfa356a453..1bab4ec404 100644 --- a/gdk/win32/gdkwin32misc.h +++ b/gdk/win32/gdkwin32misc.h @@ -78,7 +78,7 @@ GDK_AVAILABLE_IN_ALL gpointer gdk_win32_handle_table_lookup (HWND handle); /* Translate from window to Windows handle */ GDK_AVAILABLE_IN_ALL -HGDIOBJ gdk_win32_surface_get_handle (GdkSurface *window); +HWND gdk_win32_surface_get_handle (GdkSurface *window); GDK_AVAILABLE_IN_ALL GdkSurface * gdk_win32_surface_lookup_for_display (GdkDisplay *display, diff --git a/tests/dummy-headers/windows.h b/tests/dummy-headers/windows.h index fefe9e8fa2..1b1d700fc3 100644 --- a/tests/dummy-headers/windows.h +++ b/tests/dummy-headers/windows.h @@ -1,6 +1,5 @@ /* Dummy header for the Win32 backend. */ typedef void *HDC; -typedef void *HGDIOBJ; typedef void *HICON; typedef void *HWND; From 3cbf6c9d6e05ad3e89daabab1e51eba1f1072926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 16:25:30 +0400 Subject: [PATCH 4/9] gdk/win32: annotate gdk_win32_surface_get_handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And adjust the argument precondition check. Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 18 +++++++++++------- gdk/win32/gdkwin32misc.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index bd4183eb0b..79f2b9dd05 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -4621,16 +4621,20 @@ gdk_win32_surface_class_init (GdkWin32SurfaceClass *klass) impl_class->compute_size = _gdk_win32_surface_compute_size; } +/** + * gdk_win32_surface_get_handle: + * @surface: (type GdkWin32Surface): a native `GdkSurface`. + * + * Returns the HWND handle belonging to @surface. + * + * Returns: the associated HWND handle. + */ HWND -gdk_win32_surface_get_handle (GdkSurface *window) +gdk_win32_surface_get_handle (GdkSurface *surface) { - if (!GDK_IS_WIN32_SURFACE (window)) - { - g_warning (G_STRLOC " window is not a native Win32 window"); - return NULL; - } + g_return_val_if_fail (GDK_IS_WIN32_SURFACE (surface), NULL); - return GDK_SURFACE_HWND (window); + return GDK_SURFACE_HWND (surface); } #define LAST_PROP 1 diff --git a/gdk/win32/gdkwin32misc.h b/gdk/win32/gdkwin32misc.h index 1bab4ec404..7497ee593e 100644 --- a/gdk/win32/gdkwin32misc.h +++ b/gdk/win32/gdkwin32misc.h @@ -78,7 +78,7 @@ GDK_AVAILABLE_IN_ALL gpointer gdk_win32_handle_table_lookup (HWND handle); /* Translate from window to Windows handle */ GDK_AVAILABLE_IN_ALL -HWND gdk_win32_surface_get_handle (GdkSurface *window); +HWND gdk_win32_surface_get_handle (GdkSurface *surface); GDK_AVAILABLE_IN_ALL GdkSurface * gdk_win32_surface_lookup_for_display (GdkDisplay *display, From 04ebec0fa7581ddfa5d815d2de0671b2b4e45445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 16:31:07 +0400 Subject: [PATCH 5/9] gtk/win32: use gdk_win32_surface_get_handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As I propose to deprecate gdk_win32_surface_get_impl_hwnd() next, replace it with the alternative. The main difference between the two functions is that gdk_win32_surface_get_impl_hwnd() fails gracefully by returning NULL if the surface is not of the win32 implementation. All the surfaces should be native surfaces here, and the existing code doesn't seem to deal with NULL case anyway. Signed-off-by: Marc-André Lureau --- gtk/gtkimcontextime.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gtk/gtkimcontextime.c b/gtk/gtkimcontextime.c index adb122f2c6..91eb726a24 100644 --- a/gtk/gtkimcontextime.c +++ b/gtk/gtkimcontextime.c @@ -256,7 +256,7 @@ gtk_im_context_ime_set_client_widget (GtkIMContext *context, if (surface != NULL) { - HWND hwnd = gdk_win32_surface_get_impl_hwnd (surface); + HWND hwnd = gdk_win32_surface_get_handle (surface); HIMC himc = ImmGetContext (hwnd); if (himc) { @@ -418,7 +418,7 @@ gtk_im_context_ime_reset (GtkIMContext *context) if (!context_ime->client_surface) return; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return; @@ -453,7 +453,7 @@ get_utf8_preedit_string (GtkIMContextIME *context_ime, if (!context_ime->client_surface) return g_strdup (""); - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return g_strdup (""); @@ -512,7 +512,7 @@ get_pango_attr_list (GtkIMContextIME *context_ime, const char *utf8str) if (!context_ime->client_surface) return attrs; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return attrs; @@ -655,7 +655,7 @@ gtk_im_context_ime_focus_in (GtkIMContext *context) return; } - hwnd = gdk_win32_surface_get_impl_hwnd (toplevel); + hwnd = gdk_win32_surface_get_handle (toplevel); himc = ImmGetContext (hwnd); if (!himc) return; @@ -780,7 +780,7 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context, if (!context_ime->client_surface) return; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return; @@ -811,7 +811,7 @@ gtk_im_context_ime_set_use_preedit (GtkIMContext *context, HWND hwnd; HIMC himc; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return; @@ -844,7 +844,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context) if (!(context_ime->client_widget && context_ime->client_surface)) return; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return; @@ -955,10 +955,10 @@ gtk_im_context_ime_message_filter (GdkWin32Display *display, return retval; toplevel = context_ime->client_surface; - if (gdk_win32_surface_get_impl_hwnd (toplevel) != msg->hwnd) + if (gdk_win32_surface_get_handle (toplevel) != msg->hwnd) return retval; - hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface); + hwnd = gdk_win32_surface_get_handle (context_ime->client_surface); himc = ImmGetContext (hwnd); if (!himc) return retval; From a6418d50287d4cf3ea5c6c757ec50c1720d38042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 16:35:07 +0400 Subject: [PATCH 6/9] gdk/win32: deprecate gdk_win32_surface_get_impl_hwnd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 14 +++++++++++--- gdk/win32/gdkwin32misc.h | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index 79f2b9dd05..ed19c9f70a 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -4287,11 +4287,19 @@ gdk_win32_surface_show_window_menu (GdkSurface *surface, return TRUE; } +/** + * gdk_win32_surface_get_impl_hwnd: + * @surface: a `GdkSurface` + * + * Returns: the associated @surface HWND handle. + * + * Deprecated: 4.8: Use gdk_win32_surface_get_handle() instead. + */ HWND -gdk_win32_surface_get_impl_hwnd (GdkSurface *window) +gdk_win32_surface_get_impl_hwnd (GdkSurface *surface) { - if (GDK_IS_WIN32_SURFACE (window)) - return GDK_SURFACE_HWND (window); + if (GDK_IS_WIN32_SURFACE (surface)) + return GDK_SURFACE_HWND (surface); return NULL; } diff --git a/gdk/win32/gdkwin32misc.h b/gdk/win32/gdkwin32misc.h index 7497ee593e..990b8d0156 100644 --- a/gdk/win32/gdkwin32misc.h +++ b/gdk/win32/gdkwin32misc.h @@ -70,8 +70,8 @@ G_BEGIN_DECLS GDK_DEPRECATED_IN_4_8_FOR(GDK_IS_WIN32_SURFACE) gboolean gdk_win32_surface_is_win32 (GdkSurface *surface); -GDK_AVAILABLE_IN_ALL -HWND gdk_win32_surface_get_impl_hwnd (GdkSurface *window); +GDK_DEPRECATED_IN_4_8_FOR(gdk_win32_surface_get_handle) +HWND gdk_win32_surface_get_impl_hwnd (GdkSurface *surface); /* Return the Gdk* for a particular HANDLE */ GDK_AVAILABLE_IN_ALL From 88503bcc3bb3a281bd31915952a9248a7c485f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 16:42:15 +0400 Subject: [PATCH 7/9] gtk/win32: fix a switch-default warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gtk/gtkimcontextime.c:714:3: warning: switch missing default case [-Wswitch-default] Signed-off-by: Marc-André Lureau --- gtk/gtkimcontextime.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gtk/gtkimcontextime.c b/gtk/gtkimcontextime.c index 91eb726a24..e341925733 100644 --- a/gtk/gtkimcontextime.c +++ b/gtk/gtkimcontextime.c @@ -741,6 +741,9 @@ gtk_im_context_ime_focus_out (GtkIMContext *context) case GTK_WIN32_IME_FOCUS_BEHAVIOR_FOLLOW: break; + + default: + g_assert_not_reached (); } /* remove event filter */ From cad32636cec29de26701af5adaecd09285effced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 17:06:48 +0400 Subject: [PATCH 8/9] gdk/win32: annotate gdk_win32_surface_set_urgency_hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index ed19c9f70a..a2f60eb3ec 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -1305,19 +1305,27 @@ gdk_win32_surface_raise (GdkSurface *window) } } +/** + * gdk_win32_surface_set_urgency_hint: + * @surface: (type GdkWin32Surface): a native `GdkSurface`. + * @urgent: if %TRUE, flashes both the window and the taskbar button + * continuously. + * + * Flashes the specified @surface. + */ void -gdk_win32_surface_set_urgency_hint (GdkSurface *window, +gdk_win32_surface_set_urgency_hint (GdkSurface *surface, gboolean urgent) { FLASHWINFO flashwinfo; - g_return_if_fail (GDK_IS_SURFACE (window)); + g_return_if_fail (GDK_IS_WIN32_SURFACE (surface)); - if (GDK_SURFACE_DESTROYED (window)) + if (GDK_SURFACE_DESTROYED (surface)) return; flashwinfo.cbSize = sizeof (flashwinfo); - flashwinfo.hwnd = GDK_SURFACE_HWND (window); + flashwinfo.hwnd = GDK_SURFACE_HWND (surface); if (urgent) flashwinfo.dwFlags = FLASHW_ALL | FLASHW_TIMER; else From 0d7a0132bbe6810bdfc2d55b949bafd4360d1155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 23 Aug 2022 17:20:39 +0400 Subject: [PATCH 9/9] gdk/win32: annotate gdk_win32_surface_lookup_for_display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- gdk/win32/gdksurface-win32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index a2f60eb3ec..47e54ac923 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -4241,6 +4241,13 @@ gdk_win32_surface_focus (GdkSurface *window, SetFocus (GDK_SURFACE_HWND (window)); } +/** + * gdk_win32_surface_lookup_for_display: + * @display: a %GdkDisplay + * @anid: a HWND window handle + * + * Returns: (nullable): the %GdkSurface associated with the given @anid, or %NULL. + */ GdkSurface * gdk_win32_surface_lookup_for_display (GdkDisplay *display, HWND anid)