void iupdrvGetCursorPos(int *x, int *y) { Window root, child; int cx, cy; unsigned int keys; Display* display = (Display*)iupdrvGetDisplay(); int screen = XDefaultScreen(display); XQueryPointer(display, RootWindow(display, screen), &root, &child, x, y, &cx, &cy, &keys); }
QWaylandReadbackEglIntegration::QWaylandReadbackEglIntegration(QWaylandDisplay *display) : QWaylandGLIntegration() , mWaylandDisplay(display) { qDebug() << "Using Readback-EGL"; char *display_name = getenv("DISPLAY"); mDisplay = XOpenDisplay(display_name); mScreen = XDefaultScreen(mDisplay); mRootWindow = XDefaultRootWindow(mDisplay); XSync(mDisplay, False); }
// Get the current desktop the WM is displaying bool currentDesktop(long *desktop) { Window rootWin; Display *display = QX11Info::display(); bool result; rootWin = RootWindow(QX11Info::display(), XDefaultScreen(QX11Info::display())); result = getCardinal32Prop(display, rootWin, (char *)"_NET_CURRENT_DESKTOP", desktop); //if( result ) // qDebug("Current Desktop: " + QString::number(*desktop)); return result; }
static inline int x11Screen() { #if PLATFORM(QT) return XDefaultScreen(NetscapePlugin::x11HostDisplay()); #elif PLATFORM(GTK) return gdk_screen_get_number(gdk_screen_get_default()); #elif PLATFORM(EFL) && defined(HAVE_ECORE_X) return ecore_x_screen_index_get(ecore_x_default_screen_get()); #else return 0; #endif }
XWindow::XWindow(const char *title, int x, int y, int width, int height, unsigned long background) { Window rootWindow; screen = XDefaultScreen(display); rootWindow = XRootWindow(display, screen); window = XCreateSimpleWindow(display, rootWindow, x, y, width, height, 0, 0, background); XStoreName(display, window, title); XSelectInput(display, window, ExposureMask | ButtonPressMask); XMapWindow(display, window); }
KeyboardPriority::KeyboardPriority() { char *display_name = NULL; display = XOpenDisplay(display_name); if (display == NULL) { ROS_ERROR_STREAM("[check_for_keyboard_priority] Unable to open X11 display."); ros::shutdown(); exit(1); } screen_ = XDefaultScreen(display); }
// gcc -Wall x11shot2.c -o x11shot2 -lX11 -lX11ext -lpng;./x11shot2 <wid> >/tmp/screenshot.png int main(int argc,char* argv[]){ if(argc<2){ fprintf(stderr, "usage:x11shot2 <wid> >/tmp/screenshot.png\n"); exit(1); } int wid=(int)strtol(argv[1], NULL, 0); sscanf(argv[1], "%x", &wid); XShmSegmentInfo shminfo; int x_off=0,y_off=0; Display *dpy=XOpenDisplay(getenv("DISPLAY")); XImage *image; XWindowAttributes wattr; if (dpy == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } XGetWindowAttributes(dpy,wid,&wattr); fprintf(stderr,"wid:0x%x wattr x:%d y:%d w:%d h:%d begin capture\n" ,wid ,wattr.x,wattr.y ,wattr.width,wattr.height); if(!XShmQueryExtension(dpy)){ fprintf(stderr, "can't not use shm!\n"); exit(1); } int scr = XDefaultScreen(dpy); image = XShmCreateImage(dpy, DefaultVisual(dpy, scr), DefaultDepth(dpy, scr), ZPixmap, NULL, &shminfo, wattr.width,wattr.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; if (!XShmAttach(dpy, &shminfo)) { fprintf(stderr, "Fatal: Failed to attach shared memory!\n"); exit(1); } if(!XShmGetImage(dpy,wid,image,x_off,y_off,AllPlanes)) { die("Can't get image"); } pngstdout(image); XDestroyImage(image); return 0; };
void PSSetPixel(Display *display, int pixel) { if (pixel != current_gray) { current_gray = pixel; if (pixel == XBlackPixel(display, XDefaultScreen(display))) { fprintf(PSfp, "%d G\n", inverse); } else if (pixel == XWhitePixel(display, XDefaultScreen(display))) { fprintf(PSfp, "%d G\n", !inverse); } else { fprintf(PSfp, "%5.3f G\n", ComputeGray(pixel)); } } }
bool X11Device::initDevice(int argc, char *argv[]) { GNASH_REPORT_FUNCTION; char *dpyName = NULL; int num_visuals = 0; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-display") == 0) { dpyName = argv[i+1]; i++; } } _display = XOpenDisplay(dpyName); if (!_display) { log_error("couldn't open X11 display!"); return false; } _root = XDefaultRootWindow(_display); _screennum = XDefaultScreen(_display); _depth = DefaultDepth(_display, _screennum); _colormap = DefaultColormap(_display, _screennum); _screen = DefaultScreenOfDisplay(_display); XVisualInfo visTemplate; // _vid is from the Mesa EGL. The visual for EGL needs to match // the one for X11. std::cerr << "X11 visual from EGL is: " << _vid << std::endl; visTemplate.visualid = _vid; _vinfo = XGetVisualInfo(_display, VisualIDMask, &visTemplate, &num_visuals); std::cerr << "Num Visuals: " << num_visuals << std::endl; if (!_vinfo) { log_error("Error: couldn't get X visual\n"); exit(1); } std::cerr << "X11 visual is: " << _vinfo->visual << std::endl; XFree(_vinfo); // XWindowAttributes gattr; // XGetWindowAttributes(_display, _root, &gattr); // std::cerr << "Width: " << gattr.backing_store << std::endl; // std::cerr << "Width: " << gattr.depth << std::endl; return true; }
PyObject * X11Display_PyObject__glx_supported(X11Display_PyObject * self, PyObject * args) { #ifdef ENABLE_ENGINE_GL_X11 static int attribs[] = { GLX_RGBA, None }; if (glXChooseVisual(self->display, XDefaultScreen(self->display), attribs)) { Py_INCREF(Py_True); return Py_True; } #endif Py_INCREF(Py_False); return Py_False; }
extern void init_wm(struct wm * wm, unsigned options) { std::call_once(one_time_init_flag, one_time_init, wm, options); assert(wm); Display * d = open_display(); int default_screen = XDefaultScreen(d); assert(d); wm->display = d; wm->default_screen = default_screen; }
void iupdrvGetScreenSize(int *width, int *height) { if (!iupdrvCheckMainScreen(width, height)) { Display* display = (Display*)iupdrvGetDisplay(); int screen = XDefaultScreen(display); if (!xGetWorkAreaSize(display, screen, width, height)) { *width = DisplayWidth(display, screen); *height = DisplayHeight(display, screen); } } }
engine::engine(uint w, uint h) : width(w), height(h), curTime(std::chrono::system_clock::now()) { // создали нативное X11 окно XSetWindowAttributes attr; data.display = XOpenDisplay(NULL); if(!data.display) throw std::runtime_error("can't open X11 display"); data.root = XDefaultRootWindow(data.display); data.screen = XDefaultScreen(data.display); data.visual = XDefaultVisual(data.display, data.screen); data.window = XCreateSimpleWindow(data.display,data.root,0,0,width, height,0,0,0); // Настраиваем окно, обрабатываемые события, декорация и пр std::memset(&attr,0,sizeof(attr)); attr.event_mask = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|Button1MotionMask|KeyPressMask; attr.background_pixel = 0xFFFF0000; XWithdrawWindow(data.display,data.window, data.screen); XChangeWindowAttributes(data.display,data.window,CWBackPixel|CWOverrideRedirect|CWSaveUnder|CWEventMask|CWBorderPixel, &attr); XMapWindow(data.display,data.window); XFlush(data.display); // немного паранойи // получаем GL контекст с помощью GLX int glx_attr[] = { GLX_DOUBLEBUFFER, GLX_USE_GL, True, GLX_RGBA, True, GLX_BUFFER_SIZE, 32, GLX_DEPTH_SIZE, 24, None }; auto visual = glXChooseVisual(data.display, data.screen, glx_attr); if(!visual) throw std::runtime_error("[GLX] unable to find visual"); data.context = glXCreateContext(data.display, visual, NULL, True); if(!data.context) throw std::runtime_error("[GLX] unable to create window context"); glXMakeCurrent(data.display, data.window, data.context); // задаем GL вьюпорт во все окно glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height)); }
//========================================= // XInitDisplay //----------------------------------------- XInit XInitDisplay (char *displayname) { // ... // Open the display and save geometry data and // display information about colors, screen, etc. // --- XInit xi; xi.dpy = XOpenDisplay (displayname); if (!xi.dpy) { fprintf (stderr, "xlook: unable to open display %s\n", XDisplayName(displayname) ); exit (1); } xi.DScreen = XDefaultScreen(xi.dpy); xi.DMap = DefaultColormap(xi.dpy,xi.DScreen); xi.DWin = RootWindow (xi.dpy,XDefaultScreen(xi.dpy)); xi.DGc = DefaultGC (xi.dpy,XDefaultScreen(xi.dpy)); xi.DWidth = DisplayWidth (xi.dpy,XDefaultScreen(xi.dpy)); xi.DHeight = DisplayHeight (xi.dpy,XDefaultScreen(xi.dpy)); xi.DDepth = DefaultDepth(xi.dpy,xi.DScreen); xi.DVisual = DefaultVisual(xi.dpy,xi.DScreen); return(xi); }
void XCompositeEglClientBufferIntegration::initializeHardware(QtWayland::Display *) { QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); if (nativeInterface) { mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForIntegration("Display")); if (!mDisplay) qFatal("could not retrieve Display from platform integration"); mEglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForIntegration("EGLDisplay")); if (!mEglDisplay) qFatal("could not retrieve EGLDisplay from platform integration"); } else { qFatal("Platform integration doesn't have native interface"); } mScreen = XDefaultScreen(mDisplay); new XCompositeHandler(m_compositor->handle(), mDisplay); }
PyObject * X11Display_PyObject__get_size(X11Display_PyObject * self, PyObject * args) { int screen = -1, w, h; if (!PyArg_ParseTuple(args, "|i", &screen)) return NULL; XLockDisplay(self->display); if (screen == -1) screen = XDefaultScreen(self->display); w = DisplayWidth(self->display, screen); h = DisplayHeight(self->display, screen); XUnlockDisplay(self->display); return Py_BuildValue("(ii)", w, h); }
bool C4AbstractApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor) { #ifdef GDK_WINDOWING_X11 Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default()); int n; XRRScreenSize * sizes = XRRSizes(dpy, XDefaultScreen(dpy), &n); if (iIndex < n && iIndex >= 0) { *piXRes = sizes[iIndex].width; *piYRes = sizes[iIndex].height; *piBitDepth = 32; return true; } return false; #endif }
void x_init() { atexit(x_destroy); X.dpy = XOpenDisplay(NULL); X.screen = XDefaultScreen(X.dpy); x_init_font(); x_init_window(); x_init_gc(); x_init_input(); /* We don't initialize the pixmap; we'll get a resize soon enough */ XMapWindow(X.dpy, X.window); XSync(X.dpy, 0); }
WindowLinux::WindowLinux(const std::string &windowTitle, const AE::OS::WindowDesc &windowDesc) : Window(windowTitle, windowDesc) { AE::OS::WindowManagerLinux *myWindowManager = static_cast<AE::OS::WindowManagerLinux *>(AE::OS::WindowManager::getInstance()); ::Display *x11display = myWindowManager->_getX11Display(); mScreenID = XDefaultScreen(x11display); XSetWindowAttributes attributes; Visual *visual = XDefaultVisual(x11display, mScreenID); attributes.background_pixel = XWhitePixel(x11display, mScreenID); attributes.border_pixel = XBlackPixel(x11display, mScreenID); // attributes.override_redirect = True; attributes.override_redirect = False; attributes.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | SubstructureNotifyMask | ResizeRedirectMask | KeyPressMask | KeyReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask | // VisibilityChangeMask | FocusChangeMask; mWindow = XCreateWindow(x11display, RootWindow(x11display, mScreenID), windowDesc.position.x, windowDesc.position.y, windowDesc.dimensions.x, windowDesc.dimensions.y, 1, /* border width */ CopyFromParent, /* color depth */ InputOutput, /* window class */ visual, CWBackPixel | CWBorderPixel | CWEventMask | CWOverrideRedirect /* enabled attributes */, &attributes); XStoreName(x11display, mWindow, windowTitle.c_str()); // Override of the 'x' button (the closing one) Atom wmDeleteMessage = XInternAtom(x11display, "WM_DELETE_WINDOW", false); XSetWMProtocols(x11display, mWindow, &wmDeleteMessage, 1); }
void InitializeX11(uint16_t x_off, uint16_t y_off, uint16_t *w, uint16_t *h){ printf("Loading X11 Module\n"); dpy = XOpenDisplay(""); default_src = XDefaultScreen(dpy); CaptureWin = Select_Window(); XGetWindowAttributes(dpy, CaptureWin, &gwa); *w = gwa.width; *h = gwa.height; #ifdef X11_USE_XSHM_ use_shm = XShmQueryExtension(dpy); if(use_shm) { printf("XShmQueryExtension(dpy);\n"); image = XShmCreateImage(dpy, DefaultVisual(dpy, default_src), DefaultDepth(dpy, default_src), ZPixmap, NULL, &shminfo, gwa.width, gwa.height); shminfo.shmid = shmget( IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777); if(shminfo.shmid == -1) { printf("shminfo.shmid == -1\n"); return; } shminfo.shmaddr = image->data = (char*) shmat(shminfo.shmid, 0, 0); shminfo.readOnly = False; if (!XShmAttach(dpy, &shminfo)) { printf("!XShmAttach(dpy, &shminfo)\n"); return; } } else{ #endif /*X11_USE_XSHM_*/ image = XGetImage(dpy, CaptureWin, x_off,y_off, gwa.width,gwa.height, AllPlanes, ZPixmap); #ifdef X11_USE_XSHM_ } #endif /*X11_USE_XSHM_*/ printf("X11 Module Running\n"); }
static void uninit(void) { #ifdef HAVE_DGA2 XDGADevice *dgadevice; #endif if (!vo_config_count) return; if (vo_dga_is_running) { vo_dga_is_running = 0; mp_msg(MSGT_VO, MSGL_V, "vo_dga: in uninit\n"); if (vo_grabpointer) XUngrabPointer(mDisplay, CurrentTime); XUngrabKeyboard(mDisplay, CurrentTime); #ifdef HAVE_DGA2 XDGACloseFramebuffer(mDisplay, mScreen); dgadevice = XDGASetMode(mDisplay, mScreen, 0); if (dgadevice != NULL) { XFree(dgadevice); } #else XF86DGADirectVideo(mDisplay, mScreen, 0); // first disable DirectVideo and then switch mode back! #ifdef HAVE_XF86VM if (vo_dga_vidmodes != NULL) { int screen; screen = XDefaultScreen(mDisplay); mp_msg(MSGT_VO, MSGL_V, "vo_dga: VidModeExt: Switching back..\n"); // seems some graphics adaptors need this more than once ... XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); XFree(vo_dga_vidmodes); } #endif #endif } vo_x11_uninit(); }
void QWaylandXCompositeEGLIntegration::rootInformation(void *data, wl_xcomposite *xcomposite, const char *display_name, uint32_t root_window) { Q_UNUSED(xcomposite); QWaylandXCompositeEGLIntegration *integration = static_cast<QWaylandXCompositeEGLIntegration *>(data); integration->mDisplay = XOpenDisplay(display_name); integration->mRootWindow = (Window) root_window; integration->mScreen = XDefaultScreen(integration->mDisplay); integration->mEglDisplay = eglGetDisplay(integration->mDisplay); eglBindAPI(EGL_OPENGL_ES_API); EGLint minor,major; if (!eglInitialize(integration->mEglDisplay,&major,&minor)) { qFatal("Failed to initialize EGL"); } eglSwapInterval(integration->eglDisplay(),0); qDebug() << "ROOT INFORMATION" << integration->mDisplay << integration->mRootWindow << integration->mScreen; }
int initX11(int *w, int *h) { long screen = 0; XVisualInfo visual; Window rootWin; XSetWindowAttributes wa; unsigned int mask; int depth; int width; int height; if (!(x11Display = XOpenDisplay(":0"))) { printf("Error: Unable to open X display\n"); return -1; } screen = XDefaultScreen(x11Display); width = DisplayWidth(x11Display, screen); height = DisplayHeight(x11Display, screen); rootWin = RootWindow(x11Display, screen); depth = DefaultDepth(x11Display, screen); if (!XMatchVisualInfo(x11Display, screen, depth, TrueColor, &visual)) { printf("Error: Unable to acquire visual\n"); XCloseDisplay(x11Display); return -1; } x11Colormap = XCreateColormap(x11Display, rootWin, visual.visual, AllocNone); wa.colormap = x11Colormap; wa.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; x11Window = XCreateWindow(x11Display, rootWin, 0, 0, width/4*3, height/4*3, 0, CopyFromParent, InputOutput, CopyFromParent, mask, &wa); XMapWindow(x11Display, x11Window); XFlush(x11Display); if (w) *w = width; if (h) *h = height; return 0; }
int main(int argc, char *argv[]) { Display *dpy; if(!(dpy = XOpenDisplay(0x0))) return 1; int scr = XDefaultScreen(dpy); int display_width = DisplayWidth(dpy, scr); GC gc = XDefaultGC(dpy, scr); XColor col = color(dpy, "green"); Window win = XCreateSimpleWindow(dpy, XRootWindow(dpy, scr), display_width - 320 , 150, 300, 100, 3, col.pixel, XBlackPixel(dpy, scr)); XStoreName(dpy, win, "clock"); XSetForeground(dpy, gc, col.pixel); XMapWindow(dpy, win); Atom delete_message = XInternAtom(dpy, "WM_DELETE_WINDOW", True); XSetWMProtocols(dpy, win, &delete_message, 1); XFontStruct *font = get_font(dpy); XTextItem item; item.delta = 10; item.font = font -> fid; time_t now; while (1) { time(&now); char *msg1 = (char *)ctime(&now); XClearArea(dpy, win, 0, 0, 300, 100, False); item.chars = msg1; item.nchars = strlen(msg1) - 1; XDrawText(dpy, win, gc, 50, 50, &item, 1); XFlush(dpy); sleep(1); } XDestroyWindow(dpy, win); XCloseDisplay(dpy); return 1; }
void RotationDaemon::rotate(int angle) { // XXX: technically this is leaked static XRRScreenConfiguration *config = XRRGetScreenInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display())); ushort rotation; ushort size; size = XRRConfigCurrentConfiguration(config, &rotation); short rate; rate = XRRConfigCurrentRate(config); unsigned long timestamp, current_time; timestamp = XRRTimes(QX11Info::display(), XDefaultScreen(QX11Info::display()), ¤t_time); qDebug() << "RotationDaemon::rotate(" << angle << ")"; XRRSetScreenConfigAndRate(QX11Info::display(), config, DefaultRootWindow(QX11Info::display()), size, angle, rate, timestamp); }
/////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////// CXWindow::CXWindow(int SizeX, int SizeY) { display = XOpenDisplay(0); FATAL(!display); win = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, SizeX, SizeY, 0, // Border width 0, 0); { XGCValues gcv; gcv.graphics_exposures = False; gc = XCreateGC(display, win, GCGraphicsExposures, &gcv); } screen = XDefaultScreen(display); pvis = XDefaultVisual(display, screen); map = XDefaultColormap(display,DefaultScreen(display)); XColor exact; XAllocNamedColor(display, map, "white", &White, &exact); XAllocNamedColor(display, map, "black", &Black, &exact); XAllocNamedColor(display, map, "grey41", &DimGrey, &exact); XAllocNamedColor(display, map, "grey82", &LightGrey, &exact); if (pvis->red_mask && pvis->green_mask && pvis->blue_mask) { RMult = MultValue(pvis->red_mask); RMax = MaxValue(pvis->red_mask); GMult = MultValue(pvis->green_mask); GMax = MaxValue(pvis->green_mask); BMult = MultValue(pvis->blue_mask); BMax = MaxValue(pvis->blue_mask); } else RMult = RMax = GMult = GMax = BMult = BMax = 0; wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0); XSetWMProtocols(display, win, &wm_delete_window, 1); XMapRaised(display, win); }
int main( int argc, char * argv[] ) { Display * display; int screen; Window window; char status[ MESSAGE_LENGTH + 1 ]; struct config config; char home_conf[ PATH_MAX + 1 ]; strncpy( home_conf, getenv( "HOME" ), MAX_HOME_LENGTH ); home_conf[ MAX_HOME_LENGTH ] = '\0'; strcat( home_conf, LOCAL_CONF ); if( ! parse_config( "/etc/dstat.conf", & config ) && ! parse_config( home_conf, & config ) ) { config.nof_params = sizeof( DEF_CONFIG ) /sizeof( struct param_arg ); memcpy( config.order, DEF_CONFIG, sizeof( DEF_CONFIG ) ); } for(;;) { display = XOpenDisplay( NULL ); if( display == 0 ) return fail( "can`t open display" ); screen = XDefaultScreen( display ); window = XRootWindow( display, screen ); if( format( status, & config ) != 0 ) return -1; XStoreName( display, window, status ); XCloseDisplay( display ); usleep( PERIOD_MSECS * 1000 ); } return 0; }
static int vdpau_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { AVVDPAUDeviceContext *hwctx = ctx->hwctx; VDPAUDevicePriv *priv; VdpStatus err; VdpGetInformationString *get_information_string; const char *display, *vendor; priv = av_mallocz(sizeof(*priv)); if (!priv) return AVERROR(ENOMEM); ctx->user_opaque = priv; ctx->free = vdpau_device_free; priv->dpy = XOpenDisplay(device); if (!priv->dpy) { av_log(ctx, AV_LOG_ERROR, "Cannot open the X11 display %s.\n", XDisplayName(device)); return AVERROR_UNKNOWN; } display = XDisplayString(priv->dpy); err = vdp_device_create_x11(priv->dpy, XDefaultScreen(priv->dpy), &hwctx->device, &hwctx->get_proc_address); if (err != VDP_STATUS_OK) { av_log(ctx, AV_LOG_ERROR, "VDPAU device creation on X11 display %s failed.\n", display); return AVERROR_UNKNOWN; } GET_CALLBACK(VDP_FUNC_ID_GET_INFORMATION_STRING, get_information_string); GET_CALLBACK(VDP_FUNC_ID_DEVICE_DESTROY, priv->device_destroy); get_information_string(&vendor); av_log(ctx, AV_LOG_VERBOSE, "Successfully created a VDPAU device (%s) on " "X11 display %s\n", vendor, display); return 0; }
void FindPixel (char *windowName, int x, int y, Display *display, Window rootWindow) { Window parent; Window *children; Window *child; XImage *image; XWindowAttributes winAttr; XColor color; XTextProperty wmName; unsigned int noOfChildren; unsigned long pixel; int status; int i, red, green, blue; char **list; status = XGetWMName (display, rootWindow, &wmName); if ((status) && (wmName.value) && (wmName.nitems)) { if (strcmp(windowName, wmName.value) == 0) { XGetWindowAttributes(display, rootWindow, &winAttr); image = XGetImage(display, rootWindow, 0, 0, winAttr.width, winAttr.height, XAllPlanes(), ZPixmap); color.pixel = XGetPixel(image, x, y); XQueryColor(display, XDefaultColormap(display, XDefaultScreen(display)), &color); red = floor(color.red * 0.003891051); green = floor(color.green * 0.003891051); blue = floor(color.blue * 0.003891051); printf("%i %i %i\n", red, green, blue); } } status = XQueryTree (display, rootWindow, &rootWindow, &parent, &children, &noOfChildren); for (i=0; i < noOfChildren; i++) { FindPixel (windowName, x, y, display, children[i]); } XFree ((char*) children); }
static VdpStatus vdp_instance_create(const char *name, int num, vdp_instance_t **pp) { size_t namelen = (name != NULL) ? (strlen(name) + 1) : 0; vdp_instance_t *vi = malloc(sizeof (*vi) + namelen); if (unlikely(vi == NULL)) return VDP_STATUS_RESOURCES; vi->display = XOpenDisplay(name); if (vi->display == NULL) { free(vi); return VDP_STATUS_ERROR; } vi->next = NULL; if (name != NULL) { vi->name = (void *)(vi + 1); memcpy(vi->name, name, namelen); } else vi->name = NULL; if (num >= 0) vi->num = num; else vi->num = XDefaultScreen(vi->display); vi->refs = 1; VdpStatus err = vdp_create_x11(vi->display, vi->num, &vi->vdp, &vi->device); if (err != VDP_STATUS_OK) { XCloseDisplay(vi->display); free(vi); return err; } *pp = vi; return VDP_STATUS_OK; }