Created
September 30, 2017 13:59
-
-
Save emersion/cc4909ba3581928871192822fc96d00b to your computer and use it in GitHub Desktop.
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
// 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