Add runtime platform selection

This adds compile-time support for multiple platforms and runtime
detection of them.  Window system related platform functions are now
called from shared code via the function pointer struct _GLFWplatform.

The timer, thread and module loading platform functions are still called
directly by name and the implementation chosen at link-time.  These
functions are the same for any backend on a given OS, including the Null
backend.

The platforms are now enabled via CMake dependent options following the
GLFW_BUILD_<platform> pattern instead of a mix of automagic and ad-hoc
option names.  There is no longer any option for the Null backend as it
is now always enabled.

Much of the struct stitching work in platform.h was based on an earlier
experimental branch for runtime platform selection by @ronchaine.

Every platform function related to windows, contexts, monitors, input,
event processing and Vulkan have been renamed so that multiple sets of
them can exist without colliding.  Calls to these are now routed through
the _glfw.platform struct member.  These changes makes up most of this
commit.

For Wayland and X11 the client library loading and display creation is
used to detect a running compositor/server.  The XDG_SESSION_TYPE
environment variable is ignored for now, as X11 is still by far the more
complete implementation.

Closes #1655
Closes #1958
This commit is contained in:
Camilla Löwy
2021-07-13 21:50:09 +02:00
parent ff9d9515f6
commit 56a4cb0a3a
56 changed files with 2698 additions and 1235 deletions
+137 -112
View File
@@ -560,9 +560,9 @@ static void disableCursor(_GLFWwindow* window)
enableRawMouseMotion(window);
_glfw.x11.disabledCursorWindow = window;
_glfwPlatformGetCursorPos(window,
&_glfw.x11.restoreCursorPosX,
&_glfw.x11.restoreCursorPosY);
_glfwGetCursorPosX11(window,
&_glfw.x11.restoreCursorPosX,
&_glfw.x11.restoreCursorPosY);
updateCursorImage(window);
_glfwCenterCursorInContentArea(window);
XGrabPointer(_glfw.x11.display, window->x11.handle, True,
@@ -582,9 +582,9 @@ static void enableCursor(_GLFWwindow* window)
_glfw.x11.disabledCursorWindow = NULL;
XUngrabPointer(_glfw.x11.display, CurrentTime);
_glfwPlatformSetCursorPos(window,
_glfw.x11.restoreCursorPosX,
_glfw.x11.restoreCursorPosY);
_glfwSetCursorPosX11(window,
_glfw.x11.restoreCursorPosX,
_glfw.x11.restoreCursorPosY);
updateCursorImage(window);
}
@@ -655,7 +655,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
(XPointer) window);
if (!wndconfig->decorated)
_glfwPlatformSetWindowDecorated(window, GLFW_FALSE);
_glfwSetWindowDecoratedX11(window, GLFW_FALSE);
if (_glfw.x11.NET_WM_STATE && !window->monitor)
{
@@ -777,9 +777,9 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
if (_glfw.x11.im)
_glfwCreateInputContextX11(window);
_glfwPlatformSetWindowTitle(window, wndconfig->title);
_glfwPlatformGetWindowPos(window, &window->x11.xpos, &window->x11.ypos);
_glfwPlatformGetWindowSize(window, &window->x11.width, &window->x11.height);
_glfwSetWindowTitleX11(window, wndconfig->title);
_glfwGetWindowPosX11(window, &window->x11.xpos, &window->x11.ypos);
_glfwGetWindowSizeX11(window, &window->x11.width, &window->x11.height);
return GLFW_TRUE;
}
@@ -1118,8 +1118,8 @@ static void acquireMonitor(_GLFWwindow* window)
GLFWvidmode mode;
// Manually position the window over its monitor
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
_glfwPlatformGetVideoMode(window->monitor, &mode);
_glfwGetMonitorPosX11(window->monitor, &xpos, &ypos);
_glfwGetVideoModeX11(window->monitor, &mode);
XMoveResizeWindow(_glfw.x11.display, window->x11.handle,
xpos, ypos, mode.width, mode.height);
@@ -1787,7 +1787,7 @@ static void processEvent(XEvent *event)
XUnsetICFocus(window->x11.ic);
if (window->monitor && window->autoIconify)
_glfwPlatformIconifyWindow(window);
_glfwIconifyWindowX11(window);
_glfwInputWindowFocus(window, GLFW_FALSE);
return;
@@ -1827,7 +1827,7 @@ static void processEvent(XEvent *event)
}
else if (event->xproperty.atom == _glfw.x11.NET_WM_STATE)
{
const GLFWbool maximized = _glfwPlatformWindowMaximized(window);
const GLFWbool maximized = _glfwWindowMaximizedX11(window);
if (window->x11.maximized != maximized)
{
window->x11.maximized = maximized;
@@ -1970,10 +1970,10 @@ void _glfwCreateInputContextX11(_GLFWwindow* window)
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
int _glfwCreateWindowX11(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig)
{
Visual* visual = NULL;
int depth;
@@ -2031,7 +2031,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (window->monitor)
{
_glfwPlatformShowWindow(window);
_glfwShowWindowX11(window);
updateWindowMode(window);
acquireMonitor(window);
}
@@ -2040,7 +2040,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GLFW_TRUE;
}
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
void _glfwDestroyWindowX11(_GLFWwindow* window)
{
if (_glfw.x11.disabledCursorWindow == window)
_glfw.x11.disabledCursorWindow = NULL;
@@ -2074,7 +2074,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title)
{
if (_glfw.x11.xlib.utf8)
{
@@ -2098,8 +2098,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
int count, const GLFWimage* images)
void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images)
{
if (count)
{
@@ -2143,7 +2142,7 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
XFlush(_glfw.x11.display);
}
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos)
{
Window dummy;
int x, y;
@@ -2157,11 +2156,11 @@ void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
*ypos = y;
}
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
void _glfwSetWindowPosX11(_GLFWwindow* window, int xpos, int ypos)
{
// HACK: Explicitly setting PPosition to any value causes some WMs, notably
// Compiz and Metacity, to honor the position of unmapped windows
if (!_glfwPlatformWindowVisible(window))
if (!_glfwWindowVisibleX11(window))
{
long supplied;
XSizeHints* hints = XAllocSizeHints();
@@ -2181,7 +2180,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
XFlush(_glfw.x11.display);
}
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height)
{
XWindowAttributes attribs;
XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &attribs);
@@ -2192,7 +2191,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
*height = attribs.height;
}
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
void _glfwSetWindowSizeX11(_GLFWwindow* window, int width, int height)
{
if (window->monitor)
{
@@ -2210,32 +2209,32 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
int minwidth, int minheight,
int maxwidth, int maxheight)
void _glfwSetWindowSizeLimitsX11(_GLFWwindow* window,
int minwidth, int minheight,
int maxwidth, int maxheight)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwGetWindowSizeX11(window, &width, &height);
updateNormalHints(window, width, height);
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
void _glfwSetWindowAspectRatioX11(_GLFWwindow* window, int numer, int denom)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwGetWindowSizeX11(window, &width, &height);
updateNormalHints(window, width, height);
XFlush(_glfw.x11.display);
}
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
void _glfwGetFramebufferSizeX11(_GLFWwindow* window, int* width, int* height)
{
_glfwPlatformGetWindowSize(window, width, height);
_glfwGetWindowSizeX11(window, width, height);
}
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
int* left, int* top,
int* right, int* bottom)
void _glfwGetWindowFrameSizeX11(_GLFWwindow* window,
int* left, int* top,
int* right, int* bottom)
{
long* extents = NULL;
@@ -2245,7 +2244,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
if (_glfw.x11.NET_FRAME_EXTENTS == None)
return;
if (!_glfwPlatformWindowVisible(window) &&
if (!_glfwWindowVisibleX11(window) &&
_glfw.x11.NET_REQUEST_FRAME_EXTENTS)
{
XEvent event;
@@ -2294,8 +2293,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
XFree(extents);
}
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
float* xscale, float* yscale)
void _glfwGetWindowContentScaleX11(_GLFWwindow* window, float* xscale, float* yscale)
{
if (xscale)
*xscale = _glfw.x11.contentScaleX;
@@ -2303,7 +2301,7 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
*yscale = _glfw.x11.contentScaleY;
}
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
void _glfwIconifyWindowX11(_GLFWwindow* window)
{
if (window->x11.overrideRedirect)
{
@@ -2318,7 +2316,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwRestoreWindowX11(_GLFWwindow* window)
{
if (window->x11.overrideRedirect)
{
@@ -2329,12 +2327,12 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
return;
}
if (_glfwPlatformWindowIconified(window))
if (_glfwWindowIconifiedX11(window))
{
XMapWindow(_glfw.x11.display, window->x11.handle);
waitForVisibilityNotify(window);
}
else if (_glfwPlatformWindowVisible(window))
else if (_glfwWindowVisibleX11(window))
{
if (_glfw.x11.NET_WM_STATE &&
_glfw.x11.NET_WM_STATE_MAXIMIZED_VERT &&
@@ -2352,7 +2350,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
void _glfwMaximizeWindowX11(_GLFWwindow* window)
{
if (!_glfw.x11.NET_WM_STATE ||
!_glfw.x11.NET_WM_STATE_MAXIMIZED_VERT ||
@@ -2361,7 +2359,7 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
return;
}
if (_glfwPlatformWindowVisible(window))
if (_glfwWindowVisibleX11(window))
{
sendEventToWM(window,
_glfw.x11.NET_WM_STATE,
@@ -2417,22 +2415,22 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformShowWindow(_GLFWwindow* window)
void _glfwShowWindowX11(_GLFWwindow* window)
{
if (_glfwPlatformWindowVisible(window))
if (_glfwWindowVisibleX11(window))
return;
XMapWindow(_glfw.x11.display, window->x11.handle);
waitForVisibilityNotify(window);
}
void _glfwPlatformHideWindow(_GLFWwindow* window)
void _glfwHideWindowX11(_GLFWwindow* window)
{
XUnmapWindow(_glfw.x11.display, window->x11.handle);
XFlush(_glfw.x11.display);
}
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
void _glfwRequestWindowAttentionX11(_GLFWwindow* window)
{
if (!_glfw.x11.NET_WM_STATE || !_glfw.x11.NET_WM_STATE_DEMANDS_ATTENTION)
return;
@@ -2444,11 +2442,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
0, 1, 0);
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
void _glfwFocusWindowX11(_GLFWwindow* window)
{
if (_glfw.x11.NET_ACTIVE_WINDOW)
sendEventToWM(window, _glfw.x11.NET_ACTIVE_WINDOW, 1, 0, 0, 0, 0);
else if (_glfwPlatformWindowVisible(window))
else if (_glfwWindowVisibleX11(window))
{
XRaiseWindow(_glfw.x11.display, window->x11.handle);
XSetInputFocus(_glfw.x11.display, window->x11.handle,
@@ -2458,11 +2456,11 @@ void _glfwPlatformFocusWindow(_GLFWwindow* window)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
_GLFWmonitor* monitor,
int xpos, int ypos,
int width, int height,
int refreshRate)
void _glfwSetWindowMonitorX11(_GLFWwindow* window,
_GLFWmonitor* monitor,
int xpos, int ypos,
int width, int height,
int refreshRate)
{
if (window->monitor == monitor)
{
@@ -2486,8 +2484,8 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
if (window->monitor)
{
_glfwPlatformSetWindowDecorated(window, window->decorated);
_glfwPlatformSetWindowFloating(window, window->floating);
_glfwSetWindowDecoratedX11(window, window->decorated);
_glfwSetWindowFloatingX11(window, window->floating);
releaseMonitor(window);
}
@@ -2496,7 +2494,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
if (window->monitor)
{
if (!_glfwPlatformWindowVisible(window))
if (!_glfwWindowVisibleX11(window))
{
XMapRaised(_glfw.x11.display, window->x11.handle);
waitForVisibilityNotify(window);
@@ -2515,7 +2513,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
XFlush(_glfw.x11.display);
}
int _glfwPlatformWindowFocused(_GLFWwindow* window)
int _glfwWindowFocusedX11(_GLFWwindow* window)
{
Window focused;
int state;
@@ -2524,19 +2522,19 @@ int _glfwPlatformWindowFocused(_GLFWwindow* window)
return window->x11.handle == focused;
}
int _glfwPlatformWindowIconified(_GLFWwindow* window)
int _glfwWindowIconifiedX11(_GLFWwindow* window)
{
return getWindowState(window) == IconicState;
}
int _glfwPlatformWindowVisible(_GLFWwindow* window)
int _glfwWindowVisibleX11(_GLFWwindow* window)
{
XWindowAttributes wa;
XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &wa);
return wa.map_state == IsViewable;
}
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
int _glfwWindowMaximizedX11(_GLFWwindow* window)
{
Atom* states;
unsigned long i;
@@ -2571,7 +2569,7 @@ int _glfwPlatformWindowMaximized(_GLFWwindow* window)
return maximized;
}
int _glfwPlatformWindowHovered(_GLFWwindow* window)
int _glfwWindowHoveredX11(_GLFWwindow* window)
{
Window w = _glfw.x11.root;
while (w)
@@ -2599,7 +2597,7 @@ int _glfwPlatformWindowHovered(_GLFWwindow* window)
return GLFW_FALSE;
}
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
int _glfwFramebufferTransparentX11(_GLFWwindow* window)
{
if (!window->x11.transparent)
return GLFW_FALSE;
@@ -2607,14 +2605,14 @@ int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
return XGetSelectionOwner(_glfw.x11.display, _glfw.x11.NET_WM_CM_Sx) != None;
}
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
void _glfwSetWindowResizableX11(_GLFWwindow* window, GLFWbool enabled)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwGetWindowSizeX11(window, &width, &height);
updateNormalHints(window, width, height);
}
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
void _glfwSetWindowDecoratedX11(_GLFWwindow* window, GLFWbool enabled)
{
struct
{
@@ -2636,12 +2634,12 @@ void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
sizeof(hints) / sizeof(long));
}
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
void _glfwSetWindowFloatingX11(_GLFWwindow* window, GLFWbool enabled)
{
if (!_glfw.x11.NET_WM_STATE || !_glfw.x11.NET_WM_STATE_ABOVE)
return;
if (_glfwPlatformWindowVisible(window))
if (_glfwWindowVisibleX11(window))
{
const long action = enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
sendEventToWM(window,
@@ -2706,7 +2704,7 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enabled)
void _glfwSetWindowMousePassthroughX11(_GLFWwindow* window, GLFWbool enabled)
{
if (!_glfw.x11.xshape.available)
return;
@@ -2725,7 +2723,7 @@ void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, GLFWbool enable
}
}
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
float _glfwGetWindowOpacityX11(_GLFWwindow* window)
{
float opacity = 1.f;
@@ -2748,7 +2746,7 @@ float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
return opacity;
}
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
void _glfwSetWindowOpacityX11(_GLFWwindow* window, float opacity)
{
const CARD32 value = (CARD32) (0xffffffffu * (double) opacity);
XChangeProperty(_glfw.x11.display, window->x11.handle,
@@ -2756,7 +2754,7 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
PropModeReplace, (unsigned char*) &value, 1);
}
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
void _glfwSetRawMouseMotionX11(_GLFWwindow *window, GLFWbool enabled)
{
if (!_glfw.x11.xi.available)
return;
@@ -2770,12 +2768,12 @@ void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
disableRawMouseMotion(window);
}
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
GLFWbool _glfwRawMouseMotionSupportedX11(void)
{
return _glfw.x11.xi.available;
}
void _glfwPlatformPollEvents(void)
void _glfwPollEventsX11(void)
{
_GLFWwindow* window;
@@ -2796,29 +2794,29 @@ void _glfwPlatformPollEvents(void)
if (window)
{
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwGetWindowSizeX11(window, &width, &height);
// NOTE: Re-center the cursor only if it has moved since the last call,
// to avoid breaking glfwWaitEvents with MotionNotify
if (window->x11.lastCursorPosX != width / 2 ||
window->x11.lastCursorPosY != height / 2)
{
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
_glfwSetCursorPosX11(window, width / 2, height / 2);
}
}
XFlush(_glfw.x11.display);
}
void _glfwPlatformWaitEvents(void)
void _glfwWaitEventsX11(void)
{
while (!XPending(_glfw.x11.display))
waitForEvent(NULL);
_glfwPlatformPollEvents();
_glfwPollEventsX11();
}
void _glfwPlatformWaitEventsTimeout(double timeout)
void _glfwWaitEventsTimeoutX11(double timeout)
{
while (!XPending(_glfw.x11.display))
{
@@ -2826,10 +2824,10 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
break;
}
_glfwPlatformPollEvents();
_glfwPollEventsX11();
}
void _glfwPlatformPostEmptyEvent(void)
void _glfwPostEmptyEventX11(void)
{
XEvent event = { ClientMessage };
event.xclient.window = _glfw.x11.helperWindowHandle;
@@ -2840,7 +2838,7 @@ void _glfwPlatformPostEmptyEvent(void)
XFlush(_glfw.x11.display);
}
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
void _glfwGetCursorPosX11(_GLFWwindow* window, double* xpos, double* ypos)
{
Window root, child;
int rootX, rootY, childX, childY;
@@ -2857,7 +2855,7 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
*ypos = childY;
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
void _glfwSetCursorPosX11(_GLFWwindow* window, double x, double y)
{
// Store the new position so it can be recognized later
window->x11.warpCursorPosX = (int) x;
@@ -2868,11 +2866,11 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
XFlush(_glfw.x11.display);
}
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
void _glfwSetCursorModeX11(_GLFWwindow* window, int mode)
{
if (mode == GLFW_CURSOR_DISABLED)
{
if (_glfwPlatformWindowFocused(window))
if (_glfwWindowFocusedX11(window))
disableCursor(window);
}
else if (_glfw.x11.disabledCursorWindow == window)
@@ -2883,7 +2881,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
XFlush(_glfw.x11.display);
}
const char* _glfwPlatformGetScancodeName(int scancode)
const char* _glfwGetScancodeNameX11(int scancode)
{
if (!_glfw.x11.xkb.available)
return NULL;
@@ -2913,23 +2911,23 @@ const char* _glfwPlatformGetScancodeName(int scancode)
return _glfw.x11.keynames[key];
}
int _glfwPlatformGetKeyScancode(int key)
int _glfwGetKeyScancodeX11(int key)
{
return _glfw.x11.scancodes[key];
}
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image,
int xhot, int yhot)
int _glfwCreateCursorX11(_GLFWcursor* cursor,
const GLFWimage* image,
int xhot, int yhot)
{
cursor->x11.handle = _glfwCreateCursorX11(image, xhot, yhot);
cursor->x11.handle = _glfwCreateNativeCursorX11(image, xhot, yhot);
if (!cursor->x11.handle)
return GLFW_FALSE;
return GLFW_TRUE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
int _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape)
{
if (_glfw.x11.xcursor.handle)
{
@@ -3027,13 +3025,13 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
return GLFW_TRUE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
void _glfwDestroyCursorX11(_GLFWcursor* cursor)
{
if (cursor->x11.handle)
XFreeCursor(_glfw.x11.display, cursor->x11.handle);
}
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor)
{
if (window->cursorMode == GLFW_CURSOR_NORMAL)
{
@@ -3042,7 +3040,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
}
}
void _glfwPlatformSetClipboardString(const char* string)
void _glfwSetClipboardStringX11(const char* string)
{
char* copy = _glfw_strdup(string);
_glfw_free(_glfw.x11.clipboardString);
@@ -3061,12 +3059,12 @@ void _glfwPlatformSetClipboardString(const char* string)
}
}
const char* _glfwPlatformGetClipboardString(void)
const char* _glfwGetClipboardStringX11(void)
{
return getSelectionString(_glfw.x11.CLIPBOARD);
}
EGLenum _glfwPlatformGetEGLPlatform(EGLint** attribs)
EGLenum _glfwGetEGLPlatformX11(EGLint** attribs)
{
if (_glfw.egl.ANGLE_platform_angle)
{
@@ -3102,12 +3100,12 @@ EGLenum _glfwPlatformGetEGLPlatform(EGLint** attribs)
return 0;
}
EGLNativeDisplayType _glfwPlatformGetEGLNativeDisplay(void)
EGLNativeDisplayType _glfwGetEGLNativeDisplayX11(void)
{
return _glfw.x11.display;
}
EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow* window)
EGLNativeWindowType _glfwGetEGLNativeWindowX11(_GLFWwindow* window)
{
if (_glfw.egl.platform)
return &window->x11.handle;
@@ -3115,7 +3113,7 @@ EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow* window)
return (EGLNativeWindowType) window->x11.handle;
}
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
void _glfwGetRequiredInstanceExtensionsX11(char** extensions)
{
if (!_glfw.vk.KHR_surface)
return;
@@ -3136,9 +3134,9 @@ void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
extensions[1] = "VK_KHR_xlib_surface";
}
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
VkPhysicalDevice device,
uint32_t queuefamily)
int _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance,
VkPhysicalDevice device,
uint32_t queuefamily)
{
VisualID visualID = XVisualIDFromVisual(DefaultVisual(_glfw.x11.display,
_glfw.x11.screen));
@@ -3189,10 +3187,10 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
}
}
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
_GLFWwindow* window,
const VkAllocationCallbacks* allocator,
VkSurfaceKHR* surface)
VkResult _glfwCreateWindowSurfaceX11(VkInstance instance,
_GLFWwindow* window,
const VkAllocationCallbacks* allocator,
VkSurfaceKHR* surface)
{
if (_glfw.vk.KHR_xcb_surface && _glfw.x11.x11xcb.handle)
{
@@ -3272,6 +3270,13 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
GLFWAPI Display* glfwGetX11Display(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return NULL;
}
return _glfw.x11.display;
}
@@ -3279,6 +3284,13 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT_OR_RETURN(None);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return None;
}
return window->x11.handle;
}
@@ -3286,6 +3298,12 @@ GLFWAPI void glfwSetX11SelectionString(const char* string)
{
_GLFW_REQUIRE_INIT();
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return;
}
_glfw_free(_glfw.x11.primarySelectionString);
_glfw.x11.primarySelectionString = _glfw_strdup(string);
@@ -3305,6 +3323,13 @@ GLFWAPI void glfwSetX11SelectionString(const char* string)
GLFWAPI const char* glfwGetX11SelectionString(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
{
_glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized");
return NULL;
}
return getSelectionString(_glfw.x11.PRIMARY);
}