• Immutable Page
  • Info
  • Attachments

ModifierHandler

The ModifierHandler class is a toplevel class which describes display-level keycodes and modifiers. It can be used to sync X11 modifier information with compiz. It also contains some information about the bitmasks of the current modifier mappings.

Class Definition

class ModifierHandler
{
    public:

        ModifierHandler ();
        ~ModifierHandler ();

        typedef enum
        {
            Alt = 1,
            Meta,
            Super,
            Hyper,
            ModeSwitch,
            NumLock,
            ScrollLock,
            ModNum
        } Modifier;

        typedef enum
        {
            AltMask        = (1 << 16),
            MetaMask       = (1 << 17),
            SuperMask      = (1 << 18),
            HyperMask      = (1 << 19),
            ModeSwitchMask = (1 << 20),
            NumLockMask    = (1 << 21),
            ScrollLockMask = (1 << 22),
            NoMask         = (1 << 25),
        } ModMask;

    public:


        /**
         * Takes an X11 Keycode and returns a bitmask
         * with modifiers that have been pressed
         */
        unsigned int keycodeToModifiers (int keycode);

        /**
         * Updates X11 Modifier mappings
         */
        void updateModifierMappings ();

        /**
         * Takes a virtual modMask and returns a real modifier mask
         * by removing unused bits
         */
        unsigned int virtualToRealModMask (unsigned int modMask);

        /**
         * Returns a bit modifier mask for a Motifier enum
         */
        unsigned int modMask (Modifier);

        /**
         * Returns a const bit modifier mask for what should be ignored
         */
        unsigned int ignoredModMask ();

        /**
         * Returns a const XModifierKeymap for compiz
         */
        const XModifierKeymap * modMap ();

        friend class CompScreen;

    private:

        static const unsigned int virtualModMask[7];

        static const int maskTable[8];

        static const int maskTableSize = 8;

        ModMask    mModMask[ModNum];
        unsigned int    mIgnoredModMask;
        XModifierKeymap *mModMap;
};

Getting the ignored Modifier Mask

If you are reading modifier keys manually through X Events, you will need to compared with modifier masks which are ignored such that your plugin's event won't be triggered unintentionally. To do this, you can used the ::ignoredModMask () method. For example:

unsigned int modMask = REAL_MOD_MASK & ~modHandler->ignoredModMask ();

Converting between keycodes and modifier masks

If you are reading keycodes directly from X events, you will need to convert them to modifier masks before you can compare it with any ModifierHandler::ModMask. To do this, you need to use the ::keycodeToModifiers (unsigned int); function with your keycode.

It is also possible to convert from a ModifierHandler::Modifier to a ModifierHandler::ModMask through the use of the ::modMask (Modifier); method.

Development/zero-nine/CoreClasses/ModifierHandler (last edited 2010-07-26 14:45:16 by 124-169-107-122)