-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: booger action: blob revision: path_from: booger.c revision_from: refs/heads/master: path_to: revision_to:
/ booger.c
refs/heads/master:/booger.c #include <X11/Xlib.h> #include <X11/Xutil.h> #include <stdio.h> #include <unistd.h> #include <string.h> #define ZOOM_W 7 #define ZOOM_H 7 #define ZOOM_F 20 #define EVENT_MASK ButtonPressMask|PointerMotionMask int main(int argc, char *argv[]) { XSetWindowAttributes attributes; XClassHint *class_hint=XAllocClassHint(); XColor c; Display *D = XOpenDisplay((char *)NULL); Screen *S = XDefaultScreenOfDisplay(D); Visual *V = XDefaultVisualOfScreen(S); int s = XDefaultScreen(D); int depth = XDefaultDepth(D,s); Window r = XRootWindow(D,s); Window w; GC gc; int sw=XWidthOfScreen(S); int sh=XHeightOfScreen(S); Window root,child; unsigned int mask; 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); w = XCreateWindow(D,r,0,0,ZOOM_W * ZOOM_F, ZOOM_H * ZOOM_F, 1, depth,InputOutput,V, 0, &attributes); gc = XCreateGC(D,w,0,0); Pixmap pixmap = XCreatePixmap(D,w,ZOOM_W * ZOOM_F, ZOOM_H * ZOOM_F,depth); XSelectInput(D,w,EVENT_MASK); XStoreName(D,w,"booger"); XSetClassHint(D,w,class_hint); XMapWindow(D,w); XGrabPointer(D, r, 1, EVENT_MASK, GrabModeAsync, GrabModeAsync, r, None, CurrentTime); XEvent e; XGCValues gcval; 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; } 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); } } gcval.function=GXxor; XChangeGC(D,gc,GCFunction,&gcval); 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); 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);//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)); //outline the center pixel XDrawRectangle(D,pixmap,gc,((ZOOM_W - 1) / 2) * ZOOM_F -1 ,((ZOOM_H - 1) / 2) * ZOOM_F-1,ZOOM_F +1, ZOOM_F +1); gcval.function=GXcopy; XChangeGC(D,gc,GCFunction,&gcval); XCopyArea(D,pixmap,w,gc,0,0,ZOOM_W * ZOOM_F,ZOOM_H * ZOOM_F,0,0); XFlush(D); } return 0; }
-- Response ended
-- Page fetched on Sun Jun 2 12:46:38 2024