e_actions: restore action codes for window_move and window_resize accepted/tizen/unified/20230629.132052
authorJunseok Kim <juns.kim@samsung.com>
Wed, 28 Jun 2023 07:15:21 +0000 (16:15 +0900)
committerJunseok Kim <juns.kim@samsung.com>
Thu, 29 Jun 2023 02:29:04 +0000 (11:29 +0900)
Change-Id: Ie1011d189f6e5217936f7b0097d2218ab8b64aab

src/bin/e_actions.c
src/bin/e_actions.h

index 58e5915..7f34838 100644 (file)
 #include "e.h"
 
+#define INITS
+
+/* local subsystem functions */
+static void       _e_action_free(E_Action *act);
+static int        _action_groups_sort_cb(const void *d1, const void *d2);
+
+static E_Action * _e_action_add(const char *name);
+static void       _e_action_predef_name_set(const char *act_grp, const char *act_name, const char *act_cmd, const char *act_params, const char *param_example, int editable);
+static void       _e_action_predef_name_all_del(void);
+
+#define ACT_GO(name)                                      \
+  {                                                       \
+     act = _e_action_add(#name);                           \
+     if (act) act->func.go = _e_actions_act_##name##_go;  \
+  }
+#define ACT_FN_GO(act, use) \
+  static void _e_actions_act_##act##_go(E_Object * obj EINA_UNUSED, const char *params use)
+
+#define ACT_GO_MOUSE(name)                                            \
+  {                                                                   \
+     act = _e_action_add(#name);                                       \
+     if (act) act->func.go_mouse = _e_actions_act_##name##_go_mouse;  \
+  }
+#define ACT_FN_GO_MOUSE(act, use) \
+  static void _e_actions_act_##act##_go_mouse(E_Object * obj EINA_UNUSED, const char *params use, E_Binding_Event_Mouse_Button * ev EINA_UNUSED)
+
+#define ACT_GO_SIGNAL(name)                                             \
+  {                                                                     \
+     act = _e_action_add(#name);                                         \
+     if (act) act->func.go_signal = _e_actions_act_##name##_go_signal;  \
+  }
+#define ACT_FN_GO_SIGNAL(act, use) \
+  static void _e_actions_act_##act##_go_signal(E_Object * obj EINA_UNUSED, const char *params use, const char *sig, const char *src)
+
+#define ACT_GO_KEY(name)                                          \
+  {                                                               \
+     act = _e_action_add(#name);                                   \
+     if (act) act->func.go_key = _e_actions_act_##name##_go_key;  \
+  }
+#define ACT_FN_GO_KEY(act, use1, use2) \
+  static void _e_actions_act_##act##_go_key(E_Object * obj EINA_UNUSED, const char *params use1, Ecore_Event_Key * ev use2)
+
+#define ACT_END(name)                                       \
+  {                                                         \
+     act = _e_action_add(#name);                             \
+     if (act) act->func.end = _e_actions_act_##name##_end;  \
+  }
+#define ACT_FN_END(act, use) \
+  static void _e_actions_act_##act##_end(E_Object * obj EINA_UNUSED, const char *params use)
+
+#define ACT_END_MOUSE(name)                                             \
+  {                                                                     \
+     act = _e_action_add(#name);                                         \
+     if (act) act->func.end_mouse = _e_actions_act_##name##_end_mouse;  \
+  }
+#define ACT_FN_END_MOUSE(act, use) \
+  static void _e_actions_act_##act##_end_mouse(E_Object * obj EINA_UNUSED, const char *params use, E_Binding_Event_Mouse_Button * ev EINA_UNUSED)
+
+/* to save writing this in N places - the sections are defined here */
+/***************************************************************************/
+ACT_FN_GO(window_move, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   if (!((E_Client *)obj)->lock_user_location)
+     e_client_act_move_begin((E_Client *)obj, NULL);
+}
+
+ACT_FN_GO_MOUSE(window_move, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   e_client_act_move_begin((E_Client *)obj, ev);
+}
+
+ACT_FN_GO_SIGNAL(window_move, )
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   if (!((E_Client *)obj)->lock_user_location)
+     {
+        if ((params) && (!strcmp(params, "end")))
+          e_client_signal_move_end((E_Client *)obj, sig, src);
+        else
+          {
+             if (!((E_Client *)obj)->moving)
+               e_client_signal_move_begin((E_Client *)obj, sig, src);
+          }
+     }
+}
+
+ACT_FN_END(window_move, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   e_client_act_move_end((E_Client *)obj, NULL);
+}
+
+ACT_FN_END_MOUSE(window_move, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   e_client_act_move_end((E_Client *)obj, ev);
+}
+
+ACT_FN_GO_KEY(window_move, EINA_UNUSED, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE)
+     {
+        obj = E_OBJECT(e_client_focused_get());
+        if (!obj) return;
+     }
+   if (!((E_Client *)obj)->lock_user_location)
+     e_client_act_move_keyboard((E_Client *)obj);
+}
+
+/***************************************************************************/
+ACT_FN_GO(window_resize, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   if (!((E_Client *)obj)->lock_user_size)
+     e_client_act_resize_begin((E_Client *)obj, NULL, E_POINTER_RESIZE_NONE);
+}
+
+ACT_FN_GO_MOUSE(window_resize, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   if (!((E_Client *)obj)->lock_user_size)
+     e_client_act_resize_begin((E_Client *)obj, ev, E_POINTER_RESIZE_NONE);
+}
+
+ACT_FN_GO_SIGNAL(window_resize, )
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   if (!((E_Client *)obj)->lock_user_size)
+     {
+        if ((params) && (!strcmp(params, "end")))
+          e_client_signal_resize_end((E_Client *)obj, params, sig, src);
+        else
+          {
+             if (!params) params = "";
+             if (e_client_util_resizing_get((E_Client *)obj))
+               e_client_signal_resize_end((E_Client *)obj, params, sig, src);
+             else
+               e_client_signal_resize_begin((E_Client *)obj, params, sig, src);
+          }
+     }
+}
+
+ACT_FN_END(window_resize, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   e_client_act_resize_end((E_Client *)obj, NULL);
+}
+
+ACT_FN_END_MOUSE(window_resize, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE) return;
+   e_client_act_resize_end((E_Client *)obj, ev);
+}
+
+ACT_FN_GO_KEY(window_resize, EINA_UNUSED, EINA_UNUSED)
+{
+   if (!obj) obj = E_OBJECT(e_client_focused_get());
+   if (!obj) return;
+   if (obj->type != E_CLIENT_TYPE)
+     {
+        obj = E_OBJECT(e_client_focused_get());
+        if (!obj) return;
+     }
+   if (!((E_Client *)obj)->lock_user_size)
+     e_client_act_resize_keyboard((E_Client *)obj);
+}
+
+/* local subsystem globals */
+static Eina_Hash *actions = NULL;
+static Eina_List *action_list = NULL;
+static Eina_List *action_names = NULL;
+static Eina_List *action_groups = NULL;
+
+/* externally accessible functions */
+
 EINTERN int
 e_actions_init(void)
 {
+   E_Action *act;
+
+   actions = eina_hash_string_superfast_new(NULL);
+   ACT_GO(window_move);
+   _e_action_predef_name_set(N_("Window : Actions"), N_("Move"),
+                            "window_move", NULL, NULL, 0);
+
+   ACT_GO_MOUSE(window_move);
+   ACT_GO_SIGNAL(window_move);
+   ACT_END(window_move);
+   ACT_END_MOUSE(window_move);
+   ACT_GO_KEY(window_move);
+
+   /* window_resize */
+   ACT_GO(window_resize);
+   _e_action_predef_name_set(N_("Window : Actions"), N_("Resize"),
+                            "window_resize", NULL, NULL, 0);
+
+   ACT_GO_MOUSE(window_resize);
+   ACT_GO_SIGNAL(window_resize);
+   ACT_END(window_resize);
+   ACT_END_MOUSE(window_resize);
+   ACT_GO_KEY(window_resize);
+
    return 1;
 }
 
 EINTERN int
 e_actions_shutdown(void)
 {
+   Eina_List *tlist = NULL, *l;
+   E_Action *act;
+
+   _e_action_predef_name_all_del();
+
+   EINA_LIST_FOREACH(action_list, l, act)
+     tlist = eina_list_append(tlist, act);
+   EINA_LIST_FREE(tlist, act)
+     e_object_del(E_OBJECT(act));
+
+   action_names = eina_list_free(action_names);
+   eina_hash_free(actions);
+   actions = NULL;
+
    return 1;
 }
 
 EINTERN E_Action *
 e_action_find(const char *name)
 {
+   E_Action *act;
+
+   act = eina_hash_find(actions, name);
+   return act;
+}
+
+/* local subsystem functions */
+
+static E_Action *
+_e_action_add(const char *name)
+{
+   E_Action *act;
+
+   act = e_action_find(name);
+   if (!act)
+     {
+        act = E_OBJECT_ALLOC(E_Action, E_ACTION_TYPE, _e_action_free);
+        if (!act) return NULL;
+        act->name = name;
+        eina_hash_direct_add(actions, act->name, act);
+        action_names = eina_list_append(action_names, name);
+        action_list = eina_list_append(action_list, act);
+     }
+   return act;
+}
+
+static void
+_e_action_predef_name_set(const char *act_grp, const char *act_name, const char *act_cmd, const char *act_params, const char *param_example, int editable)
+{
+   E_Action_Group *actg = NULL;
+   E_Action_Description *actd = NULL;
+   Eina_List *l;
+
+   if ((!act_grp) || (!act_name)) return;
+
+   EINA_LIST_FOREACH(action_groups, l, actg)
+     {
+        if (!strcmp(actg->act_grp, act_grp)) break;
+        actg = NULL;
+     }
+
+   if (!actg)
+     {
+        actg = E_NEW(E_Action_Group, 1);
+        if (!actg) return;
+
+        actg->act_grp = eina_stringshare_add(act_grp);
+        action_groups = eina_list_append(action_groups, actg);
+        action_groups =
+          eina_list_sort(action_groups, -1, _action_groups_sort_cb);
+     }
 
-   return NULL;
+   EINA_LIST_FOREACH(actg->acts, l, actd)
+     {
+        if (!strcmp(actd->act_name, act_name)) break;
+        actd = NULL;
+     }
+
+   if (actd) return;
+
+   actd = E_NEW(E_Action_Description, 1);
+   if (!actd) return;
+
+   actd->act_name = eina_stringshare_add(act_name);
+   actd->act_cmd = !act_cmd ? NULL : eina_stringshare_add(act_cmd);
+   actd->act_params = !act_params ? NULL : eina_stringshare_add(act_params);
+   actd->param_example = !param_example ? NULL : eina_stringshare_add(param_example);
+   actd->editable = editable;
+
+   actg->acts = eina_list_append(actg->acts, actd);
 }
 
+static void
+_e_action_predef_name_all_del(void)
+{
+   E_Action_Group *actg = NULL;
+   E_Action_Description *actd = NULL;
+
+   EINA_LIST_FREE(action_groups, actg)
+     {
+        EINA_LIST_FREE(actg->acts, actd)
+          {
+             if (actd->act_name) eina_stringshare_del(actd->act_name);
+             if (actd->act_cmd) eina_stringshare_del(actd->act_cmd);
+             if (actd->act_params) eina_stringshare_del(actd->act_params);
+             if (actd->param_example) eina_stringshare_del(actd->param_example);
+
+             E_FREE(actd);
+          }
+        if (actg->act_grp) eina_stringshare_del(actg->act_grp);
+        E_FREE(actg);
+     }
+   action_groups = NULL;
+}
+
+static void
+_e_action_free(E_Action *act)
+{
+   eina_hash_del(actions, act->name, act);
+   action_names = eina_list_remove(action_names, act->name);
+   action_list = eina_list_remove(action_list, act);
+   free(act);
+}
+
+static int
+_action_groups_sort_cb(const void *d1, const void *d2)
+{
+   const E_Action_Group *g1, *g2;
+
+   if (!(g1 = d1)) return 1;
+   if (!(g2 = d2)) return -1;
+   return strcmp(g1->act_grp, g2->act_grp);
+}
index 76df7be..102fc8a 100644 (file)
@@ -1,6 +1,7 @@
 #ifdef E_TYPEDEFS
 
 typedef struct _E_Action             E_Action;
+typedef struct _E_Action_Description E_Action_Description;
 typedef struct _E_Action_Group       E_Action_Group;
 
 #else
@@ -28,10 +29,24 @@ struct _E_Action
    } func;
 };
 
+struct _E_Action_Description
+{
+   const char *act_name;
+   const char *act_cmd;
+   const char *act_params;
+   const char *param_example;
+   int         editable;
+};
+
+struct _E_Action_Group
+{
+   const char *act_grp;
+   Eina_List  *acts;
+};
+
 EINTERN int      e_actions_init(void);
 EINTERN int      e_actions_shutdown(void);
 
-/* e_action_del allows, for example, modules to define their own actions dynamically. */
 EINTERN E_Action   *e_action_find(const char *name);
 
 #endif