edje: add flag to choose between evas or edje seat naming

collections.group.use_custom_seat_names should be set to '1'
to use seat names on signals as provided by Evas.

By default just follow Edje naming approach
("seat1", "seat2", ...)
This commit is contained in:
Bruno Dilly 2016-12-06 15:06:38 -02:00
parent f34220f089
commit 287486e920
5 changed files with 125 additions and 2 deletions

View File

@ -262,6 +262,7 @@ static void st_collections_group_broadcast_signal(void);
static void st_collections_group_data_item(void);
static void st_collections_group_orientation(void);
static void st_collections_group_mouse_events(void);
static void st_collections_group_use_custom_seat_names(void);
static void st_collections_group_limits_vertical(void);
static void st_collections_group_limits_horizontal(void);
@ -716,6 +717,7 @@ New_Statement_Handler statement_handlers[] =
{"collections.group.program_source", st_collections_group_program_source},
{"collections.group.inherit", st_collections_group_inherit},
{"collections.group.inherit_only", st_collections_group_inherit_only},
{"collections.group.use_custom_seat_names", st_collections_group_use_custom_seat_names},
{"collections.group.target_group", st_collections_group_target_group}, /* dup */
{"collections.group.part_remove", st_collections_group_part_remove},
{"collections.group.program_remove", st_collections_group_program_remove},
@ -4514,6 +4516,43 @@ st_collections_group_inherit_only(void)
pcp->inherit_only = parse_bool(0);
}
/**
@page edcref
@property
use_custom_seat_names
@parameters
[1 or 0]
@effect
This flags a group as designed to listen for multiseat signals
following a custom naming instead of default Edje naming.
Seats are named on Edje as "seat1", "seat2", etc, in an incremental
way and never are changed.
But on Evas, names may be set on different places
(Evas, Ecore Evas backends, the application itself)
and name changes are allowed.
So custom names come from system at first, but can be overriden with
evas_device_name_set().
Also Evas seat names don't need to follow any pattern.
It's useful for cases where there is control of the
system, as seat names, or when the application
sets the devices names to guarantee they'll match
seat names on EDC.
@since 1.19
@endproperty
*/
static void
st_collections_group_use_custom_seat_names(void)
{
Edje_Part_Collection *pc;
check_arg_count(1);
pc = eina_list_data_get(eina_list_last(edje_collections));
pc->use_custom_seat_names = parse_bool(0);
}
/**
@page edcref
@property
@ -4692,6 +4731,7 @@ st_collections_group_inherit(void)
pc->prop.orientation = pc2->prop.orientation;
pc->lua_script_only = pc2->lua_script_only;
pc->use_custom_seat_names = pc2->use_custom_seat_names;
pcp = (Edje_Part_Collection_Parser *)pc;
pcp2 = (Edje_Part_Collection_Parser *)pc2;

View File

@ -1814,6 +1814,7 @@ _edje_edd_init(void)
#endif
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "physics_enabled", physics_enabled, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "script_recursion", script_recursion, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection, Edje_Part_Collection, "use_custom_seat_names", use_custom_seat_names, EET_T_UCHAR);
}
EAPI void

View File

@ -15616,6 +15616,9 @@ _edje_generate_source_of_group(Edje *ed, Edje_Part_Collection_Directory_Entry *p
/* Limits */
_edje_limits_source_generate(ed, buf, &ret);
if (pc->use_custom_seat_names)
BUF_APPENDF(I2 "use_custom_seat_names: 1;\n");
/* Data */
if (pc->data)
{

View File

@ -515,8 +515,13 @@ _edje_device_add(Edje *ed, Efl_Input_Device *dev)
char sig[256];
Eina_List *l;
ed->seats_count++;
name = eina_stringshare_printf("seat%i", ed->seats_count);
if (ed->collection && ed->collection->use_custom_seat_names)
name = eina_stringshare_add(efl_input_device_name_get(dev));
else
{
ed->seats_count++;
name = eina_stringshare_printf("seat%i", ed->seats_count);
}
EINA_SAFETY_ON_NULL_RETURN(name);
EINA_LIST_FOREACH(ed->seats, l, s)
@ -584,6 +589,71 @@ _edje_device_removed_cb(void *data, const Efl_Event *event)
_edje_emit(ed, sig, "");
}
static void
_edje_device_changed_cb(void *data, const Efl_Event *event)
{
Efl_Input_Device *dev = event->info;
Edje_Seat *s, *seat = NULL;
Eina_Stringshare *name;
Edje *ed = data;
char sig[256];
Eina_List *l;
if (efl_input_device_type_get(dev) != EFL_INPUT_DEVICE_CLASS_SEAT)
return;
EINA_LIST_FOREACH(ed->seats, l, s)
{
if (s->device != dev)
continue;
seat = s;
break;
}
/* not registered seat */
if (!seat)
return;
name = efl_input_device_name_get(dev);
if (!name)
return;
/* no name changes */
if (eina_streq(seat->name, name))
return;
/* check if device name was changed to match name used on EDC */
EINA_LIST_FOREACH(ed->seats, l, s)
{
if (eina_streq(s->name, name))
{
if (s->device == dev)
continue;
if (s->device)
{
WRN("Two seats were detected with the same name: %s.\n"
"Fix it or focus will misbehave", name);
break;
}
/* merge seats */
s->device = dev;
if (seat->focused_part)
s->focused_part = seat->focused_part;
ed->seats = eina_list_remove(ed->seats, seat);
eina_stringshare_del(seat->name);
free(seat);
return;
}
}
snprintf(sig, sizeof(sig), "seat,renamed,%s,%s", seat->name, name);
eina_stringshare_replace(&seat->name, name);
_edje_emit(ed, sig, "");
}
static void
_edje_devices_add(Edje *ed, Evas *tev)
{
@ -601,6 +671,10 @@ _edje_devices_add(Edje *ed, Evas *tev)
_edje_device_added_cb, ed);
efl_event_callback_add(tev, EFL_CANVAS_EVENT_DEVICE_REMOVED,
_edje_device_removed_cb, ed);
if (ed->collection && ed->collection->use_custom_seat_names)
efl_event_callback_add(tev, EFL_CANVAS_EVENT_DEVICE_CHANGED,
_edje_device_changed_cb, ed);
}
int
@ -1704,6 +1778,10 @@ _edje_file_del(Edje *ed)
_edje_device_added_cb, ed);
efl_event_callback_del(tev, EFL_CANVAS_EVENT_DEVICE_REMOVED,
_edje_device_removed_cb, ed);
if (ed->collection && ed->collection->use_custom_seat_names)
efl_event_callback_del(tev, EFL_CANVAS_EVENT_DEVICE_CHANGED,
_edje_device_changed_cb, ed);
evas_event_freeze(tev);
}

View File

@ -1137,6 +1137,7 @@ struct _Edje_Part_Collection
unsigned char broadcast_signal;
unsigned char physics_enabled; /* will be 1 if a body is declared */
unsigned char script_recursion; /* permits unsafe Embryo->EDC->Embryo scripting */
unsigned char use_custom_seat_names;
unsigned char checked : 1;
};