add code to check window property change related with keypad state
[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;
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
2004              if ((unsigned int)e->data.l[1] ==
2005                  ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
2006                {
2007                   // XXX: call right access func
2008                }
2009              else if ((unsigned int)e->data.l[1] ==
2010                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
2011                {
2012                   // XXX: call right access func
2013                }
2014              else if ((unsigned int)e->data.l[1] ==
2015                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
2016                {
2017                   _elm_access_highlight_object_activate
2018                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_DEFAULT);
2019                }
2020              else if ((unsigned int)e->data.l[1] ==
2021                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
2022                {
2023                   /* there would be better way to read highlight object */
2024                   Evas *evas;
2025                   evas = evas_object_evas_get(ELM_WIDGET_DATA(sd)->obj);
2026                   if (!evas) return ECORE_CALLBACK_PASS_ON;
2027
2028                   a = calloc(1, sizeof(Elm_Access_Action_Info));
2029                   a->x = e->data.l[2];
2030                   a->y = e->data.l[3];
2031                   elm_access_action(ELM_WIDGET_DATA(sd)->obj, ELM_ACCESS_ACTION_HIGHLIGHT, a);
2032                   free(a);
2033                }
2034              else if ((unsigned int)e->data.l[1] ==
2035                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
2036                {
2037                   _elm_access_highlight_cycle(ELM_WIDGET_DATA(sd)->obj, ELM_FOCUS_NEXT);
2038                }
2039              else if ((unsigned int)e->data.l[1] ==
2040                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
2041                {
2042                   _elm_access_highlight_cycle(ELM_WIDGET_DATA(sd)->obj, ELM_FOCUS_PREVIOUS);
2043                }
2044              else if ((unsigned int)e->data.l[1] ==
2045                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
2046                {
2047                   _elm_access_highlight_object_activate
2048                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_UP);
2049                }
2050              else if ((unsigned int)e->data.l[1] ==
2051                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
2052                {
2053                   _elm_access_highlight_object_activate
2054                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_DOWN);
2055                }
2056              else if ((unsigned int)e->data.l[1] == atom_scroll)
2057                {
2058                   _elm_access_highlight_object_scroll(ELM_WIDGET_DATA(sd)->obj,
2059                     e->data.l[2], e->data.l[3], e->data.l[4]);
2060                }
2061           }
2062      }
2063    return ECORE_CALLBACK_PASS_ON;
2064 }
2065
2066 static Eina_Bool
2067 _elm_win_property_change(void *data,
2068                          int type __UNUSED__,
2069                          void *event)
2070 {
2071    Elm_Win_Smart_Data *sd = data;
2072    Ecore_X_Event_Window_Property *e = event;
2073
2074    if (e->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE)
2075      {
2076         if (e->win == sd->x.xwin)
2077           {
2078              sd->indmode = ecore_x_e_illume_indicator_state_get(e->win);
2079              evas_object_smart_callback_call(ELM_WIDGET_DATA(sd)->obj, SIG_INDICATOR_PROP_CHANGED, NULL);
2080           }
2081      }
2082    if (e->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
2083      {
2084         if (e->win == sd->x.xwin)
2085           {
2086              sd->kbdmode = ecore_x_e_virtual_keyboard_state_get(e->win);
2087           }
2088      }
2089    return ECORE_CALLBACK_PASS_ON;
2090 }
2091 #endif
2092
2093 static void
2094 _elm_win_focus_highlight_hide(void *data __UNUSED__,
2095                               Evas_Object *obj,
2096                               const char *emission __UNUSED__,
2097                               const char *source __UNUSED__)
2098 {
2099    evas_object_hide(obj);
2100 }
2101
2102 static void
2103 _elm_win_focus_highlight_anim_end(void *data,
2104                                   Evas_Object *obj,
2105                                   const char *emission __UNUSED__,
2106                                   const char *source __UNUSED__)
2107 {
2108    Elm_Win_Smart_Data *sd = data;
2109
2110    _elm_win_focus_highlight_simple_setup(sd, obj);
2111 }
2112
2113 static void
2114 _elm_win_focus_highlight_init(Elm_Win_Smart_Data *sd)
2115 {
2116    evas_event_callback_add(sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
2117                            _elm_win_object_focus_in, sd);
2118    evas_event_callback_add(sd->evas,
2119                            EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
2120                            _elm_win_object_focus_out, sd);
2121
2122    sd->focus_highlight.cur.target = evas_focus_get(sd->evas);
2123
2124    sd->focus_highlight.top = edje_object_add(sd->evas);
2125    sd->focus_highlight.changed_theme = EINA_TRUE;
2126    edje_object_signal_callback_add(sd->focus_highlight.top,
2127                                    "elm,action,focus,hide,end", "",
2128                                    _elm_win_focus_highlight_hide, NULL);
2129    edje_object_signal_callback_add(sd->focus_highlight.top,
2130                                    "elm,action,focus,anim,end", "",
2131                                    _elm_win_focus_highlight_anim_end, sd);
2132    _elm_win_focus_highlight_reconfigure_job_start(sd);
2133 }
2134
2135 static void
2136 _elm_win_frame_cb_move_start(void *data,
2137                              Evas_Object *obj __UNUSED__,
2138                              const char *sig __UNUSED__,
2139                              const char *source __UNUSED__)
2140 {
2141    Elm_Win_Smart_Data *sd;
2142
2143    if (!(sd = data)) return;
2144    /* FIXME: Change mouse pointer */
2145
2146    /* NB: Wayland handles moving surfaces by itself so we cannot
2147     * specify a specific x/y we want. Instead, we will pass in the
2148     * existing x/y values so they can be recorded as 'previous'
2149     * position. The new position will get updated automatically when
2150     * the move is finished */
2151
2152    ecore_evas_wayland_move(sd->ee, sd->screen.x, sd->screen.y);
2153 }
2154
2155 static void
2156 _elm_win_frame_cb_resize_show(void *data,
2157                               Evas_Object *obj __UNUSED__,
2158                               const char *sig __UNUSED__,
2159                               const char *source)
2160 {
2161    Elm_Win_Smart_Data *sd;
2162
2163    if (!(sd = data)) return;
2164    if (sd->resizing) return;
2165
2166 #ifdef HAVE_ELEMENTARY_WAYLAND
2167    if (!strcmp(source, "elm.event.resize.t"))
2168      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_TOP_SIDE);
2169    else if (!strcmp(source, "elm.event.resize.b"))
2170      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_BOTTOM_SIDE);
2171    else if (!strcmp(source, "elm.event.resize.l"))
2172      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_LEFT_SIDE);
2173    else if (!strcmp(source, "elm.event.resize.r"))
2174      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_RIGHT_SIDE);
2175    else if (!strcmp(source, "elm.event.resize.tl"))
2176      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2177                                           ELM_CURSOR_TOP_LEFT_CORNER);
2178    else if (!strcmp(source, "elm.event.resize.tr"))
2179      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2180                                           ELM_CURSOR_TOP_RIGHT_CORNER);
2181    else if (!strcmp(source, "elm.event.resize.bl"))
2182      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2183                                           ELM_CURSOR_BOTTOM_LEFT_CORNER);
2184    else if (!strcmp(source, "elm.event.resize.br"))
2185      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2186                                           ELM_CURSOR_BOTTOM_RIGHT_CORNER);
2187    else
2188      ecore_wl_window_cursor_default_restore(sd->wl.win);
2189 #else
2190    (void)source;
2191 #endif
2192 }
2193
2194 static void
2195 _elm_win_frame_cb_resize_hide(void *data,
2196                               Evas_Object *obj __UNUSED__,
2197                               const char *sig __UNUSED__,
2198                               const char *source __UNUSED__)
2199 {
2200    Elm_Win_Smart_Data *sd;
2201
2202    if (!(sd = data)) return;
2203    if (sd->resizing) return;
2204
2205 #ifdef HAVE_ELEMENTARY_WAYLAND
2206    ecore_wl_window_cursor_default_restore(sd->wl.win);
2207 #endif
2208 }
2209
2210 static void
2211 _elm_win_frame_cb_resize_start(void *data,
2212                                Evas_Object *obj __UNUSED__,
2213                                const char *sig __UNUSED__,
2214                                const char *source)
2215 {
2216    Elm_Win_Smart_Data *sd;
2217
2218    if (!(sd = data)) return;
2219    if (sd->resizing) return;
2220
2221    sd->resizing = EINA_TRUE;
2222
2223    if (!strcmp(source, "elm.event.resize.t"))
2224      sd->resize_location = 1;
2225    else if (!strcmp(source, "elm.event.resize.b"))
2226      sd->resize_location = 2;
2227    else if (!strcmp(source, "elm.event.resize.l"))
2228      sd->resize_location = 4;
2229    else if (!strcmp(source, "elm.event.resize.r"))
2230      sd->resize_location = 8;
2231    else if (!strcmp(source, "elm.event.resize.tl"))
2232      sd->resize_location = 5;
2233    else if (!strcmp(source, "elm.event.resize.tr"))
2234      sd->resize_location = 9;
2235    else if (!strcmp(source, "elm.event.resize.bl"))
2236      sd->resize_location = 6;
2237    else if (!strcmp(source, "elm.event.resize.br"))
2238      sd->resize_location = 10;
2239    else
2240      sd->resize_location = 0;
2241
2242    if (sd->resize_location > 0)
2243      ecore_evas_wayland_resize(sd->ee, sd->resize_location);
2244 }
2245
2246 static void
2247 _elm_win_frame_cb_minimize(void *data,
2248                            Evas_Object *obj __UNUSED__,
2249                            const char *sig __UNUSED__,
2250                            const char *source __UNUSED__)
2251 {
2252    Elm_Win_Smart_Data *sd;
2253
2254    if (!(sd = data)) return;
2255 // sd->iconified = EINA_TRUE;
2256    TRAP(sd, iconified_set, EINA_TRUE);
2257 }
2258
2259 static void
2260 _elm_win_frame_cb_maximize(void *data,
2261                            Evas_Object *obj __UNUSED__,
2262                            const char *sig __UNUSED__,
2263                            const char *source __UNUSED__)
2264 {
2265    Elm_Win_Smart_Data *sd;
2266
2267    if (!(sd = data)) return;
2268    if (sd->maximized) sd->maximized = EINA_FALSE;
2269    else sd->maximized = EINA_TRUE;
2270    TRAP(sd, maximized_set, sd->maximized);
2271 }
2272
2273 static void
2274 _elm_win_frame_cb_close(void *data,
2275                         Evas_Object *obj __UNUSED__,
2276                         const char *sig __UNUSED__,
2277                         const char *source __UNUSED__)
2278 {
2279    Elm_Win_Smart_Data *sd;
2280    Evas_Object *win;
2281
2282    /* FIXME: After the current freeze, this should be handled differently.
2283     *
2284     * Ideally, we would want to mimic the X11 backend and use something
2285     * like ECORE_WL_EVENT_WINDOW_DELETE and handle the delete_request
2286     * inside of ecore_evas. That would be the 'proper' way, but since we are
2287     * in a freeze right now, I cannot add a new event value, or a new
2288     * event structure to ecore_wayland.
2289     *
2290     * So yes, this is a temporary 'stop-gap' solution which will be fixed
2291     * when the freeze is over, but it does fix a trac bug for now, and in a
2292     * way which does not break API or the freeze. - dh
2293     */
2294
2295    if (!(sd = data)) return;
2296
2297    win = ELM_WIDGET_DATA(sd)->obj;
2298
2299    int autodel = sd->autodel;
2300    sd->autodel_clear = &autodel;
2301    evas_object_ref(win);
2302    evas_object_smart_callback_call(win, SIG_DELETE_REQUEST, NULL);
2303    // FIXME: if above callback deletes - then the below will be invalid
2304    if (autodel) evas_object_del(win);
2305    else sd->autodel_clear = NULL;
2306    evas_object_unref(win);
2307 }
2308
2309 static void
2310 _elm_win_frame_add(Elm_Win_Smart_Data *sd,
2311                    const char *style)
2312 {
2313    evas_output_framespace_set(sd->evas, 0, 22, 0, 26);
2314
2315    sd->frame_obj = edje_object_add(sd->evas);
2316    elm_widget_theme_object_set
2317      (ELM_WIDGET_DATA(sd)->obj, sd->frame_obj, "border", "base", style);
2318
2319    evas_object_is_frame_object_set(sd->frame_obj, EINA_TRUE);
2320    evas_object_move(sd->frame_obj, 0, 0);
2321    evas_object_resize(sd->frame_obj, 1, 1);
2322
2323    edje_object_signal_callback_add
2324      (sd->frame_obj, "elm,action,move,start", "elm",
2325      _elm_win_frame_cb_move_start, sd);
2326    edje_object_signal_callback_add
2327      (sd->frame_obj, "elm,action,resize,show", "*",
2328      _elm_win_frame_cb_resize_show, sd);
2329    edje_object_signal_callback_add
2330      (sd->frame_obj, "elm,action,resize,hide", "*",
2331      _elm_win_frame_cb_resize_hide, sd);
2332    edje_object_signal_callback_add
2333      (sd->frame_obj, "elm,action,resize,start", "*",
2334      _elm_win_frame_cb_resize_start, sd);
2335    edje_object_signal_callback_add
2336      (sd->frame_obj, "elm,action,minimize", "elm",
2337      _elm_win_frame_cb_minimize, sd);
2338    edje_object_signal_callback_add
2339      (sd->frame_obj, "elm,action,maximize", "elm",
2340      _elm_win_frame_cb_maximize, sd);
2341    edje_object_signal_callback_add
2342      (sd->frame_obj, "elm,action,close", "elm", _elm_win_frame_cb_close, sd);
2343
2344    if (sd->title)
2345      {
2346         edje_object_part_text_escaped_set
2347           (sd->frame_obj, "elm.text.title", sd->title);
2348      }
2349 }
2350
2351 static void
2352 _elm_win_frame_del(Elm_Win_Smart_Data *sd)
2353 {
2354    if (sd->frame_obj)
2355      {
2356         edje_object_signal_callback_del
2357           (sd->frame_obj, "elm,action,move,start", "elm",
2358               _elm_win_frame_cb_move_start);
2359         edje_object_signal_callback_del
2360           (sd->frame_obj, "elm,action,resize,show", "*",
2361               _elm_win_frame_cb_resize_show);
2362         edje_object_signal_callback_del
2363           (sd->frame_obj, "elm,action,resize,hide", "*",
2364               _elm_win_frame_cb_resize_hide);
2365         edje_object_signal_callback_del
2366           (sd->frame_obj, "elm,action,resize,start", "*",
2367               _elm_win_frame_cb_resize_start);
2368         edje_object_signal_callback_del
2369           (sd->frame_obj, "elm,action,minimize", "elm",
2370               _elm_win_frame_cb_minimize);
2371         edje_object_signal_callback_del
2372           (sd->frame_obj, "elm,action,maximize", "elm",
2373               _elm_win_frame_cb_maximize);
2374         edje_object_signal_callback_del
2375           (sd->frame_obj, "elm,action,close", "elm",
2376               _elm_win_frame_cb_close);
2377
2378         evas_object_del(sd->frame_obj);
2379         sd->frame_obj = NULL;
2380      }
2381
2382    evas_output_framespace_set(sd->evas, 0, 0, 0, 0);
2383 }
2384
2385 #ifdef ELM_DEBUG
2386 static void
2387 _debug_key_down(void *data __UNUSED__,
2388                 Evas *e __UNUSED__,
2389                 Evas_Object *obj,
2390                 void *event_info)
2391 {
2392    Evas_Event_Key_Down *ev = event_info;
2393
2394    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
2395      return;
2396
2397    if ((strcmp(ev->keyname, "F12")) ||
2398        (!evas_key_modifier_is_set(ev->modifiers, "Control")))
2399      return;
2400
2401    printf("Tree graph generated.\n");
2402    elm_object_tree_dot_dump(obj, "./dump.dot");
2403 }
2404
2405 #endif
2406
2407 static void
2408 _win_img_hide(void *data,
2409               Evas *e __UNUSED__,
2410               Evas_Object *obj __UNUSED__,
2411               void *event_info __UNUSED__)
2412 {
2413    Elm_Win_Smart_Data *sd = data;
2414
2415    elm_widget_focus_hide_handle(ELM_WIDGET_DATA(sd)->obj);
2416 }
2417
2418 static void
2419 _win_img_mouse_up(void *data,
2420                   Evas *e __UNUSED__,
2421                   Evas_Object *obj __UNUSED__,
2422                   void *event_info)
2423 {
2424    Elm_Win_Smart_Data *sd = data;
2425    Evas_Event_Mouse_Up *ev = event_info;
2426    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
2427      elm_widget_focus_mouse_up_handle(ELM_WIDGET_DATA(sd)->obj);
2428 }
2429
2430 static void
2431 _win_img_focus_in(void *data,
2432                   Evas *e __UNUSED__,
2433                   Evas_Object *obj __UNUSED__,
2434                   void *event_info __UNUSED__)
2435 {
2436    Elm_Win_Smart_Data *sd = data;
2437    elm_widget_focus_steal(ELM_WIDGET_DATA(sd)->obj);
2438 }
2439
2440 static void
2441 _win_img_focus_out(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_focused_object_clear(ELM_WIDGET_DATA(sd)->obj);
2448 }
2449
2450 static void
2451 _win_inlined_image_set(Elm_Win_Smart_Data *sd)
2452 {
2453    evas_object_image_alpha_set(sd->img_obj, EINA_FALSE);
2454    evas_object_image_filled_set(sd->img_obj, EINA_TRUE);
2455
2456    evas_object_event_callback_add
2457      (sd->img_obj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, sd);
2458    evas_object_event_callback_add
2459      (sd->img_obj, EVAS_CALLBACK_HIDE, _win_img_hide, sd);
2460    evas_object_event_callback_add
2461      (sd->img_obj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, sd);
2462    evas_object_event_callback_add
2463      (sd->img_obj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, sd);
2464    evas_object_event_callback_add
2465      (sd->img_obj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, sd);
2466 }
2467
2468 static void
2469 _elm_win_on_icon_del(void *data,
2470                      Evas *e __UNUSED__,
2471                      Evas_Object *obj,
2472                      void *event_info __UNUSED__)
2473 {
2474    Elm_Win_Smart_Data *sd = data;
2475
2476    if (sd->icon == obj) sd->icon = NULL;
2477 }
2478
2479 static void
2480 _elm_win_smart_add(Evas_Object *obj)
2481 {
2482    EVAS_SMART_DATA_ALLOC(obj, Elm_Win_Smart_Data);
2483
2484    _elm_win_parent_sc->base.add(obj);
2485
2486    elm_widget_can_focus_set(obj, EINA_TRUE);
2487
2488    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2489 }
2490
2491 static void
2492 _elm_win_smart_set_user(Elm_Widget_Smart_Class *sc)
2493 {
2494    sc->base.add = _elm_win_smart_add;
2495    sc->base.del = _elm_win_smart_del;
2496    sc->base.show = _elm_win_smart_show;
2497    sc->base.hide = _elm_win_smart_hide;
2498    sc->base.move = _elm_win_smart_move;
2499    sc->base.resize = _elm_win_smart_resize;
2500
2501    sc->focus_next = _elm_win_smart_focus_next;
2502    sc->focus_direction = _elm_win_smart_focus_direction;
2503    sc->on_focus = _elm_win_smart_on_focus;
2504    sc->event = _elm_win_smart_event;
2505 }
2506
2507 #ifdef HAVE_ELEMENTARY_X
2508 static void
2509 _elm_x_io_err(void *data __UNUSED__)
2510 {
2511    Eina_List *l;
2512    Evas_Object *obj;
2513
2514    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2515      evas_object_smart_callback_call(obj, SIG_IOERR, NULL);
2516    elm_exit();
2517 }
2518 #endif
2519
2520 static void
2521 _elm_win_cb_hide(void *data __UNUSED__,
2522                  Evas *e __UNUSED__,
2523                  Evas_Object *obj __UNUSED__,
2524                  void *event_info __UNUSED__)
2525 {
2526    _elm_win_state_eval_queue();
2527 }
2528
2529 static void
2530 _elm_win_cb_show(void *data __UNUSED__,
2531                  Evas *e __UNUSED__,
2532                  Evas_Object *obj __UNUSED__,
2533                  void *event_info __UNUSED__)
2534 {
2535    _elm_win_state_eval_queue();
2536 }
2537
2538 EAPI Evas_Object *
2539 elm_win_add(Evas_Object *parent,
2540             const char *name,
2541             Elm_Win_Type type)
2542 {
2543    Evas *e;
2544    Evas_Object *obj;
2545    const Eina_List *l;
2546    const char *fontpath, *fallback = NULL;
2547
2548    Elm_Win_Smart_Data tmp_sd;
2549
2550    /* just to store some data while trying out to create a canvas */
2551    memset(&tmp_sd, 0, sizeof(Elm_Win_Smart_Data));
2552
2553 #define FALLBACK_TRY(engine)                                      \
2554   if (!tmp_sd.ee) {                                               \
2555      CRITICAL(engine " engine creation failed. Trying default."); \
2556        tmp_sd.ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);              \
2557        if (tmp_sd.ee)                                                   \
2558           elm_config_preferred_engine_set(ecore_evas_engine_name_get(tmp_sd.ee)); \
2559   } while (0)
2560 #define FALLBACK_STORE(engine)                               \
2561    if (tmp_sd.ee)                                            \
2562    {                                                         \
2563       CRITICAL(engine "Fallback to %s successful.", engine); \
2564       fallback = engine;                                     \
2565    }
2566
2567    switch (type)
2568      {
2569       case ELM_WIN_INLINED_IMAGE:
2570         if (!parent) break;
2571         {
2572            e = evas_object_evas_get(parent);
2573            Ecore_Evas *ee;
2574
2575            if (!e) break;
2576
2577            ee = ecore_evas_ecore_evas_get(e);
2578            if (!ee) break;
2579
2580            tmp_sd.img_obj = ecore_evas_object_image_new(ee);
2581            if (!tmp_sd.img_obj) break;
2582
2583            tmp_sd.ee = ecore_evas_object_ecore_evas_get(tmp_sd.img_obj);
2584            if (!tmp_sd.ee)
2585              {
2586                 evas_object_del(tmp_sd.img_obj);
2587                 tmp_sd.img_obj = NULL;
2588              }
2589         }
2590         break;
2591
2592       case ELM_WIN_SOCKET_IMAGE:
2593         tmp_sd.ee = ecore_evas_extn_socket_new(1, 1);
2594         break;
2595
2596       default:
2597         if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
2598           {
2599              tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2600              FALLBACK_TRY("Software X11");
2601              if (!tmp_sd.ee)
2602                {
2603                   tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2604                   FALLBACK_STORE("Software FB");
2605                }
2606           }
2607         else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
2608           {
2609              tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2610              FALLBACK_TRY("Software FB");
2611              if (!tmp_sd.ee)
2612                {
2613                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2614                   FALLBACK_STORE("Software X11");
2615                }
2616           }
2617         else if (ENGINE_COMPARE(ELM_SOFTWARE_DIRECTFB))
2618           {
2619              tmp_sd.ee = ecore_evas_directfb_new(NULL, 1, 0, 0, 1, 1);
2620              FALLBACK_TRY("Software DirectFB");
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                   if (!tmp_sd.ee)
2626                     {
2627                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2628                        FALLBACK_STORE("Software FB");
2629                     }
2630                }
2631           }
2632         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
2633           {
2634              tmp_sd.ee = ecore_evas_software_x11_16_new(NULL, 0, 0, 0, 1, 1);
2635              FALLBACK_TRY("Software-16");
2636              if (!tmp_sd.ee)
2637                {
2638                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2639                   FALLBACK_STORE("Software X11");
2640                   if (!tmp_sd.ee)
2641                     {
2642                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2643                        FALLBACK_STORE("Software FB");
2644                     }
2645                }
2646           }
2647         else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
2648           {
2649              tmp_sd.ee = ecore_evas_software_x11_8_new(NULL, 0, 0, 0, 1, 1);
2650              FALLBACK_TRY("Software-8");
2651              if (!tmp_sd.ee)
2652                {
2653                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2654                   FALLBACK_STORE("Software X11");
2655                   if (!tmp_sd.ee)
2656                     {
2657                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2658                        FALLBACK_STORE("Software FB");
2659                     }
2660                }
2661           }
2662         else if (ENGINE_COMPARE(ELM_OPENGL_X11))
2663           {
2664              int opt[10];
2665              int opt_i = 0;
2666
2667              if (_elm_config->vsync)
2668                {
2669                   opt[opt_i] = ECORE_EVAS_GL_X11_OPT_VSYNC;
2670                   opt_i++;
2671                   opt[opt_i] = 1;
2672                   opt_i++;
2673                                   opt[opt_i] = 0;
2674                }
2675              if (opt_i > 0)
2676                tmp_sd.ee = ecore_evas_gl_x11_options_new
2677                    (NULL, 0, 0, 0, 1, 1, opt);
2678              else
2679                tmp_sd.ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
2680              FALLBACK_TRY("OpenGL");
2681              if (!tmp_sd.ee)
2682                {
2683                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2684                   FALLBACK_STORE("Software X11");
2685                   if (!tmp_sd.ee)
2686                     {
2687                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2688                        FALLBACK_STORE("Software FB");
2689                     }
2690                }
2691           }
2692         else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
2693           {
2694              tmp_sd.ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
2695              FALLBACK_TRY("Software Win32");
2696           }
2697         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
2698           {
2699              tmp_sd.ee = ecore_evas_software_wince_gdi_new(NULL, 0, 0, 1, 1);
2700              FALLBACK_TRY("Software-16-WinCE");
2701           }
2702         else if (ENGINE_COMPARE(ELM_SOFTWARE_PSL1GHT))
2703           {
2704              tmp_sd.ee = ecore_evas_psl1ght_new(NULL, 1, 1);
2705              FALLBACK_TRY("PSL1GHT");
2706           }
2707         else if (ENGINE_COMPARE(ELM_SOFTWARE_SDL))
2708           {
2709              tmp_sd.ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
2710              FALLBACK_TRY("Software SDL");
2711              if (!tmp_sd.ee)
2712                {
2713                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2714                   FALLBACK_STORE("Software X11");
2715                   if (!tmp_sd.ee)
2716                     {
2717                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2718                        FALLBACK_STORE("Software FB");
2719                     }
2720                }
2721           }
2722         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_SDL))
2723           {
2724              tmp_sd.ee = ecore_evas_sdl16_new(NULL, 0, 0, 0, 0, 0, 1);
2725              FALLBACK_TRY("Software-16-SDL");
2726              if (!tmp_sd.ee)
2727                {
2728                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2729                   FALLBACK_STORE("Software X11");
2730                   if (!tmp_sd.ee)
2731                     {
2732                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2733                        FALLBACK_STORE("Software FB");
2734                     }
2735                }
2736           }
2737         else if (ENGINE_COMPARE(ELM_OPENGL_SDL))
2738           {
2739              tmp_sd.ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
2740              FALLBACK_TRY("OpenGL SDL");
2741              if (!tmp_sd.ee)
2742                {
2743                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2744                   FALLBACK_STORE("Software X11");
2745                   if (!tmp_sd.ee)
2746                     {
2747                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2748                        FALLBACK_STORE("Software FB");
2749                     }
2750                }
2751           }
2752         else if (ENGINE_COMPARE(ELM_OPENGL_COCOA))
2753           {
2754              tmp_sd.ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
2755              FALLBACK_TRY("OpenGL Cocoa");
2756           }
2757         else if (ENGINE_COMPARE(ELM_BUFFER))
2758           {
2759              tmp_sd.ee = ecore_evas_buffer_new(1, 1);
2760           }
2761         else if (ENGINE_COMPARE(ELM_EWS))
2762           {
2763              tmp_sd.ee = ecore_evas_ews_new(0, 0, 1, 1);
2764           }
2765         else if (ENGINE_COMPARE(ELM_WAYLAND_SHM))
2766           {
2767              tmp_sd.ee = ecore_evas_wayland_shm_new(NULL, 0, 0, 0, 1, 1, 0);
2768           }
2769         else if (ENGINE_COMPARE(ELM_WAYLAND_EGL))
2770           {
2771              tmp_sd.ee = ecore_evas_wayland_egl_new(NULL, 0, 0, 0, 1, 1, 0);
2772           }
2773         else if (!strncmp(ENGINE_GET(), "shot:", 5))
2774           {
2775              tmp_sd.ee = ecore_evas_buffer_new(1, 1);
2776              ecore_evas_manual_render_set(tmp_sd.ee, EINA_TRUE);
2777              tmp_sd.shot.info = eina_stringshare_add
2778                  (ENGINE_GET() + 5);
2779           }
2780 #undef FALLBACK_TRY
2781         break;
2782      }
2783
2784    if (!tmp_sd.ee)
2785      {
2786         ERR("Cannot create window.");
2787         return NULL;
2788      }
2789
2790    obj = evas_object_smart_add
2791        (ecore_evas_get(tmp_sd.ee), _elm_win_smart_class_new());
2792
2793    ELM_WIN_DATA_GET(obj, sd);
2794
2795    /* copying possibly altered fields back */
2796 #define SD_CPY(_field)             \
2797   do                               \
2798     {                              \
2799        sd->_field = tmp_sd._field; \
2800     } while (0)
2801
2802    SD_CPY(ee);
2803    SD_CPY(img_obj);
2804    SD_CPY(shot.info);
2805 #undef SD_CPY
2806
2807    if ((trap) && (trap->add))
2808      sd->trap_data = trap->add(obj);
2809
2810    /* complementary actions, which depend on final smart data
2811     * pointer */
2812    if (type == ELM_WIN_INLINED_IMAGE)
2813      _win_inlined_image_set(sd);
2814
2815 #ifdef HAVE_ELEMENTARY_X
2816     else if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2817             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2818             ENGINE_COMPARE(ELM_SOFTWARE_8_X11) ||
2819             ENGINE_COMPARE(ELM_OPENGL_X11))
2820      {
2821         sd->x.client_message_handler = ecore_event_handler_add
2822             (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, sd);
2823         sd->x.property_handler = ecore_event_handler_add
2824             (ECORE_X_EVENT_WINDOW_PROPERTY, _elm_win_property_change, sd);
2825      }
2826 #endif
2827
2828    else if (!strncmp(ENGINE_GET(), "shot:", 5))
2829      _shot_init(sd);
2830
2831    sd->kbdmode = ELM_WIN_KEYBOARD_UNKNOWN;
2832    sd->indmode = ELM_WIN_INDICATOR_UNKNOWN;
2833
2834 #ifdef HAVE_ELEMENTARY_X
2835    _elm_win_xwindow_get(sd);
2836    if (sd->x.xwin)
2837      {
2838         ecore_x_io_error_handler_set(_elm_x_io_err, NULL);
2839      }
2840 #endif
2841
2842 #ifdef HAVE_ELEMENTARY_WAYLAND
2843    sd->wl.win = ecore_evas_wayland_window_get(sd->ee);
2844 #endif
2845
2846    if ((_elm_config->bgpixmap)
2847 #ifdef HAVE_ELEMENTARY_X
2848        &&
2849        (((sd->x.xwin) && (!ecore_x_screen_is_composited(0))) ||
2850            (!sd->x.xwin))
2851 #endif
2852       )
2853      TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
2854    // bg pixmap done by x - has other issues like can be redrawn by x before it
2855    // is filled/ready by app
2856    //     TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
2857
2858    sd->type = type;
2859    sd->parent = parent;
2860
2861    if (sd->parent)
2862      evas_object_event_callback_add
2863        (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, sd);
2864
2865    sd->evas = ecore_evas_get(sd->ee);
2866
2867    evas_object_color_set(obj, 0, 0, 0, 0);
2868    evas_object_move(obj, 0, 0);
2869    evas_object_resize(obj, 1, 1);
2870    evas_object_layer_set(obj, 50);
2871    evas_object_pass_events_set(obj, EINA_TRUE);
2872
2873    if (type == ELM_WIN_INLINED_IMAGE)
2874      elm_widget_parent2_set(obj, parent);
2875
2876    /* use own version of ecore_evas_object_associate() that does TRAP() */
2877    ecore_evas_data_set(sd->ee, "elm_win", sd);
2878
2879    evas_object_event_callback_add
2880      (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2881       _elm_win_obj_callback_changed_size_hints, sd);
2882
2883    evas_object_intercept_raise_callback_add
2884      (obj, _elm_win_obj_intercept_raise, sd);
2885    evas_object_intercept_lower_callback_add
2886      (obj, _elm_win_obj_intercept_lower, sd);
2887    evas_object_intercept_stack_above_callback_add
2888      (obj, _elm_win_obj_intercept_stack_above, sd);
2889    evas_object_intercept_stack_below_callback_add
2890      (obj, _elm_win_obj_intercept_stack_below, sd);
2891    evas_object_intercept_layer_set_callback_add
2892      (obj, _elm_win_obj_intercept_layer_set, sd);
2893    evas_object_intercept_show_callback_add
2894      (obj, _elm_win_obj_intercept_show, sd);
2895    evas_object_intercept_move_callback_add
2896      (obj, _ecore_evas_move_, sd);
2897
2898    TRAP(sd, name_class_set, name, _elm_appname);
2899    ecore_evas_callback_delete_request_set(sd->ee, _elm_win_delete_request);
2900    ecore_evas_callback_resize_set(sd->ee, _elm_win_resize);
2901    ecore_evas_callback_mouse_in_set(sd->ee, _elm_win_mouse_in);
2902    ecore_evas_callback_focus_in_set(sd->ee, _elm_win_focus_in);
2903    ecore_evas_callback_focus_out_set(sd->ee, _elm_win_focus_out);
2904    ecore_evas_callback_move_set(sd->ee, _elm_win_move);
2905    ecore_evas_callback_state_change_set(sd->ee, _elm_win_state_change);
2906    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _elm_win_cb_hide, sd);
2907    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _elm_win_cb_show, sd);
2908
2909    evas_image_cache_set(sd->evas, (_elm_config->image_cache * 1024));
2910    evas_font_cache_set(sd->evas, (_elm_config->font_cache * 1024));
2911
2912    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
2913      evas_font_path_append(sd->evas, fontpath);
2914
2915    if (!_elm_config->font_hinting)
2916      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_NONE);
2917    else if (_elm_config->font_hinting == 1)
2918      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_AUTO);
2919    else if (_elm_config->font_hinting == 2)
2920      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_BYTECODE);
2921
2922 #ifdef HAVE_ELEMENTARY_X
2923    _elm_win_xwin_update(sd);
2924 #endif
2925
2926    _elm_win_list = eina_list_append(_elm_win_list, obj);
2927    _elm_win_count++;
2928
2929    if (((fallback) && (!strcmp(fallback, "Software FB"))) ||
2930        ((!fallback) && (ENGINE_COMPARE(ELM_SOFTWARE_FB))))
2931      {
2932         TRAP(sd, fullscreen_set, 1);
2933      }
2934    else if ((type != ELM_WIN_INLINED_IMAGE) &&
2935             (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
2936              ENGINE_COMPARE(ELM_WAYLAND_EGL)))
2937      _elm_win_frame_add(sd, "default");
2938
2939    if (_elm_config->focus_highlight_enable)
2940      elm_win_focus_highlight_enabled_set(obj, EINA_TRUE);
2941
2942 #ifdef ELM_DEBUG
2943    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(sd->evas, "Control");
2944    evas_object_event_callback_add
2945      (obj, EVAS_CALLBACK_KEY_DOWN, _debug_key_down, sd);
2946
2947    if (evas_object_key_grab(obj, "F12", mask, 0, EINA_TRUE))
2948      INF("Ctrl+F12 key combination exclusive for dot tree generation\n");
2949    else
2950      ERR("failed to grab F12 key to elm widgets (dot) tree generation");
2951 #endif
2952
2953    if ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_ON) ||
2954        ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_AUTO) &&
2955            (((fallback) && (!strcmp(fallback, "Software FB"))) ||
2956                ((!fallback) && (ENGINE_COMPARE(ELM_SOFTWARE_FB))))))
2957      {
2958         Evas_Object *o;
2959         Evas_Coord mw = 1, mh = 1, hx = 0, hy = 0;
2960
2961         sd->pointer.obj = o = edje_object_add(ecore_evas_get(tmp_sd.ee));
2962         _elm_theme_object_set(obj, o, "pointer", "base", "default");
2963         edje_object_size_min_calc(o, &mw, &mh);
2964         evas_object_resize(o, mw, mh);
2965         edje_object_part_geometry_get(o, "elm.swallow.hotspot",
2966                                       &hx, &hy, NULL, NULL);
2967         sd->pointer.hot_x = hx;
2968         sd->pointer.hot_y = hy;
2969         evas_object_show(o);
2970         ecore_evas_object_cursor_set(tmp_sd.ee, o, EVAS_LAYER_MAX, hx, hy);
2971      }
2972    else if (_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_OFF)
2973      {
2974         // do nothing
2975      }
2976
2977    sd->wm_rot.wm_supported = ecore_evas_wm_rotation_supported_get(sd->ee);
2978    sd->wm_rot.preferred_rot = -1; // it means that elm_win doesn't use preferred rotation.
2979
2980    return obj;
2981 }
2982
2983 EAPI Evas_Object *
2984 elm_win_util_standard_add(const char *name,
2985                           const char *title)
2986 {
2987    Evas_Object *win, *bg;
2988
2989    win = elm_win_add(NULL, name, ELM_WIN_BASIC);
2990    if (!win) return NULL;
2991
2992    elm_win_title_set(win, title);
2993    bg = elm_bg_add(win);
2994    if (!bg)
2995      {
2996         evas_object_del(win);
2997         return NULL;
2998      }
2999    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3000    elm_win_resize_object_add(win, bg);
3001    evas_object_show(bg);
3002
3003    return win;
3004 }
3005
3006 EAPI void
3007 elm_win_resize_object_add(Evas_Object *obj,
3008                           Evas_Object *subobj)
3009 {
3010    Evas_Coord w, h;
3011
3012    ELM_WIN_CHECK(obj);
3013    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3014
3015    if (eina_list_data_find(sd->resize_objs, subobj)) return;
3016
3017    if (!ELM_WIDGET_DATA(sd)->api->sub_object_add(obj, subobj))
3018      ERR("could not add %p as sub object of %p", subobj, obj);
3019
3020    sd->resize_objs = eina_list_append(sd->resize_objs, subobj);
3021
3022    evas_object_event_callback_add
3023      (subobj, EVAS_CALLBACK_DEL, _elm_win_on_resize_obj_del, obj);
3024    evas_object_event_callback_add
3025      (subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3026      _elm_win_on_resize_obj_changed_size_hints, obj);
3027
3028    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
3029    evas_object_move(subobj, 0, 0);
3030    evas_object_resize(subobj, w, h);
3031
3032    _elm_win_resize_objects_eval(obj);
3033 }
3034
3035 EAPI void
3036 elm_win_resize_object_del(Evas_Object *obj,
3037                           Evas_Object *subobj)
3038 {
3039    ELM_WIN_CHECK(obj);
3040    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3041
3042    if (!ELM_WIDGET_DATA(sd)->api->sub_object_del(obj, subobj))
3043      ERR("could not remove sub object %p from %p", subobj, obj);
3044
3045    sd->resize_objs = eina_list_remove(sd->resize_objs, subobj);
3046
3047    evas_object_event_callback_del_full
3048      (subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3049      _elm_win_on_resize_obj_changed_size_hints, obj);
3050    evas_object_event_callback_del_full
3051      (subobj, EVAS_CALLBACK_DEL, _elm_win_on_resize_obj_del, obj);
3052
3053    _elm_win_resize_objects_eval(obj);
3054 }
3055
3056 EAPI void
3057 elm_win_title_set(Evas_Object *obj,
3058                   const char *title)
3059 {
3060    ELM_WIN_CHECK(obj);
3061    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3062
3063    if (!title) return;
3064    eina_stringshare_replace(&(sd->title), title);
3065    TRAP(sd, title_set, sd->title);
3066    if (sd->frame_obj)
3067      edje_object_part_text_escaped_set
3068        (sd->frame_obj, "elm.text.title", sd->title);
3069 }
3070
3071 EAPI const char *
3072 elm_win_title_get(const Evas_Object *obj)
3073 {
3074    ELM_WIN_CHECK(obj) NULL;
3075    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3076
3077    return sd->title;
3078 }
3079
3080 EAPI void
3081 elm_win_icon_name_set(Evas_Object *obj,
3082                       const char *icon_name)
3083 {
3084    ELM_WIN_CHECK(obj);
3085    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3086
3087    if (!icon_name) return;
3088    eina_stringshare_replace(&(sd->icon_name), icon_name);
3089 #ifdef HAVE_ELEMENTARY_X
3090    _elm_win_xwin_update(sd);
3091 #endif
3092 }
3093
3094 EAPI const char *
3095 elm_win_icon_name_get(const Evas_Object *obj)
3096 {
3097    ELM_WIN_CHECK(obj) NULL;
3098    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3099
3100    return sd->icon_name;
3101 }
3102
3103 EAPI void
3104 elm_win_role_set(Evas_Object *obj, const char *role)
3105 {
3106    ELM_WIN_CHECK(obj);
3107    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3108
3109    if (!role) return;
3110    eina_stringshare_replace(&(sd->role), role);
3111 #ifdef HAVE_ELEMENTARY_X
3112    _elm_win_xwin_update(sd);
3113 #endif
3114 }
3115
3116 EAPI const char *
3117 elm_win_role_get(const Evas_Object *obj)
3118 {
3119    ELM_WIN_CHECK(obj) NULL;
3120    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3121
3122    return sd->role;
3123 }
3124
3125 EAPI void
3126 elm_win_icon_object_set(Evas_Object *obj,
3127                         Evas_Object *icon)
3128 {
3129    ELM_WIN_CHECK(obj);
3130    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3131
3132    if (sd->icon)
3133      evas_object_event_callback_del_full
3134        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, sd);
3135    sd->icon = icon;
3136    if (sd->icon)
3137      evas_object_event_callback_add
3138        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, sd);
3139 #ifdef HAVE_ELEMENTARY_X
3140    _elm_win_xwin_update(sd);
3141 #endif
3142 }
3143
3144 EAPI const Evas_Object *
3145 elm_win_icon_object_get(const Evas_Object *obj)
3146 {
3147    ELM_WIN_CHECK(obj) NULL;
3148    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3149
3150    return sd->icon;
3151 }
3152
3153 EAPI void
3154 elm_win_autodel_set(Evas_Object *obj,
3155                     Eina_Bool autodel)
3156 {
3157    ELM_WIN_CHECK(obj);
3158    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3159
3160    sd->autodel = autodel;
3161 }
3162
3163 EAPI Eina_Bool
3164 elm_win_autodel_get(const Evas_Object *obj)
3165 {
3166    ELM_WIN_CHECK(obj) EINA_FALSE;
3167    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3168
3169    return sd->autodel;
3170 }
3171
3172 EAPI void
3173 elm_win_activate(Evas_Object *obj)
3174 {
3175    ELM_WIN_CHECK(obj);
3176    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3177
3178    TRAP(sd, activate);
3179 }
3180
3181 EAPI void
3182 elm_win_lower(Evas_Object *obj)
3183 {
3184    ELM_WIN_CHECK(obj);
3185    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3186
3187    TRAP(sd, lower);
3188 }
3189
3190 EAPI void
3191 elm_win_raise(Evas_Object *obj)
3192 {
3193    ELM_WIN_CHECK(obj);
3194    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3195
3196    TRAP(sd, raise);
3197 }
3198
3199 EAPI void
3200 elm_win_center(Evas_Object *obj,
3201                Eina_Bool h,
3202                Eina_Bool v)
3203 {
3204    int win_w, win_h, screen_w, screen_h, nx, ny;
3205
3206    ELM_WIN_CHECK(obj);
3207    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3208
3209    if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj)))
3210      return;
3211
3212    ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &screen_w, &screen_h);
3213    if ((!screen_w) || (!screen_h)) return;
3214
3215    evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
3216    if ((!win_w) || (!win_h)) return;
3217
3218    if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
3219    else nx = sd->screen.x;
3220    if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
3221    else ny = sd->screen.y;
3222    if (nx < 0) nx = 0;
3223    if (ny < 0) ny = 0;
3224
3225    evas_object_move(obj, nx, ny);
3226 }
3227
3228 EAPI void
3229 elm_win_borderless_set(Evas_Object *obj,
3230                        Eina_Bool borderless)
3231 {
3232    ELM_WIN_CHECK(obj);
3233    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3234
3235    TRAP(sd, borderless_set, borderless);
3236 #ifdef HAVE_ELEMENTARY_X
3237    _elm_win_xwin_update(sd);
3238 #endif
3239 }
3240
3241 EAPI Eina_Bool
3242 elm_win_borderless_get(const Evas_Object *obj)
3243 {
3244    ELM_WIN_CHECK(obj) EINA_FALSE;
3245    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3246
3247    return ecore_evas_borderless_get(sd->ee);
3248 }
3249
3250 EAPI void
3251 elm_win_shaped_set(Evas_Object *obj,
3252                    Eina_Bool shaped)
3253 {
3254    ELM_WIN_CHECK(obj);
3255    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3256
3257    TRAP(sd, shaped_set, shaped);
3258 #ifdef HAVE_ELEMENTARY_X
3259    _elm_win_xwin_update(sd);
3260 #endif
3261 }
3262
3263 EAPI Eina_Bool
3264 elm_win_shaped_get(const Evas_Object *obj)
3265 {
3266    ELM_WIN_CHECK(obj) EINA_FALSE;
3267    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3268
3269    return ecore_evas_shaped_get(sd->ee);
3270 }
3271
3272 EAPI void
3273 elm_win_alpha_set(Evas_Object *obj,
3274                   Eina_Bool alpha)
3275 {
3276    ELM_WIN_CHECK(obj);
3277    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3278
3279    if (sd->img_obj)
3280      {
3281         evas_object_image_alpha_set(sd->img_obj, alpha);
3282         ecore_evas_alpha_set(sd->ee, alpha);
3283      }
3284    else
3285      {
3286 #ifdef HAVE_ELEMENTARY_X
3287         if (sd->x.xwin)
3288           {
3289              if (alpha)
3290                {
3291                   if (!ecore_x_screen_is_composited(0))
3292                     elm_win_shaped_set(obj, alpha);
3293                   else
3294                     TRAP(sd, alpha_set, alpha);
3295                }
3296              else
3297                TRAP(sd, alpha_set, alpha);
3298              _elm_win_xwin_update(sd);
3299           }
3300         else
3301 #endif
3302           TRAP(sd, alpha_set, alpha);
3303      }
3304 }
3305
3306 EAPI Eina_Bool
3307 elm_win_alpha_get(const Evas_Object *obj)
3308 {
3309    ELM_WIN_CHECK(obj) EINA_FALSE;
3310    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3311
3312    if (sd->img_obj)
3313      {
3314         return evas_object_image_alpha_get(sd->img_obj);
3315      }
3316
3317    return ecore_evas_alpha_get(sd->ee);
3318 }
3319
3320 EAPI void
3321 elm_win_override_set(Evas_Object *obj,
3322                      Eina_Bool override)
3323 {
3324    ELM_WIN_CHECK(obj);
3325    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3326
3327    TRAP(sd, override_set, override);
3328 #ifdef HAVE_ELEMENTARY_X
3329    _elm_win_xwin_update(sd);
3330 #endif
3331 }
3332
3333 EAPI Eina_Bool
3334 elm_win_override_get(const Evas_Object *obj)
3335 {
3336    ELM_WIN_CHECK(obj) EINA_FALSE;
3337    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3338
3339    return ecore_evas_override_get(sd->ee);
3340 }
3341
3342 EAPI void
3343 elm_win_fullscreen_set(Evas_Object *obj,
3344                        Eina_Bool fullscreen)
3345 {
3346    ELM_WIN_CHECK(obj);
3347    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3348    // YYY: handle if sd->img_obj
3349    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3350        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
3351      {
3352         // these engines... can ONLY be fullscreen
3353         return;
3354      }
3355    else
3356      {
3357 //        sd->fullscreen = fullscreen;
3358
3359         if (fullscreen)
3360           {
3361              if (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
3362                  ENGINE_COMPARE(ELM_WAYLAND_EGL))
3363                _elm_win_frame_del(sd);
3364           }
3365         else
3366           {
3367              if (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
3368                  ENGINE_COMPARE(ELM_WAYLAND_EGL))
3369                _elm_win_frame_add(sd, "default");
3370
3371              evas_object_show(sd->frame_obj);
3372           }
3373
3374         TRAP(sd, fullscreen_set, fullscreen);
3375 #ifdef HAVE_ELEMENTARY_X
3376         _elm_win_xwin_update(sd);
3377 #endif
3378      }
3379 }
3380
3381 EAPI Eina_Bool
3382 elm_win_fullscreen_get(const Evas_Object *obj)
3383 {
3384    ELM_WIN_CHECK(obj) EINA_FALSE;
3385    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3386
3387    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3388        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
3389      {
3390         // these engines... can ONLY be fullscreen
3391         return EINA_TRUE;
3392      }
3393    else
3394      {
3395         return sd->fullscreen;
3396      }
3397 }
3398
3399 EAPI void
3400 elm_win_maximized_set(Evas_Object *obj,
3401                       Eina_Bool maximized)
3402 {
3403    ELM_WIN_CHECK(obj);
3404    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3405
3406 //   sd->maximized = maximized;
3407    // YYY: handle if sd->img_obj
3408    TRAP(sd, maximized_set, maximized);
3409 #ifdef HAVE_ELEMENTARY_X
3410    _elm_win_xwin_update(sd);
3411 #endif
3412 }
3413
3414 EAPI Eina_Bool
3415 elm_win_maximized_get(const Evas_Object *obj)
3416 {
3417    ELM_WIN_CHECK(obj) EINA_FALSE;
3418    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3419
3420    return sd->maximized;
3421 }
3422
3423 EAPI void
3424 elm_win_iconified_set(Evas_Object *obj,
3425                       Eina_Bool iconified)
3426 {
3427    ELM_WIN_CHECK(obj);
3428    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3429
3430 //   sd->iconified = iconified;
3431    TRAP(sd, iconified_set, iconified);
3432 #ifdef HAVE_ELEMENTARY_X
3433    _elm_win_xwin_update(sd);
3434 #endif
3435 }
3436
3437 EAPI Eina_Bool
3438 elm_win_iconified_get(const Evas_Object *obj)
3439 {
3440    ELM_WIN_CHECK(obj) EINA_FALSE;
3441    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3442
3443    return sd->iconified;
3444 }
3445
3446 EAPI void
3447 elm_win_withdrawn_set(Evas_Object *obj,
3448                       Eina_Bool withdrawn)
3449 {
3450    ELM_WIN_CHECK(obj);
3451    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3452
3453 //   sd->withdrawn = withdrawn;
3454    TRAP(sd, withdrawn_set, withdrawn);
3455 #ifdef HAVE_ELEMENTARY_X
3456    _elm_win_xwin_update(sd);
3457 #endif
3458 }
3459
3460 EAPI Eina_Bool
3461 elm_win_withdrawn_get(const Evas_Object *obj)
3462 {
3463    ELM_WIN_CHECK(obj) EINA_FALSE;
3464    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3465
3466    return sd->withdrawn;
3467 }
3468
3469 EAPI void
3470 elm_win_profiles_set(Evas_Object  *obj,
3471                      const char  **profiles,
3472                      unsigned int  num_profiles)
3473 {
3474    char **profiles_int;
3475    const char *str;
3476    unsigned int i, num;
3477    Eina_List *l;
3478
3479    ELM_WIN_CHECK(obj);
3480    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3481
3482    if (!profiles) return;
3483
3484    if (sd->profile.timer) ecore_timer_del(sd->profile.timer);
3485    sd->profile.timer = ecore_timer_add(0.1, _elm_win_profile_change_delay, sd);
3486    EINA_LIST_FREE(sd->profile.names, str) eina_stringshare_del(str);
3487
3488    for (i = 0; i < num_profiles; i++)
3489      {
3490         if ((profiles[i]) &&
3491             _elm_config_profile_exists(profiles[i]))
3492           {
3493              str = eina_stringshare_add(profiles[i]);
3494              sd->profile.names = eina_list_append(sd->profile.names, str);
3495           }
3496      }
3497
3498    num = eina_list_count(sd->profile.names);
3499    profiles_int = alloca(num * sizeof(char *));
3500
3501    if (profiles_int)
3502      {
3503         i = 0;
3504         EINA_LIST_FOREACH(sd->profile.names, l, str)
3505           {
3506              if (str)
3507                profiles_int[i] = strdup(str);
3508              else
3509                profiles_int[i] = NULL;
3510              i++;
3511           }
3512         ecore_evas_profiles_set(sd->ee, (const char **)profiles_int, i);
3513         for (i = 0; i < num; i++)
3514           {
3515              if (profiles_int[i]) free(profiles_int[i]);
3516           }
3517      }
3518    else
3519      ecore_evas_profiles_set(sd->ee, profiles, num_profiles);
3520 }
3521
3522 EAPI const char *
3523 elm_win_profile_get(const Evas_Object *obj)
3524 {
3525    ELM_WIN_CHECK(obj) NULL;
3526    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3527
3528    return sd->profile.name;
3529 }
3530
3531 EAPI void
3532 elm_win_urgent_set(Evas_Object *obj,
3533                    Eina_Bool urgent)
3534 {
3535    ELM_WIN_CHECK(obj);
3536    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3537
3538    sd->urgent = urgent;
3539    TRAP(sd, urgent_set, urgent);
3540 #ifdef HAVE_ELEMENTARY_X
3541    _elm_win_xwin_update(sd);
3542 #endif
3543 }
3544
3545 EAPI Eina_Bool
3546 elm_win_urgent_get(const Evas_Object *obj)
3547 {
3548    ELM_WIN_CHECK(obj) EINA_FALSE;
3549    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3550
3551    return sd->urgent;
3552 }
3553
3554 EAPI void
3555 elm_win_demand_attention_set(Evas_Object *obj,
3556                              Eina_Bool demand_attention)
3557 {
3558    ELM_WIN_CHECK(obj);
3559    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3560
3561    sd->demand_attention = demand_attention;
3562    TRAP(sd, demand_attention_set, demand_attention);
3563 #ifdef HAVE_ELEMENTARY_X
3564    _elm_win_xwin_update(sd);
3565 #endif
3566 }
3567
3568 EAPI Eina_Bool
3569 elm_win_demand_attention_get(const Evas_Object *obj)
3570 {
3571    ELM_WIN_CHECK(obj) EINA_FALSE;
3572    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3573
3574    return sd->demand_attention;
3575 }
3576
3577 EAPI void
3578 elm_win_modal_set(Evas_Object *obj,
3579                   Eina_Bool modal)
3580 {
3581    ELM_WIN_CHECK(obj);
3582    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3583
3584    sd->modal = modal;
3585    TRAP(sd, modal_set, modal);
3586 #ifdef HAVE_ELEMENTARY_X
3587    _elm_win_xwin_update(sd);
3588 #endif
3589 }
3590
3591 EAPI Eina_Bool
3592 elm_win_modal_get(const Evas_Object *obj)
3593 {
3594    ELM_WIN_CHECK(obj) EINA_FALSE;
3595    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3596
3597    return sd->modal;
3598 }
3599
3600 EAPI void
3601 elm_win_aspect_set(Evas_Object *obj,
3602                    double aspect)
3603 {
3604    ELM_WIN_CHECK(obj);
3605    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3606
3607    sd->aspect = aspect;
3608    TRAP(sd, aspect_set, aspect);
3609 #ifdef HAVE_ELEMENTARY_X
3610    _elm_win_xwin_update(sd);
3611 #endif
3612 }
3613
3614 EAPI double
3615 elm_win_aspect_get(const Evas_Object *obj)
3616 {
3617    ELM_WIN_CHECK(obj) 0.0;
3618    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
3619
3620    return sd->aspect;
3621 }
3622
3623 EAPI void
3624 elm_win_size_base_set(Evas_Object *obj, int w, int h)
3625 {
3626    ELM_WIN_CHECK(obj);
3627    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3628    sd->size_base_w = w;
3629    sd->size_base_h = h;
3630    TRAP(sd, size_base_set, w, h);
3631 #ifdef HAVE_ELEMENTARY_X
3632    _elm_win_xwin_update(sd);
3633 #endif
3634 }
3635
3636 EAPI void
3637 elm_win_size_base_get(Evas_Object *obj, int *w, int *h)
3638 {
3639    ELM_WIN_CHECK(obj);
3640    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3641    if (w) *w = sd->size_base_w;
3642    if (w) *h = sd->size_base_h;
3643 }
3644
3645 EAPI void
3646 elm_win_size_step_set(Evas_Object *obj, int w, int h)
3647 {
3648    ELM_WIN_CHECK(obj);
3649    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3650    sd->size_step_w = w;
3651    sd->size_step_h = h;
3652    TRAP(sd, size_step_set, w, h);
3653 #ifdef HAVE_ELEMENTARY_X
3654    _elm_win_xwin_update(sd);
3655 #endif
3656 }
3657
3658 EAPI void
3659 elm_win_size_step_get(Evas_Object *obj, int *w, int *h)
3660 {
3661    ELM_WIN_CHECK(obj);
3662    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3663    if (w) *w = sd->size_step_w;
3664    if (w) *h = sd->size_step_h;
3665 }
3666
3667 EAPI void
3668 elm_win_layer_set(Evas_Object *obj,
3669                   int layer)
3670 {
3671    ELM_WIN_CHECK(obj);
3672    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3673
3674    TRAP(sd, layer_set, layer);
3675 #ifdef HAVE_ELEMENTARY_X
3676    _elm_win_xwin_update(sd);
3677 #endif
3678 }
3679
3680 EAPI int
3681 elm_win_layer_get(const Evas_Object *obj)
3682 {
3683    ELM_WIN_CHECK(obj) - 1;
3684    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3685
3686    return ecore_evas_layer_get(sd->ee);
3687 }
3688
3689 EAPI void
3690 elm_win_norender_push(Evas_Object *obj)
3691 {
3692    ELM_WIN_CHECK(obj);
3693    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3694
3695    sd->norender++;
3696    if (sd->norender == 1) ecore_evas_manual_render_set(sd->ee, EINA_TRUE);
3697 }
3698
3699 EAPI void
3700 elm_win_norender_pop(Evas_Object *obj)
3701 {
3702    ELM_WIN_CHECK(obj);
3703    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3704
3705    if (sd->norender <= 0) return;
3706    sd->norender--;
3707    if (sd->norender == 0) ecore_evas_manual_render_set(sd->ee, EINA_FALSE);
3708 }
3709
3710 EAPI int
3711 elm_win_norender_get(Evas_Object *obj)
3712 {
3713    ELM_WIN_CHECK(obj) - 1;
3714    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3715    return sd->norender;
3716 }
3717
3718 EAPI void
3719 elm_win_render(Evas_Object *obj)
3720 {
3721    ELM_WIN_CHECK(obj);
3722    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3723    ecore_evas_manual_render(sd->ee);
3724 }
3725
3726 static int
3727 _win_rotation_degree_check(int rotation)
3728 {
3729    if ((rotation > 360) || (rotation < 0))
3730      {
3731         WRN("Rotation degree should be 0 ~ 360 (passed degree: %d)", rotation);
3732         rotation %= 360;
3733         if (rotation < 0) rotation += 360;
3734      }
3735    return rotation;
3736 }
3737
3738 static void
3739 _win_rotate(Evas_Object *obj, Elm_Win_Smart_Data *sd, int rotation, Eina_Bool resize)
3740 {
3741    rotation = _win_rotation_degree_check(rotation);
3742    if (sd->rot == rotation) return;
3743    sd->rot = rotation;
3744    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
3745    else TRAP(sd, rotation_set, rotation);
3746    evas_object_size_hint_min_set(obj, -1, -1);
3747    evas_object_size_hint_max_set(obj, -1, -1);
3748    _elm_win_resize_objects_eval(obj);
3749 #ifdef HAVE_ELEMENTARY_X
3750    _elm_win_xwin_update(sd);
3751 #endif
3752    elm_widget_orientation_set(obj, rotation);
3753    evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
3754 }
3755
3756 EAPI void
3757 elm_win_rotation_set(Evas_Object *obj,
3758                      int rotation)
3759 {
3760    ELM_WIN_CHECK(obj);
3761    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3762    _win_rotate(obj, sd, rotation, EINA_FALSE);
3763 }
3764
3765 EAPI void
3766 elm_win_rotation_with_resize_set(Evas_Object *obj,
3767                                  int rotation)
3768 {
3769    ELM_WIN_CHECK(obj);
3770    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3771    _win_rotate(obj, sd, rotation, EINA_TRUE);
3772 }
3773
3774 EAPI int
3775 elm_win_rotation_get(const Evas_Object *obj)
3776 {
3777    ELM_WIN_CHECK(obj) - 1;
3778    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3779
3780    return sd->rot;
3781 }
3782
3783 EAPI Eina_Bool
3784 elm_win_wm_rotation_supported_get(const Evas_Object *obj)
3785 {
3786    ELM_WIN_CHECK(obj) EINA_FALSE;
3787    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3788    return sd->wm_rot.wm_supported;
3789 }
3790
3791 /* This will unset a preferred rotation, if given preferred rotation is '-1'.
3792  */
3793 EAPI void
3794 elm_win_wm_rotation_preferred_rotation_set(Evas_Object *obj,
3795                                            const int rotation)
3796 {
3797    int rot;
3798
3799    ELM_WIN_CHECK(obj);
3800    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3801
3802    if (!sd->wm_rot.use)
3803      sd->wm_rot.use = EINA_TRUE;
3804
3805    // '-1' means that elm_win doesn't use preferred rotation.
3806    if (rotation == -1)
3807      rot = -1;
3808    else
3809      rot = _win_rotation_degree_check(rotation);
3810
3811    if (sd->wm_rot.preferred_rot == rot) return;
3812    sd->wm_rot.preferred_rot = rot;
3813
3814    ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
3815 }
3816
3817 EAPI int
3818 elm_win_wm_rotation_preferred_rotation_get(const Evas_Object *obj)
3819 {
3820    ELM_WIN_CHECK(obj) -1;
3821    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3822    if (!sd->wm_rot.use) return -1;
3823    return sd->wm_rot.preferred_rot;
3824 }
3825
3826 EAPI void
3827 elm_win_wm_rotation_available_rotations_set(Evas_Object *obj,
3828                                             const int   *rotations,
3829                                             unsigned int count)
3830 {
3831    unsigned int i;
3832    int r;
3833
3834    ELM_WIN_CHECK(obj);
3835    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3836
3837    if (!sd->wm_rot.use)
3838      sd->wm_rot.use = EINA_TRUE;
3839
3840    if (sd->wm_rot.rots) free(sd->wm_rot.rots);
3841
3842    sd->wm_rot.rots = NULL;
3843    sd->wm_rot.count = 0;
3844
3845    if (count > 0)
3846      {
3847         sd->wm_rot.rots = calloc(count, sizeof(int));
3848         if (!sd->wm_rot.rots) return;
3849         for (i = 0; i < count; i++)
3850           {
3851              r = _win_rotation_degree_check(rotations[i]);
3852              sd->wm_rot.rots[i] = r;
3853           }
3854      }
3855
3856    sd->wm_rot.count = count;
3857
3858    ecore_evas_wm_rotation_available_rotations_set(sd->ee,
3859                                                   sd->wm_rot.rots,
3860                                                   sd->wm_rot.count);
3861 }
3862
3863 EAPI Eina_Bool
3864 elm_win_wm_rotation_available_rotations_get(const Evas_Object *obj,
3865                                             int              **rotations,
3866                                             unsigned int      *count)
3867 {
3868    ELM_WIN_CHECK(obj) EINA_FALSE;
3869    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3870    if (!sd->wm_rot.use) return EINA_FALSE;
3871
3872    if (sd->wm_rot.count > 0)
3873      {
3874         if ((rotations) && (*rotations))
3875           {
3876              *rotations = calloc(sd->wm_rot.count, sizeof(int));
3877              if (*rotations)
3878                {
3879                   memcpy(*rotations,
3880                          sd->wm_rot.rots,
3881                          sizeof(int) * sd->wm_rot.count);
3882                }
3883           }
3884      }
3885
3886    if (count) *count = sd->wm_rot.count;
3887
3888    return EINA_TRUE;
3889 }
3890
3891 EAPI void
3892 elm_win_sticky_set(Evas_Object *obj,
3893                    Eina_Bool sticky)
3894 {
3895    ELM_WIN_CHECK(obj);
3896    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3897
3898 //   sd->sticky = sticky;
3899    TRAP(sd, sticky_set, sticky);
3900 #ifdef HAVE_ELEMENTARY_X
3901    _elm_win_xwin_update(sd);
3902 #endif
3903 }
3904
3905 EAPI Eina_Bool
3906 elm_win_sticky_get(const Evas_Object *obj)
3907 {
3908    ELM_WIN_CHECK(obj) EINA_FALSE;
3909    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3910
3911    return sd->sticky;
3912 }
3913
3914 EAPI void
3915 elm_win_keyboard_mode_set(Evas_Object *obj,
3916                           Elm_Win_Keyboard_Mode mode)
3917 {
3918    ELM_WIN_CHECK(obj);
3919    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3920
3921    if (mode == sd->kbdmode) return;
3922 #ifdef HAVE_ELEMENTARY_X
3923    _elm_win_xwindow_get(sd);
3924 #endif
3925    sd->kbdmode = mode;
3926 #ifdef HAVE_ELEMENTARY_X
3927    if (sd->x.xwin)
3928      ecore_x_e_virtual_keyboard_state_set
3929        (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
3930 #endif
3931 }
3932
3933 EAPI Elm_Win_Keyboard_Mode
3934 elm_win_keyboard_mode_get(const Evas_Object *obj)
3935 {
3936    ELM_WIN_CHECK(obj) ELM_WIN_KEYBOARD_UNKNOWN;
3937    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_KEYBOARD_UNKNOWN);
3938
3939    return sd->kbdmode;
3940 }
3941
3942 EAPI void
3943 elm_win_keyboard_win_set(Evas_Object *obj,
3944                          Eina_Bool is_keyboard)
3945 {
3946    ELM_WIN_CHECK(obj);
3947    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3948
3949 #ifdef HAVE_ELEMENTARY_X
3950    _elm_win_xwindow_get(sd);
3951    if (sd->x.xwin)
3952      ecore_x_e_virtual_keyboard_set(sd->x.xwin, is_keyboard);
3953 #else
3954    (void)is_keyboard;
3955 #endif
3956 }
3957
3958 EAPI Eina_Bool
3959 elm_win_keyboard_win_get(const Evas_Object *obj)
3960 {
3961    ELM_WIN_CHECK(obj) EINA_FALSE;
3962    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3963
3964 #ifdef HAVE_ELEMENTARY_X
3965    _elm_win_xwindow_get(sd);
3966    if (sd->x.xwin)
3967      return ecore_x_e_virtual_keyboard_get(sd->x.xwin);
3968 #endif
3969    return EINA_FALSE;
3970 }
3971
3972 EAPI void
3973 elm_win_indicator_mode_set(Evas_Object *obj,
3974                            Elm_Win_Indicator_Mode mode)
3975 {
3976    ELM_WIN_CHECK(obj);
3977    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3978
3979    if (mode == sd->indmode) return;
3980 #ifdef HAVE_ELEMENTARY_X
3981    _elm_win_xwindow_get(sd);
3982 #endif
3983    sd->indmode = mode;
3984 #ifdef HAVE_ELEMENTARY_X
3985    if (sd->x.xwin)
3986      {
3987         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
3988           ecore_x_e_illume_indicator_state_set
3989             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
3990         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
3991           ecore_x_e_illume_indicator_state_set
3992             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
3993      }
3994 #endif
3995    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
3996 }
3997
3998 EAPI Elm_Win_Indicator_Mode
3999 elm_win_indicator_mode_get(const Evas_Object *obj)
4000 {
4001    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_UNKNOWN;
4002    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_UNKNOWN);
4003
4004    return sd->indmode;
4005 }
4006
4007 EAPI void
4008 elm_win_indicator_opacity_set(Evas_Object *obj,
4009                               Elm_Win_Indicator_Opacity_Mode mode)
4010 {
4011    ELM_WIN_CHECK(obj);
4012    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4013
4014    if (mode == sd->ind_o_mode) return;
4015    sd->ind_o_mode = mode;
4016 #ifdef HAVE_ELEMENTARY_X
4017    _elm_win_xwindow_get(sd);
4018    if (sd->x.xwin)
4019      {
4020         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
4021           ecore_x_e_illume_indicator_opacity_set
4022             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_OPAQUE);
4023         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
4024           ecore_x_e_illume_indicator_opacity_set
4025             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
4026         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
4027           ecore_x_e_illume_indicator_opacity_set
4028             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
4029      }
4030 #endif
4031    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4032 }
4033
4034 EAPI Elm_Win_Indicator_Opacity_Mode
4035 elm_win_indicator_opacity_get(const Evas_Object *obj)
4036 {
4037    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_OPACITY_UNKNOWN;
4038    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_OPACITY_UNKNOWN);
4039
4040    return sd->ind_o_mode;
4041 }
4042
4043 EAPI void
4044 elm_win_indicator_type_set(Evas_Object *obj,
4045                               Elm_Win_Indicator_Type_Mode mode)
4046 {
4047    ELM_WIN_CHECK(obj);
4048    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4049
4050    if (mode == sd->ind_t_mode) return;
4051    sd->ind_t_mode = mode;
4052 #ifdef HAVE_ELEMENTARY_X
4053    _elm_win_xwindow_get(sd);
4054    if (sd->x.xwin)
4055      {
4056         if (sd->ind_t_mode == ELM_WIN_INDICATOR_TYPE_1)
4057           ecore_x_e_illume_indicator_type_set
4058             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TYPE_1);
4059         else if (sd->ind_t_mode == ELM_WIN_INDICATOR_TYPE_2)
4060           ecore_x_e_illume_indicator_type_set
4061             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TYPE_2);
4062      }
4063 #endif
4064    //evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4065 }
4066
4067 EAPI Elm_Win_Indicator_Type_Mode
4068 elm_win_indicator_type_get(const Evas_Object *obj)
4069 {
4070    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_TYPE_UNKNOWN;
4071    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_TYPE_UNKNOWN);
4072
4073    return sd->ind_t_mode;
4074 }
4075 EAPI void
4076 elm_win_screen_position_get(const Evas_Object *obj,
4077                             int *x,
4078                             int *y)
4079 {
4080    ELM_WIN_CHECK(obj);
4081    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4082
4083    if (x) *x = sd->screen.x;
4084    if (y) *y = sd->screen.y;
4085 }
4086
4087 EAPI Eina_Bool
4088 elm_win_focus_get(const Evas_Object *obj)
4089 {
4090    ELM_WIN_CHECK(obj) EINA_FALSE;
4091    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4092
4093    return ecore_evas_focus_get(sd->ee);
4094 }
4095
4096 EAPI void
4097 elm_win_screen_constrain_set(Evas_Object *obj,
4098                              Eina_Bool constrain)
4099 {
4100    ELM_WIN_CHECK(obj);
4101    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4102
4103    sd->constrain = !!constrain;
4104 }
4105
4106 EAPI Eina_Bool
4107 elm_win_screen_constrain_get(Evas_Object *obj)
4108 {
4109    ELM_WIN_CHECK(obj) EINA_FALSE;
4110    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4111
4112    return sd->constrain;
4113 }
4114
4115 EAPI void
4116 elm_win_screen_size_get(const Evas_Object *obj,
4117                         int *x,
4118                         int *y,
4119                         int *w,
4120                         int *h)
4121 {
4122    ELM_WIN_CHECK(obj);
4123    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4124
4125    ecore_evas_screen_geometry_get(sd->ee, x, y, w, h);
4126 }
4127
4128 EAPI void
4129 elm_win_screen_dpi_get(const Evas_Object *obj,
4130                        int *xdpi,
4131                        int *ydpi)
4132 {
4133    ELM_WIN_CHECK(obj);
4134    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4135
4136    ecore_evas_screen_dpi_get(sd->ee, xdpi, ydpi);
4137 }
4138
4139 EAPI void
4140 elm_win_conformant_set(Evas_Object *obj,
4141                        Eina_Bool conformant)
4142 {
4143    ELM_WIN_CHECK(obj);
4144    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4145
4146 #ifdef HAVE_ELEMENTARY_X
4147    _elm_win_xwindow_get(sd);
4148    if (sd->x.xwin)
4149      ecore_x_e_illume_conformant_set(sd->x.xwin, conformant);
4150 #else
4151    (void)conformant;
4152 #endif
4153 }
4154
4155 EAPI Eina_Bool
4156 elm_win_conformant_get(const Evas_Object *obj)
4157 {
4158    ELM_WIN_CHECK(obj) EINA_FALSE;
4159    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4160
4161 #ifdef HAVE_ELEMENTARY_X
4162    _elm_win_xwindow_get(sd);
4163    if (sd->x.xwin)
4164      return ecore_x_e_illume_conformant_get(sd->x.xwin);
4165 #endif
4166    return EINA_FALSE;
4167 }
4168
4169 EAPI void
4170 elm_win_quickpanel_set(Evas_Object *obj,
4171                        Eina_Bool quickpanel)
4172 {
4173    ELM_WIN_CHECK(obj);
4174    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4175 #ifdef HAVE_ELEMENTARY_X
4176    _elm_win_xwindow_get(sd);
4177    if (sd->x.xwin)
4178      {
4179         ecore_x_e_illume_quickpanel_set(sd->x.xwin, quickpanel);
4180         if (quickpanel)
4181           {
4182              Ecore_X_Window_State states[2];
4183
4184              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
4185              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
4186              ecore_x_netwm_window_state_set(sd->x.xwin, states, 2);
4187              ecore_x_icccm_hints_set(sd->x.xwin, 0, 0, 0, 0, 0, 0, 0);
4188           }
4189      }
4190 #else
4191    (void)quickpanel;
4192 #endif
4193 }
4194
4195 EAPI Eina_Bool
4196 elm_win_quickpanel_get(const Evas_Object *obj)
4197 {
4198    ELM_WIN_CHECK(obj) EINA_FALSE;
4199    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4200
4201 #ifdef HAVE_ELEMENTARY_X
4202    _elm_win_xwindow_get(sd);
4203    if (sd->x.xwin)
4204      return ecore_x_e_illume_quickpanel_get(sd->x.xwin);
4205 #endif
4206    return EINA_FALSE;
4207 }
4208
4209 EAPI void
4210 elm_win_quickpanel_priority_major_set(Evas_Object *obj,
4211                                       int priority)
4212 {
4213    ELM_WIN_CHECK(obj);
4214    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4215
4216 #ifdef HAVE_ELEMENTARY_X
4217    _elm_win_xwindow_get(sd);
4218    if (sd->x.xwin)
4219      ecore_x_e_illume_quickpanel_priority_major_set(sd->x.xwin, priority);
4220 #else
4221    (void)priority;
4222 #endif
4223 }
4224
4225 EAPI int
4226 elm_win_quickpanel_priority_major_get(const Evas_Object *obj)
4227 {
4228    ELM_WIN_CHECK(obj) - 1;
4229    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4230
4231 #ifdef HAVE_ELEMENTARY_X
4232    _elm_win_xwindow_get(sd);
4233    if (sd->x.xwin)
4234      return ecore_x_e_illume_quickpanel_priority_major_get(sd->x.xwin);
4235 #endif
4236    return -1;
4237 }
4238
4239 EAPI void
4240 elm_win_quickpanel_priority_minor_set(Evas_Object *obj,
4241                                       int priority)
4242 {
4243    ELM_WIN_CHECK(obj);
4244    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4245
4246 #ifdef HAVE_ELEMENTARY_X
4247    _elm_win_xwindow_get(sd);
4248    if (sd->x.xwin)
4249      ecore_x_e_illume_quickpanel_priority_minor_set(sd->x.xwin, priority);
4250 #else
4251    (void)priority;
4252 #endif
4253 }
4254
4255 EAPI int
4256 elm_win_quickpanel_priority_minor_get(const Evas_Object *obj)
4257 {
4258    ELM_WIN_CHECK(obj) - 1;
4259    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4260
4261 #ifdef HAVE_ELEMENTARY_X
4262    _elm_win_xwindow_get(sd);
4263    if (sd->x.xwin)
4264      return ecore_x_e_illume_quickpanel_priority_minor_get(sd->x.xwin);
4265 #endif
4266    return -1;
4267 }
4268
4269 EAPI void
4270 elm_win_quickpanel_zone_set(Evas_Object *obj,
4271                             int zone)
4272 {
4273    ELM_WIN_CHECK(obj);
4274    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4275
4276 #ifdef HAVE_ELEMENTARY_X
4277    _elm_win_xwindow_get(sd);
4278    if (sd->x.xwin)
4279      ecore_x_e_illume_quickpanel_zone_set(sd->x.xwin, zone);
4280 #else
4281    (void)zone;
4282 #endif
4283 }
4284
4285 EAPI int
4286 elm_win_quickpanel_zone_get(const Evas_Object *obj)
4287 {
4288    ELM_WIN_CHECK(obj) 0;
4289    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0);
4290
4291 #ifdef HAVE_ELEMENTARY_X
4292    _elm_win_xwindow_get(sd);
4293    if (sd->x.xwin)
4294      return ecore_x_e_illume_quickpanel_zone_get(sd->x.xwin);
4295 #endif
4296    return 0;
4297 }
4298
4299 EAPI void
4300 elm_win_prop_focus_skip_set(Evas_Object *obj,
4301                             Eina_Bool skip)
4302 {
4303    ELM_WIN_CHECK(obj);
4304    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4305
4306    sd->skip_focus = skip;
4307    TRAP(sd, focus_skip_set, skip);
4308 }
4309
4310 EAPI void
4311 elm_win_illume_command_send(Evas_Object *obj,
4312                             Elm_Illume_Command command,
4313                             void *params __UNUSED__)
4314 {
4315    ELM_WIN_CHECK(obj);
4316    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4317
4318 #ifdef HAVE_ELEMENTARY_X
4319    _elm_win_xwindow_get(sd);
4320    if (sd->x.xwin)
4321      {
4322         switch (command)
4323           {
4324            case ELM_ILLUME_COMMAND_FOCUS_BACK:
4325              ecore_x_e_illume_focus_back_send(sd->x.xwin);
4326              break;
4327
4328            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
4329              ecore_x_e_illume_focus_forward_send(sd->x.xwin);
4330              break;
4331
4332            case ELM_ILLUME_COMMAND_FOCUS_HOME:
4333              ecore_x_e_illume_focus_home_send(sd->x.xwin);
4334              break;
4335
4336            case ELM_ILLUME_COMMAND_CLOSE:
4337              ecore_x_e_illume_close_send(sd->x.xwin);
4338              break;
4339
4340            default:
4341              break;
4342           }
4343      }
4344 #else
4345    (void)command;
4346 #endif
4347 }
4348
4349 EAPI Evas_Object *
4350 elm_win_inlined_image_object_get(Evas_Object *obj)
4351 {
4352    ELM_WIN_CHECK(obj) NULL;
4353    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4354
4355    return sd->img_obj;
4356 }
4357
4358 EAPI void
4359 elm_win_focus_highlight_enabled_set(Evas_Object *obj,
4360                                     Eina_Bool enabled)
4361 {
4362    ELM_WIN_CHECK(obj);
4363    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4364
4365    enabled = !!enabled;
4366    if (sd->focus_highlight.enabled == enabled)
4367      return;
4368
4369    sd->focus_highlight.enabled = enabled;
4370
4371    if (sd->focus_highlight.enabled)
4372      _elm_win_focus_highlight_init(sd);
4373    else
4374      _elm_win_focus_highlight_shutdown(sd);
4375 }
4376
4377 EAPI Eina_Bool
4378 elm_win_focus_highlight_enabled_get(const Evas_Object *obj)
4379 {
4380    ELM_WIN_CHECK(obj) EINA_FALSE;
4381    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4382
4383    return sd->focus_highlight.enabled;
4384 }
4385
4386 EAPI void
4387 elm_win_focus_highlight_style_set(Evas_Object *obj,
4388                                   const char *style)
4389 {
4390    ELM_WIN_CHECK(obj);
4391    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4392
4393    eina_stringshare_replace(&sd->focus_highlight.style, style);
4394    sd->focus_highlight.changed_theme = EINA_TRUE;
4395    _elm_win_focus_highlight_reconfigure_job_start(sd);
4396 }
4397
4398 EAPI const char *
4399 elm_win_focus_highlight_style_get(const Evas_Object *obj)
4400 {
4401    ELM_WIN_CHECK(obj) NULL;
4402    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4403
4404    return sd->focus_highlight.style;
4405 }
4406
4407 EAPI Eina_Bool
4408 elm_win_socket_listen(Evas_Object *obj,
4409                       const char *svcname,
4410                       int svcnum,
4411                       Eina_Bool svcsys)
4412 {
4413    ELM_WIN_CHECK(obj) EINA_FALSE;
4414    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4415
4416    if (!sd->ee) return EINA_FALSE;
4417
4418    if (!ecore_evas_extn_socket_listen(sd->ee, svcname, svcnum, svcsys))
4419      return EINA_FALSE;
4420
4421    return EINA_TRUE;
4422 }
4423
4424 /* windowing specific calls - shall we do this differently? */
4425
4426 EAPI Ecore_X_Window
4427 elm_win_xwindow_get(const Evas_Object *obj)
4428 {
4429    if (!obj) return 0;
4430
4431    if (!evas_object_smart_type_check_ptr(obj, WIN_SMART_NAME))
4432      {
4433         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4434         return _elm_ee_xwin_get(ee);
4435      }
4436
4437    ELM_WIN_CHECK(obj) 0;
4438    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0);
4439
4440 #ifdef HAVE_ELEMENTARY_X
4441    if (sd->x.xwin) return sd->x.xwin;
4442    if (sd->parent) return elm_win_xwindow_get(sd->parent);
4443 #endif
4444    return 0;
4445 }
4446
4447 EAPI Ecore_Wl_Window *
4448 elm_win_wl_window_get(const Evas_Object *obj)
4449 {
4450    if (!obj) return NULL;
4451
4452    if (!evas_object_smart_type_check_ptr(obj, WIN_SMART_NAME))
4453      {
4454         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4455         return ecore_evas_wayland_window_get(ee);
4456      }
4457
4458    ELM_WIN_CHECK(obj) NULL;
4459    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4460 #if HAVE_ELEMENTARY_WAYLAND
4461    if (sd->wl.win) return sd->wl.win;
4462    if (sd->parent) return elm_win_wl_window_get(sd->parent);
4463 #endif
4464    return NULL;
4465 }
4466
4467 EAPI Eina_Bool
4468 elm_win_trap_set(const Elm_Win_Trap *t)
4469 {
4470    DBG("old %p, new %p", trap, t);
4471
4472    if ((t) && (t->version != ELM_WIN_TRAP_VERSION))
4473      {
4474         CRITICAL("trying to set a trap version %lu while %lu was expected!",
4475                  t->version, ELM_WIN_TRAP_VERSION);
4476         return EINA_FALSE;
4477      }
4478
4479    trap = t;
4480    return EINA_TRUE;
4481 }
4482
4483 EAPI void
4484 elm_win_floating_mode_set(Evas_Object *obj, Eina_Bool floating)
4485 {
4486    ELM_WIN_CHECK(obj);
4487    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4488
4489    if (floating == sd->floating) return;
4490    sd->floating = floating;
4491 #ifdef HAVE_ELEMENTARY_X
4492    _elm_win_xwindow_get(sd);
4493    if (sd->x.xwin)
4494      {
4495         if (sd->floating)
4496           ecore_x_e_illume_window_state_set
4497              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_FLOATING);
4498         else
4499           ecore_x_e_illume_window_state_set
4500              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_NORMAL);
4501      }
4502 #endif
4503 }
4504
4505 EAPI Eina_Bool
4506 elm_win_floating_mode_get(const Evas_Object *obj)
4507 {
4508    ELM_WIN_CHECK(obj) EINA_FALSE;
4509    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4510
4511    return sd->floating;
4512 }
4513