2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef HAVE_CONFIG_H */
|
2009-01-31 10:33:39 -08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef ECORE_XTEST
|
|
|
|
# include <X11/extensions/XTest.h>
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef ECORE_XTEST */
|
2009-01-31 10:33:39 -08:00
|
|
|
|
2008-03-28 07:38:35 -07:00
|
|
|
#include "ecore_x_private.h"
|
|
|
|
#include "Ecore_X.h"
|
2009-04-16 10:17:36 -07:00
|
|
|
#include <string.h>
|
2008-03-28 07:38:35 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
EAPI Eina_Bool
|
2011-06-16 08:11:30 -07:00
|
|
|
#ifdef ECORE_XTEST
|
2008-03-28 07:38:35 -07:00
|
|
|
ecore_x_test_fake_key_down(const char *key)
|
2011-06-16 08:11:30 -07:00
|
|
|
#else
|
|
|
|
ecore_x_test_fake_key_down(const char *key __UNUSED__)
|
|
|
|
#endif
|
2008-03-28 07:38:35 -07:00
|
|
|
{
|
|
|
|
#ifdef ECORE_XTEST
|
2010-07-27 22:23:42 -07:00
|
|
|
KeyCode keycode = 0;
|
|
|
|
KeySym keysym;
|
|
|
|
|
2010-02-25 04:19:02 -08:00
|
|
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
2008-03-28 07:38:35 -07:00
|
|
|
if (!strncmp(key, "Keycode-", 8))
|
2011-10-20 22:40:59 -07:00
|
|
|
keycode = atoi(key + 8);
|
2008-03-28 07:38:35 -07:00
|
|
|
else
|
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
keysym = XStringToKeysym(key);
|
|
|
|
if (keysym == NoSymbol)
|
2011-10-20 22:40:59 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-27 22:23:42 -07:00
|
|
|
|
|
|
|
keycode = XKeysymToKeycode(_ecore_x_disp, keysym);
|
2008-03-28 07:38:35 -07:00
|
|
|
}
|
2010-07-27 22:23:42 -07:00
|
|
|
|
|
|
|
if (keycode == 0)
|
2011-10-20 22:40:59 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
return XTestFakeKeyEvent(_ecore_x_disp, keycode, 1, 0) ? EINA_TRUE : EINA_FALSE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#else /* ifdef ECORE_XTEST */
|
2010-09-26 10:49:05 -07:00
|
|
|
return EINA_FALSE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef ECORE_XTEST */
|
|
|
|
} /* ecore_x_test_fake_key_down */
|
2008-03-28 07:38:35 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
EAPI Eina_Bool
|
2011-06-16 08:11:30 -07:00
|
|
|
#ifdef ECORE_XTEST
|
2008-03-28 07:38:35 -07:00
|
|
|
ecore_x_test_fake_key_up(const char *key)
|
2011-06-16 08:11:30 -07:00
|
|
|
#else
|
|
|
|
ecore_x_test_fake_key_up(const char *key __UNUSED__)
|
|
|
|
#endif
|
2008-03-28 07:38:35 -07:00
|
|
|
{
|
|
|
|
#ifdef ECORE_XTEST
|
2010-07-27 22:23:42 -07:00
|
|
|
KeyCode keycode = 0;
|
|
|
|
KeySym keysym;
|
|
|
|
|
2010-02-25 04:19:02 -08:00
|
|
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
2008-03-28 07:38:35 -07:00
|
|
|
if (!strncmp(key, "Keycode-", 8))
|
2011-10-20 22:40:59 -07:00
|
|
|
keycode = atoi(key + 8);
|
2008-03-28 07:38:35 -07:00
|
|
|
else
|
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
keysym = XStringToKeysym(key);
|
|
|
|
if (keysym == NoSymbol)
|
2011-10-20 22:40:59 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-27 22:23:42 -07:00
|
|
|
|
|
|
|
keycode = XKeysymToKeycode(_ecore_x_disp, keysym);
|
2008-03-28 07:38:35 -07:00
|
|
|
}
|
2010-07-27 22:23:42 -07:00
|
|
|
|
|
|
|
if (keycode == 0)
|
2011-10-20 22:40:59 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
return XTestFakeKeyEvent(_ecore_x_disp, keycode, 0, 0) ? EINA_TRUE : EINA_FALSE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#else /* ifdef ECORE_XTEST */
|
2010-09-26 10:49:05 -07:00
|
|
|
return EINA_FALSE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef ECORE_XTEST */
|
|
|
|
} /* ecore_x_test_fake_key_up */
|
2008-07-16 10:05:31 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
EAPI Eina_Bool
|
2011-06-16 08:11:30 -07:00
|
|
|
#ifdef ECORE_XTEST
|
2008-07-16 10:05:31 -07:00
|
|
|
ecore_x_test_fake_key_press(const char *key)
|
2011-06-16 08:11:30 -07:00
|
|
|
#else
|
|
|
|
ecore_x_test_fake_key_press(const char *key __UNUSED__)
|
|
|
|
#endif
|
2008-07-16 10:05:31 -07:00
|
|
|
{
|
|
|
|
#ifdef ECORE_XTEST
|
2010-07-27 22:23:42 -07:00
|
|
|
KeyCode keycode = 0;
|
|
|
|
KeySym keysym = 0;
|
|
|
|
int shift = 0;
|
|
|
|
|
2010-02-25 04:19:02 -08:00
|
|
|
LOGFN(__FILE__, __LINE__, __FUNCTION__);
|
2008-07-16 10:05:31 -07:00
|
|
|
if (!strncmp(key, "Keycode-", 8))
|
2011-10-20 22:40:59 -07:00
|
|
|
keycode = atoi(key + 8);
|
2008-07-16 10:05:31 -07:00
|
|
|
else
|
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
keysym = XStringToKeysym(key);
|
|
|
|
if (keysym == NoSymbol)
|
2011-10-20 22:40:59 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-27 22:23:42 -07:00
|
|
|
|
|
|
|
keycode = XKeysymToKeycode(_ecore_x_disp, keysym);
|
|
|
|
if (XKeycodeToKeysym(_ecore_x_disp, keycode, 0) != keysym)
|
|
|
|
{
|
|
|
|
if (XKeycodeToKeysym(_ecore_x_disp, keycode, 1) == keysym)
|
2011-10-20 22:40:59 -07:00
|
|
|
shift = 1;
|
2010-07-27 22:23:42 -07:00
|
|
|
else
|
2011-10-20 22:40:59 -07:00
|
|
|
keycode = 0;
|
2010-07-27 22:23:42 -07:00
|
|
|
}
|
|
|
|
else
|
2011-10-20 22:40:59 -07:00
|
|
|
shift = 0;
|
2008-07-16 10:05:31 -07:00
|
|
|
}
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2008-07-16 10:05:31 -07:00
|
|
|
if (keycode == 0)
|
|
|
|
{
|
2010-07-27 22:23:42 -07:00
|
|
|
static int mod = 0;
|
|
|
|
KeySym *keysyms;
|
|
|
|
int keycode_min, keycode_max, keycode_num;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
XDisplayKeycodes(_ecore_x_disp, &keycode_min, &keycode_max);
|
|
|
|
keysyms = XGetKeyboardMapping(_ecore_x_disp, keycode_min,
|
|
|
|
keycode_max - keycode_min + 1,
|
|
|
|
&keycode_num);
|
|
|
|
mod = (mod + 1) & 0x7;
|
|
|
|
i = (keycode_max - keycode_min - mod - 1) * keycode_num;
|
|
|
|
|
|
|
|
keysyms[i] = keysym;
|
|
|
|
XChangeKeyboardMapping(_ecore_x_disp, keycode_min, keycode_num,
|
|
|
|
keysyms, (keycode_max - keycode_min));
|
|
|
|
XFree(keysyms);
|
|
|
|
XSync(_ecore_x_disp, False);
|
|
|
|
keycode = keycode_max - mod - 1;
|
2008-07-16 10:05:31 -07:00
|
|
|
}
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2008-07-16 10:05:31 -07:00
|
|
|
if (shift)
|
2011-10-20 22:40:59 -07:00
|
|
|
XTestFakeKeyEvent(_ecore_x_disp,
|
|
|
|
XKeysymToKeycode(_ecore_x_disp, XK_Shift_L), 1, 0);
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2010-08-02 10:47:49 -07:00
|
|
|
XTestFakeKeyEvent(_ecore_x_disp, keycode, 1, 0);
|
|
|
|
XTestFakeKeyEvent(_ecore_x_disp, keycode, 0, 0);
|
2008-07-16 10:05:31 -07:00
|
|
|
if (shift)
|
2011-10-20 22:40:59 -07:00
|
|
|
XTestFakeKeyEvent(_ecore_x_disp,
|
|
|
|
XKeysymToKeycode(_ecore_x_disp, XK_Shift_L), 0, 0);
|
2010-07-27 22:23:42 -07:00
|
|
|
|
2010-09-26 10:49:05 -07:00
|
|
|
return EINA_TRUE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#else /* ifdef ECORE_XTEST */
|
2010-09-26 10:49:05 -07:00
|
|
|
return EINA_FALSE;
|
2010-08-02 10:47:49 -07:00
|
|
|
#endif /* ifdef ECORE_XTEST */
|
|
|
|
} /* ecore_x_test_fake_key_press */
|
2008-07-16 10:05:31 -07:00
|
|
|
|
|
|
|
EAPI const char *
|
|
|
|
ecore_x_keysym_string_get(int keysym)
|
|
|
|
{
|
|
|
|
return XKeysymToString(keysym);
|
2010-08-02 10:47:49 -07:00
|
|
|
} /* ecore_x_keysym_string_get */
|
|
|
|
|