atspi: refactor atspi_object class into mixins.
[platform/upstream/elementary.git] / src / lib / elm_win.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #include <Elementary.h>
6 #include <Elementary_Cursor.h>
7
8 #include "elm_priv.h"
9 #include "elm_widget_menu.h"
10
11 #define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
12
13 #include "elm_interface_atspi_accessible.h"
14 #include "elm_interface_atspi_accessible.eo.h"
15 #include "elm_interface_atspi_window.eo.h"
16 #include "elm_interface_atspi_widget.eo.h"
17
18 #define MY_CLASS ELM_OBJ_WIN_CLASS
19
20 #define MY_CLASS_NAME "Elm_Win"
21 #define MY_CLASS_NAME_LEGACY "elm_win"
22
23 static const Elm_Win_Trap *trap = NULL;
24
25 #define TRAP(sd, name, ...)                                             \
26   do                                                                    \
27     {                                                                   \
28        if ((!trap) || (!trap->name) ||                                  \
29            ((trap->name) &&                                             \
30             (trap->name(sd->trap_data, sd->obj, ## __VA_ARGS__)))) \
31          ecore_evas_##name(sd->ee, ##__VA_ARGS__);                      \
32     }                                                                   \
33   while (0)
34
35 #define ELM_WIN_DATA_GET(o, sd) \
36   Elm_Win_Data * sd = eo_data_scope_get(o, MY_CLASS)
37
38 #define ELM_WIN_DATA_GET_OR_RETURN(o, ptr)           \
39   ELM_WIN_DATA_GET(o, ptr);                          \
40   if (!ptr)                                          \
41     {                                                \
42        CRI("No widget data for object %p (%s)", \
43                 o, evas_object_type_get(o));         \
44        return;                                       \
45     }
46
47 #define ELM_WIN_DATA_GET_OR_RETURN_VAL(o, ptr, val)  \
48   ELM_WIN_DATA_GET(o, ptr);                          \
49   if (!ptr)                                          \
50     {                                                \
51        CRI("No widget data for object %p (%s)", \
52                 o, evas_object_type_get(o));         \
53        return val;                                   \
54     }
55
56 #define ELM_WIN_CHECK(obj)                                             \
57   if (!obj || !eo_isa(obj, MY_CLASS)) \
58     return
59
60 #define DECREMENT_MODALITY()                                    \
61   EINA_LIST_FOREACH(_elm_win_list, l, current)                  \
62     {                                                           \
63        ELM_WIN_DATA_GET_OR_RETURN(current, cursd);              \
64        if ((obj != current) && (cursd->modal_count > 0))        \
65          {                                                      \
66             cursd->modal_count--;                               \
67          }                                                      \
68        if (cursd->modal_count == 0)                             \
69          {                                                      \
70             edje_object_signal_emit(cursd->layout, \
71                         "elm,action,hide_blocker", "elm");      \
72             evas_object_smart_callback_call(cursd->main_menu, \
73                         "elm,action,unblock_menu", NULL);       \
74          }                                                      \
75     }
76
77 #define INCREMENT_MODALITY()                                    \
78   EINA_LIST_FOREACH(_elm_win_list, l, current)                  \
79     {                                                           \
80        ELM_WIN_DATA_GET_OR_RETURN(current, cursd);              \
81        if (obj != current)                                      \
82          {                                                      \
83             cursd->modal_count++;                               \
84          }                                                      \
85        if (cursd->modal_count > 0)                              \
86          {                                                      \
87             edje_object_signal_emit(cursd->layout, \
88                              "elm,action,show_blocker", "elm"); \
89             evas_object_smart_callback_call(cursd->main_menu, \
90                              "elm,action,block_menu", NULL);    \
91          }                                                      \
92     }
93
94 #define ENGINE_GET() (_elm_preferred_engine ? _elm_preferred_engine : (_elm_config->engine ? _elm_config->engine : ""))
95 #define ENGINE_COMPARE(name) (!strcmp(ENGINE_GET(), name))
96
97 typedef struct _Elm_Win_Data Elm_Win_Data;
98
99 struct _Elm_Win_Data
100 {
101    Ecore_Evas           *ee;
102    Evas                 *evas;
103    Evas_Object          *parent; /* parent *window* object*/
104    Evas_Object          *img_obj, *frame_obj;
105    Evas_Object          *client_obj; /* rect representing the client */
106    Evas_Object          *spacer_obj;
107    Eo                   *layout;
108    Eo                   *box;
109    Evas_Object          *obj; /* The object itself */
110 #ifdef HAVE_ELEMENTARY_X
111    struct
112    {
113       Ecore_X_Window       xwin;
114       Ecore_Event_Handler *client_message_handler;
115       Ecore_Event_Handler *property_handler;
116    } x;
117 #endif
118 #ifdef HAVE_ELEMENTARY_WAYLAND
119    struct
120    {
121       Ecore_Wl_Window *win;
122    } wl;
123 #endif
124
125    Ecore_Job                     *deferred_resize_job;
126    Ecore_Job                     *deferred_child_eval_job;
127
128    Elm_Win_Type                   type;
129    Elm_Win_Keyboard_Mode          kbdmode;
130    Elm_Win_Indicator_Mode         indmode;
131    Elm_Win_Indicator_Opacity_Mode ind_o_mode;
132    struct
133    {
134       const char  *info;
135       Ecore_Timer *timer;
136       int          repeat_count;
137       int          shot_counter;
138    } shot;
139    int                            resize_location;
140    int                           *autodel_clear, rot;
141    struct
142    {
143       int x, y;
144    } screen;
145    struct
146    {
147       Ecore_Evas  *ee;
148       Evas        *evas;
149       Evas_Object *obj, *hot_obj;
150       int          hot_x, hot_y;
151    } pointer;
152    struct
153    {
154       Evas_Object *fobj; /* focus highlight edje object */
155
156       struct
157       {
158          Evas_Object *target;
159          Eina_Bool    visible : 1;
160          Eina_Bool    in_theme: 1; /**< focus highlight is handled by theme.
161                                      this is set true if edc data item "focus_highlight" is set to "on" during focus in callback. */
162       } cur, prev;
163
164       const char  *style;
165       Ecore_Job   *reconf_job;
166
167       Eina_Bool    enabled : 1;
168       Eina_Bool    theme_changed : 1; /* set true when the focus theme is changed */
169       Eina_Bool    animate : 1; /* set true when the focus highlight animate is enabled */
170       Eina_Bool    animate_supported : 1; /* set true when the focus highlight animate is supported by theme */
171       Eina_Bool    geometry_changed : 1;
172    } focus_highlight;
173
174    Evas_Object *icon;
175    const char  *title;
176    const char  *icon_name;
177    const char  *role;
178
179    Evas_Object *main_menu;
180
181    struct
182    {
183       const char  *name;
184       const char **available_list;
185       unsigned int count;
186    } profile;
187    struct
188    {
189       int          preferred_rot; /* indicates preferred rotation value, -1 means invalid. */
190       int         *rots; /* indicates available rotations */
191       unsigned int count; /* number of elements in available rotations */
192       Eina_Bool    wm_supported : 1; /* set true when the window manager support window rotation */
193       Eina_Bool    use : 1; /* set ture when application use window manager rotation. */
194    } wm_rot;
195
196    void *trap_data;
197
198    double       aspect;
199    int          size_base_w, size_base_h;
200    int          size_step_w, size_step_h;
201    int          norender;
202    int          modal_count;
203    Eina_Bool    urgent : 1;
204    Eina_Bool    modal : 1;
205    Eina_Bool    demand_attention : 1;
206    Eina_Bool    autodel : 1;
207    Eina_Bool    constrain : 1;
208    Eina_Bool    resizing : 1;
209    Eina_Bool    iconified : 1;
210    Eina_Bool    withdrawn : 1;
211    Eina_Bool    sticky : 1;
212    Eina_Bool    fullscreen : 1;
213    Eina_Bool    maximized : 1;
214    Eina_Bool    skip_focus : 1;
215    Eina_Bool    floating : 1;
216 };
217
218 static const char SIG_DELETE_REQUEST[] = "delete,request";
219 static const char SIG_FOCUS_OUT[] = "focus,out"; // deprecated. use "focused" instead.
220 static const char SIG_FOCUS_IN[] = "focus,in"; // deprecated. use "unfocused" instead.
221 static const char SIG_MOVED[] = "moved";
222 static const char SIG_WITHDRAWN[] = "withdrawn";
223 static const char SIG_ICONIFIED[] = "iconified";
224 static const char SIG_NORMAL[] = "normal";
225 static const char SIG_STICK[] = "stick";
226 static const char SIG_UNSTICK[] = "unstick";
227 static const char SIG_FULLSCREEN[] = "fullscreen";
228 static const char SIG_UNFULLSCREEN[] = "unfullscreen";
229 static const char SIG_MAXIMIZED[] = "maximized";
230 static const char SIG_UNMAXIMIZED[] = "unmaximized";
231 static const char SIG_IOERR[] = "ioerr";
232 static const char SIG_INDICATOR_PROP_CHANGED[] = "indicator,prop,changed";
233 static const char SIG_ROTATION_CHANGED[] = "rotation,changed";
234 static const char SIG_PROFILE_CHANGED[] = "profile,changed";
235 static const char SIG_FOCUSED[] = "focused";
236 static const char SIG_UNFOCUSED[] = "unfocused";
237 static const char SIG_WM_ROTATION_CHANGED[] = "wm,rotation,changed";
238
239 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
240    {SIG_DELETE_REQUEST, ""},
241    {SIG_FOCUS_OUT, ""},
242    {SIG_FOCUS_IN, ""},
243    {SIG_MOVED, ""},
244    {SIG_WITHDRAWN, ""},
245    {SIG_ICONIFIED, ""},
246    {SIG_NORMAL, ""},
247    {SIG_STICK, ""},
248    {SIG_UNSTICK, ""},
249    {SIG_FULLSCREEN, ""},
250    {SIG_UNFULLSCREEN, ""},
251    {SIG_MAXIMIZED, ""},
252    {SIG_UNMAXIMIZED, ""},
253    {SIG_IOERR, ""},
254    {SIG_INDICATOR_PROP_CHANGED, ""},
255    {SIG_ROTATION_CHANGED, ""},
256    {SIG_PROFILE_CHANGED, ""},
257    {SIG_FOCUSED, ""},
258    {SIG_UNFOCUSED, ""},
259    {SIG_WM_ROTATION_CHANGED, ""},
260    {NULL, NULL}
261 };
262
263 static Eina_Bool _key_action_return(Evas_Object *obj, const char *params);
264 static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
265
266 static const Elm_Action key_actions[] = {
267    {"return", _key_action_return},
268    {"move", _key_action_move},
269    {NULL, NULL}
270 };
271
272 Eina_List *_elm_win_list = NULL;
273 int _elm_win_deferred_free = 0;
274
275 static int _elm_win_count = 0;
276
277 static Eina_Bool _elm_win_auto_throttled = EINA_FALSE;
278
279 static Ecore_Job *_elm_win_state_eval_job = NULL;
280
281 static void
282 _elm_win_on_resize_obj_changed_size_hints(void *data,
283                                           Evas *e,
284                                           Evas_Object *obj,
285                                           void *event_info);
286 static void
287 _elm_win_img_callbacks_del(Evas_Object *obj, Evas_Object *imgobj);
288
289 #ifdef HAVE_ELEMENTARY_X
290 static void _elm_win_xwin_update(Elm_Win_Data *sd);
291 #endif
292
293 EAPI double _elm_startup_time = 0;
294
295 static void
296 _elm_win_first_frame_do(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
297 {
298    double end = ecore_time_unix_get();
299    char *first = data;
300
301    switch (*first)
302      {
303       case 'A': abort();
304       case 'E':
305       case 'D': exit(-1);
306       case 'T': fprintf(stderr, "Startup time: '%f' - '%f' = '%f' sec\n", end, _elm_startup_time, end - _elm_startup_time);
307                 break;
308      }
309
310    evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_POST, _elm_win_first_frame_do, data);
311 }
312
313 static void
314 _elm_win_state_eval(void *data EINA_UNUSED)
315 {
316    Eina_List *l;
317    Evas_Object *obj;
318    int _elm_win_count_shown = 0;
319    int _elm_win_count_iconified = 0;
320    int _elm_win_count_withdrawn = 0;
321
322    _elm_win_state_eval_job = NULL;
323
324    if (_elm_config->auto_norender_withdrawn)
325      {
326         EINA_LIST_FOREACH(_elm_win_list, l, obj)
327           {
328              if ((elm_win_withdrawn_get(obj)) ||
329                  ((elm_win_iconified_get(obj) &&
330                    (_elm_config->auto_norender_iconified_same_as_withdrawn))))
331                {
332                   if (!evas_object_data_get(obj, "__win_auto_norender"))
333                     {
334                        Evas *evas = evas_object_evas_get(obj);
335
336                        elm_win_norender_push(obj);
337                        evas_object_data_set(obj, "__win_auto_norender", obj);
338
339                        if (_elm_config->auto_flush_withdrawn)
340                          {
341                             edje_file_cache_flush();
342                             edje_collection_cache_flush();
343                             evas_image_cache_flush(evas);
344                             evas_font_cache_flush(evas);
345                          }
346                        if (_elm_config->auto_dump_withdrawn)
347                          {
348                             evas_render_dump(evas);
349                          }
350                     }
351                }
352              else
353                {
354                   if (evas_object_data_get(obj, "__win_auto_norender"))
355                     {
356                        elm_win_norender_pop(obj);
357                        evas_object_data_del(obj, "__win_auto_norender");
358                     }
359                }
360           }
361      }
362    if (((_elm_config->auto_throttle) &&
363         (elm_policy_get(ELM_POLICY_THROTTLE) != ELM_POLICY_THROTTLE_NEVER)) ||
364         (elm_policy_get(ELM_POLICY_THROTTLE) == ELM_POLICY_THROTTLE_HIDDEN_ALWAYS))
365      {
366         if (_elm_win_count == 0)
367           {
368              if (_elm_win_auto_throttled)
369                {
370                   ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
371                   _elm_win_auto_throttled = EINA_FALSE;
372                }
373           }
374         else
375           {
376              EINA_LIST_FOREACH(_elm_win_list, l, obj)
377                {
378                   if (elm_win_withdrawn_get(obj))
379                     _elm_win_count_withdrawn++;
380                   else if (elm_win_iconified_get(obj))
381                     _elm_win_count_iconified++;
382                   else if (evas_object_visible_get(obj))
383                     _elm_win_count_shown++;
384                }
385              if (_elm_win_count_shown <= 0)
386                {
387                   if (!_elm_win_auto_throttled)
388                     {
389                        ecore_throttle_adjust(_elm_config->auto_throttle_amount);
390                        _elm_win_auto_throttled = EINA_TRUE;
391                     }
392                }
393              else
394                {
395                   if (_elm_win_auto_throttled)
396                     {
397                        ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
398                        _elm_win_auto_throttled = EINA_FALSE;
399                     }
400                }
401           }
402      }
403 }
404
405 static void
406 _elm_win_state_eval_queue(void)
407 {
408    ecore_job_del(_elm_win_state_eval_job);
409    _elm_win_state_eval_job = ecore_job_add(_elm_win_state_eval, NULL);
410 }
411
412 // example shot spec (wait 0.1 sec then save as my-window.png):
413 // ELM_ENGINE="shot:delay=0.1:file=my-window.png"
414
415 static double
416 _shot_delay_get(Elm_Win_Data *sd)
417 {
418    char *p, *pd;
419    char *d = strdup(sd->shot.info);
420
421    if (!d) return 0.5;
422    for (p = (char *)sd->shot.info; *p; p++)
423      {
424         if (!strncmp(p, "delay=", 6))
425           {
426              double v;
427
428              for (pd = d, p += 6; (*p) && (*p != ':'); p++, pd++)
429                {
430                   *pd = *p;
431                }
432              *pd = 0;
433              v = _elm_atof(d);
434              free(d);
435              return v;
436           }
437      }
438    free(d);
439
440    return 0.5;
441 }
442
443 static char *
444 _shot_file_get(Elm_Win_Data *sd)
445 {
446    char *p;
447    char *tmp = strdup(sd->shot.info);
448    char *repname = NULL;
449
450    if (!tmp) return NULL;
451
452    for (p = (char *)sd->shot.info; *p; p++)
453      {
454         if (!strncmp(p, "file=", 5))
455           {
456              strcpy(tmp, p + 5);
457              if (!sd->shot.repeat_count) return tmp;
458              else
459                {
460                   char *dotptr = strrchr(tmp, '.');
461                   if (dotptr)
462                     {
463                        size_t size = sizeof(char) * (strlen(tmp) + 16);
464                        repname = malloc(size);
465                        strncpy(repname, tmp, dotptr - tmp);
466                        snprintf(repname + (dotptr - tmp), size -
467                                 (dotptr - tmp), "%03i",
468                                 sd->shot.shot_counter + 1);
469                        strcat(repname, dotptr);
470                        free(tmp);
471                        return repname;
472                     }
473                }
474           }
475      }
476    free(tmp);
477    if (!sd->shot.repeat_count) return strdup("out.png");
478
479    repname = malloc(sizeof(char) * 24);
480    snprintf(repname, sizeof(char) * 24, "out%03i.png",
481             sd->shot.shot_counter + 1);
482
483    return repname;
484 }
485
486 static int
487 _shot_repeat_count_get(Elm_Win_Data *sd)
488 {
489    char *p, *pd;
490    char *d = strdup(sd->shot.info);
491
492    if (!d) return 0;
493    for (p = (char *)sd->shot.info; *p; p++)
494      {
495         if (!strncmp(p, "repeat=", 7))
496           {
497              int v;
498
499              for (pd = d, p += 7; (*p) && (*p != ':'); p++, pd++)
500                {
501                   *pd = *p;
502                }
503              *pd = 0;
504              v = atoi(d);
505              if (v < 0) v = 0;
506              if (v > 1000) v = 999;
507              free(d);
508              return v;
509           }
510      }
511    free(d);
512
513    return 0;
514 }
515
516 static char *
517 _shot_key_get(Elm_Win_Data *sd EINA_UNUSED)
518 {
519    return NULL;
520 }
521
522 static char *
523 _shot_flags_get(Elm_Win_Data *sd EINA_UNUSED)
524 {
525    return NULL;
526 }
527
528 static void
529 _shot_do(Elm_Win_Data *sd)
530 {
531    Ecore_Evas *ee;
532    Evas_Object *o;
533    unsigned int *pixels;
534    int w, h;
535    char *file, *key, *flags;
536
537    ecore_evas_manual_render(sd->ee);
538    pixels = (void *)ecore_evas_buffer_pixels_get(sd->ee);
539    if (!pixels) return;
540
541    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
542    if ((w < 1) || (h < 1)) return;
543
544    file = _shot_file_get(sd);
545    if (!file) return;
546
547    key = _shot_key_get(sd);
548    flags = _shot_flags_get(sd);
549    ee = ecore_evas_buffer_new(1, 1);
550    o = evas_object_image_add(ecore_evas_get(ee));
551    evas_object_image_alpha_set(o, ecore_evas_alpha_get(sd->ee));
552    evas_object_image_size_set(o, w, h);
553    evas_object_image_data_set(o, pixels);
554    if (!evas_object_image_save(o, file, key, flags))
555      {
556         ERR("Cannot save window to '%s' (key '%s', flags '%s')",
557             file, key, flags);
558      }
559    free(file);
560    free(key);
561    free(flags);
562    ecore_evas_free(ee);
563    if (sd->shot.repeat_count) sd->shot.shot_counter++;
564 }
565
566 static Eina_Bool
567 _shot_delay(void *data)
568 {
569    ELM_WIN_DATA_GET(data, sd);
570
571    _shot_do(sd);
572    if (sd->shot.repeat_count)
573      {
574         int remainshot = (sd->shot.repeat_count - sd->shot.shot_counter);
575         if (remainshot > 0) return EINA_TRUE;
576      }
577    sd->shot.timer = NULL;
578    elm_exit();
579
580    return EINA_FALSE;
581 }
582
583 static void
584 _shot_init(Elm_Win_Data *sd)
585 {
586    if (!sd->shot.info) return;
587
588    sd->shot.repeat_count = _shot_repeat_count_get(sd);
589    sd->shot.shot_counter = 0;
590 }
591
592 static void
593 _shot_handle(Elm_Win_Data *sd)
594 {
595    if (!sd->shot.info) return;
596
597    if (!sd->shot.timer)
598      sd->shot.timer = ecore_timer_add(_shot_delay_get(sd), _shot_delay,
599                                       sd->obj);
600 }
601
602 /* elm-win specific associate, does the trap while ecore_evas_object_associate()
603  * does not.
604  */
605 static Elm_Win_Data *
606 _elm_win_associate_get(const Ecore_Evas *ee)
607 {
608    Evas_Object *obj = ecore_evas_data_get(ee, "elm_win");
609    if (!obj) return NULL;
610    ELM_WIN_DATA_GET(obj, sd);
611    return sd;
612 }
613
614 /* Interceptors Callbacks */
615 static void
616 _elm_win_obj_intercept_raise(void *data, Evas_Object *obj EINA_UNUSED)
617 {
618    ELM_WIN_DATA_GET(data, sd);
619    TRAP(sd, raise);
620 }
621
622 static void
623 _elm_win_obj_intercept_lower(void *data, Evas_Object *obj EINA_UNUSED)
624 {
625    ELM_WIN_DATA_GET(data, sd);
626    TRAP(sd, lower);
627 }
628
629 static void
630 _elm_win_obj_intercept_stack_above(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *above EINA_UNUSED)
631 {
632    INF("TODO: %s", __FUNCTION__);
633 }
634
635 static void
636 _elm_win_obj_intercept_stack_below(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *below EINA_UNUSED)
637 {
638    INF("TODO: %s", __FUNCTION__);
639 }
640
641 static void
642 _elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj EINA_UNUSED, int l)
643 {
644    ELM_WIN_DATA_GET(data, sd);
645    TRAP(sd, layer_set, l);
646 }
647
648 /* Event Callbacks */
649
650 static void
651 _elm_win_obj_callback_changed_size_hints(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
652 {
653    ELM_WIN_DATA_GET(data, sd);
654    Evas_Coord w, h;
655
656    evas_object_size_hint_min_get(obj, &w, &h);
657    TRAP(sd, size_min_set, w, h);
658
659    evas_object_size_hint_max_get(obj, &w, &h);
660    if (w < 1) w = -1;
661    if (h < 1) h = -1;
662    TRAP(sd, size_max_set, w, h);
663 }
664 /* end of elm-win specific associate */
665
666 static void
667 _elm_win_move(Ecore_Evas *ee)
668 {
669    Elm_Win_Data *sd = _elm_win_associate_get(ee);
670    int x, y;
671
672    if (!sd) return;
673
674    ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
675    sd->screen.x = x;
676    sd->screen.y = y;
677    evas_object_smart_callback_call(sd->obj, SIG_MOVED, NULL);
678    evas_nochange_push(evas_object_evas_get(sd->obj));
679    evas_object_move(sd->obj, x, y);
680    evas_nochange_pop(evas_object_evas_get(sd->obj));
681 }
682
683 static void
684 _elm_win_resize_job(void *data)
685 {
686    ELM_WIN_DATA_GET(data, sd);
687    int w, h;
688
689    sd->deferred_resize_job = NULL;
690    ecore_evas_request_geometry_get(sd->ee, NULL, NULL, &w, &h);
691    if (sd->constrain)
692      {
693         int sw, sh;
694         ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
695         w = MIN(w, sw);
696         h = MIN(h, sh);
697      }
698
699    if (sd->frame_obj)
700      {
701         int fx, fy, fw, fh;
702
703         evas_output_framespace_get(sd->evas, &fx, &fy, &fw, &fh);
704         evas_object_move(sd->frame_obj, -fx, -fy);
705         evas_object_resize(sd->frame_obj, w + fw, h + fh);
706      }
707
708    evas_object_resize(sd->obj, w, h);
709    evas_object_resize(sd->layout, w, h);
710 }
711
712 static void
713 _elm_win_resize(Ecore_Evas *ee)
714 {
715    Elm_Win_Data *sd = _elm_win_associate_get(ee);
716    if (!sd) return;
717
718    ecore_job_del(sd->deferred_resize_job);
719    sd->deferred_resize_job = ecore_job_add(_elm_win_resize_job, sd->obj);
720 }
721
722 static void
723 _elm_win_mouse_in(Ecore_Evas *ee)
724 {
725    Elm_Win_Data *sd = _elm_win_associate_get(ee);
726    if (!sd) return;
727
728    if (sd->resizing) sd->resizing = EINA_FALSE;
729 }
730
731 static void
732 _elm_win_focus_highlight_reconfigure_job_stop(Elm_Win_Data *sd)
733 {
734    ELM_SAFE_FREE(sd->focus_highlight.reconf_job, ecore_job_del);
735 }
736
737 static void
738 _elm_win_focus_highlight_visible_set(Elm_Win_Data *sd,
739                                      Eina_Bool visible)
740 {
741    Evas_Object *fobj = sd->focus_highlight.fobj;
742    if (!fobj) return;
743
744    if (visible)
745      {
746         evas_object_show(fobj);
747         edje_object_signal_emit(fobj, "elm,action,focus,show", "elm");
748      }
749    else
750      {
751         edje_object_signal_emit(fobj, "elm,action,focus,hide", "elm");
752      }
753 }
754
755 static void
756 _elm_win_focus_highlight_anim_setup(Elm_Win_Data *sd,
757                                     Evas_Object *obj)
758 {
759    Evas_Coord tx, ty, tw, th;
760    Evas_Coord px, py, pw, ph;
761    Edje_Message_Int_Set *m;
762    Evas_Object *target = sd->focus_highlight.cur.target;
763
764    evas_object_geometry_get(obj, &px, &py, &pw, &ph);
765    elm_widget_focus_highlight_geometry_get(target, &tx, &ty, &tw, &th, EINA_TRUE);
766    evas_object_move(obj, tx, ty);
767    evas_object_resize(obj, tw, th);
768
769    if ((px == tx) && (py == ty) && (pw == tw) && (ph == th)) return;
770
771    if (!_elm_config->focus_highlight_clip_disable)
772      evas_object_clip_unset(obj);
773
774    m = alloca(sizeof(*m) + (sizeof(int) * 8));
775    m->count = 8;
776    m->val[0] = px - tx;
777    m->val[1] = py - ty;
778    m->val[2] = pw;
779    m->val[3] = ph;
780    m->val[4] = 0;
781    m->val[5] = 0;
782    m->val[6] = tw;
783    m->val[7] = th;
784    edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 1, m);
785 }
786
787 static void
788 _elm_win_focus_highlight_simple_setup(Elm_Win_Data *sd,
789                                       Evas_Object *obj)
790 {
791    Evas_Object *clip, *target = sd->focus_highlight.cur.target;
792    Evas_Coord x, y, w, h;
793
794    elm_widget_focus_highlight_geometry_get(target, &x, &y, &w, &h, EINA_TRUE);
795
796    evas_object_move(obj, x, y);
797    evas_object_resize(obj, w, h);
798
799    if (!_elm_config->focus_highlight_clip_disable)
800      {
801         clip = evas_object_clip_get(target);
802         if (clip) evas_object_clip_set(obj, clip);
803      }
804
805    edje_object_signal_emit(obj, "elm,state,anim,stop", "elm");
806 }
807
808 static void
809 _elm_win_focus_highlight_reconfigure_job(void *data)
810 {
811    ELM_WIN_DATA_GET(data, sd);
812    Evas_Object *target = sd->focus_highlight.cur.target;
813    Evas_Object *previous = sd->focus_highlight.prev.target;
814    Evas_Object *fobj = sd->focus_highlight.fobj;
815    Eina_Bool visible_changed;
816    Eina_Bool common_visible;
817    const char *sig = NULL;
818    const char *focus_style_target = NULL;
819    const char *focus_style_previous = NULL;
820
821    _elm_win_focus_highlight_reconfigure_job_stop(sd);
822
823    visible_changed = (sd->focus_highlight.cur.visible !=
824                       sd->focus_highlight.prev.visible);
825
826    if ((target == previous) && (!visible_changed) &&
827        (!sd->focus_highlight.geometry_changed) &&
828        (!sd->focus_highlight.theme_changed))
829      return;
830
831    if ((previous) && (sd->focus_highlight.prev.in_theme))
832      elm_widget_signal_emit
833        (previous, "elm,action,focus_highlight,hide", "elm");
834
835    if (!target)
836      common_visible = EINA_FALSE;
837    else if (sd->focus_highlight.cur.in_theme)
838      {
839         common_visible = EINA_FALSE;
840         if (sd->focus_highlight.cur.visible)
841           sig = "elm,action,focus_highlight,show";
842         else
843           sig = "elm,action,focus_highlight,hide";
844      }
845    else
846      common_visible = sd->focus_highlight.cur.visible;
847
848    if (sig)
849      elm_widget_signal_emit(target, sig, "elm");
850
851    if ((!target) || (!common_visible) || (sd->focus_highlight.cur.in_theme))
852      goto the_end;
853
854    if (previous)
855      focus_style_previous = elm_widget_focus_highlight_style_get(previous);
856    focus_style_target = elm_widget_focus_highlight_style_get(target);
857
858    if (sd->focus_highlight.theme_changed ||
859        (focus_style_target != focus_style_previous))
860      {
861         const char *str;
862
863         if (focus_style_target)
864           str = focus_style_target;
865         else if (sd->focus_highlight.style)
866           str = sd->focus_highlight.style;
867         else
868           str = "default";
869
870         elm_widget_theme_object_set
871           (sd->obj, fobj, "focus_highlight", "top", str);
872         sd->focus_highlight.theme_changed = EINA_FALSE;
873
874         if (sd->focus_highlight.animate)
875           {
876              str = edje_object_data_get(sd->focus_highlight.fobj, "animate");
877              sd->focus_highlight.animate_supported = ((str) && (!strcmp(str, "on")));
878           }
879         else
880           sd->focus_highlight.animate_supported = EINA_FALSE;
881      }
882
883    if ((sd->focus_highlight.animate_supported) && (previous) &&
884        (!sd->focus_highlight.prev.in_theme))
885      _elm_win_focus_highlight_anim_setup(sd, fobj);
886    else
887      _elm_win_focus_highlight_simple_setup(sd, fobj);
888    evas_object_raise(fobj);
889
890 the_end:
891    _elm_win_focus_highlight_visible_set(sd, common_visible);
892    sd->focus_highlight.geometry_changed = EINA_FALSE;
893    sd->focus_highlight.prev = sd->focus_highlight.cur;
894 }
895
896 static void
897 _elm_win_focus_highlight_reconfigure_job_start(Elm_Win_Data *sd)
898 {
899    ecore_job_del(sd->focus_highlight.reconf_job);
900
901    sd->focus_highlight.reconf_job = ecore_job_add(
902        _elm_win_focus_highlight_reconfigure_job, sd->obj);
903 }
904
905 static void
906 _elm_win_focus_in(Ecore_Evas *ee)
907 {
908    Elm_Win_Data *sd = _elm_win_associate_get(ee);
909    Evas_Object *obj;
910    unsigned int order = 0;
911
912    if ((!sd) || (sd->modal_count)) return;
913
914    obj = sd->obj;
915
916    _elm_widget_top_win_focused_set(obj, EINA_TRUE);
917    if (!elm_widget_focus_order_get(obj)
918        || (obj == elm_widget_newest_focus_order_get(obj, &order, EINA_TRUE)))
919      {
920         elm_widget_focus_steal(obj);
921      }
922    else
923      elm_widget_focus_restore(obj);
924    evas_object_smart_callback_call(obj, SIG_FOCUS_IN, NULL);
925    evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
926    sd->focus_highlight.cur.visible = EINA_TRUE;
927    _elm_win_focus_highlight_reconfigure_job_start(sd);
928    if (sd->frame_obj)
929      {
930         edje_object_signal_emit(sd->frame_obj, "elm,action,focus", "elm");
931      }
932
933    /* do nothing */
934    /* else if (sd->img_obj) */
935    /*   { */
936    /*   } */
937 }
938
939 static void
940 _elm_win_focus_out(Ecore_Evas *ee)
941 {
942    Elm_Win_Data *sd = _elm_win_associate_get(ee);
943    Evas_Object *obj;
944
945    if (!sd) return;
946
947    obj = sd->obj;
948
949    elm_object_focus_set(obj, EINA_FALSE);
950    _elm_widget_top_win_focused_set(obj, EINA_FALSE);
951    evas_object_smart_callback_call(obj, SIG_FOCUS_OUT, NULL);
952    evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
953    sd->focus_highlight.cur.visible = EINA_FALSE;
954    _elm_win_focus_highlight_reconfigure_job_start(sd);
955    if (sd->frame_obj)
956      {
957         edje_object_signal_emit(sd->frame_obj, "elm,action,unfocus", "elm");
958      }
959
960    /* access */
961    _elm_access_object_highlight_disable(evas_object_evas_get(obj));
962
963    /* do nothing */
964    /* if (sd->img_obj) */
965    /*   { */
966    /*   } */
967 }
968
969 static void
970 _elm_win_available_profiles_del(Elm_Win_Data *sd)
971 {
972    if (!sd->profile.available_list) return;
973
974    unsigned int i;
975    for (i = 0; i < sd->profile.count; i++)
976      ELM_SAFE_FREE(sd->profile.available_list[i], eina_stringshare_del);
977    sd->profile.count = 0;
978    ELM_SAFE_FREE(sd->profile.available_list, free);
979 }
980
981 static void
982 _elm_win_profile_del(Elm_Win_Data *sd)
983 {
984    ELM_SAFE_FREE(sd->profile.name, eina_stringshare_del);
985 }
986
987 static Eina_Bool
988 _internal_elm_win_profile_set(Elm_Win_Data *sd, const char *profile)
989 {
990    Eina_Bool changed = EINA_FALSE;
991    if (profile)
992      {
993         if (sd->profile.name)
994           {
995              if (strcmp(sd->profile.name, profile) != 0)
996                {
997                   eina_stringshare_replace(&(sd->profile.name), profile);
998                   changed = EINA_TRUE;
999                }
1000           }
1001         else
1002           {
1003              sd->profile.name = eina_stringshare_add(profile);
1004              changed = EINA_TRUE;
1005           }
1006      }
1007    else
1008      _elm_win_profile_del(sd);
1009
1010    return changed;
1011 }
1012
1013 static void
1014 _elm_win_profile_update(Elm_Win_Data *sd)
1015 {
1016    if (sd->profile.available_list)
1017      {
1018         Eina_Bool found = EINA_FALSE;
1019         if (sd->profile.name)
1020           {
1021              unsigned int i;
1022              for (i = 0; i < sd->profile.count; i++)
1023                {
1024                   if (!strcmp(sd->profile.name,
1025                               sd->profile.available_list[i]))
1026                     {
1027                        found = EINA_TRUE;
1028                        break;
1029                     }
1030                }
1031           }
1032
1033         /* If current profile is not present in an available profiles,
1034          * change current profile to the 1st element of an array.
1035          */
1036         if (!found)
1037           _internal_elm_win_profile_set(sd, sd->profile.available_list[0]);
1038      }
1039
1040    _elm_config_profile_set(sd->profile.name);
1041
1042    /* update sub ee */
1043    Ecore_Evas *ee2;
1044    Eina_List *sub, *l = NULL;
1045
1046    sub = ecore_evas_sub_ecore_evas_list_get(sd->ee);
1047    EINA_LIST_FOREACH(sub, l, ee2)
1048      ecore_evas_window_profile_set(ee2, sd->profile.name);
1049
1050    evas_object_smart_callback_call(sd->obj, SIG_PROFILE_CHANGED, NULL);
1051 }
1052
1053 static void
1054 _elm_win_state_change(Ecore_Evas *ee)
1055 {
1056    Elm_Win_Data *sd = _elm_win_associate_get(ee);
1057    Evas_Object *obj;
1058    Eina_Bool ch_withdrawn = EINA_FALSE;
1059    Eina_Bool ch_sticky = EINA_FALSE;
1060    Eina_Bool ch_iconified = EINA_FALSE;
1061    Eina_Bool ch_fullscreen = EINA_FALSE;
1062    Eina_Bool ch_maximized = EINA_FALSE;
1063    Eina_Bool ch_profile = EINA_FALSE;
1064    Eina_Bool ch_wm_rotation = EINA_FALSE;
1065    const char *profile;
1066
1067    if (!sd) return;
1068
1069    obj = sd->obj;
1070
1071    if (sd->withdrawn != ecore_evas_withdrawn_get(sd->ee))
1072      {
1073         sd->withdrawn = ecore_evas_withdrawn_get(sd->ee);
1074         ch_withdrawn = EINA_TRUE;
1075      }
1076    if (sd->sticky != ecore_evas_sticky_get(sd->ee))
1077      {
1078         sd->sticky = ecore_evas_sticky_get(sd->ee);
1079         ch_sticky = EINA_TRUE;
1080      }
1081    if (sd->iconified != ecore_evas_iconified_get(sd->ee))
1082      {
1083         sd->iconified = ecore_evas_iconified_get(sd->ee);
1084         ch_iconified = EINA_TRUE;
1085      }
1086    if (sd->fullscreen != ecore_evas_fullscreen_get(sd->ee))
1087      {
1088         sd->fullscreen = ecore_evas_fullscreen_get(sd->ee);
1089         ch_fullscreen = EINA_TRUE;
1090      }
1091    if (sd->maximized != ecore_evas_maximized_get(sd->ee))
1092      {
1093         sd->maximized = ecore_evas_maximized_get(sd->ee);
1094         ch_maximized = EINA_TRUE;
1095      }
1096
1097    profile = ecore_evas_window_profile_get(sd->ee);
1098    ch_profile = _internal_elm_win_profile_set(sd, profile);
1099
1100    if (sd->wm_rot.use)
1101      {
1102         if (sd->rot != ecore_evas_rotation_get(sd->ee))
1103           {
1104              sd->rot = ecore_evas_rotation_get(sd->ee);
1105              ch_wm_rotation = EINA_TRUE;
1106           }
1107      }
1108
1109    _elm_win_state_eval_queue();
1110
1111    if ((ch_withdrawn) || (ch_iconified))
1112      {
1113         if (sd->withdrawn)
1114           evas_object_smart_callback_call(obj, SIG_WITHDRAWN, NULL);
1115         else if (sd->iconified)
1116           evas_object_smart_callback_call(obj, SIG_ICONIFIED, NULL);
1117         else
1118           evas_object_smart_callback_call(obj, SIG_NORMAL, NULL);
1119      }
1120    if (ch_sticky)
1121      {
1122         if (sd->sticky)
1123           evas_object_smart_callback_call(obj, SIG_STICK, NULL);
1124         else
1125           evas_object_smart_callback_call(obj, SIG_UNSTICK, NULL);
1126      }
1127    if (ch_fullscreen)
1128      {
1129         if (sd->fullscreen)
1130           evas_object_smart_callback_call(obj, SIG_FULLSCREEN, NULL);
1131         else
1132           evas_object_smart_callback_call(obj, SIG_UNFULLSCREEN, NULL);
1133      }
1134    if (ch_maximized)
1135      {
1136         if (sd->maximized)
1137           evas_object_smart_callback_call(obj, SIG_MAXIMIZED, NULL);
1138         else
1139           evas_object_smart_callback_call(obj, SIG_UNMAXIMIZED, NULL);
1140      }
1141    if (ch_profile)
1142      {
1143         _elm_win_profile_update(sd);
1144      }
1145    if (ch_wm_rotation)
1146      {
1147         evas_object_size_hint_min_set(obj, -1, -1);
1148         evas_object_size_hint_max_set(obj, -1, -1);
1149 #ifdef HAVE_ELEMENTARY_X
1150         _elm_win_xwin_update(sd);
1151 #endif
1152         elm_widget_orientation_set(obj, sd->rot);
1153         evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
1154         evas_object_smart_callback_call(obj, SIG_WM_ROTATION_CHANGED, NULL);
1155      }
1156 }
1157
1158 EOLIAN static Eina_Bool
1159 _elm_win_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Win_Data *_pd EINA_UNUSED)
1160 {
1161    return EINA_TRUE;
1162 }
1163
1164 EOLIAN static Eina_Bool
1165 _elm_win_elm_widget_focus_next(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, Elm_Focus_Direction dir, Evas_Object **next)
1166 {
1167    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
1168
1169    const Eina_List *items;
1170    void *(*list_data_get)(const Eina_List *list);
1171
1172    /* Focus chain */
1173    if (wd->subobjs)
1174      {
1175         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1176           {
1177              items = wd->subobjs;
1178              if (!items)
1179                return EINA_FALSE;
1180           }
1181         list_data_get = eina_list_data_get;
1182
1183         elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
1184
1185         if (*next) return EINA_TRUE;
1186      }
1187    *next = (Evas_Object *)obj;
1188    return EINA_FALSE;
1189 }
1190
1191 EOLIAN static Eina_Bool
1192 _elm_win_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Win_Data *_pd EINA_UNUSED)
1193 {
1194    return EINA_TRUE;
1195 }
1196
1197 EOLIAN static Eina_Bool
1198 _elm_win_elm_widget_focus_direction(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, const Evas_Object *base, double degree, Evas_Object **direction, double *weight)
1199 {
1200    const Eina_List *items;
1201    void *(*list_data_get)(const Eina_List *list);
1202
1203    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
1204
1205    /* Focus chain */
1206    if (wd->subobjs)
1207      {
1208         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1209           items = wd->subobjs;
1210
1211         list_data_get = eina_list_data_get;
1212
1213         return elm_widget_focus_list_direction_get
1214                  (obj, base, items, list_data_get, degree, direction, weight);
1215      }
1216
1217    return EINA_FALSE;
1218 }
1219
1220 EOLIAN static Eina_Bool
1221 _elm_win_elm_widget_on_focus(Eo *obj, Elm_Win_Data *sd)
1222 {
1223    Eina_Bool int_ret = EINA_FALSE;
1224    eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_on_focus());
1225    if (!int_ret) return EINA_TRUE;
1226
1227    if (sd->img_obj)
1228      evas_object_focus_set(sd->img_obj, elm_widget_focus_get(obj));
1229    else
1230      evas_object_focus_set(obj, elm_widget_focus_get(obj));
1231
1232    return EINA_TRUE;
1233 }
1234
1235 static Eina_Bool
1236 _key_action_return(Evas_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
1237 {
1238    return EINA_FALSE;
1239 }
1240
1241 static Eina_Bool
1242 _key_action_move(Evas_Object *obj, const char *params)
1243 {
1244    const char *dir = params;
1245
1246    if (!strcmp(dir, "previous"))
1247      elm_widget_focus_cycle(obj, ELM_FOCUS_PREVIOUS);
1248    else if (!strcmp(dir, "next"))
1249      elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1250    else if (!strcmp(dir, "left"))
1251      elm_widget_focus_cycle(obj, ELM_FOCUS_LEFT);
1252    else if (!strcmp(dir, "right"))
1253      elm_widget_focus_cycle(obj, ELM_FOCUS_RIGHT);
1254    else if (!strcmp(dir, "up"))
1255      elm_widget_focus_cycle(obj, ELM_FOCUS_UP);
1256    else if (!strcmp(dir, "down"))
1257      elm_widget_focus_cycle(obj, ELM_FOCUS_DOWN);
1258    else return EINA_FALSE;
1259
1260    return EINA_TRUE;
1261 }
1262
1263 EOLIAN static Eina_Bool
1264 _elm_win_elm_widget_event(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, Evas_Object *src, Evas_Callback_Type type, void *event_info)
1265 {
1266    (void) src;
1267    Evas_Event_Key_Down *ev = event_info;
1268
1269    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1270    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1271
1272    if (!_elm_config_key_binding_call(obj, ev, key_actions))
1273      return EINA_FALSE;
1274
1275    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1276    return EINA_TRUE;
1277 }
1278
1279 static void
1280 _deferred_ecore_evas_free(void *data)
1281 {
1282    ecore_evas_free(data);
1283    _elm_win_deferred_free--;
1284 }
1285
1286 EOLIAN static void
1287 _elm_win_evas_smart_show(Eo *obj, Elm_Win_Data *sd)
1288 {
1289    if (sd->modal_count) return;
1290    const Eina_List *l;
1291    Evas_Object *current;
1292
1293    if (!evas_object_visible_get(obj))
1294      _elm_win_state_eval_queue();
1295    eo_do_super(obj, MY_CLASS, evas_obj_smart_show());
1296
1297    if ((sd->modal) && (!evas_object_visible_get(obj)))
1298      {
1299         INCREMENT_MODALITY()
1300      }
1301
1302    TRAP(sd, show);
1303
1304    if (sd->shot.info) _shot_handle(sd);
1305 }
1306
1307 EOLIAN static void
1308 _elm_win_evas_smart_hide(Eo *obj, Elm_Win_Data *sd)
1309 {
1310    if (sd->modal_count) return;
1311    const Eina_List *l;
1312    Evas_Object *current;
1313
1314    if (evas_object_visible_get(obj))
1315      _elm_win_state_eval_queue();
1316    eo_do_super(obj, MY_CLASS, evas_obj_smart_hide());
1317
1318    if ((sd->modal) && (evas_object_visible_get(obj)))
1319      {
1320         DECREMENT_MODALITY()
1321      }
1322
1323    TRAP(sd, hide);
1324
1325    if (sd->frame_obj)
1326      {
1327         evas_object_hide(sd->frame_obj);
1328      }
1329    if (sd->img_obj)
1330      {
1331         evas_object_hide(sd->img_obj);
1332      }
1333    if (sd->pointer.obj)
1334      {
1335         evas_object_hide(sd->pointer.obj);
1336         ecore_evas_hide(sd->pointer.ee);
1337      }
1338 }
1339
1340 static void
1341 _elm_win_on_parent_del(void *data,
1342                        Evas *e EINA_UNUSED,
1343                        Evas_Object *obj,
1344                        void *event_info EINA_UNUSED)
1345 {
1346    ELM_WIN_DATA_GET(data, sd);
1347
1348    if (obj == sd->parent) sd->parent = NULL;
1349 }
1350
1351 static void
1352 _elm_win_focus_target_move(void *data,
1353                            Evas *e EINA_UNUSED,
1354                            Evas_Object *obj EINA_UNUSED,
1355                            void *event_info EINA_UNUSED)
1356 {
1357    ELM_WIN_DATA_GET(data, sd);
1358
1359    sd->focus_highlight.geometry_changed = EINA_TRUE;
1360    _elm_win_focus_highlight_reconfigure_job_start(sd);
1361 }
1362
1363 static void
1364 _elm_win_focus_target_resize(void *data,
1365                              Evas *e EINA_UNUSED,
1366                              Evas_Object *obj EINA_UNUSED,
1367                              void *event_info EINA_UNUSED)
1368 {
1369    ELM_WIN_DATA_GET(data, sd);
1370
1371    sd->focus_highlight.geometry_changed = EINA_TRUE;
1372    _elm_win_focus_highlight_reconfigure_job_start(sd);
1373 }
1374
1375 static void
1376 _elm_win_focus_target_del(void *data,
1377                           Evas *e EINA_UNUSED,
1378                           Evas_Object *obj EINA_UNUSED,
1379                           void *event_info EINA_UNUSED)
1380 {
1381    ELM_WIN_DATA_GET(data, sd);
1382
1383    sd->focus_highlight.cur.target = NULL;
1384
1385    _elm_win_focus_highlight_reconfigure_job_start(sd);
1386 }
1387
1388 static Evas_Object *
1389 _elm_win_focus_target_get(Evas_Object *obj)
1390 {
1391    Evas_Object *o = obj;
1392
1393    do
1394      {
1395         if (elm_widget_is(o))
1396           {
1397              if (!elm_widget_highlight_ignore_get(o))
1398                break;
1399              o = elm_widget_parent_get(o);
1400              if (!o)
1401                o = evas_object_smart_parent_get(o);
1402           }
1403         else
1404           {
1405              o = elm_widget_parent_widget_get(o);
1406              if (!o)
1407                o = evas_object_smart_parent_get(o);
1408           }
1409      }
1410    while (o);
1411
1412    return o;
1413 }
1414
1415 static void
1416 _elm_win_focus_target_callbacks_add(Elm_Win_Data *sd)
1417 {
1418    Evas_Object *obj = sd->focus_highlight.cur.target;
1419    if (!obj) return;
1420
1421    evas_object_event_callback_add
1422      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd->obj);
1423    evas_object_event_callback_add
1424      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd->obj);
1425    evas_object_event_callback_add
1426      (obj, EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
1427 }
1428
1429 static void
1430 _elm_win_focus_target_callbacks_del(Elm_Win_Data *sd)
1431 {
1432    Evas_Object *obj = sd->focus_highlight.cur.target;
1433
1434    evas_object_event_callback_del_full
1435      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd->obj);
1436    evas_object_event_callback_del_full
1437      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd->obj);
1438    evas_object_event_callback_del_full
1439      (obj, EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
1440 }
1441
1442 static void
1443 _elm_win_object_focus_in(void *data,
1444                          Evas *e EINA_UNUSED,
1445                          void *event_info)
1446 {
1447    Evas_Object *obj = event_info, *target;
1448    ELM_WIN_DATA_GET(data, sd);
1449
1450    if (sd->focus_highlight.cur.target == obj)
1451      return;
1452
1453    target = _elm_win_focus_target_get(obj);
1454    sd->focus_highlight.cur.target = target;
1455    if (target && elm_widget_highlight_in_theme_get(target))
1456      sd->focus_highlight.cur.in_theme = EINA_TRUE;
1457    else
1458      _elm_win_focus_target_callbacks_add(sd);
1459
1460    _elm_win_focus_highlight_reconfigure_job_start(sd);
1461 }
1462
1463 static void
1464 _elm_win_object_focus_out(void *data,
1465                           Evas *e EINA_UNUSED,
1466                           void *event_info EINA_UNUSED)
1467 {
1468    ELM_WIN_DATA_GET(data, sd);
1469
1470    if (!sd->focus_highlight.cur.target)
1471      return;
1472
1473    if (!sd->focus_highlight.cur.in_theme)
1474      _elm_win_focus_target_callbacks_del(sd);
1475
1476    sd->focus_highlight.cur.target = NULL;
1477    sd->focus_highlight.cur.in_theme = EINA_FALSE;
1478
1479    _elm_win_focus_highlight_reconfigure_job_start(sd);
1480 }
1481
1482 static void
1483 _elm_win_focus_highlight_shutdown(Elm_Win_Data *sd)
1484 {
1485    _elm_win_focus_highlight_reconfigure_job_stop(sd);
1486    if (sd->focus_highlight.cur.target)
1487      {
1488         elm_widget_signal_emit(sd->focus_highlight.cur.target,
1489                                "elm,action,focus_highlight,hide", "elm");
1490         _elm_win_focus_target_callbacks_del(sd);
1491         sd->focus_highlight.cur.target = NULL;
1492      }
1493    ELM_SAFE_FREE(sd->focus_highlight.fobj, evas_object_del);
1494
1495    evas_event_callback_del_full
1496      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
1497      _elm_win_object_focus_in, sd->obj);
1498    evas_event_callback_del_full
1499      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
1500      _elm_win_object_focus_out, sd->obj);
1501 }
1502
1503 static void
1504 _win_img_hide(void *data,
1505               Evas *e EINA_UNUSED,
1506               Evas_Object *obj EINA_UNUSED,
1507               void *event_info EINA_UNUSED)
1508 {
1509    elm_widget_focus_hide_handle(data);
1510 }
1511
1512 static void
1513 _win_img_mouse_up(void *data,
1514                   Evas *e EINA_UNUSED,
1515                   Evas_Object *obj EINA_UNUSED,
1516                   void *event_info)
1517 {
1518    Evas_Event_Mouse_Up *ev = event_info;
1519    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
1520      elm_widget_focus_mouse_up_handle(data);
1521 }
1522
1523 static void
1524 _win_img_focus_in(void *data,
1525                   Evas *e EINA_UNUSED,
1526                   Evas_Object *obj EINA_UNUSED,
1527                   void *event_info EINA_UNUSED)
1528 {
1529    elm_widget_focus_steal(data);
1530 }
1531
1532 static void
1533 _win_img_focus_out(void *data,
1534                    Evas *e EINA_UNUSED,
1535                    Evas_Object *obj EINA_UNUSED,
1536                    void *event_info EINA_UNUSED)
1537 {
1538    elm_widget_focused_object_clear(data);
1539 }
1540
1541 static void
1542 _elm_win_on_img_obj_del(void *data,
1543                         Evas *e EINA_UNUSED,
1544                         Evas_Object *obj EINA_UNUSED,
1545                         void *event_info EINA_UNUSED)
1546 {
1547    ELM_WIN_DATA_GET(data, sd);
1548    _elm_win_img_callbacks_del(sd->obj, sd->img_obj);
1549    sd->img_obj = NULL;
1550 }
1551
1552 static void
1553 _elm_win_img_callbacks_del(Evas_Object *obj, Evas_Object *imgobj)
1554 {
1555    evas_object_event_callback_del_full
1556      (imgobj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, obj);
1557    evas_object_event_callback_del_full
1558      (imgobj, EVAS_CALLBACK_HIDE, _win_img_hide, obj);
1559    evas_object_event_callback_del_full
1560      (imgobj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, obj);
1561    evas_object_event_callback_del_full
1562      (imgobj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, obj);
1563    evas_object_event_callback_del_full
1564      (imgobj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, obj);
1565 }
1566
1567 EOLIAN static void
1568 _elm_win_evas_smart_del(Eo *obj, Elm_Win_Data *sd)
1569 {
1570    const Eina_List *l;
1571    Evas_Object *current;
1572
1573    if ((sd->modal) && (evas_object_visible_get(obj)))
1574      {
1575        DECREMENT_MODALITY()
1576      }
1577
1578    if ((sd->modal) && (sd->modal_count > 0)) 
1579      ERR("Deleted modal win was blocked by another modal win which was created after creation of that win.");
1580
1581    evas_object_event_callback_del_full(sd->layout,
1582                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1583                                        _elm_win_on_resize_obj_changed_size_hints,
1584                                        obj);
1585    evas_object_del(sd->box);
1586    evas_object_del(sd->layout);
1587
1588    /* NB: child deletion handled by parent's smart del */
1589
1590    if ((trap) && (trap->del))
1591      trap->del(sd->trap_data, obj);
1592
1593    if (sd->parent)
1594      {
1595         evas_object_event_callback_del_full
1596           (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, obj);
1597         sd->parent = NULL;
1598      }
1599
1600    if (sd->autodel_clear) *(sd->autodel_clear) = -1;
1601
1602    _elm_win_list = eina_list_remove(_elm_win_list, obj);
1603    _elm_win_count--;
1604    _elm_win_state_eval_queue();
1605
1606    if (sd->ee)
1607      {
1608         ecore_evas_callback_delete_request_set(sd->ee, NULL);
1609         ecore_evas_callback_resize_set(sd->ee, NULL);
1610      }
1611
1612    ecore_job_del(sd->deferred_resize_job);
1613    ecore_job_del(sd->deferred_child_eval_job);
1614    eina_stringshare_del(sd->shot.info);
1615    ecore_timer_del(sd->shot.timer);
1616
1617 #ifdef HAVE_ELEMENTARY_X
1618    ecore_event_handler_del(sd->x.client_message_handler);
1619    ecore_event_handler_del(sd->x.property_handler);
1620 #endif
1621
1622    if (sd->img_obj)
1623      {
1624         _elm_win_img_callbacks_del(obj, sd->img_obj);
1625         sd->img_obj = NULL;
1626      }
1627    else
1628      {
1629         if (sd->ee)
1630           {
1631              ecore_job_add(_deferred_ecore_evas_free, sd->ee);
1632              _elm_win_deferred_free++;
1633           }
1634      }
1635
1636    _elm_win_focus_highlight_shutdown(sd);
1637    eina_stringshare_del(sd->focus_highlight.style);
1638
1639    eina_stringshare_del(sd->title);
1640    eina_stringshare_del(sd->icon_name);
1641    eina_stringshare_del(sd->role);
1642    evas_object_del(sd->icon);
1643    evas_object_del(sd->main_menu);
1644
1645    _elm_win_profile_del(sd);
1646    _elm_win_available_profiles_del(sd);
1647
1648    /* Don't let callback in the air that point to sd */
1649    ecore_evas_callback_delete_request_set(sd->ee, NULL);
1650    ecore_evas_callback_resize_set(sd->ee, NULL);
1651    ecore_evas_callback_mouse_in_set(sd->ee, NULL);
1652    ecore_evas_callback_focus_in_set(sd->ee, NULL);
1653    ecore_evas_callback_focus_out_set(sd->ee, NULL);
1654    ecore_evas_callback_move_set(sd->ee, NULL);
1655    ecore_evas_callback_state_change_set(sd->ee, NULL);
1656
1657    eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
1658
1659    if ((!_elm_win_list) &&
1660        (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
1661      {
1662         edje_file_cache_flush();
1663         edje_collection_cache_flush();
1664         evas_image_cache_flush(evas_object_evas_get(obj));
1665         evas_font_cache_flush(evas_object_evas_get(obj));
1666         elm_exit();
1667      }
1668 }
1669
1670 static void
1671 _elm_win_obj_intercept_show(void *data,
1672                             Evas_Object *obj)
1673 {
1674    ELM_WIN_DATA_GET(data, sd);
1675
1676    // this is called to make sure all smart containers have calculated their
1677    // sizes BEFORE we show the window to make sure it initially appears at
1678    // our desired size (ie min size is known first)
1679    evas_smart_objects_calculate(evas_object_evas_get(obj));
1680    if (sd->frame_obj)
1681      {
1682         evas_object_show(sd->frame_obj);
1683      }
1684    if (sd->img_obj)
1685      {
1686         evas_object_show(sd->img_obj);
1687      }
1688    if (sd->pointer.obj)
1689      {
1690         ecore_evas_show(sd->pointer.ee);
1691         evas_object_show(sd->pointer.obj);
1692      }
1693    evas_object_show(obj);
1694 }
1695
1696 EOLIAN static void
1697 _elm_win_evas_smart_move(Eo *obj, Elm_Win_Data *sd, Evas_Coord x, Evas_Coord y)
1698 {
1699    if (sd->img_obj)
1700      {
1701         if ((x != sd->screen.x) || (y != sd->screen.y))
1702           {
1703              sd->screen.x = x;
1704              sd->screen.y = y;
1705              evas_object_smart_callback_call(obj, SIG_MOVED, NULL);
1706           }
1707         return;
1708      }
1709    else
1710      {
1711         TRAP(sd, move, x, y);
1712         if (!ecore_evas_override_get(sd->ee))  return;
1713      }
1714
1715    eo_do_super(obj, MY_CLASS, evas_obj_smart_move(x, y));
1716
1717    if (ecore_evas_override_get(sd->ee))
1718      {
1719         sd->screen.x = x;
1720         sd->screen.y = y;
1721         evas_object_smart_callback_call(obj, SIG_MOVED, NULL);
1722      }
1723    if (sd->frame_obj)
1724      {
1725         /* FIXME: We should update ecore_wl_window_location here !! */
1726         sd->screen.x = x;
1727         sd->screen.y = y;
1728      }
1729    if (sd->img_obj)
1730      {
1731         sd->screen.x = x;
1732         sd->screen.y = y;
1733      }
1734 }
1735
1736 EOLIAN static void
1737 _elm_win_evas_smart_resize(Eo *obj, Elm_Win_Data *sd, Evas_Coord w, Evas_Coord h)
1738 {
1739    eo_do_super(obj, MY_CLASS, evas_obj_smart_resize(w, h));
1740
1741    if (sd->img_obj)
1742      {
1743         if (sd->constrain)
1744           {
1745              int sw, sh;
1746
1747              ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
1748              w = MIN(w, sw);
1749              h = MIN(h, sh);
1750           }
1751         if (w < 1) w = 1;
1752         if (h < 1) h = 1;
1753
1754         evas_object_image_size_set(sd->img_obj, w, h);
1755      }
1756
1757    TRAP(sd, resize, w, h);
1758 }
1759
1760 static void
1761 _elm_win_delete_request(Ecore_Evas *ee)
1762 {
1763    Elm_Win_Data *sd = _elm_win_associate_get(ee);
1764    Evas_Object *obj;
1765
1766    if (!sd) return;
1767
1768    obj = sd->obj;
1769
1770    int autodel = sd->autodel;
1771    sd->autodel_clear = &autodel;
1772    evas_object_ref(obj);
1773    evas_object_smart_callback_call(obj, SIG_DELETE_REQUEST, NULL);
1774    // FIXME: if above callback deletes - then the below will be invalid
1775    if (autodel) evas_object_del(obj);
1776    else sd->autodel_clear = NULL;
1777    evas_object_unref(obj);
1778 }
1779
1780 Ecore_X_Window
1781 _elm_ee_xwin_get(const Ecore_Evas *ee)
1782 {
1783 #ifdef HAVE_ELEMENTARY_X
1784    const char *engine_name;
1785    if (!ee) return 0;
1786
1787    engine_name = ecore_evas_engine_name_get(ee);
1788    if (EINA_UNLIKELY(!engine_name)) return 0;
1789
1790    if (!strcmp(engine_name, ELM_SOFTWARE_X11))
1791      {
1792         return ecore_evas_software_x11_window_get(ee);
1793      }
1794    else if (!strcmp(engine_name, ELM_OPENGL_X11))
1795      {
1796         return ecore_evas_gl_x11_window_get(ee);
1797      }
1798 #else
1799    (void)ee;
1800 #endif
1801    return 0;
1802 }
1803
1804 #ifdef HAVE_ELEMENTARY_X
1805 static void
1806 _internal_elm_win_xwindow_get(Elm_Win_Data *sd)
1807 {
1808    sd->x.xwin = _elm_ee_xwin_get(sd->ee);
1809 }
1810 #endif
1811
1812 Ecore_Wl_Window *
1813 _elm_ee_wlwin_get(const Ecore_Evas *ee)
1814 {
1815 #ifdef HAVE_ELEMENTARY_WAYLAND
1816    const char *engine_name;
1817
1818    if (!ee) return NULL;
1819
1820    engine_name = ecore_evas_engine_name_get(ee);
1821    if (EINA_UNLIKELY(!engine_name)) return NULL;
1822
1823    if ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
1824        (!strcmp(engine_name, ELM_WAYLAND_EGL)))
1825      {
1826         return ecore_evas_wayland_window_get(ee);
1827      }
1828 #else
1829    (void)ee;
1830 #endif
1831    return NULL;
1832 }
1833
1834 #ifdef HAVE_ELEMENTARY_WAYLAND
1835 static void
1836 _elm_win_wlwindow_get(Elm_Win_Data *sd)
1837 {
1838    sd->wl.win = _elm_ee_wlwin_get(sd->ee);
1839 }
1840 #endif
1841
1842 #ifdef HAVE_ELEMENTARY_X
1843 static void
1844 _elm_win_xwin_update(Elm_Win_Data *sd)
1845 {
1846    const char *s;
1847
1848    _internal_elm_win_xwindow_get(sd);
1849    if (sd->parent)
1850      {
1851         ELM_WIN_DATA_GET(sd->parent, sdp);
1852         if (sdp)
1853           {
1854              if (sd->x.xwin)
1855                ecore_x_icccm_transient_for_set(sd->x.xwin, sdp->x.xwin);
1856           }
1857      }
1858
1859    if (!sd->x.xwin) return;  /* nothing more to do */
1860
1861    s = sd->title;
1862    if (!s) s = _elm_appname;
1863    if (!s) s = "";
1864    if (sd->icon_name) s = sd->icon_name;
1865    ecore_x_icccm_icon_name_set(sd->x.xwin, s);
1866    ecore_x_netwm_icon_name_set(sd->x.xwin, s);
1867
1868    s = sd->role;
1869    if (s) ecore_x_icccm_window_role_set(sd->x.xwin, s);
1870
1871    // set window icon
1872    if (sd->icon)
1873      {
1874         void *data;
1875
1876         data = evas_object_image_data_get(sd->icon, EINA_FALSE);
1877         if (data)
1878           {
1879              Ecore_X_Icon ic;
1880              int w = 0, h = 0, stride, x, y;
1881              unsigned char *p;
1882              unsigned int *p2;
1883
1884              evas_object_image_size_get(sd->icon, &w, &h);
1885              stride = evas_object_image_stride_get(sd->icon);
1886              if ((w > 0) && (h > 0) &&
1887                  (stride >= (int)(w * sizeof(unsigned int))))
1888                {
1889                   ic.width = w;
1890                   ic.height = h;
1891                   ic.data = malloc(w * h * sizeof(unsigned int));
1892
1893                   if (ic.data)
1894                     {
1895                        p = (unsigned char *)data;
1896                        p2 = (unsigned int *)ic.data;
1897                        for (y = 0; y < h; y++)
1898                          {
1899                             for (x = 0; x < w; x++)
1900                               {
1901                                  *p2 = *((unsigned int *)p);
1902                                  p += sizeof(unsigned int);
1903                                  p2++;
1904                               }
1905                             p += (stride - (w * sizeof(unsigned int)));
1906                          }
1907                        ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
1908                        free(ic.data);
1909                     }
1910                }
1911              evas_object_image_data_set(sd->icon, data);
1912           }
1913      }
1914
1915    switch (sd->type)
1916      {
1917       case ELM_WIN_BASIC:
1918         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_NORMAL);
1919         break;
1920
1921       case ELM_WIN_DIALOG_BASIC:
1922         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DIALOG);
1923         break;
1924
1925       case ELM_WIN_DESKTOP:
1926         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DESKTOP);
1927         break;
1928
1929       case ELM_WIN_DOCK:
1930         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DOCK);
1931         break;
1932
1933       case ELM_WIN_TOOLBAR:
1934         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLBAR);
1935         break;
1936
1937       case ELM_WIN_MENU:
1938         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_MENU);
1939         break;
1940
1941       case ELM_WIN_UTILITY:
1942         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_UTILITY);
1943         break;
1944
1945       case ELM_WIN_SPLASH:
1946         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_SPLASH);
1947         break;
1948
1949       case ELM_WIN_DROPDOWN_MENU:
1950         ecore_x_netwm_window_type_set
1951           (sd->x.xwin, ECORE_X_WINDOW_TYPE_DROPDOWN_MENU);
1952         break;
1953
1954       case ELM_WIN_POPUP_MENU:
1955         ecore_x_netwm_window_type_set
1956           (sd->x.xwin, ECORE_X_WINDOW_TYPE_POPUP_MENU);
1957         break;
1958
1959       case ELM_WIN_TOOLTIP:
1960         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLTIP);
1961         break;
1962
1963       case ELM_WIN_NOTIFICATION:
1964         ecore_x_netwm_window_type_set
1965           (sd->x.xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
1966         break;
1967
1968       case ELM_WIN_COMBO:
1969         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_COMBO);
1970         break;
1971
1972       case ELM_WIN_DND:
1973         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DND);
1974         break;
1975
1976       default:
1977         break;
1978      }
1979    ecore_x_e_virtual_keyboard_state_set
1980      (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
1981    if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
1982      ecore_x_e_illume_indicator_state_set
1983        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
1984    else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
1985      ecore_x_e_illume_indicator_state_set
1986        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
1987 }
1988
1989 #endif
1990
1991 /**
1992   * @internal
1993   *
1994   * Resize the window according to window layout's min and weight.
1995   * If the window layout's weight is 0.0, the window max is limited to layout's
1996   * min size.
1997   *
1998   * This is called when the window layout's weight hint is changed or when the
1999   * window is rotated.
2000   *
2001   * @param obj window object
2002   */
2003 static void
2004 _elm_win_resize_objects_eval(Evas_Object *obj)
2005 {
2006    ELM_WIN_DATA_GET(obj, sd);
2007    Evas_Coord w, h, minw, minh, maxw, maxh;
2008    double wx, wy;
2009
2010    evas_object_size_hint_min_get(sd->layout, &minw, &minh);
2011    if (minw < 1) minw = 1;
2012    if (minh < 1) minh = 1;
2013
2014    evas_object_size_hint_weight_get(sd->layout, &wx, &wy);
2015    if (!wx) maxw = minw;
2016    else maxw = 32767;
2017    if (!wy) maxh = minh;
2018    else maxh = 32767;
2019
2020    evas_object_size_hint_min_set(obj, minw, minh);
2021    evas_object_size_hint_max_set(obj, maxw, maxh);
2022    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
2023    if (w < minw) w = minw;
2024    if (h < minh) h = minh;
2025    if (w > maxw) w = maxw;
2026    if (h > maxh) h = maxh;
2027    evas_object_resize(obj, w, h);
2028 }
2029
2030 static void
2031 _elm_win_on_resize_obj_changed_size_hints(void *data,
2032                                           Evas *e EINA_UNUSED,
2033                                           Evas_Object *obj EINA_UNUSED,
2034                                           void *event_info EINA_UNUSED)
2035 {
2036    _elm_win_resize_objects_eval(data);
2037 }
2038
2039 void
2040 _elm_win_shutdown(void)
2041 {
2042    while (_elm_win_list) evas_object_del(_elm_win_list->data);
2043    ELM_SAFE_FREE(_elm_win_state_eval_job, ecore_job_del);
2044 }
2045
2046 void
2047 _elm_win_rescale(Elm_Theme *th,
2048                  Eina_Bool use_theme)
2049 {
2050    const Eina_List *l;
2051    Evas_Object *obj;
2052
2053    if (!use_theme)
2054      {
2055         EINA_LIST_FOREACH(_elm_win_list, l, obj)
2056           elm_widget_theme(obj);
2057      }
2058    else
2059      {
2060         EINA_LIST_FOREACH(_elm_win_list, l, obj)
2061           elm_widget_theme_specific(obj, th, EINA_FALSE);
2062      }
2063 }
2064
2065 void
2066 _elm_win_access(Eina_Bool is_access)
2067 {
2068    Evas *evas;
2069    const Eina_List *l;
2070    Evas_Object *obj;
2071    Evas_Object *fobj;
2072
2073    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2074      {
2075         elm_widget_access(obj, is_access);
2076
2077          /* floating orphan object. if there are A, B, C objects and user does
2078             as below, then there would be floating orphan objects.
2079
2080               1. elm_object_content_set(layout, A);
2081               2. elm_object_content_set(layout, B);
2082               3. elm_object_content_set(layout, C);
2083
2084             now, the object A and B are floating orphan objects */
2085
2086         fobj = obj;
2087         for (;;)
2088           {
2089              fobj = evas_object_below_get(fobj);
2090              if (!fobj) break;
2091
2092              if (elm_widget_is(fobj) && !elm_widget_parent_get(fobj))
2093                {
2094                   elm_widget_access(fobj, is_access);
2095                }
2096           }
2097
2098         if (!is_access)
2099           {
2100              evas = evas_object_evas_get(obj);
2101             if (evas) _elm_access_object_highlight_disable(evas);
2102           }
2103      }
2104 }
2105
2106 void
2107 _elm_win_translate(void)
2108 {
2109    const Eina_List *l;
2110    Evas_Object *obj;
2111
2112    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2113      elm_widget_translate(obj);
2114 }
2115
2116 #ifdef HAVE_ELEMENTARY_X
2117 static Eina_Bool
2118 _elm_win_client_message(void *data,
2119                         int type EINA_UNUSED,
2120                         void *event)
2121 {
2122    ELM_WIN_DATA_GET(data, sd);
2123    Ecore_X_Event_Client_Message *e = event;
2124
2125    if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
2126    if (e->message_type == ECORE_X_ATOM_E_COMP_FLUSH)
2127      {
2128         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2129           {
2130              Evas *evas = evas_object_evas_get(sd->obj);
2131              if (evas)
2132                {
2133                   edje_file_cache_flush();
2134                   edje_collection_cache_flush();
2135                   evas_image_cache_flush(evas);
2136                   evas_font_cache_flush(evas);
2137                }
2138           }
2139      }
2140    else if (e->message_type == ECORE_X_ATOM_E_COMP_DUMP)
2141      {
2142         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2143           {
2144              Evas *evas = evas_object_evas_get(sd->obj);
2145              if (evas)
2146                {
2147                   edje_file_cache_flush();
2148                   edje_collection_cache_flush();
2149                   evas_image_cache_flush(evas);
2150                   evas_font_cache_flush(evas);
2151                   evas_render_dump(evas);
2152                }
2153           }
2154      }
2155    else if (e->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
2156      {
2157         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2158           {
2159              if ((unsigned int)e->data.l[1] ==
2160                  ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
2161                {
2162                   // XXX: call right access func
2163                }
2164              else if ((unsigned int)e->data.l[1] ==
2165                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
2166                {
2167                   // XXX: call right access func
2168                }
2169              else if ((unsigned int)e->data.l[1] ==
2170                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
2171                {
2172                   _elm_access_highlight_object_activate
2173                     (sd->obj, ELM_ACTIVATE_DEFAULT);
2174                }
2175              else if ((unsigned int)e->data.l[1] ==
2176                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
2177                {
2178                   /* there would be better way to read highlight object */
2179                   Evas *evas;
2180                   evas = evas_object_evas_get(sd->obj);
2181                   if (!evas) return ECORE_CALLBACK_PASS_ON;
2182
2183                   _elm_access_mouse_event_enabled_set(EINA_TRUE);
2184
2185                   evas_event_feed_mouse_in(evas, 0, NULL);
2186                   evas_event_feed_mouse_move
2187                     (evas, e->data.l[2], e->data.l[3], 0, NULL);
2188
2189                   _elm_access_mouse_event_enabled_set(EINA_FALSE);
2190                }
2191              else if ((unsigned int)e->data.l[1] ==
2192                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
2193                {
2194                   _elm_access_highlight_cycle(sd->obj, ELM_FOCUS_NEXT);
2195                }
2196              else if ((unsigned int)e->data.l[1] ==
2197                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
2198                {
2199                   _elm_access_highlight_cycle(sd->obj, ELM_FOCUS_PREVIOUS);
2200                }
2201              else if ((unsigned int)e->data.l[1] ==
2202                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
2203                {
2204                   _elm_access_highlight_object_activate
2205                     (sd->obj, ELM_ACTIVATE_UP);
2206                }
2207              else if ((unsigned int)e->data.l[1] ==
2208                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
2209                {
2210                   _elm_access_highlight_object_activate
2211                     (sd->obj, ELM_ACTIVATE_DOWN);
2212                }
2213           }
2214      }
2215    return ECORE_CALLBACK_PASS_ON;
2216 }
2217
2218 static Eina_Bool
2219 _elm_win_property_change(void *data,
2220                          int type EINA_UNUSED,
2221                          void *event)
2222 {
2223    ELM_WIN_DATA_GET(data, sd);
2224    Ecore_X_Event_Window_Property *e = event;
2225
2226    if (e->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE)
2227      {
2228         if (e->win == sd->x.xwin)
2229           {
2230              sd->indmode = (Elm_Win_Indicator_Mode)ecore_x_e_illume_indicator_state_get(e->win);
2231              evas_object_smart_callback_call(sd->obj, SIG_INDICATOR_PROP_CHANGED, NULL);
2232           }
2233      }
2234    return ECORE_CALLBACK_PASS_ON;
2235 }
2236 #endif
2237
2238 static void
2239 _elm_win_focus_highlight_hide(void *data EINA_UNUSED,
2240                               Evas_Object *obj,
2241                               const char *emission EINA_UNUSED,
2242                               const char *source EINA_UNUSED)
2243 {
2244    evas_object_hide(obj);
2245 }
2246
2247 static void
2248 _elm_win_focus_highlight_anim_end(void *data,
2249                                   Evas_Object *obj,
2250                                   const char *emission EINA_UNUSED,
2251                                   const char *source EINA_UNUSED)
2252 {
2253    ELM_WIN_DATA_GET(data, sd);
2254
2255    _elm_win_focus_highlight_simple_setup(sd, obj);
2256 }
2257
2258 static void
2259 _elm_win_focus_highlight_init(Elm_Win_Data *sd)
2260 {
2261    evas_event_callback_add(sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
2262                            _elm_win_object_focus_in, sd->obj);
2263    evas_event_callback_add(sd->evas,
2264                            EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
2265                            _elm_win_object_focus_out, sd->obj);
2266
2267    sd->focus_highlight.cur.target = NULL;
2268    sd->focus_highlight.fobj = edje_object_add(sd->evas);
2269    sd->focus_highlight.theme_changed = EINA_TRUE;
2270
2271    edje_object_signal_callback_add(sd->focus_highlight.fobj,
2272                                    "elm,action,focus,hide,end", "*",
2273                                    _elm_win_focus_highlight_hide, NULL);
2274    edje_object_signal_callback_add(sd->focus_highlight.fobj,
2275                                    "elm,action,focus,anim,end", "*",
2276                                    _elm_win_focus_highlight_anim_end, sd->obj);
2277    _elm_win_focus_highlight_reconfigure_job_start(sd);
2278 }
2279
2280 static void
2281 _elm_win_frame_cb_move_start(void *data,
2282                              Evas_Object *obj EINA_UNUSED,
2283                              const char *sig EINA_UNUSED,
2284                              const char *source)
2285 {
2286    ELM_WIN_DATA_GET(data, sd);
2287
2288    if (!sd) return;
2289
2290 #ifdef HAVE_ELEMENTARY_WAYLAND
2291    if (!strcmp(source, "elm"))
2292      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_HAND1);
2293    else
2294      ecore_wl_window_cursor_default_restore(sd->wl.win);
2295 #else
2296    (void)source;
2297 #endif
2298
2299    /* NB: Wayland handles moving surfaces by itself so we cannot
2300     * specify a specific x/y we want. Instead, we will pass in the
2301     * existing x/y values so they can be recorded as 'previous'
2302     * position. The new position will get updated automatically when
2303     * the move is finished */
2304
2305    ecore_evas_wayland_move(sd->ee, sd->screen.x, sd->screen.y);
2306 }
2307
2308 static void
2309 _elm_win_frame_cb_move_stop(void *data,
2310                             Evas_Object *obj EINA_UNUSED,
2311                             const char *sig EINA_UNUSED,
2312                             const char *source EINA_UNUSED)
2313 {
2314    ELM_WIN_DATA_GET(data, sd);
2315
2316    if (!sd) return;
2317
2318 #ifdef HAVE_ELEMENTARY_WAYLAND
2319    ecore_wl_window_cursor_default_restore(sd->wl.win);
2320 #endif
2321 }
2322
2323 #ifdef HAVE_ELEMENTARY_WAYLAND
2324 struct _resize_info
2325 {
2326    const char *name;
2327    int location;
2328 };
2329
2330 static struct _resize_info _border_side[4] =
2331 {
2332      { ELM_CURSOR_TOP_SIDE, 1 },
2333      { ELM_CURSOR_LEFT_SIDE, 4 },
2334      { ELM_CURSOR_BOTTOM_SIDE, 2 },
2335      { ELM_CURSOR_RIGHT_SIDE, 8 },
2336 };
2337
2338 static struct _resize_info _border_corner[4] =
2339 {
2340      { ELM_CURSOR_TOP_LEFT_CORNER, 5 },
2341      { ELM_CURSOR_BOTTOM_LEFT_CORNER, 6 },
2342      { ELM_CURSOR_BOTTOM_RIGHT_CORNER, 10 },
2343      { ELM_CURSOR_TOP_RIGHT_CORNER, 9 },
2344 };
2345 #endif
2346
2347 static void
2348 _elm_win_frame_obj_update(Elm_Win_Data *sd)
2349 {
2350    int fx, fy, fw, fh;
2351    int ox, oy, ow, oh;
2352    int sx, sy, sw, sh;
2353    int x, y, w, h;
2354    evas_object_geometry_get(sd->frame_obj, &fx, &fy, &fw, &fh);
2355    evas_object_geometry_get(sd->client_obj, &ox, &oy, &ow, &oh);
2356    evas_object_geometry_get(sd->spacer_obj, &sx, &sy, &sw, &sh);
2357
2358    evas_output_framespace_get(sd->evas, &x, &y, &w, &h);
2359
2360    if ((x != (ox - fx)) || (y != (oy - fy)) ||
2361        (w != (fw - ow)) || (h != (fh - oh)))
2362      {
2363         evas_output_framespace_set(sd->evas, (ox - fx), (oy - fy),
2364                                    (fw - ow), (fh - oh));
2365      }
2366
2367 #ifdef HAVE_ELEMENTARY_WAYLAND
2368    ecore_wl_window_opaque_region_set(sd->wl.win, -fx, -(fy - sy), sw, sh);
2369 #endif
2370 }
2371
2372 static void
2373 _elm_win_frame_obj_move(void *data,
2374                         Evas *e EINA_UNUSED,
2375                         Evas_Object *obj EINA_UNUSED,
2376                         void *event_info EINA_UNUSED)
2377 {
2378    Elm_Win_Data *sd;
2379
2380    if (!(sd = data)) return;
2381    if (!sd->client_obj) return;
2382
2383    _elm_win_frame_obj_update(sd);
2384 }
2385
2386 static void
2387 _elm_win_frame_obj_resize(void *data,
2388                           Evas *e EINA_UNUSED,
2389                           Evas_Object *obj EINA_UNUSED,
2390                           void *event_info EINA_UNUSED)
2391 {
2392    Elm_Win_Data *sd;
2393
2394    if (!(sd = data)) return;
2395    if (!sd->client_obj) return;
2396
2397    _elm_win_frame_obj_update(sd);
2398 }
2399
2400 static void
2401 _elm_win_frame_cb_resize_show(void *data,
2402                               Evas_Object *obj EINA_UNUSED,
2403                               const char *sig EINA_UNUSED,
2404                               const char *source)
2405 {
2406    ELM_WIN_DATA_GET(data, sd);
2407
2408    if (!sd) return;
2409    if (sd->resizing) return;
2410
2411 #ifdef HAVE_ELEMENTARY_WAYLAND
2412    int i;
2413    i = sd->rot / 90;
2414    if (!strcmp(source, "elm.event.resize.t"))
2415      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2416                                           _border_side[(0 + i) % 4].name);
2417    else if (!strcmp(source, "elm.event.resize.b"))
2418      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2419                                           _border_side[(2 + i) % 4].name);
2420    else if (!strcmp(source, "elm.event.resize.l"))
2421      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2422                                           _border_side[(1 + i) % 4].name);
2423    else if (!strcmp(source, "elm.event.resize.r"))
2424      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2425                                           _border_side[(3 + i) % 4].name);
2426    else if (!strcmp(source, "elm.event.resize.tl"))
2427      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2428                                           _border_corner[(0 + i) % 4].name);
2429    else if (!strcmp(source, "elm.event.resize.tr"))
2430      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2431                                           _border_corner[(3 + i) % 4].name);
2432    else if (!strcmp(source, "elm.event.resize.bl"))
2433      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2434                                           _border_corner[(1 + i) % 4].name);
2435    else if (!strcmp(source, "elm.event.resize.br"))
2436      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2437                                           _border_corner[(2 + i) % 4].name);
2438    else
2439      ecore_wl_window_cursor_default_restore(sd->wl.win);
2440 #else
2441    (void)source;
2442 #endif
2443 }
2444
2445 static void
2446 _elm_win_frame_cb_resize_hide(void *data,
2447                               Evas_Object *obj EINA_UNUSED,
2448                               const char *sig EINA_UNUSED,
2449                               const char *source EINA_UNUSED)
2450 {
2451    ELM_WIN_DATA_GET(data, sd);
2452
2453    if (!sd) return;
2454    if (sd->resizing) return;
2455
2456 #ifdef HAVE_ELEMENTARY_WAYLAND
2457    ecore_wl_window_cursor_default_restore(sd->wl.win);
2458 #endif
2459 }
2460
2461 static void
2462 _elm_win_frame_cb_resize_start(void *data,
2463                                Evas_Object *obj EINA_UNUSED,
2464                                const char *sig EINA_UNUSED,
2465                                const char *source)
2466 {
2467 #ifdef HAVE_ELEMENTARY_WAYLAND
2468    ELM_WIN_DATA_GET(data, sd);
2469    int i;
2470
2471    if (!sd) return;
2472    if (sd->resizing) return;
2473
2474    sd->resizing = EINA_TRUE;
2475    i = sd->rot / 90;
2476    if (!strcmp(source, "elm.event.resize.t"))
2477      sd->resize_location = _border_side[(0 + i) % 4].location;
2478    else if (!strcmp(source, "elm.event.resize.b"))
2479      sd->resize_location = _border_side[(2 + i) % 4].location;
2480    else if (!strcmp(source, "elm.event.resize.l"))
2481      sd->resize_location = _border_side[(1 + i) % 4].location;
2482    else if (!strcmp(source, "elm.event.resize.r"))
2483      sd->resize_location = _border_side[(3 + i) % 4].location;
2484    else if (!strcmp(source, "elm.event.resize.tl"))
2485      sd->resize_location = _border_corner[(0 + i) % 4].location;
2486    else if (!strcmp(source, "elm.event.resize.tr"))
2487      sd->resize_location = _border_corner[(3 + i) % 4].location;
2488    else if (!strcmp(source, "elm.event.resize.bl"))
2489      sd->resize_location = _border_corner[(1 + i) % 4].location;
2490    else if (!strcmp(source, "elm.event.resize.br"))
2491      sd->resize_location = _border_corner[(2 + i) % 4].location;
2492    else
2493      sd->resize_location = 0;
2494
2495    if (sd->resize_location > 0)
2496      ecore_evas_wayland_resize(sd->ee, sd->resize_location);
2497 #else
2498    (void)data;
2499    (void)source;
2500 #endif
2501 }
2502
2503 static void
2504 _elm_win_frame_cb_minimize(void *data,
2505                            Evas_Object *obj EINA_UNUSED,
2506                            const char *sig EINA_UNUSED,
2507                            const char *source EINA_UNUSED)
2508 {
2509    ELM_WIN_DATA_GET(data, sd);
2510
2511    if (!sd) return;
2512 //   sd->iconified = EINA_TRUE;
2513    TRAP(sd, iconified_set, EINA_TRUE);
2514 }
2515
2516 static void
2517 _elm_win_frame_maximized_state_update(Elm_Win_Data *sd, Eina_Bool maximized)
2518 {
2519    const char *emission;
2520
2521    if (maximized)
2522      emission = "elm,state,maximized";
2523    else
2524      emission = "elm,state,unmaximized";
2525
2526    edje_object_signal_emit(sd->frame_obj, emission, "elm");
2527    edje_object_message_signal_process(sd->frame_obj);
2528    evas_object_smart_calculate(sd->frame_obj);
2529
2530    _elm_win_frame_obj_update(sd);
2531 }
2532
2533 static void
2534 _elm_win_frame_cb_maximize(void *data,
2535                            Evas_Object *obj EINA_UNUSED,
2536                            const char *sig EINA_UNUSED,
2537                            const char *source EINA_UNUSED)
2538 {
2539    Eina_Bool value;
2540    ELM_WIN_DATA_GET(data, sd);
2541
2542    if (!sd) return;
2543    if (sd->maximized) value = EINA_FALSE;
2544    else value = EINA_TRUE;
2545
2546    _elm_win_frame_maximized_state_update(sd, value);
2547
2548    TRAP(sd, maximized_set, value);
2549 }
2550
2551 static void
2552 _elm_win_frame_cb_close(void *data,
2553                         Evas_Object *obj EINA_UNUSED,
2554                         const char *sig EINA_UNUSED,
2555                         const char *source EINA_UNUSED)
2556 {
2557    ELM_WIN_DATA_GET(data, sd);
2558    Evas_Object *win;
2559
2560    /* FIXME: After the current freeze, this should be handled differently.
2561     *
2562     * Ideally, we would want to mimic the X11 backend and use something
2563     * like ECORE_WL_EVENT_WINDOW_DELETE and handle the delete_request
2564     * inside of ecore_evas. That would be the 'proper' way, but since we are
2565     * in a freeze right now, I cannot add a new event value, or a new
2566     * event structure to ecore_wayland.
2567     *
2568     * So yes, this is a temporary 'stop-gap' solution which will be fixed
2569     * when the freeze is over, but it does fix a trac bug for now, and in a
2570     * way which does not break API or the freeze. - dh
2571     */
2572
2573    if (!sd) return;
2574
2575    win = sd->obj;
2576
2577    int autodel = sd->autodel;
2578    sd->autodel_clear = &autodel;
2579    evas_object_ref(win);
2580    evas_object_smart_callback_call(win, SIG_DELETE_REQUEST, NULL);
2581    // FIXME: if above callback deletes - then the below will be invalid
2582    if (autodel) evas_object_del(win);
2583    else sd->autodel_clear = NULL;
2584    evas_object_unref(win);
2585 }
2586
2587 static void
2588 _elm_win_frame_add(Elm_Win_Data *sd,
2589                    const char *style)
2590 {
2591    Evas_Object *obj = sd->obj;
2592    int w, h, mw, mh;
2593    short layer;
2594
2595    sd->frame_obj = edje_object_add(sd->evas);
2596    layer = evas_object_layer_get(obj);
2597    evas_object_layer_set(sd->frame_obj, layer + 1);
2598    if (!elm_widget_theme_object_set
2599        (sd->obj, sd->frame_obj, "border", "base", style))
2600      {
2601         ELM_SAFE_FREE(sd->frame_obj, evas_object_del);
2602         return;
2603      }
2604
2605    sd->spacer_obj = evas_object_rectangle_add(sd->evas);
2606    evas_object_color_set(sd->spacer_obj, 0, 0, 0, 0);
2607    evas_object_repeat_events_set(sd->spacer_obj, EINA_TRUE);
2608    edje_object_part_swallow(sd->frame_obj, "elm.swallow.frame_spacer",
2609                             sd->spacer_obj);
2610
2611    sd->client_obj = evas_object_rectangle_add(sd->evas);
2612    evas_object_color_set(sd->client_obj, 0, 0, 0, 0);
2613    /* NB: Tried pass_events here, but that fails to send events */
2614    evas_object_repeat_events_set(sd->client_obj, EINA_TRUE);
2615    edje_object_part_swallow(sd->frame_obj, "elm.swallow.client",
2616                             sd->client_obj);
2617
2618    evas_object_is_frame_object_set(sd->frame_obj, EINA_TRUE);
2619
2620    evas_object_event_callback_add
2621      (sd->frame_obj, EVAS_CALLBACK_MOVE, _elm_win_frame_obj_move, sd);
2622    evas_object_event_callback_add
2623      (sd->frame_obj, EVAS_CALLBACK_RESIZE, _elm_win_frame_obj_resize, sd);
2624
2625    /* NB: Do NOT remove these calls !! Needed to calculate proper
2626     * framespace on inital show of the window */
2627    edje_object_size_min_calc(sd->frame_obj, &mw, &mh);
2628    evas_object_move(sd->frame_obj, 0, 0);
2629    evas_object_resize(sd->frame_obj, mw, mh);
2630    evas_object_smart_calculate(sd->frame_obj);
2631
2632    edje_object_signal_callback_add
2633      (sd->frame_obj, "elm,action,move,start", "elm",
2634      _elm_win_frame_cb_move_start, obj);
2635    edje_object_signal_callback_add
2636      (sd->frame_obj, "elm,action,move,stop", "elm",
2637      _elm_win_frame_cb_move_stop, obj);
2638    edje_object_signal_callback_add
2639      (sd->frame_obj, "elm,action,resize,show", "*",
2640      _elm_win_frame_cb_resize_show, obj);
2641    edje_object_signal_callback_add
2642      (sd->frame_obj, "elm,action,resize,hide", "*",
2643      _elm_win_frame_cb_resize_hide, obj);
2644    edje_object_signal_callback_add
2645      (sd->frame_obj, "elm,action,resize,start", "*",
2646      _elm_win_frame_cb_resize_start, obj);
2647    edje_object_signal_callback_add
2648      (sd->frame_obj, "elm,action,minimize", "elm",
2649      _elm_win_frame_cb_minimize, obj);
2650    edje_object_signal_callback_add
2651      (sd->frame_obj, "elm,action,maximize", "elm",
2652      _elm_win_frame_cb_maximize, obj);
2653    edje_object_signal_callback_add
2654      (sd->frame_obj, "elm,action,close", "elm", _elm_win_frame_cb_close, obj);
2655
2656    if (sd->title)
2657      {
2658         edje_object_part_text_escaped_set
2659           (sd->frame_obj, "elm.text.title", sd->title);
2660      }
2661
2662    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
2663    ecore_evas_resize(sd->ee, w, h);
2664 }
2665
2666 static void
2667 _elm_win_frame_del(Elm_Win_Data *sd)
2668 {
2669    int w, h;
2670
2671    ELM_SAFE_FREE(sd->client_obj, evas_object_del);
2672
2673    if (sd->frame_obj)
2674      {
2675         evas_object_event_callback_del_full
2676           (sd->frame_obj, EVAS_CALLBACK_MOVE, _elm_win_frame_obj_move, sd);
2677         evas_object_event_callback_del_full
2678           (sd->frame_obj, EVAS_CALLBACK_RESIZE, _elm_win_frame_obj_resize, sd);
2679
2680         edje_object_signal_callback_del
2681           (sd->frame_obj, "elm,action,move,start", "elm",
2682               _elm_win_frame_cb_move_start);
2683         edje_object_signal_callback_del
2684           (sd->frame_obj, "elm,action,move,stop", "elm",
2685               _elm_win_frame_cb_move_stop);
2686         edje_object_signal_callback_del
2687           (sd->frame_obj, "elm,action,resize,show", "*",
2688               _elm_win_frame_cb_resize_show);
2689         edje_object_signal_callback_del
2690           (sd->frame_obj, "elm,action,resize,hide", "*",
2691               _elm_win_frame_cb_resize_hide);
2692         edje_object_signal_callback_del
2693           (sd->frame_obj, "elm,action,resize,start", "*",
2694               _elm_win_frame_cb_resize_start);
2695         edje_object_signal_callback_del
2696           (sd->frame_obj, "elm,action,minimize", "elm",
2697               _elm_win_frame_cb_minimize);
2698         edje_object_signal_callback_del
2699           (sd->frame_obj, "elm,action,maximize", "elm",
2700               _elm_win_frame_cb_maximize);
2701         edje_object_signal_callback_del
2702           (sd->frame_obj, "elm,action,close", "elm",
2703               _elm_win_frame_cb_close);
2704
2705         ELM_SAFE_FREE(sd->frame_obj, evas_object_del);
2706      }
2707
2708    evas_output_framespace_set(sd->evas, 0, 0, 0, 0);
2709    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
2710    ecore_evas_resize(sd->ee, w, h);
2711 }
2712
2713 #ifdef ELM_DEBUG
2714 static void
2715 _debug_key_down(void *data EINA_UNUSED,
2716                 Evas *e EINA_UNUSED,
2717                 Evas_Object *obj,
2718                 void *event_info)
2719 {
2720    Evas_Event_Key_Down *ev = event_info;
2721
2722    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
2723      return;
2724
2725    if ((strcmp(ev->key, "F12")) ||
2726        (!evas_key_modifier_is_set(ev->modifiers, "Control")))
2727      return;
2728
2729    INF("Tree graph generated.");
2730    elm_object_tree_dot_dump(obj, "./dump.dot");
2731 }
2732
2733 #endif
2734
2735 static void
2736 _win_inlined_image_set(Elm_Win_Data *sd)
2737 {
2738    evas_object_image_alpha_set(sd->img_obj, EINA_FALSE);
2739    evas_object_image_filled_set(sd->img_obj, EINA_TRUE);
2740
2741    evas_object_event_callback_add
2742      (sd->img_obj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, sd->obj);
2743    evas_object_event_callback_add
2744      (sd->img_obj, EVAS_CALLBACK_HIDE, _win_img_hide, sd->obj);
2745    evas_object_event_callback_add
2746      (sd->img_obj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, sd->obj);
2747    evas_object_event_callback_add
2748      (sd->img_obj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, sd->obj);
2749    evas_object_event_callback_add
2750      (sd->img_obj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, sd->obj);
2751 }
2752
2753 static void
2754 _elm_win_on_icon_del(void *data,
2755                      Evas *e EINA_UNUSED,
2756                      Evas_Object *obj,
2757                      void *event_info EINA_UNUSED)
2758 {
2759    ELM_WIN_DATA_GET(data, sd);
2760
2761    if (sd->icon == obj) sd->icon = NULL;
2762 }
2763
2764 EOLIAN static void
2765 _elm_win_evas_smart_add(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED)
2766 {
2767    eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
2768
2769    elm_widget_can_focus_set(obj, EINA_TRUE);
2770
2771    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2772 }
2773
2774 #ifdef HAVE_ELEMENTARY_X
2775 static void
2776 _elm_x_io_err(void *data EINA_UNUSED)
2777 {
2778    Eina_List *l;
2779    Evas_Object *obj;
2780
2781    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2782      evas_object_smart_callback_call(obj, SIG_IOERR, NULL);
2783    elm_exit();
2784 }
2785 #endif
2786
2787 EAPI Evas_Object *
2788 elm_win_add(Evas_Object *parent,
2789             const char *name,
2790             Elm_Win_Type type)
2791 {
2792    Evas_Object *obj = eo_add_custom(MY_CLASS, parent, elm_obj_win_constructor(name, type));
2793    eo_unref(obj);
2794    return obj;
2795 }
2796
2797 static void
2798 _elm_win_cb_hide(void *data EINA_UNUSED,
2799                  Evas *e EINA_UNUSED,
2800                  Evas_Object *obj EINA_UNUSED,
2801                  void *event_info EINA_UNUSED)
2802 {
2803    _elm_win_state_eval_queue();
2804 }
2805
2806 static void
2807 _elm_win_cb_show(void *data EINA_UNUSED,
2808                  Evas *e EINA_UNUSED,
2809                  Evas_Object *obj EINA_UNUSED,
2810                  void *event_info EINA_UNUSED)
2811 {
2812    _elm_win_state_eval_queue();
2813 }
2814
2815 /**
2816   * @internal
2817   *
2818   * Recalculate the size of window considering its resize objects' weight and
2819   * min size. If any of its resize objects' weight equals to 0.0, window
2820   * layout's weight will be set to 0.0.
2821   *
2822   * @param o box object
2823   * @param p box's private data
2824   * @param data window object
2825   */
2826 static void
2827 _window_layout_stack(Evas_Object *o, Evas_Object_Box_Data *p, void *data)
2828 {
2829    const Eina_List *l;
2830    Evas_Object *child;
2831    Evas_Object_Box_Option *opt;
2832    Evas_Coord x, y, w, h;
2833    double wx, wy;
2834    Evas_Coord minw = -1, minh = -1;
2835    double weight_x = EVAS_HINT_EXPAND;
2836    double weight_y = EVAS_HINT_EXPAND;
2837
2838    EINA_LIST_FOREACH(p->children, l, opt)
2839      {
2840         child = opt->obj;
2841         evas_object_size_hint_weight_get(child, &wx, &wy);
2842         if (wx == 0.0) weight_x = 0;
2843         if (wy == 0.0) weight_y = 0;
2844
2845         evas_object_size_hint_min_get(child, &w, &h);
2846         if (w > minw) minw = w;
2847         if (h > minh) minh = h;
2848      }
2849
2850    evas_object_size_hint_min_set(o, minw, minh);
2851    evas_object_geometry_get(o, &x, &y, &w, &h);
2852    if (w < minw) w = minw;
2853    if (h < minh) h = minh;
2854    evas_object_resize(o, w, h);
2855
2856    EINA_LIST_FOREACH(p->children, l, opt)
2857      {
2858         child = opt->obj;
2859         evas_object_move(child, x, y);
2860         evas_object_resize(child, w, h);
2861      }
2862
2863    ELM_WIN_DATA_GET(data, sd);
2864    evas_object_size_hint_weight_set(sd->layout, weight_x, weight_y);
2865    evas_object_smart_changed(sd->layout);
2866 }
2867
2868 static Eina_Bool
2869 _accel_is_gl(void)
2870 {
2871    const char *env = NULL;
2872    const char *str;
2873    
2874    str = _elm_accel_preference;
2875    env = getenv("ELM_ACCEL");
2876    if (env) str = env;
2877    if ((str) &&
2878        ((!strcasecmp(str, "gl")) ||
2879         (!strcasecmp(str, "opengl")) ||
2880         (!strcasecmp(str, "3d")) ||
2881         (!strcasecmp(str, "hw")) ||
2882         (!strcasecmp(str, "accel")) ||
2883         (!strcasecmp(str, "hardware"))
2884        ))
2885      return EINA_TRUE;
2886    return EINA_FALSE;
2887 }
2888
2889 EOLIAN static void
2890 _elm_win_constructor(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type type)
2891 {
2892    sd->obj = obj; // in ctor
2893
2894    Evas_Object *parent = NULL;
2895    Evas *e;
2896    const Eina_List *l;
2897    const char *fontpath, *engine = NULL, *enginelist[32], *disp;
2898    int i;
2899
2900    Elm_Win_Data tmp_sd;
2901
2902    eo_do(obj, parent = eo_parent_get());
2903
2904    /* just to store some data while trying out to create a canvas */
2905    memset(&tmp_sd, 0, sizeof(Elm_Win_Data));
2906
2907    switch (type)
2908      {
2909       case ELM_WIN_INLINED_IMAGE:
2910         if (!parent) break;
2911           {
2912              e = evas_object_evas_get(parent);
2913              Ecore_Evas *ee;
2914
2915              if (!e) break;
2916
2917              ee = ecore_evas_ecore_evas_get(e);
2918              if (!ee) break;
2919
2920              tmp_sd.img_obj = ecore_evas_object_image_new(ee);
2921              if (!tmp_sd.img_obj) break;
2922
2923              tmp_sd.ee = ecore_evas_object_ecore_evas_get(tmp_sd.img_obj);
2924              if (!tmp_sd.ee)
2925                {
2926                   ELM_SAFE_FREE(tmp_sd.img_obj, evas_object_del);
2927                }
2928           }
2929         break;
2930
2931       case ELM_WIN_SOCKET_IMAGE:
2932         tmp_sd.ee = ecore_evas_extn_socket_new(1, 1);
2933         break;
2934
2935       default:
2936         disp = getenv("ELM_DISPLAY");
2937         if ((disp) && (!strcmp(disp, "x11")))
2938           {
2939              if (_accel_is_gl())
2940                {
2941                   enginelist[0] = ELM_OPENGL_X11;
2942                   enginelist[1] = ELM_SOFTWARE_X11;
2943                   enginelist[2] = NULL;
2944                }
2945              else
2946                {
2947                   enginelist[0] = ENGINE_GET();
2948                   enginelist[1] = ELM_SOFTWARE_X11;
2949                   enginelist[2] = ELM_OPENGL_X11;
2950                   enginelist[3] = NULL;
2951                }
2952           }
2953         else if ((disp) && (!strcmp(disp, "wl")))
2954           {
2955              if (_accel_is_gl())
2956                {
2957                   enginelist[0] = ELM_WAYLAND_EGL;
2958                   enginelist[1] = ELM_WAYLAND_SHM;
2959                   enginelist[2] = NULL;
2960                }
2961              else
2962                {
2963                   enginelist[0] = ENGINE_GET();
2964                   enginelist[1] = ELM_WAYLAND_SHM;
2965                   enginelist[2] = ELM_WAYLAND_EGL;
2966                   enginelist[3] = NULL;
2967                }
2968           }
2969         else if ((disp) && (!strcmp(disp, "win")))
2970           {
2971              enginelist[0] = ENGINE_GET();
2972              enginelist[1] = ELM_SOFTWARE_WIN32;
2973              enginelist[2] = NULL;
2974           }
2975         else if ((disp) && (!strcmp(disp, "sdl")))
2976           {
2977              if (_accel_is_gl())
2978                {
2979                   enginelist[0] = ELM_OPENGL_SDL;
2980                   enginelist[1] = ELM_SOFTWARE_SDL;
2981                   enginelist[2] = NULL;
2982                }
2983              else
2984                {
2985                   enginelist[0] = ENGINE_GET();
2986                   enginelist[1] = ELM_SOFTWARE_SDL;
2987                   enginelist[2] = ELM_OPENGL_SDL;
2988                   enginelist[3] = NULL;
2989                }
2990           }
2991         else if ((disp) && (!strcmp(disp, "mac")))
2992           {
2993              enginelist[0] = ENGINE_GET();
2994              enginelist[1] = ELM_OPENGL_COCOA;
2995              enginelist[2] = NULL;
2996           }
2997         else if ((disp) && (!strcmp(disp, "ews")))
2998           {
2999              enginelist[0] = ENGINE_GET();
3000              enginelist[1] = ELM_EWS;
3001              enginelist[2] = NULL;
3002           }
3003         else if ((disp) && (!strcmp(disp, "fb")))
3004           {
3005              enginelist[0] = ENGINE_GET();
3006              enginelist[1] = ELM_DRM;
3007              enginelist[2] = ELM_SOFTWARE_FB;
3008              enginelist[3] = NULL;
3009           }
3010         else if ((disp) && (!strcmp(disp, "buffer")))
3011           {
3012              enginelist[0] = ENGINE_GET();
3013              enginelist[1] = ELM_BUFFER;
3014              enginelist[2] = NULL;
3015           }
3016         else if ((disp) && (!strcmp(disp, "ps3")))
3017           {
3018              enginelist[0] = ENGINE_GET();
3019              enginelist[1] = ELM_SOFTWARE_PSL1GHT;
3020              enginelist[2] = NULL;
3021           }
3022         else if ((disp) && (!strcmp(disp, "shot")))
3023           {
3024              enginelist[0] = ENGINE_GET();
3025              enginelist[1] = NULL;
3026           }
3027         else
3028           {
3029              if (_accel_is_gl())
3030                {
3031                   enginelist[0] = ELM_OPENGL_X11;
3032                   enginelist[1] = ELM_WAYLAND_EGL;
3033                   enginelist[2] = ELM_DRM;
3034                   enginelist[3] = ELM_SOFTWARE_FB;
3035                   enginelist[4] = ELM_OPENGL_COCOA;
3036                   enginelist[5] = ELM_OPENGL_SDL;
3037                   enginelist[6] = NULL;
3038                }
3039              else
3040                {
3041                   enginelist[0] = ENGINE_GET();
3042                   enginelist[1] = ELM_SOFTWARE_X11;
3043                   enginelist[2] = ELM_WAYLAND_SHM;
3044                   enginelist[3] = ELM_DRM;
3045                   enginelist[4] = ELM_SOFTWARE_FB;
3046                   enginelist[5] = ELM_OPENGL_COCOA;
3047                   enginelist[6] = ELM_SOFTWARE_SDL;
3048                   enginelist[7] = NULL;
3049                }
3050           }
3051         for (i = 0; i < 30; i++)
3052           {
3053              if ((i > 0) && (!enginelist[i])) break;
3054              if (!strcmp(enginelist[i], ELM_SOFTWARE_X11))
3055                tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
3056              else if (!strcmp(enginelist[i], ELM_OPENGL_X11))
3057                {
3058                   int opt[10], opt_i = 0;
3059
3060                   if (_elm_config->vsync)
3061                     {
3062                        opt[opt_i++] = ECORE_EVAS_GL_X11_OPT_VSYNC;
3063                        opt[opt_i++] = 1;
3064                        opt[opt_i++] = 0;
3065                     }
3066                   if (opt_i > 0)
3067                     tmp_sd.ee = ecore_evas_gl_x11_options_new(NULL, 0, 0, 0, 1, 1, opt);
3068                   else
3069                     tmp_sd.ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
3070                }
3071              else if (!strcmp(enginelist[i], ELM_WAYLAND_SHM))
3072                tmp_sd.ee = ecore_evas_wayland_shm_new(NULL, 0, 0, 0, 1, 1, 0);
3073              else if (!strcmp(enginelist[i], ELM_WAYLAND_EGL))
3074                tmp_sd.ee = ecore_evas_wayland_egl_new(NULL, 0, 0, 0, 1, 1, 0);
3075              else if (!strcmp(enginelist[i], ELM_SOFTWARE_WIN32))
3076                tmp_sd.ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
3077              else if (!strcmp(enginelist[i], ELM_SOFTWARE_SDL))
3078                tmp_sd.ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
3079              else if (!strcmp(enginelist[i], ELM_OPENGL_SDL))
3080                tmp_sd.ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
3081              else if (!strcmp(enginelist[i], ELM_OPENGL_COCOA))
3082                tmp_sd.ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
3083              else if (!strcmp(enginelist[i], ELM_EWS))
3084                tmp_sd.ee = ecore_evas_ews_new(0, 0, 1, 1);
3085              else if (!strcmp(enginelist[i], ELM_SOFTWARE_FB))
3086                tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
3087              else if (!strcmp(enginelist[i], ELM_BUFFER))
3088                tmp_sd.ee = ecore_evas_buffer_new(1, 1);
3089              else if (!strcmp(enginelist[i], ELM_SOFTWARE_PSL1GHT))
3090                tmp_sd.ee = ecore_evas_psl1ght_new(NULL, 1, 1);
3091              else if (!strcmp(enginelist[i], ELM_DRM))
3092                tmp_sd.ee = ecore_evas_drm_new(NULL, 0, 0, 0, 1, 1);
3093              else if (!strncmp(enginelist[i], "shot:", 5))
3094                {
3095                   tmp_sd.ee = ecore_evas_buffer_new(1, 1);
3096                   ecore_evas_manual_render_set(tmp_sd.ee, EINA_TRUE);
3097                   tmp_sd.shot.info = eina_stringshare_add(ENGINE_GET() + 5);
3098                }
3099              engine = enginelist[i];
3100              if (tmp_sd.ee) break;
3101           }
3102         break;
3103      }
3104
3105    if (!tmp_sd.ee)
3106      {
3107         ERR("Cannot create window.");
3108         eo_error_set(obj);
3109         return;
3110      }
3111
3112    eo_do(obj, eo_parent_set(ecore_evas_get(tmp_sd.ee)));
3113    eo_do_super(obj, MY_CLASS, eo_constructor());
3114    eo_do(obj,
3115          evas_obj_type_set(MY_CLASS_NAME_LEGACY),
3116          evas_obj_smart_callbacks_descriptions_set(_smart_callbacks));
3117
3118    if (getenv("ELM_FIRST_FRAME"))
3119      evas_event_callback_add(ecore_evas_get(tmp_sd.ee), EVAS_CALLBACK_RENDER_POST,
3120                              _elm_win_first_frame_do, getenv("ELM_FIRST_FRAME"));
3121
3122    /* copying possibly altered fields back */
3123 #define SD_CPY(_field)             \
3124   do                               \
3125     {                              \
3126        sd->_field = tmp_sd._field; \
3127     } while (0)
3128
3129    SD_CPY(ee);
3130    SD_CPY(img_obj);
3131    SD_CPY(shot.info);
3132 #undef SD_CPY
3133
3134    if ((trap) && (trap->add))
3135      sd->trap_data = trap->add(obj);
3136
3137    /* complementary actions, which depend on final smart data
3138     * pointer */
3139    if (type == ELM_WIN_INLINED_IMAGE)
3140      _win_inlined_image_set(sd);
3141 #ifdef HAVE_ELEMENTARY_X
3142    else if ((engine) &&
3143             ((!strcmp(engine, ELM_SOFTWARE_X11)) ||
3144              (!strcmp(engine, ELM_OPENGL_X11))))
3145      {
3146         sd->x.client_message_handler = ecore_event_handler_add
3147             (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, obj);
3148         sd->x.property_handler = ecore_event_handler_add
3149             (ECORE_X_EVENT_WINDOW_PROPERTY, _elm_win_property_change, obj);
3150      }
3151 #endif
3152    else if ((engine) && (!strncmp(engine, "shot:", 5)))
3153      _shot_init(sd);
3154
3155    sd->kbdmode = ELM_WIN_KEYBOARD_UNKNOWN;
3156    sd->indmode = ELM_WIN_INDICATOR_UNKNOWN;
3157
3158 #ifdef HAVE_ELEMENTARY_X
3159    _internal_elm_win_xwindow_get(sd);
3160    if (sd->x.xwin)
3161      {
3162         ecore_x_io_error_handler_set(_elm_x_io_err, NULL);
3163      }
3164 #endif
3165
3166 #ifdef HAVE_ELEMENTARY_WAYLAND
3167    if ((ENGINE_COMPARE(ELM_WAYLAND_SHM)) || (ENGINE_COMPARE(ELM_WAYLAND_EGL)))
3168      _elm_win_wlwindow_get(sd);
3169 #endif
3170
3171    if ((_elm_config->bgpixmap)
3172 #ifdef HAVE_ELEMENTARY_X
3173        &&
3174        (((sd->x.xwin) && (!ecore_x_screen_is_composited(0))) ||
3175            (!sd->x.xwin)))
3176 #else
3177      )
3178 #endif
3179      TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
3180    // bg pixmap done by x - has other issues like can be redrawn by x before it
3181    // is filled/ready by app
3182    //     TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
3183
3184    sd->type = type;
3185    sd->parent = parent;
3186    sd->modal_count = 0;
3187
3188    if (sd->parent)
3189      evas_object_event_callback_add
3190        (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, obj);
3191
3192    sd->evas = ecore_evas_get(sd->ee);
3193
3194    evas_object_color_set(obj, 0, 0, 0, 0);
3195    evas_object_move(obj, 0, 0);
3196    evas_object_resize(obj, 1, 1);
3197    evas_object_layer_set(obj, 50);
3198    evas_object_pass_events_set(obj, EINA_TRUE);
3199
3200    if (type == ELM_WIN_INLINED_IMAGE)
3201      elm_widget_parent2_set(obj, parent);
3202
3203    /* use own version of ecore_evas_object_associate() that does TRAP() */
3204    ecore_evas_data_set(sd->ee, "elm_win", obj);
3205
3206    evas_object_event_callback_add
3207      (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3208       _elm_win_obj_callback_changed_size_hints, obj);
3209
3210    evas_object_intercept_raise_callback_add
3211      (obj, _elm_win_obj_intercept_raise, obj);
3212    evas_object_intercept_lower_callback_add
3213      (obj, _elm_win_obj_intercept_lower, obj);
3214    evas_object_intercept_stack_above_callback_add
3215      (obj, _elm_win_obj_intercept_stack_above, obj);
3216    evas_object_intercept_stack_below_callback_add
3217      (obj, _elm_win_obj_intercept_stack_below, obj);
3218    evas_object_intercept_layer_set_callback_add
3219      (obj, _elm_win_obj_intercept_layer_set, obj);
3220    evas_object_intercept_show_callback_add
3221      (obj, _elm_win_obj_intercept_show, obj);
3222
3223    TRAP(sd, name_class_set, name, _elm_appname);
3224    ecore_evas_callback_delete_request_set(sd->ee, _elm_win_delete_request);
3225    ecore_evas_callback_resize_set(sd->ee, _elm_win_resize);
3226    ecore_evas_callback_mouse_in_set(sd->ee, _elm_win_mouse_in);
3227    ecore_evas_callback_focus_in_set(sd->ee, _elm_win_focus_in);
3228    ecore_evas_callback_focus_out_set(sd->ee, _elm_win_focus_out);
3229    ecore_evas_callback_move_set(sd->ee, _elm_win_move);
3230    ecore_evas_callback_state_change_set(sd->ee, _elm_win_state_change);
3231    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _elm_win_cb_hide, NULL);
3232    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _elm_win_cb_show, NULL);
3233
3234    evas_image_cache_set(sd->evas, (_elm_config->image_cache * 1024));
3235    evas_font_cache_set(sd->evas, (_elm_config->font_cache * 1024));
3236
3237    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
3238      evas_font_path_append(sd->evas, fontpath);
3239
3240    if (!_elm_config->font_hinting)
3241      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_NONE);
3242    else if (_elm_config->font_hinting == 1)
3243      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_AUTO);
3244    else if (_elm_config->font_hinting == 2)
3245      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_BYTECODE);
3246
3247 #ifdef HAVE_ELEMENTARY_X
3248    _elm_win_xwin_update(sd);
3249 #endif
3250
3251    _elm_win_list = eina_list_append(_elm_win_list, obj);
3252    _elm_win_count++;
3253
3254    if ((engine) && ((!strcmp(engine, ELM_SOFTWARE_FB)) || (!strcmp(engine, ELM_DRM))))
3255      {
3256         TRAP(sd, fullscreen_set, 1);
3257      }
3258    else if ((type != ELM_WIN_INLINED_IMAGE) &&
3259             ((engine) &&
3260              ((!strcmp(engine, ELM_WAYLAND_SHM) ||
3261               (!strcmp(engine, ELM_WAYLAND_EGL))))))
3262      _elm_win_frame_add(sd, "default");
3263
3264    if (_elm_config->focus_highlight_enable)
3265      elm_win_focus_highlight_enabled_set(obj, EINA_TRUE);
3266    if (_elm_config->focus_highlight_animate)
3267      elm_win_focus_highlight_animate_set(obj, EINA_TRUE);
3268
3269 #ifdef ELM_DEBUG
3270    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(sd->evas, "Control");
3271    evas_object_event_callback_add
3272      (obj, EVAS_CALLBACK_KEY_DOWN, _debug_key_down, NULL);
3273
3274    if (evas_object_key_grab(obj, "F12", mask, 0, EINA_TRUE))
3275      INF("Ctrl+F12 key combination exclusive for dot tree generation\n");
3276    else
3277      ERR("failed to grab F12 key to elm widgets (dot) tree generation");
3278 #endif
3279
3280    if ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_ON) ||
3281        ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_AUTO) &&
3282         ((engine) && 
3283          ((!strcmp(engine, ELM_SOFTWARE_FB)) || (!strcmp(engine, ELM_DRM))))))
3284      {
3285         Evas_Object *o;
3286         Evas_Coord mw = 1, mh = 1, hx = 0, hy = 0;
3287
3288         sd->pointer.obj = o = edje_object_add(ecore_evas_get(tmp_sd.ee));
3289         _elm_theme_object_set(obj, o, "pointer", "base", "default");
3290         edje_object_size_min_calc(o, &mw, &mh);
3291         evas_object_resize(o, mw, mh);
3292         edje_object_part_geometry_get(o, "elm.swallow.hotspot",
3293                                       &hx, &hy, NULL, NULL);
3294         sd->pointer.hot_x = hx;
3295         sd->pointer.hot_y = hy;
3296         evas_object_show(o);
3297         ecore_evas_object_cursor_set(tmp_sd.ee, o, EVAS_LAYER_MAX, hx, hy);
3298      }
3299    else if (_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_OFF)
3300      {
3301         // do nothing
3302      }
3303
3304    sd->wm_rot.wm_supported = ecore_evas_wm_rotation_supported_get(sd->ee);
3305    sd->wm_rot.preferred_rot = -1; // it means that elm_win doesn't use preferred rotation.
3306
3307    sd->layout = edje_object_add(sd->evas);
3308    _elm_theme_object_set(obj, sd->layout, "win", "base", "default");
3309    sd->box = evas_object_box_add(sd->evas);
3310    evas_object_box_layout_set(sd->box, _window_layout_stack, obj, NULL);
3311    edje_object_part_swallow(sd->layout, "elm.swallow.contents", sd->box);
3312    evas_object_move(sd->layout, 0, 0);
3313    evas_object_resize(sd->layout, 1, 1);
3314    edje_object_update_hints_set(sd->layout, EINA_TRUE);
3315    evas_object_event_callback_add(sd->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3316                                   _elm_win_on_resize_obj_changed_size_hints, obj);
3317
3318    if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
3319      {
3320         eo_do(obj, elm_interface_atspi_accessible_role_set(ELM_ATSPI_ROLE_WINDOW));
3321         elm_interface_atspi_accessible_children_changed_added_signal_emit(_elm_atspi_root_get(), obj);
3322         eo_do(obj, eo_event_callback_call(ELM_INTERFACE_ATSPI_WINDOW_EVENT_WINDOW_CREATED, NULL));
3323      }
3324
3325    evas_object_show(sd->layout);
3326 }
3327
3328 EOLIAN static void
3329 _elm_win_eo_base_constructor(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED)
3330 {
3331    eo_error_set(obj);
3332    ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME);
3333 }
3334
3335 EOLIAN static Elm_Win_Type
3336 _elm_win_type_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3337 {
3338    return sd->type;
3339 }
3340
3341 EAPI Evas_Object *
3342 elm_win_util_standard_add(const char *name,
3343                           const char *title)
3344 {
3345    Evas_Object *win, *bg;
3346
3347    win = elm_win_add(NULL, name, ELM_WIN_BASIC);
3348    if (!win) return NULL;
3349
3350    elm_win_title_set(win, title);
3351    bg = elm_bg_add(win);
3352    if (!bg)
3353      {
3354         evas_object_del(win);
3355         return NULL;
3356      }
3357    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3358    elm_win_resize_object_add(win, bg);
3359    evas_object_show(bg);
3360
3361    return win;
3362 }
3363
3364 EOLIAN static void
3365 _elm_win_resize_object_add(Eo *obj, Elm_Win_Data *sd, Evas_Object *subobj)
3366 {
3367    elm_widget_sub_object_add(obj, subobj);
3368
3369    if (!evas_object_box_append(sd->box, subobj))
3370      ERR("could not append %p to box", subobj);
3371 }
3372
3373 EOLIAN static void
3374 _elm_win_resize_object_del(Eo *obj, Elm_Win_Data *sd, Evas_Object *subobj)
3375 {
3376    if (!elm_widget_sub_object_del(obj, subobj))
3377      ERR("could not remove sub object %p from %p", subobj, obj);
3378
3379    evas_object_box_remove(sd->box, subobj);
3380 }
3381
3382 EOLIAN static void
3383 _elm_win_title_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *title)
3384 {
3385    if (!title) return;
3386    eina_stringshare_replace(&(sd->title), title);
3387    TRAP(sd, title_set, sd->title);
3388    if (sd->frame_obj)
3389      edje_object_part_text_escaped_set
3390        (sd->frame_obj, "elm.text.title", sd->title);
3391 }
3392
3393 EOLIAN static const char*
3394 _elm_win_title_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3395 {
3396    return sd->title;
3397 }
3398
3399 EOLIAN static void
3400 _elm_win_icon_name_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *icon_name)
3401 {
3402    if (!icon_name) return;
3403    eina_stringshare_replace(&(sd->icon_name), icon_name);
3404 #ifdef HAVE_ELEMENTARY_X
3405    _elm_win_xwin_update(sd);
3406 #endif
3407 }
3408
3409 EOLIAN static const char*
3410 _elm_win_icon_name_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3411 {
3412    return sd->icon_name;
3413 }
3414
3415 EOLIAN static void
3416 _elm_win_role_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *role)
3417 {
3418    if (!role) return;
3419    eina_stringshare_replace(&(sd->role), role);
3420 #ifdef HAVE_ELEMENTARY_X
3421    _elm_win_xwin_update(sd);
3422 #endif
3423 }
3424
3425 EOLIAN static const char*
3426 _elm_win_role_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3427 {
3428    return sd->role;
3429 }
3430
3431 EOLIAN static void
3432 _elm_win_icon_object_set(Eo *obj, Elm_Win_Data *sd, Evas_Object *icon)
3433 {
3434    if (sd->icon)
3435      evas_object_event_callback_del_full
3436        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, obj);
3437    sd->icon = icon;
3438    if (sd->icon)
3439      evas_object_event_callback_add
3440        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, obj);
3441 #ifdef HAVE_ELEMENTARY_X
3442    _elm_win_xwin_update(sd);
3443 #endif
3444 }
3445
3446 EOLIAN static const Evas_Object*
3447 _elm_win_icon_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3448 {
3449    return sd->icon;
3450 }
3451
3452 EOLIAN static void
3453 _elm_win_autodel_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool autodel)
3454 {
3455    sd->autodel = autodel;
3456 }
3457
3458 EOLIAN static Eina_Bool
3459 _elm_win_autodel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3460 {
3461    return sd->autodel;
3462 }
3463
3464 EOLIAN static void
3465 _elm_win_activate(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3466 {
3467    TRAP(sd, activate);
3468 }
3469
3470 EOLIAN static void
3471 _elm_win_lower(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3472 {
3473    TRAP(sd, lower);
3474 }
3475
3476 EOLIAN static void
3477 _elm_win_raise(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3478 {
3479    TRAP(sd, raise);
3480 }
3481
3482 EOLIAN static void
3483 _elm_win_center(Eo *obj, Elm_Win_Data *sd, Eina_Bool h, Eina_Bool v)
3484 {
3485    int win_w, win_h, screen_w, screen_h, nx, ny;
3486
3487    if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj)))
3488      return;
3489
3490    ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &screen_w, &screen_h);
3491    if ((!screen_w) || (!screen_h)) return;
3492
3493    evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
3494    if ((!win_w) || (!win_h)) return;
3495
3496    if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
3497    else nx = sd->screen.x;
3498    if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
3499    else ny = sd->screen.y;
3500    if (nx < 0) nx = 0;
3501    if (ny < 0) ny = 0;
3502
3503    evas_object_move(obj, nx, ny);
3504 }
3505
3506 EOLIAN static void
3507 _elm_win_borderless_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool borderless)
3508 {
3509    Eina_Bool need_frame = EINA_FALSE;
3510
3511    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
3512    need_frame = engine_name &&
3513                 ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
3514                  (!strcmp(engine_name, ELM_WAYLAND_EGL)));
3515
3516    if (borderless)
3517      {
3518         if (need_frame)
3519           _elm_win_frame_del(sd);
3520      }
3521    else
3522      {
3523         if (need_frame)
3524           _elm_win_frame_add(sd, "default");
3525
3526         if (sd->frame_obj)
3527           evas_object_show(sd->frame_obj);
3528      }
3529
3530    TRAP(sd, borderless_set, borderless);
3531 #ifdef HAVE_ELEMENTARY_X
3532    _elm_win_xwin_update(sd);
3533 #endif
3534 }
3535
3536 EOLIAN static Eina_Bool
3537 _elm_win_borderless_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3538 {
3539    return ecore_evas_borderless_get(sd->ee);
3540 }
3541
3542 EOLIAN static void
3543 _elm_win_shaped_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool shaped)
3544 {
3545    TRAP(sd, shaped_set, shaped);
3546 #ifdef HAVE_ELEMENTARY_X
3547    _elm_win_xwin_update(sd);
3548 #endif
3549 }
3550
3551 EOLIAN static Eina_Bool
3552 _elm_win_shaped_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3553 {
3554    return ecore_evas_shaped_get(sd->ee);
3555 }
3556
3557 EOLIAN static void
3558 _elm_win_alpha_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool enabled)
3559 {
3560    if (sd->img_obj)
3561      {
3562         evas_object_image_alpha_set(sd->img_obj, enabled);
3563         ecore_evas_alpha_set(sd->ee, enabled);
3564      }
3565    else
3566      {
3567 #ifdef HAVE_ELEMENTARY_X
3568         if (sd->x.xwin)
3569           {
3570              if (enabled)
3571                {
3572                   if (!ecore_x_screen_is_composited(0))
3573                     elm_win_shaped_set(obj, enabled);
3574                   else
3575                     TRAP(sd, alpha_set, enabled);
3576                }
3577              else
3578                TRAP(sd, alpha_set, enabled);
3579              _elm_win_xwin_update(sd);
3580           }
3581         else
3582 #endif
3583           TRAP(sd, alpha_set, enabled);
3584      }
3585 }
3586
3587 EOLIAN static Eina_Bool
3588 _elm_win_alpha_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3589 {
3590    if (sd->img_obj)
3591      {
3592         return evas_object_image_alpha_get(sd->img_obj);
3593      }
3594    else
3595      {
3596         return ecore_evas_alpha_get(sd->ee);
3597      }
3598
3599    return EINA_FALSE;
3600 }
3601
3602 EOLIAN static void
3603 _elm_win_override_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool override)
3604 {
3605    TRAP(sd, override_set, override);
3606 #ifdef HAVE_ELEMENTARY_X
3607    _elm_win_xwin_update(sd);
3608 #endif
3609 }
3610
3611 EOLIAN static Eina_Bool
3612 _elm_win_override_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3613 {
3614    return ecore_evas_override_get(sd->ee);
3615 }
3616
3617 EOLIAN static void
3618 _elm_win_fullscreen_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool fullscreen)
3619 {
3620    // YYY: handle if sd->img_obj
3621    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3622        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE) || 
3623        ENGINE_COMPARE(ELM_DRM))
3624      {
3625         // these engines... can ONLY be fullscreen
3626         return;
3627      }
3628    else
3629      {
3630 //        sd->fullscreen = fullscreen;
3631
3632         Eina_Bool need_frame = EINA_FALSE;
3633
3634         const char *engine_name = ecore_evas_engine_name_get(sd->ee);
3635         need_frame = engine_name &&
3636                      ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
3637                       (!strcmp(engine_name, ELM_WAYLAND_EGL)));
3638
3639         TRAP(sd, fullscreen_set, fullscreen);
3640
3641         if (fullscreen)
3642           {
3643              if (need_frame)
3644                _elm_win_frame_del(sd);
3645           }
3646         else
3647           {
3648              if (need_frame)
3649                _elm_win_frame_add(sd, "default");
3650
3651              if (sd->frame_obj)
3652                evas_object_show(sd->frame_obj);
3653           }
3654 #ifdef HAVE_ELEMENTARY_X
3655         _elm_win_xwin_update(sd);
3656 #endif
3657      }
3658 }
3659
3660 EOLIAN static Eina_Bool
3661 _elm_win_fullscreen_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3662 {
3663    const char* engine_name = ecore_evas_engine_name_get(sd->ee);
3664
3665    if (engine_name &&
3666        ((!strcmp(engine_name, ELM_SOFTWARE_FB)) ||
3667         (!strcmp(engine_name, ELM_SOFTWARE_16_WINCE)) || 
3668         (!strcmp(engine_name, ELM_DRM))))
3669      {
3670         // these engines... can ONLY be fullscreen
3671         return EINA_TRUE;
3672      }
3673    else
3674      {
3675         return sd->fullscreen;
3676      }
3677
3678    return EINA_FALSE;
3679 }
3680
3681 static void
3682 _dbus_menu_set(Eina_Bool dbus_connect, void *data)
3683 {
3684    ELM_WIN_DATA_GET_OR_RETURN(data, sd);
3685
3686    if (dbus_connect)
3687      {
3688         DBG("Setting menu to D-Bus");
3689         edje_object_part_unswallow(sd->layout, sd->main_menu);
3690         edje_object_signal_emit(sd->layout, "elm,action,hide_menu", "elm");
3691         _elm_menu_menu_bar_hide(sd->main_menu);
3692      }
3693    else
3694      {
3695         DBG("Setting menu to local mode");
3696         edje_object_part_swallow(sd->layout, "elm.swallow.menu", sd->main_menu);
3697         edje_object_signal_emit(sd->layout, "elm,action,show_menu", "elm");
3698         evas_object_show(sd->main_menu);
3699      }
3700 }
3701
3702 EOLIAN static Evas_Object *
3703 _elm_win_main_menu_get(Eo *obj, Elm_Win_Data *sd)
3704 {
3705    Eina_Bool use_dbus = EINA_FALSE;
3706
3707    if (sd->main_menu) goto end;
3708
3709    sd->main_menu = elm_menu_add(obj);
3710    _elm_menu_menu_bar_set(sd->main_menu, EINA_TRUE);
3711
3712 #ifdef HAVE_ELEMENTARY_X
3713    if (!_elm_config->disable_external_menu && sd->x.xwin) use_dbus = EINA_TRUE;
3714 #endif
3715
3716 #ifdef HAVE_ELEMENTARY_X
3717    if (use_dbus && _elm_dbus_menu_register(sd->main_menu))
3718      {
3719         _elm_dbus_menu_app_menu_register(sd->x.xwin, sd->main_menu,
3720                                          _dbus_menu_set, obj);
3721      }
3722    else
3723 #endif
3724      _dbus_menu_set(EINA_FALSE, obj);
3725
3726 end:
3727    return sd->main_menu;
3728 }
3729
3730 EOLIAN static void
3731 _elm_win_maximized_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool maximized)
3732 {
3733    _elm_win_frame_maximized_state_update(sd, maximized);
3734    // YYY: handle if sd->img_obj
3735    TRAP(sd, maximized_set, maximized);
3736 #ifdef HAVE_ELEMENTARY_X
3737    _elm_win_xwin_update(sd);
3738 #endif
3739 }
3740
3741 EOLIAN static Eina_Bool
3742 _elm_win_maximized_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3743 {
3744    return sd->maximized;
3745 }
3746
3747 EOLIAN static void
3748 _elm_win_iconified_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool iconified)
3749 {
3750 //   sd->iconified = iconified;
3751    TRAP(sd, iconified_set, iconified);
3752 #ifdef HAVE_ELEMENTARY_X
3753    _elm_win_xwin_update(sd);
3754 #endif
3755 }
3756
3757 EOLIAN static Eina_Bool
3758 _elm_win_iconified_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3759 {
3760    return sd->iconified;
3761 }
3762
3763 EOLIAN static void
3764 _elm_win_withdrawn_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool withdrawn)
3765 {
3766 //   sd->withdrawn = withdrawn;
3767    TRAP(sd, withdrawn_set, withdrawn);
3768 #ifdef HAVE_ELEMENTARY_X
3769    _elm_win_xwin_update(sd);
3770 #endif
3771 }
3772
3773 EOLIAN static Eina_Bool
3774 _elm_win_withdrawn_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3775 {
3776    return sd->withdrawn;
3777 }
3778
3779 EOLIAN static void
3780 _elm_win_available_profiles_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char **profiles, unsigned int count)
3781 {
3782    Eina_Bool found = EINA_FALSE;
3783
3784    _elm_win_available_profiles_del(sd);
3785    if ((profiles) && (count >= 1))
3786      {
3787         sd->profile.available_list = calloc(count, sizeof(char *));
3788         if (sd->profile.available_list)
3789           {
3790              if (!sd->profile.name) found = EINA_TRUE;
3791
3792              unsigned int i;
3793              for (i = 0; i < count; i++)
3794                {
3795                   sd->profile.available_list[i] = eina_stringshare_add(profiles[i]);
3796
3797                   /* check to see if a given array has a current profile of elm_win */
3798                   if ((sd->profile.name) &&
3799                       (!strcmp(sd->profile.name, profiles[i])))
3800                     {
3801                        found = EINA_TRUE;
3802                     }
3803                }
3804              sd->profile.count = count;
3805           }
3806      }
3807
3808    if (ecore_evas_window_profile_supported_get(sd->ee))
3809      {
3810         ecore_evas_window_available_profiles_set(sd->ee,
3811                                                  sd->profile.available_list,
3812                                                  sd->profile.count);
3813
3814         /* current profile of elm_win is wrong, change profile */
3815         if ((sd->profile.available_list) && (!found))
3816           {
3817              eina_stringshare_replace(&(sd->profile.name),
3818                                       sd->profile.available_list[0]);
3819              ecore_evas_window_profile_set(sd->ee, sd->profile.name);
3820           }
3821
3822      }
3823    else
3824      {
3825         if (sd->profile.available_list)
3826           _elm_win_profile_update(sd);
3827      }
3828 }
3829
3830 EOLIAN static Eina_Bool
3831 _elm_win_available_profiles_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, char ***profiles, unsigned int *count)
3832 {
3833    if (ecore_evas_window_profile_supported_get(sd->ee))
3834      {
3835         return ecore_evas_window_available_profiles_get(sd->ee,
3836                                                        profiles,
3837                                                        count);
3838      }
3839    else
3840      {
3841         if (profiles) *profiles = (char **)sd->profile.available_list;
3842         if (count) *count = sd->profile.count;
3843         return EINA_TRUE;
3844      }
3845 }
3846
3847 EOLIAN static void
3848 _elm_win_profile_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *profile)
3849 {
3850    /* check to see if a given profile is present in an available profiles */
3851    if ((profile) && (sd->profile.available_list))
3852      {
3853         Eina_Bool found = EINA_FALSE;
3854         unsigned int i;
3855         for (i = 0; i < sd->profile.count; i++)
3856           {
3857              if (!strcmp(profile,
3858                          sd->profile.available_list[i]))
3859                {
3860                   found = EINA_TRUE;
3861                   break;
3862                }
3863           }
3864         if (!found) return;
3865      }
3866
3867    if (ecore_evas_window_profile_supported_get(sd->ee))
3868      {
3869         if (!profile) _elm_win_profile_del(sd);
3870         ecore_evas_window_profile_set(sd->ee, profile);
3871      }
3872    else
3873      {
3874         if (_internal_elm_win_profile_set(sd, profile))
3875           _elm_win_profile_update(sd);
3876      }
3877 }
3878
3879 EOLIAN static const char*
3880 _elm_win_profile_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3881 {
3882    return sd->profile.name;
3883 }
3884
3885 EOLIAN static void
3886 _elm_win_urgent_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool urgent)
3887 {
3888    sd->urgent = urgent;
3889    TRAP(sd, urgent_set, urgent);
3890 #ifdef HAVE_ELEMENTARY_X
3891    _elm_win_xwin_update(sd);
3892 #endif
3893 }
3894
3895 EOLIAN static Eina_Bool
3896 _elm_win_urgent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3897 {
3898    return sd->urgent;
3899 }
3900
3901 EOLIAN static void
3902 _elm_win_demand_attention_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool demand_attention)
3903 {
3904    sd->demand_attention = demand_attention;
3905    TRAP(sd, demand_attention_set, demand_attention);
3906 #ifdef HAVE_ELEMENTARY_X
3907    _elm_win_xwin_update(sd);
3908 #endif
3909 }
3910
3911 EOLIAN static Eina_Bool
3912 _elm_win_demand_attention_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3913 {
3914    return sd->demand_attention;
3915 }
3916
3917 EOLIAN static void
3918 _elm_win_modal_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool modal)
3919 {
3920    if (sd->modal_count) return;
3921
3922    const Eina_List *l;
3923    Evas_Object *current;
3924
3925    if ((modal) && (!sd->modal) && (evas_object_visible_get(obj)))
3926      {
3927        INCREMENT_MODALITY()
3928      }
3929    else if ((!modal) && (sd->modal) && (evas_object_visible_get(obj)))
3930      {
3931        DECREMENT_MODALITY()
3932      }
3933
3934    sd->modal = modal;
3935    TRAP(sd, modal_set, modal);
3936 #ifdef HAVE_ELEMENTARY_X
3937    _elm_win_xwin_update(sd);
3938 #endif
3939 }
3940
3941 EOLIAN static Eina_Bool
3942 _elm_win_modal_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3943 {
3944    return sd->modal;
3945 }
3946
3947 EOLIAN static void
3948 _elm_win_aspect_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, double aspect)
3949 {
3950    sd->aspect = aspect;
3951    TRAP(sd, aspect_set, aspect);
3952 #ifdef HAVE_ELEMENTARY_X
3953    _elm_win_xwin_update(sd);
3954 #endif
3955 }
3956
3957 EOLIAN static double
3958 _elm_win_aspect_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3959 {
3960    return sd->aspect;
3961 }
3962
3963 EOLIAN static void
3964 _elm_win_size_base_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
3965 {
3966    sd->size_base_w = w;
3967    sd->size_base_h = h;
3968    TRAP(sd, size_base_set, w, h);
3969 #ifdef HAVE_ELEMENTARY_X
3970    _elm_win_xwin_update(sd);
3971 #endif
3972 }
3973
3974 EOLIAN static void
3975 _elm_win_size_base_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
3976 {
3977    if (w) *w = sd->size_base_w;
3978    if (w) *h = sd->size_base_h;
3979 }
3980
3981 EOLIAN static void
3982 _elm_win_size_step_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
3983 {
3984    sd->size_step_w = w;
3985    sd->size_step_h = h;
3986    TRAP(sd, size_step_set, w, h);
3987 #ifdef HAVE_ELEMENTARY_X
3988    _elm_win_xwin_update(sd);
3989 #endif
3990 }
3991
3992 EOLIAN static void
3993 _elm_win_size_step_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
3994 {
3995    if (w) *w = sd->size_step_w;
3996    if (w) *h = sd->size_step_h;
3997 }
3998
3999 EOLIAN static void
4000 _elm_win_layer_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int layer)
4001 {
4002    TRAP(sd, layer_set, layer);
4003 #ifdef HAVE_ELEMENTARY_X
4004    _elm_win_xwin_update(sd);
4005 #endif
4006 }
4007
4008 EOLIAN static int
4009 _elm_win_layer_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4010 {
4011    return ecore_evas_layer_get(sd->ee);
4012 }
4013
4014 EAPI void
4015 elm_win_norender_push(Evas_Object *obj)
4016 {
4017    ELM_WIN_CHECK(obj);
4018    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4019
4020    sd->norender++;
4021    if (sd->norender == 1) ecore_evas_manual_render_set(sd->ee, EINA_TRUE);
4022 }
4023
4024 EAPI void
4025 elm_win_norender_pop(Evas_Object *obj)
4026 {
4027    ELM_WIN_CHECK(obj);
4028    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4029
4030    if (sd->norender <= 0) return;
4031    sd->norender--;
4032    if (sd->norender == 0) ecore_evas_manual_render_set(sd->ee, EINA_FALSE);
4033 }
4034
4035 EAPI int
4036 elm_win_norender_get(Evas_Object *obj)
4037 {
4038    ELM_WIN_CHECK(obj) - 1;
4039    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4040    return sd->norender;
4041 }
4042
4043 EAPI void
4044 elm_win_render(Evas_Object *obj)
4045 {
4046    ELM_WIN_CHECK(obj);
4047    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4048    ecore_evas_manual_render(sd->ee);
4049 }
4050
4051 static int
4052 _win_rotation_degree_check(int rotation)
4053 {
4054    if ((rotation > 360) || (rotation < 0))
4055      {
4056         WRN("Rotation degree should be 0 ~ 360 (passed degree: %d)", rotation);
4057         rotation %= 360;
4058         if (rotation < 0) rotation += 360;
4059      }
4060    return rotation;
4061 }
4062
4063 /*
4064  * This API resizes the internal window(ex: X window) and evas_output.
4065  * But this does not resize the elm window object and its contents.
4066  */
4067 static void
4068 _win_rotate(Evas_Object *obj, Elm_Win_Data *sd, int rotation, Eina_Bool resize)
4069 {
4070    rotation = _win_rotation_degree_check(rotation);
4071    if (sd->rot == rotation) return;
4072    sd->rot = rotation;
4073    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
4074    else TRAP(sd, rotation_set, rotation);
4075    evas_object_size_hint_min_set(obj, -1, -1);
4076    evas_object_size_hint_max_set(obj, -1, -1);
4077    _elm_win_resize_objects_eval(obj);
4078 #ifdef HAVE_ELEMENTARY_X
4079    _elm_win_xwin_update(sd);
4080 #endif
4081    _elm_win_frame_obj_update(sd);
4082    elm_widget_orientation_set(obj, rotation);
4083    evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
4084 }
4085
4086 EOLIAN static void
4087 _elm_win_rotation_set(Eo *obj, Elm_Win_Data *sd, int rotation)
4088 {
4089    _win_rotate(obj, sd, rotation, EINA_FALSE);
4090 }
4091
4092 /*
4093  * This API does not resize the internal window (ex: X window).
4094  * But this resizes evas_output, elm window, and its contents.
4095  */
4096 EOLIAN static void
4097 _elm_win_rotation_with_resize_set(Eo *obj, Elm_Win_Data *sd, int rotation)
4098 {
4099    _win_rotate(obj, sd, rotation, EINA_TRUE);
4100 }
4101
4102 EOLIAN static int
4103 _elm_win_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4104 {
4105    return sd->rot;
4106 }
4107
4108 EOLIAN static Eina_Bool
4109 _elm_win_wm_rotation_supported_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4110 {
4111    return sd->wm_rot.wm_supported;
4112 }
4113
4114 /* This will unset a preferred rotation, if given preferred rotation is '-1'.
4115  */
4116 EAPI void
4117 elm_win_wm_rotation_preferred_rotation_set(const Evas_Object *obj,
4118                                            int rotation)
4119 {
4120    ELM_WIN_CHECK(obj);
4121    eo_do((Eo *) obj, elm_obj_win_wm_preferred_rotation_set(rotation));
4122 }
4123
4124 EOLIAN static void
4125 _elm_win_wm_preferred_rotation_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int rotation)
4126 {
4127    int rot;
4128
4129    if (!sd->wm_rot.use)
4130      sd->wm_rot.use = EINA_TRUE;
4131
4132    // '-1' means that elm_win doesn't use preferred rotation.
4133    if (rotation == -1)
4134      rot = -1;
4135    else
4136      rot = _win_rotation_degree_check(rotation);
4137
4138    if (sd->wm_rot.preferred_rot == rot) return;
4139    sd->wm_rot.preferred_rot = rot;
4140
4141    ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
4142 }
4143
4144 EOLIAN static int
4145 _elm_win_wm_preferred_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4146 {
4147    return sd->wm_rot.preferred_rot;
4148 }
4149
4150 EOLIAN static void
4151 _elm_win_wm_available_rotations_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const int *rotations, unsigned int count)
4152 {
4153    unsigned int i;
4154    int r;
4155
4156    if (!sd->wm_rot.use)
4157      sd->wm_rot.use = EINA_TRUE;
4158
4159    ELM_SAFE_FREE(sd->wm_rot.rots, free);
4160    sd->wm_rot.count = 0;
4161
4162    if (count > 0)
4163      {
4164         sd->wm_rot.rots = calloc(count, sizeof(int));
4165         if (!sd->wm_rot.rots) return;
4166         for (i = 0; i < count; i++)
4167           {
4168              r = _win_rotation_degree_check(rotations[i]);
4169              sd->wm_rot.rots[i] = r;
4170           }
4171      }
4172
4173    sd->wm_rot.count = count;
4174
4175    ecore_evas_wm_rotation_available_rotations_set(sd->ee,
4176                                                   sd->wm_rot.rots,
4177                                                   sd->wm_rot.count);
4178 }
4179
4180 EOLIAN static Eina_Bool
4181 _elm_win_wm_available_rotations_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int **rotations, unsigned int *count)
4182 {
4183    if (!sd->wm_rot.use) return EINA_FALSE;
4184
4185    if (sd->wm_rot.count > 0)
4186      {
4187         if (rotations)
4188           {
4189              *rotations = calloc(sd->wm_rot.count, sizeof(int));
4190              if (*rotations)
4191                {
4192                   memcpy(*rotations,
4193                          sd->wm_rot.rots,
4194                          sizeof(int) * sd->wm_rot.count);
4195                }
4196           }
4197      }
4198
4199    if (count) *count = sd->wm_rot.count;
4200    return EINA_TRUE;
4201 }
4202
4203 EOLIAN static void
4204 _elm_win_wm_manual_rotation_done_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool set)
4205 {
4206    if (!sd->wm_rot.use) return;
4207    ecore_evas_wm_rotation_manual_rotation_done_set(sd->ee, set);
4208 }
4209
4210 EOLIAN static Eina_Bool
4211 _elm_win_wm_manual_rotation_done_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4212 {
4213    if (!sd->wm_rot.use) return EINA_FALSE;
4214    return ecore_evas_wm_rotation_manual_rotation_done_get(sd->ee);
4215 }
4216
4217 EOLIAN static void
4218 _elm_win_wm_manual_rotation_done(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4219 {
4220    if (!sd->wm_rot.use) return;
4221    ecore_evas_wm_rotation_manual_rotation_done(sd->ee);
4222 }
4223
4224 EOLIAN static void
4225 _elm_win_sticky_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool sticky)
4226 {
4227 //   sd->sticky = sticky;
4228    TRAP(sd, sticky_set, sticky);
4229 #ifdef HAVE_ELEMENTARY_X
4230    _elm_win_xwin_update(sd);
4231 #endif
4232 }
4233
4234 EOLIAN static Eina_Bool
4235 _elm_win_sticky_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4236 {
4237    return sd->sticky;
4238 }
4239
4240 EOLIAN static void
4241 _elm_win_keyboard_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Keyboard_Mode mode)
4242 {
4243    if (mode == sd->kbdmode) return;
4244 #ifdef HAVE_ELEMENTARY_X
4245    _internal_elm_win_xwindow_get(sd);
4246 #endif
4247    sd->kbdmode = mode;
4248 #ifdef HAVE_ELEMENTARY_X
4249    if (sd->x.xwin)
4250      ecore_x_e_virtual_keyboard_state_set
4251        (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
4252 #endif
4253 }
4254
4255 EOLIAN static Elm_Win_Keyboard_Mode
4256 _elm_win_keyboard_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4257 {
4258    return sd->kbdmode;
4259 }
4260
4261 EOLIAN static void
4262 _elm_win_keyboard_win_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool is_keyboard)
4263 {
4264 #ifdef HAVE_ELEMENTARY_X
4265    _internal_elm_win_xwindow_get(sd);
4266    if (sd->x.xwin)
4267      ecore_x_e_virtual_keyboard_set(sd->x.xwin, is_keyboard);
4268 #else
4269    (void)is_keyboard;
4270 #endif
4271 }
4272
4273 EOLIAN static Eina_Bool
4274 _elm_win_keyboard_win_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4275 {
4276 #ifdef HAVE_ELEMENTARY_X
4277    _internal_elm_win_xwindow_get(sd);
4278    if (sd->x.xwin) return ecore_x_e_virtual_keyboard_get(sd->x.xwin);
4279 #endif
4280    return EINA_FALSE;
4281 }
4282
4283 EOLIAN static void
4284 _elm_win_indicator_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Mode mode)
4285 {
4286    if (mode == sd->indmode) return;
4287 #ifdef HAVE_ELEMENTARY_X
4288    _internal_elm_win_xwindow_get(sd);
4289 #endif
4290    sd->indmode = mode;
4291 #ifdef HAVE_ELEMENTARY_X
4292    if (sd->x.xwin)
4293      {
4294         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
4295           ecore_x_e_illume_indicator_state_set
4296             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
4297         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
4298           ecore_x_e_illume_indicator_state_set
4299             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
4300      }
4301 #endif
4302    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4303 }
4304
4305 EOLIAN static Elm_Win_Indicator_Mode
4306 _elm_win_indicator_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4307 {
4308    return sd->indmode;
4309 }
4310
4311 EOLIAN static void
4312 _elm_win_indicator_opacity_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Opacity_Mode mode)
4313 {
4314    if (mode == sd->ind_o_mode) return;
4315    sd->ind_o_mode = mode;
4316 #ifdef HAVE_ELEMENTARY_X
4317    _internal_elm_win_xwindow_get(sd);
4318    if (sd->x.xwin)
4319      {
4320         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
4321           ecore_x_e_illume_indicator_opacity_set
4322             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_OPAQUE);
4323         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
4324           ecore_x_e_illume_indicator_opacity_set
4325             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
4326         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
4327           ecore_x_e_illume_indicator_opacity_set
4328             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
4329      }
4330 #endif
4331    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4332 }
4333
4334 EOLIAN static Elm_Win_Indicator_Opacity_Mode
4335 _elm_win_indicator_opacity_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4336 {
4337    return sd->ind_o_mode;
4338 }
4339
4340 EOLIAN static void
4341 _elm_win_screen_position_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y)
4342 {
4343    if (x) *x = sd->screen.x;
4344    if (y) *y = sd->screen.y;
4345 }
4346
4347 EOLIAN static Eina_Bool
4348 _elm_win_focus_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4349 {
4350    return ecore_evas_focus_get(sd->ee);
4351 }
4352
4353 EOLIAN static void
4354 _elm_win_screen_constrain_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool constrain)
4355 {
4356    sd->constrain = !!constrain;
4357 }
4358
4359 EOLIAN static Eina_Bool
4360 _elm_win_screen_constrain_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4361 {
4362    return sd->constrain;
4363 }
4364
4365 EOLIAN static void
4366 _elm_win_screen_size_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y, int *w, int *h)
4367 {
4368    ecore_evas_screen_geometry_get(sd->ee, x, y, w, h);
4369 }
4370
4371 EOLIAN static void
4372 _elm_win_screen_dpi_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *xdpi, int *ydpi)
4373 {
4374    ecore_evas_screen_dpi_get(sd->ee, xdpi, ydpi);
4375 }
4376
4377 EOLIAN static void
4378 _elm_win_conformant_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool conformant)
4379 {
4380 #ifdef HAVE_ELEMENTARY_X
4381    _internal_elm_win_xwindow_get(sd);
4382    if (sd->x.xwin)
4383      ecore_x_e_illume_conformant_set(sd->x.xwin, conformant);
4384 #else
4385    (void)conformant;
4386 #endif
4387 }
4388
4389 EOLIAN static Eina_Bool
4390 _elm_win_conformant_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4391 {
4392 #ifdef HAVE_ELEMENTARY_X
4393    _internal_elm_win_xwindow_get(sd);
4394    if (sd->x.xwin)
4395      return ecore_x_e_illume_conformant_get(sd->x.xwin);
4396 #endif
4397
4398    return EINA_FALSE;
4399 }
4400
4401 EOLIAN static void
4402 _elm_win_quickpanel_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool quickpanel)
4403 {
4404 #ifdef HAVE_ELEMENTARY_X
4405    _internal_elm_win_xwindow_get(sd);
4406    if (sd->x.xwin)
4407      {
4408         ecore_x_e_illume_quickpanel_set(sd->x.xwin, quickpanel);
4409         if (quickpanel)
4410           {
4411              Ecore_X_Window_State states[2];
4412
4413              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
4414              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
4415              ecore_x_netwm_window_state_set(sd->x.xwin, states, 2);
4416              ecore_x_icccm_hints_set(sd->x.xwin, 0, 0, 0, 0, 0, 0, 0);
4417           }
4418      }
4419 #else
4420    (void)quickpanel;
4421 #endif
4422 }
4423
4424 EOLIAN static Eina_Bool
4425 _elm_win_quickpanel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4426 {
4427 #ifdef HAVE_ELEMENTARY_X
4428    _internal_elm_win_xwindow_get(sd);
4429    if (sd->x.xwin)
4430      return ecore_x_e_illume_quickpanel_get(sd->x.xwin);
4431 #endif
4432
4433    return EINA_FALSE;
4434 }
4435
4436 EOLIAN static void
4437 _elm_win_quickpanel_priority_major_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
4438 {
4439 #ifdef HAVE_ELEMENTARY_X
4440    _internal_elm_win_xwindow_get(sd);
4441    if (sd->x.xwin)
4442      ecore_x_e_illume_quickpanel_priority_major_set(sd->x.xwin, priority);
4443 #else
4444    (void)priority;
4445 #endif
4446 }
4447
4448 EOLIAN static int
4449 _elm_win_quickpanel_priority_major_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4450 {
4451 #ifdef HAVE_ELEMENTARY_X
4452    _internal_elm_win_xwindow_get(sd);
4453    if (sd->x.xwin)
4454      return ecore_x_e_illume_quickpanel_priority_major_get(sd->x.xwin);
4455 #endif
4456
4457    return -1;
4458 }
4459
4460 EOLIAN static void
4461 _elm_win_quickpanel_priority_minor_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
4462 {
4463 #ifdef HAVE_ELEMENTARY_X
4464    _internal_elm_win_xwindow_get(sd);
4465    if (sd->x.xwin)
4466      ecore_x_e_illume_quickpanel_priority_minor_set(sd->x.xwin, priority);
4467 #else
4468    (void)priority;
4469 #endif
4470 }
4471
4472 EOLIAN static int
4473 _elm_win_quickpanel_priority_minor_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4474 {
4475 #ifdef HAVE_ELEMENTARY_X
4476    _internal_elm_win_xwindow_get(sd);
4477    if (sd->x.xwin)
4478      return ecore_x_e_illume_quickpanel_priority_minor_get(sd->x.xwin);
4479 #endif
4480
4481    return -1;
4482 }
4483
4484 EOLIAN static void
4485 _elm_win_quickpanel_zone_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int zone)
4486 {
4487 #ifdef HAVE_ELEMENTARY_X
4488    _internal_elm_win_xwindow_get(sd);
4489    if (sd->x.xwin)
4490      ecore_x_e_illume_quickpanel_zone_set(sd->x.xwin, zone);
4491 #else
4492    (void)zone;
4493 #endif
4494 }
4495
4496 EOLIAN static int
4497 _elm_win_quickpanel_zone_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4498 {
4499 #ifdef HAVE_ELEMENTARY_X
4500    _internal_elm_win_xwindow_get(sd);
4501    if (sd->x.xwin)
4502      return ecore_x_e_illume_quickpanel_zone_get(sd->x.xwin);
4503 #endif
4504
4505    return 0;
4506 }
4507
4508 EOLIAN static void
4509 _elm_win_prop_focus_skip_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool skip)
4510 {
4511    sd->skip_focus = skip;
4512    TRAP(sd, focus_skip_set, skip);
4513 }
4514
4515 EOLIAN static void
4516 _elm_win_illume_command_send(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Illume_Command command, void *params)
4517 {
4518    (void) params;
4519
4520 #ifdef HAVE_ELEMENTARY_X
4521    _internal_elm_win_xwindow_get(sd);
4522    if (sd->x.xwin)
4523      {
4524         switch (command)
4525           {
4526            case ELM_ILLUME_COMMAND_FOCUS_BACK:
4527              ecore_x_e_illume_focus_back_send(sd->x.xwin);
4528              break;
4529
4530            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
4531              ecore_x_e_illume_focus_forward_send(sd->x.xwin);
4532              break;
4533
4534            case ELM_ILLUME_COMMAND_FOCUS_HOME:
4535              ecore_x_e_illume_focus_home_send(sd->x.xwin);
4536              break;
4537
4538            case ELM_ILLUME_COMMAND_CLOSE:
4539              ecore_x_e_illume_close_send(sd->x.xwin);
4540              break;
4541
4542            default:
4543              break;
4544           }
4545      }
4546 #else
4547    (void)command;
4548 #endif
4549 }
4550
4551 EOLIAN static Evas_Object*
4552 _elm_win_inlined_image_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4553 {
4554    return sd->img_obj;
4555 }
4556
4557 EOLIAN static void
4558 _elm_win_focus_highlight_enabled_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool enabled)
4559 {
4560    enabled = !!enabled;
4561    if (sd->focus_highlight.enabled == enabled)
4562      return;
4563
4564    sd->focus_highlight.enabled = enabled;
4565
4566    if (sd->focus_highlight.enabled)
4567      _elm_win_focus_highlight_init(sd);
4568    else
4569      _elm_win_focus_highlight_shutdown(sd);
4570 }
4571
4572 EOLIAN static Eina_Bool
4573 _elm_win_focus_highlight_enabled_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4574 {
4575    return sd->focus_highlight.enabled;
4576 }
4577
4578 EOLIAN static Eina_Bool
4579 _elm_win_elm_widget_theme_apply(Eo *obj, Elm_Win_Data *sd)
4580 {
4581    Eina_Bool int_ret = EINA_FALSE;
4582    eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
4583    if (!int_ret) return EINA_TRUE;
4584
4585    sd->focus_highlight.theme_changed = EINA_TRUE;
4586    _elm_win_focus_highlight_reconfigure_job_start(sd);
4587
4588    return EINA_TRUE;
4589 }
4590
4591 EOLIAN static void
4592 _elm_win_focus_highlight_style_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *style)
4593 {
4594    eina_stringshare_replace(&sd->focus_highlight.style, style);
4595    sd->focus_highlight.theme_changed = EINA_TRUE;
4596    _elm_win_focus_highlight_reconfigure_job_start(sd);
4597 }
4598
4599 EOLIAN static const char*
4600 _elm_win_focus_highlight_style_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4601 {
4602    return sd->focus_highlight.style;
4603 }
4604
4605 EOLIAN static void
4606 _elm_win_focus_highlight_animate_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool animate)
4607 {
4608    animate = !!animate;
4609    if (sd->focus_highlight.animate == animate)
4610      return;
4611
4612    sd->focus_highlight.animate = animate;
4613    sd->focus_highlight.theme_changed = EINA_TRUE;
4614    _elm_win_focus_highlight_reconfigure_job_start(sd);
4615 }
4616
4617 EOLIAN static Eina_Bool
4618 _elm_win_focus_highlight_animate_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4619 {
4620    return sd->focus_highlight.animate;
4621 }
4622
4623 EOLIAN static Eina_Bool
4624 _elm_win_socket_listen(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *svcname, int svcnum, Eina_Bool svcsys)
4625 {
4626    if (!sd->ee) return EINA_FALSE;
4627
4628    if (!ecore_evas_extn_socket_listen(sd->ee, svcname, svcnum, svcsys))
4629      return EINA_FALSE;
4630
4631    return EINA_TRUE;
4632 }
4633
4634 /* windowing specific calls - shall we do this differently? */
4635
4636 EOLIAN static Ecore_X_Window
4637 _elm_win_xwindow_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4638 {
4639 #ifdef HAVE_ELEMENTARY_X
4640    if (sd->x.xwin) return sd->x.xwin;
4641    if (sd->parent) return elm_win_xwindow_get(sd->parent);
4642 #endif
4643    return 0;
4644 }
4645
4646 EAPI Ecore_Wl_Window *
4647 elm_win_wl_window_get(const Evas_Object *obj)
4648 {
4649    if (!obj) return NULL;
4650
4651    if ((!ENGINE_COMPARE(ELM_WAYLAND_SHM)) &&
4652        (!ENGINE_COMPARE(ELM_WAYLAND_EGL)))
4653      return NULL;
4654
4655    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
4656      {
4657         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4658         return _elm_ee_wlwin_get(ee);
4659      }
4660
4661    ELM_WIN_CHECK(obj) NULL;
4662    Ecore_Wl_Window *ret = NULL;
4663    eo_do((Eo *) obj, ret = elm_obj_win_wl_window_get());
4664    return ret;
4665 }
4666
4667 EOLIAN static Ecore_Wl_Window*
4668 _elm_win_wl_window_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4669 {
4670 #if HAVE_ELEMENTARY_WAYLAND
4671    if (sd->wl.win) return sd->wl.win;
4672    if (sd->parent) return elm_win_wl_window_get(sd->parent);
4673 #else
4674    (void)sd;
4675 #endif
4676    return NULL;
4677 }
4678
4679 EAPI Eina_Bool
4680 elm_win_trap_set(const Elm_Win_Trap *t)
4681 {
4682    DBG("old %p, new %p", trap, t);
4683
4684    if ((t) && (t->version != ELM_WIN_TRAP_VERSION))
4685      {
4686         CRI("trying to set a trap version %lu while %lu was expected!",
4687                  t->version, ELM_WIN_TRAP_VERSION);
4688         return EINA_FALSE;
4689      }
4690
4691    trap = t;
4692    return EINA_TRUE;
4693 }
4694
4695 EAPI void
4696 elm_win_floating_mode_set(Evas_Object *obj, Eina_Bool floating)
4697 {
4698    ELM_WIN_CHECK(obj);
4699    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4700
4701    floating = !!floating;
4702    if (floating == sd->floating) return;
4703    sd->floating = floating;
4704 #ifdef HAVE_ELEMENTARY_X
4705    _internal_elm_win_xwindow_get(sd);
4706    if (sd->x.xwin)
4707      {
4708         if (sd->floating)
4709           ecore_x_e_illume_window_state_set
4710              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_FLOATING);
4711         else
4712           ecore_x_e_illume_window_state_set
4713              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_NORMAL);
4714      }
4715 #endif
4716 }
4717
4718 EAPI Eina_Bool
4719 elm_win_floating_mode_get(const Evas_Object *obj)
4720 {
4721    ELM_WIN_CHECK(obj) EINA_FALSE;
4722    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4723
4724    return sd->floating;
4725 }
4726
4727 EOLIAN static Ecore_Window
4728 _elm_win_window_id_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4729 {
4730    if ((ENGINE_COMPARE(ELM_WAYLAND_SHM)) || (ENGINE_COMPARE(ELM_WAYLAND_EGL)))
4731      {
4732 #if HAVE_ELEMENTARY_WAYLAND
4733         if (sd->wl.win) return (Ecore_Window)ecore_wl_window_surface_id_get(sd->wl.win);
4734         if (sd->parent)
4735           {
4736              Ecore_Wl_Window *parent;
4737
4738              parent = elm_win_wl_window_get(sd->parent);
4739              if (parent) return (Ecore_Window)ecore_wl_window_surface_id_get(parent);
4740              return 0;
4741           }
4742 #endif
4743      }
4744    else
4745      {
4746 #ifdef HAVE_ELEMENTARY_X
4747         _internal_elm_win_xwindow_get(sd);
4748         if (sd->x.xwin) return (Ecore_Window)sd->x.xwin;
4749         if (sd->parent) return (Ecore_Window)elm_win_xwindow_get(sd->parent);
4750 #endif
4751      }
4752
4753    return 0;
4754 }
4755
4756 void
4757 _elm_win_focus_highlight_start(Evas_Object *obj)
4758 {
4759    ELM_WIN_DATA_GET(obj, sd);
4760
4761    if (!elm_win_focus_highlight_enabled_get(obj)) return;
4762    sd->focus_highlight.cur.visible = EINA_TRUE;
4763    sd->focus_highlight.geometry_changed = EINA_TRUE;
4764    _elm_win_focus_highlight_reconfigure_job(obj);
4765 }
4766
4767 EAPI Ecore_Window
4768 elm_win_window_id_get(const Evas_Object *obj)
4769 {
4770    if (!obj) return 0;
4771
4772    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
4773      {
4774         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4775         return ecore_evas_window_get(ee);
4776      }
4777
4778    ELM_WIN_CHECK(obj) 0;
4779    Ecore_Window ret = 0;
4780    eo_do((Eo *) obj, ret = elm_obj_win_window_id_get());
4781    return ret;
4782 }
4783
4784 EOLIAN static void
4785 _elm_win_class_constructor(Eo_Class *klass)
4786 {
4787    evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
4788 }
4789
4790 EOLIAN static Eo*
4791 _elm_win_elm_interface_atspi_accessible_parent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd EINA_UNUSED)
4792 {
4793    // attach all kinds of windows directly to ATSPI application root object
4794    return _elm_atspi_root_get();
4795 }
4796
4797 #include "elm_win.eo.c"