M
M
Maxim Kuprashevich2017-04-19 12:08:05
linux
Maxim Kuprashevich, 2017-04-19 12:08:05

How to change cursor in XCB or XLIB?

dis = XOpenDisplay(0);
    xcb_connection_t *conn = XGetXCBConnection(dis);
    Window window = 0;
    int revert_to;
    XGetInputFocus(dis, &window, &revert_to);

    xcb_cursor_t cursor = 71;
    xcb_change_window_attributes(conn, window, XCB_CW_CURSOR, &cursor);
    xcb_flush(conn);

The test code does not work for some reason, nothing changes.
There is also an example on XLib, but for some reason it only changes the cursor on the first call and no longer wants to:
Cursor cursor;
    Window window = 0;
    int revert_to;
    XGetInputFocus(dis, &window, &revert_to);
    XUndefineCursor(dis, window);

    auto temp_d = XOpenDisplay(0);

    if (dis != temp_d) {
        qDebug() << "Not equal";
        XCloseDisplay(dis);
        dis = temp_d;
    } else {
        XCloseDisplay(temp_d);
    }

    switch (cursorState) {
    case TL:
        cursor = XCreateFontCursor(dis, XC_ul_angle);
        break;
    case BR:
        cursor = XCreateFontCursor(dis, XC_lr_angle);
        break;
    case TR:
        cursor = XCreateFontCursor(dis, XC_ur_angle);
        break;
    case BL:
        cursor = XCreateFontCursor(dis, XC_ll_angle);
        break;
    case B:
        cursor = XCreateFontCursor(dis, XC_bottom_side);
        break;
    case T:
        cursor = XCreateFontCursor(dis, XC_top_side);
        break;
    case L:
        cursor = XCreateFontCursor(dis, XC_left_side);
        break;
    case R:
        cursor = XCreateFontCursor(dis, XC_right_side);
        break;
    case Inside:
        cursor = XCreateFontCursor(dis, XC_X_cursor);
        break;
    default:
        cursor = XCreateFontCursor(dis, XC_arrow);
        break;
    }

    //Cursor c = XcursorLibraryLoadCursor(dis, "sb_v_double_arrow");
    XDefineCursor(dis, window, cursor);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question