tools: add key events to the example client

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-03 12:04:00 +10:00
parent a9f07368a5
commit 39fcf16ec8

View file

@ -61,8 +61,12 @@ int main(int argc, char **argv)
struct ei_device *ptr = ei_device_new(ei);
ei_device_configure_capability(ptr, EI_DEVICE_CAP_POINTER);
struct ei_device *kbd = ei_device_new(ei);
ei_device_configure_capability(kbd, EI_DEVICE_CAP_KEYBOARD);
bool stop = false;
bool have_device = false;
bool have_ptr = false;
bool have_kbd = false;
while (!stop && poll(&fds, 1, 2000) > -1) {
ei_dispatch(ei);
@ -75,6 +79,7 @@ int main(int argc, char **argv)
case EI_EVENT_CONNECT:
printf("client: connected\n");
ei_device_add(ptr);
ei_device_add(kbd);
break;
case EI_EVENT_DISCONNECT:
{
@ -85,13 +90,19 @@ int main(int argc, char **argv)
case EI_EVENT_DEVICE_ADDED:
{
printf("client: our device was accepted\n");
have_device = true;
if (ei_event_get_device(e) == ptr)
have_ptr = true;
if (ei_event_get_device(e) == kbd)
have_kbd = true;
break;
}
case EI_EVENT_DEVICE_REMOVED:
{
printf("client: our device was removed\n");
have_device = false;
if (ei_event_get_device(e) == ptr)
have_ptr = true;
if (ei_event_get_device(e) == kbd)
have_kbd = true;
break;
}
default:
@ -100,7 +111,7 @@ int main(int argc, char **argv)
ei_event_unref(e);
}
if (have_device) {
if (have_ptr) {
printf("client: sending motion event\n");
ei_device_pointer_motion(ptr, -1, 1);
/* BTN_LEFT */
@ -108,6 +119,12 @@ int main(int argc, char **argv)
ei_device_pointer_button(ptr, 0x110, true);
ei_device_pointer_button(ptr, 0x110, false);
}
if (have_kbd) {
printf("client: sending key event\n");
ei_device_keyboard_key(kbd, 57, true); /* KEY_SPACE */
ei_device_keyboard_key(kbd, 57, false); /* KEY_SPACE */
}
}
ei_unref(ei);