Last active
December 15, 2020 07:49
-
-
Save smalinux/e17d48077b86cc2cbada0667ff7bdde8 to your computer and use it in GitHub Desktop.
My X11 simple window creation example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc x11.c -L/usr/X11R6/lib -lX11 -o x11 | |
#include <X11/Xlib.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(void) { | |
Display *d; | |
Window w; | |
XEvent e; | |
const char *msg = "Hello, World!"; | |
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), 10, 10, 100, 100, 1, | |
BlackPixel(d, s), WhitePixel(d, s)); | |
XSelectInput(d, w, ExposureMask | KeyPressMask); | |
XMapWindow(d, w); | |
while (1) { | |
XNextEvent(d, &e); | |
if (e.type == Expose) { | |
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10); | |
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)); | |
} | |
if (e.type == KeyPress) | |
break; | |
} | |
XCloseDisplay(d); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment