[cairo-commit] [cairo-www] src/Xlib.mdwn
Bryce Harrington
bryce at freedesktop.org
Wed Nov 19 17:29:49 PST 2014
src/Xlib.mdwn | 96 +++++++++++++++++++++++++++-------------------------------
1 file changed, 46 insertions(+), 50 deletions(-)
New commits:
commit 18af1e9dfdd479cc706f9a9a2bcbd03bca648d75
Author: Bryce Harrington <bryce at osg.samsung.com>
Date: Wed Nov 19 17:29:29 2014 -0800
Xlib: Fix code indentation
diff --git a/src/Xlib.mdwn b/src/Xlib.mdwn
index 8075a81..ccb1aa1 100644
--- a/src/Xlib.mdwn
+++ b/src/Xlib.mdwn
@@ -31,29 +31,27 @@ the following steps:
After the window is ready, it is mapped to a cairo Xlib surface. The following
function shows how to do it.
-```C
-cairo_surface_t *cairo_create_x11_surface0(int x, int y)
-{
- Display *dsp;
- Drawable da;
- int screen;
- cairo_surface_t *sfc;
-
- if ((dsp = XOpenDisplay(NULL)) == NULL)
- exit(1);
- screen = DefaultScreen(dsp);
- da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp),
- 0, 0, x, y, 0, 0, 0);
- XSelectInput(dsp, da, ButtonPressMask | KeyPressMask);
- XMapWindow(dsp, da);
-
- sfc = cairo_xlib_surface_create(dsp, da,
- DefaultVisual(dsp, screen), x, y);
- cairo_xlib_surface_set_size(sfc, x, y);
-
- return sfc;
-}
-```
+ cairo_surface_t *cairo_create_x11_surface0(int x, int y)
+ {
+ Display *dsp;
+ Drawable da;
+ int screen;
+ cairo_surface_t *sfc;
+
+ if ((dsp = XOpenDisplay(NULL)) == NULL)
+ exit(1);
+ screen = DefaultScreen(dsp);
+ da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp),
+ 0, 0, x, y, 0, 0, 0);
+ XSelectInput(dsp, da, ButtonPressMask | KeyPressMask);
+ XMapWindow(dsp, da);
+
+ sfc = cairo_xlib_surface_create(dsp, da,
+ DefaultVisual(dsp, screen), x, y);
+ cairo_xlib_surface_set_size(sfc, x, y);
+
+ return sfc;
+ }
# Receiving Events
@@ -73,33 +71,31 @@ receives key codes which have to be translated with `XLookupString(3)` to
symbols. All symbols are defined in `X11/keysyndef.h`. The following function
shows how to do it.
-```C
-int cairo_check_event(cairo_surface_t *sfc, int block)
-{
- char keybuf[8];
- KeySym key;
- XEvent e;
-
- for (;;)
- {
- if (block || XPending(cairo_xlib_surface_get_display(sfc)))
- XNextEvent(cairo_xlib_surface_get_display(sfc), &e);
- else
- return 0;
-
- switch (e.type)
- {
- case ButtonPress:
- return -e.xbutton.button;
- case KeyPress:
- XLookupString(&e.xkey, keybuf, sizeof(keybuf), &key, NULL);
- return key;
- default:
- fprintf(stderr, "Dropping unhandled XEevent.type = %d.\n", e.type);
- }
- }
-}
-```
+ int cairo_check_event(cairo_surface_t *sfc, int block)
+ {
+ char keybuf[8];
+ KeySym key;
+ XEvent e;
+
+ for (;;)
+ {
+ if (block || XPending(cairo_xlib_surface_get_display(sfc)))
+ XNextEvent(cairo_xlib_surface_get_display(sfc), &e);
+ else
+ return 0;
+
+ switch (e.type)
+ {
+ case ButtonPress:
+ return -e.xbutton.button;
+ case KeyPress:
+ XLookupString(&e.xkey, keybuf, sizeof(keybuf), &key, NULL);
+ return key;
+ default:
+ fprintf(stderr, "Dropping unhandled XEevent.type = %d.\n", e.type);
+ }
+ }
+ }
Putting all this together creates a first simple window example. Download the
<a
More information about the cairo-commit
mailing list