mmi-manager: added focus management logic/apis 39/264039/1
authorSung-Jin Park <sj76.park@samsung.com>
Sat, 24 Jul 2021 19:00:01 +0000 (04:00 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:24:34 +0000 (20:24 +0900)
Change-Id: I054ddadb143152683af8204eb4affd3a9136d342
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/mmi-manager.c
src/mmi-manager.h

index c2f2bbe..81c8976 100644 (file)
 #include <Eina.h>
 
 static Eina_Bool _init_done = false;
+static Eina_List *_focus_candidates = NULL;
+static int _focus_candidates_cnt = 0;
+static mmi_client* _cur_focus_client = NULL;
 
 int MMI_MANAGER_EVENT_FOCUS_CHANGE = -1;
 int MMI_MANAGER_EVENT_STATE_CHANGE = -1;
 
 int
+mmi_manager_remove_client_from_focus_candidates(mmi_client *client)
+{
+       if (!client)
+               return -1;
+
+       if (client != eina_list_data_find(_focus_candidates, client))
+       {
+               return -1;
+       }
+
+       _focus_candidates = eina_list_remove(_focus_candidates, client);
+       LOGI("Client(=%s) has been removed from focus_candidates !\n",
+               client_manager_get_client_sender(client));
+       _focus_candidates_cnt--;
+       return 0;
+}
+
+int
+_add_focus_change_event(mmi_client *cur_focus, mmi_client *new_focus)
+{
+       mmi_manager_event_focus_change *ev = NULL;
+       ev = calloc(1, sizeof(mmi_manager_event_focus_change));
+
+       if (!ev)
+       {
+               LOGE("Failed to allocate memory for focus change !\n");
+               return -1;
+       }
+
+       ev->timestamp = ecore_time_get();
+       ev->cur_focus = cur_focus;
+       ev->new_focus = new_focus;
+
+       ecore_event_add(MMI_MANAGER_EVENT_FOCUS_CHANGE, ev, NULL, NULL);
+       return 0;
+}
+
+int
+mmi_manager_remove_focus_client(mmi_client *client)
+{
+       mmi_client *new_focus = NULL;
+
+       if (!client || (client != _cur_focus_client) || !client_manager_get_client_has_focus(client))
+       {
+               LOGE("Invalid client was given !\n");
+               return -1;
+       }
+
+       new_focus = eina_list_nth(_focus_candidates, 0);
+       return _add_focus_change_event(client, new_focus);
+}
+
+int
 mmi_manager_get_focus(mmi_client *client)
 {
-       (void) client;
+       if (!client)
+               return -1;
 
        LOGI("...");
-       return 0;
+
+       return _add_focus_change_event(_cur_focus_client, client);
 }
 
 int
 mmi_manager_set_state(mmi_client *client, mmi_state state)
 {
-       (void) client;
-       (void) state;
+       if (!client)
+               return -1;
+
+       if (client_manager_get_client_state(client) == state)
+       {
+               LOGI("Given state equals to the current state(=%d) of client !\n", state);
+               return 0;
+       }
 
        LOGI("...");
+
+       mmi_manager_event_state_change *ev = NULL;
+       ev = calloc(1, sizeof(mmi_manager_event_state_change));
+
+       if (!ev)
+       {
+               LOGE("Failed to allocate memory for state change !\n");
+               goto err;
+       }
+
+       ev->timestamp = ecore_time_get();
+       ev->from_state = client_manager_get_client_state(client);
+       ev->to_state = state;
+
+       ecore_event_add(MMI_MANAGER_EVENT_STATE_CHANGE, ev, NULL, NULL);
        return 0;
+err:
+       return -1;
 }
 
 static void
index 0344a84..0fb5e88 100644 (file)
@@ -46,6 +46,9 @@ typedef struct
 
 int mmi_manager_get_focus(mmi_client *client);
 int mmi_manager_set_state(mmi_client *client, mmi_state state);
+int mmi_manager_remove_client_from_focus_candidates(mmi_client *client);
+int mmi_manager_remove_focus_client(mmi_client *client);
+
 
 void mmi_manager_init(void);
 void mmi_manager_loop_begin(void);