commit 8a298c4
chld
·
2026-07-12 14:04:28 +0000 UTC
parent 72f3398
adapt pixmap size
1 files changed,
+27,
-12
M
xd.c
M
xd.c
+27,
-12
1@@ -22,7 +22,7 @@ int main(void)
2 100, 100, wi, hi, 0, BlackPixel(d,s),
3 WhitePixel(d, s));
4 XStoreName(d, w, "xd");
5- XSelectInput(d, w, ExposureMask|KeyPressMask|
6+ XSelectInput(d, w, ExposureMask|KeyPressMask|StructureNotifyMask|
7 ButtonPressMask|ButtonReleaseMask|
8 PointerMotionMask);
9 XMapWindow(d, w);
10@@ -46,19 +46,35 @@ int main(void)
11
12 switch(ev.type)
13 {
14- case Expose: {
15- XWindowAttributes at;
16- if(XGetWindowAttributes(d,w,&at))
17+ case Expose:
18+ XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
19+ break;
20+ case ConfigureNotify:
21+ if(ev.xconfigure.width!=wi||ev.xconfigure.height!=hi)
22 {
23- wi=at.width;
24- hi=at.height;
25- } else {
26- fprintf(stderr, "couldnt resize pixmap\n");
27- }
28+ Pixmap l=XCreatePixmap(d,w,
29+ ev.xconfigure.width,ev.xconfigure.height,
30+ DefaultDepth(d,s));
31
32- XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
33+ XSetForeground(d, gc, WhitePixel(d,s));
34+ XFillRectangle(d, l,gc,0,0,wi,hi);
35+
36+ int cw = wi < ev.xconfigure.width ? wi : ev.xconfigure.width;
37+ int ch = hi < ev.xconfigure.height ? hi : ev.xconfigure.height;
38+
39+ XCopyArea(d,p,l,gc,0,0,\
40+ //ev.xconfigure.width,ev.xconfigure.height,
41+ cw,ch,
42+ 0,0); /* copy old pixmap to new pixmap */
43+ XFreePixmap(d,p);
44+ p=l;
45+
46+ wi=ev.xconfigure.width;
47+ hi=ev.xconfigure.height;
48+
49+ XCopyArea(d,p,w,gc,0,0,wi,hi,0,0);
50+ }
51 break;
52- }
53 case ButtonPress:
54 if(ev.xbutton.button==Button1)
55 {
56@@ -74,7 +90,6 @@ int main(void)
57 }
58 break;
59 case MotionNotify:
60-
61 if (dr)
62 {
63 XSetForeground(d, gc, er ? WhitePixel(d,s) : BlackPixel(d,s));