Tk_GetVisual(3tk)
β¨ NAME β¨
Tk_GetVisual β it translates a string into a visual, bestie π
(yes this is a page from the Tk library procedures manual, section 3tk, and it's lowkey iconic)
π¦ SYNOPSIS π¦
#include <tk.h>
Visual *
Tk_GetVisual(interp, tkwin, string, depthPtr, colormapPtr)
π ARGUMENTS π
Tcl_Interp *interp(in) β the interpreter we throw error messages into, so it can be the one to break the bad news πTk_Window tkwin(in) β the token for the window this visual is gonna be used inconst char *string(in) β the string that says which visual you want. Valid formats are down below, keep scrolling π«Άint *depthPtr(out) β the depth of the returned visual gets parked right hereColormap *colormapPtr(out) β if it's notNULL, we go find a suitable colormap for the visual and stash its identifier here
πΈ DESCRIPTION πΈ
So Tk_GetVisual takes a string describing a visual, and finds a suitable X Visual you can use in tkwin, if there is one. If there is, you get back a pointer to the X Visual structure, and the number of bits per pixel for it gets stored at *depthPtr. No cap, that's the whole deal β¨
But if the string is unrecognizable, or if no suitable visual could be found at all? Then it returns NULL, and Tk_GetVisual leaves an error message in the interpreter interp's result. Not me getting rejected by the X server π
And if colormap is non-NULL, Tk_GetVisual also goes and locates an appropriate colormap to use with the resulting visual, storing its X identifier at *colormapPtr. Two for one, we love to see it π
π How to spell your visual π
The string argument says which visual you want, and it can be any one of these formats:
class depthβ a class name, then an integer depth, and any amount of white space in between (including literally none, she's flexible like that). Theclasspicks what sort of visual you're after and has to be one ofdirectcolor,grayscale,greyscale,pseudocolor,staticcolor,staticgray,staticgrey, ortruecolorβ or a unique abbreviation, because we're chill. Thedepthsays how many bits per pixel the visual needs. If possible,Tk_GetVisualreturns a visual with exactly that depth; but if there's no visual at the depth you asked for, it looks first for a visual with greater depth, and then one with less depth. It's giving "we'll figure something out" energy π§defaultβ just use the default visual fortkwin's screen. Simple. Clean. Main character behavior πpathNameβ use the visual of the window given bypathName. Important:pathNamehas to be the name of a window on the same screen astkwin, or it's a no from us πnumberβ use the visual whose X identifier isnumberbest ?depth?β okay bestie, this one chooses the "best possible" visual, using these rules in decreasing order of priority:- A visual that has exactly the desired depth is best, followed by a visual with greater depth than requested (but as little extra as possible, don't be greedy π ), followed by a visual with less depth than requested (but as great a depth as possible)
- If no depth is specified at all, then the deepest available visual is chosen
pseudocoloris better thantruecolorordirectcolor, which are better thanstaticcolor, which is better thanstaticgrayorgrayscale- The default visual for the screen is better than any other visual
The best rules are a strict priority order, so rule (a) beats (b) beats (c) beats (d). Don't shuffle them, that's not the vibe π₯
π CREDITS π
The idea for Tk_GetVisual, and the very first implementation, came from Paul Mackerras. Giving credit where credit is due, periodt π«Ά
β KEYWORDS β
colormap, screen, visual
and that's the whole page, bestie!! this one's from the Tk manual, version 4.0, filed under Tk_GetVisual(3tk) β go forth and pick ur visuals wisely πβ¨ππ¦πΈ
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms