summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell de Bruyn <mitch@physicscat.org>2013-11-21 13:53:45 +0200
committerUli Schlachter <psychon@znc.in>2013-11-23 11:49:00 +0100
commitea1923e6c782cf2672d1788149cbcab1387608ea (patch)
tree20cc1c5350463b89c45639056edd1ea63978b931
parenta42a48b95ed78e4dd1f52da59bc7224b79d34553 (diff)
General fixes for the Tutorials
Fix some compile errors and formatting mainly in the complete examples.
-rw-r--r--tutorial.mdwn12
-rw-r--r--tutorial/basicwindowsanddrawing.mdwn12
-rw-r--r--tutorial/events.mdwn55
-rw-r--r--tutorial/fonts.mdwn28
-rw-r--r--tutorial/mousecursors.mdwn18
-rw-r--r--windowcontextandmanipulation.mdwn10
6 files changed, 55 insertions, 80 deletions
diff --git a/tutorial.mdwn b/tutorial.mdwn
index 3c26c46..b883b80 100644
--- a/tutorial.mdwn
+++ b/tutorial.mdwn
@@ -88,13 +88,9 @@ Here is a program that computes the time to create 500 atoms with Xlib and XCB.
To further compare Xlib to XCB, there's a XInternAtoms routine. It's the Xlib method to request all the atoms in an array at one time to help hide the latency. Mostly the good Xlib time takes twice the time as the good XCB time. It also highlights the complexity of using XCB, 3 simple statements for Xlib vs 9 statements including two loops for XCB. If this simple test was expanded beyond requesting Atoms, XCB would allow submitting all the various requests at one time, Xlib wouldn't.
- /* It's a good idea to paste this and other long code examples
- into a text editor for easier reading */
+ /* It's a good idea to paste this and other long code examples
+ into a text editor for easier reading */
-/*
- It's a good idea to paste this and other long code examples into a text
- editor for easier reading */
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -315,8 +311,8 @@ So for example:
...
- xcb_connection_t *c = xcb_connect (NULL, NULL);
- xcb_disconnect (c);
+ xcb_connection_t *connection = xcb_connect (NULL, NULL);
+ xcb_disconnect (connection);
Comparison Xlib/XCB:
diff --git a/tutorial/basicwindowsanddrawing.mdwn b/tutorial/basicwindowsanddrawing.mdwn
index 21361a3..5c64bbb 100644
--- a/tutorial/basicwindowsanddrawing.mdwn
+++ b/tutorial/basicwindowsanddrawing.mdwn
@@ -142,7 +142,7 @@ We give now an example on how to allocate a graphic context that specifies that
return 0;
}
-Note should be taken regarding the role of "valuemask" and "valuelist" in the prototype of xcb\_create\_gc(). Since a graphic context has many attributes, and since we often just want to define a few of them, we need to be able to tell the xcb\_create\_gc() which attributes we want to set. This is what the "valuemask" parameter is for. We then use the "valuelist" parameter to specify actual values for the attribute we defined in "valuemask". Thus, for each constant used in "valuelist", we will use the matching constant in "value_mask". In this case, we define a graphic context with one attribute: when drawing (a point, a line, etc), the foreground color will be black. The rest of the attributes of this graphic context will be set to their default values.
+Note should be taken regarding the role of "valuemask" and "valuelist" in the prototype of xcb\_create\_gc(). Since a graphic context has many attributes, and since we often just want to define a few of them, we need to be able to tell the xcb\_create\_gc() which attributes we want to set. This is what the "valuemask" parameter is for. We then use the "valuelist" parameter to specify actual values for the attribute we defined in "valuemask". Thus, for each constant used in "valuelist", we will use the matching constant in "value\_mask". In this case, we define a graphic context with one attribute: when drawing (a point, a line, etc), the foreground color will be black. The rest of the attributes of this graphic context will be set to their default values.
See the next Subsection for more details.
@@ -162,7 +162,7 @@ Once we have allocated a Graphic Context, we may need to change its attributes (
uint32_t value_mask, /* Components of the Graphic Context that have to be set */
const uint32_t *value_list ); /* Value as specified by value_mask */
-The valuemask parameter could take any combination of these masks from the xcb_gc_t enumeration:
+The valuemask parameter could take any combination of these masks from the xcb\_gc\_t enumeration:
XCB_GC_FUNCTION
XCB_GC_PLANE_MASK
@@ -207,7 +207,7 @@ To draw a point, or several points, we use:
uint32_t points_len, /* The number of points */
const xcb_point_t *points ); /* An array of points */
-The coordinate_mode parameter specifies the coordinate mode. Available values are:
+The coordinate\_mode parameter specifies the coordinate mode. Available values are:
XCB_COORD_MODE_ORIGIN
XCB_COORD_MODE_PREVIOUS
@@ -325,7 +325,7 @@ To fill one or several arcs, we use:
To illustrate these functions, here is an example that draws four points, a polygonal line, two segments, two rectangles and two arcs. Remark that we use events for the first time, as an introduction to the next section.
-TODO: Use screen->root_depth for depth parameter.
+TODO: Use screen-> root\_depth for depth parameter.
#include <stdlib.h>
#include <stdio.h>
@@ -377,7 +377,6 @@ TODO: Use screen->root_depth for depth parameter.
/* Create a window */
-
window = xcb_generate_id (connection);
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
@@ -402,9 +401,8 @@ TODO: Use screen->root_depth for depth parameter.
/* draw primitives */
-
xcb_generic_event_t *event;
- while (event = xcb_wait_for_event (connection)) {
+ while ((event = xcb_wait_for_event (connection))) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE:
/* We draw the points */
diff --git a/tutorial/events.mdwn b/tutorial/events.mdwn
index bde3624..3963e91 100644
--- a/tutorial/events.mdwn
+++ b/tutorial/events.mdwn
@@ -83,16 +83,18 @@ Here's how you might use xcb\_wait\_for\_event:
xcb_generic_event_t *event;
- while (event = xcb_wait_for_event (connection)) {
+ while ( (event = xcb_wait_for_event (connection)) ) {
switch (event->response_type & ~0x80) {
- case XCB_EXPOSE:
+ case XCB_EXPOSE: {
xcb_expose_event_t *expose = (xcb_expose_event_t *)event;
/* ...do stuff */
break;
- case XCB_BUTTON_PRESS:
+ }
+ case XCB_BUTTON_PRESS: {
xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
/* ...do stuff */
break;
+ }
default:
/* Unknown event type, ignore it */
break;
@@ -113,7 +115,7 @@ The equivalent in XCB looks like:
xcb_generic_event_t *event;
- while (event = xcb_poll_for_event (connection, 0)) {
+ while ( (event = xcb_poll_for_event (connection, 0)) ) {
/* ...handle the event */
}
@@ -322,7 +324,7 @@ As an example for handling events, we show a program that creates a window, ente
};
printf ("Modifier mask: ");
- for (char **modifier = MODIFIERS ; mask; mask >>= 1, ++modifier) {
+ for (const char **modifier = MODIFIERS ; mask; mask >>= 1, ++modifier) {
if (mask & 1) {
printf (*modifier);
}
@@ -337,7 +339,7 @@ As an example for handling events, we show a program that creates a window, ente
xcb_connection_t *connection = xcb_connect (NULL, NULL);
/* Get the first screen */
- xcb_screen_t *screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
+ xcb_screen_t *screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data;
/* Create the window */
@@ -362,25 +364,25 @@ As an example for handling events, we show a program that creates a window, ente
mask, values ); /* masks */
/* Map the window on the screen */
- xcb_map_window (c, win);
+ xcb_map_window (connection, window);
- xcb_flush (c);
+ xcb_flush (connection);
xcb_generic_event_t *event;
- while (event = xcb_wait_for_event (connection)) {
+ while ( (event = xcb_wait_for_event (connection)) ) {
switch (event->response_type & ~0x80) {
- case XCB_EXPOSE:
+ case XCB_EXPOSE: {
xcb_expose_event_t *expose = (xcb_expose_event_t *)event;
printf ("Window %"PRIu32" exposed. Region to be redrawn at location (%"PRIu16",%"PRIu16"), with dimension (%"PRIu16",%"PRIu16")\n",
expose->window, expose->x, expose->y, expose->width, expose->height );
break;
-
- case XCB_BUTTON_PRESS:
+ }
+ case XCB_BUTTON_PRESS: {
xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event;
print_modifiers (bp->state);
- switch (press->detail) {
+ switch (bp->detail) {
case 4:
printf ("Wheel Button up in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
bp->event, bp->event_x, bp->event_y );
@@ -394,52 +396,53 @@ As an example for handling events, we show a program that creates a window, ente
bp->detail, bp->event, bp->event_x, bp->event_y );
break;
}
- break;
- case XCB_BUTTON_RELEASE:
+ break;
+ }
+ case XCB_BUTTON_RELEASE: {
xcb_button_release_event_t *br = (xcb_button_release_event_t *)event;
print_modifiers(br->state);
printf ("Button %"PRIu8" released in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
br->detail, br->event, br->event_x, br->event_y );
break;
-
- case XCB_MOTION_NOTIFY:
+ }
+ case XCB_MOTION_NOTIFY: {
xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event;
printf ("Mouse moved in window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
motion->event, motion->event_x, motion->event_y );
break;
-
- case XCB_ENTER_NOTIFY:
+ }
+ case XCB_ENTER_NOTIFY: {
xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *)event;
printf ("Mouse entered window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
enter->event, enter->event_x, enter->event_y );
break;
-
- case XCB_LEAVE_NOTIFY:
+ }
+ case XCB_LEAVE_NOTIFY: {
xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *)event;
printf ("Mouse left window %"PRIu32", at coordinates (%"PRIi16",%"PRIi16")\n",
leave->event, leave->event_x, leave->event_y );
break;
-
- case XCB_KEY_PRESS:
+ }
+ case XCB_KEY_PRESS: {
xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event;
print_modifiers(kp->state);
printf ("Key pressed in window %"PRIu32"\n",
kp->event);
break;
-
- case XCB_KEY_RELEASE:
+ }
+ case XCB_KEY_RELEASE: {
xcb_key_release_event_t *kr = (xcb_key_release_event_t *)event;
print_modifiers(kr->state);
printf ("Key released in window %"PRIu32"\n",
kr->event);
break;
-
+ }
default:
/* Unknown event type, ignore it */
printf ("Unknown event: %"PRIu8"\n",
diff --git a/tutorial/fonts.mdwn b/tutorial/fonts.mdwn
index 88d4fa0..8fa63b5 100644
--- a/tutorial/fonts.mdwn
+++ b/tutorial/fonts.mdwn
@@ -22,7 +22,7 @@ To open a font, we use the following function:
uint16_t name_len,
const char *name);
-The fid parameter is the font Id defined by xcb_generate_id() (see above). The name parameter is the name of the font you want to open. Use the command xlsfonts in a terminal to know which are the fonts available on your computer. The parameter name_len is the length of the name of the font (given by strlen()).
+The fid parameter is the font Id defined by xcb\_generate\_id() (see above). The name parameter is the name of the font you want to open. Use the command xlsfonts in a terminal to know which are the fonts available on your computer. The parameter name\_len is the length of the name of the font (given by strlen()).
### 3. Assigning a Font to a Graphic Context
@@ -105,10 +105,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
}
}
-
-
- /*
- */
static void
drawText (xcb_connection_t *connection,
xcb_screen_t *screen,
@@ -117,16 +113,12 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
int16_t y1,
const char *label )
{
- xcb_generic_error_t *error; // used by TEST_SUCCESS();
-
/* get graphics context */
-
- xcb_gcontext_t gc = getFontGC (connection, screen, window, "7x13");
+ xcb_gcontext_t gc = getFontGC (connection, screen, window, "fixed");
/* draw the text */
-
xcb_void_cookie_t textCookie = xcb_image_text_8_checked (connection,
strlen (label),
window,
@@ -138,15 +130,12 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* free the gc */
-
xcb_void_cookie_t gcCookie = xcb_free_gc (connection, gc);
testCookie(gcCookie, connection, "can't free gc");
}
- /*
- */
static xcb_gc_t
getFontGC (xcb_connection_t *connection,
xcb_screen_t *screen,
@@ -154,7 +143,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
const char *font_name )
{
/* get font */
-
xcb_font_t font = xcb_generate_id (connection);
xcb_void_cookie_t fontCookie = xcb_open_font_checked (connection,
font,
@@ -165,7 +153,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* create graphics context */
-
xcb_gcontext_t gc = xcb_generate_id (connection);
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
uint32_t value_list[3] = { screen->black_pixel,
@@ -182,7 +169,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* close font */
-
fontCookie = xcb_close_font_checked (connection, font);
testCookie(fontCookie, connection, "can't close font");
@@ -191,13 +177,10 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
}
- /*
- */
int
main ()
{
/* get the connection */
-
int screenNum;
xcb_connection_t *connection = xcb_connect (NULL, &screenNum);
if (!connection) {
@@ -207,8 +190,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* get the current screen */
-
-
xcb_screen_iterator_t iter = xcb_setup_roots_iterator (xcb_get_setup (connection));
// we want the screen at index screenNum of the iterator
@@ -226,7 +207,6 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* create the window */
-
xcb_window_t window = xcb_generate_id (connection);
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
@@ -256,11 +236,9 @@ This example draw a text at 10 pixels (for the base line) of the bottom of a win
/* event loop */
-
xcb_generic_event_t *event;
-
while (1) { ;
- if (event = xcb_poll_for_event(connection)) {
+ if ( (event = xcb_poll_for_event(connection)) ) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE: {
drawText (connection,
diff --git a/tutorial/mousecursors.mdwn b/tutorial/mousecursors.mdwn
index 67e6319..0046a94 100644
--- a/tutorial/mousecursors.mdwn
+++ b/tutorial/mousecursors.mdwn
@@ -22,7 +22,7 @@ In the first method, we use a special font named "cursor", and the function xcb\
uint16_t back_green, /* green value for the background of the source */
uint16_t back_blue ); /* blue value for the background of the source */
-TODO: Describe source_char and mask_char, for example by giving an example on how to get the values. There is a list there: X Font Cursors
+TODO: Describe source\_char and mask\_char, for example by giving an example on how to get the values. There is a list there: X Font Cursors
So we first open that font (see Loading a Font) and create the new cursor. As for every X ressource, we have to ask for an X id with xcb\_generate\_id first:
@@ -31,12 +31,12 @@ So we first open that font (see Loading a Font) and create the new cursor. As fo
cursor = xcb_generate_id (connection);
xcb_create_glyph_cursor (connection,
- cursor, /* cursor id */
+ cursor, /* cursor id */
source_font, /* source glyph font */
- mask_font, /* mask glyph font */
- 58, /* source character glyph */
- 58 + 1, /* mask character glyph */
- 0, 0, 0, 0, 0, 0); /* r b g r b g */
+ mask_font, /* mask glyph font */
+ 58, /* source character glyph */
+ 58 + 1, /* mask character glyph */
+ 0, 0, 0, 0, 0, 0); /* r b g r b g */
We have created the cursor "right hand" by specifying 58 to the `source_font` argument and 58 + 1 to the `mask_font`.
@@ -52,7 +52,7 @@ TODO: give an example.
### 2. Setting a window's mouse cursor
-Once the cursor is created, we can modify the cursor of our window by using xcb\_change\_window_attributes and using the XCB\_CW\_CURSOR attribute:
+Once the cursor is created, we can modify the cursor of our window by using xcb\_change\_window\_attributes and using the XCB\_CW\_CURSOR attribute:
/* ...assume cursor created here... */
@@ -124,7 +124,7 @@ The following example displays a window with a button. When entering the window,
points[4].x = x1;
points[4].y = y1;
- xcb_gcontext_t gc = getFontGC (connection, screen, window, "7x13");
+ xcb_gcontext_t gc = getFontGC (connection, screen, window, "fixed");
xcb_void_cookie_t lineCookie = xcb_poly_line_checked (connection,
XCB_COORD_MODE_ORIGIN,
window,
@@ -157,7 +157,7 @@ The following example displays a window with a button. When entering the window,
const char *label )
{
- xcb_gcontext_t gc = getFontGC (connection, screen, window, "7x13");
+ xcb_gcontext_t gc = getFontGC (connection, screen, window, "fixed");
xcb_void_cookie_t textCookie = xcb_image_text_8_checked (connection,
strlen (label),
window,
diff --git a/windowcontextandmanipulation.mdwn b/windowcontextandmanipulation.mdwn
index 7227607..1de96d9 100644
--- a/windowcontextandmanipulation.mdwn
+++ b/windowcontextandmanipulation.mdwn
@@ -29,7 +29,7 @@ The mode parameter coud be one of the following values (defined in enumeration x
### 2. Setting the window name and icon name
-The first thing we want to do would be to set the name for our window. This is done using the xcb\_change\_property() function. This name may be used by the window manager as the title of the window (in the title bar), in a task list, etc. The property atom to use to set the name of a window is XCB\_ATOM\_WM\_NAME (and XCB\_ATOM\_WM\_ICON_NAME for the iconified window) and its type is XCB\_ATOM\_STRING. Here is an example of utilization:
+The first thing we want to do would be to set the name for our window. This is done using the xcb\_change\_property() function. This name may be used by the window manager as the title of the window (in the title bar), in a task list, etc. The property atom to use to set the name of a window is XCB\_ATOM\_WM\_NAME (and XCB\_ATOM\_WM\_ICON\_NAME for the iconified window) and its type is XCB\_ATOM\_STRING. Here is an example of utilization:
#include <string.h>
@@ -80,7 +80,7 @@ The first thing we want to do would be to set the name for our window. This is d
char *iconTitle = "Hello World ! (iconified)";
xcb_change_property (connection,
XCB_PROP_MODE_REPLACE,
- windows,
+ window,
XCB_ATOM_WM_ICON_NAME,
XCB_ATOM_STRING,
8,
@@ -100,9 +100,9 @@ The first thing we want to do would be to set the name for our window. This is d
return 0;
}
-Note: the use of the atoms needs our program to be compiled and linked against xcb_atom, so that we have to use
+Note: the use of the atoms needs our program to be compiled and linked against xcb\_atom, so that we have to use
- gcc prog.c -o prog `pkg-config --cflags --libs xcb_atom`
+ gcc prog.c -o prog `pkg-config --cflags --libs xcb-atom`
...for the program to compile fine.
@@ -126,7 +126,7 @@ Un-mapping a window is also simple. You use the function
xcb_void_cookie_t xcb_unmap_window (xcb_connection_t *c,
xcb_window_t window );
-The utilization of this function is the same as xcb_map_window().
+The utilization of this function is the same as xcb\_map\_window().
### 2. Configuring a window