mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-01-08 00:00:16 +01:00
tools: add touch support to the ei-demo-client
This commit is contained in:
parent
46bef9fe86
commit
44295ab044
1 changed files with 58 additions and 0 deletions
|
|
@ -279,11 +279,13 @@ int main(int argc, char **argv)
|
|||
_unref_(ei_device) *ptr = NULL;
|
||||
_unref_(ei_device) *kbd = NULL;
|
||||
_unref_(ei_device) *abs = NULL;
|
||||
_unref_(ei_device) *touch = NULL;
|
||||
|
||||
bool stop = false;
|
||||
bool have_ptr = false;
|
||||
bool have_kbd = false;
|
||||
bool have_abs = false;
|
||||
bool have_touch = false;
|
||||
struct ei_seat *default_seat = NULL;
|
||||
|
||||
uint32_t sequence = 0;
|
||||
|
|
@ -344,6 +346,11 @@ int main(int argc, char **argv)
|
|||
abs = ei_device_ref(device);
|
||||
handle_regions(device);
|
||||
}
|
||||
if (ei_device_has_capability(device, EI_DEVICE_CAP_TOUCH)) {
|
||||
colorprint("New touch device: %s\n", ei_device_get_name(device));
|
||||
touch = ei_device_ref(device);
|
||||
handle_regions(device);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EI_EVENT_DEVICE_RESUMED:
|
||||
|
|
@ -365,6 +372,12 @@ int main(int argc, char **argv)
|
|||
colorprint("Abs pointer device was resumed\n");
|
||||
have_abs = true;
|
||||
}
|
||||
if (ei_event_get_device(e) == touch) {
|
||||
if (!receiver)
|
||||
ei_device_start_emulating(touch, ++sequence);
|
||||
colorprint("Touch device was resumed\n");
|
||||
have_touch = true;
|
||||
}
|
||||
break;
|
||||
case EI_EVENT_DEVICE_PAUSED:
|
||||
if (ei_event_get_device(e) == ptr) {
|
||||
|
|
@ -379,6 +392,10 @@ int main(int argc, char **argv)
|
|||
colorprint("Abs pointer device was paused\n");
|
||||
have_abs = false;
|
||||
}
|
||||
if (ei_event_get_device(e) == touch) {
|
||||
colorprint("Touch device was paused\n");
|
||||
have_touch = false;
|
||||
}
|
||||
break;
|
||||
case EI_EVENT_DEVICE_REMOVED:
|
||||
{
|
||||
|
|
@ -441,6 +458,21 @@ int main(int argc, char **argv)
|
|||
ei_event_keyboard_get_key_is_press(e) ? "press" : "release");
|
||||
}
|
||||
break;
|
||||
case EI_EVENT_TOUCH_DOWN:
|
||||
case EI_EVENT_TOUCH_MOTION:
|
||||
{
|
||||
colorprint("touch %s %u %.2f/%.2f\n",
|
||||
ei_event_get_type(e) == EI_EVENT_TOUCH_DOWN ? "down" : "motion",
|
||||
ei_event_touch_get_id(e),
|
||||
ei_event_touch_get_x(e),
|
||||
ei_event_touch_get_y(e));
|
||||
}
|
||||
break;
|
||||
case EI_EVENT_TOUCH_UP:
|
||||
{
|
||||
colorprint("touch up %u\n", ei_event_touch_get_id(e));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
|
@ -492,6 +524,32 @@ int main(int argc, char **argv)
|
|||
ei_device_frame(abs, now);
|
||||
now += interval;
|
||||
}
|
||||
|
||||
if (have_touch) {
|
||||
static int x, y;
|
||||
static int counter = 0;
|
||||
static struct ei_touch *t;
|
||||
|
||||
switch (counter++ % 5) {
|
||||
case 0:
|
||||
colorprint("sending touch down event\n");
|
||||
t = ei_device_touch_new(touch);
|
||||
ei_touch_down(t, 100 + ++x, 200 - ++y);
|
||||
ei_device_frame(touch, now);
|
||||
break;
|
||||
case 4:
|
||||
colorprint("sending touch down event\n");
|
||||
ei_touch_up(t);
|
||||
ei_device_frame(touch, now);
|
||||
t = ei_touch_unref(t);
|
||||
break;
|
||||
default:
|
||||
ei_touch_motion(t, 100 + ++x, 200 - ++y);
|
||||
ei_device_frame(touch, now);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue