-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx.c
69 lines (60 loc) · 1.42 KB
/
x.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "output.h"
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#define PIX 10 /* side of a pixel */
Display *d;
Window w;
XEvent e;
int s;
void cleanup()
{
XDestroyWindow(d,w);
XCloseDisplay(d);
}
void init()
{
d = XOpenDisplay(NULL);
if(!d) {
printf("Couldn't open display\n");
exit(1);
}
s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d,s), 0, 0, X*PIX, Y*PIX, 0, 0, WhitePixel(d,s));
Atom delWindow = XInternAtom(d, "WM_DELETE_WINDOW", 0);
XSetWMProtocols(d,w,&delWindow, 1);
/* make the window floating and fixed-size */
XSizeHints *sizeh = NULL;
sizeh = XAllocSizeHints();
sizeh->flags = PSize | PMaxSize | PMinSize;
sizeh->height = sizeh->min_width = sizeh->max_width = X*PIX;
sizeh->width = sizeh->min_height = sizeh->max_height = Y*PIX;
XSetWMProperties(d, w, NULL, NULL, NULL, 0, sizeh, NULL, NULL);
XFree(sizeh);
XSelectInput(d,w,ExposureMask);
XMapWindow(d,w);
}
void output(char field[Y][X])
{
XSetForeground(d,DefaultGC(d,s),WhitePixel(d,s));
XFillRectangle(d,w,DefaultGC(d,s),0,0,X*PIX,Y*PIX);
XSetForeground(d,DefaultGC(d,s),BlackPixel(d,s));
for(int i = 0; i < Y; i++) {
for(int j = 0; j < X; j++) {
if(field[i][j]==ALIVE)
XFillRectangle(d,w,DefaultGC(d,s),i*PIX,j*PIX,PIX,PIX);
}
}
XFlush(d);
}
int process_input()
{
if(XPending(d)) {
XNextEvent(d,&e);
if(e.type == ClientMessage) {
return MSG_EXIT;
}
}
return 0;
}