edje: add flag to choose between evas or edje seat naming
authorBruno Dilly <bdilly@profusion.mobi>
Tue, 6 Dec 2016 17:06:38 +0000 (15:06 -0200)
committerBruno Dilly <bdilly@profusion.mobi>
Mon, 19 Dec 2016 16:58:35 +0000 (14:58 -0200)
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", ...)

src/bin/edje/edje_cc_handlers.c
src/lib/edje/edje_data.c
src/lib/edje/edje_edit.c
src/lib/edje/edje_load.c
src/lib/edje/edje_private.h

index 9428e45..3861cd9 100644 (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},
@@ -4517,6 +4519,43 @@ st_collections_group_inherit_only(void)
 /**
     @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
         target_group
     @parameters
         [name] [part or program] (part or program) (part or program) ...
@@ -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;
index 9141ae1..6c4ef6a 100644 (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
index 3178920..6c57a75 100644 (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)
      {
index d3b9f20..91695b2 100644 (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)
@@ -585,6 +590,71 @@ _edje_device_removed_cb(void *data, const Efl_Event *event)
 }
 
 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)
 {
    const Eina_List *devices, *l;
@@ -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);
      }
 
index d98f324..93b131c 100644 (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;
 };