Tk_CreateEventHandler(3tk)

πŸ’– Tk_CreateEventHandler β€” the Tk Library Procedures girlies πŸ’–

okay so bestie, you're in the Tk Library Procedures section and this page is all about Tk_CreateEventHandler, Tk_DeleteEventHandler, Tk_GetButtonMask and Tk_SendVirtualEvent. they all do one iconic thing: associate procedure callback with an X event ✨


🌸 NAME 🌸

Tk_CreateEventHandler, Tk_DeleteEventHandler, Tk_GetButtonMask, Tk_SendVirtualEvent β€” associate procedure callback with an X event πŸ’…


✨ SYNOPSIS ✨

#include <tk.h>

Tk_CreateEventHandler(tkwin, mask, proc, clientData)

Tk_DeleteEventHandler(tkwin, mask, proc, clientData)

Tk_GetButtonMask(button)

Tk_SendVirtualEvent(tkwin, eventName, detail)

πŸŽ€ ARGUMENTS πŸŽ€

  • unsigned button (in) β€” the button number, bestie. just a number πŸ”’
  • const char *eventName (in) β€” the name of the virtual event πŸ¦‹
  • Tcl_Obj *detail (in) β€” detail information for the virtual event. may be NULL, no biggie πŸ™ˆ
  • Tk_Window tkwin (in) β€” token for window in which events may occur πŸͺŸ
  • unsigned long mask (in) β€” bit-mask of events (like ButtonPressMask, iykyk) for which proc should be called 🎯
  • Tk_EventProc *proc (in) β€” procedure to invoke whenever an event in mask occurs in the window given by tkwin πŸ“ž
  • void *clientData (in) β€” arbitrary one-word value to pass to proc. yes, one word. keep it cute, keep it small πŸ’Œ

πŸ’œ DESCRIPTION πŸ’œ

Tk_CreateEventHandler arranges for proc to be invoked in the future whenever one of the event types specified by mask occurs in the window specified by tkwin. the callback to proc gets made by Tk_HandleEvent β€” and the way that this mechanism only works is in programs that dispatch events through Tk_HandleEvent (or through other Tk procedures that call Tk_HandleEvent, like Tcl_DoOneEvent or Tk_MainLoop). so like, no dispatching, no callback. periodt πŸ’…

Proc should have arguments and result that match the type Tk_EventProc:

typedef void Tk_EventProc(
        void *clientData,
        XEvent *eventPtr);

the clientData parameter to proc is a copy of the clientData argument you gave to Tk_CreateEventHandler back when the callback was created. typically, clientData points to a data structure containing application-specific information about the window in which the event occurred. and eventPtr is a pointer to the X event, which will be one of the ones specified in the mask argument to Tk_CreateEventHandler. literally just handing you back your own stuff 🫢

Tk_DeleteEventHandler may be called to delete a previously-created event handler: it deletes the first handler it finds that is associated with tkwin and matches the mask, proc, and clientData arguments. if no such handler exists, then Tk_HandleEvent returns without doing anything. (yes, Tk_HandleEvent. that's what it says, bestie, we don't ask questions 😭)

ok so warning time 🚨 β€” although Tk supports it, it's probably a bad idea to have more than one callback with the same mask, proc, and clientData arguments. just don't, ngl.

when a window is deleted, all of its handlers get deleted automatically, so in that case there is no need to call Tk_DeleteEventHandler at all. free cleanup, we love that 🌈

if multiple handlers are declared for the same type of X event on the same window, then the handlers will be invoked in the order they were created. first come, first served, iconic πŸ‘‘

Tk_GetButtonMask returns the button mask corresponding to the button. e.g. it will return Button1Mask for button Button1. πŸ–±οΈ

Tk_SendVirtualEvent sends a virtual event to Tk's event queue. that's it, that's the whole vibe ✨


πŸ‘‘ KEYWORDS πŸ‘‘

bind, callback, event, handler


and that's the page, bestie!! this whole thing came to you from the Tk source, under the page name Tk_CreateEventHandler(3tk). go forth and handle those events, you absolute main character πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from