-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: booger
action: commit
revision:
path_from:
revision_from: f138e7660ce6899545538cf04133b9f2e1793ee9:
path_to:
revision_to:

git.thebackupbox.net

booger

git://git.thebackupbox.net/booger

commit f138e7660ce6899545538cf04133b9f2e1793ee9
Author: epoch <epoch@enzo.thebackupbox.net>
Date:   Thu Oct 14 08:31:22 2021 +0000

    made window bigger, added comments, only do some things if the pointer moves, only allocate an image once instead of each loop.

diff --git a/booger.c b/booger.c

index 3afe6086009c7d00cffb10fae0db6d9a588e4ee0..

index ..d2825b9ce6c2bbeb273710b04b117a0eef272bbb 100644

--- a/booger.c
+++ b/booger.c
@@ -4,11 +4,11 @@
 #include <unistd.h>
 #include <string.h>

-#define ZOOM_W 5
-#define ZOOM_H 5
+#define ZOOM_W 7
+#define ZOOM_H 7
 #define ZOOM_F 20

-#define EVENT_MASK ButtonPressMask
+#define EVENT_MASK ButtonPressMask|PointerMotionMask

 int main(int argc, char *argv[]) {
 	XSetWindowAttributes attributes;
@@ -30,13 +30,12 @@ int main(int argc, char *argv[]) {

 	Window root,child;
 	unsigned int mask;
-	int x,y;
-	int rx=0;
-	int ry=0;
-	int wx=0;
-	int wy=0;
+	int x,y;//iterators in for loops
+	int rx=0,ry=0;//root-relative pointer position.
+	int wx=0,wy=0;//because XQueryPointer will crash if the pointers for window-relative position are NULL
 	int startx,starty;
 	int top,left,width,height;
+	char moved=1;
 	class_hint->res_name="booger";
 	class_hint->res_class=class_hint->res_name;
 	setbuf(stdout,0);
@@ -54,30 +53,38 @@ int main(int argc, char *argv[]) {
 	int direction,ascent,descent;
 	XFontStruct *font=XLoadQueryFont(D,"fixed");
 	XCharStruct overall;
+	XImage *image=XGetImage(D,r,0,0,ZOOM_W,ZOOM_H,AllPlanes, XYPixmap);
 	char text[256];
 	while(1) {
 		usleep(100);
 		while(XCheckMaskEvent(D,EVENT_MASK,&e)) {
 			if(e.type == ButtonPress) return 0;
+			if(e.type == MotionNotify) moved=1;
 		}
-		XQueryPointer(D,r,&root,&child,&rx,&ry,&wx,&wy,&mask);
-		XImage *image;
-		left=rx-((ZOOM_W - 1) / 2);
-		if(left < 0) left=0;
-		top=ry-((ZOOM_H - 1) / 2);
-		if(top < 0) top=0;
-		width=ZOOM_W;//need to prevent these from going off-screen and breaking shit
-		height=ZOOM_H;//^
-		if(top + height > sh) height = sh - top;
-		if(left + width > sw) width = sw - left;
-		image = XGetImage(D, r, left, top, width, height, AllPlanes, XYPixmap);
-		startx=0 - rx-((ZOOM_W - 1) / 2);//need to start later if left was < 0 earlier
-		starty=0 - ry-((ZOOM_H - 1) / 2);
+		if(moved) {
+			moved=0;
+			XQueryPointer(D,r,&root,&child,&rx,&ry,&wx,&wy,&mask);
+			left=rx-((ZOOM_W - 1) / 2);
+			if(left < 0) left=0;
+			top=ry-((ZOOM_H - 1) / 2);
+			if(top < 0) top=0;
+			width=ZOOM_W;//need to prevent these from going off-screen and breaking shit
+			height=ZOOM_H;//^
+			if(top + height > sh) height = sh - top;
+			if(left + width > sw) width = sw - left;
+		}
+		//we still need to XGetSubImage even if the pointer didn't move because stuff underneath could still be moving.
+		XGetSubImage(D, r, left, top, width, height, AllPlanes, XYPixmap, image ,0,0);
+
+		//it seems like I don't have to actually do this math because GetPixel outside of the image doesn't hurt.
+		//startx=0 - rx-((ZOOM_W - 1) / 2);//need to start later if left was < 0 earlier
+		//starty=0 - ry-((ZOOM_H - 1) / 2);
 		startx=0;
 		starty=0;
 		for(x=startx;x<ZOOM_W;x++) {
 			for(y=starty;y<ZOOM_H;y++) {
 				XSetForeground(D,gc,XGetPixel(image,x,y));
+				//this is if you want to see the unitialized data between the zoomed pixels. looks pretty.
 				//XFillRectangle(D,pixmap,gc,x * ZOOM_F + 1,y * ZOOM_F + 1,ZOOM_F-1,ZOOM_F-1);
 				XFillRectangle(D,pixmap,gc,x * ZOOM_F,y * ZOOM_F,ZOOM_F,ZOOM_F);
 			}
@@ -87,10 +94,10 @@ int main(int argc, char *argv[]) {
 		XSetForeground(D,gc,WhitePixel(D,DefaultScreen(D)));

 		c.pixel = XGetPixel (image,((ZOOM_W - 1) / 2), ((ZOOM_H - 1) / 2));
-		XQueryColor (D, XDefaultColormap(D, s), &c); //??? what is this for?
+		XQueryColor (D, XDefaultColormap(D, s), &c);
 		snprintf(text,sizeof(text)-1,"#%02x%02x%02x",c.red >> 8,c.green >> 8,c.blue >> 8);
 		printf("%s\n",text);
-		XStoreName(D,w,text);
+		XStoreName(D,w,text);//let's set the window title to the color too. you might find a use for this.
 		XTextExtents(font,text,strlen(text),&direction,&ascent,&descent,&overall);
 		XDrawString(D,pixmap,gc,10,10+(descent+ascent),text,strlen(text));

@@ -100,7 +107,6 @@ int main(int argc, char *argv[]) {
 		gcval.function=GXcopy;
 		XChangeGC(D,gc,GCFunction,&gcval);

-		XFree(image);
 		XCopyArea(D,pixmap,w,gc,0,0,ZOOM_W * ZOOM_F,ZOOM_H * ZOOM_F,0,0);
 		XFlush(D);
 	}

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 11:17:58 2024