Skip to content

Instantly share code, notes, and snippets.

@EmperorPenguin18
Created May 10, 2021 23:24
Show Gist options
  • Save EmperorPenguin18/88459386479460217bdfd4aab68fdcfc to your computer and use it in GitHub Desktop.
Save EmperorPenguin18/88459386479460217bdfd4aab68fdcfc to your computer and use it in GitHub Desktop.
Create an X window
#include <X11/Xlib.h>
#include <assert.h>
#include <unistd.h>
#define NIL (0)
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, blackColor, blackColor);
XSelectInput9dpy, w, StructureNotifyMask);
XMapWindow(dpy, w);
GC gc = XCreateGC(dpy, w, 0, NIL);
XSetForeground(dpy, gc, whiteColor);
for (;;)
{
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify) { break; }
}
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
XFlush(dpy);
sleep(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment