Fix revision: 18690, bug #17850
authorDiego Borghetti <bdiego@gmail.com>
Fri, 30 Jan 2009 21:01:18 +0000 (21:01 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Fri, 30 Jan 2009 21:01:18 +0000 (21:01 +0000)
The problem was that Qt convert the text to the type
STRING or UTF8, that is why Blender can't get the text,
now should be work fine.

intern/ghost/intern/GHOST_SystemX11.cpp

index 9950ef8887976806be71ef5c9c0ff595be064143..02dfdc2e25ca49cf9c4961bf3a87012a523c992d 100644 (file)
@@ -981,11 +981,11 @@ getClipboard(int flag
 ) const {
        //Flag 
        //0 = Regular clipboard 1 = selection
-       static Atom Primary_atom, clip_String, compound_text;
+       static Atom Primary_atom, clip_String, compound_text, a_text, a_string;
        Atom rtype;
        Window m_window, owner;
        unsigned char *data, *tmp_data;
-       int bits;
+       int bits, count;
        unsigned long len, bytes;
        XEvent xevent;
        
@@ -996,6 +996,8 @@ getClipboard(int flag
 
        clip_String = XInternAtom(m_display, "_BLENDER_STRING", False);
        compound_text = XInternAtom(m_display, "COMPOUND_TEXT", False);
+       a_text= XInternAtom(m_display, "TEXT", False);
+       a_string= XInternAtom(m_display, "STRING", False);
 
        //lets check the owner and if it is us then return the static buffer
        if(flag == 0) {
@@ -1029,23 +1031,46 @@ getClipboard(int flag
        XFlush(m_display);
 
        //This needs to change so we do not wait for ever or check owner first
+       count= 1;
        while(1) {
                XNextEvent(m_display, &xevent);
-               if(xevent.type == SelectionNotify) { 
-                       if (xevent.xselection.property ) { /* eric4 on linux gives zero Atom xevent.xselection.property value, closes blender instantly */
+               if(xevent.type == SelectionNotify) {
+                       if (xevent.xselection.property == None) {
+                               /* Ok, the client can't convert the property
+                                * to some that we can handle, try other types..
+                                */
+                               if (count == 1) {
+                                       XConvertSelection(m_display, Primary_atom, a_text, clip_String, m_window, CurrentTime);
+                                       count++;
+                               }
+                               else if (count == 2) {
+                                       XConvertSelection(m_display, Primary_atom, a_string, clip_String, m_window, CurrentTime);
+                                       count++;
+                               }
+                               else {
+                                       /* Ok, the owner of the selection can't 
+                                        * convert the data to something that we can
+                                        * handle.
+                                        */
+                                       return(NULL);
+                               }
+                       }
+                       else {
                                if(XGetWindowProperty(m_display, m_window, xevent.xselection.property , 0L, 4096L, False, AnyPropertyType, &rtype, &bits, &len, &bytes, &data) == Success) {
                                        if (data) {
-                                               tmp_data = (unsigned char*) malloc(strlen((char*)data)+1);
-                                               strcpy((char*)tmp_data, (char*)data);
+                                               if (bits == 8 && (rtype == compound_text || rtype == a_text || rtype == a_string)) {
+                                                       tmp_data = (unsigned char*) malloc(strlen((char*)data)+1);
+                                                       strcpy((char*)tmp_data, (char*)data);
+                                               }
+                                               else
+                                                       tmp_data= NULL;
+
                                                XFree(data);
                                                return (GHOST_TUns8*)tmp_data;
                                        }
                                }
+                               return(NULL);
                        }
-                       else {
-                               fprintf(stderr, "error: cut buffer had a zero xevent.xselection.property, FIXME\n"); // XXX fix this problem!
-                       }
-                       return NULL;
                }
        }
 }