commit 956b246
chld
·
2026-07-13 21:03:22 +0000 UTC
parent 99d0d65
background color
1 files changed,
+9,
-5
M
xd.c
M
xd.c
+9,
-5
1@@ -5,7 +5,7 @@
2 #include<stdio.h>
3 #include<stdlib.h>
4
5-int main(void)
6+int main(int ac, char **av)
7 {
8 int wi=640, hi=480;
9
10@@ -18,6 +18,10 @@ int main(void)
11
12 int s=DefaultScreen(d);
13
14+ XColor bg;
15+ XParseColor(d, DefaultColormap(d, s), av[1] ? av[1] : "#ffffff", &bg);
16+ XAllocColor(d, DefaultColormap(d, s), &bg);
17+
18 Window w=XCreateSimpleWindow(d, RootWindow(d, s),
19 100, 100, wi, hi, 0, BlackPixel(d,s),
20 WhitePixel(d, s));
21@@ -28,7 +32,7 @@ int main(void)
22 XMapWindow(d, w);
23 GC gc=XCreateGC(d, w, 0, NULL);
24 Pixmap p=XCreatePixmap(d,w,wi,hi,DefaultDepth(d,s));
25- XSetForeground(d, gc, WhitePixel(d,s));
26+ XSetForeground(d, gc, bg.pixel);
27 XFillRectangle(d, p,gc,0,0,wi,hi);
28 XSetForeground(d, gc, BlackPixel(d,s));
29
30@@ -56,7 +60,7 @@ int main(void)
31 ev.xconfigure.width,ev.xconfigure.height,
32 DefaultDepth(d,s));
33
34- XSetForeground(d, gc, WhitePixel(d,s));
35+ XSetForeground(d, gc, bg.pixel);
36 XFillRectangle(d, l,gc,0,0,ev.xconfigure.width,ev.xconfigure.height);
37
38 int cw = wi < ev.xconfigure.width ? wi : ev.xconfigure.width;
39@@ -91,7 +95,7 @@ int main(void)
40 case MotionNotify:
41 if (dr)
42 {
43- XSetForeground(d, gc, er ? WhitePixel(d,s) : BlackPixel(d,s));
44+ XSetForeground(d, gc, er ? bg.pixel : BlackPixel(d,s));
45 XDrawLine(d,p,gc,lx,ly,
46 ev.xmotion.x,
47 ev.xmotion.y);
48@@ -104,7 +108,7 @@ int main(void)
49 KeySym k=XLookupKeysym(&ev.xkey, 0);
50 if (k==XK_q||k==XK_Escape) goto q;
51 if (k==XK_c) {
52- XSetForeground(d, gc, WhitePixel(d,s));
53+ XSetForeground(d, gc, bg.pixel);
54 XFillRectangle(d, p,gc,0,0,wi,hi);
55 XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
56 XSetForeground(d, gc, BlackPixel(d,s));