• Immutable Page
  • Info
  • Attachments

CompAction

A CompAction represents a binding/callback sequence in compiz for triggering plugin action options.

Class Definition

#define CompModAlt        0
#define CompModMeta       1
#define CompModSuper      2
#define CompModHyper      3
#define CompModModeSwitch 4
#define CompModNumLock    5
#define CompModScrollLock 6
#define CompModNum        7

#define CompAltMask        (1 << 16)
#define CompMetaMask       (1 << 17)
#define CompSuperMask      (1 << 18)
#define CompHyperMask      (1 << 19)
#define CompModeSwitchMask (1 << 20)
#define CompNumLockMask    (1 << 21)
#define CompScrollLockMask (1 << 22)

#define CompNoMask         (1 << 25)

/**
 * Context of an event occuring.
 */
class CompAction {
    public:
        typedef enum {
            StateInitKey     = 1 <<  0,
            StateTermKey     = 1 <<  1,
            StateInitButton  = 1 <<  2,
            StateTermButton  = 1 <<  3,
            StateInitBell    = 1 <<  4,
            StateInitEdge    = 1 <<  5,
            StateTermEdge    = 1 <<  6,
            StateInitEdgeDnd = 1 <<  7,
            StateTermEdgeDnd = 1 <<  8,
            StateCommit      = 1 <<  9,
            StateCancel      = 1 << 10,
            StateAutoGrab    = 1 << 11,
            StateNoEdgeDelay = 1 << 12
        } StateEnum;
        
        /**
         * Type of event a CompAction is bound to.
         */
        typedef enum {
            BindingTypeNone       = 0,
            BindingTypeKey        = 1 << 0,
            BindingTypeButton     = 1 << 1,
            BindingTypeEdgeButton = 1 << 2
        } BindingTypeEnum;

        class KeyBinding {
            public:
                KeyBinding ();
                KeyBinding (const KeyBinding&);
                KeyBinding (int keycode, unsigned int modifiers = 0);

                unsigned int modifiers () const;
                int keycode () const;

                bool fromString (const CompString &str);
                CompString toString () const;

            private:
                unsigned int mModifiers;
                int          mKeycode;
        };

        class ButtonBinding {
            public:
                ButtonBinding ();
                ButtonBinding (const ButtonBinding&);
                ButtonBinding (int button, unsigned int modifiers = 0);

                unsigned int modifiers () const;
                int button () const;

                bool fromString (const CompString &str);
                CompString toString () const;

            private:
                unsigned int mModifiers;
                int          mButton;
        };

        typedef unsigned int State;
        typedef unsigned int BindingType;
        typedef boost::function <bool (CompAction *, State, CompOption::Vector &)> CallBack;

    public:
        CompAction ();
        CompAction (const CompAction &);
        ~CompAction ();

        CallBack initiate ();
        CallBack terminate ();

        void setInitiate (const CallBack &initiate);
        void setTerminate (const CallBack &terminate);

        State state ();
        BindingType type ();

        KeyBinding & key ();
        void setKey (const KeyBinding &key);

        ButtonBinding & button ();
        void setButton (const ButtonBinding &button);

        unsigned int edgeMask ();
        void setEdgeMask (unsigned int edge);

        bool bell ();
        void setBell (bool bell);

        void setState (State state);

        void copyState (const CompAction &action);

        bool operator== (const CompAction& val);
        CompAction & operator= (const CompAction &action);

        bool keyFromString (const CompString &str);
        bool buttonFromString (const CompString &str);
        bool edgeMaskFromString (const CompString &str);

        CompString keyToString ();
        CompString buttonToString ();
        CompString edgeMaskToString ();

        static CompString edgeToString (unsigned int edge);

    private:
        PrivateAction *priv;
};

The State of the CompAction

A CompAction can be in the states listed by CompAction::StateEnum. This state mask can be retrieved with the ::state () member function. The state governs how the action behaves when it receives further events.

State

Behaviour

|| StateInitKey,

  • StateInitButton, StateInitEdge, StateInitEdgeDnd, StateInitBell || Trigger the initiate callback on the depress of a key, button, or the initial hit of an edge, etc ||

|| StateTermKey,

  • StateTermButton, StateTermEdge, StateTermEdgeDnd, StateTermBell || Trigger the terminate callback on the depress of a key, button, or the initial hit of an edge, etc ||

The state can also be set with the ::setState () member function. You should use this if you want to change the way the action behaves. Most plugins already do this if they want a callback to be triggered on a keybinding or button binding press and release. At the end of your initiate callback, you should set the state to the corresponding Term state to your Init state.

The Type of the CompAction

Actions fall into a few separate types, namely keys, buttons, edges, edgeDnD's and bells. This type can be retrieved with the ::type () member function.

Key Types

You can retrieve the keybinding subclass with the ::key () member function and set a new one with the ::setKey () function. From this data you can determine the X11 keycode with ::keycode () and also necessary modifiers with ::modifiers () to see what is necessary to trigger the keybinding. It is also possible to get the and set the binding from strings, with the ::toString () and ::fromString () member functions. The string must be formatted as so:

CompString keybindingString = "<Control><Alt>f" // For Control-Alt-f

Button Types

You can retrieve the buttonbinding subclass with the ::button () member function and set a new one with the ::setKey () function. From this data you can determine the button number with ::button () and also necessary modifiers with ::modifiers () to see what is necessary to trigger the keybinding. It is also possible to get the and set the binding from strings, with the ::toString () and ::fromString () member functions. The string must be formatted as so:

CompString buttonString = "<Control><Alt>Button3" // For Control-Alt-Right Click

Development/zero-nine/CoreClasses/CompAction (last edited 2010-09-05 02:25:08 by dsl-124-150-53-112)