add a feature for getting visible window information 89/114189/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Fri, 10 Feb 2017 08:44:20 +0000 (17:44 +0900)
committerDoyoun Kang <doyoun.kang@samsung.com>
Fri, 10 Feb 2017 08:44:20 +0000 (17:44 +0900)
Change-Id: I350c22f44f43e9037eb10cc53c43f0d6fa92c536

src/e_mod_processmgr.c

index 4c02421..952ae23 100644 (file)
@@ -9,14 +9,20 @@ static Eina_List *_e_processmgr_ec_handlers = NULL;
 Eldbus_Connection *_e_processmgr_conn;
 Eldbus_Service_Interface *_e_processmgr_iface;
 
+// global res_id, geo(x,y,w,h), alpha, visibility, focused, pid, parent pid, acestor pid
+#define VALUE_TYPE_FOR_VISIBLE_WINS "uiiiibibiii"
+
 static void _e_processmgr_process_action_send(int pid, E_Process_Action act);
 static void _e_processmgr_cb_hook_action_change(void *d EINA_UNUSED, E_Process *epro, void *user);
 static Eldbus_Message* _e_processmgr_process_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg);
+static Eldbus_Message *_e_processmgr_visible_window_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg);
+
 static Eina_Bool _e_processmgr_cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
 static Eina_Bool _e_processmgr_cb_client_remove(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
 
 static const Eldbus_Method _e_processmgr_methods[] = {
    { "GetProcStatus", ELDBUS_ARGS({"i", "pid"}), ELDBUS_ARGS({"i","process status"}, {"i", "focused"}), _e_processmgr_process_info_get, 0 },
+   { "GetVisibleWinInfo", NULL, ELDBUS_ARGS({"a("VALUE_TYPE_FOR_VISIBLE_WINS")", "array of window"}), _e_processmgr_visible_window_info_get, 0 },
    { NULL, NULL, NULL, NULL, 0 }
 };
 
@@ -107,6 +113,116 @@ _e_processmgr_process_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED
    return reply;
 }
 
+static pid_t
+_process_id_get(E_Client *ec)
+{
+   pid_t pid = -1;
+
+   if (!ec) return pid;
+
+   pid = ec->netwm.pid;
+   if (pid <= 0)
+     {
+        if (ec->comp_data)
+          {
+             E_Comp_Wl_Client_Data *cdata = (E_Comp_Wl_Client_Data*)ec->comp_data;
+             if (cdata->surface)
+               wl_client_get_credentials(wl_resource_get_client(cdata->surface), &pid, NULL, NULL);
+          }
+     }
+   return pid;
+}
+
+static void
+_msg_window_info_append(Eldbus_Message_Iter *iter)
+{
+   Eldbus_Message_Iter *array_of_win;
+   E_Client *ec;
+   E_Client *p_ec;
+   E_Client *a_ec;
+   Evas_Object *o;
+
+   eldbus_message_iter_arguments_append(iter, "a("VALUE_TYPE_FOR_VISIBLE_WINS")", &array_of_win);
+
+   // append info.
+   for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
+     {
+        Eldbus_Message_Iter* struct_of_win;
+        uint32_t res_id = 0;
+        int x, y, w, h;
+        Eina_Bool is_alpha;
+        int visibility;
+        Eina_Bool focused;
+        pid_t pid = -1;
+        pid_t p_pid = -1;
+        pid_t a_pid = -1;
+
+        ec = evas_object_data_get(o, "E_Client");
+        if (!ec) continue;
+        if (e_client_util_ignored_get(ec)) continue;
+
+        // get resource id
+        if (ec->pixmap)
+          res_id = e_pixmap_res_id_get(ec->pixmap);
+
+        // get geometry
+        x = ec->x;
+        y = ec->y;
+        w = ec->w;
+        h = ec->h;
+
+        // color depth
+        is_alpha = ec->argb;
+
+        // visibility
+        visibility = ec->visibility.obscured;
+
+        // focused
+        focused = ec->focused;
+
+        // get pid
+        pid = _process_id_get(ec);
+
+        p_ec = ec->parent;
+        if (p_ec)
+          {
+             // get parent pid
+             p_pid = _process_id_get(p_ec);
+             a_ec = p_ec;
+
+             p_ec = p_ec->parent;
+             while (p_ec)
+               {
+                  a_ec = p_ec;
+                  p_ec = p_ec->parent;
+               }
+
+             // get ancestor pid
+             a_pid = _process_id_get(a_ec);
+          }
+
+        eldbus_message_iter_arguments_append(array_of_win, "("VALUE_TYPE_FOR_VISIBLE_WINS")", &struct_of_win);
+
+        eldbus_message_iter_arguments_append
+           (struct_of_win, VALUE_TYPE_FOR_VISIBLE_WINS,
+            res_id, x, y, w, h, is_alpha, visibility, focused, pid, p_pid, a_pid);
+
+        eldbus_message_iter_container_close(array_of_win, struct_of_win);
+     }
+
+   eldbus_message_iter_container_close(iter, array_of_win);
+}
+
+static Eldbus_Message *
+_e_processmgr_visible_window_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply = eldbus_message_method_return_new(msg);
+
+   _msg_window_info_append(eldbus_message_iter_get(reply));
+
+   return reply;
+}
+
 static Eina_Bool
 _e_processmgr_dbus_init(void *data EINA_UNUSED)
 {