Drag and Drop on X11?

Hey all,

I’m working adding drog and drop plus cut and paste to Cpw for the 2.0 release. I’m familiar with Windows methods for doing this but don’t know much about x11. From what I’ve read the functionality for drag and drop and cut and paste varies for each desktop environment. Curious if some X11 guru out there can give me opinions on a system I’ve come up with.

I’m fiddling with something that looks like this:

Registering for drag & drop and cut & paste:

cpwDragDropCallback( pCpw cpw,
CpwDropCallback ddcb );

The callback receives an object list pointer, and a window id as such:

CpwDragDropCallback ( pCpw cpw,
uint_32 winid,
bool in_out,
CpwDDList * list );

where in_out indicates if this a drop/paste (in) or drag/cut (out).

Here’s the list:

struct _CpwDDList
CpwDDObject* objs;
uint_32 listLength;

and here’s an object which holds or receives data :

struct _CpwDDObject
pChar mimeType;
puChar extendedInfo;
pVoid data;
uint_32 dataLength;

There would be some utility routines for creating objects and inserting them into a
DD list object.

A simple text paste object would look like this:

obj.mimeType = “text/plain”
obj.extendedInfo = “”
obj.data = “Hello!”
obj.dataLength = 6

A paste of a tga file would look something like this, where the data is left to
the user to read in:

obj.mimeType = “image/tga”
obj.extendedInfo = “/dir/dir/roadster.tga”
obj.data = 0
obj.dataLength = 0

I’m curious if people think this type of system will work under X11?


Note, I looked at Qt’s docs in coming up with this:

If you look at the bottom of those QT docs
you’ll see it mentions they use the XDND
protocol on X11, but the link is bad.
This link works though.


By the way, I’m also still looking ideas on
how to sneak XDND events into the GLUT event
loop. Yeah, yeah, I know. GLUT is dead and
all that…

Hey thanks for the link. That helps. Good
luck on Modifying the GLUT source. I’ve
spent a great deal of time digging through
that code base - it is not much fun.
If you work up a patch please let me know
and I’ll add it to the Gl Toolkits FAQ.


Actually I was hoping to accomplish it
without a patch. I managed to pull it off
in Windows without patching glut. I was
kind of hoping for a similar clever hack
for X11. Something along the lines of
XCheckTypedEvent() in the glut callbacks
to grab the XDND events before glut throws
them away. Where are those gurus when you
need them.

For the X11 case you may find this useful!

You can register a callback which will parse any un-handled Xevents …

I was going to use this to handle the new window manager close event callback , but unfortunately the glut event loop already processed this and so I could not use this without modifying the code!

[I too looked to see if the new functionality could be added without changing code … almost!]

In glut_event.c

__glutRegisterEventParser(GLUTeventParser * parser)
parser->next = eventParserList;
eventParserList = parser;


Yeah! That could possibly do it. Thanks!
That’s not documented anywhere besides in
the glut code itself, is it? I don’t know
why I didn’t think of examining the code
myself. I’ll have a look at it now though.

Is there a similar function for registering
an additional eventMask? Actually I don’t
even know if it’s needed. It’s been a while
since I did much of anything at the xlib

I peeked at the code and it looks like
glut discards any ClientMessage that isn’t
a __glutWMDeleteWindow, so XDND isn’t going
to work via __glutRegisterEventParser
either withoug modifying glut. Oh well.

ooops … forgot that dnd were client msgs!

You’ll have to trap them.

As a start my code which registers the new callback for close window client msg may be a good start (like all the code is there, just add a new member to the window struct and a couple of other bits and bobs, and there you go!)

Check the code at (get the directory contents)

Hope it helps,