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"
|
||||
|
||||
static void
|
||||
_seat_event_free(void *d, void *ev EINA_UNUSED)
|
||||
{
|
||||
_udev_seat_destroy(d);
|
||||
}
|
||||
|
||||
static void
|
||||
_seat_caps_update(Elput_Seat *seat)
|
||||
{
|
||||
|
@ -12,8 +18,9 @@ _seat_caps_update(Elput_Seat *seat)
|
|||
ev->keyboard_count = seat->count.kbd;
|
||||
ev->touch_count = seat->count.touch;
|
||||
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
|
||||
|
@ -25,7 +32,8 @@ _seat_frame_send(Elput_Seat *seat)
|
|||
if (!ev) return;
|
||||
|
||||
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
|
||||
|
@ -1558,6 +1566,7 @@ _evdev_device_create(Elput_Seat *seat, struct libinput_device *device)
|
|||
edev = calloc(1, sizeof(Elput_Device));
|
||||
if (!edev) return NULL;
|
||||
|
||||
edev->refs = 1;
|
||||
edev->seat = seat;
|
||||
edev->device = device;
|
||||
edev->caps = 0;
|
||||
|
@ -1621,6 +1630,8 @@ void
|
|||
_evdev_device_destroy(Elput_Device *edev)
|
||||
{
|
||||
if (!edev) return;
|
||||
edev->refs--;
|
||||
if (edev->refs) return;
|
||||
|
||||
if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
|
||||
_pointer_release(edev->seat);
|
||||
|
|
|
@ -103,6 +103,7 @@ _udev_seat_create(Elput_Manager *em, const char *name)
|
|||
if (!eseat) return NULL;
|
||||
|
||||
eseat->manager = em;
|
||||
eseat->refs = 1;
|
||||
|
||||
eseat->name = eina_stringshare_add(name);
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
_udev_seat_destroy(Elput_Seat *eseat)
|
||||
{
|
||||
Elput_Device *edev;
|
||||
|
||||
eseat->refs--;
|
||||
if (eseat->refs) return;
|
||||
|
||||
EINA_LIST_FREE(eseat->devices, edev)
|
||||
_evdev_device_destroy(edev);
|
||||
|
||||
|
@ -170,6 +174,7 @@ _device_event_cb_free(void *data EINA_UNUSED, void *event)
|
|||
if (seat)
|
||||
seat->devices = eina_list_remove(seat->devices, ev->device);
|
||||
|
||||
ev->device->refs--;
|
||||
_evdev_device_destroy(ev->device);
|
||||
}
|
||||
|
||||
|
@ -186,6 +191,7 @@ _device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
|
|||
|
||||
ev->device = edev;
|
||||
ev->type = type;
|
||||
edev->refs++;
|
||||
|
||||
ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@ struct _Elput_Touch
|
|||
|
||||
struct _Elput_Seat
|
||||
{
|
||||
int refs; //for events
|
||||
const char *name;
|
||||
|
||||
struct
|
||||
|
@ -209,6 +210,7 @@ struct _Elput_Seat
|
|||
struct _Elput_Device
|
||||
{
|
||||
Elput_Seat *seat;
|
||||
int refs; //for events
|
||||
|
||||
uint32_t ow, oh;
|
||||
|
||||
|
@ -289,4 +291,6 @@ extern Elput_Interface _logind_interface;
|
|||
void _keyboard_keymap_update(Elput_Seat *seat);
|
||||
void _keyboard_group_update(Elput_Seat *seat);
|
||||
|
||||
|
||||
void _udev_seat_destroy(Elput_Seat *eseat);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue