win: fix borderless_set behavior
[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_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_object_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_object_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_object_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_object_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_object_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_object_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 (need_frame)
3533      need_frame = !sd->fullscreen;
3534
3535    if (borderless)
3536      {
3537         if (need_frame)
3538           _elm_win_frame_del(sd);
3539      }
3540    else
3541      {
3542         if (need_frame)
3543           _elm_win_frame_add(sd, "default");
3544
3545         if (sd->frame_obj)
3546           evas_object_show(sd->frame_obj);
3547      }
3548
3549    TRAP(sd, borderless_set, borderless);
3550 #ifdef HAVE_ELEMENTARY_X
3551    _elm_win_xwin_update(sd);
3552 #endif
3553 }
3554
3555 EOLIAN static Eina_Bool
3556 _elm_win_borderless_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3557 {
3558    return ecore_evas_borderless_get(sd->ee);
3559 }
3560
3561 EOLIAN static void
3562 _elm_win_shaped_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool shaped)
3563 {
3564    TRAP(sd, shaped_set, shaped);
3565 #ifdef HAVE_ELEMENTARY_X
3566    _elm_win_xwin_update(sd);
3567 #endif
3568 }
3569
3570 EOLIAN static Eina_Bool
3571 _elm_win_shaped_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3572 {
3573    return ecore_evas_shaped_get(sd->ee);
3574 }
3575
3576 EOLIAN static void
3577 _elm_win_alpha_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool enabled)
3578 {
3579    if (sd->img_obj)
3580      {
3581         evas_object_image_alpha_set(sd->img_obj, enabled);
3582         ecore_evas_alpha_set(sd->ee, enabled);
3583      }
3584    else
3585      {
3586 #ifdef HAVE_ELEMENTARY_X
3587         if (sd->x.xwin)
3588           {
3589              if (enabled)
3590                {
3591                   if (!ecore_x_screen_is_composited(0))
3592                     elm_win_shaped_set(obj, enabled);
3593                   else
3594                     TRAP(sd, alpha_set, enabled);
3595                }
3596              else
3597                TRAP(sd, alpha_set, enabled);
3598              _elm_win_xwin_update(sd);
3599           }
3600         else
3601 #endif
3602           TRAP(sd, alpha_set, enabled);
3603      }
3604 }
3605
3606 EOLIAN static Eina_Bool
3607 _elm_win_alpha_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3608 {
3609    if (sd->img_obj)
3610      {
3611         return evas_object_image_alpha_get(sd->img_obj);
3612      }
3613    else
3614      {
3615         return ecore_evas_alpha_get(sd->ee);
3616      }
3617
3618    return EINA_FALSE;
3619 }
3620
3621 EOLIAN static void
3622 _elm_win_override_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool override)
3623 {
3624    TRAP(sd, override_set, override);
3625 #ifdef HAVE_ELEMENTARY_X
3626    _elm_win_xwin_update(sd);
3627 #endif
3628 }
3629
3630 EOLIAN static Eina_Bool
3631 _elm_win_override_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3632 {
3633    return ecore_evas_override_get(sd->ee);
3634 }
3635
3636 EOLIAN static void
3637 _elm_win_fullscreen_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool fullscreen)
3638 {
3639    // YYY: handle if sd->img_obj
3640    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3641        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE) || 
3642        ENGINE_COMPARE(ELM_DRM))
3643      {
3644         // these engines... can ONLY be fullscreen
3645         return;
3646      }
3647    else
3648      {
3649 //        sd->fullscreen = fullscreen;
3650
3651         Eina_Bool need_frame = EINA_FALSE;
3652
3653         const char *engine_name = ecore_evas_engine_name_get(sd->ee);
3654         need_frame = engine_name &&
3655                      ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
3656                       (!strcmp(engine_name, ELM_WAYLAND_EGL)));
3657
3658         if (need_frame)
3659           need_frame = !ecore_evas_borderless_get(sd->ee);
3660
3661         TRAP(sd, fullscreen_set, fullscreen);
3662
3663         if (fullscreen)
3664           {
3665              if (need_frame)
3666                _elm_win_frame_del(sd);
3667           }
3668         else
3669           {
3670              if (need_frame)
3671                _elm_win_frame_add(sd, "default");
3672
3673              if (sd->frame_obj)
3674                evas_object_show(sd->frame_obj);
3675           }
3676 #ifdef HAVE_ELEMENTARY_X
3677         _elm_win_xwin_update(sd);
3678 #endif
3679      }
3680 }
3681
3682 EOLIAN static Eina_Bool
3683 _elm_win_fullscreen_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3684 {
3685    const char* engine_name = ecore_evas_engine_name_get(sd->ee);
3686
3687    if (engine_name &&
3688        ((!strcmp(engine_name, ELM_SOFTWARE_FB)) ||
3689         (!strcmp(engine_name, ELM_SOFTWARE_16_WINCE)) || 
3690         (!strcmp(engine_name, ELM_DRM))))
3691      {
3692         // these engines... can ONLY be fullscreen
3693         return EINA_TRUE;
3694      }
3695    else
3696      {
3697         return sd->fullscreen;
3698      }
3699
3700    return EINA_FALSE;
3701 }
3702
3703 static void
3704 _dbus_menu_set(Eina_Bool dbus_connect, void *data)
3705 {
3706    ELM_WIN_DATA_GET_OR_RETURN(data, sd);
3707
3708    if (dbus_connect)
3709      {
3710         DBG("Setting menu to D-Bus");
3711         edje_object_part_unswallow(sd->layout, sd->main_menu);
3712         edje_object_signal_emit(sd->layout, "elm,action,hide_menu", "elm");
3713         _elm_menu_menu_bar_hide(sd->main_menu);
3714      }
3715    else
3716      {
3717         DBG("Setting menu to local mode");
3718         edje_object_part_swallow(sd->layout, "elm.swallow.menu", sd->main_menu);
3719         edje_object_signal_emit(sd->layout, "elm,action,show_menu", "elm");
3720         evas_object_show(sd->main_menu);
3721      }
3722 }
3723
3724 EOLIAN static Evas_Object *
3725 _elm_win_main_menu_get(Eo *obj, Elm_Win_Data *sd)
3726 {
3727    Eina_Bool use_dbus = EINA_FALSE;
3728
3729    if (sd->main_menu) goto end;
3730
3731    sd->main_menu = elm_menu_add(obj);
3732    _elm_menu_menu_bar_set(sd->main_menu, EINA_TRUE);
3733
3734 #ifdef HAVE_ELEMENTARY_X
3735    if (!_elm_config->disable_external_menu && sd->x.xwin) use_dbus = EINA_TRUE;
3736 #endif
3737
3738 #ifdef HAVE_ELEMENTARY_X
3739    if (use_dbus && _elm_dbus_menu_register(sd->main_menu))
3740      {
3741         _elm_dbus_menu_app_menu_register(sd->x.xwin, sd->main_menu,
3742                                          _dbus_menu_set, obj);
3743      }
3744    else
3745 #endif
3746      _dbus_menu_set(EINA_FALSE, obj);
3747
3748 end:
3749    return sd->main_menu;
3750 }
3751
3752 EOLIAN static void
3753 _elm_win_maximized_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool maximized)
3754 {
3755    _elm_win_frame_maximized_state_update(sd, maximized);
3756    // YYY: handle if sd->img_obj
3757    TRAP(sd, maximized_set, maximized);
3758 #ifdef HAVE_ELEMENTARY_X
3759    _elm_win_xwin_update(sd);
3760 #endif
3761 }
3762
3763 EOLIAN static Eina_Bool
3764 _elm_win_maximized_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3765 {
3766    return sd->maximized;
3767 }
3768
3769 EOLIAN static void
3770 _elm_win_iconified_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool iconified)
3771 {
3772 //   sd->iconified = iconified;
3773    TRAP(sd, iconified_set, iconified);
3774 #ifdef HAVE_ELEMENTARY_X
3775    _elm_win_xwin_update(sd);
3776 #endif
3777 }
3778
3779 EOLIAN static Eina_Bool
3780 _elm_win_iconified_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3781 {
3782    return sd->iconified;
3783 }
3784
3785 EOLIAN static void
3786 _elm_win_withdrawn_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool withdrawn)
3787 {
3788 //   sd->withdrawn = withdrawn;
3789    TRAP(sd, withdrawn_set, withdrawn);
3790 #ifdef HAVE_ELEMENTARY_X
3791    _elm_win_xwin_update(sd);
3792 #endif
3793 }
3794
3795 EOLIAN static Eina_Bool
3796 _elm_win_withdrawn_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3797 {
3798    return sd->withdrawn;
3799 }
3800
3801 EOLIAN static void
3802 _elm_win_available_profiles_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char **profiles, unsigned int count)
3803 {
3804    Eina_Bool found = EINA_FALSE;
3805
3806    _elm_win_available_profiles_del(sd);
3807    if ((profiles) && (count >= 1))
3808      {
3809         sd->profile.available_list = calloc(count, sizeof(char *));
3810         if (sd->profile.available_list)
3811           {
3812              if (!sd->profile.name) found = EINA_TRUE;
3813
3814              unsigned int i;
3815              for (i = 0; i < count; i++)
3816                {
3817                   sd->profile.available_list[i] = eina_stringshare_add(profiles[i]);
3818
3819                   /* check to see if a given array has a current profile of elm_win */
3820                   if ((sd->profile.name) &&
3821                       (!strcmp(sd->profile.name, profiles[i])))
3822                     {
3823                        found = EINA_TRUE;
3824                     }
3825                }
3826              sd->profile.count = count;
3827           }
3828      }
3829
3830    if (ecore_evas_window_profile_supported_get(sd->ee))
3831      {
3832         ecore_evas_window_available_profiles_set(sd->ee,
3833                                                  sd->profile.available_list,
3834                                                  sd->profile.count);
3835
3836         /* current profile of elm_win is wrong, change profile */
3837         if ((sd->profile.available_list) && (!found))
3838           {
3839              eina_stringshare_replace(&(sd->profile.name),
3840                                       sd->profile.available_list[0]);
3841              ecore_evas_window_profile_set(sd->ee, sd->profile.name);
3842           }
3843
3844      }
3845    else
3846      {
3847         if (sd->profile.available_list)
3848           _elm_win_profile_update(sd);
3849      }
3850 }
3851
3852 EOLIAN static Eina_Bool
3853 _elm_win_available_profiles_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, char ***profiles, unsigned int *count)
3854 {
3855    if (ecore_evas_window_profile_supported_get(sd->ee))
3856      {
3857         return ecore_evas_window_available_profiles_get(sd->ee,
3858                                                        profiles,
3859                                                        count);
3860      }
3861    else
3862      {
3863         if (profiles) *profiles = (char **)sd->profile.available_list;
3864         if (count) *count = sd->profile.count;
3865         return EINA_TRUE;
3866      }
3867 }
3868
3869 EOLIAN static void
3870 _elm_win_profile_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *profile)
3871 {
3872    /* check to see if a given profile is present in an available profiles */
3873    if ((profile) && (sd->profile.available_list))
3874      {
3875         Eina_Bool found = EINA_FALSE;
3876         unsigned int i;
3877         for (i = 0; i < sd->profile.count; i++)
3878           {
3879              if (!strcmp(profile,
3880                          sd->profile.available_list[i]))
3881                {
3882                   found = EINA_TRUE;
3883                   break;
3884                }
3885           }
3886         if (!found) return;
3887      }
3888
3889    if (ecore_evas_window_profile_supported_get(sd->ee))
3890      {
3891         if (!profile) _elm_win_profile_del(sd);
3892         ecore_evas_window_profile_set(sd->ee, profile);
3893      }
3894    else
3895      {
3896         if (_internal_elm_win_profile_set(sd, profile))
3897           _elm_win_profile_update(sd);
3898      }
3899 }
3900
3901 EOLIAN static const char*
3902 _elm_win_profile_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3903 {
3904    return sd->profile.name;
3905 }
3906
3907 EOLIAN static void
3908 _elm_win_urgent_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool urgent)
3909 {
3910    sd->urgent = urgent;
3911    TRAP(sd, urgent_set, urgent);
3912 #ifdef HAVE_ELEMENTARY_X
3913    _elm_win_xwin_update(sd);
3914 #endif
3915 }
3916
3917 EOLIAN static Eina_Bool
3918 _elm_win_urgent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3919 {
3920    return sd->urgent;
3921 }
3922
3923 EOLIAN static void
3924 _elm_win_demand_attention_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool demand_attention)
3925 {
3926    sd->demand_attention = demand_attention;
3927    TRAP(sd, demand_attention_set, demand_attention);
3928 #ifdef HAVE_ELEMENTARY_X
3929    _elm_win_xwin_update(sd);
3930 #endif
3931 }
3932
3933 EOLIAN static Eina_Bool
3934 _elm_win_demand_attention_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3935 {
3936    return sd->demand_attention;
3937 }
3938
3939 EOLIAN static void
3940 _elm_win_modal_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool modal)
3941 {
3942    if (sd->modal_count) return;
3943
3944    const Eina_List *l;
3945    Evas_Object *current;
3946
3947    if ((modal) && (!sd->modal) && (evas_object_visible_get(obj)))
3948      {
3949        INCREMENT_MODALITY()
3950      }
3951    else if ((!modal) && (sd->modal) && (evas_object_visible_get(obj)))
3952      {
3953        DECREMENT_MODALITY()
3954      }
3955
3956    sd->modal = modal;
3957    TRAP(sd, modal_set, modal);
3958 #ifdef HAVE_ELEMENTARY_X
3959    _elm_win_xwin_update(sd);
3960 #endif
3961 }
3962
3963 EOLIAN static Eina_Bool
3964 _elm_win_modal_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3965 {
3966    return sd->modal;
3967 }
3968
3969 EOLIAN static void
3970 _elm_win_aspect_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, double aspect)
3971 {
3972    sd->aspect = aspect;
3973    TRAP(sd, aspect_set, aspect);
3974 #ifdef HAVE_ELEMENTARY_X
3975    _elm_win_xwin_update(sd);
3976 #endif
3977 }
3978
3979 EOLIAN static double
3980 _elm_win_aspect_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3981 {
3982    return sd->aspect;
3983 }
3984
3985 EOLIAN static void
3986 _elm_win_size_base_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
3987 {
3988    sd->size_base_w = w;
3989    sd->size_base_h = h;
3990    TRAP(sd, size_base_set, w, h);
3991 #ifdef HAVE_ELEMENTARY_X
3992    _elm_win_xwin_update(sd);
3993 #endif
3994 }
3995
3996 EOLIAN static void
3997 _elm_win_size_base_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
3998 {
3999    if (w) *w = sd->size_base_w;
4000    if (w) *h = sd->size_base_h;
4001 }
4002
4003 EOLIAN static void
4004 _elm_win_size_step_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
4005 {
4006    sd->size_step_w = w;
4007    sd->size_step_h = h;
4008    TRAP(sd, size_step_set, w, h);
4009 #ifdef HAVE_ELEMENTARY_X
4010    _elm_win_xwin_update(sd);
4011 #endif
4012 }
4013
4014 EOLIAN static void
4015 _elm_win_size_step_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
4016 {
4017    if (w) *w = sd->size_step_w;
4018    if (w) *h = sd->size_step_h;
4019 }
4020
4021 EOLIAN static void
4022 _elm_win_layer_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int layer)
4023 {
4024    TRAP(sd, layer_set, layer);
4025 #ifdef HAVE_ELEMENTARY_X
4026    _elm_win_xwin_update(sd);
4027 #endif
4028 }
4029
4030 EOLIAN static int
4031 _elm_win_layer_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4032 {
4033    return ecore_evas_layer_get(sd->ee);
4034 }
4035
4036 EAPI void
4037 elm_win_norender_push(Evas_Object *obj)
4038 {
4039    ELM_WIN_CHECK(obj);
4040    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4041
4042    sd->norender++;
4043    if (sd->norender == 1) ecore_evas_manual_render_set(sd->ee, EINA_TRUE);
4044 }
4045
4046 EAPI void
4047 elm_win_norender_pop(Evas_Object *obj)
4048 {
4049    ELM_WIN_CHECK(obj);
4050    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4051
4052    if (sd->norender <= 0) return;
4053    sd->norender--;
4054    if (sd->norender == 0) ecore_evas_manual_render_set(sd->ee, EINA_FALSE);
4055 }
4056
4057 EAPI int
4058 elm_win_norender_get(Evas_Object *obj)
4059 {
4060    ELM_WIN_CHECK(obj) - 1;
4061    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4062    return sd->norender;
4063 }
4064
4065 EAPI void
4066 elm_win_render(Evas_Object *obj)
4067 {
4068    ELM_WIN_CHECK(obj);
4069    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4070    ecore_evas_manual_render(sd->ee);
4071 }
4072
4073 static int
4074 _win_rotation_degree_check(int rotation)
4075 {
4076    if ((rotation > 360) || (rotation < 0))
4077      {
4078         WRN("Rotation degree should be 0 ~ 360 (passed degree: %d)", rotation);
4079         rotation %= 360;
4080         if (rotation < 0) rotation += 360;
4081      }
4082    return rotation;
4083 }
4084
4085 /*
4086  * This API resizes the internal window(ex: X window) and evas_output.
4087  * But this does not resize the elm window object and its contents.
4088  */
4089 static void
4090 _win_rotate(Evas_Object *obj, Elm_Win_Data *sd, int rotation, Eina_Bool resize)
4091 {
4092    rotation = _win_rotation_degree_check(rotation);
4093    if (sd->rot == rotation) return;
4094    sd->rot = rotation;
4095    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
4096    else TRAP(sd, rotation_set, rotation);
4097    evas_object_size_hint_min_set(obj, -1, -1);
4098    evas_object_size_hint_max_set(obj, -1, -1);
4099    _elm_win_resize_objects_eval(obj);
4100 #ifdef HAVE_ELEMENTARY_X
4101    _elm_win_xwin_update(sd);
4102 #endif
4103    _elm_win_frame_obj_update(sd);
4104    elm_widget_orientation_set(obj, rotation);
4105    evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
4106 }
4107
4108 EOLIAN static void
4109 _elm_win_rotation_set(Eo *obj, Elm_Win_Data *sd, int rotation)
4110 {
4111    _win_rotate(obj, sd, rotation, EINA_FALSE);
4112 }
4113
4114 /*
4115  * This API does not resize the internal window (ex: X window).
4116  * But this resizes evas_output, elm window, and its contents.
4117  */
4118 EOLIAN static void
4119 _elm_win_rotation_with_resize_set(Eo *obj, Elm_Win_Data *sd, int rotation)
4120 {
4121    _win_rotate(obj, sd, rotation, EINA_TRUE);
4122 }
4123
4124 EOLIAN static int
4125 _elm_win_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4126 {
4127    return sd->rot;
4128 }
4129
4130 EOLIAN static Eina_Bool
4131 _elm_win_wm_rotation_supported_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4132 {
4133    return sd->wm_rot.wm_supported;
4134 }
4135
4136 /* This will unset a preferred rotation, if given preferred rotation is '-1'.
4137  */
4138 EAPI void
4139 elm_win_wm_rotation_preferred_rotation_set(const Evas_Object *obj,
4140                                            int rotation)
4141 {
4142    ELM_WIN_CHECK(obj);
4143    eo_do((Eo *) obj, elm_obj_win_wm_preferred_rotation_set(rotation));
4144 }
4145
4146 EOLIAN static void
4147 _elm_win_wm_preferred_rotation_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int rotation)
4148 {
4149    int rot;
4150
4151    if (!sd->wm_rot.use)
4152      sd->wm_rot.use = EINA_TRUE;
4153
4154    // '-1' means that elm_win doesn't use preferred rotation.
4155    if (rotation == -1)
4156      rot = -1;
4157    else
4158      rot = _win_rotation_degree_check(rotation);
4159
4160    if (sd->wm_rot.preferred_rot == rot) return;
4161    sd->wm_rot.preferred_rot = rot;
4162
4163    ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
4164 }
4165
4166 EOLIAN static int
4167 _elm_win_wm_preferred_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4168 {
4169    return sd->wm_rot.preferred_rot;
4170 }
4171
4172 EOLIAN static void
4173 _elm_win_wm_available_rotations_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const int *rotations, unsigned int count)
4174 {
4175    unsigned int i;
4176    int r;
4177
4178    if (!sd->wm_rot.use)
4179      sd->wm_rot.use = EINA_TRUE;
4180
4181    ELM_SAFE_FREE(sd->wm_rot.rots, free);
4182    sd->wm_rot.count = 0;
4183
4184    if (count > 0)
4185      {
4186         sd->wm_rot.rots = calloc(count, sizeof(int));
4187         if (!sd->wm_rot.rots) return;
4188         for (i = 0; i < count; i++)
4189           {
4190              r = _win_rotation_degree_check(rotations[i]);
4191              sd->wm_rot.rots[i] = r;
4192           }
4193      }
4194
4195    sd->wm_rot.count = count;
4196
4197    ecore_evas_wm_rotation_available_rotations_set(sd->ee,
4198                                                   sd->wm_rot.rots,
4199                                                   sd->wm_rot.count);
4200 }
4201
4202 EOLIAN static Eina_Bool
4203 _elm_win_wm_available_rotations_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int **rotations, unsigned int *count)
4204 {
4205    if (!sd->wm_rot.use) return EINA_FALSE;
4206
4207    if (sd->wm_rot.count > 0)
4208      {
4209         if (rotations)
4210           {
4211              *rotations = calloc(sd->wm_rot.count, sizeof(int));
4212              if (*rotations)
4213                {
4214                   memcpy(*rotations,
4215                          sd->wm_rot.rots,
4216                          sizeof(int) * sd->wm_rot.count);
4217                }
4218           }
4219      }
4220
4221    if (count) *count = sd->wm_rot.count;
4222    return EINA_TRUE;
4223 }
4224
4225 EOLIAN static void
4226 _elm_win_wm_manual_rotation_done_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool set)
4227 {
4228    if (!sd->wm_rot.use) return;
4229    ecore_evas_wm_rotation_manual_rotation_done_set(sd->ee, set);
4230 }
4231
4232 EOLIAN static Eina_Bool
4233 _elm_win_wm_manual_rotation_done_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4234 {
4235    if (!sd->wm_rot.use) return EINA_FALSE;
4236    return ecore_evas_wm_rotation_manual_rotation_done_get(sd->ee);
4237 }
4238
4239 EOLIAN static void
4240 _elm_win_wm_manual_rotation_done(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4241 {
4242    if (!sd->wm_rot.use) return;
4243    ecore_evas_wm_rotation_manual_rotation_done(sd->ee);
4244 }
4245
4246 EOLIAN static void
4247 _elm_win_sticky_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool sticky)
4248 {
4249 //   sd->sticky = sticky;
4250    TRAP(sd, sticky_set, sticky);
4251 #ifdef HAVE_ELEMENTARY_X
4252    _elm_win_xwin_update(sd);
4253 #endif
4254 }
4255
4256 EOLIAN static Eina_Bool
4257 _elm_win_sticky_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4258 {
4259    return sd->sticky;
4260 }
4261
4262 EOLIAN static void
4263 _elm_win_keyboard_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Keyboard_Mode mode)
4264 {
4265    if (mode == sd->kbdmode) return;
4266 #ifdef HAVE_ELEMENTARY_X
4267    _internal_elm_win_xwindow_get(sd);
4268 #endif
4269    sd->kbdmode = mode;
4270 #ifdef HAVE_ELEMENTARY_X
4271    if (sd->x.xwin)
4272      ecore_x_e_virtual_keyboard_state_set
4273        (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
4274 #endif
4275 }
4276
4277 EOLIAN static Elm_Win_Keyboard_Mode
4278 _elm_win_keyboard_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4279 {
4280    return sd->kbdmode;
4281 }
4282
4283 EOLIAN static void
4284 _elm_win_keyboard_win_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool is_keyboard)
4285 {
4286 #ifdef HAVE_ELEMENTARY_X
4287    _internal_elm_win_xwindow_get(sd);
4288    if (sd->x.xwin)
4289      ecore_x_e_virtual_keyboard_set(sd->x.xwin, is_keyboard);
4290 #else
4291    (void)is_keyboard;
4292 #endif
4293 }
4294
4295 EOLIAN static Eina_Bool
4296 _elm_win_keyboard_win_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4297 {
4298 #ifdef HAVE_ELEMENTARY_X
4299    _internal_elm_win_xwindow_get(sd);
4300    if (sd->x.xwin) return ecore_x_e_virtual_keyboard_get(sd->x.xwin);
4301 #endif
4302    return EINA_FALSE;
4303 }
4304
4305 EOLIAN static void
4306 _elm_win_indicator_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Mode mode)
4307 {
4308    if (mode == sd->indmode) return;
4309 #ifdef HAVE_ELEMENTARY_X
4310    _internal_elm_win_xwindow_get(sd);
4311 #endif
4312    sd->indmode = mode;
4313 #ifdef HAVE_ELEMENTARY_X
4314    if (sd->x.xwin)
4315      {
4316         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
4317           ecore_x_e_illume_indicator_state_set
4318             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
4319         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
4320           ecore_x_e_illume_indicator_state_set
4321             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
4322      }
4323 #endif
4324    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4325 }
4326
4327 EOLIAN static Elm_Win_Indicator_Mode
4328 _elm_win_indicator_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4329 {
4330    return sd->indmode;
4331 }
4332
4333 EOLIAN static void
4334 _elm_win_indicator_opacity_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Opacity_Mode mode)
4335 {
4336    if (mode == sd->ind_o_mode) return;
4337    sd->ind_o_mode = mode;
4338 #ifdef HAVE_ELEMENTARY_X
4339    _internal_elm_win_xwindow_get(sd);
4340    if (sd->x.xwin)
4341      {
4342         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
4343           ecore_x_e_illume_indicator_opacity_set
4344             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_OPAQUE);
4345         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
4346           ecore_x_e_illume_indicator_opacity_set
4347             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
4348         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
4349           ecore_x_e_illume_indicator_opacity_set
4350             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
4351      }
4352 #endif
4353    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4354 }
4355
4356 EOLIAN static Elm_Win_Indicator_Opacity_Mode
4357 _elm_win_indicator_opacity_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4358 {
4359    return sd->ind_o_mode;
4360 }
4361
4362 EOLIAN static void
4363 _elm_win_screen_position_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y)
4364 {
4365    if (x) *x = sd->screen.x;
4366    if (y) *y = sd->screen.y;
4367 }
4368
4369 EOLIAN static Eina_Bool
4370 _elm_win_focus_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4371 {
4372    return ecore_evas_focus_get(sd->ee);
4373 }
4374
4375 EOLIAN static void
4376 _elm_win_screen_constrain_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool constrain)
4377 {
4378    sd->constrain = !!constrain;
4379 }
4380
4381 EOLIAN static Eina_Bool
4382 _elm_win_screen_constrain_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4383 {
4384    return sd->constrain;
4385 }
4386
4387 EOLIAN static void
4388 _elm_win_screen_size_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y, int *w, int *h)
4389 {
4390    ecore_evas_screen_geometry_get(sd->ee, x, y, w, h);
4391 }
4392
4393 EOLIAN static void
4394 _elm_win_screen_dpi_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *xdpi, int *ydpi)
4395 {
4396    ecore_evas_screen_dpi_get(sd->ee, xdpi, ydpi);
4397 }
4398
4399 EOLIAN static void
4400 _elm_win_conformant_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool conformant)
4401 {
4402 #ifdef HAVE_ELEMENTARY_X
4403    _internal_elm_win_xwindow_get(sd);
4404    if (sd->x.xwin)
4405      ecore_x_e_illume_conformant_set(sd->x.xwin, conformant);
4406 #else
4407    (void)conformant;
4408 #endif
4409 }
4410
4411 EOLIAN static Eina_Bool
4412 _elm_win_conformant_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4413 {
4414 #ifdef HAVE_ELEMENTARY_X
4415    _internal_elm_win_xwindow_get(sd);
4416    if (sd->x.xwin)
4417      return ecore_x_e_illume_conformant_get(sd->x.xwin);
4418 #endif
4419
4420    return EINA_FALSE;
4421 }
4422
4423 EOLIAN static void
4424 _elm_win_quickpanel_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool quickpanel)
4425 {
4426 #ifdef HAVE_ELEMENTARY_X
4427    _internal_elm_win_xwindow_get(sd);
4428    if (sd->x.xwin)
4429      {
4430         ecore_x_e_illume_quickpanel_set(sd->x.xwin, quickpanel);
4431         if (quickpanel)
4432           {
4433              Ecore_X_Window_State states[2];
4434
4435              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
4436              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
4437              ecore_x_netwm_window_state_set(sd->x.xwin, states, 2);
4438              ecore_x_icccm_hints_set(sd->x.xwin, 0, 0, 0, 0, 0, 0, 0);
4439           }
4440      }
4441 #else
4442    (void)quickpanel;
4443 #endif
4444 }
4445
4446 EOLIAN static Eina_Bool
4447 _elm_win_quickpanel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4448 {
4449 #ifdef HAVE_ELEMENTARY_X
4450    _internal_elm_win_xwindow_get(sd);
4451    if (sd->x.xwin)
4452      return ecore_x_e_illume_quickpanel_get(sd->x.xwin);
4453 #endif
4454
4455    return EINA_FALSE;
4456 }
4457
4458 EOLIAN static void
4459 _elm_win_quickpanel_priority_major_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
4460 {
4461 #ifdef HAVE_ELEMENTARY_X
4462    _internal_elm_win_xwindow_get(sd);
4463    if (sd->x.xwin)
4464      ecore_x_e_illume_quickpanel_priority_major_set(sd->x.xwin, priority);
4465 #else
4466    (void)priority;
4467 #endif
4468 }
4469
4470 EOLIAN static int
4471 _elm_win_quickpanel_priority_major_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4472 {
4473 #ifdef HAVE_ELEMENTARY_X
4474    _internal_elm_win_xwindow_get(sd);
4475    if (sd->x.xwin)
4476      return ecore_x_e_illume_quickpanel_priority_major_get(sd->x.xwin);
4477 #endif
4478
4479    return -1;
4480 }
4481
4482 EOLIAN static void
4483 _elm_win_quickpanel_priority_minor_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
4484 {
4485 #ifdef HAVE_ELEMENTARY_X
4486    _internal_elm_win_xwindow_get(sd);
4487    if (sd->x.xwin)
4488      ecore_x_e_illume_quickpanel_priority_minor_set(sd->x.xwin, priority);
4489 #else
4490    (void)priority;
4491 #endif
4492 }
4493
4494 EOLIAN static int
4495 _elm_win_quickpanel_priority_minor_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4496 {
4497 #ifdef HAVE_ELEMENTARY_X
4498    _internal_elm_win_xwindow_get(sd);
4499    if (sd->x.xwin)
4500      return ecore_x_e_illume_quickpanel_priority_minor_get(sd->x.xwin);
4501 #endif
4502
4503    return -1;
4504 }
4505
4506 EOLIAN static void
4507 _elm_win_quickpanel_zone_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int zone)
4508 {
4509 #ifdef HAVE_ELEMENTARY_X
4510    _internal_elm_win_xwindow_get(sd);
4511    if (sd->x.xwin)
4512      ecore_x_e_illume_quickpanel_zone_set(sd->x.xwin, zone);
4513 #else
4514    (void)zone;
4515 #endif
4516 }
4517
4518 EOLIAN static int
4519 _elm_win_quickpanel_zone_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4520 {
4521 #ifdef HAVE_ELEMENTARY_X
4522    _internal_elm_win_xwindow_get(sd);
4523    if (sd->x.xwin)
4524      return ecore_x_e_illume_quickpanel_zone_get(sd->x.xwin);
4525 #endif
4526
4527    return 0;
4528 }
4529
4530 EOLIAN static void
4531 _elm_win_prop_focus_skip_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool skip)
4532 {
4533    sd->skip_focus = skip;
4534    TRAP(sd, focus_skip_set, skip);
4535 }
4536
4537 EOLIAN static void
4538 _elm_win_illume_command_send(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Illume_Command command, void *params)
4539 {
4540    (void) params;
4541
4542 #ifdef HAVE_ELEMENTARY_X
4543    _internal_elm_win_xwindow_get(sd);
4544    if (sd->x.xwin)
4545      {
4546         switch (command)
4547           {
4548            case ELM_ILLUME_COMMAND_FOCUS_BACK:
4549              ecore_x_e_illume_focus_back_send(sd->x.xwin);
4550              break;
4551
4552            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
4553              ecore_x_e_illume_focus_forward_send(sd->x.xwin);
4554              break;
4555
4556            case ELM_ILLUME_COMMAND_FOCUS_HOME:
4557              ecore_x_e_illume_focus_home_send(sd->x.xwin);
4558              break;
4559
4560            case ELM_ILLUME_COMMAND_CLOSE:
4561              ecore_x_e_illume_close_send(sd->x.xwin);
4562              break;
4563
4564            default:
4565              break;
4566           }
4567      }
4568 #else
4569    (void)command;
4570 #endif
4571 }
4572
4573 EOLIAN static Evas_Object*
4574 _elm_win_inlined_image_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4575 {
4576    return sd->img_obj;
4577 }
4578
4579 EOLIAN static void
4580 _elm_win_focus_highlight_enabled_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool enabled)
4581 {
4582    enabled = !!enabled;
4583    if (sd->focus_highlight.enabled == enabled)
4584      return;
4585
4586    sd->focus_highlight.enabled = enabled;
4587
4588    if (sd->focus_highlight.enabled)
4589      _elm_win_focus_highlight_init(sd);
4590    else
4591      _elm_win_focus_highlight_shutdown(sd);
4592 }
4593
4594 EOLIAN static Eina_Bool
4595 _elm_win_focus_highlight_enabled_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4596 {
4597    return sd->focus_highlight.enabled;
4598 }
4599
4600 EOLIAN static Eina_Bool
4601 _elm_win_elm_widget_theme_apply(Eo *obj, Elm_Win_Data *sd)
4602 {
4603    Eina_Bool int_ret = EINA_FALSE;
4604    eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
4605    if (!int_ret) return EINA_TRUE;
4606
4607    sd->focus_highlight.theme_changed = EINA_TRUE;
4608    _elm_win_focus_highlight_reconfigure_job_start(sd);
4609
4610    return EINA_TRUE;
4611 }
4612
4613 EOLIAN static void
4614 _elm_win_focus_highlight_style_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *style)
4615 {
4616    eina_stringshare_replace(&sd->focus_highlight.style, style);
4617    sd->focus_highlight.theme_changed = EINA_TRUE;
4618    _elm_win_focus_highlight_reconfigure_job_start(sd);
4619 }
4620
4621 EOLIAN static const char*
4622 _elm_win_focus_highlight_style_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4623 {
4624    return sd->focus_highlight.style;
4625 }
4626
4627 EOLIAN static void
4628 _elm_win_focus_highlight_animate_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool animate)
4629 {
4630    animate = !!animate;
4631    if (sd->focus_highlight.animate == animate)
4632      return;
4633
4634    sd->focus_highlight.animate = animate;
4635    sd->focus_highlight.theme_changed = EINA_TRUE;
4636    _elm_win_focus_highlight_reconfigure_job_start(sd);
4637 }
4638
4639 EOLIAN static Eina_Bool
4640 _elm_win_focus_highlight_animate_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4641 {
4642    return sd->focus_highlight.animate;
4643 }
4644
4645 EOLIAN static Eina_Bool
4646 _elm_win_socket_listen(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *svcname, int svcnum, Eina_Bool svcsys)
4647 {
4648    if (!sd->ee) return EINA_FALSE;
4649
4650    if (!ecore_evas_extn_socket_listen(sd->ee, svcname, svcnum, svcsys))
4651      return EINA_FALSE;
4652
4653    return EINA_TRUE;
4654 }
4655
4656 /* windowing specific calls - shall we do this differently? */
4657
4658 EOLIAN static Ecore_X_Window
4659 _elm_win_xwindow_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4660 {
4661 #ifdef HAVE_ELEMENTARY_X
4662    if (sd->x.xwin) return sd->x.xwin;
4663    if (sd->parent) return elm_win_xwindow_get(sd->parent);
4664 #endif
4665    return 0;
4666 }
4667
4668 EAPI Ecore_Wl_Window *
4669 elm_win_wl_window_get(const Evas_Object *obj)
4670 {
4671    if (!obj) return NULL;
4672
4673    if ((!ENGINE_COMPARE(ELM_WAYLAND_SHM)) &&
4674        (!ENGINE_COMPARE(ELM_WAYLAND_EGL)))
4675      return NULL;
4676
4677    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
4678      {
4679         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4680         return _elm_ee_wlwin_get(ee);
4681      }
4682
4683    ELM_WIN_CHECK(obj) NULL;
4684    Ecore_Wl_Window *ret = NULL;
4685    eo_do((Eo *) obj, ret = elm_obj_win_wl_window_get());
4686    return ret;
4687 }
4688
4689 EOLIAN static Ecore_Wl_Window*
4690 _elm_win_wl_window_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4691 {
4692 #if HAVE_ELEMENTARY_WAYLAND
4693    if (sd->wl.win) return sd->wl.win;
4694    if (sd->parent) return elm_win_wl_window_get(sd->parent);
4695 #else
4696    (void)sd;
4697 #endif
4698    return NULL;
4699 }
4700
4701 EAPI Eina_Bool
4702 elm_win_trap_set(const Elm_Win_Trap *t)
4703 {
4704    DBG("old %p, new %p", trap, t);
4705
4706    if ((t) && (t->version != ELM_WIN_TRAP_VERSION))
4707      {
4708         CRI("trying to set a trap version %lu while %lu was expected!",
4709                  t->version, ELM_WIN_TRAP_VERSION);
4710         return EINA_FALSE;
4711      }
4712
4713    trap = t;
4714    return EINA_TRUE;
4715 }
4716
4717 EAPI void
4718 elm_win_floating_mode_set(Evas_Object *obj, Eina_Bool floating)
4719 {
4720    ELM_WIN_CHECK(obj);
4721    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4722
4723    floating = !!floating;
4724    if (floating == sd->floating) return;
4725    sd->floating = floating;
4726 #ifdef HAVE_ELEMENTARY_X
4727    _internal_elm_win_xwindow_get(sd);
4728    if (sd->x.xwin)
4729      {
4730         if (sd->floating)
4731           ecore_x_e_illume_window_state_set
4732              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_FLOATING);
4733         else
4734           ecore_x_e_illume_window_state_set
4735              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_NORMAL);
4736      }
4737 #endif
4738 }
4739
4740 EAPI Eina_Bool
4741 elm_win_floating_mode_get(const Evas_Object *obj)
4742 {
4743    ELM_WIN_CHECK(obj) EINA_FALSE;
4744    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4745
4746    return sd->floating;
4747 }
4748
4749 EOLIAN static Ecore_Window
4750 _elm_win_window_id_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4751 {
4752    if ((ENGINE_COMPARE(ELM_WAYLAND_SHM)) || (ENGINE_COMPARE(ELM_WAYLAND_EGL)))
4753      {
4754 #if HAVE_ELEMENTARY_WAYLAND
4755         if (sd->wl.win) return (Ecore_Window)ecore_wl_window_surface_id_get(sd->wl.win);
4756         if (sd->parent)
4757           {
4758              Ecore_Wl_Window *parent;
4759
4760              parent = elm_win_wl_window_get(sd->parent);
4761              if (parent) return (Ecore_Window)ecore_wl_window_surface_id_get(parent);
4762              return 0;
4763           }
4764 #endif
4765      }
4766    else
4767      {
4768 #ifdef HAVE_ELEMENTARY_X
4769         _internal_elm_win_xwindow_get(sd);
4770         if (sd->x.xwin) return (Ecore_Window)sd->x.xwin;
4771         if (sd->parent) return (Ecore_Window)elm_win_xwindow_get(sd->parent);
4772 #endif
4773      }
4774
4775    return 0;
4776 }
4777
4778 void
4779 _elm_win_focus_highlight_in_theme_update(Evas_Object *obj, Eina_Bool in_theme)
4780 {
4781    ELM_WIN_DATA_GET(obj, sd);
4782    sd->focus_highlight.cur.in_theme = !!in_theme;
4783 }
4784
4785 void
4786 _elm_win_focus_highlight_start(Evas_Object *obj)
4787 {
4788    ELM_WIN_DATA_GET(obj, sd);
4789
4790    if (!elm_win_focus_highlight_enabled_get(obj)) return;
4791    sd->focus_highlight.cur.visible = EINA_TRUE;
4792    sd->focus_highlight.geometry_changed = EINA_TRUE;
4793    _elm_win_focus_highlight_reconfigure_job(obj);
4794 }
4795
4796 EAPI Ecore_Window
4797 elm_win_window_id_get(const Evas_Object *obj)
4798 {
4799    if (!obj) return 0;
4800
4801    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
4802      {
4803         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4804         return ecore_evas_window_get(ee);
4805      }
4806
4807    ELM_WIN_CHECK(obj) 0;
4808    Ecore_Window ret = 0;
4809    eo_do((Eo *) obj, ret = elm_obj_win_window_id_get());
4810    return ret;
4811 }
4812
4813 EOLIAN static void
4814 _elm_win_class_constructor(Eo_Class *klass)
4815 {
4816    evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
4817 }
4818
4819 EOLIAN static Eo*
4820 _elm_win_elm_interface_atspi_accessible_parent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd EINA_UNUSED)
4821 {
4822    // attach all kinds of windows directly to ATSPI application root object
4823    return _elm_atspi_root_get();
4824 }
4825
4826 #include "elm_win.eo.c"