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"
32 #include "simple_util.h"
38 Ecore_Event_Handler *key_up;
39 Ecore_Event_Handler *key_down;
46 GSList *key_pid_list = NULL;
48 static Eina_Bool __key_release_cb(void *data, int type, void *event);
49 static Eina_Bool __key_press_cb(void *data, int type, void *event);
51 static Eina_Bool __key_release_cb(void *data, int type, void *event)
53 Evas_Event_Key_Up *ev = event;
62 _D("Invalid event object");
63 return ECORE_CALLBACK_RENEW;
67 if (entry && entry->data) {
68 pid_data = (int *) entry->data;
71 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
72 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_RELEASED);
74 ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb);
76 _E("app_send_cmd failed with error %d\n", ret);
81 return ECORE_CALLBACK_RENEW;
85 static Eina_Bool __key_press_cb(void *data, int type, void *event)
87 Evas_Event_Key_Down *ev = event;
96 _D("Invalid event object");
97 return ECORE_CALLBACK_RENEW;
100 entry = key_pid_list;
101 if (entry && entry->data) {
102 pid_data = (int *) entry->data;
104 kb = bundle_create();
105 bundle_add(kb, AUL_K_MULTI_KEY, ev->keyname);
106 bundle_add(kb, AUL_K_MULTI_KEY_EVENT, AUL_V_KEY_PRESSED);
108 ret = app_send_cmd_with_noreply(*pid_data, APP_KEY_EVENT, kb);
110 _E("app_send_cmd failed with error %d\n", ret);
115 return ECORE_CALLBACK_RENEW;
118 int _register_key_event(int pid)
123 pid_data = malloc(sizeof(int));
124 if (pid_data == NULL) {
131 key_pid_list = g_slist_prepend(key_pid_list, pid_data);
133 _D("===key stack===");
135 for (entry = key_pid_list; entry; entry = entry->next) {
137 pid_data = (int *) entry->data;
138 _D("pid : %d",*pid_data);
145 int _unregister_key_event(int pid)
150 for (entry = key_pid_list; entry;) {
152 pid_data = (int *) entry->data;
154 if(pid == *pid_data) {
155 key_pid_list = g_slist_remove(key_pid_list, pid_data);
161 _D("===key stack===");
163 for (entry = key_pid_list; entry; entry = entry->next) {
165 pid_data = (int *) entry->data;
166 _D("pid : %d",*pid_data);
173 Ecore_X_Window _input_window_get()
180 key_info.win = ecore_x_window_input_new(ecore_x_window_root_first_get(), 0, 0, 1, 1);
182 _D("Failed to create hidden window");
185 _D("_key_init, win : %x", key_info.win);
187 ecore_x_icccm_title_set(key_info.win, "acdaemon,key,receiver");
188 ecore_x_netwm_name_set(key_info.win, "acdaemon,key,receiver");
189 ecore_x_netwm_pid_set(key_info.win, getpid());
191 ecore_x_window_show(key_info.win);
193 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYCD, SHARED_GRAB);
194 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_STOPCD, SHARED_GRAB);
195 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PAUSECD, SHARED_GRAB);
196 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_NEXTSONG, SHARED_GRAB);
197 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PREVIOUSSONG, SHARED_GRAB);
198 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_REWIND, SHARED_GRAB);
199 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_FASTFORWARD, SHARED_GRAB);
200 utilx_grab_key(ecore_x_display_get(), key_info.win, KEY_PLAYPAUSE, SHARED_GRAB);
202 key_info.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, __key_release_cb, NULL);
203 if (!key_info.key_up) {
204 _D("Failed to register a key up event handler");
207 key_info.key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __key_press_cb, NULL);
208 if (!key_info.key_down) {
209 _D("Failed to register a key down event handler");