raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
22.02k stars 2.22k forks source link

[rcore] X11: Standard cursor shape unavailable #3663

Closed japajoe closed 8 months ago

japajoe commented 9 months ago

I was playing around with rlImGui and noticed following error while moving the mouse over a resize handle:

WARNING: GLFW: Error: 65547 Description: X11: Standard cursor shape unavailable

Now I understand this probably is not in an issue for those who don't use rlImGui, but it would be nice if a fix for this could be implemented. I got around the error by making some adjustments to x11_window.c.

GLFWbool _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape)
{
    if (_glfw.x11.xcursor.handle)
    {
        char* theme = XcursorGetTheme(_glfw.x11.display);
        if (theme)
        {
            const int size = XcursorGetDefaultSize(_glfw.x11.display);
            const char* name = NULL;

            switch (shape)
            {
                case GLFW_ARROW_CURSOR:
                    name = "default";
                    break;
                case GLFW_IBEAM_CURSOR:
                    name = "text";
                    break;
                case GLFW_CROSSHAIR_CURSOR:
                    name = "crosshair";
                    break;
                case GLFW_POINTING_HAND_CURSOR:
                    name = "pointer";
                    break;
                case GLFW_RESIZE_EW_CURSOR:
                    name = "ew-resize";
                    break;
                case GLFW_RESIZE_NS_CURSOR:
                    name = "ns-resize";
                    break;
                case GLFW_RESIZE_NWSE_CURSOR:
                    name = "nwse-resize";
                    break;
                case GLFW_RESIZE_NESW_CURSOR:
                    name = "nesw-resize";
                    break;
                case GLFW_RESIZE_ALL_CURSOR:
                    name = "all-scroll";
                    break;
                case GLFW_NOT_ALLOWED_CURSOR:
                    name = "not-allowed";
                    break;
            }

            XcursorImage* image = XcursorLibraryLoadImage(name, theme, size);
            if (image)
            {
                cursor->x11.handle = XcursorImageLoadCursor(_glfw.x11.display, image);
                XcursorImageDestroy(image);
            }
        }
    }

    if (!cursor->x11.handle)
    {
        unsigned int native = 0;

        switch (shape)
        {
            case GLFW_ARROW_CURSOR:
                native = XC_left_ptr;
                break;
            case GLFW_IBEAM_CURSOR:
                native = XC_xterm;
                break;
            case GLFW_CROSSHAIR_CURSOR:
                native = XC_crosshair;
                break;
            case GLFW_POINTING_HAND_CURSOR:
                native = XC_hand2;
                break;
            case GLFW_RESIZE_EW_CURSOR:
                native = XC_sb_h_double_arrow;
                break;
            case GLFW_RESIZE_NS_CURSOR:
                native = XC_sb_v_double_arrow;
                break;
            case GLFW_RESIZE_NWSE_CURSOR: //Added this case
                native = XC_left_ptr;
                break;
            case GLFW_RESIZE_NESW_CURSOR: //Added this case
                native = XC_left_ptr;
                break;
            case GLFW_RESIZE_ALL_CURSOR:
                native = XC_fleur;
                break;
            default:
                _glfwInputError(GLFW_CURSOR_UNAVAILABLE,
                                "X11: Standard cursor shape unavailable");
                return GLFW_FALSE;
        }

        cursor->x11.handle = XCreateFontCursor(_glfw.x11.display, native);
        if (!cursor->x11.handle)
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Failed to create standard cursor");
            return GLFW_FALSE;
        }
    }

    return GLFW_TRUE;
}

Since I am on Linux I can't say if this error occurs on other platforms but maybe someone else can?

raysan5 commented 9 months ago

@japajoe It seems this issue is related to GLFW, not raylib, it should be reported to glfw project.