forked from enlightenment/efl
elput: add refcounting for seats/devices
ensure lifetimes persist through events @fix
This commit is contained in:
parent
539c2169b5
commit
4c7c613e76
|
@ -1,5 +1,11 @@
|
||||||
#include "elput_private.h"
|
#include "elput_private.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
_seat_event_free(void *d, void *ev EINA_UNUSED)
|
||||||
|
{
|
||||||
|
_udev_seat_destroy(d);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_seat_caps_update(Elput_Seat *seat)
|
_seat_caps_update(Elput_Seat *seat)
|
||||||
{
|
{
|
||||||
|
@ -12,8 +18,9 @@ _seat_caps_update(Elput_Seat *seat)
|
||||||
ev->keyboard_count = seat->count.kbd;
|
ev->keyboard_count = seat->count.kbd;
|
||||||
ev->touch_count = seat->count.touch;
|
ev->touch_count = seat->count.touch;
|
||||||
ev->seat = seat;
|
ev->seat = seat;
|
||||||
|
seat->refs++;
|
||||||
|
|
||||||
ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, NULL, NULL);
|
ecore_event_add(ELPUT_EVENT_SEAT_CAPS, ev, _seat_event_free, seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -25,7 +32,8 @@ _seat_frame_send(Elput_Seat *seat)
|
||||||
if (!ev) return;
|
if (!ev) return;
|
||||||
|
|
||||||
ev->seat = seat;
|
ev->seat = seat;
|
||||||
ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, NULL, NULL);
|
seat->refs++;
|
||||||
|
ecore_event_add(ELPUT_EVENT_SEAT_FRAME, ev, _seat_event_free, seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1558,6 +1566,7 @@ _evdev_device_create(Elput_Seat *seat, struct libinput_device *device)
|
||||||
edev = calloc(1, sizeof(Elput_Device));
|
edev = calloc(1, sizeof(Elput_Device));
|
||||||
if (!edev) return NULL;
|
if (!edev) return NULL;
|
||||||
|
|
||||||
|
edev->refs = 1;
|
||||||
edev->seat = seat;
|
edev->seat = seat;
|
||||||
edev->device = device;
|
edev->device = device;
|
||||||
edev->caps = 0;
|
edev->caps = 0;
|
||||||
|
@ -1621,6 +1630,8 @@ void
|
||||||
_evdev_device_destroy(Elput_Device *edev)
|
_evdev_device_destroy(Elput_Device *edev)
|
||||||
{
|
{
|
||||||
if (!edev) return;
|
if (!edev) return;
|
||||||
|
edev->refs--;
|
||||||
|
if (edev->refs) return;
|
||||||
|
|
||||||
if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
|
if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
|
||||||
_pointer_release(edev->seat);
|
_pointer_release(edev->seat);
|
||||||
|
|
|
@ -103,6 +103,7 @@ _udev_seat_create(Elput_Manager *em, const char *name)
|
||||||
if (!eseat) return NULL;
|
if (!eseat) return NULL;
|
||||||
|
|
||||||
eseat->manager = em;
|
eseat->manager = em;
|
||||||
|
eseat->refs = 1;
|
||||||
|
|
||||||
eseat->name = eina_stringshare_add(name);
|
eseat->name = eina_stringshare_add(name);
|
||||||
em->input.seats = eina_list_append(em->input.seats, eseat);
|
em->input.seats = eina_list_append(em->input.seats, eseat);
|
||||||
|
@ -110,11 +111,14 @@ _udev_seat_create(Elput_Manager *em, const char *name)
|
||||||
return eseat;
|
return eseat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
_udev_seat_destroy(Elput_Seat *eseat)
|
_udev_seat_destroy(Elput_Seat *eseat)
|
||||||
{
|
{
|
||||||
Elput_Device *edev;
|
Elput_Device *edev;
|
||||||
|
|
||||||
|
eseat->refs--;
|
||||||
|
if (eseat->refs) return;
|
||||||
|
|
||||||
EINA_LIST_FREE(eseat->devices, edev)
|
EINA_LIST_FREE(eseat->devices, edev)
|
||||||
_evdev_device_destroy(edev);
|
_evdev_device_destroy(edev);
|
||||||
|
|
||||||
|
@ -170,6 +174,7 @@ _device_event_cb_free(void *data EINA_UNUSED, void *event)
|
||||||
if (seat)
|
if (seat)
|
||||||
seat->devices = eina_list_remove(seat->devices, ev->device);
|
seat->devices = eina_list_remove(seat->devices, ev->device);
|
||||||
|
|
||||||
|
ev->device->refs--;
|
||||||
_evdev_device_destroy(ev->device);
|
_evdev_device_destroy(ev->device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +191,7 @@ _device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
|
||||||
|
|
||||||
ev->device = edev;
|
ev->device = edev;
|
||||||
ev->type = type;
|
ev->type = type;
|
||||||
|
edev->refs++;
|
||||||
|
|
||||||
ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
|
ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,7 @@ struct _Elput_Touch
|
||||||
|
|
||||||
struct _Elput_Seat
|
struct _Elput_Seat
|
||||||
{
|
{
|
||||||
|
int refs; //for events
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -209,6 +210,7 @@ struct _Elput_Seat
|
||||||
struct _Elput_Device
|
struct _Elput_Device
|
||||||
{
|
{
|
||||||
Elput_Seat *seat;
|
Elput_Seat *seat;
|
||||||
|
int refs; //for events
|
||||||
|
|
||||||
uint32_t ow, oh;
|
uint32_t ow, oh;
|
||||||
|
|
||||||
|
@ -289,4 +291,6 @@ extern Elput_Interface _logind_interface;
|
||||||
void _keyboard_keymap_update(Elput_Seat *seat);
|
void _keyboard_keymap_update(Elput_Seat *seat);
|
||||||
void _keyboard_group_update(Elput_Seat *seat);
|
void _keyboard_group_update(Elput_Seat *seat);
|
||||||
|
|
||||||
|
|
||||||
|
void _udev_seat_destroy(Elput_Seat *eseat);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue