Next: , Previous: Gtk GL Extras, Up: Top

13 Tips and Techniques

Don't be tempted to make a (define app ...) for a top-level application widget or similar. In Guile 1.6.4 app is used for the implementation of the module system and a new binding will stop use-modules working.
When forking a child process, care should be taken that the child doesn't call any Gtk functions, since the child has a dup of the X server connection and doing anything on it will upset the parent's communications, probably causing a crash.

Or the parent could leave the connection alone and let the child use it. The point is that only one of the two may use it. This is the same as in a C program.

Gtk sets up certain atexit handlers to shutdown its server connection, and these mustn't run in the child either. In Guile 1.8.1 and higher primitive-_exit (see Processes) can be used to exit without running those handlers. In earlier versions the suggestion is for a child to exec a do-nothing program when it wants to exit (either normally or for some exception). Eg. an error exit,

          (execl "/bin/false" "/bin/false")

For reference, the current implementation of (ice-9 popen) is safe, provided no errors are encountered in the child setups or spawning of /bin/sh.

Multiple return values
When working with the Guile Gtk functions returning multiple values it can be convenient to get those into separate variables. One easy way is for instance,
          (define (list-apply lst proc)
            (apply proc lst))
          (list-apply (gtk-accelerator-parse str)
            (lambda (key mods)

Or for instance the same with a syntax similar to receive (see Returning and Accepting Multiple Values),

          (define-macro (receive-list vars expr . body)
            `(apply (lambda ,vars ,@body) ,expr))
          (receive-list (key mods)
              (gtk-accelerator-parse str)