Add api to get focused pid 38/115938/1
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 22 Feb 2017 05:16:19 +0000 (14:16 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Wed, 22 Feb 2017 06:35:26 +0000 (22:35 -0800)
Change-Id: I49a818686b6011b0969726c7a5c44bc5e4d10813
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
(cherry picked from commit 3fcfd80f9447ce9fc3845d1e1f3c6515390d1fd2)

include/aul_window.h
src/aul_window.c

index dfdebb4..5286f8a 100755 (executable)
@@ -175,6 +175,19 @@ int aul_window_info_is_focused(aul_window_info_h info, bool *focused);
 */
 int aul_window_info_get_geometry(aul_window_info_h info, int *x, int *y, int *w, int *h);
 
+
+/**
+ * @par Description:
+ *     This API gets pid for the focused window.
+ *
+ * @param[out] pid     focused pid
+ *
+ * @return     0 if success, negative value(<0) if fail
+ *
+*/
+int aul_window_get_focused_pid(pid_t *pid);
+
+
 #ifdef __cplusplus
 }
 #endif
index dceeb3b..9dde03b 100644 (file)
@@ -31,7 +31,9 @@ static GDBusConnection *system_conn;
 #define WM_BUS_NAME    "org.enlightenment.wm"
 #define WM_OBJECT_PATH "/org/enlightenment/wm"
 #define WM_INTERFACE_NAME      "org.enlightenment.wm.proc"
-#define WM_METHOD_NAME "GetVisibleWinInfo"
+#define WM_METHOD_NAME_INFO    "GetVisibleWinInfo"
+#define WM_METHOD_NAME_FOCUS   "GetFocusProc"
+
 
 typedef struct _window_info {
        unsigned int gid;
@@ -72,7 +74,7 @@ API int aul_window_stack_get(aul_window_stack_h *handle)
        msg = g_dbus_message_new_method_call(WM_BUS_NAME,
                                                WM_OBJECT_PATH,
                                                WM_INTERFACE_NAME,
-                                               WM_METHOD_NAME);
+                                               WM_METHOD_NAME_INFO);
        if (msg == NULL) {
                _E("g_dbus_message_new_method_call() is failed.");
                return -1;
@@ -254,4 +256,63 @@ API int aul_window_info_get_geometry(aul_window_info_h info, int *x, int *y, int
        return 0;
 }
 
+API int aul_window_get_focused_pid(pid_t *pid)
+{
+       GError *err = NULL;
+       GDBusMessage *msg;
+       GDBusMessage *reply;
+       GDBusConnection *conn;
+       int res = 0;
+       GVariant *body;
+       gint32 focused_pid = 0;
+
+       if (system_conn == NULL) {
+               conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (conn == NULL) {
+                       _E("g_bus_get_sync() is failed. %s", err->message);
+                       g_error_free(err);
+                       return -1;
+               }
+               system_conn = conn;
+       }
+
+       msg = g_dbus_message_new_method_call(WM_BUS_NAME,
+                                               WM_OBJECT_PATH,
+                                               WM_INTERFACE_NAME,
+                                               WM_METHOD_NAME_FOCUS);
+       if (msg == NULL) {
+               _E("g_dbus_message_new_method_call() is failed.");
+               return -1;
+       }
+
+       reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg,
+                       G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+       if (!reply) {
+               if (err != NULL) {
+                       _E("Failed to get info [%s]", err->message);
+                       g_error_free(err);
+               }
+               res = -1;
+               goto out;
+       }
+
+       body = g_dbus_message_get_body(reply);
+       if (!body) {
+               res = -1;
+               goto out;
+       }
+
+       g_variant_get(body, "(i)", &focused_pid);
+       *pid = (pid_t)focused_pid;
+out:
+       if (msg)
+               g_object_unref(msg);
+       if (reply)
+               g_object_unref(reply);
+
+       return res;
+}
+
+