GNOME Bugzilla – Bug 69883
Change cursor while the pointer is grabbed
Last modified: 2004-12-26 07:34:35 UTC
I can not find any way to change the cursor while the pointer is grabbed in gdk (using gdk_pointer_grab). In X there is a function XChangeActivePointerGrab() that performs this, but it does not seem to be wrapped by gdk. As far as I can tell there is no way to change the cursor. Should this be added to the gdk API?
The gdk cursor api is falling behind the Xlib api in other small ways. E.g it is not possible to create glyph cursors with custom fg/bg colors or to recolor existing cursors (the limitation you found is probably more serious).
You can actually just gdk_pointer_grab() again; I believe that there is no semantic difference between calling GrabPointer again with everything the same except for the fields in ChangeActivePointerGrab and calling ChangeActivePointerGrab, though GrabPointer is a little more expensive since it is a round trip to the server. (ChangeActivePointerGrab has no return code, it just silently does nothing.) As for the other limitations; I dont't think that installing a cursor again is bad awful if you want to change the colors, and in general, I don't want to spend a lot of time mirroring the details of the X cursor API in GDK, since the X cursor API is horribly crude and I suspect will be fixed at some time in the not too distant future.
Calling gdk_pointer_grab() might work, but don't you have to call ungrab once for each grab? Then if you change the cursor depending on the mouse coordinates it can be a lot to ungrab to do in the end. That is not really nice. The documentation does not say if you have to call ungrab once for each grab, if you only have to ungrab once, then it does not sound to bad. If we should talk about API we also lack a way to turn off the cursor. You can create an empty cursor in X, but for other platforms there is actually ways to turn it off. So it might be a good idea to have an API for it.
You don't have to ungrab once for each grab; X grabs are not "recursive" in that fashion.
Owen, from a quick look at the X protocol spec, I think the semantic difference between GrabPointer and ChangeActivePointerGrab is that the former is updating the servers last-pointer-grab time while the latter isn't. But if this can be observed on the client-side other than by getting InvalidTime instead of AlreadyGrabbed errors from failed GrabPointer requests, I can't say for sure.
Oh, and one more difference is that grabbing again may produce additional enter/leave events, I guess...
You are probably right about the updated time. I have a real hard time constructing examples where this would matter. It won't produce extra enter-leave events if the old and new windows are the same. (I checked the X source code earlier on this.)
grabbing again really should work fine --> WONTFIX