commit 72f3398

chld  ·  2026-07-12 13:49:59 +0000 UTC
parent f4a1c9b
gitignore + adapting pixmap?
2 files changed,  +24, -8
M xd.c
+4, -0
1@@ -0,0 +1,4 @@
2+*.out
3+*.a
4+*.so
5+xd
M xd.c
+20, -8
 1@@ -7,6 +7,8 @@
 2 
 3 int main(void)
 4 {
 5+	int wi=640, hi=480;
 6+
 7 	Display *d=XOpenDisplay(NULL);
 8 	if(!d)
 9 	{
10@@ -17,7 +19,7 @@ int main(void)
11 	int s=DefaultScreen(d);
12 
13 	Window w=XCreateSimpleWindow(d, RootWindow(d, s),
14-			100, 100, 640, 480, 0, BlackPixel(d,s), 
15+			100, 100, wi, hi, 0, BlackPixel(d,s), 
16 			WhitePixel(d, s));
17 	XStoreName(d, w, "xd");
18 	XSelectInput(d, w, ExposureMask|KeyPressMask|
19@@ -25,9 +27,9 @@ int main(void)
20 			PointerMotionMask);
21 	XMapWindow(d, w);
22 	GC gc=XCreateGC(d, w, 0, NULL);
23-	Pixmap p=XCreatePixmap(d,w,640,480,DefaultDepth(d,s));
24+	Pixmap p=XCreatePixmap(d,w,wi,hi,DefaultDepth(d,s));
25 	XSetForeground(d, gc, WhitePixel(d,s));
26-	XFillRectangle(d, p,gc,0,0,640,480);
27+	XFillRectangle(d, p,gc,0,0,wi,hi);
28 	XSetForeground(d, gc, BlackPixel(d,s));
29 
30 	int z=20;
31@@ -44,9 +46,19 @@ int main(void)
32 
33 		switch(ev.type)
34 		{
35-			case Expose:
36-				XCopyArea(d,p,w,gc,0,0,640,480,0,0);
37+			case Expose: {
38+				XWindowAttributes at;
39+				if(XGetWindowAttributes(d,w,&at))
40+				{
41+					wi=at.width;
42+					hi=at.height;
43+				} else {
44+					fprintf(stderr, "couldnt resize pixmap\n");
45+				}
46+
47+				XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
48 				break;
49+			}
50 			case ButtonPress:
51 				if(ev.xbutton.button==Button1)
52 				{
53@@ -69,7 +81,7 @@ int main(void)
54 					XDrawLine(d,p,gc,lx,ly,
55 							ev.xmotion.x,
56 							ev.xmotion.y);
57-					XCopyArea(d,p,w,gc,0,0,640,480,0,0);
58+					XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
59 					lx=ev.xmotion.x;
60 					ly=ev.xmotion.y;
61 				}
62@@ -79,9 +91,9 @@ int main(void)
63 				if (k==XK_q||k==XK_Escape) goto q;
64 				if (k==XK_c) {
65 					XSetForeground(d, gc, WhitePixel(d,s));
66-					XFillRectangle(d, p,gc,0,0,640,480);
67+					XFillRectangle(d, p,gc,0,0,wi,hi);
68 					XClearWindow(d,w);
69-					XCopyArea(d,p,w,gc,0,0,640,480,0,0);
70+					XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
71 				}
72 				if (k==XK_e) er=!er;
73 				if (k==XK_i) z+=5;