From 010a4f48b670606dda5db2eec57cded0dcfa3f43 Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Fri, 25 Mar 2022 09:03:40 +0900 Subject: [PATCH] e_input: add func to set a input device to a new seat Change-Id: I9afef8bbb1a9b1c7791a07a1806e49c30e015ab5 --- src/bin/e_input.h | 1 + src/bin/e_input_device.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/bin/e_input_evdev.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/bin/e_input_private.h | 3 +++ 4 files changed, 89 insertions(+) diff --git a/src/bin/e_input.h b/src/bin/e_input.h index 917f604..1552cbb 100644 --- a/src/bin/e_input.h +++ b/src/bin/e_input.h @@ -118,5 +118,6 @@ EINTERN Eina_Bool e_input_device_block(E_Input_Device *dev, unsigned int type, v EINTERN Eina_Bool e_input_device_unblock(E_Input_Device *dev, void *client); EINTERN Eina_Bool e_input_device_output_name_set(E_Input_Device *dev, const char *input, const char *output); +EINTERN Eina_Bool e_input_device_seat_name_set(E_Input_Device *dev, const char *input, const char *seat_name); #endif #endif diff --git a/src/bin/e_input_device.c b/src/bin/e_input_device.c index 62273ce..049f7a3 100644 --- a/src/bin/e_input_device.c +++ b/src/bin/e_input_device.c @@ -1395,3 +1395,48 @@ e_input_device_output_name_set(E_Input_Device *dev, const char *input, const cha return EINA_FALSE; } + +EINTERN Eina_Bool +e_input_device_seat_name_set(E_Input_Device *dev, const char *input, const char *seat_name) +{ + E_Input_Seat *seat; + E_Input_Evdev *edev = NULL; + Eina_List *l, *ll; + Eina_Bool found = EINA_FALSE; + + if (!dev) + dev = _e_input_device_default_get(); + + EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE); + EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE); + EINA_SAFETY_ON_TRUE_RETURN_VAL(!seat_name, EINA_FALSE); + EINA_LIST_FOREACH(dev->seats, l, seat) + { + EINA_LIST_FOREACH(seat->devices, ll, edev) + { + if (!e_util_strcmp(edev->path, input)) + { + found = EINA_TRUE; + break; + } + } + if (found) break; + } + + if (!found || !edev) + { + ERR("Failed to find input device: %s", input); + return EINA_FALSE; + } + + INF("Current seatname:%s", e_input_evdev_seatname_get(edev)); + if (e_input_evdev_seatname_set(edev, seat_name)) + { + INF("New seatname is now set: %s", seat_name); + return EINA_TRUE; + } + else + ERR("Failed to set new seatname: %s", seat_name); + + return EINA_FALSE; +} \ No newline at end of file diff --git a/src/bin/e_input_evdev.c b/src/bin/e_input_evdev.c index d18fca1..dcbbdef 100644 --- a/src/bin/e_input_evdev.c +++ b/src/bin/e_input_evdev.c @@ -2052,3 +2052,43 @@ e_input_evdev_touch_pressed_get(E_Input_Evdev *edev) return edev->touch.pressed; } + +const char * +e_input_evdev_seatname_get(E_Input_Evdev *evdev) +{ + struct libinput_seat *libinput_seat; + EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL); + + libinput_seat = libinput_device_get_seat(evdev->device); + + return libinput_seat_get_logical_name(libinput_seat); +} + +Eina_Bool +e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname) +{ + Eina_Bool res = EINA_FALSE; + E_Input_Backend *input; + + EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE); + + if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0) + { + input = evdev->seat->input; + if (!input) return EINA_FALSE; + if (libinput_dispatch(input->libinput) != 0) + { + ERR("Failed to dispatch libinput events: %m"); + return EINA_FALSE; + } + + /* process pending events */ + _input_events_process(input); + res = EINA_TRUE; + } + + return res; +} \ No newline at end of file diff --git a/src/bin/e_input_private.h b/src/bin/e_input_private.h index 1ade6cf..c0aa8dc 100644 --- a/src/bin/e_input_private.h +++ b/src/bin/e_input_private.h @@ -141,5 +141,8 @@ void _e_input_pointer_motion_post(E_Input_Evdev *edev); void _device_calibration_set(E_Input_Evdev *edev); void e_input_device_output_changed(E_Input_Device *dev); +const char *e_input_evdev_seatname_get(E_Input_Evdev *evdev); +Eina_Bool e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname); + #endif #endif -- 2.7.4