| 3208 | |
| 3209 | template <> |
| 3210 | void Demo::create_window<WsiPlatform::xlib>() { |
| 3211 | const char *display_envar = getenv("DISPLAY"); |
| 3212 | if (display_envar == nullptr || display_envar[0] == '\0') { |
| 3213 | printf("Environment variable DISPLAY requires a valid value.\nExiting ...\n"); |
| 3214 | fflush(stdout); |
| 3215 | exit(1); |
| 3216 | } |
| 3217 | |
| 3218 | XInitThreads(); |
| 3219 | xlib_display = XOpenDisplay(nullptr); |
| 3220 | long visualMask = VisualScreenMask; |
| 3221 | int numberOfVisuals; |
| 3222 | XVisualInfo vInfoTemplate = {}; |
| 3223 | vInfoTemplate.screen = DefaultScreen(xlib_display); |
| 3224 | XVisualInfo *visualInfo = XGetVisualInfo(xlib_display, visualMask, &vInfoTemplate, &numberOfVisuals); |
| 3225 | |
| 3226 | Colormap colormap = |
| 3227 | XCreateColormap(xlib_display, RootWindow(xlib_display, vInfoTemplate.screen), visualInfo->visual, AllocNone); |
| 3228 | |
| 3229 | XSetWindowAttributes windowAttributes = {}; |
| 3230 | windowAttributes.colormap = colormap; |
| 3231 | windowAttributes.background_pixel = 0xFFFFFFFF; |
| 3232 | windowAttributes.border_pixel = 0; |
| 3233 | windowAttributes.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask | ExposureMask; |
| 3234 | |
| 3235 | xlib_window = |
| 3236 | XCreateWindow(xlib_display, RootWindow(xlib_display, vInfoTemplate.screen), 0, 0, width, height, 0, visualInfo->depth, |
| 3237 | InputOutput, visualInfo->visual, CWBackPixel | CWBorderPixel | CWEventMask | CWColormap, &windowAttributes); |
| 3238 | |
| 3239 | XSelectInput(xlib_display, xlib_window, ExposureMask | KeyPressMask); |
| 3240 | XMapWindow(xlib_display, xlib_window); |
| 3241 | XFlush(xlib_display); |
| 3242 | xlib_wm_delete_window = XInternAtom(xlib_display, "WM_DELETE_WINDOW", False); |
| 3243 | XSetWMProtocols(xlib_display, xlib_window, &xlib_wm_delete_window, 1); |
| 3244 | } |
| 3245 | |
| 3246 | void Demo::handle_xlib_event(const XEvent *event) { |
| 3247 | switch (event->type) { |
nothing calls this directly
no outgoing calls
no test coverage detected