Tk_GetGC(3)
β¨ NAME β¨
Tk_GetGC, Tk_FreeGC β maintain database of read-only graphics contexts. No cap, that's the whole vibe. This page is from the Tk Library Procedures manual, and it's literally the guide to sharing GCs like a pro. π
πΈ SYNOPSIS πΈ
okay so here's the code, bestie β copy it exactly, no typos:
#include <tk.h>
GC
Tk_GetGC(tkwin, valueMask, valuePtr)
Tk_FreeGC(display, gc)
That's it. Slay. β¨
π ARGUMENTS π
okay so these are the arguments, and each one matters, so pay attention:
Tk_Window tkwin(in) β Token for window in which the graphics context will be used. Like, which window is this GC for? That one.unsigned long valueMask(in) β Mask of bits (such asGCForegroundorGCStipple) indicating which fields of*valuePtrare valid. This is the "what do I actually care about" mask.XGCValues *valuePtr(in) β Pointer to structure describing the desired values for the graphics context. It's giving "here's what I want my GC to look like."Display *display(in) β Display for whichgcwas allocated. Which display? That one.GC gc(in) β X identifier for graphics context that is no longer needed. Must have been allocated byTk_GetGC. Important: it MUST have been allocated byTk_GetGC, okay? Don't just pass any random GC.
π¦ DESCRIPTION π¦
okay so Tk_GetGC and Tk_FreeGC are literally the duo that manages a collection of graphics contexts being used by an application. The procedures allow graphics contexts to be shared, which is a whole slay because it avoids the server overhead that would be incurred if a separate GC were created for each use. Think about it: why make a new GC every time when you can share? Exactly. Tk_GetGC takes arguments describing the desired graphics context and returns an X identifier for a GC that fits the description. The graphics context that is returned will have default values in all of the fields not specified explicitly by valueMask and valuePtr. So if you don't specify something, it gets the default β easy.
Tk_GetGC maintains a database of all the graphics contexts it has created. It's like a little GC library, and it remembers everything. Whenever possible, a call to Tk_GetGC will return an existing graphics context rather than creating a new one. This approach can substantially reduce server overhead, so Tk_GetGC should generally be used in preference to the Xlib procedure XCreateGC, which creates a new graphics context on each call. So yeah, use Tk_GetGC instead of XCreateGC unless you have a reason β it's literally better for the server.
Since the return values of Tk_GetGC are shared, callers should never modify the graphics contexts returned by Tk_GetGC. Like, NEVER. That's a big no-no. They're shared, so if you modify one, you mess it up for everyone.
warning: these GCs are shared, so if you modify one, you're literally ruining it for everyone else. don't do it.
If a graphics context must be modified dynamically, then it should be created by calling XCreateGC instead of Tk_GetGC. So if you need to change it on the fly, use XCreateGC β that's the move.
When a graphics context is no longer needed, Tk_FreeGC should be called to release it. Clean up after yourself, bestie. There should be exactly one call to Tk_FreeGC for each call to Tk_GetGC. Like, one-to-one. Don't free it twice, don't forget to free it. When a graphics context is no longer in use anywhere (i.e. it has been freed as many times as it has been gotten) Tk_FreeGC will release it to the X server and delete it from the database. So when the last person frees it, it goes back to the server and gets deleted from the database β clean.
π KEYWORDS π
graphics context
That's the keyword, and it's iconic. π
this page is from the Tk Library Procedures manual, Tk version, and the page is Tk_GetGC(3). Bye bestie β go share some GCs responsibly! π β¨
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- nixpkgs unstable: tk 9.1.0
- Copyright (c) 1990 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms