summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJi-Youn Park <jy0703.park@samsung.com>2015-05-13 20:57:36 +0900
committerJi-Youn Park <jy0703.park@samsung.com>2015-05-13 20:57:36 +0900
commit56120ffc53ee6498f8bf58c171a0d16dcc7f9b77 (patch)
treeff9fce36a5b33c06f1b051c5bb8b8afd86e4ac57
parent77b3eed82e008ade867b8e1ffd8055ffa5d112f0 (diff)
elm_win: Add elm win key grab. If keyrouter support several keygrab mode, apps can use it.
-rw-r--r--src/bin/Makefile.am1
-rw-r--r--src/bin/test.c2
-rw-r--r--src/bin/test_win_keygrab.c243
-rw-r--r--src/lib/elm_win.c37
-rw-r--r--src/lib/elm_win.eo50
5 files changed, 333 insertions, 0 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 1b917956a..3d0a990a9 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -124,6 +124,7 @@ test_video.c \
124test_weather.c \ 124test_weather.c \
125test_web.c \ 125test_web.c \
126test_win_inline.c \ 126test_win_inline.c \
127test_win_keygrab.c \
127test_win_socket.c \ 128test_win_socket.c \
128test_win_plug.c \ 129test_win_plug.c \
129test_win_state.c \ 130test_win_state.c \
diff --git a/src/bin/test.c b/src/bin/test.c
index 3a747678d..2af370655 100644
--- a/src/bin/test.c
+++ b/src/bin/test.c
@@ -215,6 +215,7 @@ void test_store(void *data, Evas_Object *obj, void *event_info);
215void test_sys_notify(void *data, Evas_Object *obj, void *event_info); 215void test_sys_notify(void *data, Evas_Object *obj, void *event_info);
216void test_systray(void *data, Evas_Object *obj, void *event_info); 216void test_systray(void *data, Evas_Object *obj, void *event_info);
217void test_win_inline(void *data, Evas_Object *obj, void *event_info); 217void test_win_inline(void *data, Evas_Object *obj, void *event_info);
218void test_win_keygrab(void *data, Evas_Object *obj, void *event_info);
218void test_win_socket(void *data, Evas_Object *obj, void *event_info); 219void test_win_socket(void *data, Evas_Object *obj, void *event_info);
219void test_win_plug(void *data, Evas_Object *obj, void *event_info); 220void test_win_plug(void *data, Evas_Object *obj, void *event_info);
220void test_win_wm_rotation(void *data, Evas_Object *obj, void *event_info); 221void test_win_wm_rotation(void *data, Evas_Object *obj, void *event_info);
@@ -538,6 +539,7 @@ add_tests:
538 ADD_TEST(NULL, "Window / Background", "Window Plug", test_win_plug); 539 ADD_TEST(NULL, "Window / Background", "Window Plug", test_win_plug);
539 ADD_TEST(NULL, "Window / Background", "Window WM Rotation", test_win_wm_rotation); 540 ADD_TEST(NULL, "Window / Background", "Window WM Rotation", test_win_wm_rotation);
540 ADD_TEST(NULL, "Window / Background", "Window Standard/Dialog", test_win_dialog); 541 ADD_TEST(NULL, "Window / Background", "Window Standard/Dialog", test_win_dialog);
542 ADD_TEST(NULL, "Window / Background", "Window Keygrab Set", test_win_keygrab);
541 543
542 //------------------------------// 544 //------------------------------//
543 ADD_TEST(NULL, "Images", "Icon", test_icon); 545 ADD_TEST(NULL, "Images", "Icon", test_icon);
diff --git a/src/bin/test_win_keygrab.c b/src/bin/test_win_keygrab.c
new file mode 100644
index 000000000..0bc476bbb
--- /dev/null
+++ b/src/bin/test_win_keygrab.c
@@ -0,0 +1,243 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4#include <Elementary.h>
5
6
7struct _api_data
8{
9 Evas_Object *win;
10 Elm_Win_Keygrab_Mode mode; /* Mode of keygr */
11 char keyname[PATH_MAX]; /* Keyname */
12};
13
14typedef struct _api_data api_data;
15
16static void
17_rdg_changed_cb(void *data EINA_UNUSED, Evas_Object *obj,
18 void *event_info EINA_UNUSED)
19{
20 int mode = -1;
21 Elm_Win_Keygrab_Mode keygrab_mode = ELM_WIN_KEYGRAB_UNKNOWN;
22 api_data *api = data;
23
24 mode = elm_radio_value_get(obj);
25 printf("radio group value : %d\n", mode);
26
27 if (mode == 1)
28 {
29 keygrab_mode = ELM_WIN_KEYGRAB_SHARED;
30 printf("keygrab mode = ELM_WIN_KEYGRAB_SHARED\n");
31 }
32 else if (mode == 2)
33 {
34 keygrab_mode = ELM_WIN_KEYGRAB_TOPMOST;
35 printf("keygrab mode = ELM_WIN_KEYGRAB_TOPMOST\n");
36 }
37 else if (mode == 3)
38 {
39 keygrab_mode = ELM_WIN_KEYGRAB_EXCLUSIVE;
40 printf("keygrab mode = ELM_WIN_KEYGRAB_EXCLUSIVE\n");
41 }
42 else if (mode == 4)
43 {
44 keygrab_mode = ELM_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE;
45 printf("keygrab mode = ELM_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE\n");
46 }
47 else
48 {
49 keygrab_mode = ELM_WIN_KEYGRAB_UNKNOWN;
50 printf("keygrab mode = ELM_WIN_KEYGRAB_UNKNOWN\n");
51 }
52 api->mode = keygrab_mode;
53}
54
55static void
56_entry_changed_cb(void *data , Evas_Object *obj, void *event_info EINA_UNUSED)
57{
58 api_data *api = data;
59 const char *str = elm_entry_entry_get(obj);
60 if (!str) return;
61 strcpy(api->keyname, str);
62 printf("entry: %s\n",str);
63}
64
65static void
66_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
67{
68 if (data)
69 free(data);
70}
71
72static void
73_set_bt_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
74{
75 Eina_Bool ret = EINA_FALSE;
76 api_data *api = data;
77
78 ret = elm_win_keygrab_set(api->win, api->keyname, 0, 0, 0, api->mode);
79 printf("Keyname:\"%s\" mode:\"%d\" keygrab set. ret=%d\n", api->keyname, api->mode, ret);
80}
81
82static void
83_unset_bt_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
84{
85 Eina_Bool ret = EINA_FALSE;
86 api_data *api = data;
87
88 ret = elm_win_keygrab_unset(api->win, api->keyname, 0, 0);
89 printf("Keyname:\"%s\" mode:\"%d\" keygrab unset. ret=%d.\n", api->keyname, api->mode, ret);
90}
91
92static void
93_group_1_create(Evas_Object *bx, api_data *api)
94{
95 Evas_Object *bx2, *fr, *lb, *en;
96
97 fr = elm_frame_add(bx);
98 elm_object_text_set(fr, "Keygrab Keyname");
99 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
101 elm_box_pack_end(bx, fr);
102 evas_object_show(fr);
103
104 bx2 = elm_box_add(fr);
105 elm_object_content_set(fr, bx2);
106 evas_object_show(bx2);
107
108 lb = elm_label_add(bx2);
109 elm_object_text_set(lb, " Keyname :");
110 evas_object_size_hint_weight_set(lb, 0.0, EVAS_HINT_EXPAND);
111 evas_object_size_hint_align_set(lb, 0.0, EVAS_HINT_FILL);
112 elm_box_pack_end(bx2, lb);
113 evas_object_show(lb);
114
115 en = elm_entry_add(bx2);
116 elm_entry_single_line_set(en, EINA_TRUE);
117 elm_entry_scrollable_set(en, EINA_TRUE);
118 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
120 evas_object_smart_callback_add(en, "changed,user", _entry_changed_cb, api);
121 elm_box_pack_end(bx2, en);
122 evas_object_show(en);
123 elm_object_focus_set(en, EINA_TRUE);
124
125
126}
127
128static void
129_group_2_create(Evas_Object *bx, api_data *api)
130{
131 Evas_Object *bx2, *fr, *rd, *rd1, *rd2, *rd3;
132
133 fr = elm_frame_add(bx);
134 elm_object_text_set(fr, "Keygrab Mode");
135 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
137 elm_box_pack_end(bx, fr);
138 evas_object_show(fr);
139
140 bx2 = elm_box_add(fr);
141 elm_object_content_set(fr, bx2);
142 elm_box_align_set(bx2, 0.0, 0.0);
143 evas_object_show(bx2);
144
145 // Shared
146 rd = elm_radio_add(bx2);
147 elm_radio_state_value_set(rd, 1);
148 evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, 0.0);
149 evas_object_size_hint_align_set(rd, EVAS_HINT_FILL, 0.5);
150 elm_object_text_set(rd, "Keygrab Shared Mode");
151 elm_box_pack_end(bx2, rd);
152 evas_object_show(rd);
153 evas_object_smart_callback_add(rd, "changed", _rdg_changed_cb, api);
154
155 // Topmost
156 rd1 = elm_radio_add(bx2);
157 elm_radio_state_value_set(rd1, 2);
158 evas_object_size_hint_weight_set(rd1, EVAS_HINT_EXPAND, 0.0);
159 evas_object_size_hint_align_set(rd1, EVAS_HINT_FILL, 0.5);
160 elm_object_text_set(rd1, "Keygrab Topmost Mode");
161 elm_radio_group_add(rd1, rd);
162 elm_box_pack_end(bx2, rd1);
163 evas_object_show(rd1);
164 evas_object_smart_callback_add(rd1, "changed", _rdg_changed_cb, api);
165
166 // Exclusive
167 rd2 = elm_radio_add(bx2);
168 elm_radio_state_value_set(rd2, 3);
169 evas_object_size_hint_weight_set(rd2, EVAS_HINT_EXPAND, 0.0);
170 evas_object_size_hint_align_set(rd2, EVAS_HINT_FILL, 0.5);
171 elm_object_text_set(rd2, "Keygrab Exclusive Mode");
172 elm_radio_group_add(rd2, rd);
173 elm_box_pack_end(bx2, rd2);
174 evas_object_show(rd2);
175 evas_object_smart_callback_add(rd2, "changed", _rdg_changed_cb, api);
176
177 //Override Exclusive
178 rd3 = elm_radio_add(bx2);
179 elm_radio_state_value_set(rd3, 4);
180 evas_object_size_hint_weight_set(rd3, EVAS_HINT_EXPAND, 0.0);
181 evas_object_size_hint_align_set(rd3, EVAS_HINT_FILL, 0.5);
182 elm_object_text_set(rd3, "Keygrab Override Exclusive Mode");
183 elm_radio_group_add(rd3, rd);
184 elm_box_pack_end(bx2, rd3);
185 evas_object_show(rd3);
186 evas_object_smart_callback_add(rd3, "changed", _rdg_changed_cb, api);
187}
188
189static void
190_group_3_create(Evas_Object *bx, api_data *api)
191{
192 Evas_Object *bt;
193
194 bt = elm_button_add(bx);
195 elm_object_text_set(bt, "Keygrab Set");
196 elm_box_pack_end(bx, bt);
197
198 evas_object_smart_callback_add(bt, "clicked", _set_bt_clicked, api);
199 evas_object_show(bt);
200
201
202 bt = elm_button_add(bx);
203 elm_object_text_set(bt, "Keygrab Unset");
204 elm_box_pack_end(bx, bt);
205 evas_object_smart_callback_add(bt, "clicked", _unset_bt_clicked, api);
206 evas_object_show(bt);
207}
208
209void
210test_win_keygrab(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
211 void *event_info EINA_UNUSED)
212{
213 Evas_Object *win, *bx, *bx1, *bx2;
214
215 api_data *api = calloc(1, sizeof(api_data));
216
217 win = elm_win_util_standard_add("keygrab", "Keygrab");
218 elm_win_autodel_set(win, EINA_TRUE);
219 evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
220
221 bx = elm_box_add(win);
222 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
223 elm_win_resize_object_add(win, bx);
224 evas_object_show(bx);
225
226 bx1 = elm_box_add(win);
227 evas_object_size_hint_weight_set(bx1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
228 elm_box_pack_end(bx, bx1);
229 elm_box_horizontal_set(bx1, EINA_TRUE);
230 evas_object_show(bx1);
231
232 bx2 = elm_box_add(win);
233 evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
234 elm_box_pack_end(bx, bx2);
235 elm_box_horizontal_set(bx2, EINA_TRUE);
236 evas_object_show(bx2);
237
238 _group_1_create(bx1, api);
239 _group_2_create(bx1, api);
240 _group_3_create(bx2, api);
241
242 evas_object_show(win);
243}
diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c
index cc7fb34e2..556030ed5 100644
--- a/src/lib/elm_win.c
+++ b/src/lib/elm_win.c
@@ -5011,6 +5011,43 @@ _elm_win_illume_command_send(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Illume_C
5011#endif 5011#endif
5012} 5012}
5013 5013
5014EOLIAN static Eina_Bool
5015_elm_win_keygrab_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *key, Evas_Modifier_Mask modifiers EINA_UNUSED, Evas_Modifier_Mask not_modifiers EINA_UNUSED, int priority EINA_UNUSED, Elm_Win_Keygrab_Mode grab_mode)
5016{
5017 Eina_Bool ret = EINA_FALSE;
5018#ifdef HAVE_ELEMENTARY_X
5019 _internal_elm_win_xwindow_get(sd);
5020 if (sd->x.xwin)
5021 {
5022 if (grab_mode == ELM_WIN_KEYGRAB_SHARED)
5023 ret = ecore_x_window_keygrab_set(sd->x.xwin, key, 0, 0, 0, ECORE_X_WIN_KEYGRAB_SHARED);
5024 else if (grab_mode == ELM_WIN_KEYGRAB_TOPMOST)
5025 ret = ecore_x_window_keygrab_set(sd->x.xwin, key, 0, 0, 0, ECORE_X_WIN_KEYGRAB_TOPMOST);
5026 else if (grab_mode == ELM_WIN_KEYGRAB_EXCLUSIVE)
5027 ret = ecore_x_window_keygrab_set(sd->x.xwin, key, 0, 0, 0, ECORE_X_WIN_KEYGRAB_EXCLUSIVE);
5028 else if (grab_mode == ELM_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE)
5029 ret = ecore_x_window_keygrab_set(sd->x.xwin, key, 0, 0, 0, ECORE_X_WIN_KEYGRAB_EXCLUSIVE);
5030 }
5031 return ret;
5032#else
5033 return ret;
5034#endif
5035}
5036
5037EOLIAN static Eina_Bool
5038_elm_win_keygrab_unset(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *key, Evas_Modifier_Mask modifiers EINA_UNUSED, Evas_Modifier_Mask not_modifiers EINA_UNUSED)
5039{
5040 Eina_Bool ret = EINA_FALSE;
5041#ifdef HAVE_ELEMENTARY_X
5042 _internal_elm_win_xwindow_get(sd);
5043 if (sd->x.xwin)
5044 ret = ecore_x_window_keygrab_unset(sd->x.xwin, key, 0, 0);
5045 return ret;
5046#else
5047 return ret;
5048#endif
5049}
5050
5014EOLIAN static Evas_Object* 5051EOLIAN static Evas_Object*
5015_elm_win_inlined_image_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd) 5052_elm_win_inlined_image_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5016{ 5053{
diff --git a/src/lib/elm_win.eo b/src/lib/elm_win.eo
index 4d5d5163d..34cc83743 100644
--- a/src/lib/elm_win.eo
+++ b/src/lib/elm_win.eo
@@ -138,6 +138,26 @@ enum Elm.Win.Indicator_Opacity_Mode
138 transparent /*@ Transparentizes the indicator */ 138 transparent /*@ Transparentizes the indicator */
139} 139}
140 140
141/**
142 */
143enum Elm.Win.Keygrab_Mode
144{
145 /*@
146 Define the keygrab modes of window.
147 A window may send commands to the Keyrouter according this mode,
148 and perform different actions.
149
150 @ingroup Win */
151
152 legacy: elm_win_keygrab;
153
154 unknown = 0, /*@ Unknown keygrab mode */
155 shared = (1 << 8), /*@ Getting the grabbed-key together with the other client windows */
156 topmost = (1 << 9), /*@ Getting the grabbed-key only when window is top of the stack */
157 exclusive = (1 << 10), /*@ Getting the grabbed-key exclusively regardless of window's position */
158 override_exclusive = (1 << 11) /*@ Getting the grabbed-key exclusively regardless of window's position. Being overrided the grab by the other client window */
159}
160
141enum Elm.Illume_Command 161enum Elm.Illume_Command
142{ 162{
143 /*@ 163 /*@
@@ -1551,6 +1571,36 @@ class Elm.Win (Elm.Widget, Elm_Interface_Atspi_Window,
1551 @in bool v; /*@ If true, center vertically. If false, do not change vertical location. */ 1571 @in bool v; /*@ If true, center vertically. If false, do not change vertical location. */
1552 } 1572 }
1553 } 1573 }
1574 keygrab_set {
1575 /*@
1576 Set keygrab value of the window
1577
1578 This function grabs the @p key of window using @p grab_mode.
1579 @ingroup Win */
1580
1581 return: bool;
1582 params {
1583 @in const(char)* key; /*@ This string is the keyname to grab. */
1584 @in Evas_Modifier_Mask modifiers; /*@ This is for the keymask feature. Currently this feature is not supported. */
1585 @in Evas_Modifier_Mask not_modifiers; /*@ This is for the keymask feature. Currently this feature is not supported. */
1586 @in int proirity; /*@ This is for the priority of keygrab. Currently this feature is not supported. */
1587 @in Elm_Win_Keygrab_Mode grab_mode; /*@ According to the grabmode, it can grab key differently */
1588 }
1589 }
1590 keygrab_unset {
1591 /*@
1592 Unset keygrab value of the window
1593
1594 This function unset keygrab value. Ungrab @p key of window.
1595 @ingroup Win */
1596
1597 return: bool;
1598 params {
1599 @in const(char)* key; /*@ This string is the keyname to grab. */
1600 @in Evas_Modifier_Mask modifiers; /*@ This is for the keymask feature. Currently this feature is not supported. */
1601 @in Evas_Modifier_Mask not_modifiers; /*@ This is for the keymask feature. Currently this feature is not supported. */
1602 }
1603 }
1554 } 1604 }
1555 implements { 1605 implements {
1556 class.constructor; 1606 class.constructor;