Handle H/W key input 60/115260/5
authorYunjin Lee <yunjin-.lee@samsung.com>
Fri, 17 Feb 2017 05:54:14 +0000 (14:54 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Thu, 2 Mar 2017 11:17:50 +0000 (20:17 +0900)
- Respond as if user select "Deny once" when H/W Home key or Back key pressed.

Change-Id: I9719981e962d54394060c5cce72b6cc50809627c
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
src/agent/notification-daemon/GuiRunner.cpp
src/agent/notification-daemon/GuiRunner.h

index cd7e758..7fd0c52 100644 (file)
@@ -68,7 +68,12 @@ const NResponseType responseMap[2][2] = {
 
 void GuiRunner::answer(bool allow)
 {
-    Eina_Bool always = elm_check_state_get(m_checkbox);
+    Eina_Bool always = EINA_FALSE;
+
+    if (!m_hwKeyClicked)
+        always = elm_check_state_get(m_checkbox);
+    else
+        m_hwKeyClicked = false;
 
     m_popupResponse = responseMap[allow][always];
 
@@ -89,6 +94,20 @@ void GuiRunner::denyAnswerCb(void *data, Evas_Object *, void *)
     runner->answer(false);
 }
 
+Eina_Bool GuiRunner::hwKeyClickedCb(void *data, int type, void *event)
+{
+    Ecore_Event_Key *ev = (Ecore_Event_Key*)event;
+    GuiRunner* runner = static_cast<GuiRunner*>(data);
+    ALOGD("HW button pressed. type <" << type << "> pressed key is <" << ev->key << ">");
+    runner->m_hwKeyClicked = true;
+    if (!strcmp("XF86Home", ev->key) || !strcmp("XF86Back", ev->key)) {
+        ALOGD("Close the window and respond as deny once.");
+        runner->m_shouldRaise = false;
+        runner->answer(false);
+    }
+    return EINA_TRUE;
+}
+
 Eina_Bool GuiRunner::dismissFdCb(void *data, Ecore_Fd_Handler *handler) {
     ALOGD("Dismiss fd awoken");
     GuiRunner *runner = static_cast<GuiRunner*>(data);
@@ -284,6 +303,9 @@ void GuiRunner::initialize()
     evas_object_smart_callback_add(m_win, "unfocused", &GuiRunner::unfocused, this);
     evas_object_smart_callback_add(m_allowButton, "clicked", &GuiRunner::allowAnswerCb, this);
     evas_object_smart_callback_add(m_denyButton, "clicked", &GuiRunner::denyAnswerCb, this);
+    elm_win_keygrab_set(m_win, "XF86Home", 0, 0, 0, ELM_WIN_KEYGRAB_SHARED);
+    elm_win_keygrab_set(m_win, "XF86Back", 0, 0, 0, ELM_WIN_KEYGRAB_TOPMOST);
+    ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, &GuiRunner::hwKeyClickedCb, this);
 
     m_initialized = true;
 }
@@ -311,6 +333,7 @@ NResponseType GuiRunner::popupRun(const std::string &app, const std::string &per
         initialize();
 
         m_running = true;
+        m_hwKeyClicked = false;
 
         std::string appId;
         std::string pkgLabel;
@@ -341,6 +364,8 @@ NResponseType GuiRunner::popupRun(const std::string &app, const std::string &per
 
         m_running = false;
         m_shouldRaise = false;
+        elm_win_keygrab_unset(m_win, "XF86Home", 0, 0);
+        elm_win_keygrab_unset(m_win, "XF86Back", 0, 0);
 
         evas_object_del(m_win);
         m_win = nullptr;
index 50bbe79..dfa90d6 100644 (file)
@@ -55,6 +55,7 @@ private:
     static void unfocused(void *data, Evas_Object *, void *);
     static void allowAnswerCb(void *data, Evas_Object *, void *);
     static void denyAnswerCb(void *data, Evas_Object *, void *);
+    static Eina_Bool hwKeyClickedCb(void *data, int type, void *event);
 
     void answer(bool allow);
     void winClose();
@@ -80,6 +81,7 @@ private:
     bool m_running = false;
     bool m_initialized = false;
     bool m_shouldRaise = false;
+    bool m_hwKeyClicked = false;
 
     std::string m_errorMsg;
 };