mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-28 19:00:18 +01:00
tools: add touchscreen support to the eis-demo-server
This commit is contained in:
parent
8c2f51fcff
commit
46bef9fe86
2 changed files with 71 additions and 1 deletions
|
|
@ -122,6 +122,7 @@ eis_demo_client_destroy(struct eis_demo_client *democlient)
|
|||
eis_device_unref(democlient->ptr);
|
||||
eis_device_unref(democlient->abs);
|
||||
eis_device_unref(democlient->kbd);
|
||||
eis_device_unref(democlient->touchscreen);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -303,8 +304,19 @@ add_device(struct eis_demo_server *server, struct eis_client *client,
|
|||
break;
|
||||
}
|
||||
case EIS_DEVICE_CAP_TOUCH:
|
||||
assert(!"Not implemented");
|
||||
{
|
||||
struct eis_device *touchscreen = eis_seat_new_device(seat);
|
||||
eis_device_configure_name(touchscreen, "test touchscreen");
|
||||
eis_device_configure_capability(touchscreen, EIS_DEVICE_CAP_TOUCH);
|
||||
colorprint("Creating touchscreen device %s for %s\n", eis_device_get_name(touchscreen),
|
||||
eis_client_get_name(client));
|
||||
eis_device_add(touchscreen);
|
||||
eis_device_resume(touchscreen);
|
||||
if (!eis_client_is_sender(client))
|
||||
eis_device_start_emulating(touchscreen, ++sequence);
|
||||
device = steal(&touchscreen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return device;
|
||||
|
|
@ -391,6 +403,16 @@ eis_demo_server_printf_handle_event(struct eis_demo_server *server,
|
|||
}
|
||||
}
|
||||
|
||||
if (eis_event_seat_has_capability(e, EIS_DEVICE_CAP_TOUCH)) {
|
||||
if (!democlient->touchscreen)
|
||||
democlient->touchscreen = add_device(server, client, seat, EIS_DEVICE_CAP_TOUCH);
|
||||
} else {
|
||||
if (democlient->touchscreen) {
|
||||
eis_device_remove(democlient->touchscreen);
|
||||
democlient->touchscreen = eis_device_unref(democlient->touchscreen);
|
||||
}
|
||||
}
|
||||
|
||||
/* Special "Feature", if all caps are unbound remove the seat.
|
||||
* This is a demo server after all, so let's demo this. */
|
||||
if (!eis_event_seat_has_capability(e, EIS_DEVICE_CAP_POINTER) &&
|
||||
|
|
@ -418,6 +440,9 @@ eis_demo_server_printf_handle_event(struct eis_demo_server *server,
|
|||
if (democlient->kbd == device)
|
||||
democlient->kbd = NULL;
|
||||
|
||||
if (democlient->touchscreen == device)
|
||||
democlient->touchscreen = NULL;
|
||||
|
||||
eis_device_unref(device);
|
||||
}
|
||||
break;
|
||||
|
|
@ -475,6 +500,21 @@ eis_demo_server_printf_handle_event(struct eis_demo_server *server,
|
|||
eis_event_keyboard_get_key_is_press(e));
|
||||
}
|
||||
break;
|
||||
case EIS_EVENT_TOUCH_DOWN:
|
||||
case EIS_EVENT_TOUCH_MOTION:
|
||||
{
|
||||
colorprint("touch %s %u %.2f/%.2f\n",
|
||||
eis_event_get_type(e) == EIS_EVENT_TOUCH_DOWN ? "down" : "motion",
|
||||
eis_event_touch_get_id(e),
|
||||
eis_event_touch_get_x(e),
|
||||
eis_event_touch_get_y(e));
|
||||
}
|
||||
break;
|
||||
case EIS_EVENT_TOUCH_UP:
|
||||
{
|
||||
colorprint("touch up %u\n", eis_event_touch_get_id(e));
|
||||
}
|
||||
break;
|
||||
case EIS_EVENT_FRAME:
|
||||
/* nothing to do, we're not fancy enough to accumulate events properly */
|
||||
break;
|
||||
|
|
@ -629,6 +669,7 @@ int main(int argc, char **argv)
|
|||
struct eis_device *ptr = democlient->ptr;
|
||||
struct eis_device *kbd = democlient->kbd;
|
||||
struct eis_device *abs = democlient->abs;
|
||||
struct eis_device *touchscreen = democlient->touchscreen;
|
||||
if (ptr) {
|
||||
colorprint("sending motion event\n");
|
||||
eis_device_pointer_motion(ptr, -1, 1);
|
||||
|
|
@ -668,6 +709,33 @@ int main(int argc, char **argv)
|
|||
eis_device_frame(abs, now);
|
||||
now += interval;
|
||||
}
|
||||
|
||||
if (touchscreen) {
|
||||
static int x, y;
|
||||
static int counter = 0;
|
||||
struct eis_touch *touch = democlient->touch;
|
||||
|
||||
switch (counter++ % 5) {
|
||||
case 0:
|
||||
colorprint("sending touch down event\n");
|
||||
touch = eis_device_touch_new(touchscreen);
|
||||
eis_touch_down(touch, 100 + ++x, 200 - ++y);
|
||||
eis_device_frame(touchscreen, now);
|
||||
democlient->touch = touch;
|
||||
break;
|
||||
case 4:
|
||||
colorprint("sending touch down event\n");
|
||||
eis_touch_up(touch);
|
||||
eis_device_frame(touchscreen, now);
|
||||
democlient->touch = eis_touch_unref(touch);
|
||||
break;
|
||||
default:
|
||||
eis_touch_motion(touch, 100 + ++x, 200 - ++y);
|
||||
eis_device_frame(touchscreen, now);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ struct eis_demo_client {
|
|||
struct eis_device *ptr;
|
||||
struct eis_device *kbd;
|
||||
struct eis_device *abs;
|
||||
struct eis_device *touchscreen;
|
||||
struct eis_touch *touch;
|
||||
};
|
||||
|
||||
struct eis_demo_server {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue