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.
23 #include <Ecore_Input.h>
30 #include "amd_config.h"
31 #include "simple_util.h"
37 Ecore_Event_Handler *key_up;
38 Ecore_Event_Handler *key_down;
45 GSList *key_pid_list = NULL;
47 static Eina_Bool __key_release_cb(void *data, int type, void *event);
48 static Eina_Bool __key_press_cb(void *data, int type, void *event);
50 static Eina_Bool __key_release_cb(void *data, int type, void *event)
52 Evas_Event_Key_Up *ev = event;
61 _D("Invalid event object");
62 return ECORE_CALLBACK_RENEW;
66 if (entry && entry->data) {
67 pid_data = (int *) entry->data;
70 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
71 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_RELEASED);
73 ret = app_send_cmd(*pid_data, APP_KEY_EVENT, kb);
75 _E("app_send_cmd failed with error %d\n", ret);
80 return ECORE_CALLBACK_RENEW;
84 static Eina_Bool __key_press_cb(void *data, int type, void *event)
86 Evas_Event_Key_Down *ev = event;
95 _D("Invalid event object");
96 return ECORE_CALLBACK_RENEW;
100 if (entry && entry->data) {
101 pid_data = (int *) entry->data;
103 kb = bundle_create();
104 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
105 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_PRESSED);
107 ret = app_send_cmd(*pid_data, APP_KEY_EVENT, kb);
109 _E("app_send_cmd failed with error %d\n", ret);
114 return ECORE_CALLBACK_RENEW;
117 int _register_key_event(int pid)
122 pid_data = malloc(sizeof(int));
125 key_pid_list = g_slist_prepend(key_pid_list, pid_data);
127 _D("===key stack===");
129 for (entry = key_pid_list; entry; entry = entry->next) {
131 pid_data = (int *) entry->data;
132 _D("pid : %d",*pid_data);
139 int _unregister_key_event(int pid)
144 for (entry = key_pid_list; entry;) {
146 pid_data = (int *) entry->data;
148 if(pid == *pid_data) {
149 key_pid_list = g_slist_remove(key_pid_list, pid_data);
155 _D("===key stack===");
157 for (entry = key_pid_list; entry; entry = entry->next) {
159 pid_data = (int *) entry->data;
160 _D("pid : %d",*pid_data);
169 key_info.win = ecore_x_window_input_new(0, 0, 0, 1, 1);
171 _D("Failed to create hidden window");
174 ecore_x_icccm_title_set(key_info.win, "acdaemon,key,receiver");
175 ecore_x_netwm_name_set(key_info.win, "acdaemon,key,receiver");
176 ecore_x_netwm_pid_set(key_info.win, getpid());
178 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYCD, SHARED_GRAB);
179 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_STOPCD, SHARED_GRAB);
180 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PAUSECD, SHARED_GRAB);
181 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_NEXTSONG, SHARED_GRAB);
182 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PREVIOUSSONG, SHARED_GRAB);
183 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_REWIND, SHARED_GRAB);
184 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_FASTFORWARD, SHARED_GRAB);
185 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYPAUSE, SHARED_GRAB);
187 key_info.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, __key_release_cb, NULL);
188 if (!key_info.key_up) {
189 _D("Failed to register a key up event handler");
192 key_info.key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __key_press_cb, NULL);
193 if (!key_info.key_down) {
194 _D("Failed to register a key down event handler");