/* XBSetVisual - set the visual class for a window and colormap Input Parameters: . nc - number of colors. Use the maximum of the visual if nc == 0. Use nc = 2 for black and white displays. */ int XBSetVisual( XBWindow *XBWin, int q_default_visual, Colormap cmap, int nc ){ if (q_default_visual) { XBWin->vis = DefaultVisual( XBWin->disp, XBWin->screen ); XBWin->depth = DefaultDepth(XBWin->disp,XBWin->screen); if (!cmap) XBWin->cmap = DefaultColormap( XBWin->disp, XBWin->screen ); else XBWin->cmap = cmap; } else { /* Try to match to some popular types */ XVisualInfo vinfo; if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 24, DirectColor, &vinfo)) { XBWin->vis = vinfo.visual; XBWin->depth = 24; } else if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 8, PseudoColor, &vinfo)) { XBWin->vis = vinfo.visual; XBWin->depth = 8; } else if (XMatchVisualInfo( XBWin->disp, XBWin->screen, DefaultDepth(XBWin->disp,XBWin->screen), PseudoColor, &vinfo)) { XBWin->vis = vinfo.visual; XBWin->depth = DefaultDepth(XBWin->disp,XBWin->screen); } else { XBWin->vis = DefaultVisual( XBWin->disp, XBWin->screen ); XBWin->depth = DefaultDepth(XBWin->disp,XBWin->screen); } /* There are other types; perhaps this routine should accept a "hint" on which types to look for. */ XBWin->cmap = (Colormap) 0; } /* reset the number of colors from info on the display, the colormap */ XBInitColors( XBWin, cmap, nc ); return 0; }
static vmResult X_video_detect(void) { XVisualInfo *vinfo; int nvinfo; XVisualInfo vtmp; static int desired_classes[] = { PseudoColor, DirectColor, GrayScale, TrueColor, StaticColor, StaticGray }; int cl; static char *classes[] = { "StaticGray", "GrayScale", "StaticColor", "PseudoColor", "TrueColor", "DirectColor" }; if (x11_dpy == NULL) return vmNotAvailable; vtmp.screen = x11_screen; x11_depth = DefaultDepth(x11_dpy, x11_screen); // most optimistic cases first for (cl = 0; cl < 6; cl++) { x11_class = desired_classes[cl]; if (XMatchVisualInfo(x11_dpy, x11_screen, 8, x11_class, &vtmp) || XMatchVisualInfo(x11_dpy, x11_screen, x11_depth, x11_class, &vtmp)) break; } if (cl >= 6) { module_logger(&X_Video, _L|LOG_ERROR | LOG_USER, _("no compatible color classes found, cannot display\n")); return vmNotAvailable; } x11_depth = vtmp.depth; if (x11_depth <= 4) { module_logger(&X_Video, _L|LOG_ERROR | LOG_USER, _("video_X: Cannot use visual with only %d colors.\n"), 1 << (x11_depth - 1)); // return vmNotAvailable; } x11_visual = vtmp.visual; module_logger(&X_Video, _L|L_0, _("color class = %s\n"), classes[x11_class]); module_logger(&X_Video, _L|LOG_USER, _("Detected X Window System...\n")); return vmOk; }
void SWRenderDisplayWindowProvider::create(DisplayWindowSite *new_site, const DisplayWindowDescription &description) { site = new_site; flip_timer_set = false; refresh_rate = description.get_refresh_rate(); if (!refresh_rate) // Default the refresh rate to 100 if not defined refresh_rate = 100; swap_interval = description.get_swap_interval(); #ifdef WIN32 window.create(site, description); #elif !defined(__APPLE__) ::Display *disp = window.get_display(); int bpp = 24; XVisualInfo visual_info; int screen = DefaultScreen(disp); //RootWindow(disp, 0); if (XMatchVisualInfo(disp, screen, 24, TrueColor, &visual_info)) {bpp = 24;} else if (XMatchVisualInfo(disp, screen, 16, TrueColor, &visual_info)) {bpp = 16;} else if (XMatchVisualInfo(disp, screen, 15, TrueColor, &visual_info)) {bpp = 15;} else if (XMatchVisualInfo(disp, screen, 32, TrueColor, &visual_info)) {bpp = 32;} else if (XMatchVisualInfo(disp, screen, 8, PseudoColor, &visual_info)) {bpp = 8;} else if (XMatchVisualInfo(disp, screen, 8, GrayScale, &visual_info)) {bpp = 8;} else if (XMatchVisualInfo(disp, screen, 8, StaticGray, &visual_info)) {bpp = 8;} else if (XMatchVisualInfo(disp, screen, 1, StaticGray, &visual_info)) {bpp = 1;} else { throw Exception("Cannot match visual info"); } window.create(&visual_info, site, description); #endif gc = GraphicContext(new SWRenderGraphicContextProvider(this)); }
NativeWindowType X11Windowing::createNativeWindow(NativeDisplayType _dpy, int width, int height) { Display *dpy = (Display *) _dpy; long defaultScreen = DefaultScreen( dpy ); Window rootWindow = RootWindow(dpy, defaultScreen); int depth = DefaultDepth(dpy, defaultScreen); XVisualInfo *visualInfo = new XVisualInfo; XMatchVisualInfo(dpy, defaultScreen, depth, TrueColor, visualInfo); if (visualInfo == NULL) { fprintf(stderr, "couldn't find matching visual\n"); return NULL; } Colormap x11Colormap = XCreateColormap(dpy, rootWindow, visualInfo->visual, AllocNone); XSetWindowAttributes sWA; sWA.colormap = x11Colormap; sWA.event_mask = StructureNotifyMask | ExposureMask; sWA.background_pixel = 0; sWA.border_pixel = 0; unsigned int attributes_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; Window win = XCreateWindow( dpy, rootWindow, 0, 0, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, attributes_mask, &sWA); XMapWindow(dpy, win); XFlush(dpy); return NativeWindowType(win); }
static gboolean gst_gl_context_egl_choose_format (GstGLContext * context, GError ** error) { #if GST_GL_HAVE_WINDOW_X11 if (GST_GL_IS_WINDOW_X11 (context->window)) { GstGLWindow *window = gst_gl_context_get_window (context); GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window); gint ret; window_x11->visual_info = g_new0 (XVisualInfo, 1); ret = XMatchVisualInfo (window_x11->device, window_x11->screen_num, window_x11->depth, TrueColor, window_x11->visual_info); gst_object_unref (window); if (ret == 0) { g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Failed to match XVisualInfo"); return FALSE; } } #endif return TRUE; }
PetscErrorCode PetscDrawXiSetVisualClass(PetscDraw_X *XiWin) { XVisualInfo vinfo; PetscFunctionBegin; if (XMatchVisualInfo(XiWin->disp,XiWin->screen,24,DirectColor,&vinfo)) { XiWin->vis = vinfo.visual; } else if (XMatchVisualInfo(XiWin->disp,XiWin->screen,8,PseudoColor,&vinfo)) { XiWin->vis = vinfo.visual; } else if (XMatchVisualInfo(XiWin->disp,XiWin->screen,DefaultDepth(XiWin->disp,XiWin->screen),PseudoColor,&vinfo)) { XiWin->vis = vinfo.visual; } else { XiWin->vis = DefaultVisual(XiWin->disp,XiWin->screen); } PetscFunctionReturn(0); }
XWin() { // Initializes the display and screen m_x11Display = XOpenDisplay(nullptr); if (!m_x11Display) throw std::runtime_error("Unable to open X display"); m_x11Screen = XDefaultScreen(m_x11Display); // Gets the window parameters Window sRootWindow = RootWindow(m_x11Display, m_x11Screen); int depth = DefaultDepth(m_x11Display, m_x11Screen); XMatchVisualInfo(m_x11Display, m_x11Screen, depth, TrueColor, &m_x11Visual); m_x11Colormap = XCreateColormap(m_x11Display, sRootWindow, m_x11Visual.visual, AllocNone); XSetWindowAttributes attrs; attrs.colormap = m_x11Colormap; attrs.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; // Creates the X11 window m_x11Window = XCreateWindow( m_x11Display, RootWindow(m_x11Display, m_x11Screen), 0, 0, 800, 480, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWBorderPixel | CWEventMask | CWColormap, &attrs); XMapWindow(m_x11Display, m_x11Window); XFlush(m_x11Display); }
/* This routine gets the visual class (PseudoColor, etc) and returns it. It finds the default visual. Possible returns are PseudoColor StaticColor DirectColor TrueColor GrayScale StaticGray */ int XBSetVisualClass( XBWindow *XBWin ){ XVisualInfo vinfo; if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 24, DirectColor, &vinfo)) { XBWin->vis = vinfo.visual; return 0; } if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 8, PseudoColor, &vinfo)) { XBWin->vis = vinfo.visual; return 0; } if (XMatchVisualInfo( XBWin->disp, XBWin->screen, DefaultDepth(XBWin->disp,XBWin->screen), PseudoColor, &vinfo)) { XBWin->vis = vinfo.visual; return 0; } XBWin->vis = DefaultVisual( XBWin->disp, XBWin->screen ); return 0; }
XVisualInfo *glXGetVisualFromFBConfig(Display *display, GLXFBConfig config) { if (xDisplay == NULL) { xDisplay = display; } XVisualInfo *visual = (XVisualInfo *)malloc(sizeof(XVisualInfo)); XMatchVisualInfo(display, 0, 16, TrueColor, visual); return visual; }
// ###################################################################### AutomateXWin::AutomateXWin(const char* win_name) : itsDisplay(NULL), itsScreen(0), itsImage(NULL), itsWidth(0), itsHeight(0), itsDepth(0) { char *dispName = XDisplayName(NULL); unsigned num_tries; int event_base, error_base; int major_version, minor_version; itsDisplay = XOpenDisplay(dispName); if(!itsDisplay) LFATAL("XOpenDisplay(%s) failed\n", dispName); if (!XTestQueryExtension (itsDisplay, &event_base, &error_base, &major_version, &minor_version)) { XCloseDisplay(itsDisplay); LFATAL("XTest extension not supported on server"); } LINFO("XTestQueryExtension passed."); LINFO("XTest information for server \"%s\":", DisplayString(itsDisplay)); LINFO(" Major version: %d", major_version); LINFO(" Minor version: %d", minor_version); LINFO(" First event number: %d", event_base); LINFO(" First error number: %d", error_base); itsScreen = DefaultScreen(itsDisplay); itsRootWin = RootWindow(itsDisplay, itsScreen); for(num_tries=0;;) { itsWindow = XWindowByName(itsDisplay, itsRootWin, win_name); if(itsWindow) break; if(++num_tries == 100) LFATAL("XWindowByName\n"); usleep(20000); } XFlush(itsDisplay); XSync(itsDisplay, False); #ifdef USE_SHM if(!XShmQueryExtension(itsDisplay)) LFATAL("XShmQueryExtension"); #endif GetWindowGeometry(); if(!XMatchVisualInfo(itsDisplay, itsScreen, itsDepth, DirectColor, &itsVInfo)) { return; } }
static Window createWindow(JNIEnv* env, Display *disp, int screen, jint window_mode, X11PeerInfo *peer_info, int x, int y, int width, int height, jboolean undecorated, long parent_handle, jboolean resizable) { Window parent = (Window)parent_handle; Window win; XSetWindowAttributes attribs; unsigned int attribmask; XVisualInfo vis_info; if ( !XMatchVisualInfo(disp, screen, DefaultDepth(disp, screen), TrueColor, &vis_info) ) { throwException(env, "Failed to acquire X visual."); return false; } cmap = XCreateColormap(disp, parent, vis_info.visual, AllocNone); if (!checkXError(env, disp)) { return false; } attribs.colormap = cmap; attribs.border_pixel = 0; attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; attribmask = CWColormap | CWEventMask | CWBorderPixel | CWBackPixel; if (isLegacyFullscreen(window_mode)) { attribmask |= CWOverrideRedirect; attribs.override_redirect = True; } win = XCreateWindow(disp, parent, x, y, width, height, 0, vis_info.depth, InputOutput, vis_info.visual, attribmask, &attribs); current_depth = vis_info.depth; current_visual = vis_info.visual; if (!checkXError(env, disp)) { XFreeColormap(disp, cmap); return false; } if (undecorated) { // Use Motif decoration hint property and hope the window manager respects them setDecorations(disp, win, 0); } if (RootWindow(disp, screen) == parent_handle) { // only set hints when Display.setParent isn't used updateWindowBounds(disp, win, x, y, width, height, JNI_TRUE, resizable); updateWindowHints(env, disp, win); } #define NUM_ATOMS 1 Atom protocol_atoms[NUM_ATOMS] = {XInternAtom(disp, "WM_DELETE_WINDOW", False)/*, XInternAtom(disp, "WM_TAKE_FOCUS", False)*/}; XSetWMProtocols(disp, win, protocol_atoms, NUM_ATOMS); if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) { Atom fullscreen_atom = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False); XChangeProperty(disp, win, XInternAtom(disp, "_NET_WM_STATE", False), XInternAtom(disp, "ATOM", False), 32, PropModeReplace, (const unsigned char*)&fullscreen_atom, 1); } if (!checkXError(env, disp)) { destroyWindow(env, disp, win); return 0; } return win; }
/************************************************************* ... *************************************************************/ enum Display_color_type get_visual(void) { int i, default_depth; Visual *default_visual; XVisualInfo visual_info; /* Try to allocate colors for PseudoColor, TrueColor, * DirectColor, and StaticColor; use black and white * for StaticGray and GrayScale */ default_depth = DefaultDepth(display, screen_number); default_visual = DefaultVisual(display, screen_number); if (default_depth == 1) { /* Must be StaticGray, use black and white */ log_verbose("found B/W display."); return BW_DISPLAY; } i=5; while(!XMatchVisualInfo(display, screen_number, default_depth, i--, &visual_info)); /* log_verbose("Found a %s class visual at default depth.", visual_class[++i]); */ if(i < StaticColor) { /* Color visual classes are 2 to 5 */ /* No color visual available at default depth; * some applications might call XMatchVisualInfo * here to try for a GrayScale visual if they * can use gray to advantage, before giving up * and using black and white */ log_verbose("found grayscale(?) display."); return GRAYSCALE_DISPLAY; } /* Otherwise, got a color visual at default depth */ /* The visual we found is not necessarily the default * visual, and therefore it is not necessarily the one * we used to create our window; however, we now know * for sure that color is supported, so the following * code will work (or fail in a controlled way) */ /* Let's check just out of curiosity: */ if (visual_info.visual != default_visual) { /* log_verbose("Found: %s class visual at default depth", visual_class[i]); */ } log_verbose("color system booted ok."); return COLOR_DISPLAY; }
static int tc_x11source_init_shm(TCX11Source *handle) { Status ret; ret = XMatchVisualInfo(handle->dpy, handle->screen, handle->depth, DirectColor, &handle->vis_info); if (!ret) { tc_log_error(__FILE__, "Can't match visual information"); goto xshm_failed; } handle->image = XShmCreateImage(handle->dpy, handle->vis_info.visual, handle->depth, ZPixmap, NULL, &handle->shm_info, handle->width, handle->height); if (handle->image == NULL) { tc_log_error(__FILE__, "XShmCreateImage failed."); goto xshm_failed_image; } handle->shm_info.shmid = shmget(IPC_PRIVATE, handle->image->bytes_per_line * handle->image->height, IPC_CREAT | 0777); if (handle->shm_info.shmid < 0) { tc_log_error(__FILE__, "failed to create shared memory segment"); goto xshm_failed_image; } handle->shm_info.shmaddr = shmat(handle->shm_info.shmid, NULL, 0); if (handle->shm_info.shmaddr == (void*)-1) { tc_log_error(__FILE__, "failed to attach shared memory segment"); goto xshm_failed_image; } shmctl(handle->shm_info.shmid, IPC_RMID, 0); /* XXX */ handle->image->data = handle->shm_info.shmaddr; handle->shm_info.readOnly = False; ret = XShmAttach(handle->dpy, &handle->shm_info); if (!ret) { tc_log_error(__FILE__, "failed to attach SHM to Xserver"); goto xshm_failed_image; } XSync(handle->dpy, False); handle->mode = TC_X11_MODE_SHM; handle->acquire_image = tc_x11source_acquire_image_shm; handle->fini = tc_x11source_fini_shm; return 0; xshm_failed_image: XDestroyImage(handle->image); handle->image = NULL; xshm_failed: return -1; }
static Visual* I_FindMode(int screen) { XVisualInfo X_visualinfo; int i; const int nice_depths[]={ 8, 16, 15, 32, 24, 0}; // 0 terminated XPixmapFormatValues *pfv; int npfv; fprintf(stderr, "I_FindMode: "); for (i=0; nice_depths[i]!=0; i++) { dest_bpp = nice_depths[i]; if (I_QueryImageTranslation()) { if (XMatchVisualInfo(X_display, screen, dest_bpp, true_color ? TrueColor : PseudoColor, &X_visualinfo)) break; if (devparm) I_PrintMode("no visual like:"); } else if (devparm) I_PrintMode("no translation to:"); } if (nice_depths[i] == 0) I_Error("Unable to find supported visual settings"); X_bpp = dest_bpp; if ((dest_bpp == 24) && (X_opt & 2)) dest_bpp = 32; // kludge for 24bpp /* find out whether depth 24 is sparse or packed */ pfv=XListPixmapFormats(X_display,&npfv); if(pfv) { for(i=0;i<npfv;i++) if(pfv[i].depth==dest_bpp) break; if(i<npfv) { dest_bpp=pfv[i].bits_per_pixel; fprintf(stderr,"(Depth %d / %d BPP) ",X_bpp,dest_bpp); } else fprintf(stderr,"(Depth %d: no pixfmt?) ",dest_bpp); XFree(pfv); } I_InitImageTranslation(); if (true_color) { // Set up colour shifts I_SetColourShift(X_visualinfo.red_mask, &redshift); I_SetColourShift(X_visualinfo.green_mask, &greenshift); I_SetColourShift(X_visualinfo.blue_mask, &blueshift); } I_PrintMode("using"); return X_visualinfo.visual; }
X11RendererPrivate(): use_shm(true) , warn_bad_pitch(true) , num_adaptors(0) , ximage(NULL) , gc(NULL) , pixfmt(VideoFormat::Format_Invalid) { XInitThreads(); #ifndef _XSHM_H_ use_shm = false; #endif //_XSHM_H_ //XvQueryExtension() char* dispName = XDisplayName(NULL); qDebug("X11 open display: %s", dispName); display = XOpenDisplay(dispName); if (!display) { available = false; qWarning("Open X11 display error"); return; } XWindowAttributes attribs; XGetWindowAttributes(display, DefaultRootWindow(display), &attribs); depth = attribs.depth; if (!XMatchVisualInfo(display, DefaultScreen(display), depth, TrueColor, &vinfo)) { qWarning("XMatchVisualInfo error"); available = false; return; } XImage *ximg = NULL; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) { //?? Visual *vs; //depth = //find_depth_from_visuals } else { ximg = XGetImage(display, DefaultRootWindow(display), 0, 0, 1, 1, AllPlanes, ZPixmap); } int ximage_depth = depth; unsigned int mask = 0; if (ximg) { bpp = ximg->bits_per_pixel; if ((ximage_depth+7)/8 != (bpp+7)/8) //24bpp use 32 depth ximage_depth = bpp; mask = ximg->red_mask | ximg->green_mask | ximg->blue_mask; qDebug("color mask: %X R:%1X G:%1X B:%1X", mask, ximg->red_mask, ximg->green_mask, ximg->blue_mask); XDestroyImage(ximg); } if (((ximage_depth + 7) / 8) == 2) { if (mask == 0x7FFF) ximage_depth = 15; else if (mask == 0xFFFF) ximage_depth = 16; } }
PetscErrorCode PetscDrawSetUpColormap_X(Display *display,int screen,Visual *visual,Colormap colormap) { PetscErrorCode ierr; PetscBool sharedcolormap = PETSC_FALSE; XVisualInfo vinfo; PetscFunctionBegin; ierr = PetscOptionsGetBool(NULL,NULL,"-draw_x_shared_colormap",&sharedcolormap,NULL);CHKERRQ(ierr); /* Need to determine if window supports allocating a private colormap, */ if (XMatchVisualInfo(display,screen,24,StaticColor,&vinfo) || XMatchVisualInfo(display,screen,24,TrueColor,&vinfo) || XMatchVisualInfo(display,screen,16,StaticColor,&vinfo) || XMatchVisualInfo(display,screen,16,TrueColor,&vinfo) || XMatchVisualInfo(display,screen,15,StaticColor,&vinfo) || XMatchVisualInfo(display,screen,15,TrueColor,&vinfo)) sharedcolormap = PETSC_TRUE; /* generate the X color map object */ if (sharedcolormap) { ierr = PetscDrawSetUpColormap_Shared(display,screen,visual,colormap);CHKERRQ(ierr); } else { ierr = PetscDrawSetUpColormap_Private(display,screen,visual,colormap);CHKERRQ(ierr); } PetscFunctionReturn(0); }
int XvGrabber::getgrabber() { Tk_Window tk = Tcl::instance().tkmain(); Display* dpy = Tk_Display(tk); int majop, eventbase, errbase; if (XQueryExtension(dpy, "XVideo", &majop, &eventbase, &errbase) == False) return (-1); Window root = DefaultRootWindow(dpy); u_int ngrabbers=0; XvAdaptorInfo* grabbers; if (XvQueryAdaptors(dpy, root, &ngrabbers, &grabbers) != Success) return (-1); if (ngrabbers > 1) fprintf(stderr, "XVgrabber: warning: more than one frame grabber\n"); for (int i=2; i<ngrabbers; i++) { //if ((grabbers[i].type)&XvOutputMask) { if ((grabbers[i].type)&XvInputMask) { fprintf(stderr, "Xv %d grabber: %s\n",i,grabbers[i].name); strncpy(grabber_name, grabbers[i].name, sizeof(grabber_name)); grabID_ = grabbers[i].base_id; } } if (!grabID_) return (-1); XvFreeAdaptorInfo(grabbers); XvQueryEncodings(dpy, grabID_, &nencodings, &encoding); #if 1 printf("Encodings(%d): ", nencodings); for (int i=0; i<nencodings; i++) printf("%s %d %d\n", encoding[i].name, encoding[i].width, encoding[i].height); printf("\n"); #endif XAbrightness = XInternAtom(dpy, "XV_BRIGHTNESS", False); XAcontrast = XInternAtom(dpy, "XV_CONTRAST", False); XAhue = XInternAtom(dpy, "XV_HUE", False); XAsaturation = XInternAtom(dpy, "XV_SATURATION", False); XAencoding = XInternAtom(dpy, "XV_ENCODING", False); XvGetPortAttribute(dpy, grabID_, XAencoding, (int *)&encodingid_); if (!XMatchVisualInfo(dpy, Tk_ScreenNumber(tk), 24, TrueColor, &vinfo_)) return (-1); return (0); }
XVisualInfo *glXChooseVisual(Display *display, int screen, int *attributes) { // apparently can't trust the Display I'm passed? if (g_display == NULL) { g_display = XOpenDisplay(NULL); } int depth = DefaultDepth(g_display, screen); XVisualInfo *visual = (XVisualInfo *)malloc(sizeof(XVisualInfo)); XMatchVisualInfo(g_display, screen, depth, TrueColor, visual); return visual; }
_0xCC::WindowManager::WindowManager(){ Xdisplay = XOpenDisplay(NULL); if (!Xdisplay) { fprintf(stderr, "Couldn't connect to X server\n"); created = false; return ; } Xscreen = DefaultScreen(Xdisplay); Xroot = RootWindow(Xdisplay, Xscreen); visual = new XVisualInfo; XMatchVisualInfo(Xdisplay, DefaultScreen(Xdisplay), 32, TrueColor, visual); cmap = XCreateColormap(Xdisplay, Xroot, visual->visual, AllocNone); }
XVisualInfo * screen::IMPL::get_visual_info() { if (_vi.visual /* TODO: check _vi.visualid */ ) return &_vi; display::pointer disp( _display.lock() ); dsI( disp ); Display * xdisp = disp->_p->_xdisplay; dsI( xdisp); VisualID vid = 0; if (vid) { XVisualInfo *vi, temp; int n; std::memset( &temp, 0, sizeof(temp) ); temp.visualid = vid; if (vi = XGetVisualInfo(xdisp, VisualIDMask, &temp, &n)) { _vi = *vi; XFree(vi); return NULL; } } int screen = this->number(); int depth = this->depth(); dsL("screen depth: "<<depth); bool useDirectColorVisual = false; if ((useDirectColorVisual && XMatchVisualInfo(xdisp, screen, depth, DirectColor, &_vi)) || XMatchVisualInfo(xdisp, screen, depth, TrueColor, &_vi) || XMatchVisualInfo(xdisp, screen, depth, PseudoColor, &_vi) || XMatchVisualInfo(xdisp, screen, depth, StaticColor, &_vi) ) return &_vi; std::memset( &_vi, 0, sizeof(_vi) ); return NULL; }
static int get_best_visual (Display *display, int screen, XVisualInfo *vi) { /* try for a 12 bit visual first, then a 16 bit, then a 24 bit, then 8 bit */ if (XMatchVisualInfo (display, screen, 12, TrueColor, vi)) { } else if (XMatchVisualInfo (display, screen, 15, TrueColor, vi)) { } else if (XMatchVisualInfo (display, screen, 16, TrueColor, vi)) { } else if (XMatchVisualInfo (display, screen, 24, TrueColor, vi)) { } else if (XMatchVisualInfo (display, screen, 32, TrueColor, vi)) { } else if (XMatchVisualInfo (display, screen, 8, PseudoColor, vi)) { /* for our HP boxes */ } else if (XMatchVisualInfo (display, screen, 8, GrayScale, vi)) { } else if (XMatchVisualInfo (display, screen, 4, PseudoColor, vi)) { /* VGA16 server. Argh. */ } else if (XMatchVisualInfo (display, screen, 1, StaticGray, vi)) { /* Mono server. Yuk */ } else { write_log ("Can't obtain appropriate X visual.\n"); return 0; } return 1; }
void setup() { /* create display and get root window */ disp = XOpenDisplay(NULL); int screen = DefaultScreen(disp); Window root = RootWindow(disp, screen); /* set to allow transparency */ XVisualInfo vinfo; XMatchVisualInfo(disp, DefaultScreen(disp), 32, TrueColor, &vinfo); ulng window_flags = CWOverrideRedirect|CWEventMask|CWColormap|CWBorderPixel|CWBackPixel; wa.colormap = XCreateColormap(disp,DefaultRootWindow(disp),vinfo.visual,AllocNone); wa.border_pixel = 0; wa.background_pixel = 0; wa.override_redirect = True; wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; win = XCreateWindow(disp, root, x, y, width, height, 0, vinfo.depth, InputOutput, vinfo.visual, window_flags, &wa); gc = XCreateGC(disp, win, 0, NULL); depth = vinfo.depth; resize(width, height); XMapRaised(disp, win); /* set window in dock mode, so that WM wont f**k with it */ long pval = XInternAtom (disp, "_NET_WM_WINDOW_TYPE_DOCK", False); long prop = XInternAtom (disp, "_NET_WM_WINDOW_TYPE", False); XChangeProperty(disp,win,prop,XA_ATOM,32,PropModeReplace,(uchr*)&pval,1); /* reserve space on the screen */ prop = XInternAtom(disp, "_NET_WM_STRUT_PARTIAL", False); long ptyp = XInternAtom(disp, "CARDINAL", False); int16_t strut[12] = {0, 0, height+y, 0, 0, 0, 0, 0, 0, width, 0, 0}; XChangeProperty(disp,win,prop,ptyp,16,PropModeReplace,(uchr*)strut,12); /* This is for support with legacy WMs */ prop = XInternAtom(disp, "_NET_WM_STRUT", False); unsigned long strut_s[4] = {0, height, 0, 0}; XChangeProperty(disp,win,prop,ptyp,32,PropModeReplace,(uchr*)strut_s,4); /* Appear on all desktops */ prop = XInternAtom(disp, "_NET_WM_DESKTOP", False); long adsk = 0xffffffff; XChangeProperty(disp,win,prop,ptyp,32,PropModeReplace,(uchr*)&adsk,1); XSelectInput(disp, win, ExposureMask); }
bool XVWindow::checkDepth () { XWindowAttributes xwattributes; XGetWindowAttributes (_display, _rootWindow, &xwattributes); _depth = xwattributes.depth; if (_depth != 15 && _depth != 16 && _depth != 24 && _depth != 32) _depth = 24; if (!XMatchVisualInfo (_display, DefaultScreen (_display), _depth, TrueColor, &_XVInfo)) { PTRACE(1, "XVideo\tCould not visual with colordepth of " << _depth << "bits per pixel"); return false; } PTRACE(4, "XVideo\tFound visual with colordepth of " << _depth << "bits per pixel"); return true; }
static void initVisualID(Display *pDisplay, int screen) { static int foundID = 0; if (foundID) return; XVisualInfo info; if (!XMatchVisualInfo(pDisplay, screen, 24, TrueColor, &info)) { fprintf(stderr, "initVisualID: No visual to match required\n"); exit(1); } gXVisual.visualid = info.visualid; gXVisInfo.visualid = info.visualid; foundID = 1; }
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; }
// Map window and return surface for that window. cairo_surface_t * cairo_create_x11_surface(int x, int y, int w, int h) { Display *display; Drawable drawable; int screen; // Screen #. cairo_surface_t *surface; // Error if no open.. if ((display = XOpenDisplay(NULL)) == NULL) // Set display though. exit(1); screen = DefaultScreen(display); // Use primary display. XVisualInfo vinfo; // Match the display settings. XMatchVisualInfo(display, screen, 32, TrueColor, &vinfo); XSetWindowAttributes attr; // We need all 3 of these attributes, or BadMatch: http://stackoverflow.com/questions/3645632/how-to-create-a-window-with-a-bit-depth-of-32 attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); attr.border_pixel = 0; attr.background_pixel = 0; drawable = XCreateWindow(display, DefaultRootWindow(display), // Returns a window (a drawable place). x,y, // Position on screen. w,h, // Width, Height. 0, // Border width. vinfo.depth, InputOutput, vinfo.visual, // Depth, Class, Visual type. CWColormap | CWBorderPixel | CWBackPixel, // Overwritten attributes. &attr); // Apply the Atoms to the new window. // Request that the X server report these events. x_set_wm(drawable, display); XSelectInput(display, drawable, ExposureMask | ButtonPressMask | KeyPressMask); XMapWindow(display, drawable); // Finally create a surface from the window. surface = cairo_xlib_surface_create(display, drawable, vinfo.visual, w, h); //cairo_xlib_surface_set_size(surface, w, h); return surface; }
void create_visual_and_colormap ( Display *display ) { int screen = DefaultScreen ( display ); // Try to create TrueColor map if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) { // Visual found, lets try to create map. map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); truecolor = TRUE; } // Failed to create map. // Use the defaults then. if ( map == None ) { truecolor = FALSE; // Two fields we use. vinfo.visual = DefaultVisual ( display, screen ); vinfo.depth = DefaultDepth ( display, screen ); map = DefaultColormap ( display, screen ); } }
int main(int argc, char* argv[]) { Display* display = XOpenDisplay(NULL); XVisualInfo vinfo; XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo); XSetWindowAttributes attr; attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone); attr.border_pixel = 0; attr.background_pixel = 0; Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr); XSelectInput(display, win, StructureNotifyMask); GC gc = XCreateGC(display, win, 0, 0); Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0); XSetWMProtocols(display, win, &wm_delete_window, 1); XMapWindow(display, win); int keep_running = 1; XEvent event; while (keep_running) { XNextEvent(display, &event); switch(event.type) { case ClientMessage: if (event.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", 1) && (Atom)event.xclient.data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", 1)) keep_running = 0; break; default: break; } } XDestroyWindow(display, win); XCloseDisplay(display); return 0; }
XVisualInfo *glXChooseVisual(Display *display, int screen, int *attributes) { // apparently can't trust the Display I'm passed? if (xDisplay == NULL) { xDisplay = display; } int default_depth = XDefaultDepth(display, screen); if (default_depth != 16 && default_depth != 24) printf("libGL: unusual desktop color depth %d\n", default_depth); XVisualInfo *visual = (XVisualInfo *)malloc(sizeof(XVisualInfo)); if (!XMatchVisualInfo(display, screen, default_depth, TrueColor, visual)) { printf("libGL: XMatchVisualInfo failed in glXChooseVisual\n"); return NULL; } return visual; }
static XVisualInfo* dummyChooseVisual (Display *dpy, int screen, int *attrib_list) { XVisualInfo *ret_visual; XVisualInfo matched_visual; // XXX Just get a visual which can be used to open a window. // Ignore the attribs; we're not going to be doing // any actual rendering in this test. if (XMatchVisualInfo(dpy, screen, DefaultDepth(dpy, screen), TrueColor, &matched_visual) == 0) { return NULL; } ret_visual = malloc(sizeof(XVisualInfo)); memcpy(ret_visual, &matched_visual, sizeof(XVisualInfo)); return ret_visual; }