Beispiel #1
0
static GLboolean initDisplay(void)
{
    Bool supported;

    _glfw.x11.display = XOpenDisplay(NULL);
    if (!_glfw.x11.display)
    {
        _glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display");
        return GL_FALSE;
    }

    // As the API currently doesn't understand multiple display devices, we hard-code
    // this choice and hope for the best
    _glfw.x11.screen = DefaultScreen(_glfw.x11.display);
    _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen);

    // Find or create window manager atoms
    _glfw.x11.WM_STATE = XInternAtom(_glfw.x11.display, "WM_STATE", False);
    _glfw.x11.WM_DELETE_WINDOW = XInternAtom(_glfw.x11.display,
                                             "WM_DELETE_WINDOW",
                                             False);

    // Check for XF86VidMode extension
    _glfw.x11.vidmode.available =
        XF86VidModeQueryExtension(_glfw.x11.display,
                                  &_glfw.x11.vidmode.eventBase,
                                  &_glfw.x11.vidmode.errorBase);

    // Check for RandR extension
    _glfw.x11.randr.available =
        XRRQueryExtension(_glfw.x11.display,
                          &_glfw.x11.randr.eventBase,
                          &_glfw.x11.randr.errorBase);

    if (_glfw.x11.randr.available)
    {
        if (!XRRQueryVersion(_glfw.x11.display,
                             &_glfw.x11.randr.versionMajor,
                             &_glfw.x11.randr.versionMinor))
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Failed to query RandR version");
            return GL_FALSE;
        }

        // The GLFW RandR path requires at least version 1.3
        if (_glfw.x11.randr.versionMajor == 1 &&
            _glfw.x11.randr.versionMinor < 3)
        {
            _glfw.x11.randr.available = GL_FALSE;
        }
    }

    // Check if Xkb is supported on this display
    _glfw.x11.xkb.versionMajor = 1;
    _glfw.x11.xkb.versionMinor = 0;
    if (!XkbQueryExtension(_glfw.x11.display,
                           &_glfw.x11.xkb.majorOpcode,
                           &_glfw.x11.xkb.eventBase,
                           &_glfw.x11.xkb.errorBase,
                           &_glfw.x11.xkb.versionMajor,
                           &_glfw.x11.xkb.versionMinor))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "X11: The keyboard extension is not available");
        return GL_FALSE;
    }

    XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported);
    if (!supported)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "X11: Detectable key repeat is not available");
        return GL_FALSE;
    }

    // Update the key code LUT
    // FIXME: We should listen to XkbMapNotify events to track changes to
    // the keyboard mapping.
    updateKeyCodeLUT();

    // Detect whether an EWMH-conformant window manager is running
    detectEWMH();

    // Find or create string format atoms
    _glfw.x11.UTF8_STRING =
        XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
    _glfw.x11.COMPOUND_STRING =
        XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False);

    // Find or create selection property atom
    _glfw.x11.selection.property =
        XInternAtom(_glfw.x11.display, "GLFW_SELECTION", False);

    // Find or create standard clipboard atoms
    _glfw.x11.TARGETS = XInternAtom(_glfw.x11.display, "TARGETS", False);
    _glfw.x11.CLIPBOARD = XInternAtom(_glfw.x11.display, "CLIPBOARD", False);

    // Find or create selection target atoms
    _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] =
        _glfw.x11.UTF8_STRING;
    _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] =
        _glfw.x11.COMPOUND_STRING;
    _glfw.x11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] =
        XA_STRING;

    return GL_TRUE;
}
Beispiel #2
0
// Initialize X11 display and look for supported X11 extensions
//
static GLboolean initExtensions(void)
{
    Bool supported;

    // Find or create window manager atoms
    _glfw.x11.WM_STATE = XInternAtom(_glfw.x11.display, "WM_STATE", False);
    _glfw.x11.WM_DELETE_WINDOW = XInternAtom(_glfw.x11.display,
                                             "WM_DELETE_WINDOW",
                                             False);
    _glfw.x11.MOTIF_WM_HINTS = XInternAtom(_glfw.x11.display,
                                           "_MOTIF_WM_HINTS",
                                           False);

    // Check for XF86VidMode extension
    _glfw.x11.vidmode.available =
        XF86VidModeQueryExtension(_glfw.x11.display,
                                  &_glfw.x11.vidmode.eventBase,
                                  &_glfw.x11.vidmode.errorBase);

    // Check for RandR extension
    _glfw.x11.randr.available =
        XRRQueryExtension(_glfw.x11.display,
                          &_glfw.x11.randr.eventBase,
                          &_glfw.x11.randr.errorBase);

    if (_glfw.x11.randr.available)
    {
        if (!XRRQueryVersion(_glfw.x11.display,
                             &_glfw.x11.randr.versionMajor,
                             &_glfw.x11.randr.versionMinor))
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "X11: Failed to query RandR version");
            return GL_FALSE;
        }

        // The GLFW RandR path requires at least version 1.3
        if (_glfw.x11.randr.versionMajor == 1 &&
            _glfw.x11.randr.versionMinor < 3)
        {
            _glfw.x11.randr.available = GL_FALSE;
        }
    }

    if (XQueryExtension(_glfw.x11.display,
                        "XInputExtension",
                        &_glfw.x11.xi.majorOpcode,
                        &_glfw.x11.xi.eventBase,
                        &_glfw.x11.xi.errorBase))
    {
        _glfw.x11.xi.versionMajor = 2;
        _glfw.x11.xi.versionMinor = 0;

        if (XIQueryVersion(_glfw.x11.display,
                           &_glfw.x11.xi.versionMajor,
                           &_glfw.x11.xi.versionMinor) != BadRequest)
        {
            _glfw.x11.xi.available = GL_TRUE;
        }
    }

    // Check if Xkb is supported on this display
    _glfw.x11.xkb.versionMajor = 1;
    _glfw.x11.xkb.versionMinor = 0;
    if (!XkbQueryExtension(_glfw.x11.display,
                           &_glfw.x11.xkb.majorOpcode,
                           &_glfw.x11.xkb.eventBase,
                           &_glfw.x11.xkb.errorBase,
                           &_glfw.x11.xkb.versionMajor,
                           &_glfw.x11.xkb.versionMinor))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "X11: The keyboard extension is not available");
        return GL_FALSE;
    }

    if (!XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "X11: Failed to set detectable key repeat");
        return GL_FALSE;
    }

    if (!supported)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "X11: Detectable key repeat is not supported");
        return GL_FALSE;
    }

    // Update the key code LUT
    // FIXME: We should listen to XkbMapNotify events to track changes to
    // the keyboard mapping.
    updateKeyCodeLUT();

    // Detect whether an EWMH-conformant window manager is running
    detectEWMH();

    // Find or create string format atoms
    _glfw.x11.UTF8_STRING =
        XInternAtom(_glfw.x11.display, "UTF8_STRING", False);
    _glfw.x11.COMPOUND_STRING =
        XInternAtom(_glfw.x11.display, "COMPOUND_STRING", False);
    _glfw.x11.ATOM_PAIR = XInternAtom(_glfw.x11.display, "ATOM_PAIR", False);

    // Find or create selection property atom
    _glfw.x11.GLFW_SELECTION =
        XInternAtom(_glfw.x11.display, "GLFW_SELECTION", False);

    // Find or create standard clipboard atoms
    _glfw.x11.TARGETS = XInternAtom(_glfw.x11.display, "TARGETS", False);
    _glfw.x11.MULTIPLE = XInternAtom(_glfw.x11.display, "MULTIPLE", False);
    _glfw.x11.CLIPBOARD = XInternAtom(_glfw.x11.display, "CLIPBOARD", False);

    // Find or create clipboard manager atoms
    _glfw.x11.CLIPBOARD_MANAGER =
        XInternAtom(_glfw.x11.display, "CLIPBOARD_MANAGER", False);
    _glfw.x11.SAVE_TARGETS =
        XInternAtom(_glfw.x11.display, "SAVE_TARGETS", False);

    return GL_TRUE;
}
Beispiel #3
0
static GLboolean initDisplay(void)
{
    _glfwLibrary.X11.display = XOpenDisplay(NULL);
    if (!_glfwLibrary.X11.display)
    {
        _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display");
        return GL_FALSE;
    }

    // As the API currently doesn't understand multiple display devices, we hard-code
    // this choice and hope for the best
    _glfwLibrary.X11.screen = DefaultScreen(_glfwLibrary.X11.display);
    _glfwLibrary.X11.root = RootWindow(_glfwLibrary.X11.display,
                                       _glfwLibrary.X11.screen);

    // Check for XF86VidMode extension
#ifdef _GLFW_HAS_XF86VIDMODE
    _glfwLibrary.X11.VidMode.available =
        XF86VidModeQueryExtension(_glfwLibrary.X11.display,
                                  &_glfwLibrary.X11.VidMode.eventBase,
                                  &_glfwLibrary.X11.VidMode.errorBase);
#else
    _glfwLibrary.X11.VidMode.available = GL_FALSE;
#endif /*_GLFW_HAS_XF86VIDMODE*/

    // Check for XRandR extension
#ifdef _GLFW_HAS_XRANDR
    _glfwLibrary.X11.RandR.available =
        XRRQueryExtension(_glfwLibrary.X11.display,
                          &_glfwLibrary.X11.RandR.eventBase,
                          &_glfwLibrary.X11.RandR.errorBase);

    if (_glfwLibrary.X11.RandR.available)
    {
        if (!XRRQueryVersion(_glfwLibrary.X11.display,
                             &_glfwLibrary.X11.RandR.majorVersion,
                             &_glfwLibrary.X11.RandR.minorVersion))
        {
            _glfwSetError(GLFW_PLATFORM_ERROR,
                          "X11/GLX: Failed to query RandR version");
            return GL_FALSE;
        }
    }
#else
    _glfwLibrary.X11.RandR.available = GL_FALSE;
#endif /*_GLFW_HAS_XRANDR*/

    // Check if GLX is supported on this display
    if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
    {
        _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found");
        return GL_FALSE;
    }

    if (!glXQueryVersion(_glfwLibrary.X11.display,
                         &_glfwLibrary.GLX.majorVersion,
                         &_glfwLibrary.GLX.minorVersion))
    {
        _glfwSetError(GLFW_OPENGL_UNAVAILABLE,
                      "X11/GLX: Failed to query GLX version");
        return GL_FALSE;
    }

    // Check if Xkb is supported on this display
#if defined(_GLFW_HAS_XKB)
    _glfwLibrary.X11.Xkb.majorVersion = 1;
    _glfwLibrary.X11.Xkb.minorVersion = 0;
    _glfwLibrary.X11.Xkb.available =
        XkbQueryExtension(_glfwLibrary.X11.display,
                          &_glfwLibrary.X11.Xkb.majorOpcode,
                          &_glfwLibrary.X11.Xkb.eventBase,
                          &_glfwLibrary.X11.Xkb.errorBase,
                          &_glfwLibrary.X11.Xkb.majorVersion,
                          &_glfwLibrary.X11.Xkb.minorVersion);
#else
    _glfwLibrary.X11.Xkb.available = GL_FALSE;
#endif /* _GLFW_HAS_XKB */

    // Update the key code LUT
    // FIXME: We should listen to XkbMapNotify events to track changes to
    // the keyboard mapping.
    updateKeyCodeLUT();

    // Find or create selection property atom
    _glfwLibrary.X11.selection.property =
        XInternAtom(_glfwLibrary.X11.display, "GLFW_SELECTION", False);

    // Find or create clipboard atom
    _glfwLibrary.X11.selection.atom =
        XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False);

    // Find or create selection target atoms
    _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] =
        XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False);
    _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] =
        XInternAtom(_glfwLibrary.X11.display, "COMPOUND_STRING", False);
    _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] =
        XA_STRING;

    _glfwLibrary.X11.selection.targets = XInternAtom(_glfwLibrary.X11.display,
                                         "TARGETS",
                                         False);

    return GL_TRUE;
}