]> git.cworth.org Git - fips/blobdiff - test/util-x11.c
util-x11: Rework init_window interface to accept XVisualInfo
[fips] / test / util-x11.c
index 7ab6ebc894fffa298b532621e1e6e5cfe0c37f0d..e3b35572d726a531b565ce70a00967c8019d804f 100644 (file)
 
 #include "util-x11.h"
 
-void
-util_x11_init_display (Display **dpy)
+Display *
+util_x11_init_display (void)
 {
-        *dpy = XOpenDisplay (NULL);
+       Display *dpy;
+
+        dpy = XOpenDisplay (NULL);
 
-        if (*dpy == NULL) {
+        if (dpy == NULL) {
                 fprintf(stderr, "Failed to open display %s\n",
                         XDisplayName(NULL));
                 exit (1);
         }
+
+       return dpy;
 }
 
 void
@@ -42,24 +46,38 @@ util_x11_fini_display (Display *dpy)
         XCloseDisplay (dpy);
 }
 
-void
-util_x11_init_window (Display *dpy, Window *window)
+Window
+util_x11_init_window (Display *dpy, XVisualInfo *visual_info)
 {
        int width = 64;
        int height = 64;
+       Window root, window;
+       XSetWindowAttributes window_attr;
+       Colormap colormap;
+       unsigned long window_mask, event_mask;
+       unsigned long black;
 
+       root = DefaultRootWindow (dpy);
+       black = BlackPixel (dpy, DefaultScreen (dpy));
+       colormap = XCreateColormap (dpy, root, visual_info->visual, AllocNone);
+       event_mask = KeyPressMask | StructureNotifyMask | ExposureMask;
 
+       window_mask = 0;
+       window_mask |= CWBackPixel;     window_attr.background_pixel = black;
+       window_mask |= CWBorderPixel;   window_attr.border_pixel = black;
+       window_mask |= CWColormap;      window_attr.colormap = colormap;
+       window_mask |= CWEventMask;     window_attr.event_mask = event_mask;
 
-        *window = XCreateSimpleWindow(dpy, DefaultRootWindow (dpy),
-                                     0, 0, width, height, 0,
-                                     BlackPixel (dpy, DefaultScreen (dpy)),
-                                     BlackPixel (dpy, DefaultScreen (dpy)));
+        window = XCreateWindow(dpy, root, 0, 0, width, height, 0,
+                              visual_info->depth, InputOutput,
+                              visual_info->visual,
+                              window_mask, &window_attr);
 
-        XSelectInput(dpy, *window,
-                     KeyPressMask | StructureNotifyMask | ExposureMask);
+        XMapWindow (dpy, window);
 
-        XMapWindow (dpy, *window);
+       XFreeColormap (dpy, colormap);
 
+       return window;
 }
 
 void