#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void) {
   Display *d;
   Window w;
   XEvent e;
   int s;
 
   d = XOpenDisplay(NULL);
   if (d == NULL) {
      fprintf(stderr, "Cannot open display\n");
      exit(1);
   }
 
   s = DefaultScreen(d);
   w = XCreateSimpleWindow(d, RootWindow(d, s), 1, 1, 100, 100, 1,
                           BlackPixel(d, s), BlackPixel(d, s));

   XSelectInput(d, w, ExposureMask | KeyPressMask);
   XMapWindow(d, w);

   FILE *fp = fopen("/tmp/windowid", "w+");
   fprintf(fp, "0x%x", w);
   fclose(fp);

   while (1) {
      XNextEvent(d, &e);
      if (e.type == KeyPress)
         break;
   }
 
   XCloseDisplay(d);
   return 0;
}

// ref: https://rosettacode.org/wiki/Window_creation/X11#Xlib
// to compile this in TCL:
// $ tce-load -wi gcc glibc_base-dev libX11-dev
// $ gcc -lX11 create_black_window.c -o create_black_window
//
// to compile this in Devuan:
// $ sudo apt install libx11-dev
// $ gcc -o create_black_window create_black_window.c -lX11
//
// NOTE: If directory from fopen line above doesn't exist, the binary throws a segmentation fault!

