Xlib and GLX: Part 2

From Sidvind
Revision as of 18:39, 5 December 2006 by EXt (Talk | contribs) (Wrote about XLookupString)

Jump to: navigation, search

Description

Still not tired of Xlib and GLX? In this part I will talk about how to handle the window managers fscking close-button.

This article required lots of cleanup ><

Catching the WM close-button

Code:

{{{2}}}

Run that code any time after creating the window. Now you can catch the event ClientMessage in your event loop. When that event is caught you need to check if event.xclient.data.l[0] equals GLWindow.wm_delete_window.

Now, if just someone could have told me this instead of me having to dig through hundreds of lines of X code.

Getting keyboard input

First, make sure your window has been created with the KeyPressMask.

In your X Event look for the KeyPress event. The event.xkey struct contains enought info to be converted to an ascii character using XLookupString. XLookupString returns the numbers of characters written to the buffer. In this case a maximum of 1 can be written. If a non-printable character occurs the lenght will be 0. XLookupString also looks for key modifiers like shift and alt.

Code:

{{{2}}}