[Spice-devel] [PATCH spice 05/17] Change VD_AGENT_CLIPBOARD_GRAB to an array of types

Hans de Goede hdegoede at redhat.com
Mon Oct 4 03:34:56 PDT 2010


A clipboard owner can indicate that it can supply the data the clipboard
owns in multiple formats, so make the data passed with a
VD_AGENT_CLIPBOARD_GRAB message an array of types rather then a single
type.
---
 client/platform.h           |    4 ++--
 client/red_client.cpp       |   10 +++++-----
 client/red_client.h         |   17 ++++++++++++++---
 client/windows/platform.cpp |   11 ++++++-----
 client/x11/platform.cpp     |   12 +++++++-----
 5 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/client/platform.h b/client/platform.h
index 4727889..48476cf 100644
--- a/client/platform.h
+++ b/client/platform.h
@@ -121,7 +121,7 @@ public:
     class ClipboardListener;
     static void set_clipboard_listener(ClipboardListener* listener);
 
-    static bool set_clipboard_owner(uint32_t type);
+    static bool set_clipboard_owner(uint32_t *types, uint32_t type_count);
     static bool set_clipboard_data(uint32_t type, const uint8_t* data, int32_t size);
     static bool request_clipboard_notification(uint32_t type);
     static void release_clipboard();
@@ -138,7 +138,7 @@ public:
 class Platform::ClipboardListener {
 public:
     virtual ~ClipboardListener() {}
-    virtual void on_clipboard_grab(uint32_t type) = 0;
+    virtual void on_clipboard_grab(uint32_t *types, uint32_t type_count) = 0;
     virtual void on_clipboard_request(uint32_t type) = 0;
     virtual void on_clipboard_notify(uint32_t type, uint8_t* data, int32_t size) = 0;
 };
diff --git a/client/red_client.cpp b/client/red_client.cpp
index 562b826..e351900 100644
--- a/client/red_client.cpp
+++ b/client/red_client.cpp
@@ -83,9 +83,8 @@ uint32_t default_agent_caps[] = {
 
 void ClipboardGrabEvent::response(AbstractProcessLoop& events_loop)
 {
-    VDAgentClipboardGrab grab = {_type};
     static_cast<RedClient*>(events_loop.get_owner())->send_agent_clipboard_message(
-        VD_AGENT_CLIPBOARD_GRAB, sizeof(grab), &grab);
+        VD_AGENT_CLIPBOARD_GRAB, _type_count * sizeof(uint32_t), _types);
 }
 
 void ClipboardRequestEvent::response(AbstractProcessLoop& events_loop)
@@ -834,13 +833,13 @@ void RedClient::send_agent_clipboard_message(uint32_t message_type, uint32_t siz
     post_message(message);
 }
 
-void RedClient::on_clipboard_grab(uint32_t type)
+void RedClient::on_clipboard_grab(uint32_t *types, uint32_t type_count)
 {
     if (!_agent_caps || !VD_AGENT_HAS_CAPABILITY(_agent_caps, _agent_caps_size,
                                                  VD_AGENT_CAP_CLIPBOARD_BY_DEMAND)) {
         return;
     }
-    AutoRef<ClipboardGrabEvent> event(new ClipboardGrabEvent(type));
+    AutoRef<ClipboardGrabEvent> event(new ClipboardGrabEvent(types, type_count));
     get_process_loop().push_event(*event);
 }
 
@@ -1091,7 +1090,8 @@ void RedClient::dispatch_agent_message(VDAgentMessage* msg, void* data)
         break;
     }
     case VD_AGENT_CLIPBOARD_GRAB:
-        Platform::set_clipboard_owner(((VDAgentClipboardGrab*)data)->type);
+        Platform::set_clipboard_owner((uint32_t *)data,
+                                      msg->size / sizeof(uint32_t));
         break;
     case VD_AGENT_CLIPBOARD_REQUEST:
         if (!Platform::request_clipboard_notification(((VDAgentClipboardRequest*)data)->type)) {
diff --git a/client/red_client.h b/client/red_client.h
index 3ccb8e3..2cfce49 100644
--- a/client/red_client.h
+++ b/client/red_client.h
@@ -146,11 +146,22 @@ public:
 
 class ClipboardGrabEvent : public Event {
 public:
-    ClipboardGrabEvent(uint32_t type) : _type (type) {}
+    ClipboardGrabEvent(uint32_t *types, uint32_t type_count)
+    {
+        _types = new uint32_t [type_count];
+        memcpy(_types, types, type_count * sizeof(uint32_t));
+        _type_count = type_count;
+    }
+    ~ClipboardGrabEvent()
+    {
+        delete[] _types;
+    }
+
     virtual void response(AbstractProcessLoop& events_loop);
 
 private:
-    uint32_t _type;
+    uint32_t *_types;
+    uint32_t _type_count;
 };
 
 class ClipboardRequestEvent : public Event {
@@ -207,7 +218,7 @@ public:
     PixmapCache& get_pixmap_cache() {return _pixmap_cache;}
     uint64_t get_pixmap_cache_size() { return _pixmap_cache_size;}
     void on_display_mode_change();
-    void on_clipboard_grab(uint32_t type);
+    void on_clipboard_grab(uint32_t *types, uint32_t type_count);
     void on_clipboard_request(uint32_t type);
     void on_clipboard_notify(uint32_t type, uint8_t* data, int32_t size);
 
diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index 95876dc..2a62944 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -51,7 +51,7 @@ static ProcessLoop* main_loop = NULL;
 
 class DefaultClipboardListener: public Platform::ClipboardListener {
 public:
-    virtual void on_clipboard_grab(uint32_t type) {}
+    virtual void on_clipboard_grab(uint32_t *types, uint32_t type_count) {}
     virtual void on_clipboard_request(uint32_t type) {}
     virtual void on_clipboard_notify(uint32_t type, uint8_t* data, int32_t size) {}
 };
@@ -151,7 +151,7 @@ static LRESULT CALLBACK PlatformWinProc(HWND hWnd, UINT message, WPARAM wParam,
         if (!clipboard_changer) {
             uint32_t type = get_available_clipboard_type();            
             if (type) {
-                clipboard_listener->on_clipboard_grab(type);
+                clipboard_listener->on_clipboard_grab(&type, 1);
             } else {
                 LOG_INFO("Unsupported clipboard format");
             }
@@ -856,12 +856,13 @@ void WinPlatform::exit_modal_loop()
     modal_loop_active = false;
 }
 
-bool Platform::set_clipboard_owner(uint32_t type)
+bool Platform::set_clipboard_owner(uint32_t *types, uint32_t type_count)
 {
-    uint32_t format = get_clipboard_format(type);
+    /* 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", type);
+        LOG_INFO("Unsupported clipboard type %u", types[0]);
         return false;
     }
     if (!OpenClipboard(platform_win)) {
diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index 8f4ed2d..6627187 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -151,7 +151,7 @@ static Platform::DisplayModeListener* display_mode_listener = &default_display_m
 
 class DefaultClipboardListener: public Platform::ClipboardListener {
 public:
-    void on_clipboard_grab(uint32_t type) {}
+    void on_clipboard_grab(uint32_t *types, uint32_t type_count) {}
     void on_clipboard_request(uint32_t type) {}
     void on_clipboard_notify(uint32_t type, uint8_t* data, int32_t size) {}
 };
@@ -2392,7 +2392,8 @@ static void root_win_proc(XEvent& event)
             return;
         }
         // FIXME: use actual type
-        clipboard_listener->on_clipboard_grab(VD_AGENT_CLIPBOARD_UTF8_TEXT);
+        uint32_t type = VD_AGENT_CLIPBOARD_UTF8_TEXT;
+        clipboard_listener->on_clipboard_grab(&type, 1);
         return;
     }
     switch (event.type) {
@@ -3144,13 +3145,14 @@ LocalCursor* Platform::create_default_cursor()
     return new XDefaultCursor();
 }
 
-bool Platform::set_clipboard_owner(uint32_t type)
+bool Platform::set_clipboard_owner(uint32_t *types, uint32_t type_count)
 {
     Lock lock(clipboard_lock);
-    uint32_t format = get_clipboard_format(type);
+    /* 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", type);
+        LOG_INFO("Unsupported clipboard type %u", types[0]);
         return false;
     }
     clipboard_changer = true;
-- 
1.7.2.2



More information about the Spice-devel mailing list