Implement keygrab using ecore API : ecore_wl_window_keygrab_set() 75/47975/5 tizen_3.0.m1_mobile accepted/tizen/mobile/20150911.091705 submit/tizen_common/20151026.085049 submit/tizen_mobile/20150911.023417 tizen_3.0.m1_mobile_release
authorgs86.lee <gs86.lee@samsung.com>
Thu, 10 Sep 2015 11:40:55 +0000 (20:40 +0900)
committerGeunSun Lee <gs86.lee@samsung.com>
Fri, 11 Sep 2015 02:29:01 +0000 (19:29 -0700)
Change-Id: I60096c236a3011424c3493562cd8c41987d1eafd

CMakeLists.txt
include/mobile/hw_key.h
packaging/starter.spec
src/mobile/hw_key.c
src/mobile/starter.c

index 8599263..76ee0bd 100644 (file)
@@ -21,6 +21,7 @@ pkg_check_modules(pkgs REQUIRED
        db-util
        dlog
        ecore
+       ecore-wayland
        ecore-evas
        ecore-input
        edbus
@@ -157,14 +158,9 @@ SET(BUILD_SOURCE
        src/mobile/lock_pwd_verification.c
        src/mobile/window_mgr.c
        src/mobile/popup.c
-)
-
-IF(X11_SUPPORT)
-SET(BUILD_SOURCE
-       ${BUILD_SOURCE}
        src/mobile/hw_key.c
 )
-ENDIF(X11_SUPPORT)
+
 ELSE("${TIZEN_PROFILE_NAME}" STREQUAL "MOBILE")
 SET(BUILD_SOURCE
        src/dbus_util.c
index 99e83ee..787a779 100644 (file)
 #ifndef __HW_KEY_H__
 #define __HW_KEY_H__
 
-#ifdef HVAE_X11
-#define        KEY_VOLUMEUP    "XF86AudioRaiseVolume"
-#define        KEY_VOLUMEDOWN  "XF86AudioLowerVolume"
-#define        KEY_HOME        "XF86Home"
-#define        KEY_CONFIG      "XF86Camera_Full"
-#define        KEY_SEARCH      "XF86Search"
-#define        KEY_MEDIA       "XF86AudioMedia"
-#define        KEY_TASKSWITCH  "XF86TaskPane"
-#define        KEY_WEBPAGE     "XF86WWW"
-#define        KEY_MAIL        "XF86Mail"
-#define        KEY_VOICE       "XF86Voice"
-#define        KEY_APPS        "XF86Apps"
-#define        KEY_CONNECT     "XF86Call"
-#define KEY_BACK       "XF86Back"
+#if HAVE_X11
+
+#define KEY_VOLUMEUP    "XF86AudioRaiseVolume"
+#define KEY_VOLUMEDOWN  "XF86AudioLowerVolume"
+#define KEY_HOME        "XF86Home"
+#define KEY_CONFIG      "XF86Camera_Full"
+#define KEY_SEARCH      "XF86Search"
+#define KEY_MEDIA       "XF86AudioMedia"
+#define KEY_TASKSWITCH  "XF86TaskPane"
+#define KEY_WEBPAGE     "XF86WWW"
+#define KEY_MAIL        "XF86Mail"
+#define KEY_VOICE       "XF86Voice"
+#define KEY_APPS        "XF86Apps"
+#define KEY_CONNECT     "XF86Call"
+#define KEY_BACK       "XF86Back"
+
+#elif HAVE_WAYLAND
+
+typedef enum {
+       KEY_VOLUMEUP = 0,
+       KEY_VOLUMEDOWN = 1,
+       KEY_POWER = 2,
+       KEY_MENU,
+       KEY_HOME,
+       KEY_BACK,
+       KLEY_CAMERA,
+       KEY_CONFIG,
+       KEY_SEARCH,
+       KEY_PLAYCD,
+       KEY_PAUSECB,
+       KEY_STOPCD,
+       KEY_NEXTSONG,
+       KEY_PRIVEIOUSSONG,
+       KEY_REWIND,
+       KEY_FASTFORWARD,
+       KEY_MEDIA,
+       KEY_PLAYPAUSE,
+       KEY_MUTE,
+       KEY_REC,
+       KEY_CANCEL,
+       KEY_SOFTBD,
+       KEY_QUICKPANEL,
+       KEY_TASKSWITCH,
+       KEY_HOMEPAGE,
+       KEY_WEBPAGE,
+       KEY_MAIL,
+       KEY_SCREENSAVER,
+       KEY_BRIGHTNESSDOWN,
+       KEY_BRIGHTNESSUP,
+       KEY_VOICE,
+       KEY_LANGUAGE,
+       KEY_APPS,
+       KEY_CONNECT,
+       KEY_GAMEPLAY,
+       KEY_VOICEWAKEUP_LPSD,
+       KEY_VOICEWAKEUP,
+       KEY_NAME_MAX,
+} key_name_e;
+#endif
 
 extern void hw_key_destroy_window(void);
 extern void hw_key_create_window(void);
-#endif //HAVE_X11
 
 #endif
-
 // End of a file
index cb21f0c..319a645 100644 (file)
@@ -38,6 +38,7 @@ BuildRequires:  pkgconfig(feedback)
 BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(ecore-wayland)
 BuildRequires:  pkgconfig(edje)
 BuildRequires: pkgconfig(edbus)
 BuildRequires:  pkgconfig(eina)
index 9fc7710..b2c2de7 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #ifdef HAVE_X11
+
 #include <app.h>
 #include <bundle.h>
 #include <Elementary.h>
@@ -486,6 +487,482 @@ void hw_key_destroy_window(void)
 
        media_key_release();
 }
-#endif //HAVE_X11
+
+#elif HAVE_WAYLAND
+
+#include <app.h>
+#include <bundle.h>
+#include <Elementary.h>
+#include <Ecore.h>
+#include <Ecore_Wayland.h>
+#include <Ecore_Input.h>
+#include <dd-deviced.h>
+#include <syspopup_caller.h>
+#include <vconf.h>
+#include <system/media_key.h>
+#include <aul.h>
+#include <feedback.h>
+#include <system_settings.h>
+
+#include "hw_key.h"
+#include "home_mgr.h"
+#include "util.h"
+#include "dbus_util.h"
+#include "lock_mgr.h"
+#include "status.h"
+#include "process_mgr.h"
+#include "lock_pwd_util.h"
+
+#define APPID_CAMERA "org.tizen.camera-app"
+#define APPID_CALLLOG "org.tizen.calllog"
+#define APPID_MUSIC_PLAYER "org.tizen.music-player"
+#define APPID_TASKMGR "org.tizen.task-mgr"
+#define APPID_BROWSER "org.tizen.browser"
+#define APPID_EMAIL "org.tizen.email"
+#define APPID_DIALER "org.tizen.phone"
+
+#define STR_ATOM_KEYROUTER_NOTIWINDOW "_KEYROUTER_NOTIWINDOW"
+
+#define LONG_PRESS_TIMER_SEC 0.4
+#define HOMEKEY_TIMER_SEC 0.2
+#define CANCEL_KEY_TIMER_SEC 0.3
+
+
+const char *key_name[KEY_NAME_MAX] = {
+       "XF86AudioRaiseVolume",
+       "XF86AudioLowerVolume",
+       "XF86PowerOff",
+       "XF86Menu",
+       "XF86Home",
+       "XF86Back",
+       "XF86Camera",
+       "XF86Camera_Full",
+       "XF86Search",
+       "XF86AudioPlay",
+       "XF86AudioPause",
+       "XF86AudioStop",
+       "XF86AudioNext",
+       "XF86AudioPrev",
+       "XF86AudioRewind",
+       "XF86AudioForward",
+       "XF86AudioMedia",
+       "XF86AudioPlayPause",
+       "XF86AudioMute",
+       "XF86AudioRecord",
+       "Cancel",
+       "XF86SoftKBD",
+       "XF86QuickPanel",
+       "XF86TaskPane",
+       "XF86HomePage",
+       "XF86WWW",
+       "XF86Mail",
+       "XF86ScreenSaver",
+       "XF86MonBrightnessDown",
+       "XF86MonBrightnessUp",
+       "XF86Voice",
+       "Hangul",
+       "XF86Apps",
+       "XF86Call",
+       "XF86Game",
+       "XF86VoiceWakeUp_LPSD",
+       "XF86VoiceWakeUp",
+       "KEY_NAME_MAX",
+};
+
+
+static struct {
+       Ecore_Event_Handler *key_up;
+       Ecore_Event_Handler *key_down;
+       Ecore_Timer *home_long_press_timer;
+       Ecore_Timer *home_multi_press_timer;
+       Ecore_Timer *keygrab_timer;
+       Eina_Bool cancel;
+       int homekey_count;
+} key_info = {
+       .key_up = NULL,
+       .key_down = NULL,
+       .home_long_press_timer = NULL,
+       .home_multi_press_timer = NULL,
+       .keygrab_timer = NULL,
+       .cancel = EINA_FALSE,
+       .homekey_count = 0,
+};
+
+
+
+
+static void _cancel_key_events(void)
+{
+       key_info.homekey_count = 0;
+
+       if (key_info.home_long_press_timer) {
+               ecore_timer_del(key_info.home_long_press_timer);
+               key_info.home_long_press_timer = NULL;
+       }
+
+       if(key_info.home_multi_press_timer) {
+               ecore_timer_del(key_info.home_multi_press_timer);
+               key_info.home_multi_press_timer = NULL;
+       }
+}
+
+
+
+#define SERVICE_OPERATION_POPUP_SEARCH "http://samsung.com/appcontrol/operation/search"
+#define SEARCH_PKG_NAME "org.tizen.sfinder"
+static int _launch_search(void)
+{
+       app_control_h app_control;
+       int ret = APP_CONTROL_ERROR_NONE;
+
+       app_control_create(&app_control);
+       app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
+       app_control_set_app_id(app_control, SEARCH_PKG_NAME);
+
+       ret = app_control_send_launch_request(app_control, NULL, NULL);
+
+       if(ret != APP_CONTROL_ERROR_NONE) {
+               _E("Cannot launch search!! err[%d]", ret);
+       }
+
+       app_control_destroy(app_control);
+       return ret;
+}
+
+
+
+static void _after_launch_taskmgr(int pid)
+{
+       if(0 < pid) {
+               if(dbus_util_send_oomadj(pid, OOM_ADJ_VALUE_DEFAULT) < 0){
+                       _E("failed to send oom dbus signal");
+               }
+       }
+}
+
+
+
+static Eina_Bool _launch_taskmgr_cb(void* data)
+{
+       int val = -1;
+
+       _D("Launch TASKMGR");
+
+       key_info.home_long_press_timer = NULL;
+
+       if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &val) < 0) {
+               _E("Cannot get VCONFKEY for lock state");
+       } else if (VCONFKEY_IDLE_LOCK == val) {
+               _E("lock state, ignore home key long press..!!");
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       process_mgr_must_launch(APPID_TASKMGR, NULL, NULL, NULL, _after_launch_taskmgr);
+
+       return ECORE_CALLBACK_CANCEL;
+}
+
+
+
+static Eina_Bool _launch_by_home_key(void *data)
+{
+       int ret = 0;
+
+       if (status_passive_get()->idle_lock_state > VCONFKEY_IDLE_UNLOCK) {
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       ret = home_mgr_open_home(NULL);
+       if(ret > 0) {
+               dbus_util_send_home_raise_signal();
+       }
+
+       return ECORE_CALLBACK_CANCEL;
+}
+
+
+
+static Eina_Bool _home_multi_press_timer_cb(void *data)
+{
+       _W("homekey count[%d]", key_info.homekey_count);
+
+       key_info.home_multi_press_timer = NULL;
+
+       if(0 == key_info.homekey_count % 2) {
+               key_info.homekey_count = 0;
+               return ECORE_CALLBACK_CANCEL;
+       } else if(key_info.homekey_count >= 3) {
+               key_info.homekey_count = 0;
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       /* Single homekey operation */
+       key_info.homekey_count = 0;
+       _launch_by_home_key(data);
+
+       return ECORE_CALLBACK_CANCEL;
+
+}
+
+
+
+static void _release_multimedia_key(const char *value)
+{
+       ret_if(NULL == value);
+       _D("Multimedia key is released with %s", value);
+       process_mgr_must_launch(APPID_MUSIC_PLAYER, "multimedia_key", value, NULL, NULL);
+}
+
+
+
+static Eina_Bool _key_release_cb(void *data, int type, void *event)
+{
+       Evas_Event_Key_Up *ev = event;
+
+       retv_if(!ev, ECORE_CALLBACK_RENEW);
+       retv_if(!ev->keyname, ECORE_CALLBACK_RENEW);
+
+       _D("_key_release_cb : %s Released", ev->keyname);
+
+       /* Priority 1 : Cancel event */
+       if (!strcmp(ev->keyname, key_name[KEY_CANCEL])) {
+               _D("CANCEL Key is released");
+               key_info.cancel = EINA_FALSE;
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       if (EINA_TRUE == key_info.cancel) {
+               _D("CANCEL is on");
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       /* Priority 2 : Execute before checking the lock status */
+       if (!strcmp(ev->keyname, key_name[KEY_MEDIA])) {
+               _release_multimedia_key("KEY_PLAYCD");
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       /* Priority 3 : Check the lock status */
+       if ((status_passive_get()->idle_lock_state  == VCONFKEY_IDLE_LOCK)
+               && (status_active_get()->setappl_screen_lock_type_int > SETTING_SCREEN_LOCK_TYPE_NONE)) {
+               if (!strcmp(ev->keyname, key_name[KEY_BACK])) {
+                       _D("Back key is released");
+                       lock_pwd_util_back_key_relased();
+               } else {
+                       _D("phone lock state, ignore home key.");
+               }
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       /* Priority 4 : These keys are only activated after checking the lock state */
+#if 0
+       if (!strcmp(ev->keyname, key_name[KEY_END])) {
+       } else
+#endif
+       if (!strcmp(ev->keyname, key_name[KEY_CONFIG])) {
+       //} else if (!strcmp(ev->keyname, key_name[KEY_SEND])) {
+       } else if (!strcmp(ev->keyname, key_name[KEY_HOME])) {
+               _W("Home Key is released");
+
+               syspopup_destroy_all();
+
+               if(key_info.home_multi_press_timer) {
+                       _D("delete homekey timer");
+                       ecore_timer_del(key_info.home_multi_press_timer);
+                       key_info.home_multi_press_timer = NULL;
+               }
+
+               if (key_info.home_long_press_timer) {
+                       ecore_timer_del(key_info.home_long_press_timer);
+                       key_info.home_long_press_timer = NULL;
+               } else {
+                       key_info.homekey_count = 0;
+                       return ECORE_CALLBACK_RENEW;
+               }
+
+               key_info.home_multi_press_timer = ecore_timer_add(HOMEKEY_TIMER_SEC, _home_multi_press_timer_cb, NULL);
+               if (!key_info.home_multi_press_timer) {
+                       _E("Critical! cannot add a timer for home multi press");
+               }
+               return ECORE_CALLBACK_RENEW;
+       //} else if (!strcmp(ev->keyname, key_name[KEY_PAUSE])) {
+       } else if (!strcmp(ev->keyname, key_name[KEY_APPS])) {
+               _D("App tray key is released");
+       } else if (!strcmp(ev->keyname, key_name[KEY_TASKSWITCH])) {
+               _D("Task switch key is released");
+               _launch_taskmgr_cb(NULL);
+       } else if (!strcmp(ev->keyname, key_name[KEY_WEBPAGE])) {
+               _D("Web page key is released");
+               process_mgr_must_open(APPID_BROWSER, NULL, NULL);
+       } else if (!strcmp(ev->keyname, key_name[KEY_MAIL])) {
+               _D("Mail key is released");
+               process_mgr_must_open(APPID_EMAIL, NULL, NULL);
+       } else if (!strcmp(ev->keyname, key_name[KEY_CONNECT])) {
+               _D("Connect key is released");
+               process_mgr_must_open(APPID_DIALER, NULL, NULL);
+       } else if (!strcmp(ev->keyname, key_name[KEY_SEARCH])) {
+               _D("Search key is released");
+               if (_launch_search() < 0) {
+                       _E("Failed to launch the search");
+               }
+       } else if (!strcmp(ev->keyname, key_name[KEY_VOICE])) {
+               _D("Voice key is released");
+       }
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+
+
+static Eina_Bool _key_press_cb(void *data, int type, void *event)
+{
+       Evas_Event_Key_Down *ev = event;
+
+       retv_if(!ev, ECORE_CALLBACK_RENEW);
+       retv_if(!ev->keyname, ECORE_CALLBACK_RENEW);
+
+       _D("_key_press_cb : %s Pressed", ev->keyname);
+
+       /* Priority 1 : Cancel */
+       /*              every reserved events have to be canceld when cancel key is pressed */
+       if (!strcmp(ev->keyname, key_name[KEY_CANCEL])) {
+               _D("Cancel button is pressed");
+               key_info.cancel = EINA_TRUE;
+               _cancel_key_events();
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       if (EINA_TRUE == key_info.cancel) {
+               _D("CANCEL is on");
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       /* Priority 2 : Check the lock status */
+       if ((status_passive_get()->idle_lock_state == VCONFKEY_IDLE_LOCK)
+               && (status_active_get()->setappl_screen_lock_type_int > SETTING_SCREEN_LOCK_TYPE_NONE)) {
+               _D("phone lock state, ignore key events.");
+               _cancel_key_events();
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       /* Priority 3 : other keys */
+#if 0
+       if (!strcmp(ev->keyname, key_name[KEY_SEND])) {
+               _D("Launch calllog");
+               process_mgr_must_open(APPID_CALLLOG, NULL, NULL);
+       } else
+#endif
+       if(!strcmp(ev->keyname, key_name[KEY_CONFIG])) {
+               _D("Launch camera");
+               process_mgr_must_open(APPID_CAMERA, NULL, NULL);
+       } else if (!strcmp(ev->keyname, key_name[KEY_HOME])) {
+               _W("Home Key is pressed");
+               if (key_info.home_long_press_timer) {
+                       ecore_timer_del(key_info.home_long_press_timer);
+                       key_info.home_long_press_timer = NULL;
+               }
+
+               key_info.homekey_count++;
+               _W("homekey count : %d", key_info.homekey_count);
+
+               if(key_info.home_multi_press_timer) {
+                       ecore_timer_del(key_info.home_multi_press_timer);
+                       key_info.home_multi_press_timer = NULL;
+                       _D("delete homekey timer");
+               }
+
+               _D("create long press timer");
+               key_info.home_long_press_timer = ecore_timer_add(LONG_PRESS_TIMER_SEC, _launch_taskmgr_cb, NULL);
+               if (!key_info.home_long_press_timer) {
+                       _E("Failed to add timer for long press detection");
+               }
+       } else if (!strcmp(ev->keyname, key_name[KEY_MEDIA])) {
+               _D("Media key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_APPS])) {
+               _D("App tray key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_TASKSWITCH])) {
+               _D("Task switch key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_WEBPAGE])) {
+               _D("Web page key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_MAIL])) {
+               _D("Mail key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_SEARCH])) {
+               _D("Search key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_VOICE])) {
+               _D("Voice key is pressed");
+       } else if (!strcmp(ev->keyname, key_name[KEY_CONNECT])) {
+               _D("Connect key is pressed");
+       }
+
+       return ECORE_CALLBACK_RENEW;
+}
+
+
+
+static Eina_Bool __keygrab_timer_cb(void *data)
+{
+       int i = 0;
+       int ret = 0;
+
+       for (i = 0; i < KEY_NAME_MAX; i++) {
+               ret = ecore_wl_window_keygrab_set(NULL, key_name[i], 0, 0, 0, ECORE_WL_WINDOW_KEYGRAB_SHARED);
+               _D("key grab : %s / ret : %d", key_name[i], ret);
+       }
+
+       key_info.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_release_cb, NULL);
+       if (!key_info.key_up) {
+               _E("Failed to register a key up event handler");
+       }
+
+       key_info.key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_press_cb, NULL);
+       if (!key_info.key_down) {
+               _E("Failed to register a key down event handler");
+       }
+
+       return ECORE_CALLBACK_CANCEL;
+}
+
+
+
+void hw_key_create_window(void)
+{
+       if (key_info.keygrab_timer) {
+               ecore_timer_del(key_info.keygrab_timer);
+               key_info.keygrab_timer = NULL;
+       }
+
+       key_info.keygrab_timer = ecore_timer_add(1.0f, __keygrab_timer_cb, NULL);
+       if (!key_info.keygrab_timer) {
+               _E("Failed to add timer for keygrab");
+       }
+}
+
+
+
+void hw_key_destroy_window(void)
+{
+       int i = 0;
+
+       for (i = 0; i < KEY_NAME_MAX; i++) {
+               ecore_wl_window_keygrab_unset(NULL, key_name[i], 0, 0);
+       }
+
+       if (key_info.keygrab_timer) {
+               ecore_timer_del(key_info.keygrab_timer);
+               key_info.keygrab_timer = NULL;
+       }
+
+       if (key_info.key_up) {
+               ecore_event_handler_del(key_info.key_up);
+               key_info.key_up = NULL;
+       }
+
+       if (key_info.key_down) {
+               ecore_event_handler_del(key_info.key_down);
+               key_info.key_down = NULL;
+       }
+}
+
+#endif
 
 // End of a file
index 4d7b28c..4d2ef09 100644 (file)
 #include "process_mgr.h"
 #include "util.h"
 #include "status.h"
-
-#ifdef HAVE_X11
 #include "hw_key.h"
-#endif
 
 #define PWLOCK_LITE_PKG_NAME "org.tizen.pwlock-lite"
 
@@ -263,9 +260,7 @@ static void _init(struct appdata *ad)
        process_mgr_must_launch(PWLOCK_LITE_PKG_NAME, NULL, NULL, _fail_to_launch_pwlock, _after_launch_pwlock);
 #endif
 
-#ifdef HAVE_X11
        hw_key_create_window();
-#endif
        home_mgr_init(NULL);
 
        aul_listen_app_dead_signal(_check_dead_signal, NULL);
@@ -276,9 +271,7 @@ static void _init(struct appdata *ad)
 static void _fini(struct appdata *ad)
 {
        home_mgr_fini();
-#ifdef HAVE_X11
        hw_key_destroy_window();
-#endif
        lock_mgr_daemon_end();
 
        status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);