src/video/x11/SDL_x11events.c
changeset 7396 a36ab6149a10
parent 7214 5b31583ecf9e
child 7402 235c9aaeefd1
equal deleted inserted replaced
7395:c1b80390a820 7396:a36ab6149a10
   776             printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data,
   776             printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data,
   777                 xevent.xselection.requestor, xevent.xselection.target);
   777                 xevent.xselection.requestor, xevent.xselection.target);
   778 #endif
   778 #endif
   779             Atom target = xevent.xselection.target;
   779             Atom target = xevent.xselection.target;
   780             if (target == data->xdnd_req) {
   780             if (target == data->xdnd_req) {
   781 
       
   782                 /* read data */
   781                 /* read data */
   783                 SDL_x11Prop p;
   782                 SDL_x11Prop p;
   784                 X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY);
   783                 X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY);
   785 
   784 
   786                 if(p.format==8) {
   785                 if (p.format == 8) {
   787                     SDL_bool expect_lf = SDL_FALSE;
   786                     SDL_bool expect_lf = SDL_FALSE;
   788                     char *start = NULL;
   787                     char *start = NULL;
   789                     char *scan = (char*)p.data;
   788                     char *scan = (char*)p.data;
   790                     char *fn;
   789                     char *fn;
   791                     char *uri;
   790                     char *uri;
   792                     int length = 0;
   791                     int length = 0;
   793                     while (p.count--) {
   792                     while (p.count--) {
   794                         if (!expect_lf) {
   793                         if (!expect_lf) {
   795                             if (*scan==0x0D) {
   794                             if (*scan == 0x0D) {
   796                                 expect_lf = SDL_TRUE;
   795                                 expect_lf = SDL_TRUE;
   797                             } else if(start == NULL) {
   796                             }
       
   797                             if (start == NULL) {
   798                                 start = scan;
   798                                 start = scan;
   799                                 length = 0;
   799                                 length = 0;
   800                             }
   800                             }
   801                             length++;
   801                             length++;
   802                         } else {
   802                         } else {
   803                             if (*scan==0x0A && length>0) {
   803                             if (*scan == 0x0A && length > 0) {
   804                                 uri = malloc(length--);
   804                                 uri = SDL_malloc(length--);
   805                                 memcpy(uri, start, length);
   805                                 SDL_memcpy(uri, start, length);
   806                                 uri[length] = 0;
   806                                 uri[length] = '\0';
   807                                 fn = X11_URIToLocal(uri);
   807                                 fn = X11_URIToLocal(uri);
   808                                 if (fn) SDL_SendDropFile(fn);
   808                                 if (fn) {
   809                                 free(uri);
   809                                     SDL_SendDropFile(fn);
       
   810                                 }
       
   811                                 SDL_free(uri);
   810                             }
   812                             }
   811                             expect_lf = SDL_FALSE;
   813                             expect_lf = SDL_FALSE;
   812                             start = NULL;
   814                             start = NULL;
   813                         }
   815                         }
   814                         scan++;
   816                         scan++;
   817 
   819 
   818                 XFree(p.data);
   820                 XFree(p.data);
   819 
   821 
   820                 /* send reply */
   822                 /* send reply */
   821                 XClientMessageEvent m;
   823                 XClientMessageEvent m;
   822                 memset(&m, 0, sizeof(XClientMessageEvent));
   824                 SDL_memset(&m, 0, sizeof(XClientMessageEvent));
   823                 m.type = ClientMessage;
   825                 m.type = ClientMessage;
   824                 m.display = display;
   826                 m.display = display;
   825                 m.window = data->xdnd_source;
   827                 m.window = data->xdnd_source;
   826                 m.message_type = videodata->XdndFinished;
   828                 m.message_type = videodata->XdndFinished;
   827                 m.format=32;
   829                 m.format = 32;
   828                 m.data.l[0] = data->xwindow;
   830                 m.data.l[0] = data->xwindow;
   829                 m.data.l[1] = 1;
   831                 m.data.l[1] = 1;
   830                 m.data.l[2] = videodata->XdndActionCopy;
   832                 m.data.l[2] = videodata->XdndActionCopy;
   831                 XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m);
   833                 XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m);
   832 
   834 
   833                 XSync(display, False);
   835                 XSync(display, False);
   834 
   836 
   835             } else {
   837             } else {
   836                 videodata->selection_waiting = SDL_FALSE;
   838                 videodata->selection_waiting = SDL_FALSE;
   837             }
   839             }
   838 
       
   839         }
   840         }
   840         break;
   841         break;
   841 
   842 
   842     default:{
   843     default:{
   843 #ifdef DEBUG_XEVENTS
   844 #ifdef DEBUG_XEVENTS