Skip to content

Instantly share code, notes, and snippets.

@emersion
Created September 30, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersion/cc4909ba3581928871192822fc96d00b to your computer and use it in GitHub Desktop.
Save emersion/cc4909ba3581928871192822fc96d00b to your computer and use it in GitHub Desktop.
// clang -Wall -L/usr/X11R6/lib -lX11 -o xlib-resize xlib-resize.c
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
Display *d;
Window w;
XEvent e;
char *msg = "Hello, World!";
int s;
d = XOpenDisplay(NULL);
if (d == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
int x = 10, y = 10, width = 100, height = 100;
s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d, s), x, y, width, height, 1,
BlackPixel(d, s), WhitePixel(d, s));
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);
printf("press any key to resize\n");
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) {
printf("resizing window\n");
x += 10;
y += 10;
width += 20;
height += 20;
XMoveResizeWindow(d, w, x, y, width, height);
}
}
XCloseDisplay(d);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment