Table of Contents
xtk_xerror.h
Catch the X errors of a few requests on windows of other programs.
A request on a window that the program owns does not fail unless the program has a bug. A request on a window of another client can fail: the program that asked for a paste, the tray manager, a window manager's frame or an embedded program can destroy its window between the moment the program looked at it and the moment the request arrives. Put those requests, and only those, inside a trap. The toolkit itself does this, for example when it answers a paste request in xtk_clipboard.h.
xtk_xerror_trap_push() calls XSync() first, so errors from earlier requests are not counted in the new trap. It then installs its own X error handler. xtk_xerror_trap_pop() calls XSync() again, so every request in the trap has had its answer, puts back the handler that was there before and returns the first error code caught. Traps can be nested up to eight deep; the innermost trap gets the errors.
Outside a trap, the toolkit installs no X error handler. An error there is a bug and goes to the handler the program chose (Xlib's default handler prints the error and exits).
Example.
xtk_xerror_trap_push(display);
XChangeProperty(display, requestor, property, XA_STRING, 8,
PropModeReplace, (const unsigned char *)"hello", 5);
if (xtk_xerror_trap_pop(display) != 0) {
// The requestor's window is gone: drop the transfer.
}
*
Note: The trap state is global to the process, as X error handlers are. Use traps from one thread only. Each push and pop is a round trip to the server, so do not put them around every request.
#include "xtk_xerror.h"
Functions: xtk_xerror_trap_push, xtk_xerror_trap_pop
Functions
xtk_xerror_trap_push
void xtk_xerror_trap_push(Display *display);
Start catching X errors.
Calls XSync(), then installs the trap's error handler. Every push must be matched by one xtk_xerror_trap_pop(). Traps deeper than eight still count, so pushes and pops stay balanced, but they catch nothing of their own (the eighth trap gets their errors). Does nothing when display is NULL.
| Parameter | Description |
|---|---|
display |
The connection whose X errors are caught |
xtk_xerror_trap_pop
int xtk_xerror_trap_pop(Display *display);
Stop catching X errors and put back the handler that was there before.
Calls XSync() first, so every request made inside the trap has had its answer before the result is given.
| Parameter | Description |
|---|---|
display |
The connection given to xtk_xerror_trap_push() |
Returns: The error code of the first error caught in this trap (for example BadWindow), or 0 if every request in it succeeded. Also 0 when display is NULL or no trap is open.
xtk API
Widgets
- button
- checkbox
- radiobutton
- label
- entry
- textview
- edit_history
- spinbutton
- slider
- progressbar
- combobox
- scrollbar
- swatch
- panel
- statusbar
- tooltip
- toolbar
- icongrid
- iconview
- pathbar
- treeview
- datagrid
- graph
- scheme_wheel
- zoom
- tray
Containers and menus
Dialogs
Rich text
Drawing and images
Color
Configuration and themes
Input and the X server
Safety
Data formats