summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/elput/elput_evdev.c112
1 files changed, 84 insertions, 28 deletions
diff --git a/src/lib/elput/elput_evdev.c b/src/lib/elput/elput_evdev.c
index 56aa78135b..4e5a960231 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -384,44 +384,100 @@ _keyboard_remapped_key_get(Elput_Device *edev, int code)
384static int 384static int
385_keyboard_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes) 385_keyboard_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
386{ 386{
387 unsigned long hbytes = 0; 387/* this function is copied, with slight changes in variable names, from KeyBind.c in libX11
388 unsigned char c; 388 * the license from that file can be found below:
389 389 */
390/*
391
392Copyright 1985, 1987, 1998 The Open Group
393
394Permission to use, copy, modify, distribute, and sell this software and its
395documentation for any purpose is hereby granted without fee, provided that
396the above copyright notice appear in all copies and that both that
397copyright notice and this permission notice appear in supporting
398documentation.
399
400The above copyright notice and this permission notice shall be included in
401all copies or substantial portions of the Software.
402
403THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
404IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
405FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
406OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
407AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
408CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
409
410Except as contained in this notice, the name of The Open Group shall not be
411used in advertising or otherwise to promote the sale, use or other dealings
412in this Software without prior written authorization from The Open Group.
413
414*/
390 if (!keysym) return 0; 415 if (!keysym) return 0;
391 hbytes = (keysym >> 8);
392
393 if (!(bytes &&
394 ((hbytes == 0) ||
395 ((hbytes == 0xFF) &&
396 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
397 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
398 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
399 (keysym == XKB_KEY_KP_Enter) ||
400 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
401 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
402 return 0;
403
404 if (keysym == XKB_KEY_KP_Space)
405 c = (XKB_KEY_space & 0x7F);
406 else if (hbytes == 0xFF)
407 c = (keysym & 0x7F);
408 else
409 c = (keysym & 0xFF);
410 416
417 /* check for possible control codes */
411 if (modifiers & ECORE_EVENT_MODIFIER_CTRL) 418 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
412 { 419 {
413 if (((c >= '@') && (c < '\177')) || c == ' ') 420 Eina_Bool valid_control_code = EINA_TRUE;
421 unsigned long hbytes = 0;
422 unsigned char c;
423
424 hbytes = (keysym >> 8);
425 if (!(bytes &&
426 ((hbytes == 0) ||
427 ((hbytes == 0xFF) &&
428 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
429 (keysym == XKB_KEY_Return) ||
430 (keysym == XKB_KEY_Escape) ||
431 (keysym == XKB_KEY_KP_Space) ||
432 (keysym == XKB_KEY_KP_Tab) ||
433 (keysym == XKB_KEY_KP_Enter) ||
434 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
435 (keysym == XKB_KEY_KP_Equal) ||
436 (keysym == XKB_KEY_Delete))))))
437 return 0;
438
439 if (keysym == XKB_KEY_KP_Space)
440 c = (XKB_KEY_space & 0x7F);
441 else if (hbytes == 0xFF)
442 c = (keysym & 0x7F);
443 else
444 c = (keysym & 0xFF);
445
446 /* We are building here a control code
447 for more details, read:
448 https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_.28ASCII_and_derivatives.29
449 */
450
451 if (((c >= '@') && (c <= '_')) || /* those are the one defined in C0 with capital letters */
452 ((c >= 'a') && (c <= 'z')) || /* the lowercase symbols (not part of the standard, but usefull */
453 c == ' ')
414 c &= 0x1F; 454 c &= 0x1F;
455 else if (c == '\x7f')
456 c = '\177';
457 /* following codes are alternatives, they are longer here, i dont want to change them */
415 else if (c == '2') 458 else if (c == '2')
416 c = '\000'; 459 c = '\000'; /* 0 code */
417 else if ((c >= '3') && (c <= '7')) 460 else if ((c >= '3') && (c <= '7'))
418 c -= ('3' - '\033'); 461 c -= ('3' - '\033'); /* from escape to unitseperator code*/
419 else if (c == '8') 462 else if (c == '8')
420 c = '\177'; 463 c = '\177'; /* delete code */
421 else if (c == '/') 464 else if (c == '/')
422 c = '_' & 0x1F; 465 c = '_' & 0x1F; /* unit seperator code */
466 else
467 valid_control_code = EINA_FALSE;
468
469 if (valid_control_code)
470 buffer[0] = c;
471 else
472 return 0;
423 } 473 }
424 buffer[0] = c; 474 else
475 {
476 /* if its not a control code, try to produce a usefull output */
477 if (!xkb_keysym_to_utf8(keysym, buffer, bytes))
478 return 0;
479 }
480
425 return 1; 481 return 1;
426} 482}
427 483