xtk_dbe.h
Back buffers for windows through the X Double Buffer Extension (DBE).
A widget that draws straight into its window shows each step of the drawing, which flickers, most of all while the window is resized. With DBE, the widget draws into a back buffer and then swaps it onto the window in one step. This header finds out whether the server has DBE, allocates and frees back buffers, and swaps them.
Most code does not call this header directly: xtk_surface.h uses it and handles the whole paint cycle, including the case where DBE is missing. Use this header for a window that does not use an XtkSurface.
Contexts. An XtkDbeContext holds what the toolkit found out about DBE on one display and screen. xtk_dbe_get_shared() gives the one context the process shares (the usual choice); xtk_dbe_init() makes a separate one, which the caller frees with xtk_dbe_destroy().
Example.
XtkDbeContext *dbe = xtk_dbe_get_shared(display, screen);
XdbeBackBuffer back = dbe ? xtk_dbe_allocate_back_buffer(dbe, window, XdbeUndefined) : None;
Drawable target = back != None ? back : window;
// ... draw into target with Xlib or Xft ...
if (back != None) xtk_dbe_swap_buffers(dbe, window, XdbeUndefined);
// Before XDestroyWindow():
if (back != None) xtk_dbe_deallocate_back_buffer(dbe, back);
*
Note: When a back buffer cannot be allocated, a line is printed on stderr with the number of back buffers the process already holds, and the caller should draw into the window directly.
#include "xtk_dbe.h"
Types: XtkDbeContext
Functions: xtk_dbe_init, xtk_dbe_destroy, xtk_dbe_get_shared, xtk_dbe_allocate_back_buffer, xtk_dbe_deallocate_back_buffer, xtk_dbe_swap_buffers, xtk_dbe_swap_buffers_multi, xtk_dbe_is_supported, xtk_dbe_get_visual_info
Types
XtkDbeContext
What the toolkit knows about DBE on one display and screen.
Made by xtk_dbe_init() or xtk_dbe_get_shared(). Read it through the functions below; the fields are public but are not meant to be changed.
| Field | Type | Description |
|---|---|---|
display |
Display * |
The display connection. |
screen |
int |
The screen number. |
supported |
int |
1 if the server has DBE and the screen has a visual that can use it, 0 otherwise |
major_version |
int |
The DBE extension's major version. |
minor_version |
int |
The DBE extension's minor version. |
visual_info |
XdbeScreenVisualInfo * |
The visuals that support double buffering (from XdbeGetVisualInfo()), or NULL. |
visual_count |
int |
The number of entries in visual_info. |
Functions
xtk_dbe_init
XtkDbeContext *xtk_dbe_init(Display *display, int screen);
Make a new DBE context for a display and screen.
Asks the server whether it has DBE and which visuals can use it. A server without DBE is not an error: the context is still made, with supported set to 0, and every buffer call on it fails quietly.
| Parameter | Description |
|---|---|
display |
The X connection |
screen |
The screen number, for example DefaultScreen(display) |
Returns: The new context, which the caller frees with xtk_dbe_destroy(); or NULL if display is NULL or memory ran out
xtk_dbe_destroy
void xtk_dbe_destroy(XtkDbeContext *dbe_context);
Free a context made by xtk_dbe_init().
Does not free back buffers allocated through the context; free those first with xtk_dbe_deallocate_back_buffer(). Never pass the shared context from xtk_dbe_get_shared(). Does nothing when dbe_context is NULL.
| Parameter | Description |
|---|---|
dbe_context |
The context to free, or NULL |
xtk_dbe_get_shared
XtkDbeContext *xtk_dbe_get_shared(Display *display, int screen);
The DBE context the whole process shares for a display.
The server is asked once, not once per widget. The toolkit expects one display and screen per process: asking for a different display or screen replaces the shared context, so widgets on two displays at the same time are not supported.
| Parameter | Description |
|---|---|
display |
The X connection |
screen |
The screen number |
Returns: The shared context (owned by the toolkit; never pass it to xtk_dbe_destroy()), or NULL if display is NULL, the server has no usable DBE or memory ran out
xtk_dbe_allocate_back_buffer
XdbeBackBuffer xtk_dbe_allocate_back_buffer(
XtkDbeContext *dbe_context,
Window window,
XdbeSwapAction swap_action);
Allocate a back buffer for a window.
The back buffer keeps the window's size: when the window is resized, the server resizes the back buffer with it.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context |
window |
The window that gets the back buffer |
swap_action |
The swap action the caller expects to use, usually XdbeUndefined (the back buffer's contents are undefined after a swap) |
Returns: The back buffer, which is also a Drawable to draw into; or None if dbe_context is NULL or not supported, window is None or the server refused (a line is then printed on stderr)
xtk_dbe_deallocate_back_buffer
int xtk_dbe_deallocate_back_buffer(XtkDbeContext *dbe_context, XdbeBackBuffer buffer);
Free a back buffer made by xtk_dbe_allocate_back_buffer().
Call it before the window is destroyed.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context the buffer was allocated through |
buffer |
The back buffer |
Returns: 1 when the buffer was freed, 0 if dbe_context is NULL or not supported, or buffer is None
xtk_dbe_swap_buffers
int xtk_dbe_swap_buffers(
XtkDbeContext *dbe_context,
Window window,
XdbeSwapAction swap_action);
Show a window's back buffer: swap it onto the window.
The request is queued, not flushed; it reaches the server with the next flush, as other Xlib requests do.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context |
window |
The window whose buffers are swapped |
swap_action |
What happens to the back buffer after the swap, usually XdbeUndefined |
Returns: 1 when the swap was sent, 0 if dbe_context is NULL or not supported, or window is None
xtk_dbe_swap_buffers_multi
int xtk_dbe_swap_buffers_multi(
XtkDbeContext *dbe_context,
XdbeSwapInfo *swap_info,
int number_windows);
Swap the buffers of several windows in one request.
All the windows change at the same moment.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context |
swap_info |
One entry per window: the window and its swap action |
number_windows |
The number of entries in swap_info |
Returns: 1 when the swap was sent, 0 if dbe_context is NULL or not supported, swap_info is NULL or number_windows is less than 1
xtk_dbe_is_supported
int xtk_dbe_is_supported(const XtkDbeContext *dbe_context);
Whether DBE can be used through a context.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context, or NULL |
Returns: 1 if the server has DBE and the screen has a visual for it, 0 if not (or dbe_context is NULL)
xtk_dbe_get_visual_info
XdbeScreenVisualInfo *xtk_dbe_get_visual_info(
const XtkDbeContext *dbe_context,
int *visual_count);
The visuals of the screen that support double buffering.
| Parameter | Description |
|---|---|
dbe_context |
The DBE context |
visual_count |
Receives the number of entries (0 when there are none); may be NULL |
Returns: The array, owned by the context (do not free it), or NULL if dbe_context is NULL or not supported
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