Different cursors for multiple pointers?

Peter Hutterer peter.hutterer at who-t.net
Wed Nov 18 15:43:15 PST 2009


On Wed, Nov 18, 2009 at 01:36:56PM +0100, Florian Echtler wrote:
> Hello Peter,
> 
> > > when using multiple pointers through XI2, is there a way to set an 
> > > individual cursor image for each pointer (globally)? If so, how?
> > XIDefineCursor on the root window, there's no server flag for this though.
> > it's not really a global setting either, it'll get overridden by
> > locally-defined cursors, pretty much in the same manner as normal cursors.
> thanks for your help. I've quickly ripped some code from libXcursor and
> hacked together a small tool to try this, however, it doesn't seem to
> have any effect. The load() routine seems to create a correct cursor ID,
> and XIDefineCursor returns 0. Is this a feature which may be missing
> from my graphics driver (I'm using radeon), or is this rather overridden
> by my desktop environment?

try it on a self-created window, I noticed that my DE got in the way when
trying to set the cursor on the root window (or just start without a DE for
testing). The code itself looks ok and should work though I couldn't test it
- i seem to the lack the png library needed.

i'll attach a simple test program that I've used to debug a few things, I
just verified it works correctly. (argv[1] must be the pointer ID of the
master pointer to change).

Cheers,
  Peter

PS: boat cursor ftw!
-------------- next part --------------
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<X11/X.h>
#include<X11/Xlib.h>
#include<X11/Xcursor/Xcursor.h>
#include<X11/cursorfont.h>
#include<X11/extensions/XInput2.h>
#include<assert.h>

int width;
int height;

int main(int argc, char** argv)
{
    Display* dpy;
    Window win;
    XSetWindowAttributes attr;
    Cursor cursor;
    int x = 100, y = 100;
    char *theme;

    width = height = 200;

    dpy = XOpenDisplay(NULL);

    assert(dpy != NULL);

    win = XCreateSimpleWindow(dpy, RootWindow(dpy, 0), x, y, width, height, 0, 0, WhitePixel(dpy, 0));

    attr.event_mask = ExposureMask | StructureNotifyMask;

    XChangeWindowAttributes(dpy, win, CWEventMask, &attr);
    XMapWindow(dpy, win);
    XFlush(dpy);

    theme = XcursorGetTheme(dpy);
    printf("theme is %s\n", theme);

    cursor = XcursorShapeLoadCursor(dpy, XC_boat);
    XDefineCursor(dpy, win, cursor);
    cursor = XcursorShapeLoadCursor(dpy, XC_coffee_mug);
    XIDefineCursor(dpy, atoi(argv[1]), win, cursor);
    XSelectInput(dpy, win, ButtonPressMask);
    XFlush(dpy);


    sleep(5);
    XIUndefineCursor(dpy, atoi(argv[1]), win);
    XIDefineCursor(dpy, atoi(argv[1]), win, cursor);
    XFlush(dpy);
    printf("now\n");

    while(1) {
        XEvent ev;
        XNextEvent(dpy, &ev);

        if (ev.type == ButtonPress)
        {
            printf("now\n");
            XIUndefineCursor(dpy, atoi(argv[1]), win);
        }

    }

    XCloseDisplay(dpy);
    return 0;
}



More information about the xorg mailing list