Subversion Repositories Krakow BASIC

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
39 nishi 1
/* $Id: x11.c 39 2024-09-06 12:56:29Z nishi $ */
2
 
3
#include <stdbool.h>
4
#include <stddef.h>
5
#include <stdint.h>
6
 
7
#include <X11/Xlib.h>
8
#include <X11/Xutil.h>
9
 
10
bool stop = false;
11
bool dorender = false;
12
 
13
const int fontwidth = 7;
14
const int fontheight = 14;
15
const int textwidth = 80;
16
const int textheight = 25;
17
int width;
18
int height;
19
 
20
GC gc;
21
Window w;
22
Display* d;
23
 
24
int bgc = 0;
25
int fgc = 15;
26
 
27
uint32_t colors[] = {
28
	0x000000
29
};
30
 
31
void render(void){
32
	XSetForeground(d, gc, colors[bgc]);
33
	XFillRectangle(d, w, gc, 0, 0, width, height);
34
	XFlush(d);
35
}
36
 
37
void* x11_thread(void* arg){
38
	width = fontwidth * textwidth;
39
	height = fontheight * textheight;
40
 
41
	d = XOpenDisplay(NULL);
42
	w = XCreateSimpleWindow(d, RootWindow(d, 0), 0, 0, width, height, 3, WhitePixel(d, 0), BlackPixel(d, 0));
43
	XStoreName(d, w, "Krakow BASIC");
44
 
45
	XSizeHints* size = XAllocSizeHints();
46
	size->flags = PMinSize | PMaxSize;
47
	size->min_width = size->max_width = width;
48
	size->min_height = size->max_height = height;
49
	XSetWMNormalHints(d, w, size);
50
	XFree(size);
51
 
52
	XEvent ev;
53
 
54
	XSelectInput(d, w, ExposureMask);
55
	XMapWindow(d, w);
56
	XFlush(d);
57
 
58
	gc = XCreateGC(d, DefaultRootWindow(d), 0, 0);
59
 
60
	render();
61
 
62
	while(1){
63
		if(dorender){
64
			render();
65
			dorender = false;
66
		}else if(XPending(d) > 0){
67
			XNextEvent(d, &ev);
68
			if(ev.type == Expose){
69
				render();
70
			}
71
		}
72
	}
73
	stop = true;
74
	return arg;
75
}