e_input: add E_API e_input_device_mouse_accel_enable_set(device_name, enable)
[platform/upstream/enlightenment.git] / src / bin / e_info_client.c
1 #include "e.h"
2 #include "e_info_shared_types.h"
3 #include "e_info_client_screen_recorder.h"
4 #include <time.h>
5 #include <dirent.h>
6 #include <sys/mman.h>
7
8 typedef void (*E_Info_Message_Cb)(const Eldbus_Message *msg);
9
10 typedef struct _E_Info_Client
11 {
12    /* eldbus */
13    int                eldbus_init;
14    Eldbus_Proxy      *proxy;
15    Eldbus_Connection *conn;
16    Eldbus_Object     *obj;
17
18    /* topvwins */
19    int                use_gl, use_hwc, use_multi_layer, hwc, hwc_windows;
20    int                use_buffer_flush, deiconify_approve;
21    int                config_engine;
22    const char        *engine;
23    Eina_List         *win_list;
24
25    /* output mode */
26    Eina_List         *mode_list;
27    int               gl;
28
29    /* pending_commit */
30    Eina_List         *pending_commit_list;
31
32    /* layer fps */
33    Eina_List         *fps_list;
34
35    /* dump_buffers */
36    const char *dump_fullpath;
37    Eina_Bool dump_success;
38
39    Eina_List *zone_list;
40 } E_Info_Client;
41
42 typedef struct _E_Zone_Info
43 {
44    int id;
45    int display_state;
46    int x, y, w, h;
47    Eina_Bool is_current;
48    int angle_cur;
49    int angle_active;
50 } E_Zone_Info;
51
52 typedef struct _E_Win_Info
53 {
54    Ecore_Window     id;         // native window id
55    uint32_t      res_id;
56    int           pid;
57    const char  *name;       // name of client window
58    int          x, y, w, h; // geometry
59    int          layer;      // value of E_Layer
60    int          vis;        // ec->visible
61    int          mapped;     // map state (ec->comp_data->mapped)
62    int          alpha;      // alpha window
63    int          opaque;
64    int          visibility; // visibillity
65    Eina_Bool    force_obscured;
66    int          iconic;
67    int          frame_visible;  //ec->frame obj visible get
68    int          focused;
69    int          hwc;        // hwc enable/disable
70    int          hwc_policy; // hwc policy
71    int          pl_zpos;    // hwc value : (hwc_windows: hwc window state) (hwc_planes: zpos of the plane)
72    Ecore_Window parent_id;
73    const char  *layer_name; // layer name
74    Eina_Bool has_input_region;
75    Eina_Bool    transformed;
76    E_Transient  transient_policy;
77    int          zone_id;
78    Eina_Bool    is_apply_layout;
79 } E_Win_Info;
80
81 typedef struct output_mode_info
82 {
83    unsigned int hdisplay, hsync_start, hsync_end, htotal;
84    unsigned int vdisplay, vsync_start, vsync_end, vtotal;
85    unsigned int refresh, vscan, clock;
86    unsigned int flags;
87    int current, output, connect, dpms;
88    const char *name;
89 } E_Info_Output_Mode;
90
91 typedef struct _E_Pending_Commit_Info
92 {
93    unsigned int plane;
94    int zpos;
95    unsigned int data;
96    unsigned int tsurface;
97 } E_Pending_Commit_Info;
98
99 typedef struct _E_Fps_Info
100 {
101    E_Info_Fps_Type type;
102    const char *output;
103    int zpos;
104    unsigned int window;
105    double fps;
106 } E_Fps_Info;
107
108 #define VALUE_TYPE_FOR_ZONE "iiiiiibii"
109 #define VALUE_TYPE_FOR_TOPVWINS "uuisiiiiibbbiibibbiiiusbbiib"
110 #define VALUE_TYPE_REQUEST_RESLIST "ui"
111 #define VALUE_TYPE_REPLY_RESLIST "ssu"
112 #define VALUE_TYPE_FOR_INPUTDEV "ssiss"
113 #define VALUE_TYPE_FOR_PENDING_COMMIT "uiuu"
114 #define VALUE_TYPE_FOR_FPS "usiud"
115 #define VALUE_TYPE_REQUEST_FOR_KILL "uts"
116 #define VALUE_TYPE_REPLY_KILL "s"
117 #define VALUE_TYPE_REQUEST_FOR_WININFO "t"
118 #define VALUE_TYPE_REPLY_WININFO "uiiiiiibbiibbbiitsiiib"
119 #define VALUE_TYPE_REQUEST_FOR_WININFO_TREE "ti"
120 #define VALUE_TYPE_REPLY_WININFO_TREE "tsia(tsiiiiiiii)"
121
122 static E_Info_Client e_info_client;
123
124 static Eina_Bool compobjs_simple = EINA_FALSE;
125
126 static void end_program(int sig);
127 static Eina_Bool _e_info_client_eldbus_message(const char *method, E_Info_Message_Cb cb);
128 static Eina_Bool _e_info_client_eldbus_message_with_args(const char *method, E_Info_Message_Cb cb, const char *signature, ...);
129 static Eina_Bool _e_info_client_eldbus_message_with_args_timeout(const char *method, E_Info_Message_Cb cb, double timeout, const char *signature, ...);
130 static void _e_info_client_eldbus_message_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *p);
131
132 static Eina_Bool
133 _util_string_to_uint(const char *str, unsigned int *num, int base)
134 {
135    char *end;
136    int errsv;
137
138    EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
139    EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
140
141    const unsigned long int ul = strtoul(str, &end, base);
142    errsv = errno;
143
144    EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a decimal number */
145    EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
146    EINA_SAFETY_ON_TRUE_RETURN_VAL(((ULONG_MAX == ul) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type unsigned long int */
147
148    *num = (unsigned int)ul;
149
150    return EINA_TRUE;
151 }
152
153 /* buff: string to be parsed
154  * next: return values it contains the address of the first invalid character
155  * num: return value it contains integer value according to the given base
156  */
157 static Eina_Bool
158 _util_string_to_int_token(const char *str, char **next, int *num, int base)
159 {
160    int errsv;
161
162    EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
163    EINA_SAFETY_ON_NULL_RETURN_VAL(next, EINA_FALSE);
164    EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
165
166    const long int sl = strtol(str, next, base);
167    errsv = errno;
168
169    EINA_SAFETY_ON_TRUE_RETURN_VAL((*next == str), EINA_FALSE); /* given string is not a decimal number */
170    EINA_SAFETY_ON_TRUE_RETURN_VAL(((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type long */
171    EINA_SAFETY_ON_TRUE_RETURN_VAL((sl > INT_MAX), EINA_FALSE); /* greater than INT_MAX */
172    EINA_SAFETY_ON_TRUE_RETURN_VAL((sl < INT_MIN), EINA_FALSE); /* less than INT_MIN */
173
174    *num = (int)sl;
175
176    return EINA_TRUE;
177 }
178
179 static Eina_Bool
180 _util_string_to_double(const char *str, double *num)
181 {
182    char *end;
183    int errsv;
184
185    EINA_SAFETY_ON_FALSE_RETURN_VAL(str, EINA_FALSE);
186    EINA_SAFETY_ON_FALSE_RETURN_VAL(num, EINA_FALSE);
187
188    const double sd = strtod(str, &end);
189    errsv = errno;
190
191    EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a floating point number */
192    EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
193    EINA_SAFETY_ON_TRUE_RETURN_VAL(((DBL_MIN == sd || DBL_MAX == sd) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type double */
194
195    *num = sd;
196
197    return EINA_TRUE;
198 }
199
200 static Eina_Bool
201 _util_string_to_ulong(const char *str, unsigned long *num, int base)
202 {
203    char *end;
204    int errsv;
205
206    EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
207    EINA_SAFETY_ON_NULL_RETURN_VAL(num, EINA_FALSE);
208
209    const unsigned long sul = strtoul(str, &end, base);
210    errsv = errno;
211
212    EINA_SAFETY_ON_TRUE_RETURN_VAL((end == str), EINA_FALSE); /* given string is not a decimal number */
213    EINA_SAFETY_ON_TRUE_RETURN_VAL(('\0' != *end), EINA_FALSE); /* given string has extra characters */
214    EINA_SAFETY_ON_TRUE_RETURN_VAL(((ULONG_MAX == sul) && (ERANGE == errsv)), EINA_FALSE); /* out of range of type unsigned long */
215
216    *num = sul;
217
218    return EINA_TRUE;
219 }
220
221 static void
222 _e_signal_get_window_under_touch(void *data, const Eldbus_Message *msg)
223 {
224    Eina_Bool res;
225    uint64_t w;
226    Ecore_Window *win = data;
227
228    res = eldbus_message_arguments_get(msg, "t", &w);
229    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
230
231    *win = (Ecore_Window)w;
232
233 finish:
234    ecore_main_loop_quit();
235 }
236
237 static void
238 _e_message_get_window_under_touch(const Eldbus_Message *msg)
239 {
240    const char *name = NULL, *text = NULL;
241    Eina_Bool res;
242    int result = 0;
243
244    res = eldbus_message_error_get(msg, &name, &text);
245    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
246
247    res = eldbus_message_arguments_get(msg, "i", &result);
248    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
249    EINA_SAFETY_ON_TRUE_GOTO(result, finish);
250
251    return;
252
253 finish:
254   if ((name) || (text))
255     {
256        printf("errname:%s errmsg:%s\n", name, text);
257     }
258
259    ecore_main_loop_quit();
260 }
261
262 static int
263 _e_get_window_under_touch(Ecore_Window *win)
264 {
265    Eina_Bool res;
266    Eldbus_Signal_Handler *signal_handler = NULL;
267
268    *win = 0;
269
270    signal_handler = eldbus_proxy_signal_handler_add(e_info_client.proxy, "win_under_touch", _e_signal_get_window_under_touch, win);
271    EINA_SAFETY_ON_NULL_GOTO(signal_handler, fail);
272
273    res = _e_info_client_eldbus_message("get_win_under_touch",
274                                        _e_message_get_window_under_touch);
275    EINA_SAFETY_ON_FALSE_GOTO(res, fail);
276
277    ecore_main_loop_begin();
278
279    eldbus_signal_handler_del(signal_handler);
280
281    return 0;
282
283 fail:
284    if (signal_handler)
285      eldbus_signal_handler_del(signal_handler);
286
287    return -1;
288 }
289
290 static void
291 _e_message_get_window_name(void *data, const Eldbus_Message *msg, Eldbus_Pending *p EINA_UNUSED)
292 {
293    char **win = data;
294
295    const char *name = NULL, *text = NULL;
296    Eina_Bool res;
297    const char *w;
298
299    res = eldbus_message_error_get(msg, &name, &text);
300    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
301
302    res = eldbus_message_arguments_get(msg, "s", &w);
303    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
304    EINA_SAFETY_ON_NULL_GOTO(w, finish);
305
306    *win = strdup(w);
307
308    ecore_main_loop_quit();
309
310    return;
311
312 finish:
313    if ((name) || (text))
314      {
315         printf("errname:%s errmsg:%s\n", name, text);
316      }
317
318    ecore_main_loop_quit();
319 }
320
321 static char *
322 _e_get_window_name(uint64_t win)
323 {
324    Eldbus_Pending *p;
325    char *win_name = NULL;
326
327    p = eldbus_proxy_call(e_info_client.proxy, "get_window_name",
328                          _e_message_get_window_name,
329                          &win_name, -1, "t", win);
330    EINA_SAFETY_ON_NULL_RETURN_VAL(p, NULL);
331
332    ecore_main_loop_begin();
333
334    return win_name;
335 }
336
337 static void
338 _e_message_get_windows(void *data, const Eldbus_Message *msg, Eldbus_Pending *p EINA_UNUSED)
339 {
340    const char *name = NULL, *text = NULL;
341    Eina_Bool res;
342    Eldbus_Message_Iter *array_of_windows;
343    uint64_t win;
344    Eina_List **win_list = data;
345
346    res = eldbus_message_error_get(msg, &name, &text);
347    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
348
349    res = eldbus_message_arguments_get(msg, "at", &array_of_windows);
350    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
351
352    while (eldbus_message_iter_get_and_next(array_of_windows, 't', &win))
353      {
354         *win_list = eina_list_append(*win_list, (void *)((Ecore_Window)win));
355      }
356
357    ecore_main_loop_quit();
358
359    return;
360
361 finish:
362    if ((name) || (text))
363      {
364         printf("errname:%s errmsg:%s\n", name, text);
365      }
366
367    ecore_main_loop_quit();
368 }
369
370 const static int _E_GET_WINDOWS_NAME_MODE = 1;
371 const static int _E_GET_WINDOWS_PID_MODE = 2;
372
373 static Eina_List *
374 _e_get_windows(int mode, char *value)
375 {
376    Eldbus_Pending *p;
377    Eina_List *win_list = NULL;
378
379    p = eldbus_proxy_call(e_info_client.proxy, "get_windows",
380                          _e_message_get_windows,
381                          &win_list, -1, "is", mode, value);
382    EINA_SAFETY_ON_NULL_RETURN_VAL(p, NULL);
383
384    ecore_main_loop_begin();
385
386    return win_list;
387 }
388
389 static E_Zone_Info *
390 _e_zone_info_new(int id, int display_state, int x, int y, int w, int h, Eina_Bool is_current, int angle_cur, int angle_active)
391 {
392    E_Zone_Info *zone_info = NULL;
393
394    zone_info = E_NEW(E_Zone_Info, 1);
395    if (!zone_info) return NULL;
396
397    zone_info->id = id;
398    zone_info->display_state = display_state;
399    zone_info->x = x;
400    zone_info->y = y;
401    zone_info->w = w;
402    zone_info->h = h;
403    zone_info->is_current = is_current;
404    zone_info->angle_cur = angle_cur;
405    zone_info->angle_active = angle_active;
406
407    return zone_info;
408 }
409
410 static void
411 _e_zone_info_make_array(Eldbus_Message_Iter *zone_array)
412 {
413    Eldbus_Message_Iter *zone;
414    Eina_Bool res;
415
416    while (eldbus_message_iter_get_and_next(zone_array, 'r', &zone))
417      {
418         E_Zone_Info *zone_info = NULL;
419         int id;
420         int display_state;
421                 int x, y, w, h;
422         Eina_Bool is_current;
423         int angle_cur;
424         int angle_active;
425
426         res = eldbus_message_iter_arguments_get(zone, VALUE_TYPE_FOR_ZONE, &id, &display_state, &x, &y, &w, &h, &is_current, &angle_cur, &angle_active);
427         if (!res)
428           {
429              printf("Failed to get win info\n");
430              continue;
431           }
432
433         zone_info = _e_zone_info_new(id, display_state, x, y, w, h, is_current, angle_cur, angle_active);
434         e_info_client.zone_list = eina_list_append(e_info_client.zone_list, zone_info);
435      }
436
437 }
438
439 static E_Win_Info *
440 _e_win_info_new(Ecore_Window id, uint32_t res_id, int pid, Eina_Bool alpha, int opaque, const char *name,
441                 int x, int y, int w, int h, int layer, int visible, int mapped, int visibility, Eina_Bool force_obscured,
442                 int iconic, int frame_visible, int focused, int hwc, int hwc_policy, int pl_zpos, Ecore_Window parent_id,
443                 const char *layer_name, Eina_Bool has_input_region, Eina_Bool transformed, E_Transient transient_policy, int zone_id, Eina_Bool is_apply_layout)
444 {
445    E_Win_Info *win = NULL;
446
447    win = E_NEW(E_Win_Info, 1);
448    EINA_SAFETY_ON_NULL_RETURN_VAL(win, NULL);
449
450    win->id = id;
451    win->res_id = res_id;
452    win->pid = pid;
453    win->name = eina_stringshare_add(name);
454    win->x = x;
455    win->y = y;
456    win->w = w;
457    win->h = h;
458    win->layer = layer;
459    win->alpha = alpha;
460    win->opaque = opaque;
461    win->vis = visible;
462    win->mapped = mapped;
463    win->visibility = visibility;
464    win->force_obscured = force_obscured;
465    win->frame_visible = frame_visible;
466    win->iconic = iconic;
467    win->focused = focused;
468    win->hwc = hwc;
469    win->hwc_policy = hwc_policy;
470    win->pl_zpos = pl_zpos;
471    win->parent_id = parent_id;
472    win->layer_name = eina_stringshare_add(layer_name);
473    win->has_input_region = has_input_region;
474    win->transformed = transformed;
475    win->transient_policy = transient_policy;
476    win->zone_id = zone_id;
477    win->is_apply_layout = is_apply_layout;
478
479    return win;
480 }
481
482 static void
483 _e_win_info_free(E_Win_Info *win)
484 {
485    EINA_SAFETY_ON_NULL_RETURN(win);
486
487    if (win->name)
488      eina_stringshare_del(win->name);
489
490    if (win->layer_name)
491      eina_stringshare_del(win->layer_name);
492
493    E_FREE(win);
494 }
495
496 static void
497 _e_win_info_make_array(Eldbus_Message_Iter *array)
498 {
499    Eldbus_Message_Iter *ec;
500    Eina_Bool res;
501
502    while (eldbus_message_iter_get_and_next(array, 'r', &ec))
503      {
504         const char *win_name;
505         const char *layer_name;
506         int x, y, w, h, layer, visibility, opaque, hwc, hwc_policy, pl_zpos, iconic;
507         Eina_Bool visible, mapped, alpha, force_obscured, focused, frame_visible, transformed;
508         Ecore_Window id, parent_id;
509         uint32_t res_id;
510         int pid;
511         E_Win_Info *win = NULL;
512         Eina_Bool has_input_region = EINA_FALSE;
513         int transient_policy;
514         int zone_id;
515         Eina_Bool is_apply_layout;
516         res = eldbus_message_iter_arguments_get(ec,
517                                                 VALUE_TYPE_FOR_TOPVWINS,
518                                                 &id,
519                                                 &res_id,
520                                                 &pid,
521                                                 &win_name,
522                                                 &x,
523                                                 &y,
524                                                 &w,
525                                                 &h,
526                                                 &layer,
527                                                 &visible,
528                                                 &mapped,
529                                                 &alpha,
530                                                 &opaque,
531                                                 &visibility,
532                                                 &force_obscured,
533                                                 &iconic,
534                                                 &frame_visible,
535                                                 &focused,
536                                                 &hwc,
537                                                 &hwc_policy,
538                                                 &pl_zpos,
539                                                 &parent_id,
540                                                 &layer_name,
541                                                 &has_input_region,
542                                                 &transformed,
543                                                 &transient_policy,
544                                                 &zone_id,
545                                                 &is_apply_layout);
546         if (!res)
547           {
548              printf("Failed to get win info\n");
549              continue;
550           }
551
552         win = _e_win_info_new(id, res_id, pid, alpha, opaque, win_name, x, y, w, h,
553                               layer, visible, mapped, visibility, force_obscured, iconic, frame_visible,
554                               focused, hwc, hwc_policy, pl_zpos, parent_id, layer_name,
555                               has_input_region, transformed, (E_Transient)transient_policy, zone_id, is_apply_layout);
556         e_info_client.win_list = eina_list_append(e_info_client.win_list, win);
557      }
558 }
559
560 static void
561 _cb_window_info_get(const Eldbus_Message *msg)
562 {
563    const char *name = NULL, *text = NULL;
564    Eldbus_Message_Iter *array;
565    Eina_Bool res;
566
567    res = eldbus_message_error_get(msg, &name, &text);
568    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
569
570    res = eldbus_message_arguments_get(msg, "iia("VALUE_TYPE_FOR_TOPVWINS")", &e_info_client.hwc, &e_info_client.hwc_windows, &array);
571    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
572
573    _e_win_info_make_array(array);
574
575 finish:
576    if ((name) || (text))
577      {
578         printf("errname:%s errmsg:%s\n", name, text);
579      }
580 }
581
582 static void
583 _cb_zone_info_get(const Eldbus_Message *msg)
584 {
585    const char *name = NULL, *text = NULL;
586    Eldbus_Message_Iter *zone_array;
587    Eina_Bool res = EINA_FALSE;
588
589    res = eldbus_message_error_get(msg, &name, &text);
590    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
591
592    res = eldbus_message_arguments_get(msg, "("VALUE_TYPE_FOR_ZONE")", &zone_array);
593    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
594
595    _e_zone_info_make_array(zone_array);
596 finish:
597    if ((name) || (text) || (!res))
598      {
599         printf("errname:%s errmsg:%s ret:%d\n", name, text, res);
600      }
601 }
602
603 static void
604 _cb_vwindow_info_get(const Eldbus_Message *msg)
605 {
606    const char *name = NULL, *text = NULL;
607    Eldbus_Message_Iter *array;
608    char *engine;
609    Eina_Bool res;
610
611    res = eldbus_message_error_get(msg, &name, &text);
612    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
613
614    res = eldbus_message_arguments_get(msg, "iiiiisiiia("VALUE_TYPE_FOR_TOPVWINS")",
615                                       &e_info_client.use_gl, &e_info_client.use_hwc, &e_info_client.use_multi_layer,
616                                       &e_info_client.hwc, &e_info_client.hwc_windows,
617                                       &engine, &e_info_client.config_engine,
618                                       &e_info_client.use_buffer_flush, &e_info_client.deiconify_approve,
619                                       &array);
620
621    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
622    e_info_client.engine = eina_stringshare_add(engine);
623
624    _e_win_info_make_array(array);
625
626 finish:
627    if ((name) || (text))
628      {
629         printf("errname:%s errmsg:%s\n", name, text);
630      }
631 }
632
633
634 static void
635 _e_info_client_cb_compobjs(const Eldbus_Message *msg)
636 {
637    const char *name = NULL, *text = NULL, *obj_name;
638    Eldbus_Message_Iter *array, *obj;
639    Eina_Bool res;
640    E_Info_Comp_Obj cobj;
641    int i;
642
643    res = eldbus_message_error_get(msg, &name, &text);
644    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
645
646    res = eldbus_message_arguments_get(msg,
647                                       "a("SIGNATURE_COMPOBJS_CLIENT")",
648                                       &array);
649    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
650
651    if (compobjs_simple)
652      printf(
653         "===========================================================================================================================\n"
654         "                        /-- Object Type        /-- Alpha                                                                   \n"
655         "                        |    r  : Rectangle    |                                          /-- Edj: group                   \n"
656         "                        |    EDJ: Edje         | /-- Pass Events                          |   Edj Member: part, value      \n"
657         "                        |    IMG: Image        | |/-- Freeze Events                       |   Native Image:                \n"
658         "                        |    EC : ec->frame    | ||/-- Focused                            |    type, buff, size, load, fill\n"
659         "                        |                      | |||/-- EvasMap                           |                      size  size\n"
660         "                        |                      | ||||                                     |   File Image:                  \n"
661         "                        |                      | |||| /-- Visibility                      |    data, size, load, fill      \n"
662         "                        |                      | |||| |                                   |                size  size      \n"
663         "                        |                      | |||| |                                   |                                \n"
664         "========================|======================|=||||=|===================================|================================\n"
665         "Layer  ObjectID         |     X    Y    W    H | |||| |   ObjectName                      | Additional Info                \n"
666         "========================|======================|=||||=|===================================|================================\n"
667         );
668    else
669      printf(
670         "=======================================================================================================================\n"
671         "                        /-- Object Type                            /-- Alpha                                           \n"
672         "                        |    r  : Rectangle Object                 |                                                   \n"
673         "                        |    EDJ: Edje Object                      | /-- Pass Events                                   \n"
674         "                        |    IMG: Image Object                     | |/-- Freeze Events                                \n"
675         "                        |    EC : ec->frame Object                 | ||/-- Focused                                     \n"
676         "                        |                                          | |||/-  EvasMap                                    \n"
677         "                        |                                          | ||||                                              \n"
678         "                        |    /-- Render Operation                  | |||| /-- Visibility                               \n"
679         "                        |    |    BL: EVAS_RENDER_BLEND            | |||| |                                            \n"
680         "                        |    |    CP: EVAS_RENDER_COPY             | |||| |                                            \n"
681         "                        |    |                                     | |||| |                           [Additional Info]\n"
682         "                        |    |                                     | |||| |                          EDJ: group, file |\n"
683         "                        |    |                                     | |||| |                   EDJ member: part, value |\n"
684         "                        |    |                                     | |||| |   Image: Type, Size, Load Size, Fill Size |\n"
685         "                        |    |                                     | |||| |             Map: Enable, Alpha, UV, Coord |\n"
686         "                        |    |                                     | |||| |                                           |\n"
687         "========================|====|=====================================|=||||=|============================================\n"
688         "Layer  ObjectID         |    |    X    Y    W    H  Color(RGBA)    | |||| |     ObjectName                            |\n"
689         "========================|====|=====================================|=||||=|============================================\n"
690         );
691
692    while (eldbus_message_iter_get_and_next(array, 'r', &obj))
693      {
694         memset(&cobj, 0, sizeof(E_Info_Comp_Obj));
695
696         res = eldbus_message_iter_arguments_get(obj,
697                                                 SIGNATURE_COMPOBJS_CLIENT,
698                                                 &cobj.obj,
699                                                 &cobj.depth,
700                                                 &cobj.type,
701                                                 &cobj.name,
702                                                 &cobj.ly,
703                                                 &cobj.opmode,
704                                                 &cobj.x, &cobj.y, &cobj.w, &cobj.h,
705                                                 &cobj.r, &cobj.g, &cobj.b, &cobj.a,
706                                                 &cobj.pass_events,
707                                                 &cobj.freeze_events,
708                                                 &cobj.focus,
709                                                 &cobj.vis,
710                                                 &cobj.edje.file,
711                                                 &cobj.edje.group,
712                                                 &cobj.edje.part,
713                                                 &cobj.edje.val,
714                                                 &cobj.img.native,
715                                                 &cobj.img.native_type,
716                                                 &cobj.img.file,
717                                                 &cobj.img.key,
718                                                 &cobj.img.data,
719                                                 &cobj.img.w, &cobj.img.h,
720                                                 &cobj.img.lw, &cobj.img.lh,
721                                                 &cobj.img.fx, &cobj.img.fy, &cobj.img.fw, &cobj.img.fh,
722                                                 &cobj.img.alpha,
723                                                 &cobj.img.dirty,
724                                                 &cobj.map.enable,
725                                                 &cobj.map.alpha,
726                                                 &cobj.map.u[0], &cobj.map.u[1], &cobj.map.u[2], &cobj.map.u[3],
727                                                 &cobj.map.v[0], &cobj.map.v[1], &cobj.map.v[2], &cobj.map.v[3],
728                                                 &cobj.map.x[0], &cobj.map.x[1], &cobj.map.x[2], &cobj.map.x[3],
729                                                 &cobj.map.y[0], &cobj.map.y[1], &cobj.map.y[2], &cobj.map.y[3],
730                                                 &cobj.map.z[0], &cobj.map.z[1], &cobj.map.z[2], &cobj.map.z[3]);
731         if (!res)
732           {
733              printf("Failed to get composite obj info\n");
734              continue;
735           }
736
737         if (cobj.depth == 0)
738           {
739              if (!compobjs_simple)
740                printf(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - |\n");
741              printf("%4d ", cobj.ly);
742           }
743         else
744           printf("     ");
745
746         for (i = 0; i < cobj.depth; i++) printf(" ");
747         printf("%08x ", cobj.obj);
748         for (i = 6; i > cobj.depth; i--) printf(" ");
749
750         if (compobjs_simple)
751           printf("%5.5s "
752                  "|%4d,%4d %4dx%4d|%s|%s%s%s%s|%s|",
753                  cobj.type,
754                  cobj.x, cobj.y, cobj.w, cobj.h,
755                  cobj.img.alpha == 1 ? "A" : " ",
756                  cobj.pass_events == 1 ? "p" : " ",
757                  cobj.freeze_events == 1 ? "z" : " ",
758                  cobj.focus == 1 ? "F" : " ",
759                  cobj.map.enable == 1 ? "M" : " ",
760                  cobj.vis == 1 ? "V" : " ");
761         else
762           printf("%5.5s "
763                  "|%3.3s"
764                  "|%4d,%4d %4dx%4d|%3d %3d %3d %3d|%s|%s%s%s%s|%s|",
765                  cobj.type,
766                  cobj.opmode,
767                  cobj.x, cobj.y, cobj.w, cobj.h,
768                  cobj.r, cobj.g, cobj.b, cobj.a,
769                  cobj.img.alpha == 1 ? "A" : " ",
770                  cobj.pass_events == 1 ? "p" : " ",
771                  cobj.freeze_events == 1 ? "z" : " ",
772                  cobj.focus == 1 ? "F" : " ",
773                  cobj.map.enable == 1 ? "M" : " ",
774                  cobj.vis == 1 ? "V" : " ");
775
776         obj_name = cobj.name;
777         if (!strncmp(obj_name, "no_use", 6)) obj_name = "";
778         printf("%-32.32s|", obj_name);
779
780         if (!strncmp(cobj.type, "EDJ", 3))
781           {
782              if (strncmp(cobj.edje.group, "no_use", 6)) printf("%s ", cobj.edje.group);
783
784              if (!compobjs_simple)
785                if (strncmp(cobj.edje.file,  "no_use", 6)) printf("%s ", cobj.edje.file);
786           }
787
788         if (strncmp(cobj.edje.part,  "no_use", 6)) printf("%s %1.1f", cobj.edje.part, cobj.edje.val);
789
790         if (!strncmp(cobj.type, "IMG", 3))
791           {
792              if (cobj.img.native)
793                {
794                   if (strncmp(cobj.img.native_type, "no_use", 6)) printf("%s ", cobj.img.native_type);
795                }
796              else
797                {
798                   if (!compobjs_simple)
799                     if (strncmp(cobj.img.file, "no_use", 6)) printf("%s ", cobj.img.file);
800
801                   if (strncmp(cobj.img.key, "no_use", 6)) printf("%s ", cobj.img.key);
802
803                }
804
805              printf("d:%x %dx%d %dx%d (%d,%d %dx%d)",
806                     cobj.img.data,
807                     cobj.img.w, cobj.img.h,
808                     cobj.img.lw, cobj.img.lh,
809                     cobj.img.fx, cobj.img.fy, cobj.img.fw, cobj.img.fh);
810           }
811
812         printf("\n");
813         if (!compobjs_simple && cobj.map.enable)
814           {
815              printf("                                                                                                            ");
816              printf("|Map: %s\n", (cobj.map.alpha == 1) ? "alpha(on)" : "alpha(off)");
817              printf("                                                                                                            ");
818              printf("|    UV (  %4d,%4d   |  %4d,%4d   |  %4d,%4d   |  %4d,%4d   )\n",
819                     (int)cobj.map.u[0], (int)cobj.map.v[0],
820                     (int)cobj.map.u[1], (int)cobj.map.v[1],
821                     (int)cobj.map.u[2], (int)cobj.map.v[2],
822                     (int)cobj.map.u[3], (int)cobj.map.v[3]);
823              printf("                                                                                                            ");
824              printf("| Coord (%4d,%4d,%4d|%4d,%4d,%4d|%4d,%4d,%4d|%4d,%4d,%4d)\n",
825                     cobj.map.x[0], cobj.map.y[0], cobj.map.z[0],
826                     cobj.map.x[1], cobj.map.y[1], cobj.map.z[1],
827                     cobj.map.x[2], cobj.map.y[2], cobj.map.z[2],
828                     cobj.map.x[3], cobj.map.y[3], cobj.map.z[3]);
829           }
830      }
831
832    if (compobjs_simple)
833      printf("===========================================================================================================================\n");
834    else
835      printf("=======================================================================================================================\n");
836
837 finish:
838    if ((name) || (text))
839      {
840         printf("errname:%s errmsg:%s\n", name, text);
841      }
842 }
843
844 static void
845 _cb_input_device_info_get(const Eldbus_Message *msg)
846 {
847    const char *name = NULL, *text = NULL;
848    Eldbus_Message_Iter *array, *eldbus_msg;
849    Eina_Bool res;
850    int i = 0;
851
852    res = eldbus_message_error_get(msg, &name, &text);
853    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
854
855    res = eldbus_message_arguments_get(msg, "a("VALUE_TYPE_FOR_INPUTDEV")", &array);
856    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
857
858    printf("--------------------------------------[ input devices ]----------------------------------------------------------\n");
859    printf(" No                     Name                identifier               Cap              Seat            Output\n");
860    printf("-----------------------------------------------------------------------------------------------------------------\n");
861
862    while (eldbus_message_iter_get_and_next(array, 'r', &eldbus_msg))
863      {
864         i++;
865         char *dev_name;
866         char *identifier;
867         int clas;
868         char *seat_name;
869         char *output_name;
870         res = eldbus_message_iter_arguments_get(eldbus_msg,
871                                                 VALUE_TYPE_FOR_INPUTDEV,
872                                                 &dev_name,
873                                                 &identifier,
874                                                 &clas,
875                                                 &seat_name,
876                                                 &output_name);
877         if (!res)
878           {
879              printf("Failed to get device info\n");
880              continue;
881           }
882
883         printf("%3d %30s %20s         ", i, dev_name, identifier);
884         if (clas == ECORE_DEVICE_CLASS_MOUSE) printf("Mouse    | ");
885         else if (clas == ECORE_DEVICE_CLASS_KEYBOARD) printf("Keyboard | ");
886         else if (clas == ECORE_DEVICE_CLASS_TOUCH) printf("Touch    | ");
887         else if (clas == ECORE_DEVICE_CLASS_SEAT) printf("Seat     | ");
888         printf("(0x%x)   ", clas);
889         printf("%10s", seat_name);
890         printf("%15s\n", output_name);
891      }
892
893    if (i == 0)
894      {
895         printf("no input devices\n");
896         return;
897      }
898
899 finish:
900    if ((name) || (text))
901      {
902         printf("errname:%s errmsg:%s\n", name, text);
903      }
904 }
905
906 static void
907 _cb_input_keymap_info_get(const Eldbus_Message *msg)
908 {
909    const char *name = NULL, *text = NULL;
910    Eina_Bool res;
911    int i;
912    int min_keycode=0, max_keycode=0, fd=0, size=0, num_mods=0, num_groups = 0;
913    struct xkb_context *context = NULL;
914    struct xkb_keymap *keymap = NULL;
915    struct xkb_state *state = NULL;
916    xkb_keysym_t sym = XKB_KEY_NoSymbol;
917    char keyname[256] = {0, };
918    char *map = NULL;
919
920    res = eldbus_message_error_get(msg, &name, &text);
921    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
922
923    res = eldbus_message_arguments_get(msg, "hi", &fd, &size);
924    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
925
926    context = xkb_context_new(0);
927    EINA_SAFETY_ON_NULL_GOTO(context, finish);
928
929    map = mmap(NULL, size, 0x01, 0x0001, fd, 0);
930    if (map == ((void *)-1))
931      {
932         xkb_context_unref(context);
933         close(fd);
934         return;
935      }
936
937    keymap = xkb_map_new_from_string(context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
938
939    munmap(map, size);
940    close(fd);
941
942    EINA_SAFETY_ON_NULL_GOTO(keymap, finish);
943    state = xkb_state_new(keymap);
944    EINA_SAFETY_ON_NULL_GOTO(state, finish);
945
946    min_keycode = xkb_keymap_min_keycode(keymap);
947    max_keycode = xkb_keymap_max_keycode(keymap);
948    num_groups = xkb_map_num_groups(keymap);
949    num_mods = xkb_keymap_num_mods(keymap);
950
951    printf("\n");
952    printf("    min keycode: %d\n", min_keycode);
953    printf("    max keycode: %d\n", max_keycode);
954    printf("    num_groups : %d\n", num_groups);
955    printf("    num_mods   : %d\n", num_mods);
956    for (i = 0; i < num_mods; i++)
957      {
958         printf("        [%2d] mod: %s\n", i, xkb_keymap_mod_get_name(keymap, i));
959      }
960
961    printf("\n\n\tkeycode\t\tkeyname\t\t  keysym\t    repeat\n");
962    printf("    ----------------------------------------------------------------------\n");
963
964    for (i = min_keycode; i < (max_keycode + 1); i++)
965      {
966         sym = xkb_state_key_get_one_sym(state, i);
967
968         memset(keyname, 0, sizeof(keyname));
969         xkb_keysym_get_name(sym, keyname, sizeof(keyname));
970
971         printf("\t%4d%-5s%-25s%-20x%-5d\n", i, "", keyname, sym, xkb_keymap_key_repeats(keymap, i));
972      }
973 finish:
974    if ((name) || (text ))
975      {
976         printf("errname:%s errmsg:%s\n", name, text);
977      }
978    if (state) xkb_state_unref(state);
979    if (keymap) xkb_map_unref(keymap);
980    if (context) xkb_context_unref(context);
981 }
982
983 #define PROTOCOL_RULE_USAGE \
984   "[COMMAND] [ARG]...\n" \
985   "\tadd    : add the rule to trace events (Usage: add [allow|deny] [RULE(iface=wl_touch and msg=down)]\n" \
986   "\tremove  : remove the rule (Usage: remove [all|RULE_INDEX])\n" \
987   "\tfile    : add rules from file (Usage: file [RULE_FILE_PATH])\n" \
988   "\tprint   : print current rules\n" \
989   "\thelp\n" \
990
991 static void
992 _e_info_client_proc_protocol_trace(int argc, char **argv)
993 {
994    char fd_name[PATH_MAX + PATH_MAX];
995    int pid;
996    char cwd[PATH_MAX];
997
998    if (argc != 3 || !argv[2])
999      {
1000         printf("protocol-trace: Usage> enlightenment_info -protocol_trace [console | file path | disable]\n");
1001         return;
1002      }
1003
1004    pid = getpid();
1005
1006    cwd[0] = '\0';
1007    if (!getcwd(cwd, sizeof(cwd)))
1008      snprintf(cwd, sizeof(cwd), "/tmp");
1009
1010    if (!strncmp(argv[2], "console", 7))
1011      snprintf(fd_name, sizeof(fd_name), "/proc/%d/fd/1", pid);
1012    else if (!strncmp(argv[2], "elog", 4))
1013      snprintf(fd_name, sizeof(fd_name), "elog");
1014    else if (!strncmp(argv[2], "disable", 7))
1015      snprintf(fd_name, sizeof(fd_name), "disable");
1016    else
1017      {
1018         if (argv[2][0] == '/')
1019           snprintf(fd_name, PATH_MAX, "%s", argv[2]);
1020         else
1021           {
1022              if (strlen(cwd) > 0)
1023                snprintf(fd_name, sizeof(fd_name), "%s/%s", cwd, argv[2]);
1024              else
1025                snprintf(fd_name, sizeof(fd_name), "%s", argv[2]);
1026           }
1027      }
1028
1029    printf("protocol-trace: %s\n", fd_name);
1030
1031    if (!_e_info_client_eldbus_message_with_args("protocol_trace", NULL, "s", fd_name))
1032      return;
1033 }
1034
1035 static void
1036 _cb_protocol_rule(const Eldbus_Message *msg)
1037 {
1038    const char *name = NULL, *text = NULL;
1039    Eina_Bool res;
1040    const char *reply;
1041
1042    res = eldbus_message_error_get(msg, &name, &text);
1043    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
1044
1045    res = eldbus_message_arguments_get(msg, "s", &reply);
1046    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
1047    printf("%s\n", reply);
1048
1049 finish:
1050    if ((name) || (text ))
1051      {
1052         printf("errname:%s errmsg:%s\n", name, text);
1053      }
1054 }
1055
1056 static void
1057 _e_info_client_proc_protocol_rule(int argc, char **argv)
1058 {
1059    char *new_argv[3];
1060    char *new_s1 = NULL;
1061    char *new_s2 = NULL;
1062    int new_argc;
1063    int i;
1064    Eina_Bool res = EINA_FALSE;
1065
1066    if (argc < 3 ||
1067       (argc > 3 && !eina_streq(argv[2], "print") && !eina_streq(argv[2], "help") && !eina_streq(argv[2], "file") && !eina_streq(argv[2], "add") && !eina_streq(argv[2], "remove")))
1068      {
1069         printf("protocol-trace: Usage> enlightenment_info -protocol_rule [add | remove | print | help] [allow/deny/all]\n");
1070         return;
1071      }
1072
1073    new_argc = argc - 2;
1074    for (i = 0; i < new_argc; i++)
1075      new_argv[i] = argv[i + 2];
1076    if (new_argc < 2)
1077      {
1078         new_s1 = (char *)calloc (1, PATH_MAX);
1079         EINA_SAFETY_ON_NULL_RETURN(new_s1);
1080
1081         snprintf(new_s1, PATH_MAX, "%s", "no_data");
1082         new_argv[1] = new_s1;
1083         new_argc++;
1084      }
1085    if (new_argc < 3)
1086      {
1087         new_s2 = (char *)calloc (1, PATH_MAX);
1088         EINA_SAFETY_ON_NULL_GOTO(new_s2, finish);
1089
1090         snprintf(new_s2, PATH_MAX, "%s", "no_data");
1091         new_argv[2] = new_s2;
1092         new_argc++;
1093      }
1094    if (new_argc != 3)
1095      {
1096         printf("protocol-trace: Usage> enlightenment_info -protocol_rule [add | remove | print | help] [allow/deny/all]\n");
1097         goto finish;
1098      }
1099
1100    res = _e_info_client_eldbus_message_with_args("protocol_rule", _cb_protocol_rule, "sss", new_argv[0], new_argv[1], new_argv[2]);
1101    if (!res) printf("Error occured while send send message\n\n");
1102
1103 finish:
1104    if (new_s1) free(new_s1);
1105    if (new_s2) free(new_s2);
1106 }
1107
1108 static void
1109 _cb_vec_info_get(const Eldbus_Message *msg)
1110 {
1111    const char *name = NULL, *text = NULL;
1112    Eldbus_Message_Iter *array;
1113    Eina_Bool res;
1114
1115    res = eldbus_message_error_get(msg, &name, &text);
1116    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
1117
1118    res = eldbus_message_arguments_get(msg, "iia("VALUE_TYPE_FOR_TOPVWINS")", &e_info_client.hwc, &e_info_client.hwc_windows, &array);
1119    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
1120
1121    _e_win_info_make_array(array);
1122
1123 finish:
1124    if ((name) || (text))
1125      {
1126         printf("errname:%s errmsg:%s\n", name, text);
1127      }
1128 }
1129
1130 static void
1131 _e_info_client_proc_ec_list_info(Eina_Bool check_visible)
1132 {
1133    E_Win_Info *win;
1134    Eina_List *l;
1135    int i = 0;
1136    int prev_layer = -1;
1137    int hwc_off = 0;
1138
1139    const char *prev_layer_name = NULL;
1140
1141    if (check_visible)
1142      {
1143         if (!_e_info_client_eldbus_message("get_ec_info", _cb_vec_info_get))
1144           return;
1145      }
1146    else
1147      {
1148         if (!_e_info_client_eldbus_message("get_all_ec_info", _cb_vec_info_get))
1149           return;
1150      }
1151
1152    printf("\n\n%d Top level windows in EC list\n", eina_list_count(e_info_client.win_list));
1153    if (check_visible)
1154      printf("--------------------------------------------[ topvwins ]------------------------------------------------------------------------------\n");
1155    else
1156      printf("--------------------------------------------[ topwins  ]------------------------------------------------------------------------------\n");
1157    if (e_info_client.hwc_windows)
1158      printf(" No   Win_ID    RcsID    PID  T    w     h       x      y  L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  HWC_ST  Parent   TP    Title\n");
1159    else
1160      printf(" No   Win_ID    RcsID    PID  T    w     h       x      y  L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  PL@ZPos Parent   TP    Title\n");
1161    printf("--------------------------------------------------------------------------------------------------------------------------------------\n");
1162
1163    if (!e_info_client.win_list)
1164      {
1165         printf("no ECs\n");
1166         return;
1167      }
1168
1169    EINA_LIST_FOREACH(e_info_client.win_list, l, win)
1170      {
1171         if (!win) return;
1172         char tmp[20];
1173         i++;
1174         if (win->layer != prev_layer)
1175           {
1176              if (prev_layer != -1)
1177                 printf("--------------------------------------------------------------------------------------------------------------------------------------[%s]\n",
1178                        prev_layer_name ? prev_layer_name : " ");
1179              prev_layer = win->layer;
1180              prev_layer_name = win->layer_name;
1181           }
1182
1183         if (win->hwc >= 0)
1184           {
1185              if (win->hwc_policy == E_HWC_POLICY_WINDOWS) // hwc windows
1186                {
1187                   switch(win->pl_zpos)
1188                     {
1189                      case E_HWC_WINDOW_STATE_NONE:   snprintf(tmp, sizeof(tmp), "  NO  "); break;
1190                      case E_HWC_WINDOW_STATE_CLIENT: snprintf(tmp, sizeof(tmp), "  CL  "); break;
1191                      case E_HWC_WINDOW_STATE_DEVICE: snprintf(tmp, sizeof(tmp), "  DV  "); break;
1192                      case E_HWC_WINDOW_STATE_VIDEO:  snprintf(tmp, sizeof(tmp), "  VD  "); break;
1193                      case E_HWC_WINDOW_STATE_CURSOR: snprintf(tmp, sizeof(tmp), "  CS  "); break;
1194                      default:                        snprintf(tmp, sizeof(tmp), "  -  "); break;
1195                     }
1196                }
1197              else // hwc planes
1198                {
1199                   if ((!win->iconic) && (win->frame_visible))
1200                     {
1201                        if (win->pl_zpos == -999)
1202                          snprintf(tmp, sizeof(tmp), " - ");
1203                        else
1204                          {
1205                             if (win->hwc) snprintf(tmp, sizeof(tmp), "hwc@%i", win->pl_zpos);
1206                             else snprintf(tmp, sizeof(tmp), "comp@%i", win->pl_zpos);
1207                          }
1208                     }
1209                   else
1210                     snprintf(tmp, sizeof(tmp), " - ");
1211                }
1212           }
1213         else
1214           {
1215              hwc_off = 1;
1216              snprintf(tmp, sizeof(tmp), " - ");
1217           }
1218
1219         printf("%3d 0x%08zx  %5d  %5d  %c %5d %5d %6d %6d  %c %2d   %c    %c   %3d  %2d   ", i, win->id, win->res_id, win->pid, win->transformed ? 'O':' ', win->w, win->h, win->x, win->y, win->is_apply_layout ? 'L':' ', win->zone_id, win->focused ? 'O':' ', win->has_input_region?'C':' ', win->alpha? 32:24, win->opaque);
1220         printf("%2d%c   %d   %d   %s   %3d    %-8s%-8zx %c  %s\n", win->visibility, win->force_obscured ? 'f':' ', win->iconic, win->vis, win->mapped? "V":"N", win->frame_visible, tmp, win->parent_id, win->parent_id?(win->transient_policy?'B':'A'):' ',win->name?:"No Name");
1221      }
1222
1223    if (prev_layer_name)
1224       printf("--------------------------------------------------------------------------------------------------------------------------------------[%s]\n",
1225              prev_layer_name);
1226
1227    if(hwc_off)
1228      printf("\nHWC is disabled\n\n");
1229
1230    E_FREE_LIST(e_info_client.win_list, _e_win_info_free);
1231    if (e_info_client.engine)
1232      {
1233         eina_stringshare_del(e_info_client.engine);
1234         e_info_client.engine = NULL;
1235      }
1236 }
1237
1238 static void
1239 _e_info_client_proc_topvwins_info(int argc, char **argv)
1240 {
1241    E_Win_Info *win;
1242    Eina_List *l;
1243    E_Zone_Info *zone_info;
1244    Eina_List *zl;
1245    int i = 0;
1246    int prev_layer = -1;
1247    int hwc_off = 0;
1248
1249    const char *prev_layer_name = NULL;
1250
1251    if (!_e_info_client_eldbus_message("get_zone_info", _cb_zone_info_get))
1252      goto ec_info;
1253
1254    if (!_e_info_client_eldbus_message("get_window_info", _cb_vwindow_info_get))
1255      goto ec_info;
1256
1257    printf("GL :  %s\n", e_info_client.use_gl ? "on":"off");
1258    printf("ENG:  %s (config: %d)\n", e_info_client.engine, e_info_client.config_engine);
1259    if (e_info_client.use_hwc)
1260      {
1261         if (e_info_client.hwc)
1262           {
1263              printf("HWC:  ");
1264              if (e_info_client.hwc_windows)
1265                printf("hwc windows policy\n");
1266              else
1267                printf("hwc planes policy and multiple plane is %s\n", e_info_client.use_multi_layer ? "on":"off");
1268           }
1269         else
1270           printf("HWC:  off");
1271      }
1272    else
1273      printf("HWC:  configuration is off");
1274
1275    printf("Buffer flush: %s\n", e_info_client.use_buffer_flush ? "on":"off");
1276    if (e_info_client.use_buffer_flush)
1277      printf("Deiconify Approve: %s\n", "auto on");
1278    else
1279      printf("Deiconify Approve: %s\n", e_info_client.deiconify_approve ? "on":"off");
1280
1281    EINA_LIST_FOREACH(e_info_client.zone_list, zl, zone_info)
1282      {
1283         printf("\n====================================================================================================================================\n");
1284         printf("Zone[%d] Info %s\n", zone_info->id, zone_info->is_current ? "(current)" : "");
1285         printf("------------------------------------------------------------------------------------------------------------------------------------\n");
1286
1287         printf("Geometry : %d,%d,%dx%d\n", zone_info->x, zone_info->y, zone_info->w, zone_info->h);
1288         if (zone_info->display_state == E_ZONE_DISPLAY_STATE_OFF)
1289           printf("Display State: %s\n", "Off");
1290         else if (zone_info->display_state == E_ZONE_DISPLAY_STATE_ON)
1291           printf("Display State: %s\n", "On");
1292         else
1293           printf("Display State: %s\n", "Unknown");
1294         printf("Angle: Cur(%d), Active(%d)\n", zone_info->angle_cur, zone_info->angle_active);
1295         printf("------------------------------------------------------------------------------------------------------------------------------------\n");
1296
1297         printf("%d Top level windows in evas object list\n", eina_list_count(e_info_client.win_list));
1298         printf("--------------------------------------[ topvwins ]----------------------------------------------------------------------------------\n");
1299         if (e_info_client.hwc_windows)
1300           printf(" No   Win_ID    RcsID    PID     w     h       x      y  L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  HWC_ST  Parent   TP    Title\n");
1301         else
1302           printf(" No   Win_ID    RcsID    PID     w     h       x      y  L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  PL@ZPos Parent   TP    Title\n");
1303         printf("------------------------------------------------------------------------------------------------------------------------------------\n");
1304
1305         if (!e_info_client.win_list)
1306           {
1307              printf("no window\n");
1308              goto ec_info;
1309           }
1310
1311         EINA_LIST_FOREACH(e_info_client.win_list, l, win)
1312           {
1313              if (!win) goto ec_info;
1314              if (win->zone_id != zone_info->id) continue;
1315
1316              char tmp[20];
1317              i++;
1318              if (win->layer != prev_layer)
1319                {
1320                   if (prev_layer != -1)
1321                     printf("------------------------------------------------------------------------------------------------------------------------------------[%s]\n",
1322                            prev_layer_name ? prev_layer_name : " ");
1323                   prev_layer = win->layer;
1324                   prev_layer_name = win->layer_name;
1325                }
1326
1327              if (win->hwc >= 0)
1328                {
1329                   if (win->hwc_policy == E_HWC_POLICY_WINDOWS) // hwc windows
1330                     {
1331                        switch(win->pl_zpos)
1332                          {
1333                           case E_HWC_WINDOW_STATE_NONE:   snprintf(tmp, sizeof(tmp), "  NO  "); break;
1334                           case E_HWC_WINDOW_STATE_CLIENT: snprintf(tmp, sizeof(tmp), "  CL  "); break;
1335                           case E_HWC_WINDOW_STATE_DEVICE: snprintf(tmp, sizeof(tmp), "  DV  "); break;
1336                           case E_HWC_WINDOW_STATE_VIDEO:  snprintf(tmp, sizeof(tmp), "  VD  "); break;
1337                           case E_HWC_WINDOW_STATE_CURSOR: snprintf(tmp, sizeof(tmp), "  CS  "); break;
1338                           default:                        snprintf(tmp, sizeof(tmp), "  -  "); break;
1339                          }
1340                     }
1341                   else // hwc planes
1342                     {
1343                        if ((!win->iconic) && (win->frame_visible))
1344                          {
1345                             if (win->pl_zpos == -999)
1346                               snprintf(tmp, sizeof(tmp), " - ");
1347                             else
1348                               {
1349                                  if (win->hwc) snprintf(tmp, sizeof(tmp), "hwc@%i", win->pl_zpos);
1350                                  else snprintf(tmp, sizeof(tmp), "comp@%i", win->pl_zpos);
1351                               }
1352                          }
1353                        else
1354                          snprintf(tmp, sizeof(tmp), " - ");
1355                     }
1356                }
1357              else
1358                {
1359                   hwc_off = 1;
1360                   snprintf(tmp, sizeof(tmp), " - ");
1361                }
1362
1363              printf("%3d 0x%08zx  %5d  %5d  %5d %5d %6d %6d  %c %2d   %c    %c   %3d  %2d   ", i, win->id, win->res_id, win->pid, win->w, win->h, win->x, win->y, win->is_apply_layout ? 'L':' ', win->zone_id, win->focused ? 'O':' ', win->has_input_region?'C':' ', win->alpha? 32:24, win->opaque);
1364              printf("%2d%c   %d   %d   %s   %3d    %-8s%-8zx %c  %s\n", win->visibility, win->force_obscured ? 'f':' ', win->iconic, win->vis, win->mapped? "V":"N", win->frame_visible, tmp, win->parent_id, win->parent_id?(win->transient_policy?'B':'A'):' ',win->name?:"No Name");
1365           }
1366
1367         if (prev_layer_name)
1368           printf("------------------------------------------------------------------------------------------------------------------------------------[%s]\n\n",
1369                  prev_layer_name);
1370      }
1371
1372    if(hwc_off)
1373      printf("\nHWC is disabled\n\n");
1374
1375    E_FREE_LIST(e_info_client.win_list, _e_win_info_free);
1376    if (e_info_client.engine)
1377      {
1378         eina_stringshare_del(e_info_client.engine);
1379         e_info_client.engine = NULL;
1380      }
1381
1382 ec_info:
1383    _e_info_client_proc_ec_list_info(EINA_TRUE);
1384
1385 }
1386
1387 static void
1388 _e_info_client_proc_topwins_info(int argc, char **argv)
1389 {
1390    E_Win_Info *win;
1391    Eina_List *l;
1392    int i = 0;
1393    int prev_layer = -1;
1394    int hwc_off = 0;
1395
1396    const char *prev_layer_name = NULL;
1397
1398    if (!_e_info_client_eldbus_message("get_all_window_info", _cb_window_info_get))
1399      goto ec_info;
1400
1401    printf("%d Top level windows\n", eina_list_count(e_info_client.win_list));
1402    printf("--------------------------------------[ topwins  ]----------------------------------------------------------------------------------\n");
1403    if (e_info_client.hwc_windows)
1404      printf(" No   Win_ID    RcsID    PID     w     h       x      y   L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  HWC_ST  Parent   TP    Title\n");
1405    else
1406      printf(" No   Win_ID    RcsID    PID     w     h       x      y   L Zone Foc InReg Dep Opaq Vsbt Icon Vis Map  Frame  PL@ZPos Parent   TP    Title\n");
1407    printf("------------------------------------------------------------------------------------------------------------------------------------\n");
1408
1409    if (!e_info_client.win_list)
1410      {
1411         printf("no window\n");
1412         goto ec_info;
1413      }
1414
1415    EINA_LIST_FOREACH(e_info_client.win_list, l, win)
1416      {
1417         if (!win) goto ec_info;
1418         char tmp[20];
1419         i++;
1420         if (win->layer != prev_layer)
1421           {
1422              if (prev_layer != -1)
1423                 printf("------------------------------------------------------------------------------------------------------------------------------------[%s]\n",
1424                        prev_layer_name ? prev_layer_name : " ");
1425              prev_layer = win->layer;
1426              prev_layer_name = win->layer_name;
1427           }
1428
1429         if (win->hwc >= 0)
1430           {
1431              if (win->hwc_policy == E_HWC_POLICY_WINDOWS) // hwc windows
1432                {
1433                   switch(win->pl_zpos)
1434                     {
1435                      case E_HWC_WINDOW_STATE_NONE:   snprintf(tmp, sizeof(tmp), "  NO  "); break;
1436                      case E_HWC_WINDOW_STATE_CLIENT: snprintf(tmp, sizeof(tmp), "  CL  "); break;
1437                      case E_HWC_WINDOW_STATE_DEVICE: snprintf(tmp, sizeof(tmp), "  DV  "); break;
1438                      case E_HWC_WINDOW_STATE_VIDEO:  snprintf(tmp, sizeof(tmp), "  VD  "); break;
1439                      case E_HWC_WINDOW_STATE_CURSOR: snprintf(tmp, sizeof(tmp), "  CS  "); break;
1440                      default:                        snprintf(tmp, sizeof(tmp), "  -  "); break;
1441                     }
1442                }
1443              else // hwc planes
1444                {
1445                   if ((!win->iconic) && (win->frame_visible))
1446                     {
1447                        if (win->pl_zpos == -999)
1448                          snprintf(tmp, sizeof(tmp), " - ");
1449                        else
1450                          {
1451                             if (win->hwc) snprintf(tmp, sizeof(tmp), "hwc@%i", win->pl_zpos);
1452                             else snprintf(tmp, sizeof(tmp), "comp@%i", win->pl_zpos);
1453                          }
1454                     }
1455                   else
1456                     snprintf(tmp, sizeof(tmp), " - ");
1457                }
1458           }
1459         else
1460           {
1461              hwc_off = 1;
1462              snprintf(tmp, sizeof(tmp), " - ");
1463           }
1464
1465         printf("%3d 0x%08zx  %5d  %5d  %5d %5d %6d %6d  %c %2d   %c    %c   %3d  %2d   ", i, win->id, win->res_id, win->pid, win->w, win->h, win->x, win->y, win->is_apply_layout ? 'L':' ', win->zone_id, win->focused ? 'O':' ', win->has_input_region ? 'C':' ',win->alpha? 32:24, win->opaque);
1466         printf("%2d%c   %d   %d   %s   %3d    %-8s%-8zx %c  %s\n", win->visibility, win->force_obscured ? 'f':' ', win->iconic, win->vis, win->mapped? "V":"N", win->frame_visible, tmp, win->parent_id, win->parent_id?(win->transient_policy?'B':'A'):' ',win->name?:"No Name");
1467      }
1468
1469    if (prev_layer_name)
1470       printf("------------------------------------------------------------------------------------------------------------------------------------[%s]\n",
1471              prev_layer_name);
1472
1473    if(hwc_off)
1474      printf("\nHWC is disabled\n\n");
1475
1476    E_FREE_LIST(e_info_client.win_list, _e_win_info_free);
1477
1478 ec_info:
1479    _e_info_client_proc_ec_list_info(EINA_FALSE);
1480 }
1481
1482 static void
1483 _e_info_client_proc_compobjs_info(int argc, char **argv)
1484 {
1485    Eina_Bool res;
1486
1487    if ((argc == 3) && (argv[2]))
1488      {
1489         if (!strncmp(argv[2], "simple", 6))
1490           compobjs_simple = EINA_TRUE;
1491      }
1492
1493    res = _e_info_client_eldbus_message("compobjs",
1494                                        _e_info_client_cb_compobjs);
1495    EINA_SAFETY_ON_FALSE_RETURN(res);
1496 }
1497
1498 static void
1499 _e_info_client_proc_input_device_info(int argc, char **argv)
1500 {
1501    if (!_e_info_client_eldbus_message("get_input_devices", _cb_input_device_info_get))
1502      return;
1503 }
1504
1505 static void
1506 _e_info_client_proc_keymap_info(int argc, char **argv)
1507 {
1508    if (!_e_info_client_eldbus_message("get_keymap", _cb_input_keymap_info_get))
1509       return;
1510 }
1511
1512 static void
1513 _e_info_client_proc_module_info(int argc, char **argv)
1514 {
1515    char fd_name[PATH_MAX];
1516    int pid;
1517
1518    if (argc != 3 || !argv[2])
1519      {
1520         printf("Usage> enlightenment_info -module_info [module name]\n");
1521         return;
1522      }
1523
1524    pid = getpid();
1525
1526    snprintf(fd_name, PATH_MAX, "/proc/%d/fd/1", pid);
1527
1528    if (!_e_info_client_eldbus_message_with_args("get_module_info", NULL, "ss", argv[2], fd_name))
1529      return;
1530 }
1531
1532 static void
1533 _e_info_client_proc_keygrab_status(int argc, char **argv)
1534 {
1535    char fd_name[PATH_MAX + PATH_MAX];
1536    int pid;
1537    char cwd[PATH_MAX];
1538
1539    if (argc != 3 || !argv[2])
1540      {
1541         printf("Usage> enlightenment_info -keygrab_status [console | file path]\n");
1542         return;
1543      }
1544
1545    pid = getpid();
1546
1547    cwd[0] = '\0';
1548    if (!getcwd(cwd, sizeof(cwd)))
1549      snprintf(cwd, sizeof(cwd), "/tmp");
1550
1551    if (!strncmp(argv[2], "console", sizeof("console")))
1552      snprintf(fd_name, sizeof(fd_name), "/proc/%d/fd/1", pid);
1553    else
1554      {
1555         if (argv[2][0] == '/')
1556           snprintf(fd_name, sizeof(fd_name), "%s", argv[2]);
1557         else
1558           {
1559              if (strlen(cwd) > 0)
1560                snprintf(fd_name, sizeof(fd_name), "%s/%s", cwd, argv[2]);
1561              else
1562                snprintf(fd_name, sizeof(fd_name), "%s", argv[2]);
1563           }
1564      }
1565
1566    if (!_e_info_client_eldbus_message_with_args("get_keygrab_status", NULL, "s", fd_name))
1567      return;
1568 }
1569
1570 static char *
1571 _directory_make(char *type, char *path)
1572 {
1573    char dir[2048], curdir[1024], stamp[256];
1574    time_t timer;
1575    struct tm *t, *buf;
1576    char *fullpath;
1577    DIR *dp;
1578
1579    timer = time(NULL);
1580
1581    buf = calloc (1, sizeof (struct tm));
1582    EINA_SAFETY_ON_NULL_RETURN_VAL(buf, NULL);
1583
1584    t = localtime_r(&timer, buf);
1585    if (!t)
1586      {
1587         free(buf);
1588         printf("fail to get local time\n");
1589         return NULL;
1590      }
1591
1592    fullpath = (char*) calloc(1, PATH_MAX*sizeof(char));
1593    if (!fullpath)
1594      {
1595         free(buf);
1596         printf("fail to alloc pathname memory\n");
1597         return NULL;
1598      }
1599
1600    if (path && path[0] == '/')
1601      snprintf(dir, sizeof(dir), "%s", path);
1602    else
1603      {
1604         char *temp = getcwd(curdir, 1024);
1605         if (!temp)
1606           {
1607              free(buf);
1608              free(fullpath);
1609              return NULL;
1610           }
1611         if (path)
1612           {
1613              int len, cur_len;
1614              cur_len = strlen(curdir);
1615              len = sizeof(dir) - strlen(path) - cur_len - 2;
1616
1617              if (cur_len == 1 && curdir[0] == '/')
1618                snprintf(dir, sizeof(dir), "/%s", path);
1619              else if (len > 0)
1620                snprintf(dir, sizeof(dir), "%s/%s", curdir, path);
1621              else
1622                {
1623                   free(buf);
1624                   free(fullpath);
1625                   return NULL;
1626                }
1627           }
1628         else
1629           snprintf(dir, sizeof(dir), "%s", curdir);
1630      }
1631
1632    if (!(dp = opendir (dir)))
1633      {
1634         free(buf);
1635         free(fullpath);
1636         printf("not exist: %s\n", dir);
1637         return NULL;
1638      }
1639    else
1640       closedir (dp);
1641
1642    /* make the folder for the result of xwd files */
1643    snprintf(stamp, sizeof(stamp), "%04d%02d%02d.%02d%02d%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
1644
1645    if (strlen(dir) == 1 && dir[0] == '/')
1646      snprintf(fullpath, PATH_MAX, "/%s-%s", type, stamp);
1647    else
1648      snprintf(fullpath, PATH_MAX, "%s/%s-%s", dir, type, stamp);
1649
1650    free (buf);
1651
1652    if ((mkdir(fullpath, 0755)) < 0)
1653      {
1654         printf("fail: mkdir '%s'\n", fullpath);
1655         free(fullpath);
1656         return NULL;
1657      }
1658
1659    printf("directory: %s\n", fullpath);
1660
1661    return fullpath;
1662 }
1663
1664 static void
1665 _e_info_client_cb_dump_wins(const Eldbus_Message *msg)
1666 {
1667    const char *log = NULL;
1668    Eina_Bool res;
1669
1670    res = eldbus_message_arguments_get(msg, "s", &log);
1671    if (!res)
1672      {
1673         printf("Failed to get log of dump\n");
1674         return;
1675      }
1676
1677    if (log)
1678      printf("%s\n", log);
1679 }
1680
1681 static void
1682 _e_info_client_proc_wins_shot(int argc, char **argv)
1683 {
1684    char *directory = NULL;
1685    char *type = NULL;
1686
1687    if (eina_streq(argv[2], "topvwins") || eina_streq(argv[2], "ns") || eina_streq(argv[2], "hwc_wins"))
1688      {
1689         if (argc == 3)
1690           directory = _directory_make(argv[2], NULL);
1691         else if (argc == 4)
1692           directory = _directory_make(argv[2], argv[3]);
1693         else
1694           goto arg_err;
1695      }
1696
1697    if (!directory) goto arg_err;
1698
1699    type = argv[2];
1700    if (!_e_info_client_eldbus_message_with_args("dump_wins", _e_info_client_cb_dump_wins, SIGNATURE_DUMP_WINS, type, directory))
1701      {
1702         free(directory);
1703         return;
1704      }
1705
1706    free(directory);
1707
1708    return;
1709 arg_err:
1710    printf("Usage: enlightenment_info -dump %s\n", USAGE_DUMPIMAGE);
1711 }
1712
1713 static void
1714 _e_info_client_cb_force_visible(const Eldbus_Message *msg)
1715 {
1716    const char *name = NULL, *text = NULL;
1717    Eina_Bool res;
1718    const char *result = NULL;
1719
1720    res = eldbus_message_error_get(msg, &name, &text);
1721    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
1722
1723    res = eldbus_message_arguments_get(msg,
1724                                       SIGNATURE_FORCE_VISIBLE_SERVER,
1725                                       &result);
1726    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
1727
1728    printf("%s\n", result);
1729    return;
1730
1731 finish:
1732    if ((name) || (text))
1733      {
1734         printf("errname:%s errmsg:%s\n", name, text);
1735      }
1736 }
1737
1738 static void
1739 _e_info_client_proc_force_visible(int argc, char **argv)
1740 {
1741    unsigned int obj, visible;
1742    Eina_Bool res;
1743
1744    if (argc != 4)
1745       goto arg_err;
1746
1747    res = _util_string_to_uint(argv[2], &obj, 16);
1748    if (!res)
1749       goto arg_err;
1750
1751    res = _util_string_to_uint(argv[3], &visible, 10);
1752    if (!res)
1753       goto arg_err;
1754
1755    if (!_e_info_client_eldbus_message_with_args("set_force_visible", _e_info_client_cb_force_visible,
1756                                                 SIGNATURE_FORCE_VISIBLE_CLIENT,
1757                                                 obj, (visible) ? EINA_TRUE : EINA_FALSE))
1758       return;
1759
1760    return;
1761 arg_err:
1762    printf("Usage: enlightenment_info -set_force_visible [obj_pointer_address] [0 or 1]\n");
1763 }
1764
1765 static void
1766 _cb_subsurface_info_get(const Eldbus_Message *msg)
1767 {
1768    const char *name = NULL, *text = NULL;
1769    Eldbus_Message_Iter *array, *ec;
1770    Eina_Bool res;
1771    int count = 0;
1772
1773    res = eldbus_message_error_get(msg, &name, &text);
1774    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
1775
1776    res = eldbus_message_arguments_get(msg, "a("SIGNATURE_SUBSURFACE")", &array);
1777    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
1778
1779    printf("--------------------------------------[ subsurfaces ]---------------------------------------------------------\n");
1780    printf(" No     Win_ID  Parent_ID  Buf_ID    w    h    x    y Rot(f) Visi Alph Igno Mask Video Stand    BgRect   Title\n");
1781    printf("--------------------------------------------------------------------------------------------------------------\n");
1782
1783    while (eldbus_message_iter_get_and_next(array, 'r', &ec))
1784      {
1785         Ecore_Window win = 0, parent = 0, bgrect = 0;
1786         unsigned int buf_id = 0;
1787         int x = 0, y = 0, w = 0, h = 0;
1788         unsigned int transform = 0, visible = 0, alpha = 0, ignore = 0, maskobj = 0, video = 0, stand = 0;
1789         const char *name = NULL;
1790         char temp[128] = {0,};
1791
1792         res = eldbus_message_iter_arguments_get(ec,
1793                                                 SIGNATURE_SUBSURFACE,
1794                                                 &win, &parent,
1795                                                 &buf_id, &x, &y, &w, &h, &transform,
1796                                                 &visible, &alpha, &ignore, &maskobj, &video, &stand, &bgrect, &name);
1797         if (!res)
1798           {
1799              printf("Failed to get win info\n");
1800              continue;
1801           }
1802
1803         count++;
1804
1805         printf("%3d 0x%08zx ", count, win);
1806         temp[0] = '\0';
1807         if (parent > 0) snprintf(temp, sizeof(temp), "0x%08zx", parent);
1808         printf("%10s", temp);
1809         temp[0] = '\0';
1810         if (buf_id != 0)
1811           snprintf(temp, sizeof(temp), "%5u%c",
1812                    buf_id & (~WAYLAND_SERVER_RESOURCE_ID_MASK),
1813                    (buf_id & WAYLAND_SERVER_RESOURCE_ID_MASK) ? 's' : 'c');
1814         printf("  %6s", temp);
1815         printf(" %4d %4d %4d %4d %3d(%d) %4s %4s %4s %4s %4s %4s   ",
1816                w, h, x, y, (4 - (transform & 3)) * 90 % 360, (transform & 4) ? 1 : 0,
1817                (visible)?"O":"", (alpha)?"O":"", (ignore)?"O":"", (maskobj)?"O":"", (video)?"O":"", (stand)?"O":"");
1818         temp[0] = '\0';
1819         if (bgrect > 0) snprintf(temp, sizeof(temp), "0x%08zx", bgrect);
1820         printf("%10s", temp);
1821         printf(" %s\n", name);
1822      }
1823
1824    if (!count)
1825      printf("no subsurface\n");
1826
1827 finish:
1828    if ((name) || (text))
1829      printf("errname:%s errmsg:%s\n", name, text);
1830 }
1831
1832 static void
1833 _e_info_client_proc_subsurface(int argc, char **argv)
1834 {
1835    Eina_Bool res;
1836    res = _e_info_client_eldbus_message("subsurface", _cb_subsurface_info_get);
1837    EINA_SAFETY_ON_FALSE_RETURN(res);
1838 }
1839
1840 static void
1841 _e_info_client_proc_eina_log_levels(int argc, char **argv)
1842 {
1843    EINA_SAFETY_ON_FALSE_RETURN(argc == 3);
1844    EINA_SAFETY_ON_NULL_RETURN(argv[2]);
1845
1846    if (!_e_info_client_eldbus_message_with_args("eina_log_levels", NULL, "s", argv[2]))
1847      {
1848         return;
1849      }
1850 }
1851
1852 static void
1853 _e_info_client_proc_eina_log_path(int argc, char **argv)
1854 {
1855    char fd_name[PATH_MAX + PATH_MAX];
1856    int pid;
1857    char cwd[PATH_MAX];
1858
1859    EINA_SAFETY_ON_FALSE_RETURN(argc == 3);
1860    EINA_SAFETY_ON_NULL_RETURN(argv[2]);
1861
1862    pid = getpid();
1863
1864    cwd[0] = '\0';
1865    if (!getcwd(cwd, sizeof(cwd)))
1866      snprintf(cwd, sizeof(cwd), "/tmp");
1867
1868    if (!strncmp(argv[2], "console", 7))
1869      snprintf(fd_name, sizeof(fd_name), "/proc/%d/fd/1", pid);
1870    else
1871      {
1872         if (argv[2][0] == '/')
1873           snprintf(fd_name, sizeof(fd_name), "%s", argv[2]);
1874         else
1875           {
1876              if (strlen(cwd) > 0)
1877                snprintf(fd_name, sizeof(fd_name), "%s/%s", cwd, argv[2]);
1878              else
1879                snprintf(fd_name, sizeof(fd_name), "%s", argv[2]);
1880           }
1881      }
1882
1883    printf("eina-log-path: %s\n", fd_name);
1884
1885    if (!_e_info_client_eldbus_message_with_args("eina_log_path", NULL, "s", fd_name))
1886      {
1887         return;
1888      }
1889 }
1890
1891 #ifdef HAVE_DLOG
1892 static void
1893 _e_info_client_proc_dlog_switch(int argc, char **argv)
1894 {
1895    uint32_t onoff;
1896
1897    EINA_SAFETY_ON_FALSE_RETURN(argc == 3);
1898    EINA_SAFETY_ON_NULL_RETURN(argv[2]);
1899
1900    onoff = atoi(argv[2]);
1901    if ((onoff == 1) || (onoff == 0))
1902      {
1903
1904         if (!_e_info_client_eldbus_message_with_args("dlog", NULL, "i", onoff))
1905           {
1906              printf("Error to switch %s logging system using dlog logging.", onoff?"on":"off");
1907              return;
1908           }
1909         if (onoff)
1910           printf("Now you can try to track enlightenment log with dlog logging system.\n"
1911                  "Track dlog with LOGTAG \"E20\" ex) dlogutil E20\n");
1912         else
1913           printf("Logging of enlightenment with dlog is disabled.\n");
1914      }
1915 }
1916 #endif
1917
1918 #define PROP_USAGE \
1919    "0x<win_id> | -id win_id | -pid pid | -name \"win_name\" [property_name [property_value]]\n" \
1920    "Example:\n" \
1921    "\tenlightenment_info -prop                        : Get all properties for a window specified via a touch\n" \
1922    "\tenlightenment_info -prop Hidden                 : Get the \"Hidden\" property for a window specified via a touch\n" \
1923    "\tenlightenment_info -prop 0xb88ffaa0 Layer       : Get the \"Layer\" property for specified window\n" \
1924    "\tenlightenment_info -prop 0xb88ffaa0 Hidden TRUE : Set the \"Hidden\" property for specified window\n" \
1925    "\tenlightenment_info -prop -pid 2502 Hidden FALSE : Set the \"Hidden\" property for all windows belonged to a process\n" \
1926    "\tenlightenment_info -prop -name err              : Get all properties for windows whose names contain an \"err\" substring\n" \
1927    "\tenlightenment_info -prop -name \"\"               : Get all properties for all windows\n" \
1928    "\tenlightenment_info -prop -name \"\" Hidden TRUE   : Set the \"Hidden\" property for all windows\n"
1929
1930 /* property value can consist of several lines separated by '\n', which we got to print nicely */
1931 static void
1932 _parse_property(const char *prop_name, const char *prop_value)
1933 {
1934    char *begin, *end;   /* current line */
1935
1936    /* process a single line property value */
1937    if (!strchr(prop_value, '\n'))
1938      {
1939         printf("%27s : %s\n", prop_name, prop_value);
1940         return;
1941      }
1942
1943    char *const tmp = strdup(prop_value);
1944    if (!tmp)
1945      return;
1946
1947    begin = tmp;
1948
1949    while (*begin != '\0')
1950      {
1951        end = strchr(begin, '\n');
1952        if (end)
1953          *end = '\0';
1954
1955        printf("%27s : %s\n", begin == tmp ? prop_name : "", begin);
1956
1957        /* it's the last line */
1958        if (!end)
1959          break;
1960
1961        begin = end + 1;
1962      }
1963
1964    free(tmp);
1965 }
1966
1967 static void
1968 _cb_window_prop_get(const Eldbus_Message *msg)
1969 {
1970    const char *name = NULL, *text = NULL;
1971    Eldbus_Message_Iter *array, *ec;
1972    Eina_Bool res;
1973    int first_delimiter = 1;
1974
1975    res = eldbus_message_error_get(msg, &name, &text);
1976    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
1977
1978    res = eldbus_message_arguments_get(msg, "a(ss)", &array);
1979    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
1980
1981    while (eldbus_message_iter_get_and_next(array, 'r', &ec))
1982      {
1983         const char *title = NULL;
1984         const char *value = NULL;
1985
1986         res = eldbus_message_iter_arguments_get(ec,
1987                                                 "ss",
1988                                                 &title,
1989                                                 &value);
1990         if (!res)
1991           {
1992              printf("Failed to get win prop info\n");
1993              continue;
1994           }
1995
1996         if (title && !strncmp(title, "delimiter", sizeof("delimiter")))
1997           {
1998              if (first_delimiter)
1999                first_delimiter = 0;
2000              else
2001                printf("---------------------------------------------------------------------------------------------------------\n");
2002           }
2003         else
2004           _parse_property(title, value);
2005      }
2006
2007    return;
2008
2009 finish:
2010    printf("error:\n");
2011
2012    if ((name) || (text))
2013      {
2014         printf(" %s :: (%s)\n", name, text);
2015      }
2016 }
2017
2018 static void
2019 _e_info_client_prop_prop_info(int argc, char **argv)
2020 {
2021    const static int WINDOW_ID_MODE = 0;
2022    const static int WINDOW_PID_MODE = 1;
2023    const static int WINDOW_NAME_MODE = 2;
2024    const char *value;
2025    const char *property_name = "", *property_value = "";
2026    uint32_t mode = 0;
2027    int simple_mode = 1;
2028
2029    Ecore_Window win;
2030    char win_id[64] = {0, };
2031
2032    /* for a window specified via a touch */
2033    /* TODO: what's about a property with "0x" as a substring? (e.g. kyky0xkyky) */
2034    if (argc < 3 || (argv[2][0] != '-' && !strstr(argv[2], "0x")))
2035      {
2036         printf("Select the window whose property(ies) you wish to get/set\n");
2037         if (_e_get_window_under_touch(&win))
2038           {
2039              printf("Error: cannot get window under touch\n");
2040              return;
2041           }
2042
2043         snprintf(win_id, sizeof(win_id), "%lu", (unsigned long int)win);
2044
2045         mode = WINDOW_ID_MODE;
2046         value = win_id;
2047
2048         if (argc > 2) property_name  = argv[2];
2049         if (argc > 3) property_value = argv[3];
2050      }
2051    else
2052      {
2053         if (argv[2][0] == '-' && argc < 4) goto error;
2054
2055         if (argv[2][0] == '-')
2056           {
2057              if (!strcmp(argv[2], "-id")) mode = WINDOW_ID_MODE;
2058              else if (!strcmp(argv[2], "-pid")) mode = WINDOW_PID_MODE;
2059              else if (!strcmp(argv[2], "-name")) mode = WINDOW_NAME_MODE;
2060              else goto error;
2061
2062              value = argv[3];
2063
2064              simple_mode = 0;
2065           }
2066         else
2067           {
2068              mode = WINDOW_ID_MODE;
2069              value = argv[2];
2070           }
2071
2072         if (simple_mode)
2073           {
2074              if (argc > 3) property_name  = argv[3];
2075              if (argc > 4) property_value = argv[4];
2076           }
2077         else
2078           {
2079              if (argc > 4) property_name  = argv[4];
2080              if (argc > 5) property_value = argv[5];
2081           }
2082      }
2083
2084    /* all checks about win_id/pid/win_name, property_name, property_value sanity are performed on server side,
2085     * in case of an error an error message contained error description will be returned */
2086    if (!_e_info_client_eldbus_message_with_args("get_window_prop", _cb_window_prop_get, "usss",
2087            mode, value, property_name, property_value))
2088      printf("_e_info_client_eldbus_message_with_args error");
2089
2090    return;
2091
2092 error:
2093    printf("Error Check Args: enlightenment_info -prop [property_name [property_value]]\n"
2094           "                  enlightenment_info -prop 0x<win_id> [property_name [property_value]]\n"
2095           "                  enlightenment_info -prop -id win_id [property_name [property_value]]\n"
2096           "                  enlightenment_info -prop -pid pid [property_name [property_value]]\n"
2097           "                  enlightenment_info -prop -name win_name [property_name [property_value]]\n");
2098 }
2099
2100 static void
2101 _cb_window_proc_connected_clients_get(const Eldbus_Message *msg)
2102 {
2103    const char *name = NULL, *text = NULL;
2104    Eldbus_Message_Iter *array, *ec;
2105    Eina_Bool res;
2106
2107    res = eldbus_message_error_get(msg, &name, &text);
2108    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
2109
2110    res = eldbus_message_arguments_get(msg, "a(ss)", &array);
2111    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
2112
2113    printf("--------------------------------------[ connected clients ]-----------------------------------------------------\n");
2114    int cnt = 0;
2115    while (eldbus_message_iter_get_and_next(array, 'r', &ec))
2116      {
2117         const char *title;
2118         const char *value;
2119         res = eldbus_message_iter_arguments_get(ec,
2120                                                 "ss",
2121                                                 &title,
2122                                                 &value);
2123         if (!res)
2124           {
2125              printf("Failed to get connected clients info\n");
2126              continue;
2127           }
2128
2129         if (!strcmp(title, "[Connected Clients]"))
2130           {
2131              printf("\n[%2d] %s\n", ++cnt, value);
2132           }
2133         else if (!strcmp(title, "[E_Client Info]"))
2134           {
2135              printf("      |----- %s :: %s\n", title, value);
2136           }
2137      }
2138
2139 finish:
2140    if ((name) || (text))
2141      {
2142         printf("errname:%s errmsg:%s\n", name, text);
2143      }
2144 }
2145
2146 static void
2147 _e_info_client_proc_connected_clients(int argc, char **argv)
2148 {
2149    if (!_e_info_client_eldbus_message("get_connected_clients", _cb_window_proc_connected_clients_get))
2150      {
2151         printf("_e_info_client_eldbus_message error");
2152         return;
2153      }
2154 }
2155
2156 #define ROTATION_USAGE \
2157    "[COMMAND] [ARG]...\n" \
2158    "\tset     : Set the orientation of zone (Usage: set [zone-no] [rval(0|90|180|270)]\n" \
2159    "\tinfo    : Get the information of zone's rotation (Usage: info [zone-no]) (Not Implemented)\n" \
2160    "\tenable  : Enable the rotation of zone (Usage: enable [zone-no]\n" \
2161    "\tdisable : Disable the rotation of zone (Usage: disable [zone-no]\n"
2162
2163 static void
2164 _cb_rotation_query(const Eldbus_Message *msg)
2165 {
2166    (void)msg;
2167    /* TODO: need implementation */
2168 }
2169
2170 static void
2171 _e_info_client_proc_rotation(int argc, char **argv)
2172 {
2173    E_Info_Rotation_Message req;
2174    int32_t zone_num = -1;
2175    int32_t rval = -1;
2176    const int off_len = 2, cmd_len = 1;
2177    Eina_Bool res = EINA_FALSE;
2178
2179    if (argc < off_len + cmd_len)
2180      goto arg_err;
2181
2182    if (eina_streq(argv[off_len], "info"))
2183      {
2184         if (argc > off_len + cmd_len)
2185           zone_num = atoi(argv[off_len + 1]);
2186
2187         res = _e_info_client_eldbus_message_with_args("rotation_query",
2188                                                       _cb_rotation_query,
2189                                                       "i", zone_num);
2190      }
2191    else
2192      {
2193         if (eina_streq(argv[off_len], "set"))
2194           {
2195              if (argc < off_len + cmd_len + 1)
2196                goto arg_err;
2197              else if (argc > off_len + cmd_len + 1)
2198                {
2199                   zone_num = atoi(argv[off_len + 1]);
2200                   rval = atoi(argv[off_len + 2]);
2201                }
2202              else
2203                rval = atoi(argv[off_len + 1]);
2204
2205              if ((rval < 0) || (rval > 270) || (rval % 90 != 0))
2206                goto arg_err;
2207
2208              req = E_INFO_ROTATION_MESSAGE_SET;
2209           }
2210         else
2211           {
2212              if (argc > off_len + cmd_len)
2213                zone_num = atoi(argv[off_len + 1]);
2214
2215              if (eina_streq(argv[off_len], "enable"))
2216                req = E_INFO_ROTATION_MESSAGE_ENABLE;
2217              else if (eina_streq(argv[off_len], "disable"))
2218                req = E_INFO_ROTATION_MESSAGE_DISABLE;
2219              else
2220                goto arg_err;
2221           }
2222
2223         res = _e_info_client_eldbus_message_with_args("rotation_message",
2224                                                       NULL, "iii",
2225                                                       req, zone_num, rval);
2226      }
2227
2228    if (!res)
2229      printf("_e_info_client_eldbus_message_with_args error");
2230
2231    return;
2232 arg_err:
2233    printf("Usage: enlightenment_info -rotation %s", ROTATION_USAGE);
2234 }
2235
2236 #define RESLIST_USAGE \
2237    "[-tree|-p]\n" \
2238    "\t-tree     : All resources\n" \
2239    "\t-p {pid}  : Specify client pid\n"
2240
2241 enum
2242 {
2243    DEFAULT_SUMMARY = 0,
2244    TREE,
2245    PID
2246 };
2247
2248 static void
2249 _pname_get(pid_t pid, char *name, int size)
2250 {
2251    if (!name) return;
2252
2253    FILE *h;
2254    char proc[512], pname[512];
2255    size_t len;
2256
2257    snprintf(proc, 512,"/proc/%d/cmdline", pid);
2258
2259    h = fopen(proc, "r");
2260    if (!h) return;
2261
2262    len = fread(pname, sizeof(char), 512, h);
2263    if (len > 0)
2264      {
2265         if ('\n' == pname[len - 1])
2266           pname[len - 1] = '\0';
2267      }
2268
2269    fclose(h);
2270
2271    strncpy(name, pname, size);
2272 }
2273
2274
2275 static void
2276 _cb_disp_res_lists_get(const Eldbus_Message *msg)
2277 {
2278    const char *name = NULL, *text = NULL;
2279    Eldbus_Message_Iter *array, *resource;
2280    Eina_Bool res;
2281    int nClient = 0, nResource = 0;
2282    char temp[PATH_MAX];
2283    int pid = 0;
2284
2285    res = eldbus_message_error_get(msg, &name, &text);
2286    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
2287
2288    res = eldbus_message_arguments_get(msg, "a("VALUE_TYPE_REPLY_RESLIST")", &array);
2289    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
2290
2291    snprintf(temp, PATH_MAX,"%6s   %6s   %s   %s\n", "NO", "PID", "N_of_Res", "NAME");
2292    printf("%s",temp);
2293
2294    while (eldbus_message_iter_get_and_next(array, 'r', &resource))
2295      {
2296         char cmd[512] = {0, };
2297         const char *type;
2298         const char *item;
2299         uint32_t id = 0;
2300         res = eldbus_message_iter_arguments_get(resource,
2301                                                 VALUE_TYPE_REPLY_RESLIST,
2302                                                 &type,
2303                                                 &item,
2304                                                 &id);
2305         if (!res)
2306           {
2307              printf("Failed to get connected clients info\n");
2308              continue;
2309           }
2310         if (!strcmp(type, "[client]"))
2311           {
2312              pid = (int)id;
2313              nResource = 0;
2314              ++nClient;
2315           }
2316         else if (!strcmp(type, "[count]"))
2317           {
2318              nResource = (int)id;
2319              _pname_get(pid, cmd, sizeof(cmd));
2320
2321              printf("%6d   %6d   %4d      %9s\n", nClient, pid, nResource, cmd);
2322              pid = 0;
2323           }
2324      }
2325
2326 finish:
2327    if ((name) || (text))
2328      {
2329         printf("errname:%s errmsg:%s\n", name, text);
2330      }
2331 }
2332
2333 static void
2334 _cb_disp_res_lists_get_detail(const Eldbus_Message *msg)
2335 {
2336    const char *name = NULL, *text = NULL;
2337    Eldbus_Message_Iter *array, *resource;
2338    Eina_Bool res;
2339    int nClient = 0, nResource = 0;
2340
2341    res = eldbus_message_error_get(msg, &name, &text);
2342    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
2343
2344    res = eldbus_message_arguments_get(msg, "a("VALUE_TYPE_REPLY_RESLIST")", &array);
2345    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
2346
2347    while (eldbus_message_iter_get_and_next(array, 'r', &resource))
2348      {
2349         const char *type;
2350         const char *item;
2351         char cmd[512] = {0, };
2352         int pid = 0;
2353         uint32_t id = 0;
2354
2355         res = eldbus_message_iter_arguments_get(resource,
2356                                                 VALUE_TYPE_REPLY_RESLIST,
2357                                                 &type,
2358                                                 &item,
2359                                                 &id);
2360
2361         if (!res)
2362           {
2363              printf("Failed to get connected clients info\n");
2364              continue;
2365           }
2366         if (!strcmp(type, "[client]"))
2367           {
2368              nResource = 0;
2369              pid = (int)id;
2370              ++nClient;
2371              _pname_get(pid, cmd, sizeof(cmd));
2372              printf("[%2d] pid %d  (%s)\n", nClient, pid, cmd);
2373
2374           }
2375         else if (!strcmp(type, "[resource]"))
2376           {
2377              ++nResource;
2378              printf("      |----- %s obj@%u\n", item, id);
2379           }
2380
2381      }
2382
2383 finish:
2384    if ((name) || (text))
2385      {
2386         printf("errname:%s errmsg:%s\n", name, text);
2387      }
2388 }
2389
2390 static void
2391 _e_info_client_proc_res_lists(int argc, char **argv)
2392 {
2393    uint32_t mode;
2394    int pid = 0;
2395
2396    if (argc == 2)
2397      {
2398         mode = DEFAULT_SUMMARY;
2399         if (!_e_info_client_eldbus_message_with_args("get_res_lists", _cb_disp_res_lists_get, VALUE_TYPE_REQUEST_RESLIST, mode, pid))
2400           {
2401              printf("%s error\n", __FUNCTION__);
2402              return;
2403           }
2404      }
2405    else if (argc == 3)
2406      {
2407         if (eina_streq(argv[2], "-tree")) mode = TREE;
2408         else goto arg_err;
2409
2410         if (!_e_info_client_eldbus_message_with_args("get_res_lists", _cb_disp_res_lists_get_detail, VALUE_TYPE_REQUEST_RESLIST, mode, pid))
2411           {
2412              printf("%s error\n", __FUNCTION__);
2413              return;
2414           }
2415      }
2416    else if (argc == 4)
2417      {
2418         if (eina_streq(argv[2], "-p"))
2419           {
2420              mode = PID;
2421              pid = atoi(argv[3]);
2422              if (pid <= 0) goto arg_err;
2423           }
2424         else goto arg_err;
2425
2426         if (!_e_info_client_eldbus_message_with_args("get_res_lists", _cb_disp_res_lists_get_detail, VALUE_TYPE_REQUEST_RESLIST, mode, pid))
2427           {
2428              printf("%s error\n", __FUNCTION__);
2429              return;
2430           }
2431      }
2432    else goto arg_err;
2433
2434    return;
2435 arg_err:
2436    printf("Usage: enlightenment_info -reslist\n%s", RESLIST_USAGE);
2437
2438 }
2439
2440 static Eina_Bool
2441 _opt_parse(char *opt, char *delims, int *vals, int n_vals)
2442 {
2443    Eina_Bool res;
2444    int n, i;
2445
2446    EINA_SAFETY_ON_FALSE_RETURN_VAL(n_vals > 0, EINA_FALSE);
2447
2448    for (i = 0; i < n_vals; i++)
2449      {
2450         res = _util_string_to_int_token(opt, &opt, &n, 10);
2451         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
2452
2453         vals[i] = n;
2454
2455         if ((strlen(opt) == 0) || (i == (n_vals - 1)))
2456           return EINA_TRUE;
2457
2458         EINA_SAFETY_ON_TRUE_RETURN_VAL((*opt != delims[i]), EINA_FALSE);
2459
2460         opt = opt + 1;
2461      }
2462
2463    return EINA_TRUE;
2464 }
2465
2466 static void
2467 _e_info_client_proc_bgcolor_set(int argc, char **argv)
2468 {
2469    int r = 0, g = 0, b = 0, a = 0;
2470    char delims_col[] = { ',', ',', ',', '\0' };
2471    int vals_col[] = { 0, 0, 0, 0};
2472    Eina_Bool res;
2473
2474    if (argc < 2)
2475      goto error_msg;
2476
2477    res = _opt_parse(argv[2], delims_col, vals_col, (sizeof(vals_col) / sizeof(int)));
2478
2479    if (!res)
2480      goto error_msg;
2481
2482    a = vals_col[0];
2483    r = vals_col[1];
2484    g = vals_col[2];
2485    b = vals_col[3];
2486
2487    printf("(A, R, G, B) : %d, %d, %d, %d\n", a, r, g, b);
2488
2489    res = _e_info_client_eldbus_message_with_args("bgcolor_set", NULL, "iiii", a, r, g, b);
2490    EINA_SAFETY_ON_FALSE_RETURN(res);
2491
2492    return;
2493
2494 error_msg:
2495    printf("Wrong argument(s)! (<a>,<r>,<g>,<b>)\n");
2496    return;
2497 }
2498
2499 static void
2500 _e_info_client_proc_punch(int argc, char **argv)
2501 {
2502    int onoff = 0, x = 0, y = 0, w = 0, h = 0;
2503    int a = 0, r = 0, g = 0, b = 0;
2504    char delims_geom[] = { 'x', '+', '+', '\0' };
2505    int vals_geom[] = { 0, 0, 0, 0 };
2506    char delims_col[] = { ',', ',', ',', '\0' };
2507    int vals_col[] = { 0, 0, 0, 0 };
2508    Eina_Bool res = EINA_FALSE;
2509
2510    EINA_SAFETY_ON_FALSE_GOTO(argc >= 3, wrong_args);
2511    EINA_SAFETY_ON_NULL_GOTO(argv[2], wrong_args);
2512
2513    if (!strncmp(argv[2], "on", 2)) onoff = 1;
2514
2515    if (argc >= 4 && argv[3])
2516      {
2517         res = _opt_parse(argv[3], delims_geom, vals_geom, (sizeof(vals_geom) / sizeof(int)));
2518         EINA_SAFETY_ON_FALSE_GOTO(res, wrong_args);
2519
2520         w = vals_geom[0]; h = vals_geom[1]; x = vals_geom[2]; y = vals_geom[3];
2521      }
2522
2523    if (argc >= 5 && argv[4])
2524      {
2525         res = _opt_parse(argv[4], delims_col, vals_col, (sizeof(vals_col) / sizeof(int)));
2526         EINA_SAFETY_ON_FALSE_GOTO(res, wrong_args);
2527
2528         a = vals_col[0]; r = vals_col[1]; g = vals_col[2]; b = vals_col[3];
2529      }
2530
2531    res = _e_info_client_eldbus_message_with_args("punch", NULL, "iiiiiiiii", onoff, x, y, w, h, a, r, g, b);
2532    if (!res) printf("Error occured while send send message\n\n");
2533
2534    return;
2535
2536 wrong_args:
2537    printf("wrong geometry arguments(<w>x<h>+<x>+<y>\n");
2538    printf("wrong color arguments(<a>,<r>,<g>,<b>)\n");
2539 }
2540
2541 static void
2542 _e_info_client_proc_transform_set(int argc, char **argv)
2543 {
2544    int32_t id_enable_xy_sxsy_angle[8];
2545    const char *role = "winfo test";
2546    int i;
2547
2548    if (argc < 11)
2549      {
2550         printf("Error Check Args: enlightenment_info -transform [windowID] [transform id] [enable] [x] [y] [scale_x(percent)] [scale_y(percent)] [degree] [background] [role(optional)]\n");
2551         return;
2552      }
2553
2554    id_enable_xy_sxsy_angle[0] = 0;      // transform id
2555    id_enable_xy_sxsy_angle[1] = 1;      // enable
2556    id_enable_xy_sxsy_angle[2] = 0;      // move x
2557    id_enable_xy_sxsy_angle[3] = 0;      // move y
2558    id_enable_xy_sxsy_angle[4] = 100;    // scale x percent
2559    id_enable_xy_sxsy_angle[5] = 100;    // scale y percent
2560    id_enable_xy_sxsy_angle[6] = 0;      // rotation degree
2561    id_enable_xy_sxsy_angle[7] = 0;      // background
2562
2563    for (i = 0 ; i < 8 &&  i+3 < argc; ++i)
2564       id_enable_xy_sxsy_angle[i] = atoi(argv[i+3]);
2565
2566    if (argc == 12)
2567      role = argv[11];
2568
2569    if (!_e_info_client_eldbus_message_with_args("transform_message", NULL, "siiiiiiiis",
2570                                                 argv[2], id_enable_xy_sxsy_angle[0] , id_enable_xy_sxsy_angle[1], id_enable_xy_sxsy_angle[2],
2571                                                 id_enable_xy_sxsy_angle[3], id_enable_xy_sxsy_angle[4], id_enable_xy_sxsy_angle[5],
2572                                                 id_enable_xy_sxsy_angle[6], id_enable_xy_sxsy_angle[7], role))
2573      {
2574         printf("_e_info_client_eldbus_message_with_args error");
2575         return;
2576      }
2577 }
2578
2579 #define DUMP_BUFFERS_USAGE \
2580   "  enlightenment_info -dump_buffers [ARG]...\n" \
2581   "  enlightenment_info -dump_buffers 1                : start dump buffer (default - buffer_count:100, path:/tmp/dump_xxxx/\n" \
2582   "  enlightenment_info -dump_buffers 1 -m             : start dump buffer with marking of various color\n" \
2583   "  enlightenment_info -dump_buffers 1 -c 50          : start dump buffer with 50 buffers\n" \
2584   "  enlightenment_info -dump_buffers 1 -p /tmp/test   : start dump buffer - the dump path is '/tmp/test/dump_xxxx'\n" \
2585   "  enlightenment_info -dump_buffers 1 -c 60 -p /test : start dump buffer with 60 buffers to '/test/dump_xxxx' folder\n" \
2586   "  enlightenment_info -dump_buffers 0                : stop dump buffer (store dump files to dump path)\n" \
2587   "  enlightenment_info -dump_buffers 1 -s 0.5         : start dump buffer with 0.5 scale factor\n" \
2588   "  enlightenment_info -dump_buffers 1 -w Wind_ID or server or client : start dump buffer with specific window or server or client\n" \
2589   "  enlightenment_info -dump_selected_buffers Win_ID(from enlightenment_info -topvwins)   : dump Win_ID(store dump files to dump path)\n" \
2590
2591 static char *
2592 _buffer_shot_directory_check(char *path)
2593 {
2594    char dir[PATH_MAX], curdir[1024];
2595    char *fullpath;
2596    DIR *dp;
2597
2598    fullpath = (char*)calloc(1, PATH_MAX * sizeof(char));
2599    if (!fullpath)
2600      {
2601         printf("fail to alloc pathname memory\n");
2602         return NULL;
2603      }
2604
2605    if (path && path[0] == '/')
2606      snprintf(dir, PATH_MAX, "%s", path);
2607    else
2608      {
2609         char *temp = getcwd(curdir, 1024);
2610         if (!temp)
2611           {
2612              free(fullpath);
2613              return NULL;
2614           }
2615         if (path)
2616           {
2617              if (strlen(curdir) == 1 && curdir[0] == '/')
2618                snprintf(dir, PATH_MAX, "/%s", path);
2619              else
2620                snprintf(dir, PATH_MAX, "%s/%s", curdir, path);
2621           }
2622         else
2623           snprintf(dir, PATH_MAX, "%s", curdir);
2624      }
2625
2626    if (!(dp = opendir(dir)))
2627      {
2628         free(fullpath);
2629         printf("not exist: %s\n", dir);
2630         return NULL;
2631      }
2632    else
2633       closedir (dp);
2634
2635    snprintf(fullpath, PATH_MAX, "%s", dir);
2636
2637    return fullpath;
2638 }
2639
2640 static void
2641 _e_info_client_proc_desk(int argc, char **argv)
2642 {
2643    const int offset = 2, cmd_len = 1;
2644    Eina_Bool res = EINA_FALSE;
2645
2646    if (argc < offset + cmd_len)
2647      goto arg_err;
2648
2649    if (eina_streq(argv[offset], "geometry"))
2650      {
2651         const int narg = 4;
2652         int geom[narg];
2653         int i;
2654
2655         if (argc < offset + cmd_len + narg)
2656           goto arg_err;
2657
2658         for (i = 0; i < narg; i++)
2659           geom[i] = atoi(argv[offset + cmd_len + i]);
2660
2661         if ((geom[2] < 0) || (geom[3] < 0))
2662           {
2663              printf("Error Check Args: Width(%d) and Height(%d) must not be less than 1.\n", geom[2], geom[3]);
2664              return;
2665           }
2666
2667         res = _e_info_client_eldbus_message_with_args("desktop_geometry_set", NULL, "iiii",
2668                                                       geom[0], geom[1], geom[2], geom[3]);
2669      }
2670    else if (eina_streq(argv[offset], "zoom"))
2671      {
2672         const int narg = 4;
2673         double zx, zy;
2674         int cx, cy;
2675
2676         if (argc < offset + cmd_len + narg)
2677           goto arg_err;
2678
2679         zx = atof(argv[offset + cmd_len]);
2680         zy = atof(argv[offset + cmd_len + 1]);
2681         cx = atoi(argv[offset + cmd_len + 2]);
2682         cy = atoi(argv[offset + cmd_len + 3]);
2683
2684         res = _e_info_client_eldbus_message_with_args("desk_zoom", NULL, "ddii",
2685                                                       zx, zy, cx, cy);
2686      }
2687    else if (eina_streq(argv[offset], "iconify"))
2688      {
2689         int option = 0;
2690         res = _e_info_client_eldbus_message_with_args("desktop_window_control", NULL, "i", option);
2691      }
2692    else if (eina_streq(argv[offset], "restore"))
2693      {
2694         int option = 1;
2695         res = _e_info_client_eldbus_message_with_args("desktop_window_control", NULL, "i", option);
2696      }
2697    else if (eina_streq(argv[offset], "clear"))
2698      {
2699         int option = 2;
2700         res = _e_info_client_eldbus_message_with_args("desktop_window_control", NULL, "i", option);
2701      }
2702    else if (eina_streq(argv[offset], "iconify_toggle"))
2703      {
2704         int option = 3;
2705         res = _e_info_client_eldbus_message_with_args("desktop_window_control", NULL, "i", option);
2706      }
2707
2708    if (!res)
2709      {
2710         printf("_e_info_client_eldbus_message_with_args error");
2711         return;
2712      }
2713
2714    return;
2715 arg_err:
2716    printf("Usage: enlightenment_info -desk\n");
2717 }
2718
2719 static void
2720 _e_info_client_proc_desk_area(int argc, char **argv)
2721 {
2722    const int offset = 2, base_cmd_len = 1;
2723    Eina_Bool res = EINA_FALSE;
2724    int sub_cmd_len = 0;
2725
2726    if (argc < offset + base_cmd_len)
2727      goto arg_err;
2728
2729    if (eina_streq(argv[offset], "info"))
2730      {
2731         res = _e_info_client_eldbus_message("desk_area_info", NULL);
2732      }
2733    else if (eina_streq(argv[offset], "enable"))
2734      {
2735         sub_cmd_len = 1;
2736         if (argc < offset + base_cmd_len + sub_cmd_len)
2737           goto arg_err;
2738
2739         uint32_t enable;
2740         enable = atoi(argv[offset+1]);
2741
2742         if (enable == 1 || enable == 0)
2743           {
2744              res = _e_info_client_eldbus_message_with_args("desk_area_enable", NULL, "i", enable);
2745           }
2746      }
2747    else if (eina_streq(argv[offset], "make_sub1"))
2748      {
2749         sub_cmd_len = 5;
2750         if (argc < offset + base_cmd_len + sub_cmd_len)
2751           goto arg_err;
2752
2753         int x, y, w, h, layer;
2754
2755         x = atoi(argv[offset + base_cmd_len]);
2756         y = atoi(argv[offset + base_cmd_len + 1]);
2757         w = atoi(argv[offset + base_cmd_len + 2]);
2758         h = atoi(argv[offset + base_cmd_len + 3]);
2759         layer = atoi(argv[offset + base_cmd_len + 4]);
2760
2761         res = _e_info_client_eldbus_message_with_args("desk_area_new_sub1", NULL, "iiiii", x, y, w, h, layer);
2762      }
2763    else if (eina_streq(argv[offset], "make_sub2"))
2764      {
2765         sub_cmd_len = 5;
2766         if (argc < offset + base_cmd_len + sub_cmd_len)
2767           goto arg_err;
2768
2769         int x, y, w, h, layer;
2770
2771         x = atoi(argv[offset + base_cmd_len]);
2772         y = atoi(argv[offset + base_cmd_len + 1]);
2773         w = atoi(argv[offset + base_cmd_len + 2]);
2774         h = atoi(argv[offset + base_cmd_len + 3]);
2775         layer = atoi(argv[offset + base_cmd_len + 4]);
2776
2777         res = _e_info_client_eldbus_message_with_args("desk_area_new_sub2", NULL, "iiiii", x, y, w, h, layer);
2778      }
2779    else if (eina_streq(argv[offset], "remove_sub1"))
2780      {
2781         uint32_t id = 1;
2782         res = _e_info_client_eldbus_message_with_args("desk_area_remove_sub", NULL, "i", id);
2783      }
2784    else if (eina_streq(argv[offset], "remove_sub2"))
2785      {
2786         uint32_t id = 2;
2787         res = _e_info_client_eldbus_message_with_args("desk_area_remove_sub", NULL, "i", id);
2788      }
2789    else if (eina_streq(argv[offset], "raise_base"))
2790      {
2791         sub_cmd_len = 1;
2792         if (argc < offset + base_cmd_len + sub_cmd_len)
2793           goto arg_err;
2794
2795         uint32_t raise;
2796         raise = atoi(argv[offset+1]);
2797
2798         if (raise == 1 || raise == 0)
2799           {
2800              res = _e_info_client_eldbus_message_with_args("desk_area_base_raise", NULL, "i", raise);
2801           }
2802      }
2803    else if (eina_streq(argv[offset], "raise_sub1"))
2804      {
2805         sub_cmd_len = 1;
2806         if (argc < offset + base_cmd_len + sub_cmd_len)
2807           goto arg_err;
2808
2809         uint32_t raise;
2810         raise = atoi(argv[offset+1]);
2811
2812         if (raise == 1 || raise == 0)
2813           {
2814              res = _e_info_client_eldbus_message_with_args("desk_area_sub1_raise", NULL, "i", raise);
2815           }
2816      }
2817    else if (eina_streq(argv[offset], "raise_sub2"))
2818      {
2819         sub_cmd_len = 1;
2820         if (argc < offset + base_cmd_len + sub_cmd_len)
2821           goto arg_err;
2822
2823         uint32_t raise;
2824         raise = atoi(argv[offset+1]);
2825
2826         if (raise == 1 || raise == 0)
2827           {
2828              res = _e_info_client_eldbus_message_with_args("desk_area_sub2_raise", NULL, "i", raise);
2829           }
2830      }
2831    else if (eina_streq(argv[offset], "check_stack"))
2832      {
2833         res = _e_info_client_eldbus_message("desk_area_check_stack", NULL);
2834      }
2835
2836    else
2837      goto arg_err;
2838
2839    if (!res)
2840      {
2841         printf("_e_info_client_eldbus_message_with_args error");
2842         return;
2843      }
2844
2845    return;
2846 arg_err:
2847    printf("Usage: enlightenment_info -desk_area -h\n");
2848 }
2849
2850 static void
2851 _cb_buffer_shot(const Eldbus_Message *msg)
2852 {
2853    const char *name = NULL, *text = NULL;
2854    char *fullpath = NULL;
2855    int error = 0;
2856    Eina_Bool res;
2857
2858    res = eldbus_message_error_get(msg, &name, &text);
2859    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
2860
2861    res = eldbus_message_arguments_get(msg, "is", &error, &fullpath);
2862    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
2863
2864    if (strcmp(fullpath, "nopath") && !e_info_client.dump_fullpath)
2865      e_info_client.dump_fullpath = eina_stringshare_add(fullpath);
2866    e_info_client.dump_success = error;
2867
2868 finish:
2869    if ((name) || (text))
2870      {
2871         printf("errname:%s errmsg:%s\n", name, text);
2872      }
2873 }
2874
2875 static void
2876 _e_info_client_proc_buffer_shot(int argc, char **argv)
2877 {
2878    const char *win_id = "";
2879    int dumprun = 0;
2880    int count = 100;
2881    int i;
2882    char path[PATH_MAX];
2883    double scale = 0.0;
2884    int mark = 0;
2885
2886    strncpy(path, "/tmp", PATH_MAX);
2887
2888    EINA_SAFETY_ON_TRUE_GOTO(argc < 3, err);
2889
2890    dumprun = atoi(argv[2]);
2891
2892    EINA_SAFETY_ON_TRUE_GOTO(dumprun < 0 || dumprun > 1, err);
2893
2894    for (i = 3; i < argc; i++)
2895      {
2896         if (eina_streq(argv[i], "-c"))
2897           {
2898              if (++i >= argc || (argv[i][0] < '0' || argv[i][0] > '9'))
2899                {
2900                   printf("Error: -c requires argument\n");
2901                   goto err;
2902                }
2903              count = atoi(argv[i]);
2904              EINA_SAFETY_ON_TRUE_GOTO(count < 1, err);
2905              continue;
2906           }
2907
2908           if (eina_streq(argv[i], "-p"))
2909             {
2910                int str_len;
2911                char *tmp_path;
2912
2913                if (++i >= argc)
2914                  {
2915                     printf("Error: -p requires argument\n");
2916                     goto err;
2917                  }
2918                tmp_path = _buffer_shot_directory_check(argv[i]);
2919                if (tmp_path == NULL)
2920                  {
2921                     printf("cannot find directory: %s\n", argv[i]);
2922                     goto err;
2923                  }
2924
2925                str_len = strlen(tmp_path);
2926                if (str_len >= PATH_MAX) str_len = PATH_MAX - 1;
2927
2928                strncpy(path, tmp_path, str_len);
2929                path[str_len] = 0;
2930
2931                free(tmp_path);
2932                continue;
2933             }
2934           if (eina_streq(argv[i], "-s"))
2935             {
2936                if (++i >= argc || (argv[i][0] < '0' || argv[i][0] > '9'))
2937                  {
2938                     printf("Error: -s requires argument\n");
2939                     goto err;
2940                  }
2941                scale = atof(argv[i]);
2942                EINA_SAFETY_ON_TRUE_GOTO(scale <= 0.0, err);
2943                continue;
2944             }
2945           if (eina_streq(argv[i], "-m"))
2946             {
2947                ++i;
2948                mark = 1;
2949                continue;
2950             }
2951
2952           if (eina_streq(argv[i], "-w"))
2953             {
2954                if (++i >= argc)
2955                  {
2956                     printf("Error: -w requires argument\n");
2957                     goto err;
2958                  }
2959
2960                win_id = argv[i];
2961                continue;
2962             }
2963
2964           goto err;
2965      }
2966
2967    if (!_e_info_client_eldbus_message_with_args_timeout("dump_buffers", _cb_buffer_shot,
2968                                                         ELDBUS_TIMEOUT_INFINITE, "iisdis",
2969                                                         dumprun, count, path, scale, mark, win_id))
2970      {
2971         printf("dump_buffers fail (%d)\n", dumprun);
2972         return;
2973      }
2974
2975    printf("dump_buffers %s %s.\n",
2976           (dumprun == 1 ? "start" : "stop"), (e_info_client.dump_success == 0 ? "success" : "fail"));
2977
2978    if (e_info_client.dump_fullpath)
2979      {
2980         if (dumprun == 0 && e_info_client.dump_success == 0 && e_info_client.dump_fullpath)
2981           printf("saved : %s\n", e_info_client.dump_fullpath);
2982
2983         eina_stringshare_del(e_info_client.dump_fullpath);
2984         e_info_client.dump_fullpath = NULL;
2985      }
2986
2987    return;
2988
2989 err:
2990    printf("Error Check Args\n%s\n", DUMP_BUFFERS_USAGE);
2991    return;
2992 }
2993
2994 static void
2995 _e_info_client_cb_selected_buffer(const Eldbus_Message *msg)
2996 {
2997    const char *log = NULL;
2998    Eina_Bool res;
2999
3000    res = eldbus_message_arguments_get(msg, "s", &log);
3001    if (!res)
3002      {
3003         printf("Failed to get log of dump\n");
3004         return;
3005      }
3006
3007    if (log)
3008      printf("%s\n", log);
3009 }
3010
3011 static void
3012 _e_info_client_proc_selected_buffer_shot(int argc, char **argv)
3013 {
3014    const char *win_id=NULL;
3015    char path[PATH_MAX];
3016
3017    strncpy(path, "/tmp", PATH_MAX);
3018    if (argc == 3)
3019      {
3020         win_id = argv[2];
3021
3022         if (!_e_info_client_eldbus_message_with_args("dump_selected_buffers", _e_info_client_cb_selected_buffer, "ss", win_id, path))
3023           {
3024              printf("_e_info_client_proc_selected_buffer_shot fail (%s)\n", win_id);
3025              return;
3026           }
3027      }
3028    else
3029      goto err;
3030
3031    return;
3032
3033 err:
3034    printf("Error Check Args\n%s\n", DUMP_BUFFERS_USAGE);
3035 return;
3036 }
3037
3038 static Eina_Bool
3039 _e_info_client_proc_screen_shot_name_check(const char *name, int length)
3040 {
3041    if (length < 5)
3042      return EINA_FALSE;
3043
3044    if (name[length - 1] != 'g' || name[length - 2] != 'n' ||
3045        name[length - 3] != 'p' || name[length - 4] != '.')
3046      return EINA_FALSE;
3047
3048    return EINA_TRUE;
3049 }
3050
3051 static void
3052 _e_info_client_proc_screen_shot(int argc, char **argv)
3053 {
3054    int i;
3055    char *path = NULL;
3056    char *name = NULL;
3057    char *fname = NULL;
3058    int path_len = 0;
3059    int name_len = 0;
3060    Eina_Bool p = EINA_FALSE;
3061    Eina_Bool n = EINA_FALSE;
3062
3063    for (i = 2; i < argc; i++)
3064      {
3065         if (eina_streq(argv[i], "-p"))
3066           {
3067              char *tmp_path;
3068
3069              if (++i >= argc)
3070                {
3071                   printf("Error: -p requires argument\n");
3072                   goto err;
3073                }
3074
3075              tmp_path = _buffer_shot_directory_check(argv[i]);
3076              if (tmp_path == NULL)
3077                {
3078                   printf("cannot find directory: %s, make directory before dump\n", argv[i]);
3079                   goto err;
3080                }
3081              free(tmp_path);
3082
3083              path = argv[i];
3084              p = EINA_TRUE;
3085
3086              continue;
3087           }
3088         if (eina_streq(argv[i], "-n"))
3089           {
3090              if (++i >= argc)
3091                {
3092                   printf("Error: -n requires argument\n");
3093                   goto err;
3094                }
3095
3096              name = argv[i];
3097              n = EINA_TRUE;
3098
3099              continue;
3100           }
3101      }
3102
3103    if (!p)
3104      {
3105         path = (char *)calloc(1, PATH_MAX * sizeof(char));
3106         EINA_SAFETY_ON_NULL_RETURN(path);
3107         strncpy(path, "/tmp/", PATH_MAX);
3108      }
3109    if (!n)
3110      {
3111         name = (char *)calloc(1, PATH_MAX * sizeof(char));
3112         EINA_SAFETY_ON_NULL_GOTO(name, err);
3113         strncpy(name, "dump_screen.png", PATH_MAX);
3114      }
3115
3116    if ((!path) || (!name)) goto err;
3117
3118    path_len = strlen(path);
3119    name_len = strlen(name);
3120
3121    if (n)
3122      {
3123         if (!_e_info_client_proc_screen_shot_name_check(name, name_len))
3124           {
3125              printf("Error: support only 'png' file\n       write like -n xxx.png\n");
3126              goto err;
3127           }
3128      }
3129
3130    if (path_len + name_len >= PATH_MAX)
3131      {
3132         printf("_e_info_client_proc_screen_shot fail. long name\n");
3133         goto err;
3134      }
3135
3136    fname = (char *)calloc(1, PATH_MAX * sizeof(char));
3137    EINA_SAFETY_ON_NULL_GOTO(fname, err);
3138    if (path[path_len - 1] == '/')
3139      snprintf(fname, PATH_MAX, "%s%s", path, name);
3140    else
3141      snprintf(fname, PATH_MAX, "%s/%s", path, name);
3142
3143    printf("make dump: %s\n", fname);
3144
3145    if (!_e_info_client_eldbus_message_with_args("dump_screen", NULL, "s", fname))
3146      printf("_e_info_client_proc_screen_shot fail\n");
3147
3148 err:
3149    if (!p) free(path);
3150    if (!n) free(name);
3151    if (fname) free(fname);
3152
3153    return;
3154 }
3155
3156
3157 static E_Info_Output_Mode *
3158 _e_output_mode_info_new(uint32_t h, uint32_t hsync_start, uint32_t hsync_end, uint32_t htotal,
3159                         uint32_t v, uint32_t vsync_start, uint32_t vsync_end, uint32_t vtotal,
3160                         uint32_t refresh, uint32_t vscan, uint32_t clock, uint32_t flags,
3161                         int current, int output, int connect, const char *name, int dpms)
3162 {
3163    E_Info_Output_Mode *mode = NULL;
3164
3165    mode = E_NEW(E_Info_Output_Mode, 1);
3166    EINA_SAFETY_ON_NULL_RETURN_VAL(mode, NULL);
3167
3168    mode->hdisplay = h;
3169    mode->hsync_start = hsync_start;
3170    mode->hsync_end = hsync_end;
3171    mode->htotal = htotal;
3172    mode->vdisplay = v;
3173    mode->vsync_start = vsync_start;
3174    mode->vsync_end = vsync_end;
3175    mode->vtotal = vtotal;
3176    mode->refresh = refresh;
3177    mode->vscan = vscan;
3178    mode->clock = clock;
3179    mode->flags = flags;
3180    mode->current = current;
3181    mode->output = output;
3182    mode->connect = connect;
3183    mode->name = eina_stringshare_add(name);
3184    mode->dpms = dpms;
3185
3186    return mode;
3187 }
3188
3189 static void
3190 _e_output_mode_info_free(E_Info_Output_Mode *mode)
3191 {
3192    EINA_SAFETY_ON_NULL_RETURN(mode);
3193
3194    if (mode->name)
3195      eina_stringshare_del(mode->name);
3196
3197    E_FREE(mode);
3198 }
3199
3200 static void
3201 _cb_output_mode_info(const Eldbus_Message *msg)
3202 {
3203    const char *name = NULL, *text = NULL;
3204    Eldbus_Message_Iter *array, *ec;
3205    Eina_Bool res;
3206    int gl = 0;
3207
3208    res = eldbus_message_error_get(msg, &name, &text);
3209    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
3210
3211    res = eldbus_message_arguments_get(msg, "a("SIGNATURE_OUTPUT_MODE_SERVER")", &array);
3212    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
3213
3214    while (eldbus_message_iter_get_and_next(array, 'r', &ec))
3215      {
3216         uint32_t h, hsync_start, hsync_end, htotal;
3217         uint32_t v, vsync_start, vsync_end, vtotal;
3218         uint32_t refresh, vscan, clock, flag;
3219         int current, output, connect, dpms;
3220         const char *name;
3221         E_Info_Output_Mode *mode = NULL;
3222         res = eldbus_message_iter_arguments_get(ec,
3223                                                 SIGNATURE_OUTPUT_MODE_SERVER,
3224                                                 &h, &hsync_start, &hsync_end, &htotal,
3225                                                 &v, &vsync_start, &vsync_end, &vtotal,
3226                                                 &refresh, &vscan, &clock, &flag, &name,
3227                                                 &current, &output, &connect, &gl, &dpms);
3228         if (!res)
3229           {
3230              printf("Failed to get output mode info\n");
3231              continue;
3232           }
3233
3234         mode = _e_output_mode_info_new(h, hsync_start, hsync_end, htotal,
3235                                        v, vsync_start, vsync_end, vtotal,
3236                                        refresh, vscan, clock, flag,
3237                                        current, output, connect, name, dpms);
3238         e_info_client.mode_list = eina_list_append(e_info_client.mode_list, mode);
3239      }
3240    e_info_client.gl = gl;
3241
3242 finish:
3243    if ((name) || (text))
3244      {
3245         printf("errname:%s errmsg:%s\n", name, text);
3246      }
3247 }
3248
3249 static void
3250 _e_info_client_proc_output_mode(int argc, char **argv)
3251 {
3252    E_Info_Output_Mode *mode = NULL;
3253    Eina_List *l;
3254    int output = 0;
3255    int idx = 0;
3256    int output_idx = 0;
3257    char curr;
3258    const char *str_dpms[] = {
3259       "on",
3260       "standby",
3261       "suspend",
3262       "off"
3263    };
3264    int count = 0;
3265
3266    if (argc == 2)
3267      {
3268         if (!_e_info_client_eldbus_message_with_args("output_mode", _cb_output_mode_info,
3269                                                      SIGNATURE_OUTPUT_MODE_CLIENT, E_INFO_CMD_OUTPUT_MODE_GET, 0))
3270           {
3271              printf("_e_info_client_proc_output_mode fail (%d)\n", E_INFO_CMD_OUTPUT_MODE_GET);
3272              return;
3273           }
3274      }
3275    else if (argc == 4)
3276      {
3277         if ((argv[2][0] < '0' || argv[2][0] > '9') ||
3278             (argv[3][0] < '0' || argv[3][0] > '9'))
3279           {
3280              printf("Error: invalid argument\n");
3281              printf("Usage: -output_mode [output idx] [mode number]\n");
3282              return;
3283           }
3284
3285         output_idx = atoi(argv[2]);
3286         count = atoi(argv[3]);
3287         if (!_e_info_client_eldbus_message_with_args("output_mode", _cb_output_mode_info,
3288                                                      SIGNATURE_OUTPUT_MODE_CLIENT, E_INFO_CMD_OUTPUT_MODE_SET, output_idx, count))
3289           {
3290              printf("_e_info_client_proc_output_mode fail (%d)\n", E_INFO_CMD_OUTPUT_MODE_SET);
3291              return;
3292           }
3293      }
3294    else
3295      {
3296         printf("Error: invalid argument\n");
3297         printf("Usage: -output_mode [output idx] [mode number]\n");
3298         return;
3299      }
3300
3301    if (!e_info_client.mode_list)
3302      {
3303         printf("no list\n");
3304         return;
3305      }
3306
3307    if (e_info_client.gl == 0)
3308      {
3309         E_FREE_LIST(e_info_client.mode_list, _e_output_mode_info_free);
3310
3311         printf("not support output_mode.\n");
3312         return;
3313      }
3314
3315    printf("--------------------------------------[ output mode ]---------------------------------------------\n");
3316    printf(" idx   modename     h  hss  hse  htot  v  vss  vse  vtot  refresh  clk  vscan  preferred  current\n");
3317    printf("--------------------------------------------------------------------------------------------------\n");
3318
3319    EINA_LIST_FOREACH(e_info_client.mode_list, l, mode)
3320      {
3321         if (!mode) return;
3322
3323         if (output == mode->output)
3324           {
3325              printf("output %u : ", mode->output);
3326              output++;
3327              idx = 0;
3328
3329              if (mode->connect == 1)
3330                printf("%s, %s\n", "connected", str_dpms[mode->dpms]);
3331              else
3332                {
3333                   printf("%s, %s\n", "disconnected", str_dpms[mode->dpms]);
3334                   continue;
3335                }
3336           }
3337
3338         if (mode->current == 1)
3339           curr = 'O';
3340         else
3341           curr = ' ';
3342
3343         printf("%3d%13s %5u%5u%5u%5u%5u%5u%5u%5u  %3u %8u  %2u        ",
3344                idx++, mode->name,
3345                mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
3346                mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal,
3347                mode->refresh, mode->clock, mode->vscan);
3348
3349         if (mode->flags == 1)
3350           printf("O         %c\n", curr);
3351         else
3352           printf("          %c\n", curr);
3353      }
3354
3355    E_FREE_LIST(e_info_client.mode_list, _e_output_mode_info_free);
3356
3357    printf("\n");
3358
3359    return;
3360 }
3361
3362 static void
3363 _e_info_client_proc_trace(int argc, char **argv)
3364 {
3365    uint32_t onoff;
3366
3367    if (argc < 4)
3368      goto arg_err;
3369
3370    onoff = atoi(argv[3]);
3371
3372    if (onoff == 1 || onoff == 0)
3373      {
3374         if (eina_streq(argv[2], "hwc"))
3375           {
3376              if (!_e_info_client_eldbus_message_with_args("trace_message_hwc", NULL, "i", onoff))
3377                {
3378                   printf("_e_info_client_eldbus_message_with_args error");
3379                }
3380              return;
3381           }
3382         else if (eina_streq(argv[2], "prstt"))
3383           {
3384              if (!_e_info_client_eldbus_message_with_args("trace_message_prstt", NULL, "i", onoff))
3385                {
3386                   printf("_e_info_client_eldbus_message_with_args error");
3387                }
3388              return;
3389           }
3390         else if (eina_streq(argv[2], "exsync"))
3391           {
3392              if (!_e_info_client_eldbus_message_with_args("trace_message_exsync", NULL, "i", onoff))
3393                {
3394                   printf("_e_info_client_eldbus_message_with_args error");
3395                }
3396              return;
3397           }
3398         else if (eina_streq(argv[2], "damage"))
3399           {
3400              if (!_e_info_client_eldbus_message_with_args("trace_message_damage", NULL, "i", onoff))
3401                {
3402                   printf("_e_info_client_eldbus_message_with_args error");
3403                }
3404              return;
3405           }
3406      }
3407
3408 arg_err:
3409    printf("Error Check Args: enlightenment_info -trace %s\n", USAGE_TRACE);
3410 }
3411
3412 static void
3413 _e_info_client_proc_hwc(int argc, char **argv)
3414 {
3415    uint32_t param;
3416
3417    if (argc < 3)
3418      goto arg_err;
3419
3420    param = atoi(argv[2]);
3421
3422    if (param == 1 || param == 0 || param == 2)
3423      {
3424         if (!_e_info_client_eldbus_message_with_args("hwc", NULL, "i", param))
3425           {
3426              printf("_e_info_client_eldbus_message_with_args error");
3427           }
3428         return;
3429      }
3430
3431 arg_err:
3432      printf("Error Check Args: enlightenment_info -hwc [0: off, 1: on, 2: info]\n");
3433
3434 }
3435
3436 static void
3437 _e_info_client_proc_show_plane_state(int argc, char **argv)
3438 {
3439    if (!_e_info_client_eldbus_message("show_plane_state", NULL))
3440      return;
3441
3442    printf("e20 print planes state with eina_log\n");
3443 }
3444
3445 static E_Pending_Commit_Info *
3446 _e_pending_commit_info_new(unsigned int plane, int zpos, unsigned int data, unsigned int tsurface)
3447 {
3448    E_Pending_Commit_Info *pending_commit = NULL;
3449
3450    pending_commit = E_NEW(E_Pending_Commit_Info, 1);
3451    EINA_SAFETY_ON_NULL_RETURN_VAL(pending_commit, NULL);
3452
3453    pending_commit->plane = plane;
3454    pending_commit->zpos = zpos;
3455    pending_commit->data = data;
3456    pending_commit->tsurface = tsurface;
3457
3458    return pending_commit;
3459 }
3460
3461 static void
3462 _e_pending_commit_info_free(E_Pending_Commit_Info *pending_commit)
3463 {
3464    E_FREE(pending_commit);
3465 }
3466
3467 static void
3468 _cb_pending_commit_info_get(const Eldbus_Message *msg)
3469 {
3470    const char *name = NULL, *text = NULL;
3471    Eldbus_Message_Iter *array, *eldbus_msg;
3472    Eina_Bool res;
3473
3474    res = eldbus_message_error_get(msg, &name, &text);
3475    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
3476
3477    res = eldbus_message_arguments_get(msg, "a("VALUE_TYPE_FOR_PENDING_COMMIT")", &array);
3478    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
3479
3480    while (eldbus_message_iter_get_and_next(array, 'r', &eldbus_msg))
3481      {
3482         E_Pending_Commit_Info *pending_commit = NULL;
3483         unsigned int plane, tsurface, data;
3484         int zpos;
3485         res = eldbus_message_iter_arguments_get(eldbus_msg,
3486                                                 VALUE_TYPE_FOR_PENDING_COMMIT,
3487                                                 &plane,
3488                                                 &zpos,
3489                                                 &data,
3490                                                 &tsurface);
3491         if (!res)
3492           {
3493              printf("Failed to get pending_commit info\n");
3494              continue;
3495           }
3496
3497         pending_commit = _e_pending_commit_info_new(plane, zpos, data, tsurface);
3498         if (!pending_commit) continue;
3499
3500         e_info_client.pending_commit_list = eina_list_append(e_info_client.pending_commit_list, pending_commit);
3501      }
3502
3503 finish:
3504    if ((name) || (text))
3505      {
3506         printf("errname:%s errmsg:%s\n", name, text);
3507      }
3508 }
3509
3510 static void
3511 _e_info_client_proc_show_pending_commit(int argc, char **argv)
3512 {
3513    Eina_List *l;
3514    int i = 0;
3515    E_Pending_Commit_Info *pending_commit;
3516
3517    if (!_e_info_client_eldbus_message("show_pending_commit", _cb_pending_commit_info_get))
3518      return;
3519
3520    printf("----------------------------[ pending commit ]-----------------------------------\n");
3521    printf(" No          Plane          Zpos          Data          tsurface\n");
3522    printf("---------------------------------------------------------------------------------\n");
3523
3524    if (!e_info_client.pending_commit_list)
3525      {
3526         printf("no peding commit\n");
3527         return;
3528      }
3529
3530    EINA_LIST_FOREACH(e_info_client.pending_commit_list, l, pending_commit)
3531      {
3532         i++;
3533         printf("%3d        %12zx   %5d         %12zx  %12zx\n",
3534                i,
3535                (uintptr_t)pending_commit->plane,
3536                pending_commit->zpos,
3537                (uintptr_t)pending_commit->data,
3538                (uintptr_t)pending_commit->tsurface);
3539      }
3540
3541    E_FREE_LIST(e_info_client.pending_commit_list, _e_pending_commit_info_free);
3542 }
3543
3544 static E_Fps_Info *
3545 _e_fps_info_new(E_Info_Fps_Type type, const char *output, int zpos, unsigned int window, double fps)
3546 {
3547    E_Fps_Info *fps_info = NULL;
3548
3549    fps_info = E_NEW(E_Fps_Info, 1);
3550    EINA_SAFETY_ON_NULL_RETURN_VAL(fps_info, NULL);
3551
3552    fps_info->type = type;
3553    fps_info->output = output;
3554    fps_info->zpos = zpos;
3555    fps_info->window = window;
3556    fps_info->fps = fps;
3557
3558    return fps_info;
3559 }
3560
3561 static void
3562 _e_fps_info_free(E_Fps_Info *fps)
3563 {
3564    E_FREE(fps);
3565 }
3566
3567 static void
3568 _cb_fps_info_get(const Eldbus_Message *msg)
3569 {
3570    const char *name = NULL, *text = NULL;
3571    Eldbus_Message_Iter *array, *eldbus_msg;
3572    Eina_Bool res;
3573
3574    res = eldbus_message_error_get(msg, &name, &text);
3575    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
3576
3577    res = eldbus_message_arguments_get(msg, "a("VALUE_TYPE_FOR_FPS")", &array);
3578    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
3579
3580    while (eldbus_message_iter_get_and_next(array, 'r', &eldbus_msg))
3581      {
3582         E_Fps_Info *fps_info = NULL;
3583         const char *output;
3584         int zpos, type;
3585         double fps;
3586         unsigned int window;
3587         res = eldbus_message_iter_arguments_get(eldbus_msg,
3588                                                 VALUE_TYPE_FOR_FPS,
3589                                                 &type,
3590                                                 &output,
3591                                                 &zpos,
3592                                                 &window,
3593                                                 &fps);
3594         if (!res)
3595           {
3596              printf("Failed to get fps info\n");
3597              continue;
3598           }
3599
3600         fps_info = _e_fps_info_new(type, output, zpos, window, fps);
3601         if (!fps_info) continue;
3602
3603         e_info_client.fps_list = eina_list_append(e_info_client.fps_list, fps_info);
3604      }
3605
3606 finish:
3607    if ((name) || (text))
3608      {
3609         printf("errname:%s errmsg:%s\n", name, text);
3610      }
3611 }
3612
3613 #define FPS_USAGE \
3614   "[COMMAND] [ARG]...\n" \
3615   "\t-help             : print this message.\n" \
3616   "\t-win_id           : print client fps.\n" \
3617   "Example:\n" \
3618   "\twinfo -fps\n" \
3619   "\twinfo -fps -win_id [win_id]\n" \
3620
3621 static void
3622 _e_info_client_proc_fps_info(int argc, char **argv)
3623 {
3624    char *win_id = "none";
3625
3626    if (argc == 2)
3627      {
3628         if (!strcmp(argv[1], "-help"))
3629           {
3630              printf(FPS_USAGE);
3631              return;
3632           }
3633      }
3634    else if (argc == 4)
3635      {
3636         if (!strcmp(argv[2], "-win_id"))
3637           {
3638              win_id = argv[3];
3639           }
3640         else
3641           {
3642              printf("Invalid argument: %s\n", argv[1]);
3643              printf(FPS_USAGE);
3644              return;
3645           }
3646      }
3647    else
3648      {
3649         printf("Invalid argument: %s\n", argv[1]);
3650         printf(FPS_USAGE);
3651         return;
3652      }
3653
3654    do
3655      {
3656         Eina_List *l;
3657         E_Fps_Info *fps;
3658
3659         if (!_e_info_client_eldbus_message_with_args("get_fps_info", _cb_fps_info_get,
3660                                                      "s", win_id))
3661           return;
3662
3663         if (!e_info_client.fps_list)
3664           goto fps_done;
3665
3666         EINA_LIST_FOREACH(e_info_client.fps_list, l, fps)
3667           {
3668              if (fps->type == E_INFO_FPS_TYPE_OUTPUT)
3669                {
3670                   printf("%3s-OUTPUT...%3.1f\n",
3671                          fps->output,
3672                          fps->fps);
3673                }
3674              else if (fps->type == E_INFO_FPS_TYPE_LAYER)
3675                {
3676                   printf("%3s-Layer-ZPos@%d...%3.1f\n",
3677                          fps->output,
3678                          fps->zpos,
3679                          fps->fps);
3680                }
3681              else if (fps->type == E_INFO_FPS_TYPE_HWC_WIN)
3682                {
3683                   printf("%3s-HWC-Win_ID(0x%x)-ZPos@%d...%3.1f\n",
3684                          fps->output,
3685                          fps->window,
3686                          fps->zpos,
3687                          fps->fps);
3688                }
3689              else if (fps->type == E_INFO_FPS_TYPE_HWC_COMP)
3690                {
3691                   printf("%3s-HWC-COMP...%3.1f\n",
3692                          fps->output,
3693                          fps->fps);
3694                }
3695              else if (fps->type == E_INFO_FPS_TYPE_CLIENT_WIN)
3696                {
3697                   printf("Client-Win_ID(0x%x)...%3.1f\n",
3698                          fps->window,
3699                          fps->fps);
3700                }
3701           }
3702
3703         E_FREE_LIST(e_info_client.fps_list, _e_fps_info_free);
3704 fps_done:
3705         usleep(500000);
3706      }
3707    while (1);
3708 }
3709
3710 static void
3711 _e_info_client_proc_effect_control(int argc, char **argv)
3712 {
3713    uint32_t onoff;
3714
3715    if (argc < 3)
3716      {
3717         printf("Error Check Args: enlightenment_info -effect [1: on, 0: off]\n");
3718         return;
3719      }
3720
3721    onoff = atoi(argv[2]);
3722
3723    if (onoff == 1 || onoff == 0)
3724      {
3725         if (!_e_info_client_eldbus_message_with_args("effect_control", NULL, "i", onoff))
3726           {
3727              printf("_e_info_client_eldbus_message_with_args error");
3728              return;
3729           }
3730      }
3731    else
3732      printf("Error Check Args: enlightenment_info -effect [1: on, 0: off]\n");
3733 }
3734
3735 static void
3736 _e_info_client_quickpanel_control(int argc, char **argv)
3737 {
3738    const char *win;
3739    int operation;
3740    Eldbus_Message *msg;
3741    Eldbus_Message_Iter *itr;
3742    Eldbus_Pending *p;
3743
3744    if (argc < 3)
3745      {
3746         printf("Error Check Args: winfo -quickpanel [operation] {window}\n");
3747         return;
3748      }
3749
3750    operation = atoi(argv[2]);
3751    if (argc >= 4)
3752      win = argv[3];
3753    else
3754      win = "default";
3755
3756    msg = eldbus_proxy_method_call_new(e_info_client.proxy, "quickpanel_control");
3757    itr = eldbus_message_iter_get(msg);
3758    eldbus_message_iter_basic_append(itr, 'i', operation);
3759    eldbus_message_iter_basic_append(itr, 's', win);
3760
3761    p = eldbus_proxy_send(e_info_client.proxy, msg,
3762                          _e_info_client_eldbus_message_cb,
3763                          NULL, -1);
3764    if (!p)
3765      {
3766         printf("\"aux_msg\" proxy_send error");
3767         return;
3768      }
3769 }
3770
3771 static void
3772 _e_info_client_proc_aux_message(int argc, char **argv)
3773 {
3774    const char *win, *key, *val;
3775    Eldbus_Message *msg;
3776    Eldbus_Message_Iter *itr, *opt_itr;
3777    Eldbus_Pending *p;
3778    int i;
3779
3780    if (argc < 5)
3781      {
3782         printf("Error Check Args: enlightenment_info -aux_msg [window] [key] [val] [options]\n");
3783         return;
3784      }
3785
3786    win = argv[2];
3787    key = argv[3];
3788    val = argv[4];
3789
3790    msg = eldbus_proxy_method_call_new(e_info_client.proxy, "aux_msg");
3791    itr = eldbus_message_iter_get(msg);
3792    eldbus_message_iter_basic_append(itr, 's', win);
3793    eldbus_message_iter_basic_append(itr, 's', key);
3794    eldbus_message_iter_basic_append(itr, 's', val);
3795
3796    opt_itr = eldbus_message_iter_container_new(itr, 'a', "s");
3797    for (i = 5; i < argc; i++)
3798      eldbus_message_iter_basic_append(opt_itr, 's', argv[i]);
3799    eldbus_message_iter_container_close(itr, opt_itr);
3800
3801    p = eldbus_proxy_send(e_info_client.proxy, msg,
3802                         _e_info_client_eldbus_message_cb,
3803                          NULL, -1);
3804    if (!p)
3805      {
3806         printf("\"aux_msg\" proxy_send error");
3807         return;
3808      }
3809
3810    ecore_main_loop_begin();
3811 }
3812
3813 static void
3814 _e_info_client_proc_aux_hint(int argc, char **argv)
3815 {
3816    const char *cmd, *win, *id, *hint, *val;
3817    Eldbus_Message *msg;
3818    Eldbus_Message_Iter *itr;
3819    Eldbus_Pending *p;
3820    uint32_t hint_id;
3821    Eina_Bool res;
3822
3823    if ((argc != 5) && (argc != 7))
3824      {
3825         goto usage;
3826         return;
3827      }
3828
3829    cmd = argv[2];
3830    win = argv[3];
3831    id = argv[4];
3832
3833    res = _util_string_to_uint(id, &hint_id, 10);
3834    if (!res)
3835      {
3836         printf("\"aux_hint\" hint id isn't uint");
3837         goto usage;
3838         return;
3839      }
3840
3841    if ((argc == 7) && !strncmp(cmd, "add", 3))
3842      {
3843         hint = argv[5];
3844         val = argv[6];
3845         msg = eldbus_proxy_method_call_new(e_info_client.proxy, "aux_hint_add");
3846         itr = eldbus_message_iter_get(msg);
3847         eldbus_message_iter_basic_append(itr, 's', win);
3848         eldbus_message_iter_basic_append(itr, 'u', hint_id);
3849         eldbus_message_iter_basic_append(itr, 's', hint);
3850         eldbus_message_iter_basic_append(itr, 's', val);
3851      }
3852    else if(!strncmp(cmd, "del", 3))
3853      {
3854         msg = eldbus_proxy_method_call_new(e_info_client.proxy, "aux_hint_del");
3855         itr = eldbus_message_iter_get(msg);
3856         eldbus_message_iter_basic_append(itr, 's', win);
3857         eldbus_message_iter_basic_append(itr, 'u', hint_id);
3858      }
3859    else
3860      {
3861         goto usage;
3862         return;
3863      }
3864
3865    p = eldbus_proxy_send(e_info_client.proxy, msg,
3866                         _e_info_client_eldbus_message_cb,
3867                          NULL, -1);
3868    if (!p)
3869      {
3870         printf("\"aux_hint\" proxy_send error");
3871         return;
3872      }
3873
3874    ecore_main_loop_begin();
3875    return;
3876
3877 usage :
3878    printf("Error Check Args: enlightenment_info -aux_hint add [window id] [hint id] [hint] [val]\n");
3879    printf("                  enlightenment_info -aux_hint del [window id] [hint id]\n");
3880    return;
3881 }
3882
3883
3884 static void
3885 _e_info_client_cb_scrsaver(const Eldbus_Message *msg)
3886 {
3887    const char *name = NULL, *text = NULL;
3888    Eina_Bool res;
3889    const char *result = NULL;
3890
3891    res = eldbus_message_error_get(msg, &name, &text);
3892    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
3893
3894    res = eldbus_message_arguments_get(msg,
3895                                       SIGNATURE_SCRSAVER_SERVER,
3896                                       &result);
3897    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
3898
3899    printf("%s\n", result);
3900    return;
3901
3902 finish:
3903    if ((name) || (text))
3904      {
3905         printf("errname:%s errmsg:%s\n", name, text);
3906      }
3907 }
3908
3909 static void
3910 _e_info_client_proc_scrsaver(int argc, char **argv)
3911 {
3912    E_Info_Cmd_Scrsaver cmd = E_INFO_CMD_SCRSAVER_UNKNOWN;
3913    Eina_Bool res;
3914    double sec = 0.0;
3915
3916    if (eina_streq(argv[2], "info"))
3917      {
3918         if (argc != 3) goto arg_err;
3919         cmd = E_INFO_CMD_SCRSAVER_INFO;
3920      }
3921    else if (eina_streq(argv[2], "enable"))
3922      {
3923         if (argc != 3) goto arg_err;
3924         cmd = E_INFO_CMD_SCRSAVER_ENABLE;
3925      }
3926    else if (eina_streq(argv[2], "disable"))
3927      {
3928         if (argc != 3) goto arg_err;
3929         cmd = E_INFO_CMD_SCRSAVER_DISABLE;
3930      }
3931    else if (eina_streq(argv[2], "timeout"))
3932      {
3933         if (argc != 4) goto arg_err;
3934
3935         res = _util_string_to_double(argv[3], &sec);
3936         EINA_SAFETY_ON_FALSE_GOTO(res, arg_err);
3937
3938         cmd = E_INFO_CMD_SCRSAVER_TIMEOUT;
3939         printf("sec: %lf\n", sec);
3940      }
3941    else
3942      goto arg_err;
3943
3944    res = _e_info_client_eldbus_message_with_args("scrsaver",
3945                                                  _e_info_client_cb_scrsaver,
3946                                                  SIGNATURE_SCRSAVER_CLIENT,
3947                                                  cmd, sec);
3948    EINA_SAFETY_ON_FALSE_RETURN(res);
3949    return;
3950
3951 arg_err:
3952    printf("Usage: enlightenment_info -scrsaver %s", USAGE_SCRSAVER);
3953 }
3954
3955 static void
3956 _e_info_client_proc_force_render(int argc, char **argv)
3957 {
3958    E_Info_Cmd_Force_Render cmd = E_INFO_CMD_FRENDER_NONE;
3959    Eina_Bool res;
3960
3961    if (eina_streq(argv[2], "all"))
3962      {
3963         if (argc != 3) goto arg_err;
3964         cmd = E_INFO_CMD_FRENDER_ALL;
3965      }
3966    else if (eina_streq(argv[2], "cls"))
3967      {
3968         if (argc != 3) goto arg_err;
3969         cmd = E_INFO_CMD_FRENDER_CLS;
3970      }
3971    else if (eina_streq(argv[2], "canvas"))
3972      {
3973         if (argc != 3) goto arg_err;
3974         cmd = E_INFO_CMD_FRENDER_CANVAS;
3975      }
3976    else
3977      goto arg_err;
3978
3979    res = _e_info_client_eldbus_message_with_args("frender",
3980                                                  NULL,
3981                                                  "i",
3982                                                  cmd);
3983    EINA_SAFETY_ON_FALSE_RETURN(res);
3984    return;
3985
3986 arg_err:
3987    printf("Usage: enlightenment_info -frender %s", USAGE_FORCE_RENDER);
3988
3989 }
3990
3991 #define KILL_USAGE \
3992   "[COMMAND] [ARG]...\n" \
3993   "\t-id     : the identifier for the resource whose creator is to be killed.\n" \
3994   "\t-name   : the name for the resource whose creator is to be killed.\n" \
3995   "\t-pid    : the pid for the resource whose creator is to be killed.\n" \
3996   "\t-pid -f : the pid of the client is going to be killed immediately.\n" \
3997   "\t-all    : kill all clients with top level windows\n" \
3998   "\t-help\n" \
3999   "Example:\n" \
4000   "\tenlightenment_info -kill\n" \
4001   "\tenlightenment_info -kill [win_id]\n" \
4002   "\tenlightenment_info -kill -id [win_id]\n" \
4003   "\tenlightenment_info -kill -name [win_name]\n" \
4004   "\tenlightenment_info -kill -pid [pid]\n" \
4005   "\tenlightenment_info -kill -pid [pid] -f\n" \
4006   "\tenlightenment_info -kill -all\n" \
4007   "\tenlightenment_info -kill -help\n" \
4008
4009 static void
4010 _e_info_client_proc_screen_rotation_pre(int argc, char **argv)
4011 {
4012    int rotation_pre;
4013
4014    if (argc < 3)
4015      {
4016         printf("Error Check Args: enlightenment_info -screen_rotation [0|90|180|270]\n");
4017         return;
4018      }
4019
4020    rotation_pre = atoi(argv[2]);
4021    if (rotation_pre < 0 || rotation_pre > 360 || rotation_pre % 90)
4022      {
4023         printf("Error Check Args: enlightenment_info -screen_rotation_pre [0|90|180|270]\n");
4024         return;
4025      }
4026
4027    if (!_e_info_client_eldbus_message_with_args("screen_rotation_pre", NULL, "i", rotation_pre))
4028      printf("_e_info_client_eldbus_message_with_args error");
4029 }
4030
4031 static void
4032 _e_info_client_proc_screen_rotation(int argc, char **argv)
4033 {
4034    int rotation;
4035
4036    if (argc < 3)
4037      {
4038         printf("Error Check Args: enlightenment_info -screen_rotation [0|90|180|270]\n");
4039         return;
4040      }
4041
4042    rotation = atoi(argv[2]);
4043    if (rotation < 0 || rotation > 360 || rotation % 90)
4044      {
4045         printf("Error Check Args: enlightenment_info -screen_rotation [0|90|180|270]\n");
4046         return;
4047      }
4048
4049    if (!_e_info_client_eldbus_message_with_args("screen_rotation", NULL, "i", rotation))
4050      printf("_e_info_client_eldbus_message_with_args error");
4051 }
4052
4053 static void
4054 _e_info_client_cb_remote_surface(const Eldbus_Message *msg)
4055 {
4056    const char *name = NULL, *text = NULL;
4057    Eina_Bool res;
4058    Eldbus_Message_Iter *lines;
4059    char *result = NULL;
4060
4061    res = eldbus_message_error_get(msg, &name, &text);
4062    if (res) goto finish;
4063
4064    res = eldbus_message_arguments_get(msg, "as", &lines);
4065    if (!res) goto finish;
4066
4067    while (eldbus_message_iter_get_and_next(lines, 's', &result))
4068      printf("%s\n", result);
4069
4070    return;
4071
4072 finish:
4073    if ((name) || (text))
4074      {
4075         printf("errname:%s errmsg:%s\n", name, text);
4076      }
4077 }
4078
4079 static void
4080 _e_info_client_cb_kill_client(const Eldbus_Message *msg)
4081 {
4082    const char *name = NULL, *text = NULL;
4083    Eina_Bool res;
4084    const char *result = NULL;
4085    Eldbus_Message_Iter *array_of_string;
4086
4087    res = eldbus_message_error_get(msg, &name, &text);
4088    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
4089
4090    res = eldbus_message_arguments_get(msg, "a"VALUE_TYPE_REPLY_KILL, &array_of_string);
4091    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4092
4093    while (eldbus_message_iter_get_and_next(array_of_string, 's', &result))
4094      {
4095         printf("%s\n", result);
4096      }
4097
4098    return;
4099
4100 finish:
4101    if ((name) || (text))
4102      {
4103         printf("errname:%s errmsg:%s\n", name, text);
4104      }
4105 }
4106
4107 static void
4108 _e_info_client_proc_remote_surface(int argc, char **argv)
4109 {
4110    Eina_Bool res;
4111    int i;
4112    int dump = -1, query = 0;
4113
4114    if (argc < 3) goto arg_err;
4115    for (i = 2; i < argc; i++)
4116      {
4117         if (eina_streq(argv[i], "dump"))
4118           {
4119              if (argc == i + 1)
4120                goto arg_err;
4121
4122              dump = atoi(argv[i+1]);
4123              i = i + 1;
4124           }
4125
4126         if (eina_streq(argv[i], "info"))
4127           {
4128              query = 1;
4129           }
4130      }
4131
4132    if (dump == -1 && query == 0)
4133      goto arg_err;
4134
4135    res = _e_info_client_eldbus_message_with_args("remote_surface",
4136                                                  _e_info_client_cb_remote_surface,
4137                                                  "ii",
4138                                                  dump, query);
4139    EINA_SAFETY_ON_FALSE_RETURN(res);
4140    return;
4141 arg_err:
4142    printf("%s\n", USAGE_REMOTE_SURFACE);
4143 }
4144
4145 static void
4146 _e_info_client_proc_kill_client(int argc, char **argv)
4147 {
4148    const static int KILL_ID_MODE = 1;
4149    const static int KILL_NAME_MODE = 2;
4150    const static int KILL_PID_MODE = 3;
4151    const static int KILL_ALL_MODE = 4;
4152    const static int KILL_PID_FORCE_MODE = 5;
4153
4154    Eina_Bool res;
4155    unsigned long tmp = 0;
4156    uintptr_t ecore_win = 0;
4157    uint64_t uint64_value = 0;
4158    const char *str_value = "";
4159    uint32_t mode = 0;
4160
4161    if (argc == 2)
4162      {
4163         mode = KILL_ID_MODE;
4164         printf("Select the window whose client you wish to kill\n");
4165         if (_e_get_window_under_touch(&ecore_win))
4166           {
4167              printf("Error: cannot get window under touch\n");
4168              return;
4169           }
4170         uint64_value = (uint64_t)ecore_win;
4171      }
4172    else if (argc == 3)
4173      {
4174         if (eina_streq(argv[2], "-all"))
4175           mode = KILL_ALL_MODE;
4176         else if (eina_streq(argv[2], "-help"))
4177           goto usage;
4178         else
4179           {
4180              mode = KILL_ID_MODE;
4181              if (strlen(argv[2]) >= 2 && argv[2][0] == '0' && argv[2][1] == 'x')
4182                res = _util_string_to_ulong(argv[2], &tmp, 16);
4183              else
4184                res = _util_string_to_ulong(argv[2], &tmp, 10);
4185
4186              uint64_value = (uint64_t)tmp;
4187
4188              EINA_SAFETY_ON_FALSE_GOTO(res, usage);
4189           }
4190      }
4191    else if (argc == 4)
4192      {
4193         if (eina_streq(argv[2], "-id"))
4194           {
4195              mode = KILL_ID_MODE;
4196              if (strlen(argv[3]) >= 2 && argv[3][0] == '0' && argv[3][1] == 'x')
4197                res = _util_string_to_ulong(argv[3], &tmp, 16);
4198              else
4199                res = _util_string_to_ulong(argv[3], &tmp, 10);
4200
4201              uint64_value = (uint64_t)tmp;
4202
4203              EINA_SAFETY_ON_FALSE_GOTO(res, usage);
4204           }
4205         else if (eina_streq(argv[2], "-name"))
4206           {
4207              mode = KILL_NAME_MODE;
4208              str_value = argv[3];
4209           }
4210         else if (eina_streq(argv[2], "-pid"))
4211           {
4212              mode = KILL_PID_MODE;
4213              if (strlen(argv[3]) >= 2 && argv[3][0] == '0' && argv[3][1] == 'x')
4214                res = _util_string_to_ulong(argv[3], &tmp, 16);
4215              else
4216                res = _util_string_to_ulong(argv[3], &tmp, 10);
4217
4218              uint64_value = (uint64_t)tmp;
4219
4220              EINA_SAFETY_ON_FALSE_GOTO(res, usage);
4221           }
4222         else
4223           goto usage;
4224      }
4225    else if (argc == 5)
4226      {
4227         if (eina_streq(argv[2], "-pid") && eina_streq(argv[4], "-f"))
4228           {
4229              mode = KILL_PID_FORCE_MODE;
4230
4231              if (strlen(argv[3]) >= 2 && argv[3][0] == '0' && argv[3][1] == 'x')
4232                res = _util_string_to_ulong(argv[3], &tmp, 16);
4233              else
4234                res = _util_string_to_ulong(argv[3], &tmp, 10);
4235
4236              uint64_value = (uint64_t)tmp;
4237              str_value = argv[4];
4238
4239              EINA_SAFETY_ON_FALSE_GOTO(res, usage);
4240           }
4241      }
4242    else
4243      goto usage;
4244
4245    res = _e_info_client_eldbus_message_with_args("kill_client",
4246                                                  _e_info_client_cb_kill_client,
4247                                                  VALUE_TYPE_REQUEST_FOR_KILL,
4248                                                  mode, uint64_value, str_value);
4249    EINA_SAFETY_ON_FALSE_RETURN(res);
4250
4251    return;
4252 usage:
4253    printf("Usage: enlightenment_info %s", KILL_USAGE);
4254 }
4255
4256 static int window_id_format_dec;
4257
4258 static void
4259 _e_info_client_cb_wininfo(const Eldbus_Message *msg)
4260 {
4261    const char *name = NULL, *text = NULL;
4262    Eina_Bool res;
4263    const char *layer_name;
4264    int x, y, w, h, layer, obscured, opaque, hwc, pl_zpos;
4265    Eina_Bool visible, alpha, iconic, focused, frame_visible, redirected;
4266    uint64_t parent_id;
4267    uint32_t res_id;
4268    int pid, xright, ybelow, border_size;
4269
4270    res = eldbus_message_error_get(msg, &name, &text);
4271    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
4272
4273    res = eldbus_message_arguments_get(msg,
4274                                       VALUE_TYPE_REPLY_WININFO,
4275                                       &res_id,
4276                                       &pid,
4277                                       &x,
4278                                       &y,
4279                                       &w,
4280                                       &h,
4281                                       &layer,
4282                                       &visible,
4283                                       &alpha,
4284                                       &opaque,
4285                                       &obscured,
4286                                       &iconic,
4287                                       &frame_visible,
4288                                       &focused,
4289                                       &hwc,
4290                                       &pl_zpos,
4291                                       &parent_id,
4292                                       &layer_name,
4293                                       &xright,
4294                                       &ybelow,
4295                                       &border_size,
4296                                       &redirected);
4297    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4298
4299    if (window_id_format_dec)
4300      printf("\n   Parent id: %lu\n", (unsigned long)parent_id);
4301    else
4302      printf("\n   Parent id: 0x%lx\n", (unsigned long)parent_id);
4303
4304    printf("   Resource id: %u\n"
4305           "   PID: %d\n"
4306           "   X: %d\n"
4307           "   Y: %d\n"
4308           "   Width: %d\n"
4309           "   Height: %d\n"
4310           "   Border size: %d\n"
4311           "   Depth: %d\n"
4312           "   Focused: %d\n"
4313           "   Opaque: %d\n"
4314           "   Obscured: %d\n"
4315           "   Iconic: %d\n"
4316           "   Map State: %s\n"
4317           "   Frame visible: %d\n"
4318           "   Redirect State: %s\n"
4319           "   Layer name: %s\n",
4320           res_id, pid, x, y, w, h, border_size, alpha ? 32 : 24,
4321           focused, opaque, obscured, iconic, visible ? "Visible" : "Not visible",
4322           frame_visible, redirected ? "yes" : "no", layer_name);
4323    if (e_info_client.hwc_windows)
4324      printf("   HWC_ST:");
4325    else
4326      printf("   PL@ZPos:");
4327    if (e_info_client.hwc)
4328      {
4329         if (e_info_client.hwc_windows) // hwc windows
4330           {
4331              switch(pl_zpos)
4332                {
4333                 case E_HWC_WINDOW_STATE_NONE:   printf("  NO  "); break;
4334                 case E_HWC_WINDOW_STATE_CLIENT: printf("  CL  "); break;
4335                 case E_HWC_WINDOW_STATE_DEVICE: printf("  DV  "); break;
4336                 case E_HWC_WINDOW_STATE_VIDEO:  printf("  VD  "); break;
4337                 case E_HWC_WINDOW_STATE_CURSOR: printf("  CS  "); break;
4338                 default:                        printf("  -  "); break;
4339                }
4340           }
4341         else                           // hwc planes
4342           {
4343              if (hwc >= 0)
4344                {
4345                   if ((!iconic) && (frame_visible))
4346                     {
4347                        if (pl_zpos == -999)
4348                          printf(" - ");
4349                        else
4350                          {
4351                             if (hwc) printf(" hwc@%i\n", pl_zpos);
4352                             else printf(" comp@%i\n", pl_zpos);
4353                          }
4354                     }
4355                   else
4356                     printf(" - \n");
4357                }
4358              else
4359                {
4360                   printf(" - \n");
4361                }
4362           }
4363      }
4364    else
4365      {
4366         printf(" - \n");
4367      }
4368
4369    printf ("   Corners:  +%d+%d  -%d+%d  -%d-%d  +%d-%d\n",
4370            x, y, xright, y, xright, ybelow, x, ybelow);
4371
4372    return;
4373
4374 finish:
4375    if ((name) || (text))
4376      {
4377         printf("errname:%s errmsg:%s\n", name, text);
4378      }
4379 }
4380
4381 static void
4382 _e_info_client_cb_wininfo_tree(const Eldbus_Message *msg)
4383 {
4384    const char *error_name = NULL, *error_text = NULL;
4385    Eina_Bool res;
4386    const char *pname;
4387    uint64_t pwin;
4388    Eldbus_Message_Iter *array_of_children, *child;
4389    int num_children;
4390
4391    res = eldbus_message_error_get(msg, &error_name, &error_text);
4392    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
4393
4394    res = eldbus_message_arguments_get(msg, VALUE_TYPE_REPLY_WININFO_TREE,
4395                                       &pwin, &pname, &num_children, &array_of_children);
4396    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4397
4398    if (window_id_format_dec)
4399      printf("\n   Parent window id: %lu \"%s\"\n", (unsigned long)pwin, pname);
4400    else
4401      printf("\n   Parent window id: 0x%lx \"%s\"\n", (unsigned long)pwin, pname);
4402
4403    printf ("      %d child%s%s\n", num_children, num_children == 1 ? "" : "ren",
4404       num_children ? ":" : ".");
4405
4406    while (eldbus_message_iter_get_and_next(array_of_children, 'r', &child))
4407      {
4408         uint64_t child_win;
4409         const char *child_name;
4410         int x, y, w, h, hwc, pl_zpos, level, j;
4411
4412         res = eldbus_message_iter_arguments_get(child,
4413                                                 "tsiiiiiiii",
4414                                                 &child_win,
4415                                                 &child_name,
4416                                                 &num_children, &level,
4417                                                 &x, &y, &w, &h, &hwc, &pl_zpos);
4418         EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4419
4420         for (j = 0; j <= level; j++) printf ("   ");
4421         if (window_id_format_dec)
4422           printf("%lu \"%s\":", (unsigned long)child_win, child_name);
4423         else
4424           printf("0x%lx \"%s\":", (unsigned long)child_win, child_name);
4425         printf (" %dx%d+%d+%d", w, h, x, y);
4426         if (pl_zpos == -999)
4427           printf(" - ");
4428         else
4429           {
4430              if (hwc > 0) printf(" hwc@%i", pl_zpos);
4431              else if (!hwc) printf(" comp@%i", pl_zpos);
4432           }
4433         printf("\n");
4434         if (num_children > 0)
4435           {
4436              for (j = 0; j <= level + 1; j++) printf ("   ");
4437              printf ("%d child%s:\n", num_children, num_children == 1 ? "" : "ren");
4438           }
4439      }
4440
4441
4442    return;
4443
4444 finish:
4445    if ((error_name) || (error_text))
4446      {
4447         printf("errname:%s errmsg:%s\n", error_name, error_text);
4448      }
4449 }
4450
4451 static void
4452 _e_info_client_cb_wininfo_print_hints(const Eldbus_Message *msg)
4453 {
4454    const char *name = NULL, *text = NULL;
4455    Eina_Bool res;
4456    Eldbus_Message_Iter *array_of_hints;
4457    int count = 0;
4458    char *hint;
4459
4460    res = eldbus_message_error_get(msg, &name, &text);
4461    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
4462
4463    res = eldbus_message_arguments_get(msg, "as", &array_of_hints);
4464    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4465
4466    while (eldbus_message_iter_get_and_next(array_of_hints, 's', &hint))
4467      {
4468         printf("   %s\n", hint);
4469         count++;
4470      }
4471
4472    if (!count)
4473      printf("   No window hints\n");
4474
4475    ecore_main_loop_quit();
4476
4477    return;
4478
4479 finish:
4480    if ((name) || (text))
4481      {
4482         printf("errname:%s errmsg:%s\n", name, text);
4483      }
4484
4485    ecore_main_loop_quit();
4486 }
4487
4488 static void
4489 _e_info_client_cb_wininfo_print_shape(const Eldbus_Message *msg)
4490 {
4491    const char *name = NULL, *text = NULL;
4492    Eina_Bool res;
4493    Eldbus_Message_Iter *array_of_shape, *array_of_shape_input;
4494    Eldbus_Message_Iter *struct_of_shape;
4495    int count = 0;
4496    int shape_rects_num, shape_input_rects_num;
4497
4498    res = eldbus_message_error_get(msg, &name, &text);
4499    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
4500
4501    res = eldbus_message_arguments_get(msg, "ia(iiii)ia(iiii)",
4502                                       &shape_rects_num, &array_of_shape,
4503                                       &shape_input_rects_num, &array_of_shape_input);
4504    EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4505
4506    printf("   Number of shape rectangles: %d\n", shape_rects_num);
4507    if (shape_rects_num)
4508      {
4509         while (eldbus_message_iter_get_and_next(array_of_shape, 'r', &struct_of_shape))
4510           {
4511              int x, y, w, h;
4512              res = eldbus_message_iter_arguments_get(struct_of_shape,
4513                                                      "iiii",
4514                                                      &x, &y, &w, &h);
4515              EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4516              count++;
4517              printf("      %d) x(%d), y(%d), w(%d), h(%d)\n", count, x, y, w, h);
4518
4519           }
4520      }
4521
4522    count = 0;
4523    printf("   Number of shape input rectangles: %d\n", shape_input_rects_num);
4524    if (shape_input_rects_num)
4525      {
4526         while (eldbus_message_iter_get_and_next(array_of_shape_input, 'r', &struct_of_shape))
4527           {
4528              int x, y, w, h;
4529              res = eldbus_message_iter_arguments_get(struct_of_shape,
4530                                                      "iiii",
4531                                                      &x, &y, &w, &h);
4532              EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4533              count++;
4534              printf("      %d) x(%d), y(%d), w(%d), h(%d)\n", count, x, y, w, h);
4535
4536           }
4537      }
4538
4539    ecore_main_loop_quit();
4540
4541    return;
4542
4543 finish:
4544    if ((name) || (text))
4545      {
4546         printf("errname:%s errmsg:%s\n", name, text);
4547      }
4548
4549    ecore_main_loop_quit();
4550 }
4551
4552 static Eina_Bool
4553 _e_info_client_display_wininfo(uint64_t win, int children, int tree, int stats,
4554                                int wm, int size, int shape)
4555 {
4556    Eina_Bool res;
4557    char *win_name;
4558
4559    win_name = _e_get_window_name(win);
4560    EINA_SAFETY_ON_NULL_RETURN_VAL(win_name, EINA_FALSE);
4561
4562    if (window_id_format_dec)
4563      printf("\nwininfo: Window id: %lu \"%s\"\n", (unsigned long)win, win_name);
4564    else
4565      printf("\nwininfo: Window id: 0x%lx \"%s\"\n", (unsigned long)win, win_name);
4566
4567    free(win_name);
4568
4569    if (!children && !tree && !wm && !size && !shape)
4570      stats = 1;
4571
4572    if ((children || tree))
4573      {
4574         res = _e_info_client_eldbus_message_with_args("wininfo_tree",
4575                                                       _e_info_client_cb_wininfo_tree,
4576                                                       VALUE_TYPE_REQUEST_FOR_WININFO_TREE,
4577                                                       win, tree);
4578         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
4579      }
4580
4581    if (stats)
4582      {
4583         res = _e_info_client_eldbus_message_with_args("wininfo",
4584                                                       _e_info_client_cb_wininfo,
4585                                                       VALUE_TYPE_REQUEST_FOR_WININFO,
4586                                                       win);
4587         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
4588      }
4589
4590    if (wm)
4591      {
4592         printf("\nAux_Hint:\n");
4593         res = _e_info_client_eldbus_message_with_args("wininfo_hints",
4594                                                       _e_info_client_cb_wininfo_print_hints,
4595                                                       "it",
4596                                                       1, win);
4597         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
4598      }
4599
4600    if (size)
4601      {
4602         printf("\nSize hints:\n");
4603         res = _e_info_client_eldbus_message_with_args("wininfo_hints",
4604                                                       _e_info_client_cb_wininfo_print_hints,
4605                                                       "it",
4606                                                       0, win);
4607         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
4608      }
4609
4610    if (shape)
4611      {
4612         res = _e_info_client_eldbus_message_with_args("wininfo_shape",
4613                                                       _e_info_client_cb_wininfo_print_shape,
4614                                                       "t",
4615                                                       win);
4616         EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EINA_FALSE);
4617      }
4618
4619    return EINA_TRUE;
4620 }
4621
4622 #define WININFO_USAGE \
4623   "[-options ...]\n\n" \
4624   "where options include:\n" \
4625   "\t-help             : print this message.\n" \
4626   "\t-children         : print parent and child identifiers.\n" \
4627   "\t-tree             : print children identifiers recursively.\n" \
4628   "\t-stats            : print window geometry [DEFAULT]\n" \
4629   "\t-id windowid      : use the window with the specified id\n" \
4630   "\t-name windowname  : use the window with the specified name\n" \
4631   "\t-pid windowpid    : use the window with the specified id\n" \
4632   "\t-int              : print window id in decimal\n" \
4633   "\t-size             : print size hints\n" \
4634   "\t-wm               : print window manager hints\n" \
4635   "\t-shape            : print shape rectangles\n" \
4636   "\t-all              : -tree, -stats, -wm, -size, -shape\n" \
4637   "Example:\n" \
4638   "\tenlightenment_info -wininfo\n" \
4639   "\tenlightenment_info -wininfo -id [win_id] -all\n" \
4640   "\tenlightenment_info -wininfo -children -stats -size\n" \
4641   "\tenlightenment_info -wininfo -name [win_name] -tree -wm\n" \
4642   "\tenlightenment_info -wininfo -pid [win_pid] -size -shape -int\n" \
4643
4644 static void
4645 _e_info_client_proc_wininfo(int argc, char **argv)
4646 {
4647    Eina_Bool res;
4648    unsigned long tmp = 0;
4649    uintptr_t ecore_win = 0;
4650    uint64_t win = 0;
4651    int i, children = 0, tree = 0, stats = 0, wm = 0, size = 0, shape = 0;
4652    char *name = NULL, *pid = NULL;
4653    Eina_List *win_list = NULL, *l;
4654
4655    /* Handle our command line arguments */
4656    for (i = 2; i < argc; i++)
4657      {
4658         if (eina_streq(argv[i], "-help"))
4659           goto usage;
4660
4661         if (eina_streq (argv[i], "-children"))
4662           {
4663              children = 1;
4664              continue;
4665           }
4666
4667         if (eina_streq(argv[i], "-tree"))
4668           {
4669              tree = 1;
4670              continue;
4671           }
4672
4673         if (eina_streq(argv[i], "-stats"))
4674           {
4675              stats = 1;
4676              continue;
4677           }
4678
4679         if (eina_streq(argv[i], "-id"))
4680           {
4681              if (++i >= argc || (argv[i][0] < '0' || argv[i][0] > '9'))
4682                {
4683                   printf("Error: -id requires argument\n");
4684                   goto usage;
4685                }
4686
4687              if (strlen(argv[i]) >= 2 && argv[i][0] == '0' && argv[i][1] == 'x')
4688                res = _util_string_to_ulong(argv[i], &tmp, 16);
4689              else
4690                res = _util_string_to_ulong(argv[i], &tmp, 10);
4691
4692              win = (uint64_t)tmp;
4693
4694              EINA_SAFETY_ON_FALSE_GOTO(res, usage);
4695
4696              continue;
4697           }
4698
4699         if (eina_streq(argv[i], "-name"))
4700           {
4701              if (++i >= argc)
4702                {
4703                   printf("Error: -name requires argument\n");
4704                   goto usage;
4705                }
4706
4707              name = argv[i];
4708              continue;
4709           }
4710
4711         if (eina_streq(argv[i], "-pid"))
4712           {
4713              if (++i >= argc || (argv[i][0] < '0' || argv[i][0] > '9'))
4714                {
4715                   printf("Error: -name requires argument\n");
4716                   goto usage;
4717                }
4718
4719              pid = argv[i];
4720              continue;
4721           }
4722         if (eina_streq (argv[i], "-int"))
4723           {
4724              window_id_format_dec = 1;
4725              continue;
4726           }
4727         if (eina_streq (argv[i], "-wm"))
4728           {
4729              wm = 1;
4730              continue;
4731           }
4732         if (eina_streq (argv[i], "-size"))
4733           {
4734              size = 1;
4735              continue;
4736           }
4737         if (eina_streq (argv[i], "-shape"))
4738           {
4739              shape = 1;
4740              continue;
4741           }
4742         if (eina_streq (argv[i], "-all"))
4743           {
4744              tree = 1;
4745              stats = 1;
4746              wm = 1;
4747              size = 1;
4748              shape = 1;
4749              continue;
4750           }
4751
4752         goto usage;
4753      }
4754
4755    if (!win && (name || pid))
4756      {
4757         if (name)
4758           win_list = _e_get_windows(_E_GET_WINDOWS_NAME_MODE, name);
4759         else
4760           win_list = _e_get_windows(_E_GET_WINDOWS_PID_MODE, pid);
4761
4762         if (!win_list)
4763           {
4764              printf("Error: cannot get windows\n");
4765              return;
4766           }
4767      }
4768
4769    if (!win && !win_list)
4770      {
4771         printf("Please select the window about which you\n"
4772                "would like information by clicking the\n"
4773                "mouse in that window.\n");
4774         if (_e_get_window_under_touch(&ecore_win))
4775           {
4776              printf("Error: cannot get window under touch\n");
4777              return;
4778           }
4779         win = (uint64_t)ecore_win;
4780      }
4781
4782    if (win)
4783      {
4784         res = _e_info_client_display_wininfo(win, children, tree, stats, wm, size, shape);
4785         EINA_SAFETY_ON_FALSE_RETURN(res);
4786      }
4787    else
4788      {
4789         for(l = win_list; l; l = eina_list_next(l))
4790           {
4791              uint64_t win;
4792
4793              win = (uint64_t)((Ecore_Window)eina_list_data_get(l));
4794              res = _e_info_client_display_wininfo(win, children, tree, stats, wm, size, shape);
4795              EINA_SAFETY_ON_FALSE_GOTO(res, finish);
4796           }
4797      }
4798
4799 finish:
4800    if (win_list)
4801      eina_list_free(win_list);
4802
4803    return;
4804
4805 usage:
4806    printf("Usage: enlightenment_info -wininfo %s", WININFO_USAGE);
4807 }
4808
4809 static void
4810 _cb_window_proc_version_get(const Eldbus_Message *msg)
4811 {
4812    const char *name = NULL, *text = NULL;
4813    char *ver, *rel;
4814    Eina_Bool res;
4815
4816    res = eldbus_message_error_get(msg, &name, &text);
4817    EINA_SAFETY_ON_TRUE_RETURN(res);
4818
4819    res = eldbus_message_arguments_get(msg, "ss", &ver, &rel);
4820    EINA_SAFETY_ON_FALSE_RETURN(res);
4821
4822    printf("Version: %s\n", ver);
4823    printf("Release: %s\n", rel);
4824 }
4825
4826 static void
4827 _e_info_client_proc_version(int argc, char **argv)
4828 {
4829    if (!_e_info_client_eldbus_message("get_version", _cb_window_proc_version_get))
4830      {
4831         printf("_e_info_client_eldbus_message error:%s\n", "get_einfo");
4832         return;
4833      }
4834 }
4835
4836 static void
4837 _e_info_client_cb_module_list_get(const Eldbus_Message *msg)
4838 {
4839    const char *errname = NULL, *errtext = NULL;
4840    Eldbus_Message_Iter *module_array = NULL;
4841    Eldbus_Message_Iter *inner_module_array = NULL;
4842    Eina_Stringshare *module_name = NULL;
4843    int count = 0;
4844    int onoff = 0;
4845
4846    // check error
4847    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
4848
4849    // get arguments
4850    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "ia(si)", &count, &module_array), err);
4851    printf("============< print module list >===========\n");
4852    printf("module count : %d\n", count);
4853    while (eldbus_message_iter_get_and_next(module_array, 'r', &inner_module_array))
4854      {
4855         EINA_SAFETY_ON_FALSE_GOTO(
4856            eldbus_message_iter_arguments_get(inner_module_array, "si", &module_name, &onoff),
4857            err);
4858         printf("module [ %30s ]\t:\t%s\n", module_name, onoff?"enabled":"disabled");
4859      }
4860    goto finish;
4861
4862 err:
4863    if (errname || errtext)
4864      printf("errname : %s, errmsg : %s\n", errname, errtext);
4865    else
4866      printf("Error occurred in _e_info_client_cb_module_list_get\n");
4867
4868 finish:
4869    return;
4870 }
4871
4872 static void
4873 _e_info_client_cb_module_load(const Eldbus_Message *msg)
4874 {
4875    const char *errname = NULL, *errtext = NULL;
4876    const char *result = NULL;
4877
4878    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
4879
4880    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
4881
4882    printf("%s\n", result);
4883    goto finish;
4884
4885 err:
4886    if (errname || errtext)
4887      printf("errname : %s, errmsg : %s\n", errname, errtext);
4888    else
4889      printf("Error occurred in _e_info_client_cb_module_load\n");
4890
4891 finish:
4892    return;
4893 }
4894
4895 static void
4896 _e_info_client_cb_module_unload(const Eldbus_Message *msg)
4897 {
4898    const char *errname = NULL, *errtext = NULL;
4899    const char *result = NULL;
4900
4901    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
4902
4903    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
4904
4905    printf("%s\n", result);
4906    goto finish;
4907
4908 err:
4909    if (errname || errtext)
4910      printf("errname : %s, errmsg : %s\n", errname, errtext);
4911    else
4912      printf("Error occurred in _e_info_client_cb_module_unload\n");
4913
4914 finish:
4915    return;
4916 }
4917
4918 static void
4919 _e_info_client_proc_module(int argc, char **argv)
4920 {
4921    const char *program = argv[0];
4922    const char *command = argv[2];
4923    const char *module_name = argv[3];
4924    Eina_Bool res = EINA_FALSE;
4925
4926    if (((argc < 3) || (argc > 4)))
4927      {
4928        goto usage;
4929      }
4930
4931    if (strncmp(command, "list", strlen(command)) == 0)
4932      {
4933         if (argc != 3)
4934           goto usage;
4935
4936         res = _e_info_client_eldbus_message("module_list_get", _e_info_client_cb_module_list_get);
4937      }
4938    else if (strncmp(command, "load", strlen(command)) == 0)
4939      {
4940         if (argc != 4)
4941            goto usage;
4942
4943         res = _e_info_client_eldbus_message_with_args("module_load",
4944                                                 _e_info_client_cb_module_load,
4945                                                 "s",
4946                                                 module_name);
4947      }
4948    else if (strncmp(command, "unload", strlen(command)) == 0)
4949      {
4950         if (argc != 4)
4951            goto usage;
4952
4953         res = _e_info_client_eldbus_message_with_args("module_unload",
4954                                                 _e_info_client_cb_module_unload,
4955                                                 "s",
4956                                                 module_name);
4957      }
4958    else
4959      goto usage;
4960
4961    EINA_SAFETY_ON_FALSE_GOTO(res, error);
4962
4963    return;
4964
4965 error:
4966    printf("Error occured while send send message\n\n");
4967
4968 usage:
4969    printf("Usage : %s -module <command> [<module_name>]\n\n", program);
4970    printf("Commands:\n"
4971           "list : Print the current modules list loaded\n"
4972           "load <module_name> : Load module with the given name\n"
4973           "unload <module_name> : Unload module with the given name\n\n");
4974    printf("Example:\n"
4975           "%s -module load e-mod-tizen-effect\n"
4976           "%s -module unload e-mod-tizen-effect\n", program, program);
4977    return;
4978 }
4979
4980 static void
4981 _e_info_client_cb_shutdown(const Eldbus_Message *msg)
4982 {
4983    const char *errname = NULL, *errtext = NULL;
4984    const char *result = NULL;
4985
4986    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
4987
4988    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
4989
4990    printf("%s", result);
4991    goto finish;
4992
4993 err:
4994    if(errname || errtext)
4995      printf("errname : %s, errmsg : %s\n", errname, errtext);
4996    else
4997      printf("Error occurred in _e_info_client_cb_shutdown\n");
4998
4999 finish:
5000    return;
5001 }
5002
5003 static void
5004 _e_info_client_proc_shutdown(int argc, char **argv)
5005 {
5006    Eina_Bool res;
5007
5008    EINA_SAFETY_ON_FALSE_GOTO(argc == 2, usage);
5009
5010    res = _e_info_client_eldbus_message("shutdown", _e_info_client_cb_shutdown);
5011    EINA_SAFETY_ON_FALSE_RETURN(res);
5012
5013    goto finish;
5014
5015 usage :
5016    printf("Usage : %s -shutdown\n\n", argv[0]);
5017
5018 finish:
5019    return;
5020 }
5021
5022 static void
5023 _e_info_client_cb_buffer_flush(const Eldbus_Message *msg)
5024 {
5025    const char *errname = NULL, *errtext = NULL;
5026    const char *result = NULL;
5027
5028    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5029    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
5030
5031    printf("%s\n", result);
5032
5033    goto finish;
5034
5035 err:
5036    if (errname || errtext)
5037      {
5038         printf("errname : %s, errmsg : %s\n", errname, errtext);
5039      }
5040    else
5041      {
5042         printf("Error occured in _e_info_client_cb_buffer_flush\n");
5043      }
5044
5045 finish:
5046    return;
5047 }
5048
5049 static void
5050 _e_info_client_proc_buffer_flush(int argc, char **argv)
5051 {
5052    unsigned long winid = 0x0;
5053    uint64_t send_winid = 0x0;
5054    Ecore_Window win = 0;
5055    Eina_Bool res = EINA_FALSE;
5056    int option = -1;
5057    char *win_name = NULL;
5058
5059    EINA_SAFETY_ON_FALSE_GOTO((argc == 3) || (argc == 4), usage);
5060    EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[2], "on")) ||
5061                              (!strcmp(argv[2], "off")) ||
5062                              (!strcmp(argv[2], "show")), usage);
5063
5064    if (argc == 4)
5065      {
5066         // if input has window id, convert to ulong
5067         if (!strcmp(argv[3], "all"))
5068           res = EINA_TRUE;
5069         else if ((strlen(argv[3]) >= 2) && (argv[3][0] == '0') && ((argv[3][1] == 'x') || (argv[3][1] == 'X')))
5070           res = _util_string_to_ulong(argv[3], &winid, 16);
5071         else
5072           res = _util_string_to_ulong(argv[3], &winid, 10);
5073         if (!res)
5074           {
5075              printf("error occured while parsing winid: %s\n", argv[3]);
5076              return;
5077           }
5078
5079         send_winid = (uint64_t) winid;
5080      }
5081
5082    if (!strcmp(argv[2], "show"))
5083      option = 2;
5084    else{
5085         if (argc == 3)
5086           {
5087              // get winid from touch
5088              printf("Select the window whose property(ies) you wish to get/set\n");
5089              if (!_e_get_window_under_touch(&win))
5090                {
5091                   win_name = _e_get_window_name(win);
5092                   if (!win_name)
5093                     {
5094                        printf("failed to get window under touch\n");
5095                        return;
5096                     }
5097
5098                   printf("%s %s: window(%s) id : 0x%08zx\n", argv[0], argv[1], win_name, win);
5099                   send_winid = (uint64_t) win;
5100
5101                   free(win_name);
5102                }
5103              else
5104                {
5105                   printf("failed to get window under touch\n");
5106                   return;
5107                }
5108           }
5109
5110         if (!strcmp(argv[2], "on"))
5111           option = 1;
5112         else if (!strcmp(argv[2], "off"))
5113           option = 0;
5114         else
5115           goto usage;
5116    }
5117
5118    res = _e_info_client_eldbus_message_with_args("buffer_flush",
5119                                                  _e_info_client_cb_buffer_flush,
5120                                                  "it",
5121                                                  option,
5122                                                  send_winid);
5123    EINA_SAFETY_ON_FALSE_GOTO(res, error);
5124
5125    return;
5126
5127 error:
5128    printf("Error occured while send send message\n\n");
5129
5130 usage:
5131    printf("Usage : %s %s [on <win_id / all>], [off <win_id / all>], [show <win_id / all>]\n\n"
5132           "\t on : turn on buffer_flush option\n"
5133           "\t off : turn off buffer_flush option\n"
5134           "\t show : show buffer_flush configuration\n",
5135           argv[0], argv[1]);
5136    printf("\n\t %s %s on 0x12345678\n", argv[0], argv[1]);
5137    printf("\t %s %s off all\n", argv[0], argv[1]);
5138    printf("\t %s %s show 0x12345678\n", argv[0], argv[1]);
5139
5140    return;
5141 }
5142
5143 static void
5144 _e_info_client_cb_deiconify_approve(const Eldbus_Message *msg)
5145 {
5146    const char *errname = NULL, *errtext = NULL;
5147    const char *result = NULL;
5148
5149    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5150    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
5151
5152    printf("%s\n", result);
5153
5154    goto finish;
5155
5156 err:
5157    if (errname || errtext)
5158      {
5159         printf("errname : %s, errmsg : %s\n", errname, errtext);
5160      }
5161    else
5162      {
5163         printf("Error occured in _e_info_client_cb_deiconify_approve\n");
5164      }
5165
5166 finish:
5167    return;
5168 }
5169
5170 static void
5171 _e_info_client_proc_deiconify_approve(int argc, char **argv)
5172 {
5173    unsigned long winid = 0x0;
5174    uint64_t send_winid = 0x0;
5175    Ecore_Window win = 0;
5176    Eina_Bool res = EINA_FALSE;
5177    int option = -1;
5178    char *win_name = NULL;
5179
5180    EINA_SAFETY_ON_TRUE_GOTO(((argc < 3) || (argc > 4)), usage);
5181    EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[2], "on")) ||
5182                              (!strcmp(argv[2], "off")) ||
5183                              (!strcmp(argv[2], "show")), usage);
5184    if (argc == 4)
5185      {
5186         // if input has window id, convert to ulong
5187         if (!strcmp(argv[3], "all"))
5188           res = EINA_TRUE;
5189         else if ((strlen(argv[3]) >= 2) && (argv[3][0] == '0') && ((argv[3][1] == 'x') || (argv[3][1] == 'X')))
5190           res = _util_string_to_ulong(argv[3], &winid, 16);
5191         else
5192           res = _util_string_to_ulong(argv[3], &winid, 10);
5193         if (!res)
5194           {
5195              printf("error occured while parsing winid: %s\n", argv[3]);
5196              return;
5197           }
5198
5199         send_winid = (uint64_t) winid;
5200      }
5201
5202    if (!strcmp(argv[2], "show"))
5203      option = 2;
5204    else{
5205         if (argc == 3)
5206           {
5207              // get winid from touch
5208              printf("Select the window whose property(ies) you wish to get/set\n");
5209              if (!_e_get_window_under_touch(&win))
5210                {
5211                   win_name = _e_get_window_name(win);
5212                   if (!win_name)
5213                     {
5214                        printf("failed to get window under touch\n");
5215                        return;
5216                     }
5217
5218                   printf("%s %s: window(%s) id : 0x%08zx\n", argv[0], argv[1], win_name, win);
5219                   send_winid = (uint64_t) win;
5220
5221                   free(win_name);
5222                }
5223              else
5224                {
5225                   printf("failed to get window under touch\n");
5226                   return;
5227                }
5228           }
5229
5230         if (!strcmp(argv[2], "on"))
5231           option = 1;
5232         else if (!strcmp(argv[2], "off"))
5233           option = 0;
5234         else
5235           goto usage;
5236    }
5237
5238    res = _e_info_client_eldbus_message_with_args("deiconify_approve",
5239                                                  _e_info_client_cb_deiconify_approve,
5240                                                  "it",
5241                                                  option,
5242                                                  send_winid);
5243    EINA_SAFETY_ON_FALSE_GOTO(res, error);
5244
5245    return;
5246
5247 error:
5248    printf("Error occured while send send message\n\n");
5249
5250 usage:
5251    printf("Usage : %s %s [on <win_id / all>], [off <win_id / all>], [show <win_id / all>]\n\n"
5252           "\t on : turn on deiconify_approve option\n"
5253           "\t off : turn off deiconify_approve option\n"
5254           "\t show : show deiconify_approve configuration\n",
5255           argv[0], argv[1]);
5256    printf("\n\t %s %s on 0x12345678\n", argv[0], argv[1]);
5257    printf("\t %s %s off all\n", argv[0], argv[1]);
5258    printf("\t %s %s show 0x12345678\n", argv[0], argv[1]);
5259
5260    return;
5261 }
5262
5263 static void
5264 _e_info_client_proc_key_repeat(int argc, char **argv)
5265 {
5266    char fd_name[PATH_MAX] = {0,};
5267    int pid, rate = 0, delay = 0;
5268
5269    if (argc == 3 && !strncmp(argv[2], "print", sizeof("print")))
5270      {
5271         pid = getpid();
5272         snprintf(fd_name, PATH_MAX, "/proc/%d/fd/1", pid);
5273      }
5274    else if (argc > 3 && argc < 6 && !strncmp(argv[2], "set", sizeof("set")))
5275      {
5276         delay = atoi(argv[3]);
5277         if (argc > 4) rate = atoi(argv[4]);
5278      }
5279    else goto usage;
5280
5281    if (!_e_info_client_eldbus_message_with_args("key_repeat", NULL, "sii", fd_name, delay, rate))
5282      printf("Error occured while send message\n");
5283
5284    return;
5285
5286 usage:
5287    printf("Usage : %s %s [print], [set <delay> <rate>]\n\n"
5288           "\t print : print current key repeat info\n"
5289           "\t set : set delay and rate (0: do not change this option)\n",
5290           argv[0], argv[1]);
5291    printf("\n\t %s %s print\n", argv[0], argv[1]);
5292    printf("\t %s %s set 400 25\n", argv[0], argv[1]);
5293    printf("\t %s %s set 0 50\n", argv[0], argv[1]);
5294 }
5295
5296 static void
5297 _e_info_client_memchecker(int argc, char **argv)
5298 {
5299    if (!_e_info_client_eldbus_message("dump_memchecker", NULL))
5300      return;
5301
5302    printf("e20 dump log file under /tmp dir.\n");
5303 }
5304
5305 static void
5306 _e_info_client_magnifier(int argc, char **argv)
5307 {
5308    uint32_t op;
5309
5310    if (argc < 3)
5311      {
5312         printf("Error Check Args: enlightenment_info -magnifier [1: on, 0: off]\n");
5313         return;
5314      }
5315
5316    if (!strncmp(argv[2], "off", sizeof("off"))) op = 0;
5317    else if (!strncmp(argv[2], "on", sizeof("on"))) op = 1;
5318    else if (!strncmp(argv[2], "new", sizeof("new"))) op = 2;
5319    else if (!strncmp(argv[2], "del", sizeof("del"))) op = 3;
5320    else if (!strncmp(argv[2], "set_stand_alone", sizeof("set_stand_alone"))) op = 4;
5321    else if (!strncmp(argv[2], "unset_stand_alone", sizeof("unset_stand_alone"))) op = 5;
5322    else if (!strncmp(argv[2], "show", sizeof("show"))) op = 6;
5323    else if (!strncmp(argv[2], "hide", sizeof("hide"))) op = 7;
5324    else
5325      {
5326         printf("Error Check Args: enlightenment_info -magnifier [on/off]\n");
5327         return;
5328      }
5329
5330    if (!_e_info_client_eldbus_message_with_args("magnifier", NULL, "i", op))
5331      printf("_e_info_client_eldbus_message_with_args error");
5332 }
5333
5334 static void
5335 _cb_input_region_get(const Eldbus_Message *msg)
5336 {
5337    const char *name = NULL, *text = NULL;
5338    Eldbus_Message_Iter *array;
5339    Eldbus_Message_Iter *iter;
5340    Eina_Bool res;
5341    int cnt = 0;
5342
5343    res = eldbus_message_error_get(msg, &name, &text);
5344    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
5345
5346    printf("Input region\n");
5347
5348    res = eldbus_message_arguments_get(msg, "a(iiii)", &array);
5349    if (!res)
5350      {
5351         printf("\tNo Input region\n");
5352         return;
5353      }
5354
5355    while (eldbus_message_iter_get_and_next(array, 'r', &iter))
5356      {
5357         int x = 0, y = 0, w = 0, h = 0;
5358         res = eldbus_message_iter_arguments_get(iter,
5359                                                 "iiii",
5360                                                 &x,
5361                                                 &y,
5362                                                 &w,
5363                                                 &h);
5364         if (!res)
5365           {
5366              printf("Failed to get input region info\n");
5367              continue;
5368           }
5369         cnt++;
5370         printf("\t[%d] [(%d, %d),  %dx%d]\n", cnt, x, y, w, h);
5371      }
5372    if (cnt == 0) printf("\tNo Input region\n");
5373
5374 finish:
5375    if ((name) || (text))
5376      {
5377         printf("errname:%s errmsg:%s\n", name, text);
5378      }
5379 }
5380
5381 static void
5382 _e_info_client_input_region_usage(void)
5383 {
5384    printf("\nUsage: \n");
5385    printf("\twinfo -input_region [options] [window_id]\n");
5386    printf("\t\toption: -t: time to show input_regions area (sec)\n");
5387    printf("\t\t        -color: color to shwo input_regions area (r, g, b) default: red\n");
5388    printf("\tex> winfo -input_region\n");
5389    printf("\t    winfo -input_region -t 2 -color g 0xabc123\n");
5390 }
5391
5392 static void
5393 _e_info_client_proc_input_region(int argc, char **argv)
5394 {
5395    const char *win_id = NULL;
5396
5397    Ecore_Window win;
5398    char win_temp[64] = {0, };
5399    int time = 5;
5400    int cnt, idx;
5401    int color_r = 0, color_g = 0, color_b = 0;
5402
5403    cnt = argc - 2;
5404    idx = 2;
5405
5406    while (cnt > 0)
5407      {
5408         if (argv[idx][0] == '-')
5409           {
5410              if (argv[idx][1] == 't')
5411                {
5412                   idx++;
5413                   cnt--;
5414                   if (cnt <= 0)
5415                     {
5416                        printf("Please input correct options\n");
5417                        _e_info_client_input_region_usage();
5418                        return;
5419                     }
5420                   time = atoi(argv[idx]);
5421                }
5422              else if (!strncmp(argv[idx], "-color", sizeof("-color")))
5423                {
5424                   idx++;
5425                   cnt--;
5426                   if (cnt <= 0)
5427                     {
5428                        printf("Please input correct options\n");
5429                        _e_info_client_input_region_usage();
5430                        return;
5431                     }
5432                   if (argv[idx][0] == 'r')
5433                     {
5434                        color_r = 255;
5435                     }
5436                   else if (argv[idx][0] == 'g')
5437                     {
5438                        color_g = 255;
5439                     }
5440                   else if (argv[idx][0] == 'b')
5441                     {
5442                        color_b = 255;
5443                     }
5444                }
5445           }
5446         else if (strstr(argv[idx], "0x"))
5447           {
5448              win_id = argv[idx];
5449           }
5450         else if (!strncmp(argv[idx], "help", sizeof("help")))
5451           {
5452              _e_info_client_input_region_usage();
5453              return;
5454           }
5455
5456         idx++;
5457         cnt--;
5458      }
5459    if (!win_id)
5460      {
5461         printf("Select the window whose input_regions you wish to show\n");
5462         printf("If you want to see more option, please input \"help\" > winfo -input_region help\n");
5463         if (_e_get_window_under_touch(&win))
5464           {
5465              printf("Error: cannot get window under touch\n");
5466              return;
5467           }
5468
5469         snprintf(win_temp, sizeof(win_temp), "%lu", (unsigned long int)win);
5470
5471         win_id = win_temp;
5472      }
5473    if (!color_r && !color_g && !color_b)
5474      color_r = 255;
5475
5476    if (!_e_info_client_eldbus_message_with_args("input_region", _cb_input_region_get, "siiii", win_id, time, color_r, color_g, color_b))
5477      printf("Error occured while send message\n");
5478
5479    return;
5480 }
5481
5482 static void
5483 _cb_hwc_wins_info_get(const Eldbus_Message *msg)
5484 {
5485    const char *name = NULL, *text = NULL;
5486    Eina_Bool res;
5487    Eldbus_Message_Iter *lines;
5488    char *result = NULL;
5489
5490    res = eldbus_message_error_get(msg, &name, &text);
5491    if (res) goto finish;
5492
5493    res = eldbus_message_arguments_get(msg, "as", &lines);
5494    if (!res) goto finish;
5495
5496    while (eldbus_message_iter_get_and_next(lines, 's', &result))
5497      printf("%s\n", result);
5498
5499    return;
5500
5501 finish:
5502    if ((name) || (text))
5503      {
5504         printf("errname:%s errmsg:%s\n", name, text);
5505      }
5506 }
5507
5508 static void
5509 _e_info_client_proc_hwc_wins(int argc, char **argv)
5510 {
5511    Eina_Bool res;
5512    E_Hwc_Wins_Debug_Cmd cmd;
5513
5514    if (argc < 2)
5515      cmd = E_HWC_WINS_DEBUG_CMD_VIS;
5516    else
5517      {
5518         if (!argv[2])
5519           cmd = E_HWC_WINS_DEBUG_CMD_VIS;
5520         else if (eina_streq(argv[2], "all"))
5521           cmd = E_HWC_WINS_DEBUG_CMD_ALL;
5522         else if (eina_streq(argv[2], "dv"))
5523           cmd = E_HWC_WINS_DEBUG_CMD_DV;
5524         else if (eina_streq(argv[2], "cl"))
5525           cmd = E_HWC_WINS_DEBUG_CMD_CL;
5526         else if (eina_streq(argv[2], "cs"))
5527           cmd = E_HWC_WINS_DEBUG_CMD_CS;
5528         else if (eina_streq(argv[2], "vd"))
5529           cmd = E_HWC_WINS_DEBUG_CMD_VD;
5530         else if (eina_streq(argv[2], "no"))
5531           cmd = E_HWC_WINS_DEBUG_CMD_NO;
5532         else if (eina_streq(argv[2], "queue"))
5533           cmd = E_HWC_WINS_DEBUG_CMD_QUEUE;
5534         else if (eina_streq(argv[2], "commit"))
5535           cmd = E_HWC_WINS_DEBUG_CMD_COMMIT;
5536         else if (eina_streq(argv[2], "help") || eina_streq(argv[2], "usage"))
5537           goto usage;
5538         else
5539           goto usage;
5540      }
5541
5542    res = _e_info_client_eldbus_message_with_args("hwc_wins", _cb_hwc_wins_info_get, "i", cmd);
5543
5544    EINA_SAFETY_ON_FALSE_RETURN(res);
5545
5546    return;
5547
5548 usage:
5549    printf("Usage: wininfo_info %s", USAGE_HWC_WINS);
5550
5551    return;
5552 }
5553
5554 static void
5555 _cb_screen_info_get(const Eldbus_Message *msg)
5556 {
5557    const char *name = NULL, *text = NULL;
5558    Eina_Bool res;
5559    Eldbus_Message_Iter *lines;
5560    char *result = NULL;
5561
5562    res = eldbus_message_error_get(msg, &name, &text);
5563    if (res) goto finish;
5564
5565    res = eldbus_message_arguments_get(msg, "as", &lines);
5566    if (!res) goto finish;
5567
5568    while (eldbus_message_iter_get_and_next(lines, 's', &result))
5569      printf("%s\n", result);
5570
5571    return;
5572
5573 finish:
5574    if ((name) || (text))
5575      {
5576         printf("errname:%s errmsg:%s\n", name, text);
5577      }
5578 }
5579
5580 static void
5581 _e_info_client_proc_screen_info(int argc, char **argv)
5582 {
5583    Eina_Bool res;
5584    int dummy_value = 1;
5585
5586    res = _e_info_client_eldbus_message_with_args("screen_info", _cb_screen_info_get, "i", dummy_value);
5587
5588    EINA_SAFETY_ON_FALSE_RETURN(res);
5589
5590    return;
5591 }
5592
5593 static void
5594 _e_info_client_cb_focus_policy_ext(const Eldbus_Message *msg)
5595 {
5596    const char *errname = NULL, *errtext = NULL;
5597    Eina_Bool changed = EINA_FALSE;
5598    int result = -1;
5599
5600    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5601    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "bi", &changed, &result), err);
5602
5603    if (changed)
5604      printf("Successfully changed, now focus_policy_ext=%d\n", result);
5605    else if (result >= 0)
5606      printf("now focus_policy_ext=%d\n", result);
5607    else
5608      printf("Error occured\n");
5609
5610    return;
5611
5612 err:
5613    if(errname || errtext)
5614      printf("errname : %s, errmsg : %s\n", errname, errtext);
5615    else
5616      printf("Error occurred in _e_info_client_cb_focus_policy_ext\n");
5617
5618    return;
5619 }
5620
5621 static void
5622 _e_info_client_proc_focus_policy_ext(int argc, char **argv)
5623 {
5624    int input = -1;
5625    Eina_Bool res;
5626
5627    EINA_SAFETY_ON_FALSE_GOTO(((argc == 2) || (argc == 3)), usage);
5628
5629    if (argc == 3)
5630      {
5631         input = atoi(argv[2]);
5632         if ((input != 0) && (input != 1)) goto usage;
5633      }
5634    else
5635      input = -1;
5636
5637    res = _e_info_client_eldbus_message_with_args("focus_policy_ext_set", _e_info_client_cb_focus_policy_ext, "i", input);
5638    EINA_SAFETY_ON_FALSE_RETURN(res);
5639
5640    return;
5641
5642 usage :
5643    printf("Usage : %s -focus_policy_ext [policy_enum]\n\n", argv[0]);
5644    printf("        %s -focus_policy_ext 0 : set focus_policy_ext to E_FOCUS_EXT_TOP_STACK\n", argv[0]);
5645    printf("        %s -focus_policy_ext 1 : set focus_policy_ext to E_FOCUS_EXT_HISTORY\n", argv[0]);
5646    printf("        %s -focus_policy_ext : show now focus_policy_ext\n", argv[0]);
5647
5648    return;
5649 }
5650
5651 static void
5652 _e_info_client_cb_focus_history(const Eldbus_Message *msg)
5653 {
5654    const char *errname = NULL, *errtext = NULL;
5655    Eldbus_Message_Iter *array = NULL, *iter = NULL;
5656    Eina_Bool res = EINA_FALSE;
5657    unsigned int i = 0;
5658
5659    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5660    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "a(ubbbs)", &array), err);
5661
5662    if (array)
5663      {
5664         printf("---------------------------------[ focus history ]----------------------------------\n");
5665         printf("   No     Win_ID     focused     focusable     focus_skip     title\n");
5666         printf("------------------------------------------------------------------------------------\n");
5667         while (eldbus_message_iter_get_and_next(array, 'r', &iter))
5668           {
5669              Eina_Bool focused, focusable, skiped;
5670              Ecore_Window id;
5671              const char *title;
5672
5673              res = eldbus_message_iter_arguments_get(iter, "ubbbs", &id, &focused, &focusable, &skiped, &title);
5674              if (!res)
5675                {
5676                   printf("Failed to get focus stack\n");
5677                   continue;
5678                }
5679
5680              printf("   %2u     0x%08zx     %c           %c              %c         %-20s\n",
5681                     i++, id, focused? 'O':' ', focusable? 'O':'X', skiped? 'O':' ', title);
5682              printf("------------------------------------------------------------------------------------\n");
5683           }
5684      }
5685    else
5686      goto err;
5687
5688    return;
5689
5690 err:
5691    if(errname || errtext)
5692      printf("errname : %s, errmsg : %s\n", errname, errtext);
5693    else
5694      printf("Error occurred in _e_info_client_cb_focus_history\n");
5695
5696    return;
5697 }
5698
5699 static void
5700 _e_info_client_proc_focus_history(int argc, char **argv)
5701 {
5702    EINA_SAFETY_ON_FALSE_GOTO(argc == 2, usage);
5703    Eina_Bool res;
5704
5705    res = _e_info_client_eldbus_message("focus_history", _e_info_client_cb_focus_history);
5706    EINA_SAFETY_ON_FALSE_RETURN(res);
5707
5708    return;
5709
5710 usage :
5711    printf("Usage : %s -focus_history\n\n", argv[0]);
5712
5713    return;
5714 }
5715
5716 static void
5717 _e_info_client_proc_screen_record(int argc, char **argv)
5718 {
5719    e_info_client_screen_recorder_run(argc, argv);
5720 }
5721
5722 static void
5723 _e_info_client_inputgen_usage(void)
5724 {
5725    printf("  If you want to generate input events, follow below steps\n");
5726    printf("  \tinit_device -> generate events (keygen) -> deinit_device\n");
5727    printf("\n\n");
5728    printf("  enlightenment_info -init_device\n");
5729    printf("  \t--node: open a device node (ex> /dev/input/event1)\n");
5730    printf("  \t--type: create a device by given type (keyboard/mouse/touch)\n");
5731    printf("  \t\tyou can select one or more types, but currently only keyboard type is supported\n");
5732    printf("  \t--name: device name want to create. used with --type option (default: E_Info_Device)\n");
5733    printf("\n");
5734    printf("  you need to choice either node or type to init device\n");
5735    printf("  example> enlightenment_info -init_device --node=/dev/input/event1\n");
5736    printf("           enlightenment_info -init_device --type=keyboard/mouse --name=Test_Device\n");
5737    printf("           enlightenment_info -init_device --type=keyboard\n");
5738    printf("\n\n");
5739    printf("  enlightenment_info -deinit_device\n");
5740    printf("  example> enlightenment_info -deinit_device\n");
5741    printf("\n\n");
5742    printf("  enlightenment_info -keygen\n");
5743    printf("  \t--name: keyname want to generate\n");
5744    printf("  \t--code: X keycode want to generate\n");
5745    printf("  \t--state: key event state want to generate [press/down/1] [release/up/0] (default: Press/Release pair)\n");
5746    printf("\n");
5747    printf("  you need to choice either name or code to generate key events\n");
5748    printf("  example> enlightenment_info -keygen --name=XF86Back\n");
5749    printf("           enlightenment_info -keygen --code=166 --state=down\n");
5750    printf("           enlightenment_info -keygen --name=XF86Back --state=0\n");
5751    printf("\n\n");
5752    printf("  enlightenment_info -touchgen\n");
5753    printf("  \t--idx: touch index want to generate (default: 0)\n");
5754    printf("  \t--axis: touch axis want to generate\n");
5755    printf("  \t--state: touch event state want to generate [press/down/1] [release/up/0] [motion/move/2] (default: Press/Motion/Release pair)\n");
5756    printf("\n");
5757    printf("  you need to input axis information to generate touch events\n");
5758    printf("  example> enlightenment_info -touchgen --axis=100,200\n");
5759    printf("           enlightenment_info -touchgen --idx=1 --axis=200,300\n");
5760    printf("           enlightenment_info -touchgen --idx=0 --axis=300,100 --state=down\n");
5761    printf("\n\n");
5762    printf("  enlightenment_info -mousegen\n");
5763    printf("  \t--button: button number want to generate (default: left button(0/272))\n");
5764    printf("  \t\t button number following linux input.h so BTN_LEFT value is 272\n");
5765    printf("  \t\t but to generate button simply support 3 button (0: left, 1: right, 2: middle)\n");
5766    printf("  \t\t you can use --btn instead\n");
5767    printf("  \t--axis: mouse relative axis want to generate\n");
5768    printf("  \t--state: mouse event state want to generate [press/down/1] [release/up/0] [motion/move/2] (default: Motion or Press/Release pair)\n");
5769    printf("  \t\t if you add option --axis, default state is move, but if you add option --button, default state is down/up pair\n");
5770    printf("  \t--wheel: mouse wheel event want to generate\n");
5771    printf("  \t--hwheel: mouse horizental wheel event want to generate\n");
5772    printf("\n");
5773    printf("  you need to choice either axis or button to generate mouse events\n");
5774    printf("  example> enlightenment_info -mousegen --axis=5,-10 --state=move\n");
5775    printf("           enlightenment_info -mousegen --axis=-12,20\n");
5776    printf("           enlightenment_info -mousegen --button=0 --state=down\n");
5777    printf("           enlightenment_info -mousegen --btn=1\n");
5778    printf("           enlightenment_info -mousegen --wheel=1\n");
5779    printf("           enlightenment_info -mousegen --hwheel=-1\n");
5780    printf("\n\n");
5781    printf("  enlightenment_info -mouse_accel\n");
5782    printf("  \t--state: set mouse acceleration usage [off/0][on/1] (default: on)\n");
5783    printf("  example> enlightenment_info -mouse_accel --state=0\n");
5784    printf("\n\n");
5785    printf("  enlightenment_info -input_log_enable [0/1]\n");
5786    printf("  \t : set input_log_enable [off/0][on/1] (default: on)\n");
5787    printf("  example> enlightenment_info -input_log_enable 1\n");
5788    printf("\n");
5789    printf("  enlightenment_info -use_cursor_timer [0/1]\n");
5790    printf("  \t : set use_cursor_timer [off/0][on/1]\n");
5791    printf("  example> enlightenment_info -use_cursor_timer 1\n");
5792    printf("\n");
5793 }
5794
5795 static void
5796 _e_info_client_cb_init_device(const Eldbus_Message *msg)
5797 {
5798    const char *errname = NULL, *errtext = NULL;
5799    char *result = NULL;
5800
5801    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5802
5803    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
5804
5805    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
5806      printf("Init_device Failed: %s\n", result);
5807
5808    return;
5809
5810 err:
5811    if(errname || errtext)
5812      printf("errname : %s, errmsg : %s\n", errname, errtext);
5813    else
5814      printf("Error occurred in _e_info_client_cb_init_device\n");
5815 }
5816
5817 void
5818 _e_info_client_proc_init_device(int argc, char **argv)
5819 {
5820    char name[80] = {0, }, node[20] = {0, };
5821    unsigned int type = 0x0;
5822    char *tmp = NULL, *buf = NULL, *buf_ptr = NULL;
5823    int i;
5824
5825    if (argc < 3)
5826      {
5827         _e_info_client_inputgen_usage();
5828         return;
5829      }
5830
5831    for (i = 2; i < argc; i++)
5832      {
5833         if (!strncmp(argv[i], "--node=", sizeof("--node=") - 1))
5834           {
5835              tmp = argv[i] + sizeof("--node=") - 1;
5836              if (strlen(tmp) > sizeof(node))
5837                {
5838                   printf("Please input correct device node. The length should be less than 20\n");
5839                   return;
5840                }
5841              strncpy(node, tmp, sizeof(node) - 1);
5842              type = 0x0;
5843              break;
5844           }
5845         else if (!strncmp(argv[i], "--type=", sizeof("--type=") - 1))
5846           {
5847              tmp = argv[i] + sizeof("--type=") - 1;
5848              buf = strtok_r(tmp, "/", &buf_ptr);
5849              if (!buf)
5850                {
5851                   printf("Please insert correct device type. keyboard/mouse/touch.\n");
5852                   return;
5853                }
5854              while (buf)
5855                {
5856                   if (!strncmp(buf, "mouse", sizeof("mouse")) ||
5857                       !strncmp(buf, "pointer", sizeof("pointer")))
5858                     {
5859                        type |= E_INPUT_SEAT_POINTER;
5860                     }
5861                   else if (!strncmp(buf, "touch", sizeof("touch")))
5862                     {
5863                        type |= E_INPUT_SEAT_TOUCH;
5864                     }
5865                   else if (!strncmp(buf, "keyboard", sizeof("keyboard")))
5866                     {
5867                        type |= E_INPUT_SEAT_KEYBOARD;
5868                     }
5869                   else
5870                     {
5871                        printf("Please insert valid device type. keyboard/mouse/touch.\n");
5872                        break;
5873                     }
5874                   buf = strtok_r(NULL, "/", &buf_ptr);
5875                }
5876           }
5877         else if (!strncmp(argv[i], "--name=", sizeof("--name=") - 1))
5878           {
5879              tmp = argv[i] + sizeof("--name=") - 1;
5880              if (strlen(tmp) > sizeof(name))
5881                {
5882                   printf("Please iuput correct device name. The length should be less than 80\n");
5883                   return;
5884                }
5885              strncpy(name, tmp, sizeof(name) - 1);
5886           }
5887         else
5888           {
5889              _e_info_client_inputgen_usage();
5890              return;
5891           }
5892      }
5893
5894    if (!type && node[0] == '\0')
5895      {
5896         printf("Please insert either node or type\n");
5897         return;
5898      }
5899    else if (type && node[0] != '\0')
5900      {
5901         printf("Please insert only one between node and type\n");
5902         return;
5903      }
5904
5905    if (type)
5906      {
5907         if (name[0] == '\0')
5908           snprintf(name, sizeof(name), "E_Info_Device");
5909      }
5910    else
5911      {
5912         snprintf(name, sizeof(name), "%s", node);
5913      }
5914
5915    if (!_e_info_client_eldbus_message_with_args("init_device", _e_info_client_cb_init_device, "us", type, name))
5916      return;
5917 }
5918
5919 void
5920 _e_info_client_proc_deinit_device(int argc, char **argv)
5921 {
5922    if (!_e_info_client_eldbus_message("deinit_device", NULL))
5923      return;
5924 }
5925
5926 static void
5927 _e_info_client_cb_keygen(const Eldbus_Message *msg)
5928 {
5929    const char *errname = NULL, *errtext = NULL;
5930    char *result = NULL;
5931
5932    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
5933
5934    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
5935
5936    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
5937      printf("Keygen Failed: %s\n", result);
5938
5939    return;
5940
5941 err:
5942    if(errname || errtext)
5943      printf("errname : %s, errmsg : %s\n", errname, errtext);
5944    else
5945      printf("Error occurred in _e_info_client_cb_keygen\n");
5946 }
5947
5948 void
5949 _e_info_client_proc_keygen(int argc, char **argv)
5950 {
5951    char name[16] = {0, };
5952    int state = E_INFO_EVENT_STATE_ALL, code = 0, i;
5953    char *tmp = NULL;
5954
5955    if (argc < 3)
5956      {
5957         _e_info_client_inputgen_usage();
5958         return;
5959      }
5960
5961    for (i = 2; i < argc; i++)
5962      {
5963         if (!strncmp(argv[i], "--name=", sizeof("--name=") - 1))
5964           {
5965              tmp = argv[i] + sizeof("--name=") - 1;
5966
5967              if (strlen(tmp) > sizeof(name))
5968                {
5969                   printf("Please input correct keyname. The length should be less than 16\n");
5970                   return;
5971                }
5972              strncpy(name, tmp, sizeof(name) - 1);
5973           }
5974         else if (!strncmp(argv[i], "--code=", sizeof("--code=") - 1))
5975           {
5976              tmp = argv[i] + sizeof("--code=") - 1;
5977              code = atoi(tmp);
5978           }
5979         else if (!strncmp(argv[i], "--state=", sizeof("--state=") - 1))
5980           {
5981              tmp = argv[i] + sizeof("--state=") - 1;
5982              if (!strncmp(tmp, "press", sizeof("press")) ||
5983                  !strncmp(tmp, "down", sizeof("down")) ||
5984                  !strncmp(tmp, "1", sizeof("1")))
5985                {
5986                   state = E_INFO_EVENT_STATE_PRESS;
5987                }
5988              else if (!strncmp(tmp, "release", sizeof("release")) ||
5989                       !strncmp(tmp, "up", sizeof("up")) ||
5990                       !strncmp(tmp, "0", sizeof("0")))
5991                {
5992                   state = E_INFO_EVENT_STATE_RELEASE;
5993                }
5994              else
5995                {
5996                   printf("Please input correct key state (press/down/1) or (release/up/0)\n");
5997                   return;
5998                }
5999           }
6000         else
6001           {
6002              _e_info_client_inputgen_usage();
6003              return;
6004           }
6005      }
6006
6007    if (!code && name[0] == '\0')
6008      {
6009         printf("Please insert either name or code\n");
6010         return;
6011      }
6012    else if (code && name[0] != '\0')
6013      {
6014         printf("Please insert only one between name and code\n");
6015         return;
6016      }
6017
6018    if (!_e_info_client_eldbus_message_with_args("keygen", _e_info_client_cb_keygen, "sii", name, code, state))
6019      return;
6020 }
6021
6022 static void
6023 _e_info_client_cb_touchgen(const Eldbus_Message *msg)
6024 {
6025    const char *errname = NULL, *errtext = NULL;
6026    char *result = NULL;
6027
6028    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6029
6030    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6031
6032    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6033      printf("Touchgen Failed: %s\n", result);
6034
6035    return;
6036
6037 err:
6038    if(errname || errtext)
6039      printf("errname : %s, errmsg : %s\n", errname, errtext);
6040    else
6041      printf("Error occurred in _e_info_client_cb_touchgen\n");
6042 }
6043
6044 void
6045 _e_info_client_proc_touchgen(int argc, char **argv)
6046 {
6047    int state = E_INFO_EVENT_STATE_ALL, idx = 0, x = -1, y = -1, cnt = 0, i;
6048    char *tmp = NULL, *buf = NULL, *buf_ptr = NULL;
6049
6050    if (argc < 3)
6051      {
6052         _e_info_client_inputgen_usage();
6053         return;
6054      }
6055
6056    for (i = 2; i < argc; i++)
6057      {
6058         if (!strncmp(argv[i], "--idx=", sizeof("--idx=") - 1))
6059           {
6060              tmp = argv[i] + sizeof("--idx=") - 1;
6061              idx = atoi(tmp);
6062           }
6063         else if (!strncmp(argv[i], "--axis=", sizeof("--axis=") - 1))
6064           {
6065              tmp = argv[i] + sizeof("--axis=") - 1;
6066              buf = strtok_r(tmp, ",", &buf_ptr);
6067              if (!buf)
6068                {
6069                   printf("Please insert correct axis. --axis=100,200\n");
6070                   return;
6071                }
6072              while (buf)
6073                {
6074                   if (cnt == 0) x = atoi(buf);
6075                   else if (cnt == 1) y = atoi(buf);
6076                   else
6077                     {
6078                        printf("Please insert valid axis. --axis=100,200\n");
6079                        return;
6080                     }
6081                   buf = strtok_r(NULL, ",", &buf_ptr);
6082                   cnt++;
6083                }
6084           }
6085         else if (!strncmp(argv[i], "--state=", sizeof("--state=") - 1))
6086           {
6087              tmp = argv[i] + sizeof("--state=") - 1;
6088              if (!strncmp(tmp, "press", sizeof("press")) ||
6089                  !strncmp(tmp, "down", sizeof("down")) ||
6090                  !strncmp(tmp, "1", sizeof("1")))
6091                {
6092                   state = E_INFO_EVENT_STATE_PRESS;
6093                }
6094              else if (!strncmp(tmp, "release", sizeof("release")) ||
6095                       !strncmp(tmp, "up", sizeof("up")) ||
6096                       !strncmp(tmp, "0", sizeof("0")))
6097                {
6098                   state = E_INFO_EVENT_STATE_RELEASE;
6099                }
6100              else if (!strncmp(tmp, "motion", sizeof("motion")) ||
6101                       !strncmp(tmp, "move", sizeof("move")) ||
6102                       !strncmp(tmp, "2", sizeof("2")))
6103                {
6104                   state = E_INFO_EVENT_STATE_MOTION;
6105                }
6106              else
6107                {
6108                   printf("Please input correct key state (press/down/1) or (release/up/0)\n");
6109                   return;
6110                }
6111           }
6112         else
6113           {
6114              _e_info_client_inputgen_usage();
6115              return;
6116           }
6117      }
6118
6119    if ((x < 0) || (y < 0))
6120      {
6121         printf("Please insert correct axis values (greater than 0)\n");
6122         return;
6123      }
6124
6125    if (!_e_info_client_eldbus_message_with_args("touchgen", _e_info_client_cb_touchgen, "iiii", idx, x, y, state))
6126      return;
6127 }
6128
6129 static void
6130 _e_info_client_cb_mousegen(const Eldbus_Message *msg)
6131 {
6132    const char *errname = NULL, *errtext = NULL;
6133    char *result = NULL;
6134
6135    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6136
6137    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6138
6139    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6140      printf("Mousegen Failed: %s\n", result);
6141
6142    return;
6143
6144 err:
6145    if(errname || errtext)
6146      printf("errname : %s, errmsg : %s\n", errname, errtext);
6147    else
6148      printf("Error occurred in _e_info_client_cb_mousegen\n");
6149 }
6150
6151 void
6152 _e_info_client_proc_mousegen(int argc, char **argv)
6153 {
6154    int state = E_INFO_EVENT_STATE_ALL, button = 0, x = -1, y = -1, cnt = 0, i;
6155    char *tmp = NULL, *buf = NULL, *buf_ptr = NULL;
6156
6157    if (argc < 3)
6158      {
6159         _e_info_client_inputgen_usage();
6160         return;
6161      }
6162
6163    for (i = 2; i < argc; i++)
6164      {
6165         if (!strncmp(argv[i], "--button=", sizeof("--button=") - 1))
6166           {
6167              tmp = argv[i] + sizeof("--button=") - 1;
6168              button = atoi(tmp);
6169           }
6170         else if (!strncmp(argv[i], "--btn=", sizeof("--btn=") - 1))
6171           {
6172              tmp = argv[i] + sizeof("--btn=") - 1;
6173              button = atoi(tmp);
6174           }
6175         else if (!strncmp(argv[i], "--axis=", sizeof("--axis=") - 1))
6176           {
6177              tmp = argv[i] + sizeof("--axis=") - 1;
6178              buf = strtok_r(tmp, ",", &buf_ptr);
6179              if (!buf)
6180                {
6181                   printf("Please insert correct axis. --axis=5,10\n");
6182                   return;
6183                }
6184              while (buf)
6185                {
6186                   if (cnt == 0) x = atoi(buf);
6187                   else if (cnt == 1) y = atoi(buf);
6188                   else
6189                     {
6190                        printf("Please insert correct axis. --axis=5,10\n");
6191                        return;
6192                     }
6193                   buf = strtok_r(NULL, ",", &buf_ptr);
6194                   cnt++;
6195                }
6196              state = E_INFO_EVENT_STATE_MOTION;
6197           }
6198         else if (!strncmp(argv[i], "--state=", sizeof("--state=") - 1))
6199           {
6200              tmp = argv[i] + sizeof("--state=") - 1;
6201              if (!strncmp(tmp, "press", sizeof("press")) ||
6202                  !strncmp(tmp, "down", sizeof("down")) ||
6203                  !strncmp(tmp, "1", sizeof("1")))
6204                {
6205                   state = E_INFO_EVENT_STATE_PRESS;
6206                }
6207              else if (!strncmp(tmp, "release", sizeof("release")) ||
6208                       !strncmp(tmp, "up", sizeof("up")) ||
6209                       !strncmp(tmp, "0", sizeof("0")))
6210                {
6211                   state = E_INFO_EVENT_STATE_RELEASE;
6212                }
6213              else if (!strncmp(tmp, "motion", sizeof("motion")) ||
6214                       !strncmp(tmp, "move", sizeof("move")) ||
6215                       !strncmp(tmp, "2", sizeof("2")))
6216                {
6217                   state = E_INFO_EVENT_STATE_MOTION;
6218                }
6219              else
6220                {
6221                   printf("Please input correct mouse state (press/down/1), (release/up/0) or (motion/move/2)\n");
6222                   return;
6223                }
6224           }
6225         else if (!strncmp(argv[i], "--wheel=", sizeof("--wheel=") - 1))
6226           {
6227              tmp = argv[i] + sizeof("--wheel=") - 1;
6228              button = E_INFO_BUTTON_WHEEL;
6229              state = E_INFO_EVENT_STATE_MOTION;
6230              x = atoi(tmp);
6231           }
6232         else if (!strncmp(argv[i], "--hwheel=", sizeof("--hwheel=") - 1))
6233           {
6234              tmp = argv[i] + sizeof("--hwheel=") - 1;
6235              button = E_INFO_BUTTON_HWHEEL;
6236              state = E_INFO_EVENT_STATE_MOTION;
6237              y = atoi(tmp);
6238           }
6239         else
6240           {
6241              _e_info_client_inputgen_usage();
6242              return;
6243           }
6244      }
6245
6246    if (state == E_INFO_EVENT_STATE_MOTION && ((x == 0) && (y == 0)))
6247      {
6248         printf("Please insert correct axis values for motion events\n");
6249         return;
6250      }
6251
6252    if (!_e_info_client_eldbus_message_with_args("mousegen", _e_info_client_cb_mousegen, "iiii", button, x, y, state))
6253      return;
6254 }
6255
6256 static void
6257 _e_info_client_cb_mouse_accel(const Eldbus_Message *msg)
6258 {
6259    const char *errname = NULL, *errtext = NULL;
6260    char *result = NULL;
6261
6262    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6263
6264    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6265
6266    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6267      printf("Mouse_accel Failed: %s\n", result);
6268    else
6269      printf("Mouse_accel Success\n");
6270
6271    return;
6272
6273 err:
6274    if(errname || errtext)
6275      printf("errname : %s, errmsg : %s\n", errname, errtext);
6276    else
6277      printf("Error occurred in _e_info_client_cb_mouse_accel\n");
6278 }
6279
6280 void
6281 _e_info_client_proc_mouse_accel(int argc, char **argv)
6282 {
6283    int state = 1;
6284    char *tmp = NULL;
6285
6286    if (argc < 3)
6287      {
6288         _e_info_client_inputgen_usage();
6289         return;
6290      }
6291
6292    if (!strncmp(argv[2], "--state=", sizeof("--state=") - 1))
6293      {
6294         tmp = argv[2] + sizeof("--state=") - 1;
6295         state = atoi(tmp);
6296         if (!(state == 0 || state == 1))
6297           {
6298              printf("Please input correct mouse_accel state (off: 0), (on: 1)\n");
6299              return;
6300           }
6301      }
6302    else
6303      {
6304         _e_info_client_inputgen_usage();
6305         return;
6306      }
6307
6308    if (!_e_info_client_eldbus_message_with_args("mouse_accel", _e_info_client_cb_mouse_accel, "i", state))
6309      return;
6310 }
6311
6312 static void
6313 _e_info_client_cb_input_log_enable(const Eldbus_Message *msg)
6314 {
6315    const char *errname = NULL, *errtext = NULL;
6316    char *result = NULL;
6317
6318    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6319
6320    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6321
6322    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6323      printf("Input_Log_Enable Failed: %s\n", result);
6324    else
6325      printf("Input_Log_Enable Success\n");
6326
6327    return;
6328
6329 err:
6330    if(errname || errtext)
6331      printf("errname : %s, errmsg : %s\n", errname, errtext);
6332    else
6333      printf("Error occurred in _e_info_client_cb_input_log_enable\n");
6334 }
6335
6336 void
6337 _e_info_client_proc_input_log_enable(int argc, char **argv)
6338 {
6339    uint32_t onoff;
6340
6341    if (argc < 3)
6342      {
6343         _e_info_client_inputgen_usage();
6344         return;
6345      }
6346
6347    if (!isdigit(*argv[2]))
6348      {
6349         printf("Error Check Args: enlightenment_info -input_log_enable [1: on, 0: off]\n");
6350         return;
6351      }
6352
6353    onoff = atoi(argv[2]);
6354
6355    if (onoff == 0 || onoff == 1)
6356      {
6357         if (!_e_info_client_eldbus_message_with_args("input_log_enable", _e_info_client_cb_input_log_enable, "i", onoff))
6358           {
6359              printf("_e_info_client_eldbus_message_with_args error");
6360              return;
6361           }
6362      }
6363    else
6364      printf("Error Check Args: enlightenment_info -input_log_enable [1: on, 0: off]\n");
6365 }
6366
6367 static void
6368 _e_info_client_cb_use_cursor_timer(const Eldbus_Message *msg)
6369 {
6370    const char *errname = NULL, *errtext = NULL;
6371    char *result = NULL;
6372
6373    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6374
6375    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6376
6377    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6378      printf("Use_Cursor_Timer Failed: %s\n", result);
6379    else
6380      printf("Use_Cursor_Timer Success\n");
6381
6382    return;
6383
6384 err:
6385    if(errname || errtext)
6386      printf("errname : %s, errmsg : %s\n", errname, errtext);
6387    else
6388      printf("Error occurred in _e_info_client_cb_input_log_enable\n");
6389 }
6390
6391 void
6392 _e_info_client_proc_use_cursor_timer(int argc, char **argv)
6393 {
6394    uint32_t onoff;
6395
6396    if (argc < 3)
6397      {
6398         _e_info_client_inputgen_usage();
6399         return;
6400      }
6401
6402    if (!isdigit(*argv[2]))
6403      {
6404         printf("Error Check Args: enlightenment_info -use_cursor_timer [1: on, 0: off]\n");
6405         return;
6406      }
6407
6408    onoff = atoi(argv[2]);
6409
6410    if (onoff == 0 || onoff == 1)
6411      {
6412         if (!_e_info_client_eldbus_message_with_args("use_cursor_timer", _e_info_client_cb_use_cursor_timer, "i", onoff))
6413           {
6414              printf("_e_info_client_eldbus_message_with_args error");
6415              return;
6416           }
6417      }
6418    else
6419      printf("Error Check Args: enlightenment_info -use_cursor_timer [1: on, 0: off]\n");
6420 }
6421
6422 static void
6423 _e_info_client_cb_filter(const Eldbus_Message *msg)
6424 {
6425    const char *name = NULL, *text = NULL;
6426    Eina_Bool res;
6427    const char *reply;
6428
6429    res = eldbus_message_error_get(msg, &name, &text);
6430    EINA_SAFETY_ON_TRUE_GOTO(res, finish);
6431
6432    res = eldbus_message_arguments_get(msg, "s", &reply);
6433    printf("%s\n", reply);
6434
6435 finish:
6436    if ((name) || (text))
6437      {
6438         printf("errname:%s errmsg:%s\n", name, text);
6439      }
6440 }
6441
6442 static void
6443 _e_info_client_proc_apply_filter(int argc, char **argv)
6444 {
6445    Eina_Bool res = EINA_FALSE;
6446    int onoff = -1;
6447
6448    if (argc == 2)
6449      {
6450         //print current filter
6451         res = _e_info_client_eldbus_message_with_args("filter",
6452                                                       _e_info_client_cb_filter,
6453                                                       "is",
6454                                                       -1,
6455                                                       "info");
6456         if (!res) printf("Error occured while sending message\n\n");
6457         return;
6458      }
6459    else if (argc == 4)
6460      {
6461         EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[2], "blur")) ||
6462                                   (!strcmp(argv[2], "grayscale")) ||
6463                                   (!strcmp(argv[2], "inverse_color")), usage);
6464         EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[3], "on")) ||
6465                                   (!strcmp(argv[3], "off")) ||
6466                                   (!strcmp(argv[3], "1")) ||
6467                                   (!strcmp(argv[3], "0")), usage);
6468
6469         if (!strcmp(argv[3], "on") || !strcmp(argv[3], "1")) onoff = 1;
6470         else onoff = 0;
6471
6472         res = _e_info_client_eldbus_message_with_args("filter",
6473                                                       _e_info_client_cb_filter,
6474                                                       "sis",
6475                                                       "0x0",
6476                                                       onoff,
6477                                                       argv[2]);
6478         if (!res) printf("Error occured while sending message\n\n");
6479         return;
6480      }
6481    else if (argc == 5)
6482      {
6483         EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[3], "blur")) ||
6484                                   (!strcmp(argv[3], "grayscale")) ||
6485                                   (!strcmp(argv[3], "inverse_color")), usage);
6486         EINA_SAFETY_ON_FALSE_GOTO((!strcmp(argv[4], "on")) ||
6487                                   (!strcmp(argv[4], "off")) ||
6488                                   (!strcmp(argv[4], "1")) ||
6489                                   (!strcmp(argv[4], "0")), usage);
6490
6491         if (!strcmp(argv[4], "on") || !strcmp(argv[4], "1")) onoff = 1;
6492         else onoff = 0;
6493
6494         res = _e_info_client_eldbus_message_with_args("filter",
6495                                                       _e_info_client_cb_filter,
6496                                                       "sis",
6497                                                       argv[2],
6498                                                       onoff,
6499                                                       argv[3]);
6500         if (!res) printf("Error occured while sending message\n\n");
6501         return;
6502      }
6503
6504 usage:
6505    printf("Usage: %s", USAGE_FILTER);
6506 }
6507
6508 static void
6509 _e_info_client_proc_mtrace(int argc, char **argv)
6510 {
6511    int enable = 0;
6512
6513    if (argc == 3)
6514      {
6515         if ((argv[2][0] != '0' && argv[2][0] != '1'))
6516           {
6517              printf("Error: invalid argument\n");
6518              return;
6519           }
6520
6521         enable = atoi(argv[2]);
6522         if (!_e_info_client_eldbus_message_with_args("mtrace", NULL, "i", enable))
6523           {
6524              printf("_e_info_client_proc_mtrace fail (enable:%d)\n", enable);
6525              return;
6526           }
6527      }
6528    else
6529      {
6530         printf("Error: invalid argument\n");
6531         return;
6532      }
6533
6534    return;
6535 }
6536
6537 static void
6538 _e_info_client_proc_gcov(int argc, char **argv)
6539 {
6540    int mode = 0;
6541
6542    if (argc == 3)
6543      {
6544         if ((argv[2][0] < '0' || argv[2][0] > '1'))
6545           {
6546              printf("Error: invalid argument\n");
6547              return;
6548           }
6549
6550         mode = atoi(argv[2]);
6551         if (!_e_info_client_eldbus_message_with_args("gcov", NULL, "i", mode))
6552           {
6553              printf("_e_info_client_proc_gcov fail (%d)\n", mode);
6554              return;
6555           }
6556      }
6557    else
6558      {
6559         printf("Error: invalid argument\n");
6560         return;
6561      }
6562
6563    return;
6564 }
6565
6566 static void
6567 _e_info_client_basic_operation_gen(int argc, char **argv)
6568 {
6569    const char *win, *operation;
6570    Eldbus_Message *msg;
6571    Eldbus_Message_Iter *itr;
6572    Eldbus_Pending *p;
6573
6574    if (argc < 4)
6575      {
6576         printf("Error Check Args: enlightenment_info -basic_op_gen [window] [operation]\n");
6577         return;
6578      }
6579
6580    win = argv[2];
6581    operation = argv[3];
6582
6583    msg = eldbus_proxy_method_call_new(e_info_client.proxy, "basic_op_gen");
6584    itr = eldbus_message_iter_get(msg);
6585    eldbus_message_iter_basic_append(itr, 's', win);
6586    eldbus_message_iter_basic_append(itr, 's', operation);
6587
6588    p = eldbus_proxy_send(e_info_client.proxy, msg,
6589                          _e_info_client_eldbus_message_cb,
6590                          NULL, -1);
6591    if (!p)
6592      {
6593         printf("\"aux_msg\" proxy_send error");
6594         return;
6595      }
6596
6597    ecore_main_loop_begin();
6598 }
6599
6600 static void
6601 _e_info_client_process_info_print(int argc, char **argv)
6602 {
6603    Eina_Bool res;
6604
6605    if (argc < 2)
6606      {
6607         printf("Error Check Args: enlightenment_info -process_info\n");
6608         return;
6609      }
6610
6611    res = _e_info_client_eldbus_message("process_info", NULL);
6612    EINA_SAFETY_ON_FALSE_RETURN(res);
6613 }
6614
6615 static void
6616 _e_info_client_proc_zone_set(int argc, char **argv)
6617 {
6618    int zone_id = 0;
6619
6620    if (argc < 4)
6621      {
6622         printf("Error Check Args: enlightenment_info -zone_set [windowID] [zone id]\n");
6623         return;
6624      }
6625
6626    zone_id = atoi(argv[3]);
6627
6628    if (!_e_info_client_eldbus_message_with_args("zone_set", NULL, "si",
6629                                                 argv[2], zone_id))
6630      {
6631         printf("_e_info_client_eldbus_message_with_args error");
6632         return;
6633      }
6634 }
6635
6636 static void
6637 _e_info_client_proc_input_output_set(int argc, char **argv)
6638 {
6639    if (argc < 4)
6640      {
6641         printf("Error Check Args: -input_output_set [input(ex./dev/input/eventX)] [output(ex.HDMIA-1)]\n");
6642         return;
6643      }
6644
6645    if (!_e_info_client_eldbus_message_with_args("input_output_set", NULL, "ss",
6646                                                 argv[2], argv[3]))
6647      {
6648         printf("_e_info_client_eldbus_message_with_args error");
6649         return;
6650      }
6651 }
6652
6653 static void
6654 _e_info_client_proc_input_seat_set(int argc, char **argv)
6655 {
6656    if (argc < 4)
6657      {
6658         printf("Error Check Args: -input_seat_set [input(ex./dev/input/eventX)] [seat(ex.seat-bluetooth)]\n");
6659         return;
6660      }
6661
6662    if (!_e_info_client_eldbus_message_with_args("input_seat_set", NULL, "ss",
6663                                                 argv[2], argv[3]))
6664      {
6665         printf("_e_info_client_eldbus_message_with_args error");
6666         return;
6667      }
6668 }
6669
6670 static void
6671 _e_info_client_proc_resize_ppu_set(int argc, char **argv)
6672 {
6673    uint32_t ppu;
6674
6675    if (argc < 4)
6676      {
6677         printf("Error Check Args: enlightenment_info -resize_ppu window_ID value[0~32]\n");
6678         return;
6679      }
6680
6681    ppu = atoi(argv[3]);
6682
6683    if (!_e_info_client_eldbus_message_with_args("resize_ppu_set", NULL, "si", argv[2], ppu))
6684      {
6685         printf("_e_info_client_eldbus_message_with_args error");
6686         return;
6687      }
6688 }
6689
6690 static void
6691 _e_info_client_property_set(int argc, char **argv)
6692 {
6693    const char *win, *property;
6694    int set;
6695
6696    if (argc < 5)
6697      {
6698         printf("Error Check Args: winfo -prop_set [window] [property] [value]\n");
6699         return;
6700      }
6701
6702    win = argv[2];
6703    property = argv[3];
6704    set = atoi(argv[4]);
6705
6706    if (!_e_info_client_eldbus_message_with_args("prop_set", NULL, "ssi", win, property, set))
6707      {
6708         printf("_e_info_client_eldbus_message_with_args error");
6709         return;
6710      }
6711 }
6712
6713 static void
6714 _e_info_client_cb_input_subtype_set(const Eldbus_Message *msg)
6715 {
6716    const char *errname = NULL, *errtext = NULL;
6717    char *result = NULL;
6718
6719    EINA_SAFETY_ON_TRUE_GOTO(eldbus_message_error_get(msg, &errname, &errtext), err);
6720
6721    EINA_SAFETY_ON_FALSE_GOTO(eldbus_message_arguments_get(msg, "s", &result), err);
6722
6723    if (strncmp(result, E_INFO_INPUT_RESULT_NONE, sizeof(E_INFO_INPUT_RESULT_NONE)))
6724      printf("Input_Subtype_Set Failed: %s\n", result);
6725    else
6726      printf("Input_Subtype_Set Success\n");
6727
6728    return;
6729
6730 err:
6731    if(errname || errtext)
6732      printf("errname : %s, errmsg : %s\n", errname, errtext);
6733    else
6734      printf("Error occurred in _e_info_client_cb_input_subtype_set\n");
6735 }
6736
6737 static void
6738 _e_info_client_proc_input_subtype_set(int argc, char **argv)
6739 {
6740    if (argc < 4)
6741      {
6742         printf("Error Check Args: -input_subtype_set [input(ex./dev/input/eventX)] [subtype(ex.None/Remocon)]\n");
6743         return;
6744      }
6745
6746    if (!_e_info_client_eldbus_message_with_args("input_subtype_set", _e_info_client_cb_input_subtype_set, "ss",
6747                                                 argv[2], argv[3]))
6748      {
6749         printf("_e_info_client_eldbus_message_with_args error");
6750         return;
6751      }
6752 }
6753
6754 static void
6755 _e_info_client_proc_kvm_transparent_set(int argc, char **argv)
6756 {
6757    int set = 0;
6758    Eina_Bool res;
6759
6760    EINA_SAFETY_ON_FALSE_GOTO(argc == 3, usage);
6761
6762    set = atoi(argv[2]);
6763    if ((set != 0) && (set != 1))
6764      goto usage;
6765
6766    res = _e_info_client_eldbus_message_with_args("kvm_transparent", NULL, "i", set);
6767    EINA_SAFETY_ON_FALSE_RETURN(res);
6768
6769    goto finish;
6770
6771 usage :
6772    printf("Usage: %s -kvm_transparent_set [0:unset(opaque), 1:set(transparent)]\n", argv[0]);
6773
6774 finish:
6775    return;
6776 }
6777
6778 typedef struct _ProcInfo
6779 {
6780    const char *option;
6781    const char *params;
6782    const char *description;
6783    void (*func)(int argc, char **argv);
6784 } ProcInfo;
6785
6786 static ProcInfo procs_to_tracelogs[] =
6787 {
6788    {
6789       "version",
6790       NULL,
6791       "Print version of enlightenment",
6792       _e_info_client_proc_version
6793    },
6794    {
6795       "protocol_trace", "[console|file_path|disable]",
6796       "Enable/Disable wayland protocol trace",
6797       _e_info_client_proc_protocol_trace
6798    },
6799    {
6800       "protocol_rule",
6801       PROTOCOL_RULE_USAGE,
6802       "Add/Remove wayland protocol rule you want to trace",
6803       _e_info_client_proc_protocol_rule
6804    },
6805    {
6806       "eina_log_levels", "[mymodule1:5,mymodule2:2]",
6807       "Set EINA_LOG_LEVELS in runtime",
6808       _e_info_client_proc_eina_log_levels
6809    },
6810    {
6811       "eina_log_path", "[console|file_path]",
6812       "Set eina-log path in runtime",
6813       _e_info_client_proc_eina_log_path
6814    },
6815 #ifdef HAVE_DLOG
6816    {
6817       "dlog",
6818       "[on:1,off:0]",
6819       "Logging using dlog system [on 1, off 0]",
6820       _e_info_client_proc_dlog_switch
6821    },
6822 #endif
6823    {
6824       "trace",
6825       "[hwc | exsync] [off: 0, on: 1]",
6826       "Show the trace log in detail",
6827       _e_info_client_proc_trace
6828    },
6829 };
6830
6831 static ProcInfo procs_to_printinfo[] =
6832 {
6833    {
6834       "topvwins", NULL,
6835       "Print top visible windows",
6836       _e_info_client_proc_topvwins_info
6837    },
6838    {
6839       "topwins", NULL,
6840       "Print all windows",
6841       _e_info_client_proc_topwins_info
6842    },
6843    {
6844       "compobjs", "[simple]",
6845       "Print detailed information of all composite objects",
6846       _e_info_client_proc_compobjs_info
6847    },
6848    {
6849       "subsurface", NULL,
6850       "Print subsurface information",
6851       _e_info_client_proc_subsurface
6852    },
6853    {
6854       "connected_clients", NULL,
6855       "Print connected clients on Enlightenment",
6856       _e_info_client_proc_connected_clients
6857    },
6858    {
6859       "reslist",
6860       RESLIST_USAGE,
6861       "Print connected client's resources",
6862       _e_info_client_proc_res_lists
6863    },
6864    {
6865       "input_devices", NULL,
6866       "Print connected input devices",
6867       _e_info_client_proc_input_device_info
6868    },
6869    {
6870       "output_mode",
6871       "[output idx] [mode number]",
6872       "Print output mode info",
6873       _e_info_client_proc_output_mode
6874    },
6875    {
6876       "show_plane_state",
6877       NULL,
6878       "Print state of plane",
6879       _e_info_client_proc_show_plane_state
6880    },
6881    {
6882       "show_pending_commit",
6883       NULL,
6884       "Print state of pending commit",
6885       _e_info_client_proc_show_pending_commit
6886    },
6887    {
6888       "fps",
6889       FPS_USAGE,
6890       "Print FPS in every sec per",
6891       _e_info_client_proc_fps_info
6892    },
6893    {
6894       "keymap", NULL,
6895       "Print a current keymap",
6896       _e_info_client_proc_keymap_info
6897    },
6898    {
6899       "keygrab_status", NULL,
6900       "Print a keygrab status",
6901       _e_info_client_proc_keygrab_status
6902    },
6903    {
6904       "module_info", NULL,
6905       "Print information maintained by extra modules",
6906       _e_info_client_proc_module_info
6907    },
6908    {
6909       "wininfo",
6910       WININFO_USAGE,
6911       "Print information about windows",
6912       _e_info_client_proc_wininfo
6913    },
6914    {
6915       "input_region",
6916       NULL,
6917       "Print input regions",
6918       _e_info_client_proc_input_region
6919    },
6920    {
6921       "hwc_wins",
6922       NULL,
6923       "Print hwc windows information",
6924       _e_info_client_proc_hwc_wins
6925    },
6926    {
6927       "screen_info",
6928       NULL,
6929       "Print screen and output information",
6930       _e_info_client_proc_screen_info
6931    },
6932 };
6933
6934 static ProcInfo procs_to_execute[] =
6935 {
6936    {
6937       "set_force_visible", NULL,
6938       "Show/Hide a composite object",
6939       _e_info_client_proc_force_visible
6940    },
6941    {
6942       "dump",
6943       USAGE_DUMPIMAGE,
6944       "Dump window images with options [topvwins, ns]",
6945       _e_info_client_proc_wins_shot
6946    },
6947    {
6948       "prop",
6949       PROP_USAGE,
6950       "Get/Set window(s) property(ies)",
6951       _e_info_client_prop_prop_info
6952    },
6953    {
6954       "rotation",
6955       ROTATION_USAGE,
6956       "Send a message about rotation",
6957       _e_info_client_proc_rotation
6958    },
6959    {
6960       "bgcolor_set", "[<a>,<r>,<g>,<b>]",
6961       "Set the background color of enlightenment canvas",
6962       _e_info_client_proc_bgcolor_set
6963    },
6964    {
6965       "key_repeat",
6966       "[print] [set <delay> <rate>]",
6967       "Print or Set key repeat info",
6968       _e_info_client_proc_key_repeat
6969    },
6970    {
6971       "punch", "[on/off] [<X>x<H>+<X>+<Y>] [<a>,<r>,<g>,<b>]",
6972       "HWC should be disabled first with \"-hwc\" option. Punch a UI framebuffer [on/off].",
6973       _e_info_client_proc_punch
6974    },
6975    {
6976       "transform",
6977       "[windowID transform_id enable x y scale_x(percent) scale_y(percent) angle is_bg]",
6978       "Set transform in runtime",
6979       _e_info_client_proc_transform_set
6980    },
6981    {
6982       "dump_buffers", DUMP_BUFFERS_USAGE,
6983       "Dump attach buffers [on:1,off:0] (default path:/tmp/dump_xxx/)",
6984       _e_info_client_proc_buffer_shot
6985    },
6986    {
6987       "dump_selected_buffers", DUMP_BUFFERS_USAGE,
6988       "Dump Win_ID buffers. Win_ID comed from enlightenment_info -topvwins(default path:/tmp/dump_xxx/)",
6989       _e_info_client_proc_selected_buffer_shot
6990    },
6991    {
6992       "dump_screen", "enlightenment_info -dump_screen -p /tmp/ -n xxx.png   :make dump /tmp/xxx.png",
6993       "Dump current screen (default path:/tmp/dump_screen.png)",
6994       _e_info_client_proc_screen_shot
6995    },
6996    {
6997       "hwc",
6998       "[on: 1, off: 0, 2: info]",
6999       "HW composite policy on(1) and off(0), or prints info(2) via dlog",
7000       _e_info_client_proc_hwc
7001    },
7002    {
7003       "effect",
7004       "[on: 1, off: 0]",
7005       "Window effect [on 1, off 0]",
7006       _e_info_client_proc_effect_control
7007    },
7008    {
7009       "quickpanel",
7010       USAGE_QUICKPANEL_CONTROL,
7011       "Control quickpanel state",
7012       _e_info_client_quickpanel_control
7013    },
7014    {
7015       "aux_msg",
7016       "[window] [key] [value] [options]",
7017       "Send aux message to client",
7018       _e_info_client_proc_aux_message
7019    },
7020    {
7021       "aux_hint",
7022       "[window] [hint id] [hint] [value]",
7023       "Set aux hint to client",
7024       _e_info_client_proc_aux_hint
7025    },
7026    {
7027       "scrsaver",
7028       USAGE_SCRSAVER,
7029       "Set parameters of the screen saver",
7030       _e_info_client_proc_scrsaver
7031    },
7032    {
7033       "desk",
7034       USAGE_DESK,
7035       "Set geometry or zoom for current desktop",
7036       _e_info_client_proc_desk
7037    },
7038    {
7039       "frender",
7040       USAGE_FORCE_RENDER,
7041       "Force render according to parameters",
7042       _e_info_client_proc_force_render
7043    },
7044    {
7045       "screen_rotation_pre",
7046       "[0|90|180|270]",
7047       "To rotate screen (pre)",
7048       _e_info_client_proc_screen_rotation_pre
7049    },
7050    {
7051       "screen_rotation",
7052       "[0|90|180|270]",
7053       "To rotate screen",
7054       _e_info_client_proc_screen_rotation
7055    },
7056    {
7057       "remote_surface",
7058       USAGE_REMOTE_SURFACE,
7059       "For remote surface debugging",
7060       _e_info_client_proc_remote_surface
7061    },
7062    {
7063       "kill",
7064       KILL_USAGE,
7065       "Kill a client",
7066       _e_info_client_proc_kill_client
7067    },
7068    {
7069       "module",
7070       "[list], [load <module_name>], [unload <module_name>]",
7071       "Manage modules on enlightenment",
7072       _e_info_client_proc_module
7073    },
7074    {
7075       "shutdown",
7076       NULL,
7077       "Shutdown Enlightenment",
7078       _e_info_client_proc_shutdown
7079    },
7080    {
7081       "buffer_flush",
7082       "[on <win_id / all>], [off <win_id / all>], [show <win_id / all>]",
7083       "Set buffer_flush configure",
7084       _e_info_client_proc_buffer_flush
7085    },
7086    {
7087       "deiconify_approve",
7088       "[on <win_id / all>], [off <win_id / all>], [show <win_id / all>]",
7089       "Set deiconify_approve configure",
7090       _e_info_client_proc_deiconify_approve
7091    },
7092    {
7093       "dump_memory",
7094       "file dumped under /tmp dir.",
7095       "Dump stack information by allocations",
7096       _e_info_client_memchecker
7097    },
7098    {
7099       "mtrace",
7100       "[enable: 1, disable: 0]",
7101       "enable/disable mtrace",
7102       _e_info_client_proc_mtrace
7103    },
7104    {
7105       "magnifier",
7106       NULL,
7107       "On/Off magnifier window",
7108       _e_info_client_magnifier
7109    },
7110    {
7111       "focus_policy_ext",
7112       "[0], [1]",
7113       "set focus_policy_ext, 0 is E_FOCUS_EXT_TOP_STACK, 1 is E_FOCUS_EXT_HISTORY",
7114       _e_info_client_proc_focus_policy_ext
7115    },
7116    {
7117       "focus_history",
7118       NULL,
7119       "get focus history",
7120       _e_info_client_proc_focus_history
7121    },
7122    {
7123       "dump_video",  /* Option */
7124       SCREEN_RECORDER_USAGE,/* Params */
7125       "Recording the screen", /* Description */
7126       _e_info_client_proc_screen_record /* func */
7127    },
7128    {
7129       "filter",
7130       USAGE_FILTER,
7131       "apply filter option to windows",
7132       _e_info_client_proc_apply_filter
7133    },
7134    {
7135       "desk_area",
7136       USAGE_DESK_AREA,
7137       "Get information or Enable/Disable functionality for desk group",
7138       _e_info_client_proc_desk_area
7139    },
7140    {
7141       "gcov",
7142       NULL,
7143       "execute gcov flush",
7144       _e_info_client_proc_gcov
7145    },
7146    {
7147       "basic_op_gen",
7148       USAGE_BASIC_OPERATION_GENERATE,
7149       "Generate basic operation",
7150       _e_info_client_basic_operation_gen
7151    },
7152    {
7153       "process_info",
7154       NULL,
7155       "Print process information",
7156       _e_info_client_process_info_print
7157    },
7158    {
7159       "zone_set",
7160       "[windowID zoneID]",
7161       "Set zone",
7162       _e_info_client_proc_zone_set
7163    },
7164    {
7165       "input_output_set",
7166       "[input(ex./dev/input/eventX) output(ex.HDMIA-1)]",
7167       "Set input device's output name",
7168       _e_info_client_proc_input_output_set
7169    },
7170    {
7171       "input_seat_set",
7172       "[input(ex./dev/input/eventX) seat(ex.seat_bluetooth)]",
7173       "Set input device's seat name",
7174       _e_info_client_proc_input_seat_set
7175    },
7176    {
7177       "resize_ppu",
7178       "[windowID ppu_value]",
7179       "Set resize ppu value",
7180       _e_info_client_proc_resize_ppu_set
7181    },
7182    {
7183       "prop_set",
7184       USAGE_PROPERTY_SET,
7185       "Set/Unset specify property",
7186       _e_info_client_property_set
7187    },
7188    {
7189       "kvm_transparent",
7190       "[0:unset(opaque), 1:set(transparent)]",
7191       "Set/Unset transparent of the kvm service window",
7192       _e_info_client_proc_kvm_transparent_set
7193    },
7194 };
7195
7196 ProcInfo procs_to_input[] =
7197 {
7198    {
7199       "init_device",    /* Option */
7200       NULL,/* Params */
7201       "Initialize input device", /* Description */
7202       _e_info_client_proc_init_device /* func */
7203    },
7204    {
7205       "deinit_device",  /* Option */
7206       NULL,/* Params */
7207       "Deinitialize input device", /* Description */
7208       _e_info_client_proc_deinit_device /* func */
7209    },
7210    {
7211       "keygen", /* Option */
7212       NULL,/* Params */
7213       "Generate key events", /* Description */
7214       _e_info_client_proc_keygen /* func */
7215    },
7216    {
7217       "touchgen",       /* Option */
7218       NULL,/* Params */
7219       "Generate touch events", /* Description */
7220       _e_info_client_proc_touchgen /* func */
7221    },
7222    {
7223       "mousegen",       /* Option */
7224       NULL,/* Params */
7225       "Generate mouse events", /* Description */
7226       _e_info_client_proc_mousegen /* func */
7227    },
7228    {
7229       "mouse_accel",    /* Option */
7230       NULL,/* Params */
7231       "Set mouse acceleration", /* Description */
7232       _e_info_client_proc_mouse_accel /* func */
7233    },
7234    {
7235       "input_log_enable",       /* Option */
7236       NULL,/* Params */
7237       "Set input log enable/disable", /* Description */
7238       _e_info_client_proc_input_log_enable /* func */
7239    },
7240    {
7241       "use_cursor_timer",       /* Option */
7242       NULL,/* Params */
7243       "Set use_cursor_timer enable/disable", /* Description */
7244       _e_info_client_proc_use_cursor_timer /* func */
7245    },
7246    {
7247       "input_subtype_set",
7248       "[input(ex./dev/input/eventX) subtype(ex.None/Remocon)]",
7249       "Set input device's subtype(subclas)",
7250       _e_info_client_proc_input_subtype_set
7251    },
7252 };
7253
7254 static Eina_List *list_tracelogs = NULL;
7255 static Eina_List *list_printinfo = NULL;
7256 static Eina_List *list_exec= NULL;
7257 static Eina_List *list_input = NULL;
7258
7259 static int
7260 _util_sort_string_cb(const void *data1, const void *data2)
7261 {
7262    const ProcInfo *info1, *info2;
7263    const char *s1, *s2;
7264
7265    info1 = data1;
7266    info2 = data2;
7267    s1 = info1->option;
7268    s2 = info2->option;
7269
7270    return strncmp(s1, s2, strlen(s2));
7271 }
7272
7273 static void
7274 _e_info_client_shutdown_list(void)
7275 {
7276    list_tracelogs = eina_list_free(list_tracelogs);
7277    list_printinfo = eina_list_free(list_printinfo);
7278    list_exec = eina_list_free(list_exec);
7279    list_input = eina_list_free(list_input);
7280 }
7281
7282 static void
7283 _e_info_client_init_list(void)
7284 {
7285    int n_info = 0, i;
7286    list_tracelogs = list_printinfo = list_exec = list_input = NULL;
7287
7288    n_info = sizeof(procs_to_tracelogs) / sizeof(procs_to_tracelogs[0]);
7289    for (i = 0; i < n_info; i++)
7290      {
7291         list_tracelogs = eina_list_append(list_tracelogs, &procs_to_tracelogs[i]);
7292      }
7293
7294    n_info = sizeof(procs_to_printinfo) / sizeof(procs_to_printinfo[0]);
7295    for (i = 0; i < n_info; i++)
7296      {
7297         list_printinfo = eina_list_append(list_printinfo, &procs_to_printinfo[i]);
7298      }
7299    list_printinfo = eina_list_sort(list_printinfo, eina_list_count(list_printinfo), _util_sort_string_cb);
7300
7301    n_info = sizeof(procs_to_execute) / sizeof(procs_to_execute[0]);
7302    for (i = 0; i < n_info; i++)
7303      {
7304         list_exec = eina_list_append(list_exec, &procs_to_execute[i]);
7305      }
7306    list_exec = eina_list_sort(list_exec, eina_list_count(list_exec), _util_sort_string_cb);
7307
7308    n_info = sizeof(procs_to_input) / sizeof(procs_to_input[0]);
7309    for (i = 0; i < n_info; i++)
7310      {
7311         list_input = eina_list_append(list_input, &procs_to_input[i]);
7312      }
7313    list_input = eina_list_sort(list_input, eina_list_count(list_input), _util_sort_string_cb);
7314 }
7315
7316 static void
7317 _e_info_client_eldbus_message_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *p EINA_UNUSED)
7318 {
7319    E_Info_Message_Cb cb = (E_Info_Message_Cb)data;
7320
7321    if (cb) cb(msg);
7322
7323    ecore_main_loop_quit();
7324 }
7325
7326 static Eina_Bool
7327 _e_info_client_eldbus_message(const char *method, E_Info_Message_Cb cb)
7328 {
7329    Eldbus_Pending *p;
7330
7331    p = eldbus_proxy_call(e_info_client.proxy, method,
7332                          _e_info_client_eldbus_message_cb,
7333                          cb, -1, "");
7334    EINA_SAFETY_ON_NULL_RETURN_VAL(p, EINA_FALSE);
7335
7336    ecore_main_loop_begin();
7337    return EINA_TRUE;
7338 }
7339
7340 static Eina_Bool
7341 _e_info_client_eldbus_message_with_args(const char *method, E_Info_Message_Cb cb, const char *signature, ...)
7342 {
7343    Eldbus_Pending *p;
7344    va_list ap;
7345
7346    va_start(ap, signature);
7347    p = eldbus_proxy_vcall(e_info_client.proxy, method,
7348                           _e_info_client_eldbus_message_cb,
7349                           cb, -1, signature, ap);
7350    va_end(ap);
7351    EINA_SAFETY_ON_NULL_RETURN_VAL(p, EINA_FALSE);
7352
7353    ecore_main_loop_begin();
7354    return EINA_TRUE;
7355 }
7356
7357 static Eina_Bool
7358 _e_info_client_eldbus_message_with_args_timeout(const char *method, E_Info_Message_Cb cb, double timeout, const char *signature, ...)
7359 {
7360    Eldbus_Pending *p;
7361    va_list ap;
7362
7363    va_start(ap, signature);
7364    p = eldbus_proxy_vcall(e_info_client.proxy, method,
7365                           _e_info_client_eldbus_message_cb,
7366                           cb, timeout, signature, ap);
7367    va_end(ap);
7368    EINA_SAFETY_ON_NULL_RETURN_VAL(p, EINA_FALSE);
7369
7370    ecore_main_loop_begin();
7371    return EINA_TRUE;
7372 }
7373
7374 static void
7375 _e_info_client_eldbus_disconnect(void)
7376 {
7377    if (e_info_client.proxy)
7378      {
7379         eldbus_proxy_unref(e_info_client.proxy);
7380         e_info_client.proxy = NULL;
7381      }
7382
7383    if (e_info_client.obj)
7384      {
7385         eldbus_object_unref(e_info_client.obj);
7386         e_info_client.obj = NULL;
7387      }
7388
7389    if (e_info_client.conn)
7390      {
7391         eldbus_connection_unref(e_info_client.conn);
7392         e_info_client.conn = NULL;
7393      }
7394
7395    if (e_info_client.eldbus_init)
7396      {
7397         eldbus_shutdown();
7398         e_info_client.eldbus_init = 0;
7399      }
7400 }
7401
7402 static Eina_Bool
7403 _e_info_client_eldbus_connect(void)
7404 {
7405    e_info_client.eldbus_init = eldbus_init();
7406    EINA_SAFETY_ON_FALSE_GOTO(e_info_client.eldbus_init > 0, err);
7407
7408    e_info_client.conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
7409    EINA_SAFETY_ON_NULL_GOTO(e_info_client.conn, err);
7410
7411    e_info_client.obj = eldbus_object_get(e_info_client.conn,
7412                                          "org.enlightenment.wm",
7413                                          "/org/enlightenment/wm");
7414    EINA_SAFETY_ON_NULL_GOTO(e_info_client.obj, err);
7415
7416    e_info_client.proxy = eldbus_proxy_get(e_info_client.obj, "org.enlightenment.wm.info");
7417    EINA_SAFETY_ON_NULL_GOTO(e_info_client.proxy, err);
7418
7419    return EINA_TRUE;
7420
7421 err:
7422    _e_info_client_eldbus_disconnect();
7423    return EINA_FALSE;
7424 }
7425
7426 static Eina_Bool
7427 _e_info_client_process(int argc, char **argv)
7428 {
7429    Eina_List *l = NULL;
7430    ProcInfo  *procinfo = NULL;
7431    int proc_option_length, argv_len;
7432
7433    signal(SIGINT,  end_program);
7434    signal(SIGALRM, end_program);
7435    signal(SIGHUP,  end_program);
7436    signal(SIGPIPE, end_program);
7437    signal(SIGQUIT, end_program);
7438    signal(SIGTERM, end_program);
7439
7440    argv_len = strlen(argv[1]+1);
7441    EINA_LIST_FOREACH(list_tracelogs, l, procinfo)
7442      {
7443         proc_option_length = strlen(procinfo->option);
7444         if (argv_len != proc_option_length) continue;
7445         if (!strncmp(argv[1]+1, procinfo->option, proc_option_length))
7446           {
7447              if (procinfo->func)
7448                procinfo->func(argc, argv);
7449
7450              return EINA_TRUE;
7451           }
7452      }
7453
7454    EINA_LIST_FOREACH(list_printinfo, l, procinfo)
7455      {
7456         proc_option_length = strlen(procinfo->option);
7457         if (argv_len != proc_option_length) continue;
7458         if (!strncmp(argv[1]+1, procinfo->option, proc_option_length))
7459           {
7460              if (procinfo->func)
7461                procinfo->func(argc, argv);
7462
7463              return EINA_TRUE;
7464           }
7465      }
7466
7467    EINA_LIST_FOREACH(list_exec, l, procinfo)
7468      {
7469         proc_option_length = strlen(procinfo->option);
7470         if (argv_len != proc_option_length) continue;
7471         if (!strncmp(argv[1]+1, procinfo->option, proc_option_length))
7472           {
7473              if (procinfo->func)
7474                procinfo->func(argc, argv);
7475
7476              return EINA_TRUE;
7477           }
7478      }
7479
7480    EINA_LIST_FOREACH(list_input, l, procinfo)
7481      {
7482         proc_option_length = strlen(procinfo->option);
7483         if (argv_len != proc_option_length) continue;
7484         if (!strncmp(argv[1]+1, procinfo->option, proc_option_length))
7485           {
7486              if (procinfo->func)
7487                procinfo->func(argc, argv);
7488
7489              return EINA_TRUE;
7490           }
7491      }
7492
7493    return EINA_FALSE;
7494 }
7495
7496 static void
7497 _e_info_client_print_usage_all(const char *exec)
7498 {
7499    Eina_List *l = NULL;
7500    ProcInfo  *procinfo = NULL;
7501
7502    printf("\nUsage:\n");
7503    EINA_LIST_FOREACH(list_tracelogs, l, procinfo)
7504      {
7505         printf("  %s -%s %s\n", exec, procinfo->option, (procinfo->params)?procinfo->params:"");
7506      }
7507    printf("\n\n");
7508    EINA_LIST_FOREACH(list_printinfo, l, procinfo)
7509      {
7510         printf("  %s -%s %s\n", exec, procinfo->option, (procinfo->params)?procinfo->params:"");
7511      }
7512    printf("\n\n");
7513    EINA_LIST_FOREACH(list_exec, l, procinfo)
7514      {
7515         printf("  %s -%s %s\n", exec, procinfo->option, (procinfo->params)?procinfo->params:"");
7516      }
7517    printf("\n\n");
7518    EINA_LIST_FOREACH(list_input, l, procinfo)
7519      {
7520         printf("  %s -%s %s\n", exec, procinfo->option, (procinfo->params)?procinfo->params:"");
7521      }
7522 }
7523
7524 static void
7525 _e_info_client_print_usage(int argc, char **argv)
7526 {
7527    Eina_List *l = NULL;
7528    ProcInfo  *procinfo = NULL;
7529    int arglen, optlen;
7530
7531    arglen = strlen(argv[1]+1);
7532    EINA_LIST_FOREACH(list_tracelogs, l, procinfo)
7533      {
7534         optlen = strlen(procinfo->option);
7535         if (arglen != optlen) continue;
7536         if (!strncmp(argv[1]+1, procinfo->option, optlen))
7537           {
7538              printf("  %s\n\n", (procinfo->description)?procinfo->description:"");
7539              printf("  %s -%s %s\n", argv[0], procinfo->option, (procinfo->params)?procinfo->params:"");
7540              goto end;
7541           }
7542      }
7543
7544    EINA_LIST_FOREACH(list_printinfo, l, procinfo)
7545      {
7546         optlen = strlen(procinfo->option);
7547         if (arglen != optlen) continue;
7548         if (!strncmp(argv[1]+1, procinfo->option, optlen))
7549           {
7550              printf("  %s\n\n", (procinfo->description)?procinfo->description:"");
7551              printf("  %s -%s %s\n", argv[0], procinfo->option, (procinfo->params)?procinfo->params:"");
7552              goto end;
7553           }
7554      }
7555
7556    EINA_LIST_FOREACH(list_exec, l, procinfo)
7557      {
7558         optlen = strlen(procinfo->option);
7559         if (arglen != optlen) continue;
7560         if (!strncmp(argv[1]+1, procinfo->option, optlen))
7561           {
7562              printf("  %s\n\n", (procinfo->description)?procinfo->description:"");
7563              printf("  %s -%s %s\n", argv[0], procinfo->option, (procinfo->params)?procinfo->params:"");
7564              goto end;
7565           }
7566      }
7567
7568    EINA_LIST_FOREACH(list_input, l, procinfo)
7569      {
7570         optlen = strlen(procinfo->option);
7571         if (arglen != optlen) continue;
7572         if (!strncmp(argv[1]+1, procinfo->option, optlen))
7573           {
7574              printf("  %s\n\n", (procinfo->description)?procinfo->description:"");
7575              printf("  %s -%s %s\n", argv[0], procinfo->option, (procinfo->params)?procinfo->params:"");
7576              goto end;
7577           }
7578      }
7579
7580 end:
7581    printf("\n");
7582 }
7583
7584 static void
7585 _e_info_client_print_description(const char *exec)
7586 {
7587    Eina_List *l = NULL;
7588    ProcInfo  *procinfo = NULL;
7589
7590    printf("\n\n");
7591
7592    EINA_LIST_FOREACH(list_tracelogs, l, procinfo)
7593      {
7594         printf(" -%-30s\t", procinfo->option);
7595         printf(": %s\n", (procinfo->description)?procinfo->description:"");
7596      }
7597    printf("\n");
7598    EINA_LIST_FOREACH(list_printinfo, l, procinfo)
7599      {
7600         printf(" -%-30s\t", procinfo->option);
7601         printf(": %s\n", (procinfo->description)?procinfo->description:"");
7602      }
7603    printf("\n");
7604    EINA_LIST_FOREACH(list_exec, l, procinfo)
7605      {
7606         printf(" -%-30s\t", procinfo->option);
7607         printf(": %s\n", (procinfo->description)?procinfo->description:"");
7608      }
7609    printf("\n");
7610    EINA_LIST_FOREACH(list_input, l, procinfo)
7611      {
7612         printf(" -%-30s\t", procinfo->option);
7613         printf(": %s\n", (procinfo->description)?procinfo->description:"");
7614      }
7615
7616    printf("\n");
7617 }
7618
7619 static void
7620 end_program(int sig)
7621 {
7622    ecore_main_loop_quit();
7623    /* disconnecting dbus */
7624    _e_info_client_eldbus_disconnect();
7625    exit(EXIT_FAILURE);
7626 }
7627
7628 int
7629 main(int argc, char **argv)
7630 {
7631    if (!eina_init())
7632      {
7633         printf("fail eina_init");
7634         return -1;
7635      }
7636
7637    if (!ecore_init())
7638      {
7639         printf("fail ecore_init");
7640         eina_shutdown();
7641         return -1;
7642      }
7643
7644    /* list up all proc*/
7645    _e_info_client_init_list();
7646
7647    if (argc < 2 || argv[1][0] != '-')
7648      {
7649         _e_info_client_print_description(argv[0]);
7650         return 0;
7651      }
7652
7653    /* connecting dbus */
7654    if (!_e_info_client_eldbus_connect())
7655      {
7656         printf("fail eldbus connection");
7657         goto err;
7658      }
7659    if (!strcmp(argv[1], "-h") ||
7660        !strcmp(argv[1], "-help") ||
7661        !strcmp(argv[1], "--help"))
7662      {
7663         _e_info_client_print_usage_all(argv[0]);
7664      }
7665    else if (argc >= 3 &&
7666       (!strcmp(argv[2], "-h") ||
7667        !strcmp(argv[2], "-help") ||
7668        !strcmp(argv[2], "--help")))
7669      {
7670         _e_info_client_print_usage(argc, argv);
7671      }
7672    else
7673      {
7674         /* handling a client request */
7675         if (!_e_info_client_process(argc, argv))
7676           {
7677              printf("unknown option: %s\n", argv[1]);
7678              _e_info_client_print_usage(argc, argv);
7679           }
7680      }
7681
7682    /* list free proc*/
7683    _e_info_client_shutdown_list();
7684
7685    /* disconnecting dbus */
7686    _e_info_client_eldbus_disconnect();
7687
7688    return 0;
7689
7690 err:
7691    _e_info_client_shutdown_list();
7692    _e_info_client_eldbus_disconnect();
7693    return -1;
7694 }