next up previous contents index
Next: 4. Managing the Virtual Up: 8. When the Keyboard Previous: 2. The Virtual Bindings   Contents   Index

3. Managing the Modifier Mappings

There are three functions available for messing about with the current mapping of the Alt modifier (remember that these ones are LESSTIF-specific!):

_XmRefreshVirtKeys


XmModifierMaskSetReference _XmGetModifierMappingsForDisplay(Display *dpy);
void _XmInvalidateModifierMappingsForDisplay(Display *dpy);
void _XmRefreshVirtKeys(Widget w);

You'll normally use only _XmGetModifierMappingsForDisplay(). This function reports the current mapping as a pointer to a XmModifiersMaskSet (and surely gets an olympic medal for its name's length). This set is simply an array that holds the modifier masks for the Alt, Meta, Super, and Hyper modifier keys. If LESSTIF can't find a binding for the Alt key it will fall back to the Mod1 modifier mask as the Alt modifier mask.

To get the modifier mask of the Alt modifier, just use the index ALTModifier into the array:


#ifdef LESSTIF_VERSION
#include <Xm/VirtKeysP.h>
    XmModifierMaskSetReference ModifierMasks;
#endif
    Modifiers                  Alt, someModifierFlags;

#ifdef LESSTIF_VERSION
    ModifierMasks = _XmGetModifierMappingsForDisplay(dpy);
    Alt           = ModifierMasks[ALTModifier];
#else
    Alt           = Mod1Mask;
#endif

    someModifierFlags = ... ;
    if ( someModifierFlags & Alt ) {
        .... ;
    }

The result of _XmGetModifierMappingsForDisplay() is cached so all but the first request won't result in a round-trip to the X server. The modifier mask set belongs to the cache, so be sure to never free it.

When the user changes the modifier mapping during the lifetime of a LESSTIF based application, LESSTIF receives a MappingNotify event and updates its modifier cache as well as the virtual bindings by calling _XmRefreshVirtKeys(). If for any reason you must invalidate the modifier mapping cache, you can call _XmInvalidateModifierMappingsForDisplay(). Any pointer to the modifier mapping array for the respective display then gets invalid!


next up previous contents index
Next: 4. Managing the Virtual Up: 8. When the Keyboard Previous: 2. The Virtual Bindings   Contents   Index
Danny Backx
2000-12-13