| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #ifndef GATE_PLATFORM_LINUX_PROCFS_H_INCLUDED | ||
| 30 | #define GATE_PLATFORM_LINUX_PROCFS_H_INCLUDED | ||
| 31 | |||
| 32 | #include "gate/gatetypes.h" | ||
| 33 | |||
| 34 | #ifdef GATE_SYS_POSIX | ||
| 35 | |||
| 36 | #include "gate/inputs.h" | ||
| 37 | #include "gate/strings.h" | ||
| 38 | #include "gate/libraries.h" | ||
| 39 | #include "gate/results.h" | ||
| 40 | |||
| 41 | #ifndef XUTIL_DEFINE_FUNCTIONS | ||
| 42 | #define XUTIL_DEFINE_FUNCTIONS | ||
| 43 | #endif | ||
| 44 | #include <X11/Xlib.h> | ||
| 45 | #include <X11/Xutil.h> | ||
| 46 | #include <X11/keysym.h> | ||
| 47 | #include <X11/Xatom.h> | ||
| 48 | |||
| 49 | typedef struct gate_xlib | ||
| 50 | { | ||
| 51 | Display* (*XOpenDisplay) (const char* display_name); | ||
| 52 | Window (*XDefaultRootWindow) (Display* display); | ||
| 53 | int (*XCloseDisplay) (Display* display); | ||
| 54 | Window (*XCreateWindow) (Display* display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth, unsigned int clazz, Visual* visual, unsigned long valuemask, XSetWindowAttributes* attributes); | ||
| 55 | Atom (*XInternAtom) (Display* display, const char* atom_name, Bool only_if_exists); | ||
| 56 | int (*XChangeProperty) (Display* display, Window w, Atom property, Atom type, int format, int mode, const unsigned char* data, int nelements); | ||
| 57 | int (*XSetWMHints) (Display* display, Window w, XWMHints* wm_hints); | ||
| 58 | int (*XMapWindow) (Display* display, Window w); | ||
| 59 | int (*XStoreName) (Display* display, Window w, const char* window_name); | ||
| 60 | int (*XPending) (Display* display); | ||
| 61 | int (*XNextEvent) (Display* display, XEvent* event_return); | ||
| 62 | int (*XDestroyWindow) (Display* display, Window w); | ||
| 63 | Bool (*XCheckWindowEvent) (Display* display, Window w, long event_mask, XEvent* event_return); | ||
| 64 | int (*XGetInputFocus) (Display* display, Window* focus_return, int* revert_to_return); | ||
| 65 | KeyCode (*XKeysymToKeycode) (Display* display, KeySym keysym); | ||
| 66 | KeySym (*XStringToKeysym) (const char* str); | ||
| 67 | Status (*XSendEvent) (Display* display, Window w, Bool propagate, long event_mask, XEvent* event_send); | ||
| 68 | Status (*XGetWindowAttributes) (Display* display, Window w, XWindowAttributes* window_attributes_return); | ||
| 69 | int (*XFlush) (Display* display); | ||
| 70 | int (*XDefaultScreen) (Display*); | ||
| 71 | Colormap (*XDefaultColormap) (Display*, int); | ||
| 72 | int (*XQueryColor) (Display*, Colormap, XColor*); | ||
| 73 | int (*XResizeWindow) (Display* display, Window w, unsigned int width, unsigned int height); | ||
| 74 | Bool (*XCheckMaskEvent) (Display* display, long event_mask, XEvent* event_return); | ||
| 75 | KeySym (*XLookupKeysym) (XKeyEvent* key_event, int index); | ||
| 76 | int (*XSelectInput) (Display* display, Window w, long event_mask); | ||
| 77 | Status (*XMatchVisualInfo) (Display* display, int screen, int depth, int clazz, XVisualInfo* vinfo_return); | ||
| 78 | Colormap (*XCreateColormap) (Display* display, Window w, Visual* visual, int alloc); | ||
| 79 | void (*XSetWMProtocols) (Display* display, Window w, Atom* protocols, int count); | ||
| 80 | int (*XAutoRepeatOff) (Display* display); | ||
| 81 | int (*XAutoRepeatOn) (Display* display); | ||
| 82 | /********/ | ||
| 83 | Status (*XInitThreads) (void); | ||
| 84 | int (*XDefaultDepth) (Display* display, int screen_number); | ||
| 85 | Visual* (*XDefaultVisual) (Display* display, int screen_number); | ||
| 86 | int (*XBitmapPad) (Display* display); | ||
| 87 | Window (*XRootWindow) (Display* display, int screen_number); | ||
| 88 | Bool (*XTranslateCoordinates)(Display* display, Window src_w, Window dest_w, int src_x, int src_y, int* dest_x_return, int* dest_y_return, Window* child_return); | ||
| 89 | int (*XConnectionNumber) (Display* display); | ||
| 90 | int (*XMoveResizeWindow) (Display* display, Window w, int x, int y, unsigned int width, unsigned int height); | ||
| 91 | int (*XSetInputFocus) (Display* display, Window focus, int revert_to, Time time); | ||
| 92 | int (*XUnmapWindow) (Display* display, Window w); | ||
| 93 | |||
| 94 | int (*XSetGraphicsExposures)(Display* display, GC gc, Bool graphics_exposures); | ||
| 95 | Pixmap (*XCreatePixmap) (Display* display, Drawable d, unsigned int width, unsigned int height, unsigned int depth); | ||
| 96 | int (*XFreePixmap) (Display* display, Pixmap pixmap); | ||
| 97 | GC (*XCreateGC) (Display* display, Drawable d, unsigned long valuemask, XGCValues* values); | ||
| 98 | int (*XFreeGC) (Display* display, GC gc); | ||
| 99 | XImage* (*XCreateImage) (Display* display, Visual* visual, unsigned int depth, int format, int offset, char* data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line); | ||
| 100 | XImage* (*XGetImage) (Display* display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format); | ||
| 101 | int (*XPutImage) (Display* display, Drawable d, GC gc, XImage* image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); | ||
| 102 | int (*XDestroyImage) (XImage* ximage); | ||
| 103 | |||
| 104 | Status (*XAllocColor) (Display* display, Colormap colormap, XColor* screen_in_out); | ||
| 105 | unsigned long(*XBlackPixel) (Display* display, int screen_number); | ||
| 106 | unsigned long(*XWhitePixel) (Display* display, int screen_number); | ||
| 107 | int (*XSetForeground) (Display* display, GC gc, unsigned long foreground); | ||
| 108 | unsigned long(*XGetPixel) (XImage* ximage, int x, int y); | ||
| 109 | int (*XPutPixel) (XImage* ximage, int x, int y, unsigned long pixel); | ||
| 110 | int (*XDrawPoint) (Display* display, Drawable d, GC gc, int x, int y); | ||
| 111 | int (*XDrawLine) (Display* display, Drawable d, GC gc, int x1, int y1, int x2, int y2); | ||
| 112 | int (*XDrawLines) (Display* display, Drawable d, GC gc, XPoint* points, int npoints, int mode); | ||
| 113 | int (*XFillPolygon) (Display* display, Drawable d, GC gc, XPoint* points, int npoints, int shape, int mode); | ||
| 114 | int (*XDrawRectangle) (Display* display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); | ||
| 115 | int (*XFillRectangle) (Display* display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); | ||
| 116 | |||
| 117 | Font (*XLoadFont) (Display* display, char const* name); | ||
| 118 | int (*XSetFont) (Display* display, GC gc, Font font); | ||
| 119 | char** (*XListFonts) (Display* display, char const* pattern, int maxnames, int* actual_count_return); | ||
| 120 | int (*XFreeFontNames) (char** list); | ||
| 121 | int (*XDrawString) (Display* display, Drawable d, GC gc, int x, int y, char const* string, int length); | ||
| 122 | int (*XFreeFontInfo) (char** names, XFontStruct* free_info, int actual_count); | ||
| 123 | XFontStruct*(*XQueryFont) (Display* display, XID font_ID); | ||
| 124 | int (*XTextWidth) (XFontStruct* font_struct, char const* string, int count); | ||
| 125 | int (*XUnloadFont) (Display* display, Font font); | ||
| 126 | Cursor (*XCreateFontCursor) (Display* display, unsigned int shape); | ||
| 127 | int (*XDefineCursor) (Display* display, Window w, Cursor cursor); | ||
| 128 | int (*XUndefineCursor) (Display* display, Window w); | ||
| 129 | int (*XFreeCursor) (Display* display, Cursor cursor); | ||
| 130 | Bool (*XQueryPointer) (Display* display, Window w, Window* root_return, Window* child_return, int* root_x_return, int* root_y_return, int* win_x_return, int* win_y_return, unsigned int* mask_return); | ||
| 131 | int (*XWarpPointer) (Display* display, Window src_w, Window dest_w, int src_x, int src_y, unsigned int src_width, unsigned int src_height, int dest_x, int dest_y); | ||
| 132 | |||
| 133 | } gate_xlib_t; | ||
| 134 | |||
| 135 | static gate_xlib_t xlib = GATE_INIT_EMPTY; | ||
| 136 | static gate_bool_t volatile xlib_loaded = false; | ||
| 137 | |||
| 138 | ✗ | static gate_result_t gate_xlib_load_functions(void) | |
| 139 | { | ||
| 140 | static gate_string_t xlib_lib_name = GATE_STRING_INIT_STATIC("libX11.so"); | ||
| 141 | ✗ | gate_result_t ret = GATE_RESULT_FAILED; | |
| 142 | static gate_library_t xlib_lib = NULL; | ||
| 143 | |||
| 144 | do | ||
| 145 | { | ||
| 146 | ✗ | if (xlib_loaded) | |
| 147 | { | ||
| 148 | ✗ | ret = GATE_RESULT_OK; | |
| 149 | ✗ | break; | |
| 150 | } | ||
| 151 | |||
| 152 | ✗ | if (xlib_lib == NULL) | |
| 153 | { | ||
| 154 | ✗ | ret = gate_library_open(&xlib_lib_name, &xlib_lib, GATE_LIBRARY_FLAG_DEFAULT); | |
| 155 | ✗ | GATE_BREAK_IF_FAILED(ret); | |
| 156 | } | ||
| 157 | |||
| 158 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XOpenDisplay", &xlib.XOpenDisplay)); | |
| 159 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultRootWindow", &xlib.XDefaultRootWindow)); | |
| 160 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCloseDisplay", &xlib.XCloseDisplay)); | |
| 161 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateWindow", &xlib.XCreateWindow)); | |
| 162 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XInternAtom", &xlib.XInternAtom)); | |
| 163 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XChangeProperty", &xlib.XChangeProperty)); | |
| 164 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetWMHints", &xlib.XSetWMHints)); | |
| 165 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMapWindow", &xlib.XMapWindow)); | |
| 166 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XStoreName", &xlib.XStoreName)); | |
| 167 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPending", &xlib.XPending)); | |
| 168 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XNextEvent", &xlib.XNextEvent)); | |
| 169 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDestroyWindow", &xlib.XDestroyWindow)); | |
| 170 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCheckWindowEvent", &xlib.XCheckWindowEvent)); | |
| 171 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetInputFocus", &xlib.XGetInputFocus)); | |
| 172 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XKeysymToKeycode", &xlib.XKeysymToKeycode)); | |
| 173 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XStringToKeysym", &xlib.XStringToKeysym)); | |
| 174 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSendEvent", &xlib.XSendEvent)); | |
| 175 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetWindowAttributes", &xlib.XGetWindowAttributes)); | |
| 176 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFlush", &xlib.XFlush)); | |
| 177 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultScreen", &xlib.XDefaultScreen)); | |
| 178 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultColormap", &xlib.XDefaultColormap)); | |
| 179 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryColor", &xlib.XQueryColor)); | |
| 180 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XResizeWindow", &xlib.XResizeWindow)); | |
| 181 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCheckMaskEvent", &xlib.XCheckMaskEvent)); | |
| 182 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XLookupKeysym", &xlib.XLookupKeysym)); | |
| 183 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSelectInput", &xlib.XSelectInput)); | |
| 184 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMatchVisualInfo", &xlib.XMatchVisualInfo)); | |
| 185 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateColormap", &xlib.XCreateColormap)); | |
| 186 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetWMProtocols", &xlib.XSetWMProtocols)); | |
| 187 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAutoRepeatOff", &xlib.XAutoRepeatOff)); | |
| 188 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAutoRepeatOn", &xlib.XAutoRepeatOn)); | |
| 189 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XInitThreads", &xlib.XInitThreads)); | |
| 190 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultDepth", &xlib.XDefaultDepth)); | |
| 191 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultVisual", &xlib.XDefaultVisual)); | |
| 192 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XBitmapPad", &xlib.XBitmapPad)); | |
| 193 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XRootWindow", &xlib.XRootWindow)); | |
| 194 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XTranslateCoordinates", &xlib.XTranslateCoordinates)); | |
| 195 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XConnectionNumber", &xlib.XConnectionNumber)); | |
| 196 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMoveResizeWindow", &xlib.XMoveResizeWindow)); | |
| 197 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetInputFocus", &xlib.XSetInputFocus)); | |
| 198 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUnmapWindow", &xlib.XUnmapWindow)); | |
| 199 | |||
| 200 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetGraphicsExposures", &xlib.XSetGraphicsExposures)); | |
| 201 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreatePixmap", &xlib.XCreatePixmap)); | |
| 202 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreePixmap", &xlib.XFreePixmap)); | |
| 203 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateGC", &xlib.XCreateGC)); | |
| 204 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeGC", &xlib.XFreeGC)); | |
| 205 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateImage", &xlib.XCreateImage)); | |
| 206 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetImage", &xlib.XGetImage)); | |
| 207 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPutImage", &xlib.XPutImage)); | |
| 208 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDestroyImage", &xlib.XDestroyImage)); | |
| 209 | |||
| 210 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAllocColor", &xlib.XAllocColor)); | |
| 211 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XBlackPixel", &xlib.XBlackPixel)); | |
| 212 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XWhitePixel", &xlib.XWhitePixel)); | |
| 213 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetForeground", &xlib.XSetForeground)); | |
| 214 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetPixel", &xlib.XGetPixel)); | |
| 215 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPutPixel", &xlib.XPutPixel)); | |
| 216 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawPoint", &xlib.XDrawPoint)); | |
| 217 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawLine", &xlib.XDrawLine)); | |
| 218 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawLines", &xlib.XDrawLines)); | |
| 219 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFillPolygon", &xlib.XFillPolygon)); | |
| 220 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawRectangle", &xlib.XDrawRectangle)); | |
| 221 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFillRectangle", &xlib.XFillRectangle)); | |
| 222 | |||
| 223 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XLoadFont", &xlib.XLoadFont)); | |
| 224 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetFont", &xlib.XSetFont)); | |
| 225 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XListFonts", &xlib.XListFonts)); | |
| 226 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeFontNames", &xlib.XFreeFontNames)); | |
| 227 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawString", &xlib.XDrawString)); | |
| 228 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeFontInfo", &xlib.XFreeFontInfo)); | |
| 229 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryFont", &xlib.XQueryFont)); | |
| 230 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XTextWidth", &xlib.XTextWidth)); | |
| 231 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUnloadFont", &xlib.XUnloadFont)); | |
| 232 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateFontCursor", &xlib.XCreateFontCursor)); | |
| 233 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefineCursor", &xlib.XDefineCursor)); | |
| 234 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUndefineCursor", &xlib.XUndefineCursor)); | |
| 235 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeCursor", &xlib.XFreeCursor)); | |
| 236 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryPointer", &xlib.XQueryPointer)); | |
| 237 | ✗ | GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XWarpPointer", &xlib.XWarpPointer)); | |
| 238 | |||
| 239 | ✗ | xlib_loaded = true; | |
| 240 | ✗ | ret = GATE_RESULT_OK; | |
| 241 | } while (0); | ||
| 242 | ✗ | return ret; | |
| 243 | } | ||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | struct gate_xlib_keysym_mapping | ||
| 248 | { | ||
| 249 | gate_input_keycode_t keycode; | ||
| 250 | KeySym keysym; | ||
| 251 | }; | ||
| 252 | |||
| 253 | static struct gate_xlib_keysym_mapping const gate_xlib_keysym_mappings[] = | ||
| 254 | { | ||
| 255 | { GATE_KBD_KEY_CTRL, XK_Control_L }, | ||
| 256 | { GATE_KBD_KEY_CTRL, XK_Control_R }, | ||
| 257 | { GATE_KBD_KEY_MENU, XK_Alt_L }, | ||
| 258 | { GATE_KBD_KEY_MENU, XK_Alt_R }, | ||
| 259 | { GATE_KBD_KEY_SHIFT, XK_Shift_L }, | ||
| 260 | { GATE_KBD_KEY_SHIFT, XK_Shift_R }, | ||
| 261 | { GATE_KBD_KEY_ADD, XK_plus }, | ||
| 262 | { GATE_KBD_KEY_SUBTRACT, XK_minus }, | ||
| 263 | { GATE_KBD_KEY_TAB, XK_Tab }, | ||
| 264 | /*{ GATE_KBD_KEY_CAPSLOCK, XK_Caps_Lock },*/ | ||
| 265 | { GATE_KBD_KEY_BACKSPACE, XK_BackSpace }, | ||
| 266 | { GATE_KBD_KEY_RETURN, XK_Return }, | ||
| 267 | { GATE_KBD_KEY_RETURN, XK_KP_Enter }, | ||
| 268 | { GATE_KBD_KEY_ESCAPE, XK_Escape }, | ||
| 269 | { GATE_KBD_KEY_INSERT, XK_Insert }, | ||
| 270 | { GATE_KBD_KEY_DELETE, XK_Delete }, | ||
| 271 | { GATE_KBD_KEY_HOME, XK_Home }, | ||
| 272 | { GATE_KBD_KEY_END, XK_End }, | ||
| 273 | { GATE_KBD_KEY_PGUP, XK_Page_Up }, | ||
| 274 | { GATE_KBD_KEY_PGDOWN, XK_Page_Down }, | ||
| 275 | { GATE_KBD_KEY_LEFT, XK_Left }, | ||
| 276 | { GATE_KBD_KEY_UP, XK_Up }, | ||
| 277 | { GATE_KBD_KEY_RIGHT, XK_Right }, | ||
| 278 | { GATE_KBD_KEY_DOWN, XK_Down }, | ||
| 279 | { GATE_KBD_KEY_PRINT, XK_Print }, | ||
| 280 | /* { GATE_KBD_KEY_BREAK, XK_Break },*/ | ||
| 281 | { GATE_KBD_KEY_SCROLLLOCK, XK_Scroll_Lock }, | ||
| 282 | { GATE_KBD_KEY_NUMLOCK, XK_Num_Lock }, | ||
| 283 | { GATE_KBD_KEY_F1, XK_F1 }, { GATE_KBD_KEY_F2, XK_F2 }, { GATE_KBD_KEY_F3, XK_F3 }, | ||
| 284 | { GATE_KBD_KEY_F4, XK_F4 }, { GATE_KBD_KEY_F5, XK_F5 }, { GATE_KBD_KEY_F6, XK_F6 }, | ||
| 285 | { GATE_KBD_KEY_F7, XK_F7 }, { GATE_KBD_KEY_F8, XK_F8 }, { GATE_KBD_KEY_F9, XK_F9 }, | ||
| 286 | { GATE_KBD_KEY_F10, XK_F10 }, { GATE_KBD_KEY_F11, XK_F11 }, { GATE_KBD_KEY_F12, XK_F12 }, | ||
| 287 | { GATE_KBD_KEY_SPACEBAR, XK_space }, | ||
| 288 | { GATE_KBD_KEY_BRACE_LEFT, XK_braceleft }, | ||
| 289 | { GATE_KBD_KEY_BRACE_RIGHT, XK_braceright }, | ||
| 290 | { GATE_KBD_KEY_A, XK_A }, { GATE_KBD_KEY_B, XK_B }, { GATE_KBD_KEY_C, XK_C }, | ||
| 291 | { GATE_KBD_KEY_D, XK_D }, { GATE_KBD_KEY_E, XK_E }, { GATE_KBD_KEY_F, XK_F }, | ||
| 292 | { GATE_KBD_KEY_G, XK_G }, { GATE_KBD_KEY_H, XK_H }, { GATE_KBD_KEY_I, XK_I }, | ||
| 293 | { GATE_KBD_KEY_J, XK_J }, { GATE_KBD_KEY_K, XK_K }, { GATE_KBD_KEY_L, XK_L }, | ||
| 294 | { GATE_KBD_KEY_M, XK_M }, { GATE_KBD_KEY_N, XK_N }, { GATE_KBD_KEY_O, XK_O }, | ||
| 295 | { GATE_KBD_KEY_P, XK_P }, { GATE_KBD_KEY_Q, XK_Q }, { GATE_KBD_KEY_R, XK_R }, | ||
| 296 | { GATE_KBD_KEY_S, XK_S }, { GATE_KBD_KEY_T, XK_T }, { GATE_KBD_KEY_U, XK_U }, | ||
| 297 | { GATE_KBD_KEY_V, XK_V }, { GATE_KBD_KEY_W, XK_W }, { GATE_KBD_KEY_X, XK_X }, | ||
| 298 | { GATE_KBD_KEY_Y, XK_Y }, { GATE_KBD_KEY_Z, XK_Z }, | ||
| 299 | { GATE_KBD_KEY_A, XK_a }, { GATE_KBD_KEY_B, XK_b }, { GATE_KBD_KEY_C, XK_c }, | ||
| 300 | { GATE_KBD_KEY_D, XK_d }, { GATE_KBD_KEY_E, XK_e }, { GATE_KBD_KEY_F, XK_f }, | ||
| 301 | { GATE_KBD_KEY_G, XK_g }, { GATE_KBD_KEY_H, XK_h }, { GATE_KBD_KEY_I, XK_i }, | ||
| 302 | { GATE_KBD_KEY_J, XK_j }, { GATE_KBD_KEY_K, XK_k }, { GATE_KBD_KEY_L, XK_l }, | ||
| 303 | { GATE_KBD_KEY_M, XK_m }, { GATE_KBD_KEY_N, XK_n }, { GATE_KBD_KEY_O, XK_o }, | ||
| 304 | { GATE_KBD_KEY_P, XK_p }, { GATE_KBD_KEY_Q, XK_q }, { GATE_KBD_KEY_R, XK_r }, | ||
| 305 | { GATE_KBD_KEY_S, XK_s }, { GATE_KBD_KEY_T, XK_t }, { GATE_KBD_KEY_U, XK_u }, | ||
| 306 | { GATE_KBD_KEY_V, XK_v }, { GATE_KBD_KEY_W, XK_w }, { GATE_KBD_KEY_X, XK_x }, | ||
| 307 | { GATE_KBD_KEY_Y, XK_y }, { GATE_KBD_KEY_Z, XK_z }, | ||
| 308 | { GATE_KBD_KEY_0, XK_0 }, | ||
| 309 | { GATE_KBD_KEY_1, XK_1 }, { GATE_KBD_KEY_2, XK_2 }, { GATE_KBD_KEY_3, XK_3 }, | ||
| 310 | { GATE_KBD_KEY_4, XK_4 }, { GATE_KBD_KEY_5, XK_5 }, { GATE_KBD_KEY_6, XK_6 }, | ||
| 311 | { GATE_KBD_KEY_7, XK_7 }, { GATE_KBD_KEY_8, XK_8 }, { GATE_KBD_KEY_9, XK_9 } | ||
| 312 | }; | ||
| 313 | |||
| 314 | static gate_size_t const gate_xlib_keysym_mappings_count = sizeof(gate_xlib_keysym_mappings) / sizeof(gate_xlib_keysym_mappings[0]); | ||
| 315 | |||
| 316 | ✗ | static gate_bool_t gate_xlib_convert_keysym(KeySym key_sym, gate_input_keycode_t* key_code) | |
| 317 | { | ||
| 318 | gate_size_t index; | ||
| 319 | ✗ | for (index = 0; index != gate_xlib_keysym_mappings_count; ++index) | |
| 320 | { | ||
| 321 | ✗ | if (gate_xlib_keysym_mappings[index].keysym == key_sym) | |
| 322 | { | ||
| 323 | ✗ | *key_code = gate_xlib_keysym_mappings[index].keycode; | |
| 324 | ✗ | return true; | |
| 325 | } | ||
| 326 | } | ||
| 327 | ✗ | return false; | |
| 328 | } | ||
| 329 | |||
| 330 | ✗ | static gate_bool_t gate_xlib_resolve_keysym(gate_input_keycode_t key_code, KeySym* key_sym) | |
| 331 | { | ||
| 332 | gate_size_t index; | ||
| 333 | ✗ | for (index = 0; index != gate_xlib_keysym_mappings_count; ++index) | |
| 334 | { | ||
| 335 | ✗ | if (gate_xlib_keysym_mappings[index].keysym == key_code) | |
| 336 | { | ||
| 337 | ✗ | *key_sym = gate_xlib_keysym_mappings[index].keysym; | |
| 338 | ✗ | return true; | |
| 339 | } | ||
| 340 | } | ||
| 341 | ✗ | return false; | |
| 342 | } | ||
| 343 | |||
| 344 | #endif | ||
| 345 | |||
| 346 | #endif | ||
| 347 |