IT lexicon › Programming › Application context (Xt)

Application context (Xt)

Programming På svenska → Updated: 2026-10-10

Xt's container for everything that belongs to a program rather than to a window, display connections, event queue, timers and background work, introduced to get rid of the global variables.

The first version of the X Toolkit Intrinsics assumed one program with one display and one event loop, and kept its state in globals: you called XtInitialize and XtMainLoop and accepted that the library could not be used twice in the same process. X11R3 in 1988 introduced the type XtAppContext as the explicit owner of all of it. The program creates a context, opens its displays within it, registers timers with XtAppAddTimeOut, file descriptors with XtAppAddInput and background work with XtAppAddWorkProc, and runs XtAppMainLoop, which waits on all of them at once. R4 bundled the setup into XtAppInitialize, and the resource database from Xresources is loaded per display inside the context.

The old calls were kept, marked obsolete and rewritten internally against a hidden default context, so the examples in the textbooks went on using them for years. The ability to have several contexts, a library running its own Xt inside someone else's Xt program, was rarely exploited. The real gain was that the event loop became something you could own and drive yourself with XtAppPending and XtAppProcessEvent, instead of handing the program to XtMainLoop and never getting it back. The pattern, one object owning timers, input sources and the main loop, carried on into GLib's GMainContext and Qt's QCoreApplication.

← Back to the lexicon