merge from 2.4 , block compile error
[apps/core/preloaded/quickpanel.git] / daemon / service / keyboard.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <vconf.h>
19 #ifdef HAVE_X
20 #include <utilX.h>
21 #include <X11/Xlib.h>
22 #endif
23 #include <Ecore_Input.h>
24 #include <feedback.h>
25 #include "common.h"
26 #include "noti_util.h"
27 #include "keyboard.h"
28
29 #define KEY_BACK        "XF86Back"
30 #define KEY_CANCEL      "Cancel"
31 #define KEY_MENU        "XF86Menu"
32 #define KEY_QUICKPANEL  "XF86QuickPanel"
33 #define KEY_HOME        "XF86Home"
34
35 static Eina_Bool _service_hardkey_up_cb(void *data, int type, void *event)
36 {
37         struct appdata *ad = NULL;
38         Ecore_Event_Key *key_event = NULL;
39
40         retif(data == NULL || event == NULL, EINA_FALSE, "Invalid parameter!");
41         ad = data;
42         key_event = event;
43
44         if (!strcmp(key_event->keyname, KEY_HOME)) {
45                 if (ad->is_hardkey_cancel == EINA_FALSE) {
46                         quickpanel_uic_close_quickpanel(false, 0);
47                 } else {
48                         DBG("Cancel status, do nothing");
49                 }
50         } else if (!strcmp(key_event->keyname, KEY_CANCEL)) {
51                 ad->is_hardkey_cancel = EINA_FALSE;
52         } else if (!strcmp(key_event->keyname, KEY_BACK)) {
53                 if (ad->popup != NULL) {
54                         Evas_Smart_Cb back_cb = evas_object_data_get(ad->popup, EDATA_BACKKEY_CB);
55                         if (back_cb != NULL) {
56                                 back_cb(ad->popup, ad->popup, NULL);
57                         }
58                 } else {
59                         quickpanel_uic_close_quickpanel(false, 0);
60                 }
61         }
62         return EINA_FALSE;
63 }
64
65 static Eina_Bool _service_hardkey_down_cb(void *data, int type, void *event)
66 {
67         Ecore_Event_Key *key_event = event;
68         struct appdata *ad = data;
69         retif(key_event == NULL, EINA_FALSE, "Invalid parameter!");
70         retif(ad == NULL, EINA_FALSE, "Invalid parameter!");
71
72         if (!strcmp(key_event->keyname, KEY_CANCEL)) {
73                 ad->is_hardkey_cancel = EINA_TRUE;
74         } else if (!strcmp(key_event->keyname, KEY_QUICKPANEL)) {
75                 quickpanel_uic_toggle_openning_quickpanel();
76         }
77         return EINA_FALSE;
78 }
79
80 HAPI void quickpanel_keyboard_init(void *data)
81 {
82         struct appdata *ad = data;
83         Ecore_Event_Handler *hdl_key_down = NULL;
84         Ecore_Event_Handler *hdl_key_up = NULL;
85         retif(ad == NULL, , "Invalid parameter!");
86
87         if (elm_win_keygrab_set(elm_win_xwindow_get(ad->win), KEY_QUICKPANEL, 0, 0, 0, ELM_WIN_KEYGRAB_SHARED) != 0) {
88                 ERR("failed to grab KEY_QUICKPANEL");
89         }
90
91         hdl_key_down = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _service_hardkey_down_cb, ad);
92         if (hdl_key_down == NULL) {
93                 ERR("failed to add handler(ECORE_EVENT_KEY_DOWN)");
94         }
95         ad->hdl_hardkey_down = hdl_key_down;
96
97         hdl_key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _service_hardkey_up_cb, ad);
98         if (hdl_key_up == NULL) {
99                 ERR("failed to add handler(ECORE_EVENT_KEY_UP)");
100         }
101         ad->hdl_hardkey_up = hdl_key_up;
102         ad->is_hardkey_cancel = EINA_FALSE;
103 }
104
105 HAPI void quickpanel_keyboard_fini(void *data)
106 {
107         struct appdata *ad = data;
108         retif(ad == NULL, , "Invalid parameter!");
109
110         if (ad->hdl_hardkey_up != NULL) {
111                 ecore_event_handler_del(ad->hdl_hardkey_up);
112                 ad->hdl_hardkey_up = NULL;
113         }
114
115         if (ad->hdl_hardkey_down != NULL) {
116                 ecore_event_handler_del(ad->hdl_hardkey_down);
117                 ad->hdl_hardkey_down = NULL;
118         }
119
120         if (elm_win_keygrab_unset(elm_win_xwindow_get(ad->win), KEY_QUICKPANEL, 0, 0) != 0) {
121                 ERR("failed to ungrab KEY_QUICKPANEL");
122         }
123
124 }
125
126 HAPI void quickpanel_keyboard_openning_init(void *data)
127 {
128         struct appdata *ad = data;
129         retif(ad == NULL, , "Invalid parameter!");
130
131         if (elm_win_keygrab_set(elm_win_xwindow_get(ad->win), KEY_BACK, 0, 0, 0, ELM_WIN_KEYGRAB_EXCLUSIVE ) != 0) {
132                 ERR("failed to grab KEY_BACK");
133         }
134
135         if (elm_win_keygrab_set(elm_win_xwindow_get(ad->win), KEY_MENU, 0, 0, 0, ELM_WIN_KEYGRAB_EXCLUSIVE ) != 0) {
136                 ERR("failed to grab KEY_MENU");
137         }
138
139         if (elm_win_keygrab_set(elm_win_xwindow_get(ad->win), KEY_HOME, 0, 0, 0, ELM_WIN_KEYGRAB_SHARED) != 0) {
140                 ERR("failed to grab KEY_HOME");
141         }
142 }
143
144 HAPI void quickpanel_keyboard_closing_fini(void *data)
145 {
146         struct appdata *ad = data;
147         retif(ad == NULL, , "Invalid parameter!");
148
149         if (elm_win_keygrab_unset(elm_win_xwindow_get(ad->win), KEY_BACK ,0 ,0) != 0) {
150                 ERR("failed to ungrab KEY_BACK");
151         }
152
153         if (elm_win_keygrab_unset(elm_win_xwindow_get(ad->win), KEY_MENU ,0 ,0) != 0) {
154                 ERR("failed to ungrab KEY_MENU");
155         }
156
157         if (elm_win_keygrab_unset(elm_win_xwindow_get(ad->win), KEY_HOME ,0 ,0) != 0) {
158                 ERR("failed to ungrab KEY_HOME");
159         }
160 }