summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-09-07 11:00:20 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2015-09-07 11:00:20 +0200
commit240a275be0d81cd692169bd9b549f8248afb6f13 (patch)
treecc4f49da3d783ea21ba86da49d42bdb694cc45c9 /src/examples
parent99c0c1cb620fa9de87b6efb39077c5507df4fbdb (diff)
ecore_example: Cleanup of ecore_compose_get_example.c
Summary: Relating to D3010. This patch is code cleanup. Have done dos2unix. After this will update D3010 bug. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric, stefan_schmidt Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D3025
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/ecore/ecore_compose_get_example.c384
1 files changed, 192 insertions, 192 deletions
diff --git a/src/examples/ecore/ecore_compose_get_example.c b/src/examples/ecore/ecore_compose_get_example.c
index f9b45cfe86..4359cb07dc 100644
--- a/src/examples/ecore/ecore_compose_get_example.c
+++ b/src/examples/ecore/ecore_compose_get_example.c
@@ -1,192 +1,192 @@
1/* gcc -g -Wall -o test_keys2 test_keys2.c `pkg-config --cflags --libs ecore-input ecore-evas ecore evas eina` */ 1/* gcc -g -Wall -o test_keys2 test_keys2.c `pkg-config --cflags --libs ecore-input ecore-evas ecore evas eina` */
2 2
3#include <stdio.h> 3#include <stdio.h>
4 4
5#include <Eina.h> 5#include <Eina.h>
6#include <Evas.h> 6#include <Evas.h>
7#include <Ecore.h> 7#include <Ecore.h>
8#include <Ecore_Evas.h> 8#include <Ecore_Evas.h>
9 9
10/******* begin 1 : Ecore compose stuff *******/ 10/******* begin 1 : Ecore compose stuff *******/
11 11
12#include <Ecore_Input.h> 12#include <Ecore_Input.h>
13 13
14typedef struct 14typedef struct
15{ 15{
16 Eina_List *seq; 16 Eina_List *seq;
17 Eina_Bool composing; 17 Eina_Bool composing;
18} Data; 18} Data;
19 19
20static void 20static void
21_data_reset(Data *d) 21_data_reset(Data *d)
22{ 22{
23 char *str; 23 char *str;
24 24
25 EINA_LIST_FREE(d->seq, str) eina_stringshare_del(str); 25 EINA_LIST_FREE(d->seq, str) eina_stringshare_del(str);
26 d->composing = EINA_FALSE; 26 d->composing = EINA_FALSE;
27} 27}
28 28
29static Eina_Bool 29static Eina_Bool
30_is_modifier(const char *key) 30_is_modifier(const char *key)
31{ 31{
32 if ((!strncmp(key, "Shift", 5)) || 32 if ((!strncmp(key, "Shift", 5)) ||
33 (!strncmp(key, "Control", 7)) || 33 (!strncmp(key, "Control", 7)) ||
34 (!strncmp(key, "Alt", 3)) || 34 (!strncmp(key, "Alt", 3)) ||
35 (!strncmp(key, "Meta", 4)) || 35 (!strncmp(key, "Meta", 4)) ||
36 (!strncmp(key, "Super", 5)) || 36 (!strncmp(key, "Super", 5)) ||
37 (!strncmp(key, "Hyper", 5)) || 37 (!strncmp(key, "Hyper", 5)) ||
38 (!strcmp(key, "Scroll_Lock")) || 38 (!strcmp(key, "Scroll_Lock")) ||
39 (!strcmp(key, "Num_Lock")) || 39 (!strcmp(key, "Num_Lock")) ||
40 (!strcmp(key, "Caps_Lock"))) 40 (!strcmp(key, "Caps_Lock")))
41 return EINA_TRUE; 41 return EINA_TRUE;
42 return EINA_FALSE; 42 return EINA_FALSE;
43} 43}
44 44
45/******* end 1 : Ecore compose stuff *******/ 45/******* end 1 : Ecore compose stuff *******/
46 46
47static void 47static void
48_key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event) 48_key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
49{ 49{
50 Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event; 50 Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event;
51 int alt; 51 int alt;
52 int shift; 52 int shift;
53 int ctrl; 53 int ctrl;
54 54
55 alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); 55 alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
56 shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); 56 shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
57 ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); 57 ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
58 58
59 printf("down : keyname: %s key: %s compose: **%s** string: **%s** [%zu] %d (%d:%d:%d)\n", 59 printf("down : keyname: %s key: %s compose: **%s** string: **%s** [%zu] %d (%d:%d:%d)\n",
60 ev->keyname, ev->key, ev->string, ev->compose, (ev->compose) ? strlen(ev->compose) : (size_t)-1, (ev->compose) ? *(ev->compose) : -1, 60 ev->keyname, ev->key, ev->string, ev->compose, (ev->compose) ? strlen(ev->compose) : (size_t)-1, (ev->compose) ? *(ev->compose) : -1,
61 alt, shift, ctrl); 61 alt, shift, ctrl);
62} 62}
63 63
64static void 64static void
65_key_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event) 65_key_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
66{ 66{
67 Evas_Event_Key_Up *ev; 67 Evas_Event_Key_Up *ev;
68 int alt; 68 int alt;
69 int shift; 69 int shift;
70 int ctrl; 70 int ctrl;
71 71
72 ev = (Evas_Event_Key_Up *)event; 72 ev = (Evas_Event_Key_Up *)event;
73 73
74 alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); 74 alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
75 shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); 75 shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
76 ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); 76 ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
77 77
78 printf("up : keyname: %s key: %s string: %s %d (%d:%d:%d)\n", 78 printf("up : keyname: %s key: %s string: %s %d (%d:%d:%d)\n",
79 ev->keyname, ev->key, ev->compose, (ev->compose) ? *(ev->compose) : -1, 79 ev->keyname, ev->key, ev->compose, (ev->compose) ? *(ev->compose) : -1,
80 alt, shift, ctrl); 80 alt, shift, ctrl);
81 81
82 if (!alt && !shift) 82 if (!alt && !shift)
83 { 83 {
84 if (!strcmp(ev->key, "q")) 84 if (!strcmp(ev->key, "q"))
85 ecore_main_loop_quit(); 85 ecore_main_loop_quit();
86 } 86 }
87 87
88/******* begin 2 : Ecore compose stuff *******/ 88/******* begin 2 : Ecore compose stuff *******/
89 89
90 { 90 {
91 Data *d; 91 Data *d;
92 char *compres = NULL; 92 char *compres = NULL;
93 char *string = NULL; 93 char *string = NULL;
94 Ecore_Compose_State state; 94 Ecore_Compose_State state;
95 Eina_Bool free_string = EINA_FALSE; 95 Eina_Bool free_string = EINA_FALSE;
96 96
97 d = (Data *)data; 97 d = (Data *)data;
98 if (!d->composing) 98 if (!d->composing)
99 { 99 {
100 _data_reset(d); 100 _data_reset(d);
101 d->seq = eina_list_append(d->seq, eina_stringshare_add(ev->key)); 101 d->seq = eina_list_append(d->seq, eina_stringshare_add(ev->key));
102 state = ecore_compose_get(d->seq, &compres); 102 state = ecore_compose_get(d->seq, &compres);
103 if (state == ECORE_COMPOSE_MIDDLE) d->composing = EINA_TRUE; 103 if (state == ECORE_COMPOSE_MIDDLE) d->composing = EINA_TRUE;
104 else d->composing = EINA_FALSE; 104 else d->composing = EINA_FALSE;
105 if (!d->composing) _data_reset(d); 105 if (!d->composing) _data_reset(d);
106 else goto end; 106 else goto end;
107 } 107 }
108 else 108 else
109 { 109 {
110 if (_is_modifier(ev->key)) goto end; 110 if (_is_modifier(ev->key)) goto end;
111 d->seq = eina_list_append(d->seq, eina_stringshare_add(ev->key)); 111 d->seq = eina_list_append(d->seq, eina_stringshare_add(ev->key));
112 state = ecore_compose_get(d->seq, &compres); 112 state = ecore_compose_get(d->seq, &compres);
113 if (state == ECORE_COMPOSE_NONE) _data_reset(d); 113 if (state == ECORE_COMPOSE_NONE) _data_reset(d);
114 else if (state == ECORE_COMPOSE_DONE) 114 else if (state == ECORE_COMPOSE_DONE)
115 { 115 {
116 _data_reset(d); 116 _data_reset(d);
117 if (compres) 117 if (compres)
118 { 118 {
119 string = compres; 119 string = compres;
120 free_string = EINA_TRUE; 120 free_string = EINA_TRUE;
121 } 121 }
122 } 122 }
123 else goto end; 123 else goto end;
124 } 124 }
125 125
126 if (string) 126 if (string)
127 { 127 {
128 printf(" ** string : %s %zu 0x%hhx%hhX\n", string, strlen(string), string[1], string[0]); 128 printf(" ** string : %s %zu 0x%hhx%hhX\n", string, strlen(string), string[1], string[0]);
129 if (free_string) 129 if (free_string)
130 free(string); 130 free(string);
131 } 131 }
132 } 132 }
133 133
134/******* end 2 : Ecore compose stuff *******/ 134/******* end 2 : Ecore compose stuff *******/
135 135
136 end: 136 end:
137 return; 137 return;
138} 138}
139 139
140static void 140static void
141_del(Ecore_Evas *ee EINA_UNUSED) 141_del(Ecore_Evas *ee EINA_UNUSED)
142{ 142{
143 ecore_main_loop_quit(); 143 ecore_main_loop_quit();
144} 144}
145 145
146int main() 146int main()
147{ 147{
148 Ecore_Evas *ee; 148 Ecore_Evas *ee;
149 Evas *evas; 149 Evas *evas;
150 Evas_Object *o; 150 Evas_Object *o;
151 151
152/******* begin 3 : Ecore compose stuff *******/ 152/******* begin 3 : Ecore compose stuff *******/
153 Data *d; 153 Data *d;
154 154
155 d = calloc(1, sizeof(Data)); 155 d = calloc(1, sizeof(Data));
156 156
157 if (!ecore_event_init()) 157 if (!ecore_event_init())
158 return 0; 158 return 0;
159 159
160/******* end 3 : Ecore compose stuff *******/ 160/******* end 3 : Ecore compose stuff *******/
161 161
162 if (!ecore_evas_init()) 162 if (!ecore_evas_init())
163 return 0; 163 return 0;
164 164
165 ee = ecore_evas_new(NULL, 10, 10, 0, 0, NULL); 165 ee = ecore_evas_new(NULL, 10, 10, 0, 0, NULL);
166 if (!ee) 166 if (!ee)
167 return -1; 167 return -1;
168 ecore_evas_callback_delete_request_set(ee, _del); 168 ecore_evas_callback_delete_request_set(ee, _del);
169 169
170 evas = ecore_evas_get(ee); 170 evas = ecore_evas_get(ee);
171 171
172 o = evas_object_rectangle_add(evas); 172 o = evas_object_rectangle_add(evas);
173 evas_object_color_set(o, 255, 0, 0, 255); 173 evas_object_color_set(o, 255, 0, 0, 255);
174 evas_object_move(o, 0, 0); 174 evas_object_move(o, 0, 0);
175 evas_object_resize(o, 480, 480); 175 evas_object_resize(o, 480, 480);
176 evas_object_focus_set(o, EINA_TRUE); 176 evas_object_focus_set(o, EINA_TRUE);
177 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, 177 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN,
178 _key_down_cb, d); 178 _key_down_cb, d);
179 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_UP, 179 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_UP,
180 _key_up_cb, d); 180 _key_up_cb, d);
181 evas_object_show(o); 181 evas_object_show(o);
182 182
183 ecore_evas_resize(ee, 480, 480); 183 ecore_evas_resize(ee, 480, 480);
184 ecore_evas_show(ee); 184 ecore_evas_show(ee);
185 185
186 ecore_main_loop_begin(); 186 ecore_main_loop_begin();
187 187
188 ecore_event_shutdown(); 188 ecore_event_shutdown();
189 ecore_evas_shutdown(); 189 ecore_evas_shutdown();
190 190
191 return 0; 191 return 0;
192} 192}