Packaging: Update version up to tz9_17.0.0
[platform/upstream/enlightenment.git] / src / bin / e_input_thread_client.c
1 #include "e_input_thread_client_intern.h"
2 #include "e_comp_canvas.h"
3 #include "e_comp_input_intern.h"
4
5 struct _E_Input_Thread_Client
6 {
7    EINA_INLIST;
8    void *ec;
9    struct wl_resource *surface;
10    E_Layer layer;
11    E_Visibility visibility;
12    Eina_Bool layer_block;
13    Eina_Bool layer_pending;
14    Eina_Bool is_video;
15    Eina_Bool deleted;
16    Eina_Bool is_cursor;
17    Eina_Stringshare *icccm_name;
18    Eina_Stringshare *netwm_name;
19    Eina_Stringshare *icccm_title;
20 };
21
22 static Eina_List *_itc_list = NULL;
23
24 ///////////////////////////////////////////
25 EINTERN void
26 e_input_thread_client_init()
27 {
28
29 }
30
31 EINTERN void
32 e_input_thread_client_shutdown()
33 {
34    if (_itc_list)
35      eina_list_free(_itc_list);
36
37    _itc_list = NULL;
38 }
39
40 EINTERN E_Input_Thread_Client *
41 e_input_thread_client_new(E_Client *ec, struct wl_resource *surface)
42 {
43    E_Input_Thread_Client *itc = E_NEW(E_Input_Thread_Client, 1);
44    EINA_SAFETY_ON_NULL_RETURN_VAL(itc, NULL);
45
46    itc->ec = ec;
47    itc->surface = surface;
48    itc->layer = E_LAYER_CLIENT_NORMAL;
49    itc->visibility = E_VISIBILITY_UNKNOWN;
50
51    _itc_list = eina_list_append(_itc_list, itc);
52    INF("[%s] iec(%p), ec(%p), surface(%p)\n", __func__, itc, ec, surface);
53
54    return itc;
55 }
56
57 EINTERN void
58 e_input_thread_client_free(E_Input_Thread_Client *iec)
59 {
60    EINA_SAFETY_ON_NULL_RETURN(iec);
61
62    INF("[%s] iec(%p), ec(%p)", __func__, iec, iec->ec);
63
64    _itc_list = eina_list_remove(_itc_list, iec);
65
66    E_FREE(iec);
67 }
68
69 EINTERN void
70 e_input_thread_client_del(E_Input_Thread_Client *iec)
71 {
72    EINA_SAFETY_ON_NULL_RETURN(iec);
73
74    INF("[%s] iec(%p), ec(%p)", __func__, iec, iec->ec);
75    iec->deleted = 1;
76 }
77
78 EINTERN void
79 e_input_thread_client_visibility_set(E_Input_Thread_Client *iec, E_Visibility visibility)
80 {
81    EINA_SAFETY_ON_NULL_RETURN(iec);
82
83    iec->visibility = visibility;
84    INF("[%s] iec(%p), ec(%p), visibility(%d)\n", __func__, iec, iec->ec, visibility);
85 }
86
87 E_API E_Visibility
88 e_input_thread_client_visibility_get(E_Input_Thread_Client *iec)
89 {
90    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, E_VISIBILITY_UNKNOWN);
91
92    return iec->visibility;
93 }
94
95 E_API Eina_Bool
96 e_input_thread_client_video_mode_get(E_Input_Thread_Client *iec)
97 {
98    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, EINA_FALSE);
99
100    return iec->is_video;
101 }
102
103 EINTERN void
104 e_input_thread_client_video_set(E_Input_Thread_Client *iec, Eina_Bool is_video)
105 {
106    EINA_SAFETY_ON_NULL_RETURN(iec);
107
108    iec->is_video = is_video;
109    INF("[%s] iec(%p), ec(%p), video(%d)\n", __func__, iec, iec->ec, is_video);
110 }
111
112 E_API Eina_Bool
113 e_input_thread_client_visible_get(E_Input_Thread_Client *iec)
114 {
115    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, EINA_FALSE);
116
117    return iec->visibility;
118 }
119
120 EINTERN void
121 e_input_thread_client_icccm_name_set(E_Input_Thread_Client *iec, char *name)
122 {
123    EINA_SAFETY_ON_NULL_RETURN(iec);
124
125    eina_stringshare_replace(&iec->icccm_name, name);
126    INF("[%s] iec(%p), ec(%p), name(%s)\n", __func__, iec, iec->ec, name);
127 }
128
129 E_API Eina_Stringshare *
130 e_input_thread_client_icccm_name_get(E_Input_Thread_Client *iec)
131 {
132    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
133
134    return iec->icccm_name;
135 }
136
137 EINTERN void
138 e_input_thread_client_icccm_title_set(E_Input_Thread_Client *iec, char *title)
139 {
140    EINA_SAFETY_ON_NULL_RETURN(iec);
141
142    eina_stringshare_replace(&iec->icccm_title, title);
143
144    INF("[%s] iec(%p), ec(%p), title(%s)\n", __func__, iec, iec->ec, title);
145 }
146
147 E_API Eina_Stringshare *
148 e_input_thread_client_icccm_title_get(E_Input_Thread_Client *iec)
149 {
150    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
151
152    return iec->icccm_title;
153 }
154
155 EINTERN void
156 e_input_thread_client_netwm_name_set(E_Input_Thread_Client *iec, char *name)
157 {
158    EINA_SAFETY_ON_NULL_RETURN(iec);
159
160    eina_stringshare_replace(&iec->icccm_name, name);
161
162    INF("[%s] iec(%p), ec(%p), name(%s)\n", __func__, iec, iec->ec, name);
163 }
164
165 E_API Eina_Stringshare *
166 e_input_thread_client_netwm_name_get(E_Input_Thread_Client *iec)
167 {
168    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
169
170    return iec->icccm_name;
171 }
172
173 E_API Eina_Stringshare *
174 e_input_thread_client_util_name_get(E_Input_Thread_Client *iec)
175 {
176    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
177
178    if (iec->netwm_name)
179      return iec->netwm_name;
180    else if (iec->icccm_title)
181      return iec->icccm_title;
182
183    return NULL;
184 }
185
186 E_API Eina_Bool e_input_thread_client_cursor_mode_get(E_Input_Thread_Client *iec)
187 {
188    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, EINA_FALSE);
189
190    return iec->is_cursor;
191 }
192
193 EINTERN void e_input_thread_client_layer_set(E_Input_Thread_Client *iec, E_Layer layer)
194 {
195    EINA_SAFETY_ON_NULL_RETURN(iec);
196
197    iec->layer = layer;
198    INF("[%s] iec(%p), ec(%p), layer(%d)\n", __func__, iec, iec->ec, layer);
199 }
200
201 EINTERN void e_input_thread_client_layer_block_set(E_Input_Thread_Client *iec, Eina_Bool block)
202 {
203    EINA_SAFETY_ON_NULL_RETURN(iec);
204
205    iec->layer_block = block;
206    INF("[%s] iec(%p), ec(%p), layer_block(%d)\n", __func__, iec, iec->ec, iec->layer_block);
207 }
208
209 EINTERN void e_input_thread_client_layer_pending_set(E_Input_Thread_Client *iec, Eina_Bool pending)
210 {
211    EINA_SAFETY_ON_NULL_RETURN(iec);
212
213    iec->layer_pending = pending;
214    INF("[%s] iec(%p), ec(%p), layer_pending(%d)\n", __func__, iec, iec->ec, iec->layer_pending);
215 }
216
217 EINTERN void e_input_thread_client_is_cursor_set(E_Input_Thread_Client *iec, Eina_Bool is_cursor)
218 {
219    EINA_SAFETY_ON_NULL_RETURN(iec);
220
221    iec->is_cursor = is_cursor;
222    INF("[%s] iec(%p), ec(%p), is_cursor(%d)\n", __func__, iec, iec->ec, iec->is_cursor);
223 }
224
225 EINTERN E_Input_Thread_Client * e_input_thread_client_get(E_Client *ec)
226 {
227    Eina_List *l;
228    void *list_data;
229    E_Input_Thread_Client *itc = NULL;
230
231    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, NULL);
232
233    EINA_LIST_FOREACH(_itc_list, l, list_data)
234      {
235         itc = (E_Input_Thread_Client *)list_data;
236         if (itc && itc->ec == ec)
237           return itc;
238      }
239
240    return NULL;
241 }
242
243 EINTERN Eina_Inlist * e_input_thread_client_Inlist_get(E_Client *ec)
244 {
245    E_Input_Thread_Client *iec = e_input_thread_client_get(ec);
246    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
247
248    return &(iec->__in_list);
249 }
250
251 E_API E_Input_Thread_Client *e_input_thread_client_above_get(E_Input_Thread_Client *iec)
252 {
253    unsigned int x;
254    E_Input_Thread_Client *iec2;
255
256    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
257    if (EINA_INLIST_GET(iec)->next) //check current layer
258      {
259         EINA_INLIST_FOREACH(EINA_INLIST_GET(iec)->next, iec2)
260           {
261              if (iec == iec2)
262                {
263                   INF("[%s] iec: %p\n", __func__, iec);
264                   continue;
265                }
266              if (!iec2->deleted)
267                return iec2;
268           }
269      }
270    if (iec->layer == E_LAYER_CLIENT_CURSOR) return NULL;
271    if (e_comp_canvas_client_layer_map(iec->layer) == 9999) return NULL;
272
273    for (x = e_comp_canvas_layer_map(iec->layer) + 1; x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
274      {
275         if (!e_comp_input->layers[x].clients) continue;
276         EINA_INLIST_FOREACH(e_comp_input->layers[x].clients, iec2)
277           {
278              if (iec == iec2)
279                {
280                   INF("EC exist above layer. ec layer_map:%d, cur layer_map:%d", e_comp_canvas_layer_map(iec->layer), x);
281                   continue;
282                }
283              if (!iec2->deleted)
284                {
285                   return iec2;
286                }
287           }
288      }
289
290    return NULL;
291 }
292
293 E_API E_Input_Thread_Client *e_input_thread_client_below_get(E_Input_Thread_Client *iec)
294 {
295    unsigned int x;
296    E_Input_Thread_Client *iec2;
297    Eina_Inlist *l;
298    E_Layer iec_layer, iec_layer_cw;
299    int cw_layer;
300
301    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
302    if (EINA_INLIST_GET(iec)->prev) //check current layer
303      {
304         for (l = EINA_INLIST_GET(iec)->prev; l; l = l->prev)
305           {
306              iec2 = EINA_INLIST_CONTAINER_GET(l, E_Input_Thread_Client);
307              if (iec == iec2)
308                {
309                   INF("CHECK the ec inlist prev");
310                   continue;
311                }
312              if (!iec2->deleted)
313                return iec2;
314           }
315      }
316
317    // check layer validation
318    iec_layer = iec->layer;
319    if (iec->layer_block || iec->layer_pending)
320      {
321         cw_layer = iec->layer;
322         if (cw_layer >= 0)
323           {
324              iec_layer_cw = e_comp_canvas_layer_map_to(cw_layer);
325              if (iec_layer != iec_layer_cw)
326                {
327                   INF("LAYER is not same. USE obj layer! (ec->layer:%d, obj:%d). block:%d, pending:%d)", iec_layer, iec_layer_cw, iec->layer_block, iec->layer_pending);
328                   iec_layer = iec_layer_cw;
329                }
330           }
331      }
332
333    if (iec_layer == E_LAYER_CLIENT_DESKTOP) return NULL;
334    if (e_comp_canvas_client_layer_map(iec_layer) == 9999) return NULL;
335
336    /* go down the layers until we find one */
337    x = e_comp_canvas_layer_map(iec_layer);
338    if (x > 0) x--;
339
340    for (; x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
341      {
342         if (!e_comp_input->layers[x].clients) continue;
343         EINA_INLIST_REVERSE_FOREACH(e_comp_input->layers[x].clients, iec2)
344           {
345              if (iec == iec2)
346                {
347                   INF("EC exist below layer. ec layer_map:%d, cur layer_map:%d", e_comp_canvas_layer_map(iec_layer), x);
348                   continue;
349                }
350              if (!iec2->deleted)
351                return iec2;
352           }
353      }
354
355    return NULL;
356 }
357
358 E_API E_Input_Thread_Client *e_input_thread_client_bottom_get()
359 {
360    unsigned int x;
361    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x <= e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x++)
362      {
363         E_Input_Thread_Client *iec2;
364         if (!e_comp_input->layers[x].clients) continue;
365
366         EINA_INLIST_FOREACH(e_comp_input->layers[x].clients, iec2)
367           if (!iec2->deleted)
368             return iec2;
369      }
370
371    return NULL;
372 }
373
374 E_API E_Input_Thread_Client *e_input_thread_client_top_get()
375 {
376    unsigned int x;
377    for (x = e_comp_canvas_layer_map(E_LAYER_CLIENT_CURSOR); x >= e_comp_canvas_layer_map(E_LAYER_CLIENT_DESKTOP); x--)
378      {
379         E_Input_Thread_Client *iec2;
380         if (!e_comp_input->layers[x].clients) continue;
381
382         EINA_INLIST_REVERSE_FOREACH(e_comp_input->layers[x].clients, iec2)
383           if (!iec2->deleted)
384             return iec2;
385      }
386
387    return NULL;
388 }
389
390 E_API E_Input_Thread_Client *e_input_thread_client_focused_get()
391 {
392    return e_input_thread_client_get(e_comp_input->focused_ec);
393 }
394
395 E_API E_Input_Thread_Client *e_input_thread_client_from_surface_resource(struct wl_resource *surface_resource)
396 {
397    Eina_List *l;
398    void *list_data;
399    E_Input_Thread_Client *itc = NULL;
400
401    EINA_SAFETY_ON_NULL_RETURN_VAL(surface_resource, NULL);
402
403    EINA_LIST_FOREACH(_itc_list, l, list_data)
404      {
405         itc = (E_Input_Thread_Client *)list_data;
406         if (itc && itc->surface == surface_resource)
407           return itc;
408      }
409
410    return NULL;
411 }
412
413 E_API struct wl_resource *e_input_thread_client_wl_resource_get(E_Input_Thread_Client *iec)
414 {
415    EINA_SAFETY_ON_NULL_RETURN_VAL(iec, NULL);
416
417    return iec->surface;
418 }