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