Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <X11/extensions/XShm.h>
- void slop(Window *window, unsigned int *w, unsigned int *h)
- {
- FILE *slop;
- char out[256];
- slop = popen("/usr/bin/slop -f '%i,%w,%h'", "r");
- fread(out, sizeof(out), 1, slop);
- pclose(slop);
- sscanf(out, "%lu,%u,%u", window, w, h);
- }
- int main(int argc, char **argv)
- {
- Display *display;
- Window window_in, window_out;
- GC gc;
- XEvent ev;
- XWindowAttributes attrs;
- XShmSegmentInfo shminfo;
- XImage *image;
- unsigned int w,h;
- slop(&window_in, &w, &h);
- display = XOpenDisplay(NULL);
- gc = DefaultGC(display, DefaultScreen(display));
- window_out = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, w, h, 0, 0, 0);
- XSelectInput(display, window_out, StructureNotifyMask | ButtonPressMask);
- XMapWindow(display, window_out);
- XNextEvent(display, &ev); // wait for window to be mapped
- do {
- XGrabServer(display);
- XGetWindowAttributes(display, window_in, &attrs);
- // doesn't have the bug
- //image = XGetImage(display, window_in, 0, 0, attrs.width, attrs.height, 0xffffffff, ZPixmap);
- // has the bug
- image = XShmCreateImage(display, attrs.visual, attrs.depth, ZPixmap, NULL, &shminfo, attrs.width, attrs.height);
- shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777);
- shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0);
- shminfo.readOnly = False;
- XShmAttach(display, &shminfo);
- XShmGetImage(display, window_in, image, 0, 0, AllPlanes);
- XUngrabServer(display);
- XPutImage(display, window_out, gc, image, 0, 0, 0, 0, attrs.width, attrs.height);
- XShmDetach(display, &shminfo);
- XDestroyImage(image);
- shmdt(shminfo.shmaddr);
- shmctl(shminfo.shmid, IPC_RMID, 0);
- XNextEvent(display, &ev);
- } while (ev.type != ButtonPress);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement