Chapter 15. Other Programming Techniques

As its title implies, this chapter discusses a few orphaned techniques that didn’t quite fit in anywhere else. This chapter is important if you want to use one of these techniques, but most readers may just want to skim it.

This chapter covers a few obscure but occasionally necessary programming techniques. The routines and techniques described here will not be needed in most programs.

The end of the chapter contains information about porting and portability.

15.1 Reading and Writing Properties

Chapter 12, described many of the usual properties used in communication with the window manager and other clients. Xlib provides convenience routines for reading and writing these properties. But if you establish any other private protocols between two of your applications or between your application and a proprietary window manager, you will need to write your own routines to read and write properties. Example 15-1 is the code for XFetchName() that shows how to read a property containing a string.

Example 15-1. Reading a property

#include "Xatom.h" Status XFetchName (dpy, w, name) register Display *dpy; Window w; char **name; { Atom actual_type; int actual_format; unsigned long nitems; unsigned long leftover; unsigned char *data = NULL; if (XGetWindowProperty(dpy, w, XA_WM_NAME, 0L, (long)BUFSIZ, False, XA_STRING, &actual_type, &actual_format, &nitems, &leftover, &data) != Success) { *name = NULL; return (0); } if ( (actual_type == XA_STRING) && (actual_format ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.