commit f9d81c91710080893ae48f59f7741e8dcdd439e8
Author: Roberto Tronci <roberto.tronci@bittree.it>
Date:   Mon Sep 19 16:29:52 2016 +0200

    Adding Retry on OpenClipboard to avoid locks form external tools

diff --git a/gdk/win32/gdkselection-win32.c b/gdk/win32/gdkselection-win32.c
index 131c0bf..df661bd 100644
--- a/gdk/win32/gdkselection-win32.c
+++ b/gdk/win32/gdkselection-win32.c
@@ -63,6 +63,22 @@ static GdkAtom text_plain;
 static GdkAtom text_plain_charset_utf_8;
 static GdkAtom text_plain_charset_CP1252;
 
+static guint
+_gdk_win32_open_clipboard (HWND  hwnd_new_owner,
+                           guint retry_times,
+                           guint microseconds_retry_delay)
+{
+    while (--retry_times > 0) 
+      {
+        if (OpenClipboard (hwnd_new_owner))
+            return 1;
+
+        g_usleep(microseconds_retry_delay);
+      }
+
+    return (API_CALL (OpenClipboard, (hwnd_new_owner)));
+}
+
 void
 _gdk_win32_selection_init (void)
 {
@@ -292,7 +309,7 @@ _gdk_win32_display_set_selection_owner (GdkDisplay *display,
   else
     hwnd = NULL;
 
-  if (!API_CALL (OpenClipboard, (hwnd)))
+  if (!_gdk_win32_open_clipboard ((hwnd), 10, 5000))
     return FALSE;
 
   _ignore_destroy_clipboard = TRUE;
@@ -419,7 +436,7 @@ _gdk_win32_display_convert_selection (GdkDisplay *display,
       gboolean has_png = FALSE;
       gboolean has_bmp = FALSE;
 
-      if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
+      if (!_gdk_win32_open_clipboard((GDK_WINDOW_HWND (requestor)), 10, 5000))
 	return;
 
       targets = g_new (GdkAtom, CountClipboardFormats ());
@@ -523,7 +540,7 @@ _gdk_win32_display_convert_selection (GdkDisplay *display,
        * contents of the clipboard. Get the clipboard data, and store
        * it for later.
        */
-      if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
+      if (!_gdk_win32_open_clipboard((GDK_WINDOW_HWND (requestor)), 10, 5000))
 	return;
 
       if ((hdata = GetClipboardData (CF_UNICODETEXT)) != NULL)
@@ -568,7 +585,7 @@ _gdk_win32_display_convert_selection (GdkDisplay *display,
     }
   else if (selection == GDK_SELECTION_CLIPBOARD && target == _image_bmp)
     {
-      if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
+      if (!_gdk_win32_open_clipboard((GDK_WINDOW_HWND (requestor)), 10, 5000))
 	return;
 
       if ((hdata = GetClipboardData (CF_DIB)) != NULL)
@@ -745,7 +762,7 @@ _gdk_win32_display_convert_selection (GdkDisplay *display,
       gchar *mapped_target_name;
       UINT fmt = 0;
 
-      if (!API_CALL (OpenClipboard, (GDK_WINDOW_HWND (requestor))))
+      if (!_gdk_win32_open_clipboard((GDK_WINDOW_HWND (requestor)), 10, 5000))
 	return;
 
       mapped_target_name = get_mapped_gdk_atom_name (target);
@@ -1181,7 +1198,7 @@ gdk_win32_selection_add_targets (GdkWindow  *owner,
       hwnd = GDK_WINDOW_HWND (owner);
     }
 
-  if (!API_CALL (OpenClipboard, (hwnd)))
+  if (!_gdk_win32_open_clipboard ((hwnd), 10, 5000))
     return;
 
   /* We have a very simple strategy: If some kind of pixmap image
