Tk_AllocCursorFromObj(3)
π NAME π
okay bestie, this is the Tk Library Procedures page for Tk_AllocCursorFromObj(3), and it covers Tk_AllocCursorFromObj, Tk_GetCursor, Tk_GetCursorFromObj, Tk_GetCursorFromData, Tk_NameOfCursor, Tk_FreeCursorFromObj, and Tk_FreeCursor β literally the whole maintain-database-of-cursors squad. π«Ά
β¨ SYNOPSIS β¨
#include <tk.h>
Tk_Cursor
Tk_AllocCursorFromObj(interp, tkwin, objPtr)
Tk_Cursor
Tk_GetCursor(interp, tkwin, name)
Tk_Cursor
Tk_GetCursorFromObj(tkwin, objPtr)
Tk_Cursor
Tk_GetCursorFromData(interp, tkwin, source, mask, width, height, xHot, yHot, fg, bg)
const char *
Tk_NameOfCursor(display, cursor)
Tk_FreeCursorFromObj(tkwin, objPtr)
Tk_FreeCursor(display, cursor)
π ARGUMENTS π
Tcl_Interp *interp(in) β interpreter to use for error reporting, bestie.Tk_Window tkwin(in) β token for the window where the cursor will be used.Tcl_Obj *objPtr(in/out) β description of the cursor; see below for possible values. Its internal rep will be modified to cache a pointer to the correspondingTk_Cursor.const char *name(in) β same asobjPtr, except the cursor description is passed as a string and the resultingTk_Cursoris not cached.const char *source(in) β data for cursor cursor, in standard cursor format.const char *mask(in) β data for mask cursor, in standard cursor format.int width(in) β width ofsourceandmask.int height(in) β height ofsourceandmask.int xHot(in) β X-location of the cursor hot-spot.int yHot(in) β Y-location of the cursor hot-spot.const char *fg(in) β textual description of the foreground color for the cursor.const char *bg(in) β textual description of the background color for the cursor.Display *display(in) β display for which the cursor was allocated.Tk_Cursor cursor(in) β opaque Tk identifier for a cursor. If passed toTk_FreeCursor, it must have been returned by some previous call toTk_GetCursororTk_GetCursorFromData.
π¦ DESCRIPTION π¦
These procedures manage a collection of cursors being used by an application. They let cursors be re-used efficiently, thereby avoiding server overhead, and they also let cursors be named with character strings. π
Tk_AllocCursorFromObj takes as argument an object describing a cursor, and returns an opaque Tk identifier for a cursor corresponding to the description. It re-uses an existing cursor if possible and creates a new one otherwise. Tk_AllocCursorFromObj caches information about the return value in objPtr, which speeds up future calls to procedures such as Tk_AllocCursorFromObj and Tk_GetCursorFromObj. If an error occurs in creating the cursor, such as when objPtr refers to a non-existent file, then None is returned and an error message will be stored in interp's result if interp is not NULL. ObjPtr must contain a standard Tcl list with one of the following forms:
π«Ά cursor description forms π«Ά
name [fgColor [bgColor]]βnameis the name of a cursor in the standard X cursor cursor, i.e., any of the names defined incursorcursor.h, without theXC_. Some example values areX_cursor,hand2, orleft_ptr. Appendix B of βThe X Window Systemβ by Scheifler & Gettys has illustrations showing what each of these cursors looks like. IffgColorandbgColorare both specified, they give the foreground and background colors to use for the cursor (any of the forms acceptable toTk_GetColormay be used). If onlyfgColoris specified, then there will be no background color: the background will be transparent. If no colors are specified, then the cursor will use black for its foreground color and white for its background color.
The Macintosh version of Tk supports all of the X cursors and will also accept any of the standard Mac cursors including ibeam, crosshair, watch, plus, and arrow. In addition, Tk will load Macintosh cursor resources of the types crsr (color) and CURS (black and white) by the name of the resource. The application and all its open dynamic library's resource files will be searched for the named cursor. If there are conflicts color cursors will always be loaded in preference to black and white cursors.
@sourceName maskName fgColor bgColorβ in this form,sourceNameandmaskNameare the names of files describing cursors for the cursor's source bits and mask. Each file must be in standard X11 cursor format.FgColorandbgColorindicate the colors to use for the cursor, in any of the forms acceptable toTk_GetColor. This form of the command will not work on Macintosh or Windows computers. π@sourceName fgColorβ this form is similar to the one above, except that the source is used as mask also. This means that the cursor's background is transparent. This form of the command will not work on Macintosh or Windows computers.@sourceNameβ this form only works on Windows, and will load a Windows system cursor (.anior.cur) from the file specified insourceName.
Tk_GetCursor is identical to Tk_AllocCursorFromObj except that the description of the cursor is specified with a string instead of an object. This prevents Tk_GetCursor from caching the return value, so Tk_GetCursor is less efficient than Tk_AllocCursorFromObj. ngl, cache is kind of the moment here. β¨
Tk_GetCursorFromObj returns the token for an existing cursor, given the window and description used to create the cursor. Tk_GetCursorFromObj does not actually create the cursor; the cursor must already have been created with a previous call to Tk_AllocCursorFromObj or Tk_GetCursor. The return value is cached in objPtr, which speeds up future calls to Tk_GetCursorFromObj with the same objPtr and tkwin. π
Tk_GetCursorFromData allows cursors to be created from in-memory descriptions of their source and mask cursors. source points to standard cursor data for the cursor's source bits, and mask points to standard cursor data describing which pixels of source are to be drawn and which are to be considered transparent. width and height give the dimensions of the cursor, xHot and yHot indicate the location of the cursor's hot-spot (the point that is reported when an event occurs), and fg and bg describe the cursor's foreground and background colors textually (any of the forms suitable for Tk_GetColor may be used). Typically, the arguments to Tk_GetCursorFromData are created by including a cursor file directly into the source code for a program, as in the following example:
Tk_Cursor cursor;
#include "source.cursor"
#include "mask.cursor"
cursor = Tk_GetCursorFromData(interp, tkwin, source_bits,
mask_bits, source_width, source_height, source_x_hot,
source_y_hot, "red", "blue");
Under normal conditions Tk_GetCursorFromData will return an identifier for the requested cursor. If an error occurs in creating the cursor then None is returned and an error message will be stored in interp's result.
Tk_AllocCursorFromObj, Tk_GetCursor, and Tk_GetCursorFromData maintain a database of all the cursors they have created. Whenever possible, a call to Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursorFromData will return an existing cursor rather than creating a new one. This approach can substantially reduce server overhead, so the Tk procedures should generally be used in preference to Xlib procedures like XCreateFontCursor or XCreatePixmapCursor, which create a new cursor on each call. The Tk procedures are also more portable than the lower-level X procedures. π
The procedure Tk_NameOfCursor is roughly the inverse of Tk_GetCursor. If its cursor argument was created by Tk_GetCursor, then the return value is the name argument that was passed to Tk_GetCursor to create the cursor. If cursor was created by a call to Tk_GetCursorFromData, or by any other mechanism, then the return value is a hexadecimal string giving the X identifier for the cursor. Note that the string returned by Tk_NameOfCursor is only guaranteed to persist until the next call to Tk_NameOfCursor. Also, this call is not portable except for cursors returned by Tk_GetCursor.
When a cursor returned by Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursorFromData is no longer needed, Tk_FreeCursorFromObj or Tk_FreeCursor should be called to release it. For Tk_FreeCursorFromObj the cursor to release is specified with the same information used to create it; for Tk_FreeCursor the cursor to release is specified with its Tk_Cursor token. There should be exactly one call to Tk_FreeCursor for each call to Tk_AllocCursorFromObj, Tk_GetCursor, or Tk_GetCursorFromData. π§
π BUGS π
In determining whether an existing cursor can be used to satisfy a new request, Tk_AllocCursorFromObj, Tk_GetCursor, and Tk_GetCursorFromData consider only the immediate values of their arguments. For example, when a file name is passed to Tk_GetCursor, Tk_GetCursor will assume it is safe to re-use an existing cursor created from the same file name: it will not check to see whether the file itself has changed, or whether the current directory has changed, thereby causing the name to refer to a different file. Similarly, Tk_GetCursorFromData assumes that if the same source pointer is used in two different calls, then the pointers refer to the same data; it does not check to see if the actual data values have changed. so yeah, that's the gotcha, bestie β the cache is literally only looking at the immediate values. ππ
π KEYWORDS π
cursor
that's the whole page, bestie β sourced from Tk version 8.1, page Tk_AllocCursorFromObj(3), and the footer has no date listed, so that's that ππ bye and slay your cursor management β¨
π¦ 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-1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms