1 #include "evas_common.h"
2 #include "evas_private.h"
7 evas_key_modifier_number(const Evas_Modifier *m, const char *keyname)
11 for (i = 0; i < m->mod.count; i++)
13 if (!strcmp(m->mod.list[i], keyname)) return i;
19 evas_key_lock_number(const Evas_Lock *l, const char *keyname)
23 for (i = 0; i < l->lock.count; i++)
25 if (!strcmp(l->lock.list[i], keyname)) return i;
35 * Returns a handle to the modifiers available in the system. This is required to check
36 * for modifiers with the evas_key_modifier_is_set_get function.
39 * @see evas_key_modifier_add
40 * @see evas_key_modifier_del
41 * @see evas_key_modifier_on
42 * @see evas_key_modifier_off
43 * @see evas_key_modifier_is_set_get
45 * @param e The pointer to the Evas Canvas
47 * @return An Evas_Modifier handle to query the modifier subsystem with
48 * evas_key_modifier_is_set_get, or NULL on error.
50 EAPI const Evas_Modifier *
51 evas_key_modifier_get(const Evas *e)
53 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
56 return &(e->modifiers);
60 * Returns a handle to the locks available in the system. This is required to check for
61 * locks with the evas_key_lock_is_set_get function.
63 * @see evas_key_lock_add
64 * @see evas_key_lock_del
65 * @see evas_key_lock_on
66 * @see evas_key_lock_off
68 * @see evas_key_lock_is_set_get
69 * @param e The pointer to the Evas Canvas
71 * @return An Evas_Lock handle to query the lock subsystem with
72 * evas_key_lock_is_set_get, or NULL on error.
74 EAPI const Evas_Lock *
75 evas_key_lock_get(const Evas *e)
77 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
84 * Checks the state of a given modifier. If the modifier is set, such as shift being pressed
85 * this function returns true.
87 * @see evas_key_modifier_add
88 * @see evas_key_modifier_del
89 * @see evas_key_modifier_get
90 * @see evas_key_modifier_on
91 * @see evas_key_modifier_off
93 * @param m The current modifier set as returned by evas_key_modifier_get.
94 * @param keyname The name of the key to check its status.
96 * @return 1 if the @p keyname is on, 0 otherwise.
99 evas_key_modifier_is_set(const Evas_Modifier *m, const char *keyname)
101 Evas_Modifier_Mask num;
105 if (!keyname) return 0;
106 n = evas_key_modifier_number(m, keyname);
108 num = (Evas_Modifier_Mask)n;
110 if (m->mask & num) return 1;
115 * Checks the state of a given lock. If the lock is set, such as caps lock, this function
118 * @see evas_key_lock_get
119 * @see evas_key_lock_add
120 * @see evas_key_lock_del
121 * @see evas_key_lock_on
122 * @see evas_key_lock_off
124 * @param l The current lock set as returned by evas_key_lock_get.
125 * @param keyname The name of the lock to add the the list.
127 * @param 1 if the @p keyname kock is set, 0 otherwise.
130 evas_key_lock_is_set(const Evas_Lock *l, const char *keyname)
132 Evas_Modifier_Mask num;
136 if (!keyname) return 0;
137 n = evas_key_lock_number(l, keyname);
139 num = (Evas_Modifier_Mask)n;
141 if (l->mask & num) return 1;
146 * Adds the @p keyname to the current list of modifiers.
148 * Modifiers can be keys like shift, alt and ctrl, as well as user defined. This allows
149 * custom modifiers to be added to the evas system as run time. It is then possible to set
150 * and unset the modifier for other parts of the program to check and act on.
152 * @see evas_key_modifier_del
153 * @see evas_key_modifier_get
154 * @see evas_key_modifier_on
155 * @see evas_key_modifier_off
156 * @see evas_key_modifier_is_set_get
158 * @param e The pointer to the Evas Canvas
159 * @param keyname The name of the modifier to add to the list.
162 evas_key_modifier_add(Evas *e, const char *keyname)
164 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
167 if (!keyname) return;
168 if (e->modifiers.mod.count >= 64) return;
169 evas_key_modifier_del(e, keyname);
170 e->modifiers.mod.count++;
171 e->modifiers.mod.list = realloc(e->modifiers.mod.list, e->modifiers.mod.count * sizeof(char *));
172 e->modifiers.mod.list[e->modifiers.mod.count - 1] = strdup(keyname);
173 e->modifiers.mask = 0;
177 * Removes the @p keyname from the current list of modifiers.
179 * @see evas_key_modifier_add
180 * @see evas_key_modifier_get
181 * @see evas_key_modifier_on
182 * @see evas_key_modifier_off
183 * @see evas_key_modifier_is_set_get
185 * @param e The pointer to the Evas Canvas
186 * @param keyname The name of the key to remove from the modifiers list.
189 evas_key_modifier_del(Evas *e, const char *keyname)
193 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
196 if (!keyname) return;
197 for (i = 0; i < e->modifiers.mod.count; i++)
199 if (!strcmp(e->modifiers.mod.list[i], keyname))
203 free(e->modifiers.mod.list[i]);
204 e->modifiers.mod.count--;
205 for (j = i; j < e->modifiers.mod.count; j++)
206 e->modifiers.mod.list[j] = e->modifiers.mod.list[j + 1];
207 e->modifiers.mask = 0;
214 * Adds the @p keyname to the current list of locks.
216 * Locks can be keys like caps lock, num lock or scroll lock, as well as user defined. This
217 * allows custom locks to be added to the evas system at run time. It is then possible to
218 * set and unset the lock for other parts of the program to check and act on.
220 * @see evas_key_lock_get
221 * @see evas_key_lock_del
222 * @see evas_key_lock_on
223 * @see evas_key_lock_off
225 * @param e The pointer to the Evas Canvas
226 * @param keyname The name of the key to remove from the modifier list.
229 evas_key_lock_add(Evas *e, const char *keyname)
231 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
234 if (!keyname) return;
235 if (e->locks.lock.count >= 64) return;
236 evas_key_lock_del(e, keyname);
237 e->locks.lock.count++;
238 e->locks.lock.list = realloc(e->locks.lock.list, e->locks.lock.count * sizeof(char *));
239 e->locks.lock.list[e->locks.lock.count - 1] = strdup(keyname);
244 * Removes The @p keyname from the current list of locks.
246 * @see evas_key_lock_get
247 * @see evas_key_lock_add
248 * @see evas_key_lock_on
249 * @see evas_key_lock_off
251 * @param e The pointer to the Evas Canvas
252 * @param keyname The name of the key to remove from the lock list.
255 evas_key_lock_del(Evas *e, const char *keyname)
259 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
262 if (!keyname) return;
264 for (i = 0; i < e->locks.lock.count; i++)
266 if (!strcmp(e->locks.lock.list[i], keyname))
270 free(e->locks.lock.list[i]);
271 e->locks.lock.count--;
272 for (j = i; j < e->locks.lock.count; j++)
273 e->locks.lock.list[j] = e->locks.lock.list[j + 1];
281 * Enables or turns on the modifier with name @p keyname.
283 * @see evas_key_modifier_add
284 * @see evas_key_modifier_get
285 * @see evas_key_modifier_off
286 * @see evas_key_modifier_is_set_get
288 * @param e The pointer to the Evas Canvas
289 * @param keyname The name of the modifier to set.
292 evas_key_modifier_on(Evas *e, const char *keyname)
294 Evas_Modifier_Mask num;
297 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
300 n = (Evas_Modifier_Mask)evas_key_modifier_number(&(e->modifiers), keyname);
302 num = (Evas_Modifier_Mask)n;
304 e->modifiers.mask |= num;
308 * Disables or turns off the modifier with name @p keyname.
310 * @see evas_key_modifier_add
311 * @see evas_key_modifier_get
312 * @see evas_key_modifier_on
313 * @see evas_key_modifier_is_set_get
315 * @param e The pointer to the Evas Canvas
316 * @param keyname The name of the modifier to un-set.
319 evas_key_modifier_off(Evas *e, const char *keyname)
321 Evas_Modifier_Mask num;
324 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
327 n = evas_key_modifier_number(&(e->modifiers), keyname);
329 num = (Evas_Modifier_Mask)n;
331 e->modifiers.mask &= ~num;
335 * Enables or turns on the lock with name @p keyname.
337 * @see evas_key_lock_get
338 * @see evas_key_lock_add
339 * @see evas_key_lock_del
340 * @see evas_key_lock_off
342 * @param e The pointer to the Evas Canvas
343 * @param keyname The name of the lock to set.
346 evas_key_lock_on(Evas *e, const char *keyname)
348 Evas_Modifier_Mask num;
351 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
354 n = evas_key_lock_number(&(e->locks), keyname);
356 num = (Evas_Modifier_Mask)n;
358 e->locks.mask |= num;
362 * Disables or turns off the lock with name @p keyname.
364 * @see evas_key_lock_get
365 * @see evas_key_lock_add
366 * @see evas_key_lock_del
367 * @see evas_key_lock_on
369 * @param e The pointer to the Evas Canvas
370 * @param keyname The name of the lock to un-set.
373 evas_key_lock_off(Evas *e, const char *keyname)
375 Evas_Modifier_Mask num;
378 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
381 n = evas_key_lock_number(&(e->locks), keyname);
383 num = (Evas_Modifier_Mask)n;
385 e->locks.mask &= ~num;
388 /* errr need to add key grabbing/ungrabbing calls - missing modifier stuff. */
391 * Creates a bit mask from the @p keyname for use with events to check for the presence
392 * of the @p keyname modifier.
394 * @see evas_key_modifier_add
395 * @see evas_key_modifier_get
396 * @see evas_key_modifier_on
397 * @see evas_key_modifier_off
398 * @see evas_key_modifier_is_set_get
400 * @param keyname The name of the modifier to create the mask for.
402 * @returns the bit mask or 0 if the @p keyname wasn't registered as a modifier.
404 EAPI Evas_Modifier_Mask
405 evas_key_modifier_mask_get(const Evas *e, const char *keyname)
407 Evas_Modifier_Mask num;
410 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
413 if (!keyname) return 0;
414 n = evas_key_modifier_number(&(e->modifiers), keyname);
416 num = (Evas_Modifier_Mask)n;