x11 - XShmGetImage fails without any error displayed -
i have tried below simple program use xshmgetimage desktop image.
#include <x11/xlib.h> #include <x11/xatom.h> #include <x11/xutil.h> #include <x11/extensions/xshm.h> #include <x11/extensions/xfixes.h> #include <stdio.h> #include <stdlib.h> #include <sys/ipc.h> #include <sys/shm.h> int main(int argc, const char *argv[]) { int screen; window root; display* display; ximage* img, int shm=0; xshmsegmentinfo shminfo; /* desktop screen resolution */ int width=1360; int height=768; display = xopendisplay(getenv("display")); shm = xshmqueryextension(display); if ( shm) { printf ("ha... queryextension successful..\n"); int scr = xdefaultscreen (display); printf ("\n screen number %d ", scr); img = xshmcreateimage (display, defaultvisual(display, scr), defaultdepth ( display, scr), zpixmap, null, &shminfo, width, height); printf ("\n bytes per line %d ", img->bytes_per_line); shminfo.shmid = shmget (ipc_private, img->bytes_per_line * img->height, ipc_creat | 0777); if ( shminfo.shmid == -1 ) { printf ("\n can not shared memory ..."); } else { printf ("\n greate able shared memory.."); } shminfo.shmaddr = img->data =shmat (shminfo.shmid, 0,0); shminfo.readonly = false; if (!xshmattach (display, &shminfo)) { printf ("\n unable attach now.."); } else { printf ("\n super.. able attach shared memory extension "); } if ( !xshmgetimage (display, rootwindow(display, defaultscreen(display)), img, 0,0, allplanes)){ printf ("\n should have image in ximage"); } else { printf ("\n ooops.. wrong."); } }
output:
ha... queryextension successful.. screen number 0 bytes per line 5440 greate able shared memory.. super.. able attach shared memory extension ooops.. wrong.
unfortunately, xshmgetimage fails, , no information displayed. please help.
there blunder side. actually, works properly, , misinterpreted return value of xshmgetimage api().
the correct 1 is
if ( !xshmgetimage (display, rootwindow(display, defaultscreen(display)), img, 0,0, allplanes)){ printf ("\n ooops.. wrong."); } else { printf ("\n should have image in ximage"); }
Comments
Post a Comment