GCC Code Coverage Report


Directory: src/gate/
File: src/gate/platform/posix/xlib.h
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 86 100 86.0%
Functions: 1 3 33.3%
Branches: 80 168 47.6%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, 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 #if defined(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
42 #ifndef XUTIL_DEFINE_FUNCTIONS
43 #define XUTIL_DEFINE_FUNCTIONS
44 #endif
45 #include <X11/Xlib.h>
46 #include <X11/Xutil.h>
47 #include <X11/keysym.h>
48 #include <X11/Xatom.h>
49
50 typedef struct gate_xlib
51 {
52 Display* (*XOpenDisplay) (const char* display_name);
53 Window (*XDefaultRootWindow) (Display* display);
54 int (*XCloseDisplay) (Display* display);
55 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);
56 Atom (*XInternAtom) (Display* display, const char* atom_name, Bool only_if_exists);
57 int (*XChangeProperty) (Display* display, Window w, Atom property, Atom type, int format, int mode, const unsigned char* data, int nelements);
58 int (*XSetWMHints) (Display* display, Window w, XWMHints* wm_hints);
59 int (*XMapWindow) (Display* display, Window w);
60 int (*XStoreName) (Display* display, Window w, const char* window_name);
61 int (*XPending) (Display* display);
62 int (*XNextEvent) (Display* display, XEvent* event_return);
63 int (*XDestroyWindow) (Display* display, Window w);
64 Bool (*XCheckWindowEvent) (Display* display, Window w, long event_mask, XEvent* event_return);
65 int (*XGetInputFocus) (Display* display, Window* focus_return, int* revert_to_return);
66 KeyCode (*XKeysymToKeycode) (Display* display, KeySym keysym);
67 KeySym (*XStringToKeysym) (const char* str);
68 Status (*XSendEvent) (Display* display, Window w, Bool propagate, long event_mask, XEvent* event_send);
69 Status (*XGetWindowAttributes) (Display* display, Window w, XWindowAttributes* window_attributes_return);
70 int (*XFlush) (Display* display);
71 int (*XDefaultScreen) (Display*);
72 Colormap (*XDefaultColormap) (Display*, int);
73 int (*XQueryColor) (Display*, Colormap, XColor*);
74 int (*XResizeWindow) (Display* display, Window w, unsigned int width, unsigned int height);
75 Bool (*XCheckMaskEvent) (Display* display, long event_mask, XEvent* event_return);
76 KeySym (*XLookupKeysym) (XKeyEvent* key_event, int index);
77 int (*XSelectInput) (Display* display, Window w, long event_mask);
78 Status (*XMatchVisualInfo) (Display* display, int screen, int depth, int clazz, XVisualInfo* vinfo_return);
79 Colormap (*XCreateColormap) (Display* display, Window w, Visual* visual, int alloc);
80 void (*XSetWMProtocols) (Display* display, Window w, Atom* protocols, int count);
81 int (*XAutoRepeatOff) (Display* display);
82 int (*XAutoRepeatOn) (Display* display);
83 /********/
84 Status (*XInitThreads) (void);
85 int (*XDefaultDepth) (Display* display, int screen_number);
86 Visual* (*XDefaultVisual) (Display* display, int screen_number);
87 int (*XBitmapPad) (Display* display);
88 Window (*XRootWindow) (Display* display, int screen_number);
89 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);
90 int (*XConnectionNumber) (Display* display);
91 int (*XMoveResizeWindow) (Display* display, Window w, int x, int y, unsigned int width, unsigned int height);
92 int (*XSetInputFocus) (Display* display, Window focus, int revert_to, Time time);
93 int (*XUnmapWindow) (Display* display, Window w);
94
95 int (*XSetGraphicsExposures)(Display* display, GC gc, Bool graphics_exposures);
96 Pixmap (*XCreatePixmap) (Display* display, Drawable d, unsigned int width, unsigned int height, unsigned int depth);
97 int (*XFreePixmap) (Display* display, Pixmap pixmap);
98 GC (*XCreateGC) (Display* display, Drawable d, unsigned long valuemask, XGCValues* values);
99 int (*XFreeGC) (Display* display, GC gc);
100 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);
101 XImage* (*XGetImage) (Display* display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format);
102 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);
103 int (*XDestroyImage) (XImage* ximage);
104
105 Status (*XAllocColor) (Display* display, Colormap colormap, XColor* screen_in_out);
106 unsigned long(*XBlackPixel) (Display* display, int screen_number);
107 unsigned long(*XWhitePixel) (Display* display, int screen_number);
108 int (*XSetForeground) (Display* display, GC gc, unsigned long foreground);
109 unsigned long(*XGetPixel) (XImage* ximage, int x, int y);
110 int (*XPutPixel) (XImage* ximage, int x, int y, unsigned long pixel);
111 int (*XDrawPoint) (Display* display, Drawable d, GC gc, int x, int y);
112 int (*XDrawLine) (Display* display, Drawable d, GC gc, int x1, int y1, int x2, int y2);
113 int (*XDrawLines) (Display* display, Drawable d, GC gc, XPoint* points, int npoints, int mode);
114 int (*XFillPolygon) (Display* display, Drawable d, GC gc, XPoint* points, int npoints, int shape, int mode);
115 int (*XDrawRectangle) (Display* display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height);
116 int (*XFillRectangle) (Display* display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height);
117
118 Font (*XLoadFont) (Display* display, char const* name);
119 int (*XSetFont) (Display* display, GC gc, Font font);
120 char** (*XListFonts) (Display* display, char const* pattern, int maxnames, int* actual_count_return);
121 int (*XFreeFontNames) (char** list);
122 int (*XDrawString) (Display* display, Drawable d, GC gc, int x, int y, char const* string, int length);
123 int (*XFreeFontInfo) (char** names, XFontStruct* free_info, int actual_count);
124 XFontStruct*(*XQueryFont) (Display* display, XID font_ID);
125 int (*XTextWidth) (XFontStruct* font_struct, char const* string, int count);
126 int (*XUnloadFont) (Display* display, Font font);
127 Cursor (*XCreateFontCursor) (Display* display, unsigned int shape);
128 int (*XDefineCursor) (Display* display, Window w, Cursor cursor);
129 int (*XUndefineCursor) (Display* display, Window w);
130 int (*XFreeCursor) (Display* display, Cursor cursor);
131 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);
132 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);
133
134 } gate_xlib_t;
135
136 static gate_xlib_t xlib = GATE_INIT_EMPTY;
137 static gate_bool_t volatile xlib_loaded = false;
138
139 2 static gate_result_t gate_xlib_load_functions(void)
140 {
141 static gate_string_t xlib_lib_name = GATE_STRING_INIT_STATIC("libX11.so");
142 2 gate_result_t ret = GATE_RESULT_FAILED;
143 static gate_library_t xlib_lib = NULL;
144
145 do
146 {
147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (xlib_loaded)
148 {
149 ret = GATE_RESULT_OK;
150 break;
151 }
152
153
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (xlib_lib == NULL)
154 {
155 2 ret = gate_library_open(&xlib_lib_name, &xlib_lib, GATE_LIBRARY_FLAG_DEFAULT);
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret);
157 }
158
159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XOpenDisplay", &xlib.XOpenDisplay));
160
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultRootWindow", &xlib.XDefaultRootWindow));
161
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCloseDisplay", &xlib.XCloseDisplay));
162
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateWindow", &xlib.XCreateWindow));
163
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XInternAtom", &xlib.XInternAtom));
164
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XChangeProperty", &xlib.XChangeProperty));
165
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetWMHints", &xlib.XSetWMHints));
166
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMapWindow", &xlib.XMapWindow));
167
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XStoreName", &xlib.XStoreName));
168
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPending", &xlib.XPending));
169
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XNextEvent", &xlib.XNextEvent));
170
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDestroyWindow", &xlib.XDestroyWindow));
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCheckWindowEvent", &xlib.XCheckWindowEvent));
172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetInputFocus", &xlib.XGetInputFocus));
173
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XKeysymToKeycode", &xlib.XKeysymToKeycode));
174
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XStringToKeysym", &xlib.XStringToKeysym));
175
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSendEvent", &xlib.XSendEvent));
176
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetWindowAttributes", &xlib.XGetWindowAttributes));
177
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFlush", &xlib.XFlush));
178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultScreen", &xlib.XDefaultScreen));
179
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultColormap", &xlib.XDefaultColormap));
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryColor", &xlib.XQueryColor));
181
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XResizeWindow", &xlib.XResizeWindow));
182
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCheckMaskEvent", &xlib.XCheckMaskEvent));
183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XLookupKeysym", &xlib.XLookupKeysym));
184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSelectInput", &xlib.XSelectInput));
185
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMatchVisualInfo", &xlib.XMatchVisualInfo));
186
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateColormap", &xlib.XCreateColormap));
187
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetWMProtocols", &xlib.XSetWMProtocols));
188
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAutoRepeatOff", &xlib.XAutoRepeatOff));
189
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAutoRepeatOn", &xlib.XAutoRepeatOn));
190
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XInitThreads", &xlib.XInitThreads));
191
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultDepth", &xlib.XDefaultDepth));
192
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefaultVisual", &xlib.XDefaultVisual));
193
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XBitmapPad", &xlib.XBitmapPad));
194
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XRootWindow", &xlib.XRootWindow));
195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XTranslateCoordinates", &xlib.XTranslateCoordinates));
196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XConnectionNumber", &xlib.XConnectionNumber));
197
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XMoveResizeWindow", &xlib.XMoveResizeWindow));
198
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetInputFocus", &xlib.XSetInputFocus));
199
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUnmapWindow", &xlib.XUnmapWindow));
200
201
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetGraphicsExposures", &xlib.XSetGraphicsExposures));
202
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreatePixmap", &xlib.XCreatePixmap));
203
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreePixmap", &xlib.XFreePixmap));
204
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateGC", &xlib.XCreateGC));
205
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeGC", &xlib.XFreeGC));
206
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateImage", &xlib.XCreateImage));
207
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetImage", &xlib.XGetImage));
208
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPutImage", &xlib.XPutImage));
209
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDestroyImage", &xlib.XDestroyImage));
210
211
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XAllocColor", &xlib.XAllocColor));
212
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XBlackPixel", &xlib.XBlackPixel));
213
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XWhitePixel", &xlib.XWhitePixel));
214
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetForeground", &xlib.XSetForeground));
215
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XGetPixel", &xlib.XGetPixel));
216
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XPutPixel", &xlib.XPutPixel));
217
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawPoint", &xlib.XDrawPoint));
218
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawLine", &xlib.XDrawLine));
219
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawLines", &xlib.XDrawLines));
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFillPolygon", &xlib.XFillPolygon));
221
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawRectangle", &xlib.XDrawRectangle));
222
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFillRectangle", &xlib.XFillRectangle));
223
224
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XLoadFont", &xlib.XLoadFont));
225
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XSetFont", &xlib.XSetFont));
226
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XListFonts", &xlib.XListFonts));
227
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeFontNames", &xlib.XFreeFontNames));
228
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDrawString", &xlib.XDrawString));
229
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeFontInfo", &xlib.XFreeFontInfo));
230
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryFont", &xlib.XQueryFont));
231
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XTextWidth", &xlib.XTextWidth));
232
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUnloadFont", &xlib.XUnloadFont));
233
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XCreateFontCursor", &xlib.XCreateFontCursor));
234
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XDefineCursor", &xlib.XDefineCursor));
235
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XUndefineCursor", &xlib.XUndefineCursor));
236
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XFreeCursor", &xlib.XFreeCursor));
237
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XQueryPointer", &xlib.XQueryPointer));
238
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_function_name(xlib_lib, "XWarpPointer", &xlib.XWarpPointer));
239
240 2 xlib_loaded = true;
241 2 ret = GATE_RESULT_OK;
242 } while (0);
243 2 return ret;
244 }
245
246
247
248 struct gate_xlib_keysym_mapping
249 {
250 gate_input_keycode_t keycode;
251 KeySym keysym;
252 };
253
254 static struct gate_xlib_keysym_mapping const gate_xlib_keysym_mappings[] =
255 {
256 { GATE_KBD_KEY_CTRL, XK_Control_L },
257 { GATE_KBD_KEY_CTRL, XK_Control_R },
258 { GATE_KBD_KEY_MENU, XK_Alt_L },
259 { GATE_KBD_KEY_MENU, XK_Alt_R },
260 { GATE_KBD_KEY_SHIFT, XK_Shift_L },
261 { GATE_KBD_KEY_SHIFT, XK_Shift_R },
262 { GATE_KBD_KEY_ADD, XK_plus },
263 { GATE_KBD_KEY_SUBTRACT, XK_minus },
264 { GATE_KBD_KEY_TAB, XK_Tab },
265 /*{ GATE_KBD_KEY_CAPSLOCK, XK_Caps_Lock },*/
266 { GATE_KBD_KEY_BACKSPACE, XK_BackSpace },
267 { GATE_KBD_KEY_RETURN, XK_Return },
268 { GATE_KBD_KEY_RETURN, XK_KP_Enter },
269 { GATE_KBD_KEY_ESCAPE, XK_Escape },
270 { GATE_KBD_KEY_INSERT, XK_Insert },
271 { GATE_KBD_KEY_DELETE, XK_Delete },
272 { GATE_KBD_KEY_HOME, XK_Home },
273 { GATE_KBD_KEY_END, XK_End },
274 { GATE_KBD_KEY_PGUP, XK_Page_Up },
275 { GATE_KBD_KEY_PGDOWN, XK_Page_Down },
276 { GATE_KBD_KEY_LEFT, XK_Left },
277 { GATE_KBD_KEY_UP, XK_Up },
278 { GATE_KBD_KEY_RIGHT, XK_Right },
279 { GATE_KBD_KEY_DOWN, XK_Down },
280 { GATE_KBD_KEY_PRINT, XK_Print },
281 /* { GATE_KBD_KEY_BREAK, XK_Break },*/
282 { GATE_KBD_KEY_SCROLLLOCK, XK_Scroll_Lock },
283 { GATE_KBD_KEY_NUMLOCK, XK_Num_Lock },
284 { GATE_KBD_KEY_F1, XK_F1 }, { GATE_KBD_KEY_F2, XK_F2 }, { GATE_KBD_KEY_F3, XK_F3 },
285 { GATE_KBD_KEY_F4, XK_F4 }, { GATE_KBD_KEY_F5, XK_F5 }, { GATE_KBD_KEY_F6, XK_F6 },
286 { GATE_KBD_KEY_F7, XK_F7 }, { GATE_KBD_KEY_F8, XK_F8 }, { GATE_KBD_KEY_F9, XK_F9 },
287 { GATE_KBD_KEY_F10, XK_F10 }, { GATE_KBD_KEY_F11, XK_F11 }, { GATE_KBD_KEY_F12, XK_F12 },
288 { GATE_KBD_KEY_SPACEBAR, XK_space },
289 { GATE_KBD_KEY_BRACE_LEFT, XK_braceleft },
290 { GATE_KBD_KEY_BRACE_RIGHT, XK_braceright },
291 { GATE_KBD_KEY_A, XK_A }, { GATE_KBD_KEY_B, XK_B }, { GATE_KBD_KEY_C, XK_C },
292 { GATE_KBD_KEY_D, XK_D }, { GATE_KBD_KEY_E, XK_E }, { GATE_KBD_KEY_F, XK_F },
293 { GATE_KBD_KEY_G, XK_G }, { GATE_KBD_KEY_H, XK_H }, { GATE_KBD_KEY_I, XK_I },
294 { GATE_KBD_KEY_J, XK_J }, { GATE_KBD_KEY_K, XK_K }, { GATE_KBD_KEY_L, XK_L },
295 { GATE_KBD_KEY_M, XK_M }, { GATE_KBD_KEY_N, XK_N }, { GATE_KBD_KEY_O, XK_O },
296 { GATE_KBD_KEY_P, XK_P }, { GATE_KBD_KEY_Q, XK_Q }, { GATE_KBD_KEY_R, XK_R },
297 { GATE_KBD_KEY_S, XK_S }, { GATE_KBD_KEY_T, XK_T }, { GATE_KBD_KEY_U, XK_U },
298 { GATE_KBD_KEY_V, XK_V }, { GATE_KBD_KEY_W, XK_W }, { GATE_KBD_KEY_X, XK_X },
299 { GATE_KBD_KEY_Y, XK_Y }, { GATE_KBD_KEY_Z, XK_Z },
300 { GATE_KBD_KEY_A, XK_a }, { GATE_KBD_KEY_B, XK_b }, { GATE_KBD_KEY_C, XK_c },
301 { GATE_KBD_KEY_D, XK_d }, { GATE_KBD_KEY_E, XK_e }, { GATE_KBD_KEY_F, XK_f },
302 { GATE_KBD_KEY_G, XK_g }, { GATE_KBD_KEY_H, XK_h }, { GATE_KBD_KEY_I, XK_i },
303 { GATE_KBD_KEY_J, XK_j }, { GATE_KBD_KEY_K, XK_k }, { GATE_KBD_KEY_L, XK_l },
304 { GATE_KBD_KEY_M, XK_m }, { GATE_KBD_KEY_N, XK_n }, { GATE_KBD_KEY_O, XK_o },
305 { GATE_KBD_KEY_P, XK_p }, { GATE_KBD_KEY_Q, XK_q }, { GATE_KBD_KEY_R, XK_r },
306 { GATE_KBD_KEY_S, XK_s }, { GATE_KBD_KEY_T, XK_t }, { GATE_KBD_KEY_U, XK_u },
307 { GATE_KBD_KEY_V, XK_v }, { GATE_KBD_KEY_W, XK_w }, { GATE_KBD_KEY_X, XK_x },
308 { GATE_KBD_KEY_Y, XK_y }, { GATE_KBD_KEY_Z, XK_z },
309 { GATE_KBD_KEY_0, XK_0 },
310 { GATE_KBD_KEY_1, XK_1 }, { GATE_KBD_KEY_2, XK_2 }, { GATE_KBD_KEY_3, XK_3 },
311 { GATE_KBD_KEY_4, XK_4 }, { GATE_KBD_KEY_5, XK_5 }, { GATE_KBD_KEY_6, XK_6 },
312 { GATE_KBD_KEY_7, XK_7 }, { GATE_KBD_KEY_8, XK_8 }, { GATE_KBD_KEY_9, XK_9 }
313 };
314
315 static gate_size_t const gate_xlib_keysym_mappings_count = sizeof(gate_xlib_keysym_mappings) / sizeof(gate_xlib_keysym_mappings[0]);
316
317 static gate_bool_t gate_xlib_convert_keysym(KeySym key_sym, gate_input_keycode_t* key_code)
318 {
319 gate_size_t index;
320 for (index = 0; index != gate_xlib_keysym_mappings_count; ++index)
321 {
322 if (gate_xlib_keysym_mappings[index].keysym == key_sym)
323 {
324 *key_code = gate_xlib_keysym_mappings[index].keycode;
325 return true;
326 }
327 }
328 return false;
329 }
330
331 static gate_bool_t gate_xlib_resolve_keysym(gate_input_keycode_t key_code, KeySym* key_sym)
332 {
333 gate_size_t index;
334 for (index = 0; index != gate_xlib_keysym_mappings_count; ++index)
335 {
336 if (gate_xlib_keysym_mappings[index].keysym == key_code)
337 {
338 *key_sym = gate_xlib_keysym_mappings[index].keysym;
339 return true;
340 }
341 }
342 return false;
343 }
344
345 #endif /* GATE_SYS_POSIX */
346
347 #endif
348