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