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