Tcl_DoOneEvent(3tcl)
β¨ Tcl_DoOneEvent β¨ (that's the 3tcl manual page bestie, from the Tcl Library Procedures π)
πΈ NAME πΈ
Tcl_DoOneEvent β wait for events and invoke event handlers π¦
π SYNOPSIS π
#include <tcl.h>
int
Tcl_DoOneEvent(flags)
π ARGUMENTS π
int flags(in) β okay so normally this is just zero, no thoughts head empty π . But it can also be an OR-ed combo of any of these flag bits:TCL_WINDOW_EVENTS,TCL_FILE_EVENTS,TCL_TIMER_EVENTS,TCL_IDLE_EVENTS,TCL_ALL_EVENTS, orTCL_DONT_WAIT.
π₯ DESCRIPTION π₯
So Tcl_DoOneEvent is literally the entry point to Tcl's event loop β main character energy fr fr π. It's the one responsible for waiting for events and dispatching the event handlers that got created with procedures like Tk_CreateEventHandler, Tcl_CreateFileHandler, Tcl_CreateTimerHandler, and Tcl_DoWhenIdle.
Here's the whole vibe check, step by step:
Tcl_DoOneEventchecks whether events are already chilling on the Tcl event queue. If they are β it calls the handler(s) for the first (oldest) event, removes it from the queue, and returns. Slay, done. β¨- If there are no events ready to be handled, then
Tcl_DoOneEventchecks for new events from all possible sources. If it finds any, it puts all of them on Tcl's event queue, calls handlers for the first event on the queue, and returns. π¦ - If no events are found at all,
Tcl_DoOneEventchecks forTcl_DoWhenIdlecallbacks. If any are found, it invokes all of them and returns. π - And finally β if there are no events and no idle callbacks, then
Tcl_DoOneEventliterally sleeps until an event occurs. Then it adds any new events to the Tcl event queue, calls handlers for the first event, and returns. π΄
The normal return value is 1, to signify that some event was processed (but lowkey there are other alternatives below, keep reading bestie π).
π The Flags, One By One π
If the flags argument to Tcl_DoOneEvent is non-zero, it restricts the kinds of events that Tcl_DoOneEvent will process. Flags can be an OR-ed combination of any of these bits:
TCL_WINDOW_EVENTSβ process window system events. πͺTCL_FILE_EVENTSβ process file events. πTCL_TIMER_EVENTSβ process timer events. β°TCL_IDLE_EVENTSβ process idle callbacks. π€TCL_ALL_EVENTSβ process all kinds of events. It's equivalent to OR-ing together all of the above flags, or specifying none of them. The "no thoughts, all events" option, iconic. πTCL_DONT_WAITβ do not sleep: process only the events that are ready at the time of the call. No waiting around, we're busy. π
π§ How The Filtering Actually Works π§
If any of the flags TCL_WINDOW_EVENTS, TCL_FILE_EVENTS, TCL_TIMER_EVENTS, or TCL_IDLE_EVENTS is set, then the only events that will be considered are those for which flags are set. Setting none of these flags is equivalent to the value TCL_ALL_EVENTS, which causes all event types to be processed. And if an application has defined additional event sources with Tcl_CreateEventSource, then additional flag values may also be valid, depending on those event sources. So like, other flags can absolutely exist, it's just up to those sources. π
π The TCL_DONT_WAIT Situation π
The TCL_DONT_WAIT flag causes Tcl_DoOneEvent not to put the process to sleep: it will check for events, but if none are found then it returns immediately with a return value of 0 to indicate that no work was done. Not me getting zero, zero, zero π«Ά.
Tcl_DoOneEvent will also return 0 without doing anything if the only alternative is to block forever. This can happen, for example, if flags is TCL_IDLE_EVENTS and there are no Tcl_DoWhenIdle callbacks pending, or if no event handlers or timer handlers exist. Yeah bestie, blocking forever is not the move, so it just bails instead. π
π Recursion, Because Of Course π
Tcl_DoOneEvent may be invoked recursively. For example, it is possible to invoke Tcl_DoOneEvent recursively from a handler called by Tcl_DoOneEvent. This sort of operation is useful in some modal situations, such as when a notification dialog has been popped up and an application wishes to wait for the user to click a button in the dialog before doing anything else. It's giving "wait for the user to make a choice" energy, and honestly? We respect it. π
β¨
π KEYWORDS π
callback, event, handler, idle, timer
And that's the whole page bestie!! πβ¨ This lil' gem lives in the Tcl manual, version 7.5, dated back in the day β so go forth, loop those events, and remember: no cap, always handle your oldest event first. π¦ππ
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1990-1992 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