How do you hide the mouse pointer under Linux/X11?

前端 未结 10 2088
小蘑菇
小蘑菇 2020-12-05 00:44

How do I hide the mouse pointer under X11? I would like to use the built in libraries in order to do this and not something like SDL (SDL_ShowCursor(0)) or glut (glutSetCur

10条回答
  •  执笔经年
    2020-12-05 00:59

    I ended up using XDefineCursor like ephemient mentioned. The control application changed the default root window cursor and the other applications (which are under my control) inherited it.

    Code specifics look like:

    // Hide the cursor
    
    if (NULL==(display=XOpenDisplay(NULL))) 
    {
       printf("Unable to open NULL display\n");
       exit(1);
    }
    window = DefaultRootWindow(display);
    
    Cursor invisibleCursor;
    Pixmap bitmapNoData;
    XColor black;
    static char noData[] = { 0,0,0,0,0,0,0,0 };
    black.red = black.green = black.blue = 0;
    
    bitmapNoData = XCreateBitmapFromData(display, window, noData, 8, 8);
    invisibleCursor = XCreatePixmapCursor(display, bitmapNoData, bitmapNoData, 
                                         &black, &black, 0, 0);
    XDefineCursor(display,window, invisibleCursor);
    XFreeCursor(display, invisibleCursor);
    XFreePixmap(display, bitmapNoData);
    

    In order to hide the cursor and then after I'm done

    // Restore the X left facing cursor
    Cursor cursor;
    cursor=XCreateFontCursor(display,XC_left_ptr);
    XDefineCursor(display, window, cursor);
    XFreeCursor(display, cursor);
    

    To restore X's left handed cursor (Since it's the root window and I don't want it to stay invisible. I'm not sure, but I might also be able to use

    XUndefineCursor(display, window);
    

提交回复
热议问题