1 #ifndef _keymapper__hpp__included__
2 #define _keymapper__hpp__included__
13 * Takes in a raw command and returns the command that should be actually executed given the key polarity.
15 * parameter cmd: Raw command.
16 * parameter polarity: Polarity (True => Being pressed, False => Being released).
17 * returns: The fixed command, "" if no command should be executed.
18 * throws std::bad_alloc: Not enough memory.
20 std::string
fixup_command_polarity(std::string cmd
, bool polarity
) throw(std::bad_alloc
);
33 modifier(const std::string
& name
) throw(std::bad_alloc
);
35 * Create linked modifier.
37 modifier(const std::string
& name
, const std::string
& linkgroup
) throw(std::bad_alloc
);
41 static modifier
& lookup(const std::string
& name
) throw(std::bad_alloc
, std::runtime_error
);
43 * Get name of modifier.
45 std::string
name() const throw(std::bad_alloc
);
48 modifier(const modifier
&);
49 modifier
& operator=(const modifier
&);
62 void add(const modifier
& mod
, bool really
= true) throw(std::bad_alloc
);
66 void remove(const modifier
& mod
, bool really
= true) throw(std::bad_alloc
);
68 * Construct set from string.
70 static modifier_set
construct(const std::string
& modifiers
) throw(std::bad_alloc
, std::runtime_error
);
72 * Check modifier against its mask for validity.
74 static bool valid(const modifier_set
& set
, const modifier_set
& mask
) throw(std::bad_alloc
);
76 * Check if this modifier set triggers the action.
78 static bool triggers(const modifier_set
& set
, const modifier_set
& trigger
, const modifier_set
& mask
)
79 throw(std::bad_alloc
);
83 bool operator==(const modifier_set
& m
) const throw();
86 std::set
<const modifier
*> set
;
109 * Pressure-sensitive button
121 KT_AXIS_PAIR_INVERSE
,
128 * Create new key group.
130 keygroup(const std::string
& name
, enum type t
) throw(std::bad_alloc
);
132 * Change type of key group.
134 void change_type(enum type t
);
136 * Change calibration (Axis pairs and pressure buttons only).
138 void change_calibration(short left
, short center
, short right
, double tolerance
);
140 * Change state of this key group.
142 * For KT_KEY, value is zero/nonzero.
143 * For KT_PRESSURE_* and KT_AXIS_PAIR*, value is -32768...32767.
144 * For KT_HAT, 1 is up, 2 is right, 4 is down, 8 is left (may be ORed).
146 void set_position(short pos
, const modifier_set
& modifiers
) throw();
148 * Look up key by name.
150 static std::pair
<keygroup
*, unsigned> lookup(const std::string
& name
) throw(std::bad_alloc
,
155 std::string
name() throw(std::bad_alloc
);
157 * Keyboard key listener.
164 virtual void key_event(const modifier_set
& modifiers
, keygroup
& keygroup
, unsigned subkey
,
165 bool polarity
, const std::string
& name
) = 0;
170 void add_key_listener(key_listener
& l
) throw(std::bad_alloc
);
172 * Remove key listener.
174 void remove_key_listener(key_listener
& l
) throw(std::bad_alloc
);
176 * Excelusive key listener.
178 static void set_exclusive_key_listener(key_listener
* l
) throw();
185 double cal_tolerance
;
186 double compensate(short value
);
187 double compensate2(double value
);
188 void run_listeners(const modifier_set
& modifiers
, unsigned subkey
, bool polarity
, bool really
, double x
);
189 std::list
<key_listener
*> listeners
;
191 static key_listener
* exclusive
;
195 * This class handles internals of mapping events from keyboard buttons and pseudo-buttons.
202 * Binds a key, erroring out if binding would conflict with existing one.
204 * parameter mod: Modifier set to require to be pressed.
205 * parameter modmask: Modifier set to take into account.
206 * parameter keyname: Key to bind the action to.
207 * parameter command: The command to bind.
208 * throws std::bad_alloc: Not enough memory.
209 * throws std::runtime_error: The binding would conflict with existing one or invalid modifier/key.
211 static void bind(std::string mod
, std::string modmask
, std::string keyname
, std::string command
)
212 throw(std::bad_alloc
, std::runtime_error
);
214 * Unbinds a key, erroring out if binding does not exist..
216 * parameter mod: Modifier set to require to be pressed.
217 * parameter modmask: Modifier set to take into account.
218 * parameter keyname: Key to bind the action to.
219 * throws std::bad_alloc: Not enough memory.
220 * throws std::runtime_error: The binding does not exist.
222 static void unbind(std::string mod
, std::string modmask
, std::string keyname
) throw(std::bad_alloc
,
226 * Dump list of bindigns as message to console.
228 * throws std::bad_alloc: Not enough memory.
230 static void dumpbindings() throw(std::bad_alloc
);