This commit is contained in:
pknowles 2026-09-25 14:13:31 -07:00 • committed by GitHub
commit 54e54104fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 131 additions and 2 deletions

View file

@ -2307,6 +2307,7 @@ PREDEFINED = GLFWAPI= \
GLFW_EXPOSE_NATIVE_WIN32 \
GLFW_EXPOSE_NATIVE_WGL \
GLFW_EXPOSE_NATIVE_X11 \
GLFW_EXPOSE_NATIVE_XCB \
GLFW_EXPOSE_NATIVE_WAYLAND \
GLFW_EXPOSE_NATIVE_GLX \
GLFW_EXPOSE_NATIVE_COCOA \

View file

@ -61,6 +61,7 @@ extern "C" {
* * `GLFW_EXPOSE_NATIVE_WIN32`
* * `GLFW_EXPOSE_NATIVE_COCOA`
* * `GLFW_EXPOSE_NATIVE_X11`
* * `GLFW_EXPOSE_NATIVE_XCB`
* * `GLFW_EXPOSE_NATIVE_WAYLAND`
*
* The available context API macros are:
@ -119,6 +120,10 @@ extern "C" {
#include <X11/extensions/Xrandr.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_XCB)
#include <xcb/xcb.h>
#endif
#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
#include <wayland-client.h>
#endif
@ -444,6 +449,72 @@ GLFWAPI void glfwSetX11SelectionString(const char* string);
GLFWAPI const char* glfwGetX11SelectionString(void);
#endif
#if defined(GLFW_EXPOSE_NATIVE_XCB)
/*! @brief Returns the `xcb_connection_t` used by GLFW.
*
* @return The `xcb_connection_t` used by GLFW, or `NULL` if an
* [error](@ref error_handling) occurred.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_UNAVAILABLE, @ref GLFW_FEATURE_UNAVAILABLE and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark This function requires the X11-xcb library, which GLFW loads during
* initialization only if the
* [GLFW_X11_XCB_VULKAN_SURFACE](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint) init
* hint is set, as it is by default. If the library or its `XGetXCBConnection`
* function is not available, this function emits @ref
* GLFW_FEATURE_UNAVAILABLE.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.6.
*
* @ingroup native
*/
GLFWAPI xcb_connection_t* glfwGetXCBConnection(void);
/*! @brief Returns the `xcb_visualid_t` of the default visual of the screen.
*
* Windows created with the [GLFW_CLIENT_API](@ref GLFW_CLIENT_API_hint) hint
* set to `GLFW_NO_API` use this visual, and it is the visual @ref
* glfwGetPhysicalDevicePresentationSupport queries. Windows with an OpenGL or
* OpenGL ES context may use a different visual.
*
* @return The `xcb_visualid_t` of the default visual, or zero if an
* [error](@ref error_handling) occurred.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.6.
*
* @ingroup native
*/
GLFWAPI xcb_visualid_t glfwGetXCBVisualID(void);
/*! @brief Returns the `xcb_window_t` of the specified window.
*
* @return The `xcb_window_t` of the specified window, or `XCB_NONE` if an
* [error](@ref error_handling) occurred.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_UNAVAILABLE.
*
* @thread_safety This function may be called from any thread. Access is not
* synchronized.
*
* @since Added in version 3.6.
*
* @ingroup native
*/
GLFWAPI xcb_window_t glfwGetXCBWindow(GLFWwindow* window);
#endif
#if defined(GLFW_EXPOSE_NATIVE_GLX)
/*! @brief Returns the `GLXContext` of the specified window.
*

View file

@ -80,6 +80,7 @@
#if defined(_GLFW_X11)
#include "x11_platform.h"
#define GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_XCB
#define GLFW_EXPOSE_NATIVE_GLX
#else
#define GLFW_X11_WINDOW_STATE

View file

@ -354,8 +354,8 @@ typedef XineramaScreenInfo* (* PFN_XineramaQueryScreens)(Display*,int*);
#define XineramaQueryExtension _glfw.x11.xinerama.QueryExtension
#define XineramaQueryScreens _glfw.x11.xinerama.QueryScreens
typedef XID xcb_window_t;
typedef XID xcb_visualid_t;
typedef uint32_t xcb_window_t;
typedef uint32_t xcb_visualid_t;
typedef struct xcb_connection_t xcb_connection_t;
typedef xcb_connection_t* (* PFN_XGetXCBConnection)(Display*);
#define XGetXCBConnection _glfw.x11.x11xcb.GetXCBConnection

View file

@ -3383,5 +3383,61 @@ GLFWAPI const char* glfwGetX11SelectionString(void)
return getSelectionString(_glfw.x11.PRIMARY);
}
GLFWAPI xcb_connection_t* glfwGetXCBConnection(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return NULL;
}
// Only loaded when the GLFW_X11_XCB_VULKAN_SURFACE init hint is set
if (!_glfw.x11.x11xcb.GetXCBConnection)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"X11: XGetXCBConnection from X11-xcb library is not loaded");
return NULL;
}
xcb_connection_t* connection = XGetXCBConnection(_glfw.x11.display);
if (!connection)
{
_glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to retrieve XCB connection");
return NULL;
}
return connection;
}
GLFWAPI xcb_visualid_t glfwGetXCBVisualID(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return 0;
}
return (xcb_visualid_t) XVisualIDFromVisual(DefaultVisual(_glfw.x11.display,
_glfw.x11.screen));
}
GLFWAPI xcb_window_t glfwGetXCBWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return 0;
}
return (xcb_window_t) window->x11.handle;
}
#endif // _GLFW_X11