4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <Ecore_Input.h>
25 #ifdef _APPFW_FEATURE_AMD_KEY
32 #include <bundle_internal.h>
34 #include "amd_config.h"
36 #include "simple_util.h"
42 Ecore_Event_Handler *key_up;
43 Ecore_Event_Handler *key_down;
50 GSList *key_pid_list = NULL;
52 #ifdef _APPFW_FEATURE_AMD_KEY
53 static Eina_Bool __key_release_cb(void *data, int type, void *event);
54 static Eina_Bool __key_press_cb(void *data, int type, void *event);
56 static Eina_Bool __key_release_cb(void *data, int type, void *event)
58 Evas_Event_Key_Up *ev = event;
67 _D("Invalid event object");
68 return ECORE_CALLBACK_RENEW;
71 if (strcmp(ev->keyname, X_KEY_BACK) == 0) {
72 _D("skip back key case");
73 return ECORE_CALLBACK_RENEW;
77 if (entry && entry->data) {
78 pid_data = (int *) entry->data;
81 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
82 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_RELEASED);
84 ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb);
86 _E("app_send_cmd failed with error %d\n", ret);
91 return ECORE_CALLBACK_RENEW;
95 static Eina_Bool __key_press_cb(void *data, int type, void *event)
97 Evas_Event_Key_Down *ev = event;
106 _D("Invalid event object");
107 return ECORE_CALLBACK_RENEW;
110 if (strcmp(ev->keyname, X_KEY_BACK) == 0) {
111 _D("skip back key case");
112 return ECORE_CALLBACK_RENEW;
115 entry = key_pid_list;
116 if (entry && entry->data) {
117 pid_data = (int *) entry->data;
119 kb = bundle_create();
120 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
121 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_PRESSED);
123 ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb);
125 _E("app_send_cmd failed with error %d\n", ret);
130 return ECORE_CALLBACK_RENEW;
134 int _register_key_event(int pid)
136 #ifdef _APPFW_FEATURE_AMD_KEY
140 pid_data = malloc(sizeof(int));
141 if (pid_data == NULL) {
148 key_pid_list = g_slist_prepend(key_pid_list, pid_data);
150 _D("===key stack===");
152 for (entry = key_pid_list; entry; entry = entry->next) {
154 pid_data = (int *) entry->data;
155 _D("pid : %d",*pid_data);
162 int _unregister_key_event(int pid)
164 #ifdef _APPFW_FEATURE_AMD_KEY
168 for (entry = key_pid_list; entry;) {
170 pid_data = (int *) entry->data;
172 if(pid == *pid_data) {
173 key_pid_list = g_slist_remove(key_pid_list, pid_data);
179 _D("===key stack===");
181 for (entry = key_pid_list; entry; entry = entry->next) {
183 pid_data = (int *) entry->data;
184 _D("pid : %d",*pid_data);
191 Ecore_X_Window _input_window_get()
198 #ifdef _APPFW_FEATURE_AMD_KEY
199 key_info.win = ecore_x_window_input_new(ecore_x_window_root_first_get(), 0, 0, 1, 1);
201 _D("Failed to create hidden window");
204 _D("_key_init, win : %x", key_info.win);
206 ecore_x_icccm_title_set(key_info.win, "acdaemon,key,receiver");
207 ecore_x_netwm_name_set(key_info.win, "acdaemon,key,receiver");
208 ecore_x_netwm_pid_set(key_info.win, getpid());
210 ecore_x_window_show(key_info.win);
212 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PLAYCD, SHARED_GRAB);
213 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_STOPCD, SHARED_GRAB);
214 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PAUSECD, SHARED_GRAB);
215 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_NEXTSONG, SHARED_GRAB);
216 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PREVIOUSSONG, SHARED_GRAB);
217 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_REWIND, SHARED_GRAB);
218 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_FASTFORWARD, SHARED_GRAB);
219 utilx_grab_key(ecore_x_display_get(), key_info.win, X_KEY_PLAYPAUSE, SHARED_GRAB);
221 key_info.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, __key_release_cb, NULL);
222 if (!key_info.key_up) {
223 _D("Failed to register a key up event handler");
226 key_info.key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __key_press_cb, NULL);
227 if (!key_info.key_down) {
228 _D("Failed to register a key down event handler");
234 int _key_grab(const char* key, int grab_mode)
236 #ifdef _APPFW_FEATURE_AMD_KEY
240 _D("There is no created hidden window");
243 _D("_key_grab, win : %x", key_info.win);
245 ret = utilx_grab_key(ecore_x_display_get(), key_info.win, key, grab_mode);
247 _W("fail(%d) to grab key(%s-%d)", ret, key, grab_mode);
256 int _key_ungrab(const char* key)
258 #ifdef _APPFW_FEATURE_AMD_KEY
262 _D("There is no created hidden window");
265 _D("_key_ungrab, win : %x", key_info.win);
267 ret = utilx_ungrab_key(ecore_x_display_get(), key_info.win, key);
269 _W("fail(%d) to ungrab key(%s)", ret, key);