win32: destroy clipboard notification window on dispose

The clipboard uses a hidden window to get some specific events.
The window was created but never destroyed on dispose.
This commit is contained in:
Ignacio Casal Quinteiro
2015-11-12 16:42:51 +01:00
parent a4ccf0e382
commit 1f5f3ca41b
2 changed files with 28 additions and 21 deletions

View File

@ -570,30 +570,32 @@ _clipboard_window_procedure (HWND hwnd,
/* /*
* Creates a hidden window and adds it to the clipboard chain * Creates a hidden window and adds it to the clipboard chain
*/ */
static HWND static gboolean
_gdk_win32_register_clipboard_notification (void) register_clipboard_notification (GdkDisplay *display)
{ {
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
WNDCLASS wclass = { 0, }; WNDCLASS wclass = { 0, };
HWND hwnd; HWND hwnd;
ATOM klass; ATOM klass;
wclass.lpszClassName = "GdkClipboardNotification"; wclass.lpszClassName = "GdkClipboardNotification";
wclass.lpfnWndProc = _clipboard_window_procedure; wclass.lpfnWndProc = _clipboard_window_procedure;
wclass.hInstance = _gdk_app_hmodule; wclass.hInstance = _gdk_app_hmodule;
klass = RegisterClass (&wclass); klass = RegisterClass (&wclass);
if (!klass) if (!klass)
return NULL; return FALSE;
hwnd = CreateWindow (MAKEINTRESOURCE (klass), display_win32->clipboard_hwnd = CreateWindow (MAKEINTRESOURCE (klass),
NULL, WS_POPUP, NULL, WS_POPUP,
0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL,
_gdk_app_hmodule, NULL); _gdk_app_hmodule, NULL);
if (!hwnd)
if (display_win32->clipboard_hwnd == NULL)
goto failed; goto failed;
SetLastError (0); SetLastError (0);
_hwnd_next_viewer = SetClipboardViewer (hwnd); _hwnd_next_viewer = SetClipboardViewer (display_win32->clipboard_hwnd);
if (_hwnd_next_viewer == NULL && GetLastError() != 0) if (_hwnd_next_viewer == NULL && GetLastError() != 0)
goto failed; goto failed;
@ -603,20 +605,20 @@ _gdk_win32_register_clipboard_notification (void)
/* if (AddClipboardFormatListener (hwnd) == FALSE) */ /* if (AddClipboardFormatListener (hwnd) == FALSE) */
/* goto failed; */ /* goto failed; */
return hwnd; return TRUE;
failed: failed:
g_critical ("Failed to install clipboard viewer"); g_critical ("Failed to install clipboard viewer");
UnregisterClass (MAKEINTRESOURCE (klass), _gdk_app_hmodule); UnregisterClass (MAKEINTRESOURCE (klass), _gdk_app_hmodule);
return NULL; return FALSE;
} }
static gboolean static gboolean
gdk_win32_display_request_selection_notification (GdkDisplay *display, gdk_win32_display_request_selection_notification (GdkDisplay *display,
GdkAtom selection) GdkAtom selection)
{ {
static HWND hwndViewer = NULL; GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
gboolean ret = FALSE; gboolean ret = FALSE;
GDK_NOTE (DND, GDK_NOTE (DND,
@ -626,12 +628,14 @@ gdk_win32_display_request_selection_notification (GdkDisplay *display,
if (selection == GDK_SELECTION_CLIPBOARD || if (selection == GDK_SELECTION_CLIPBOARD ||
selection == GDK_SELECTION_PRIMARY) selection == GDK_SELECTION_PRIMARY)
{ {
if (!hwndViewer) if (display_win32->clipboard_hwnd == NULL)
{ {
hwndViewer = _gdk_win32_register_clipboard_notification (); if (register_clipboard_notification (display))
GDK_NOTE (DND, g_print (" registered")); GDK_NOTE (DND, g_print (" registered"));
else
GDK_NOTE (DND, g_print (" failed to register"));
} }
ret = (hwndViewer != NULL); ret = (display_win32->clipboard_hwnd != NULL);
} }
else else
{ {
@ -711,6 +715,8 @@ gdk_win32_display_dispose (GObject *object)
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (object); GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (object);
g_clear_pointer (&display_win32->hwnd, (GDestroyNotify)DestroyWindow); g_clear_pointer (&display_win32->hwnd, (GDestroyNotify)DestroyWindow);
g_clear_pointer (&display_win32->clipboard_hwnd, (GDestroyNotify)DestroyWindow);
_hwnd_next_viewer = NULL;
G_OBJECT_CLASS (gdk_win32_display_parent_class)->dispose (object); G_OBJECT_CLASS (gdk_win32_display_parent_class)->dispose (object);
} }

View File

@ -32,6 +32,7 @@ struct _GdkWin32Display
GHashTable *cursor_cache; GHashTable *cursor_cache;
HWND hwnd; HWND hwnd;
HWND clipboard_hwnd;
/* WGL/OpenGL Items */ /* WGL/OpenGL Items */
guint have_wgl : 1; guint have_wgl : 1;