[Spice-commits] 4 commits - client/windows

Arnon Gilboa agilboa at kemper.freedesktop.org
Mon Oct 11 08:52:40 PDT 2010


 client/windows/platform.cpp |   90 ++++++++++++++++++++++----------------------
 1 file changed, 46 insertions(+), 44 deletions(-)

New commits:
commit 57cea3235fd2c6a0b88ea67b4fbb350058ebe724
Author: Arnon Gilboa <agilboa at redhat.com>
Date:   Mon Oct 11 15:07:14 2010 +0200

    spice-win: handle multiple types on clipboard grab send & receive

diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index 9361180..1c309b3 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -75,6 +75,8 @@ static ClipboardFormat clipboard_formats[] = {
     {CF_UNICODETEXT, VD_AGENT_CLIPBOARD_UTF8_TEXT},
     {0, 0}};
 
+#define clipboard_formats_count (sizeof(clipboard_formats) / sizeof(clipboard_formats[0]))
+
 static const unsigned long MODAL_LOOP_TIMER_ID = 1;
 static const int MODAL_LOOP_DEFAULT_TIMEOUT = 100;
 static bool modal_loop_active = false;
@@ -100,17 +102,21 @@ static uint32_t get_clipboard_format(uint32_t type) {
     return iter->format;
 }
 
-//FIXME: handle multiple types
-static uint32_t get_available_clipboard_type()
+static int get_available_clipboard_types(uint32_t** types)
 {
-    uint32_t type = 0;
+    int count = 0;
 
-    for (ClipboardFormat* iter = clipboard_formats; iter->format && !type; iter++) {
+    *types = new uint32_t[clipboard_formats_count];
+    for (ClipboardFormat* iter = clipboard_formats; iter->format; iter++) {
         if (IsClipboardFormatAvailable(iter->format)) {
-            type = iter->type;
+            *types[count++] = iter->type;
         }
     }
-    return type;
+    if (!count) {
+        delete[] *types;
+        *types = NULL;
+    }
+    return count;
 }
 
 static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
@@ -145,11 +151,12 @@ static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam,
         break;
     case WM_DRAWCLIPBOARD:
         if (platform_win != GetClipboardOwner()) {
+            int type_count;
+            uint32_t* types;
             Platform::set_clipboard_owner(Platform::owner_none);
-            //FIXME: handle multiple types
-            uint32_t type = get_available_clipboard_type();            
-            if (type) {
-                clipboard_listener->on_clipboard_grab(&type, 1);
+            if (type_count = get_available_clipboard_types(&types)) {
+                clipboard_listener->on_clipboard_grab(types, type_count);
+                delete[] types;
             } else {
                 LOG_INFO("Unsupported clipboard format");
             }
@@ -874,18 +881,28 @@ void Platform::set_clipboard_owner(int new_owner)
 
 bool Platform::on_clipboard_grab(uint32_t *types, uint32_t type_count)
 {
-    /* FIXME use all types rather then just the first one */
-    uint32_t format = get_clipboard_format(types[0]);
-    
-    if (!format) {
-        LOG_INFO("Unsupported clipboard type %u", types[0]);
-        return false;
+    bool has_supported_type = false;
+    uint32_t format;
+
+    for (uint32_t i = 0; i < type_count; i++) {
+        format = get_clipboard_format(types[i]);
+        //On first supported type, open and empty the clipboard
+        if (format && !has_supported_type) {
+            has_supported_type = true;
+            if (!OpenClipboard(platform_win)) {
+                return false;
+            }
+            EmptyClipboard();
+        }
+        //For all supported type set delayed rendering
+        if (format) {
+            SetClipboardData(format, NULL);
+        }
     }
-    if (!OpenClipboard(platform_win)) {
+    if (!has_supported_type) {
+        LOG_INFO("No supported clipboard types in client grab");
         return false;
     }
-    EmptyClipboard();
-    SetClipboardData(format, NULL);
     CloseClipboard();
 
     set_clipboard_owner(owner_guest);
commit 1148edfea4593a72694375367cd97097e9dfced5
Author: Arnon Gilboa <agilboa at redhat.com>
Date:   Wed Oct 6 16:47:45 2010 +0200

    spice-win: remove clipboard_changer hack
    
    Instead of keeping a flag, we simply check wether the new owner is us or not

diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index 4df7d43..9361180 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -64,11 +64,6 @@ static Platform::ClipboardListener* clipboard_listener = &default_clipboard_list
 static HWND next_clipboard_viewer_win = NULL;
 static HANDLE clipboard_event = NULL;
 
-// clipboard_changer says whether the client was the last one to change cliboard, for loop
-// prevention. It's initialized to true so we ignore the first clipboard change event which
-// happens right when we call SetClipboardViewer().
-static bool clipboard_changer = true;
-
 static const int CLIPBOARD_TIMEOUT_MS = 10000;
 
 typedef struct ClipboardFormat {
@@ -149,7 +144,8 @@ static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam,
         }
         break;
     case WM_DRAWCLIPBOARD:
-        if (!clipboard_changer) {
+        if (platform_win != GetClipboardOwner()) {
+            Platform::set_clipboard_owner(Platform::owner_none);
             //FIXME: handle multiple types
             uint32_t type = get_available_clipboard_type();            
             if (type) {
@@ -157,8 +153,6 @@ static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam,
             } else {
                 LOG_INFO("Unsupported clipboard format");
             }
-        } else {
-            clipboard_changer = false;
         }
         if (next_clipboard_viewer_win) {
             SendMessage(next_clipboard_viewer_win, message, wParam, lParam);
@@ -890,7 +884,6 @@ bool Platform::on_clipboard_grab(uint32_t *types, uint32_t type_count)
     if (!OpenClipboard(platform_win)) {
         return false;
     }
-    clipboard_changer = true;
     EmptyClipboard();
     SetClipboardData(format, NULL);
     CloseClipboard();
commit f2ef521740d3b5a0bdc03408dc1648197c919f83
Author: Arnon Gilboa <agilboa at redhat.com>
Date:   Wed Oct 6 16:00:39 2010 +0200

    spice-win: handle type VD_AGENT_CLIPBOARD_NONE in Platform::on_clipboard_notify()

diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index c875022..4df7d43 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -105,6 +105,7 @@ static uint32_t get_clipboard_format(uint32_t type) {
     return iter->format;
 }
 
+//FIXME: handle multiple types
 static uint32_t get_available_clipboard_type()
 {
     uint32_t type = 0;
@@ -149,6 +150,7 @@ static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam,
         break;
     case WM_DRAWCLIPBOARD:
         if (!clipboard_changer) {
+            //FIXME: handle multiple types
             uint32_t type = get_available_clipboard_type();            
             if (type) {
                 clipboard_listener->on_clipboard_grab(&type, 1);
@@ -865,12 +867,15 @@ void Platform::set_clipboard_owner_unlocked(int new_owner)
 
 void Platform::set_clipboard_owner(int new_owner)
 {
+    const char * const owner_str[] = { "none", "guest", "client" };
+
     if (new_owner == owner_none) {
         clipboard_listener->on_clipboard_release();
 
         /* FIXME clear cached clipboard type info and data */
     }
     _clipboard_owner = new_owner;
+    LOG_INFO("new clipboard owner: %s", owner_str[new_owner]);
 }
 
 bool Platform::on_clipboard_grab(uint32_t *types, uint32_t type_count)
@@ -908,6 +913,10 @@ bool Platform::on_clipboard_notify(uint32_t type, const uint8_t* data, int32_t s
     UINT format;
     bool ret = false;
 
+    if (type == VD_AGENT_CLIPBOARD_NONE) {
+        SetEvent(clipboard_event);
+        return true;
+    }
     // Get the required clipboard size
     switch (type) {
     case VD_AGENT_CLIPBOARD_UTF8_TEXT:
@@ -920,7 +929,7 @@ bool Platform::on_clipboard_notify(uint32_t type, const uint8_t* data, int32_t s
         break;
     default:
         LOG_INFO("Unsupported clipboard type %u", type);
-        return false;
+        return true;
     }
 
     // Allocate and lock clipboard memory
commit 26814c4f9ca492bab8f11145a4a50cb63c695a7a
Author: Arnon Gilboa <agilboa at redhat.com>
Date:   Mon Oct 4 12:35:06 2010 +0200

    spice-win: remove windows-specific bitmap cut & paste support
    
    will wait until png comes in

diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index 075d269..c875022 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -78,7 +78,6 @@ typedef struct ClipboardFormat {
 
 static ClipboardFormat clipboard_formats[] = {
     {CF_UNICODETEXT, VD_AGENT_CLIPBOARD_UTF8_TEXT},
-    {CF_DIB, VD_AGENT_CLIPBOARD_BITMAP},
     {0, 0}};
 
 static const unsigned long MODAL_LOOP_TIMER_ID = 1;
@@ -919,9 +918,6 @@ bool Platform::on_clipboard_notify(uint32_t type, const uint8_t* data, int32_t s
         clip_len++;
         clip_size = clip_len * sizeof(WCHAR);
         break;
-    case VD_AGENT_CLIPBOARD_BITMAP:
-        clip_size = size;
-        break;
     default:
         LOG_INFO("Unsupported clipboard type %u", type);
         return false;
@@ -942,10 +938,6 @@ bool Platform::on_clipboard_notify(uint32_t type, const uint8_t* data, int32_t s
         ret = !!MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)data, size, (LPWSTR)clip_buf, clip_len);
         ((LPWSTR)clip_buf)[clip_len - 1] = L'\0';
         break;
-    case VD_AGENT_CLIPBOARD_BITMAP:
-        memcpy(clip_buf, data, size);
-        ret = true;
-        break;
     }
     GlobalUnlock(clip_data);
     if (!ret) {
@@ -997,15 +989,6 @@ bool Platform::on_clipboard_request(uint32_t type)
         delete[] (uint8_t *)utf8_data;
         break;
     }
-    case VD_AGENT_CLIPBOARD_BITMAP: {
-        size_t clip_size = GlobalSize(clip_data);
-        if (!clip_size) {
-            break;
-        }
-        clipboard_listener->on_clipboard_notify(type, (uint8_t*)clip_buf, clip_size);
-        ret = true;
-        break;
-    }
     default:
         LOG_INFO("Unsupported clipboard type %u", type);
     }


More information about the Spice-commits mailing list