commit 89babb3
chld
·
2026-07-12 13:42:32 +0000 UTC
parent 89babb3
init
A
build.sh
+20,
-0
1@@ -0,0 +1,20 @@
2+#!/bin/sh
3+LIBS=`pkgconf --libs x11`
4+OUT=xd
5+PREFIX=${PREFIX:-/usr/local}
6+
7+case $1 in
8+ make)
9+ cc xd.c $LIBS -o $OUT
10+ ;;
11+ install)
12+ [ ! -f xd ] && return
13+ cp $OUT $PREFIX/bin/$OUT
14+ ;;
15+ uninstall)
16+ rm $PREFIX/bin/$OUT
17+ ;;
18+ clean)
19+ rm $OUT
20+ ;;
21+esac
A
xd.c
+96,
-0
1@@ -0,0 +1,96 @@
2+#include<X11/Xlib.h>
3+#include<X11/keysym.h>
4+
5+#include<stdbool.h>
6+#include<stdio.h>
7+#include<stdlib.h>
8+
9+int main(void)
10+{
11+ Display *d=XOpenDisplay(NULL);
12+ if(!d)
13+ {
14+ fprintf(stderr, "couldnt open display\n");
15+ return 1;
16+ }
17+
18+ int s=DefaultScreen(d);
19+
20+ Window w=XCreateSimpleWindow(d, RootWindow(d, s),
21+ 100, 100, 640, 480, 0, BlackPixel(d,s),
22+ WhitePixel(d, s));
23+ XStoreName(d, w, "xd");
24+ /*
25+ * exposure mask redraws lost parts on window manipulation
26+ */
27+ XSelectInput(d, w, ExposureMask|KeyPressMask|
28+ ButtonPressMask|ButtonReleaseMask|
29+ PointerMotionMask);
30+ XMapWindow(d, w);
31+ GC gc=XCreateGC(d, w, 0, NULL);
32+ XSetForeground(d, gc, BlackPixel(d,s));
33+
34+ int z=20;
35+ XSetLineAttributes(d, gc, z, LineSolid, CapRound, JoinRound);
36+
37+ bool dr=false, er=false;
38+ int lx=0, ly=0;
39+
40+ while(1)
41+ {
42+ XEvent ev;
43+ XNextEvent(d, &ev);
44+ XSetLineAttributes(d, gc, z, LineSolid, CapRound, JoinRound);
45+
46+ switch(ev.type)
47+ {
48+ case Expose: break;
49+ case ButtonPress:
50+ if(ev.xbutton.button==Button1)
51+ {
52+ dr=true;
53+ lx=ev.xbutton.x;
54+ ly=ev.xbutton.y;
55+ }
56+ break;
57+ case ButtonRelease:
58+ if(ev.xbutton.button==Button1)
59+ {
60+ dr=false;
61+ }
62+ break;
63+ case MotionNotify:
64+
65+ if (dr)
66+ {
67+ XSetForeground(d, gc, er ? WhitePixel(d,s) : BlackPixel(d,s));
68+ XDrawLine(d,w,gc,lx,ly,
69+ ev.xmotion.x,
70+ ev.xmotion.y);
71+ lx=ev.xmotion.x;
72+ ly=ev.xmotion.y;
73+ XFlush(d);
74+ }
75+ break;
76+ case KeyPress: {
77+ KeySym k=XLookupKeysym(&ev.xkey, 0);
78+ if (k==XK_q||k==XK_Escape) goto q;
79+ if (k==XK_c) XClearWindow(d,w);
80+ if (k==XK_e) er=!er;
81+ if (k==XK_i) z+=5;
82+ if (k==XK_o) z-=5;
83+ if (k==XK_p) z=20;
84+
85+ break;
86+ }
87+ }
88+ }
89+
90+q:
91+ XFreeGC(d,gc);
92+ XDestroyWindow(d,w);
93+ XCloseDisplay(d);
94+ return 0;
95+
96+}
97+