Tk_CreateGenericHandler(3)
π Tk_CreateGenericHandler(3) π
Tk_CreateGenericHandler, Tk_DeleteGenericHandler β associate a procedure callback with all X events. Like, every single one. π
Welcome to the Tk Library Procedures manual, bestie. Weβre doing the Tk_CreateGenericHandler(3) page today, and itβs giving βI want to know about every eventβ energy. β¨
β¨ SYNOPSIS β¨
#include <tk.h>
Tk_CreateGenericHandler(proc, clientData)
Tk_DeleteGenericHandler(proc, clientData)
π ARGUMENTS π
Tk_GenericProc *proc(in) β the procedure to invoke whenever any X event occurs on any display. Thatβs the whole job. π«Άvoid *clientData(in) β an arbitrary one-word value to pass toproc. One word. No cap. π¬
π¦ DESCRIPTION π¦
So Tk_CreateGenericHandler arranges for proc to be invoked in the future whenever any X event occurs. Itβs giving βIβm watching everything,β and honestly? Iconic. β¨
β οΈ But listen: this mechanism is not intended for dispatching X events on windows managed by Tk. For that, you should use Tk_CreateEventHandler instead. Periodt. π
Tk_CreateGenericHandler is intended for other purposes, such as tracing X events, monitoring events on windows not owned by Tk, accessing X-related libraries that were not originally designed for use with Tk, and so on. Very βIβm just observing, bestieβ energy. π
The callback to proc will be made by Tk_HandleEvent. That means this mechanism only works in programs that dispatch events through Tk_HandleEvent β or through other Tk procedures that call Tk_HandleEvent, such as Tcl_DoOneEvent or Tk_MainLoop. No event dispatch through those paths, no callback. Simple as that. π
proc should have arguments and result that match the type Tk_GenericProc:
typedef int Tk_GenericProc(
void *clientData,
XEvent *eventPtr);
The clientData parameter to proc is a copy of the clientData argument given to Tk_CreateGenericHandler when the callback was created. Typically, clientData points to a data structure containing application-specific information about how to handle events. eventPtr is a pointer to the X event. π―
Whenever an X event is processed by Tk_HandleEvent, proc is called. The return value from proc is normally 0. A non-zero return value indicates that the event is not to be handled further β that is, proc has done all processing that is to be allowed for the event. So 0 is the usual return; non-zero is the stop sign for further handling. π
If there are multiple generic event handlers, each one is called for each event, in the order in which they were established. First come, first called. Line up, besties. ποΈ
Tk_DeleteGenericHandler may be called to delete a previously-created generic event handler: it deletes each handler it finds that matches the proc and clientData arguments. If no such handler exists, then Tk_DeleteGenericHandler returns without doing anything. Itβs not dramatic about it. π
Although Tk supports it, itβs probably a bad idea to have more than one callback with the same proc and clientData arguments. Like, technically allowed? Yes. Recommended? Absolutely not, bestie. π©
Establishing a generic event handler does nothing to ensure that the process will actually receive the X events that the handler wants to process. For example, it is the callerβs responsibility to invoke XSelectInput to select the desired events, if that is necessary. So donβt just set up the callback and assume the events will show up β you gotta do your part. πͺ
π KEYWORDS π
bind, callback, event, handler
Okay bestie, thatβs the whole page. Footer sign-off: source/version is Tk, page is Tk_CreateGenericHandler(3), and this footer doesnβt show a date. Byeee ππ¦
π¦ 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) 1992-1994 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