chromium/third_party/dawn/third_party/glfw/src/x11_platform.h

//========================================================================
// GLFW 3.5 X11 - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2019 Camilla Löwy <[email protected]>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would
//    be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
//    be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
//    distribution.
//
//========================================================================

#include <unistd.h>
#include <signal.h>
#include <stdint.h>

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xresource.h>
#include <X11/Xcursor/Xcursor.h>

// The XRandR extension provides mode setting and gamma control
#include <X11/extensions/Xrandr.h>

// The Xkb extension provides improved keyboard support
#include <X11/XKBlib.h>

// The Xinerama extension provides legacy monitor indices
#include <X11/extensions/Xinerama.h>

// The XInput extension provides raw mouse motion input
#include <X11/extensions/XInput2.h>

// The Shape extension provides custom window shapes
#include <X11/extensions/shape.h>

#define GLX_VENDOR
#define GLX_RGBA_BIT
#define GLX_WINDOW_BIT
#define GLX_DRAWABLE_TYPE
#define GLX_RENDER_TYPE
#define GLX_RGBA_TYPE
#define GLX_DOUBLEBUFFER
#define GLX_STEREO
#define GLX_AUX_BUFFERS
#define GLX_RED_SIZE
#define GLX_GREEN_SIZE
#define GLX_BLUE_SIZE
#define GLX_ALPHA_SIZE
#define GLX_DEPTH_SIZE
#define GLX_STENCIL_SIZE
#define GLX_ACCUM_RED_SIZE
#define GLX_ACCUM_GREEN_SIZE
#define GLX_ACCUM_BLUE_SIZE
#define GLX_ACCUM_ALPHA_SIZE
#define GLX_SAMPLES
#define GLX_VISUAL_ID

#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
#define GLX_CONTEXT_DEBUG_BIT_ARB
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB
#define GLX_CONTEXT_PROFILE_MASK_ARB
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
#define GLX_CONTEXT_MAJOR_VERSION_ARB
#define GLX_CONTEXT_MINOR_VERSION_ARB
#define GLX_CONTEXT_FLAGS_ARB
#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT
#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB
#define GLX_LOSE_CONTEXT_ON_RESET_ARB
#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
#define GLX_NO_RESET_NOTIFICATION_ARB
#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB
#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB
#define GLX_CONTEXT_OPENGL_NO_ERROR_ARB

GLXWindow;
GLXDrawable;
GLXFBConfig;
GLXContext;
__GLXextproc;

PFN_XAllocClassHint;
PFN_XAllocSizeHints;
PFN_XAllocWMHints;
PFN_XChangeProperty;
PFN_XChangeWindowAttributes;
PFN_XCheckIfEvent;
PFN_XCheckTypedWindowEvent;
PFN_XCloseDisplay;
PFN_XCloseIM;
PFN_XConvertSelection;
PFN_XCreateColormap;
PFN_XCreateFontCursor;
PFN_XCreateIC;
PFN_XCreateRegion;
PFN_XCreateWindow;
PFN_XDefineCursor;
PFN_XDeleteContext;
PFN_XDeleteProperty;
PFN_XDestroyIC;
PFN_XDestroyRegion;
PFN_XDestroyWindow;
PFN_XDisplayKeycodes;
PFN_XEventsQueued;
PFN_XFilterEvent;
PFN_XFindContext;
PFN_XFlush;
PFN_XFree;
PFN_XFreeColormap;
PFN_XFreeCursor;
PFN_XFreeEventData;
PFN_XGetErrorText;
PFN_XGetEventData;
PFN_XGetICValues;
PFN_XGetIMValues;
PFN_XGetInputFocus;
PFN_XGetKeyboardMapping;
PFN_XGetScreenSaver;
PFN_XGetSelectionOwner;
PFN_XGetVisualInfo;
PFN_XGetWMNormalHints;
PFN_XGetWindowAttributes;
PFN_XGetWindowProperty;
PFN_XGrabPointer;
PFN_XIconifyWindow;
PFN_XInitThreads;
PFN_XInternAtom;
PFN_XLookupString;
PFN_XMapRaised;
PFN_XMapWindow;
PFN_XMoveResizeWindow;
PFN_XMoveWindow;
PFN_XNextEvent;
PFN_XOpenDisplay;
PFN_XOpenIM;
PFN_XPeekEvent;
PFN_XPending;
PFN_XQueryExtension;
PFN_XQueryPointer;
PFN_XRaiseWindow;
PFN_XRegisterIMInstantiateCallback;
PFN_XResizeWindow;
PFN_XResourceManagerString;
PFN_XSaveContext;
PFN_XSelectInput;
PFN_XSendEvent;
PFN_XSetClassHint;
PFN_XSetErrorHandler;
PFN_XSetICFocus;
PFN_XSetIMValues;
PFN_XSetInputFocus;
PFN_XSetLocaleModifiers;
PFN_XSetScreenSaver;
PFN_XSetSelectionOwner;
PFN_XSetWMHints;
PFN_XSetWMNormalHints;
PFN_XSetWMProtocols;
PFN_XSupportsLocale;
PFN_XSync;
PFN_XTranslateCoordinates;
PFN_XUndefineCursor;
PFN_XUngrabPointer;
PFN_XUnmapWindow;
PFN_XUnsetICFocus;
PFN_XVisualIDFromVisual;
PFN_XWarpPointer;
PFN_XkbFreeKeyboard;
PFN_XkbFreeNames;
PFN_XkbGetMap;
PFN_XkbGetNames;
PFN_XkbGetState;
PFN_XkbKeycodeToKeysym;
PFN_XkbQueryExtension;
PFN_XkbSelectEventDetails;
PFN_XkbSetDetectableAutoRepeat;
PFN_XrmDestroyDatabase;
PFN_XrmGetResource;
PFN_XrmGetStringDatabase;
PFN_XrmInitialize;
PFN_XrmUniqueQuark;
PFN_XUnregisterIMInstantiateCallback;
PFN_Xutf8LookupString;
PFN_Xutf8SetWMProperties;
#define XAllocClassHint
#define XAllocSizeHints
#define XAllocWMHints
#define XChangeProperty
#define XChangeWindowAttributes
#define XCheckIfEvent
#define XCheckTypedWindowEvent
#define XCloseDisplay
#define XCloseIM
#define XConvertSelection
#define XCreateColormap
#define XCreateFontCursor
#define XCreateIC
#define XCreateRegion
#define XCreateWindow
#define XDefineCursor
#define XDeleteContext
#define XDeleteProperty
#define XDestroyIC
#define XDestroyRegion
#define XDestroyWindow
#define XDisplayKeycodes
#define XEventsQueued
#define XFilterEvent
#define XFindContext
#define XFlush
#define XFree
#define XFreeColormap
#define XFreeCursor
#define XFreeEventData
#define XGetErrorText
#define XGetEventData
#define XGetICValues
#define XGetIMValues
#define XGetInputFocus
#define XGetKeyboardMapping
#define XGetScreenSaver
#define XGetSelectionOwner
#define XGetVisualInfo
#define XGetWMNormalHints
#define XGetWindowAttributes
#define XGetWindowProperty
#define XGrabPointer
#define XIconifyWindow
#define XInternAtom
#define XLookupString
#define XMapRaised
#define XMapWindow
#define XMoveResizeWindow
#define XMoveWindow
#define XNextEvent
#define XOpenIM
#define XPeekEvent
#define XPending
#define XQueryExtension
#define XQueryPointer
#define XRaiseWindow
#define XRegisterIMInstantiateCallback
#define XResizeWindow
#define XResourceManagerString
#define XSaveContext
#define XSelectInput
#define XSendEvent
#define XSetClassHint
#define XSetErrorHandler
#define XSetICFocus
#define XSetIMValues
#define XSetInputFocus
#define XSetLocaleModifiers
#define XSetScreenSaver
#define XSetSelectionOwner
#define XSetWMHints
#define XSetWMNormalHints
#define XSetWMProtocols
#define XSupportsLocale
#define XSync
#define XTranslateCoordinates
#define XUndefineCursor
#define XUngrabPointer
#define XUnmapWindow
#define XUnsetICFocus
#define XVisualIDFromVisual
#define XWarpPointer
#define XkbFreeKeyboard
#define XkbFreeNames
#define XkbGetMap
#define XkbGetNames
#define XkbGetState
#define XkbKeycodeToKeysym
#define XkbQueryExtension
#define XkbSelectEventDetails
#define XkbSetDetectableAutoRepeat
#define XrmDestroyDatabase
#define XrmGetResource
#define XrmGetStringDatabase
#define XrmUniqueQuark
#define XUnregisterIMInstantiateCallback
#define Xutf8LookupString
#define Xutf8SetWMProperties

PFN_XRRAllocGamma;
PFN_XRRFreeCrtcInfo;
PFN_XRRFreeGamma;
PFN_XRRFreeOutputInfo;
PFN_XRRFreeScreenResources;
PFN_XRRGetCrtcGamma;
PFN_XRRGetCrtcGammaSize;
PFN_XRRGetCrtcInfo;
PFN_XRRGetOutputInfo;
PFN_XRRGetOutputPrimary;
PFN_XRRGetScreenResourcesCurrent;
PFN_XRRQueryExtension;
PFN_XRRQueryVersion;
PFN_XRRSelectInput;
PFN_XRRSetCrtcConfig;
PFN_XRRSetCrtcGamma;
PFN_XRRUpdateConfiguration;
#define XRRAllocGamma
#define XRRFreeCrtcInfo
#define XRRFreeGamma
#define XRRFreeOutputInfo
#define XRRFreeScreenResources
#define XRRGetCrtcGamma
#define XRRGetCrtcGammaSize
#define XRRGetCrtcInfo
#define XRRGetOutputInfo
#define XRRGetOutputPrimary
#define XRRGetScreenResourcesCurrent
#define XRRQueryExtension
#define XRRQueryVersion
#define XRRSelectInput
#define XRRSetCrtcConfig
#define XRRSetCrtcGamma
#define XRRUpdateConfiguration

PFN_XcursorImageCreate;
PFN_XcursorImageDestroy;
PFN_XcursorImageLoadCursor;
PFN_XcursorGetTheme;
PFN_XcursorGetDefaultSize;
PFN_XcursorLibraryLoadImage;
#define XcursorImageCreate
#define XcursorImageDestroy
#define XcursorImageLoadCursor
#define XcursorGetTheme
#define XcursorGetDefaultSize
#define XcursorLibraryLoadImage

PFN_XineramaIsActive;
PFN_XineramaQueryExtension;
PFN_XineramaQueryScreens;
#define XineramaIsActive
#define XineramaQueryExtension
#define XineramaQueryScreens

xcb_window_t;
xcb_visualid_t;
xcb_connection_t;
PFN_XGetXCBConnection;
#define XGetXCBConnection

PFN_XF86VidModeQueryExtension;
PFN_XF86VidModeGetGammaRamp;
PFN_XF86VidModeSetGammaRamp;
PFN_XF86VidModeGetGammaRampSize;
#define XF86VidModeQueryExtension
#define XF86VidModeGetGammaRamp
#define XF86VidModeSetGammaRamp
#define XF86VidModeGetGammaRampSize

PFN_XIQueryVersion;
PFN_XISelectEvents;
#define XIQueryVersion
#define XISelectEvents

PFN_XRenderQueryExtension;
PFN_XRenderQueryVersion;
PFN_XRenderFindVisualFormat;
#define XRenderQueryExtension
#define XRenderQueryVersion
#define XRenderFindVisualFormat

PFN_XShapeQueryExtension;
PFN_XShapeQueryVersion;
PFN_XShapeCombineRegion;
PFN_XShapeCombineMask;

#define XShapeQueryExtension
#define XShapeQueryVersion
#define XShapeCombineRegion
#define XShapeCombineMask

PFNGLXGETFBCONFIGATTRIBPROC;
PFNGLXGETCLIENTSTRINGPROC;
PFNGLXQUERYEXTENSIONPROC;
PFNGLXQUERYVERSIONPROC;
PFNGLXDESTROYCONTEXTPROC;
PFNGLXMAKECURRENTPROC;
PFNGLXSWAPBUFFERSPROC;
PFNGLXQUERYEXTENSIONSSTRINGPROC;
PFNGLXGETFBCONFIGSPROC;
PFNGLXCREATENEWCONTEXTPROC;
PFNGLXGETPROCADDRESSPROC;
PFNGLXSWAPINTERVALEXTPROC;
PFNGLXGETVISUALFROMFBCONFIGPROC;
PFNGLXCREATEWINDOWPROC;
PFNGLXDESTROYWINDOWPROC;

PFNGLXSWAPINTERVALMESAPROC;
PFNGLXSWAPINTERVALSGIPROC;
PFNGLXCREATECONTEXTATTRIBSARBPROC;

// libGL.so function pointer typedefs
#define glXGetFBConfigs
#define glXGetFBConfigAttrib
#define glXGetClientString
#define glXQueryExtension
#define glXQueryVersion
#define glXDestroyContext
#define glXMakeCurrent
#define glXSwapBuffers
#define glXQueryExtensionsString
#define glXCreateNewContext
#define glXGetVisualFromFBConfig
#define glXCreateWindow
#define glXDestroyWindow

VkXlibSurfaceCreateFlagsKHR;
VkXcbSurfaceCreateFlagsKHR;

VkXlibSurfaceCreateInfoKHR;

VkXcbSurfaceCreateInfoKHR;

PFN_vkCreateXlibSurfaceKHR;
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR;
PFN_vkCreateXcbSurfaceKHR;
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR;

#include "xkb_unicode.h"
#include "posix_poll.h"

#define GLFW_X11_WINDOW_STATE
#define GLFW_X11_LIBRARY_WINDOW_STATE
#define GLFW_X11_MONITOR_STATE
#define GLFW_X11_CURSOR_STATE

#define GLFW_GLX_CONTEXT_STATE
#define GLFW_GLX_LIBRARY_CONTEXT_STATE


// GLX-specific per-context data
//
_GLFWcontextGLX;

// GLX-specific global data
//
_GLFWlibraryGLX;

// X11-specific per-window data
//
_GLFWwindowX11;

// X11-specific global data
//
_GLFWlibraryX11;

// X11-specific per-monitor data
//
_GLFWmonitorX11;

// X11-specific per-cursor data
//
_GLFWcursorX11;


GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform);
int _glfwInitX11(void);
void _glfwTerminateX11(void);

GLFWbool _glfwCreateWindowX11(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig);
void _glfwDestroyWindowX11(_GLFWwindow* window);
void _glfwSetWindowTitleX11(_GLFWwindow* window, const char* title);
void _glfwSetWindowIconX11(_GLFWwindow* window, int count, const GLFWimage* images);
void _glfwGetWindowPosX11(_GLFWwindow* window, int* xpos, int* ypos);
void _glfwSetWindowPosX11(_GLFWwindow* window, int xpos, int ypos);
void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height);
void _glfwSetWindowSizeX11(_GLFWwindow* window, int width, int height);
void _glfwSetWindowSizeLimitsX11(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight);
void _glfwSetWindowAspectRatioX11(_GLFWwindow* window, int numer, int denom);
void _glfwGetFramebufferSizeX11(_GLFWwindow* window, int* width, int* height);
void _glfwGetWindowFrameSizeX11(_GLFWwindow* window, int* left, int* top, int* right, int* bottom);
void _glfwGetWindowContentScaleX11(_GLFWwindow* window, float* xscale, float* yscale);
void _glfwIconifyWindowX11(_GLFWwindow* window);
void _glfwRestoreWindowX11(_GLFWwindow* window);
void _glfwMaximizeWindowX11(_GLFWwindow* window);
void _glfwShowWindowX11(_GLFWwindow* window);
void _glfwHideWindowX11(_GLFWwindow* window);
void _glfwRequestWindowAttentionX11(_GLFWwindow* window);
void _glfwFocusWindowX11(_GLFWwindow* window);
void _glfwSetWindowMonitorX11(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
GLFWbool _glfwWindowFocusedX11(_GLFWwindow* window);
GLFWbool _glfwWindowIconifiedX11(_GLFWwindow* window);
GLFWbool _glfwWindowVisibleX11(_GLFWwindow* window);
GLFWbool _glfwWindowMaximizedX11(_GLFWwindow* window);
GLFWbool _glfwWindowHoveredX11(_GLFWwindow* window);
GLFWbool _glfwFramebufferTransparentX11(_GLFWwindow* window);
void _glfwSetWindowResizableX11(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowDecoratedX11(_GLFWwindow* window, GLFWbool enabled);
void _glfwSetWindowFloatingX11(_GLFWwindow* window, GLFWbool enabled);
float _glfwGetWindowOpacityX11(_GLFWwindow* window);
void _glfwSetWindowOpacityX11(_GLFWwindow* window, float opacity);
void _glfwSetWindowMousePassthroughX11(_GLFWwindow* window, GLFWbool enabled);

void _glfwSetRawMouseMotionX11(_GLFWwindow *window, GLFWbool enabled);
GLFWbool _glfwRawMouseMotionSupportedX11(void);

void _glfwPollEventsX11(void);
void _glfwWaitEventsX11(void);
void _glfwWaitEventsTimeoutX11(double timeout);
void _glfwPostEmptyEventX11(void);

void _glfwGetCursorPosX11(_GLFWwindow* window, double* xpos, double* ypos);
void _glfwSetCursorPosX11(_GLFWwindow* window, double xpos, double ypos);
void _glfwSetCursorModeX11(_GLFWwindow* window, int mode);
const char* _glfwGetScancodeNameX11(int scancode);
int _glfwGetKeyScancodeX11(int key);
GLFWbool _glfwCreateCursorX11(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
GLFWbool _glfwCreateStandardCursorX11(_GLFWcursor* cursor, int shape);
void _glfwDestroyCursorX11(_GLFWcursor* cursor);
void _glfwSetCursorX11(_GLFWwindow* window, _GLFWcursor* cursor);
void _glfwSetClipboardStringX11(const char* string);
const char* _glfwGetClipboardStringX11(void);

EGLenum _glfwGetEGLPlatformX11(EGLint** attribs);
EGLNativeDisplayType _glfwGetEGLNativeDisplayX11(void);
EGLNativeWindowType _glfwGetEGLNativeWindowX11(_GLFWwindow* window);

void _glfwGetRequiredInstanceExtensionsX11(char** extensions);
GLFWbool _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceX11(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);

void _glfwFreeMonitorX11(_GLFWmonitor* monitor);
void _glfwGetMonitorPosX11(_GLFWmonitor* monitor, int* xpos, int* ypos);
void _glfwGetMonitorContentScaleX11(_GLFWmonitor* monitor, float* xscale, float* yscale);
void _glfwGetMonitorWorkareaX11(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height);
GLFWvidmode* _glfwGetVideoModesX11(_GLFWmonitor* monitor, int* count);
GLFWbool _glfwGetVideoModeX11(_GLFWmonitor* monitor, GLFWvidmode* mode);
GLFWbool _glfwGetGammaRampX11(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
void _glfwSetGammaRampX11(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);

void _glfwPollMonitorsX11(void);
void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor);

Cursor _glfwCreateNativeCursorX11(const GLFWimage* image, int xhot, int yhot);

unsigned long _glfwGetWindowPropertyX11(Window window,
                                        Atom property,
                                        Atom type,
                                        unsigned char** value);
GLFWbool _glfwIsVisualTransparentX11(Visual* visual);

void _glfwGrabErrorHandlerX11(void);
void _glfwReleaseErrorHandlerX11(void);
void _glfwInputErrorX11(int error, const char* message);

void _glfwPushSelectionToManagerX11(void);
void _glfwCreateInputContextX11(_GLFWwindow* window);

GLFWbool _glfwInitGLX(void);
void _glfwTerminateGLX(void);
GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
                               const _GLFWctxconfig* ctxconfig,
                               const _GLFWfbconfig* fbconfig);
void _glfwDestroyContextGLX(_GLFWwindow* window);
GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
                              const _GLFWctxconfig* ctxconfig,
                              const _GLFWfbconfig* fbconfig,
                              Visual** visual, int* depth);