summaryrefslogtreecommitdiff
path: root/include/compaction.h
blob: 22f77fd66643427e0c8ac4a9b17d373556e1c80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef _COMPACTION_H
#define _COMPACTION_H

#include <boost/function.hpp>

#include <compoption.h>

class PrivateAction;

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;

	typedef enum {
	    BindingTypeNone       = 0,
	    BindingTypeKey        = 1 << 0,
	    BindingTypeButton     = 1 << 1,
	    BindingTypeEdgeButton = 1 << 2
	} BindingTypeEnum;

	class KeyBinding {
	    public:
		KeyBinding ();
		KeyBinding (const KeyBinding&);

		unsigned int modifiers ();
		int keycode ();

		bool fromString (CompDisplay *d, const CompString str);
		CompString toString (CompDisplay *d);

	    private:
		unsigned int mModifiers;
		int          mKeycode;
	};

	class ButtonBinding {
	    public:
		ButtonBinding ();
		ButtonBinding (const ButtonBinding&);

		unsigned int modifiers ();
		int button ();

		bool fromString (CompDisplay *d, const CompString str);
		CompString toString (CompDisplay *d);

	    private:
		unsigned int mModifiers;
		int          mButton;
	};

	typedef unsigned int State;
	typedef unsigned int BindingType;
	typedef boost::function <bool (CompDisplay *, 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 ();
	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);

	void keyFromString (CompDisplay *d, const CompString str);
	void buttonFromString (CompDisplay *d, const CompString str);
	void edgeMaskFromString (const CompString str);

	CompString keyToString (CompDisplay *d);
	CompString buttonToString (CompDisplay *d);
	CompString edgeMaskToString ();

	static CompString edgeToString (unsigned int edge);

    private:
	PrivateAction *priv;
};

#endif