1 #include "e.h"
2 #include "e_mod_main.h"
3 
4 /* gadcon requirements */
5 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
6 static void             _gc_shutdown(E_Gadcon_Client *gcc);
7 static void             _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
8 static const char      *_gc_label(const E_Gadcon_Client_Class *client_class);
9 static Evas_Object     *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
10 static const char      *_gc_id_new(const E_Gadcon_Client_Class *client_class);
11 static void             _gc_id_del(const E_Gadcon_Client_Class *client_class, const char *id);
12 /* and actually define the gadcon class that this module provides (just 1) */
13 static const E_Gadcon_Client_Class _gadcon_class =
14 {
15    GADCON_CLIENT_CLASS_VERSION,
16    "ibox",
17    {
18       _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, _gc_id_del,
19       e_gadcon_site_is_not_toolbar
20    },
21    E_GADCON_CLIENT_STYLE_INSET
22 };
23 
24 /* actual module specifics */
25 
26 typedef struct _Instance  Instance;
27 
28 typedef struct _IBox      IBox;
29 typedef struct _IBox_Icon IBox_Icon;
30 
31 struct _Instance
32 {
33    E_Gadcon_Client *gcc;
34    E_Comp_Object_Mover *iconify_provider;
35    Evas_Object     *o_ibox;
36    IBox            *ibox;
37    E_Drop_Handler  *drop_handler;
38    Config_Item     *ci;
39    E_Gadcon_Orient  orient;
40 };
41 
42 struct _IBox
43 {
44    Instance    *inst;
45    Evas_Object *o_box;
46    Evas_Object *o_drop;
47    Evas_Object *o_drop_over;
48    Evas_Object *o_empty;
49    IBox_Icon   *ic_drop_before;
50    int          drop_before;
51    Eina_List   *icons;
52    E_Zone      *zone;
53    Evas_Coord   dnd_x, dnd_y;
54 };
55 
56 struct _IBox_Icon
57 {
58    IBox        *ibox;
59    Evas_Object *o_holder;
60    Evas_Object *o_icon;
61    Evas_Object *o_holder2;
62    Evas_Object *o_icon2;
63    E_Client    *client;
64    struct
65    {
66       unsigned char start E_BITFIELD;
67       unsigned char dnd E_BITFIELD;
68       int           x, y;
69       int           dx, dy;
70    } drag;
71 };
72 
73 static IBox        *_ibox_new(Evas_Object *parent, E_Zone *zone);
74 static void         _ibox_free(IBox *b);
75 static void         _ibox_cb_empty_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
76 static void         _ibox_empty_handle(IBox *b);
77 static void         _ibox_fill(IBox *b);
78 static void         _ibox_empty(IBox *b);
79 static void         _ibox_orient_set(IBox *b, int horizontal);
80 static void         _ibox_resize_handle(IBox *b);
81 static void         _ibox_instance_drop_zone_recalc(Instance *inst);
82 static IBox_Icon   *_ibox_icon_find(IBox *b, E_Client *ec);
83 static IBox_Icon   *_ibox_icon_at_coord(IBox *b, Evas_Coord x, Evas_Coord y);
84 static IBox_Icon   *_ibox_icon_new(IBox *b, E_Client *ec);
85 static void         _ibox_icon_free(IBox_Icon *ic);
86 static void         _ibox_icon_fill(IBox_Icon *ic);
87 static void         _ibox_icon_fill_label(IBox_Icon *ic);
88 static void         _ibox_icon_empty(IBox_Icon *ic);
89 static void         _ibox_icon_signal_emit(IBox_Icon *ic, char *sig, char *src);
90 static Eina_List   *_ibox_zone_find(E_Zone *zone);
91 static void         _ibox_cb_obj_moveresize(void *data, Evas *e, Evas_Object *obj, void *event_info);
92 static void         _ibox_cb_menu_configuration(void *data, E_Menu *m, E_Menu_Item *mi);
93 static void         _ibox_cb_icon_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
94 static void         _ibox_cb_icon_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info);
95 static void         _ibox_cb_icon_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
96 static void         _ibox_cb_icon_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
97 static void         _ibox_cb_icon_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
98 static void         _ibox_cb_icon_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
99 static void         _ibox_cb_icon_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
100 static void         _ibox_cb_drag_finished(E_Drag *drag, int dropped);
101 static void         _ibox_inst_cb_enter(void *data, const char *type, void *event_info);
102 static void         _ibox_inst_cb_move(void *data, const char *type, void *event_info);
103 static void         _ibox_inst_cb_leave(void *data, const char *type, void *event_info);
104 static void         _ibox_inst_cb_drop(void *data, const char *type, void *event_info);
105 static void         _ibox_drop_position_update(Instance *inst, Evas_Coord x, Evas_Coord y);
106 static void         _ibox_inst_cb_scroll(void *data);
107 static Eina_Bool    _ibox_cb_event_client_add(void *data, int type, void *event);
108 static Eina_Bool    _ibox_cb_event_client_remove(void *data, int type, void *event);
109 static Eina_Bool    _ibox_cb_event_client_iconify(void *data, int type, void *event);
110 static Eina_Bool    _ibox_cb_event_client_uniconify(void *data, int type, void *event);
111 static Eina_Bool    _ibox_cb_event_client_zone_set(void *data, int type, void *event);
112 static Eina_Bool    _ibox_cb_event_desk_show(void *data, int type, void *event);
113 static Config_Item *_ibox_config_item_get(const char *id);
114 
115 static E_Config_DD *conf_edd = NULL;
116 static E_Config_DD *conf_item_edd = NULL;
117 
118 Config *ibox_config = NULL;
119 
120 static void
_ibox_cb_iconify_end_cb(void * data,Evas_Object * obj EINA_UNUSED,const char * sig EINA_UNUSED,const char * src EINA_UNUSED)121 _ibox_cb_iconify_end_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
122 {
123    E_Client *ec = data;
124 
125    evas_object_layer_set(ec->frame, ec->layer);
126    ec->layer_block = 0;
127    if (ec->iconic)
128      evas_object_hide(ec->frame);
129 }
130 
131 static Eina_Bool
_ibox_cb_iconify_provider(void * data,Evas_Object * obj,const char * signal)132 _ibox_cb_iconify_provider(void *data, Evas_Object *obj, const char *signal)
133 {
134    Instance *inst = data;
135    IBox_Icon *ic;
136    Evas_Coord ox, oy, ow, oh;
137    Eina_List *l;
138    E_Client *ec;
139    ox = oy = ow = oh = 0;
140 
141    ec = e_comp_object_client_get(obj);
142    if (ec->zone != inst->gcc->gadcon->zone) return EINA_FALSE;
143    if (!strcmp(signal, "e,action,uniconify"))
144      {
145         EINA_LIST_FOREACH(inst->ibox->icons, l, ic)
146           {
147              if (ic->client == ec)
148                {
149                   evas_object_geometry_get(ic->o_holder, &ox, &oy, &ow, &oh);
150                   break;
151                }
152           }
153      }
154    else
155      {
156         // XXX: ibox doesn't know yet where a new icon might go... so assume right
157         // edge of ibox
158         evas_object_geometry_get(inst->ibox->o_box, &ox, &oy, &ow, &oh);
159         ox += ow - 1;
160         oy += (oh / 2);
161      }
162    ec->layer_block = 1;
163    evas_object_layer_set(ec->frame, E_LAYER_CLIENT_PRIO);
164    e_comp_object_effect_set(ec->frame, "iconify/ibox");
165    e_comp_object_effect_params_set(ec->frame, 1, (int[]){ec->x, ec->y, ec->w, ec->h, ox, oy, ow, oh}, 8);
166    e_comp_object_effect_params_set(ec->frame, 0, (int[]){!!strcmp(signal, "e,action,iconify")}, 1);
167    e_comp_object_effect_start(ec->frame, _ibox_cb_iconify_end_cb, ec);
168    return EINA_TRUE;
169 }
170 
171 static E_Gadcon_Client *
_gc_init(E_Gadcon * gc,const char * name,const char * id,const char * style)172 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
173 {
174    IBox *b;
175    Evas_Object *o;
176    E_Gadcon_Client *gcc;
177    Instance *inst;
178    Evas_Coord x, y, w, h;
179    const char *drop[] = { "enlightenment/border" };
180    Config_Item *ci;
181 
182    inst = E_NEW(Instance, 1);
183 
184    ci = _ibox_config_item_get(id);
185    inst->ci = ci;
186 
187    b = _ibox_new(gc->o_container ?: e_comp->elm, gc->zone);
188    b->inst = inst;
189    inst->ibox = b;
190    o = b->o_box;
191    gcc = e_gadcon_client_new(gc, name, id, style, o);
192    gcc->data = inst;
193    ci->gcc = gcc;
194 
195    inst->gcc = gcc;
196    inst->o_ibox = o;
197    inst->orient = E_GADCON_ORIENT_HORIZ;
198    _ibox_fill(b);
199 
200    evas_object_geometry_get(o, &x, &y, &w, &h);
201    inst->drop_handler =
202      e_drop_handler_add(E_OBJECT(inst->gcc), NULL, inst,
203                         _ibox_inst_cb_enter, _ibox_inst_cb_move,
204                         _ibox_inst_cb_leave, _ibox_inst_cb_drop,
205                         drop, 1, x, y, w, h);
206    evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE,
207                                   _ibox_cb_obj_moveresize, inst);
208    evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
209                                   _ibox_cb_obj_moveresize, inst);
210    ibox_config->instances = eina_list_append(ibox_config->instances, inst);
211    // add highest priority iconify provider - tasks and ibar can do this
212    // but lower priority
213    inst->iconify_provider = e_comp_object_effect_mover_add(100, "e,action,*iconify", _ibox_cb_iconify_provider, inst);
214    return gcc;
215 }
216 
217 static void
_gc_shutdown(E_Gadcon_Client * gcc)218 _gc_shutdown(E_Gadcon_Client *gcc)
219 {
220    Instance *inst;
221 
222    inst = gcc->data;
223    e_comp_object_effect_mover_del(inst->iconify_provider);
224    inst->ci->gcc = NULL;
225    ibox_config->instances = eina_list_remove(ibox_config->instances, inst);
226    e_drop_handler_del(inst->drop_handler);
227    _ibox_free(inst->ibox);
228    free(inst);
229 }
230 
231 static void
_gc_orient(E_Gadcon_Client * gcc,E_Gadcon_Orient orient)232 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient)
233 {
234    Instance *inst;
235 
236    inst = gcc->data;
237    if ((int)orient != -1) inst->orient = orient;
238 
239    switch (inst->orient)
240      {
241       case E_GADCON_ORIENT_FLOAT:
242       case E_GADCON_ORIENT_HORIZ:
243       case E_GADCON_ORIENT_TOP:
244       case E_GADCON_ORIENT_BOTTOM:
245       case E_GADCON_ORIENT_CORNER_TL:
246       case E_GADCON_ORIENT_CORNER_TR:
247       case E_GADCON_ORIENT_CORNER_BL:
248       case E_GADCON_ORIENT_CORNER_BR:
249         _ibox_orient_set(inst->ibox, 1);
250         e_gadcon_client_aspect_set(gcc, eina_list_count(inst->ibox->icons) * 16, 16);
251         break;
252 
253       case E_GADCON_ORIENT_VERT:
254       case E_GADCON_ORIENT_LEFT:
255       case E_GADCON_ORIENT_RIGHT:
256       case E_GADCON_ORIENT_CORNER_LT:
257       case E_GADCON_ORIENT_CORNER_RT:
258       case E_GADCON_ORIENT_CORNER_LB:
259       case E_GADCON_ORIENT_CORNER_RB:
260         _ibox_orient_set(inst->ibox, 0);
261         e_gadcon_client_aspect_set(gcc, 16, eina_list_count(inst->ibox->icons) * 16);
262         break;
263 
264       default:
265         break;
266      }
267    e_gadcon_client_min_size_set(gcc, 16, 16);
268 }
269 
270 static const char *
_gc_label(const E_Gadcon_Client_Class * client_class EINA_UNUSED)271 _gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
272 {
273    return _("IBox");
274 }
275 
276 static Evas_Object *
_gc_icon(const E_Gadcon_Client_Class * client_class EINA_UNUSED,Evas * evas)277 _gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas *evas)
278 {
279    Evas_Object *o;
280    char buf[PATH_MAX];
281 
282    o = edje_object_add(evas);
283    snprintf(buf, sizeof(buf), "%s/e-module-ibox.edj",
284             e_module_dir_get(ibox_config->module));
285    edje_object_file_set(o, buf, "icon");
286    return o;
287 }
288 
289 static const char *
_gc_id_new(const E_Gadcon_Client_Class * client_class)290 _gc_id_new(const E_Gadcon_Client_Class *client_class)
291 {
292    static char buf[4096];
293 
294    snprintf(buf, sizeof(buf), "%s.%d", client_class->name,
295             eina_list_count(ibox_config->instances) + 1);
296    return buf;
297 }
298 
299 static void
_gc_id_del(const E_Gadcon_Client_Class * client_class EINA_UNUSED,const char * id EINA_UNUSED)300 _gc_id_del(const E_Gadcon_Client_Class *client_class EINA_UNUSED, const char *id EINA_UNUSED)
301 {
302 /* yes - don't do this. on shutdown gadgets are deleted and this means config
303  * for them is deleted - that means empty config is saved. keep them around
304  * as if u add a gadget back it can pick up its old config again
305    Config_Item *ci;
306 
307    ci = _ibox_config_item_get(id);
308    if (ci)
309      {
310         if (ci->id) eina_stringshare_del(ci->id);
311         ibox_config->items = eina_list_remove(ibox_config->items, ci);
312      }
313  */
314 }
315 
316 static IBox *
_ibox_new(Evas_Object * parent,E_Zone * zone)317 _ibox_new(Evas_Object *parent, E_Zone *zone)
318 {
319    IBox *b;
320 
321    b = E_NEW(IBox, 1);
322    b->o_box = elm_box_add(e_win_evas_object_win_get(parent));
323    elm_box_homogeneous_set(b->o_box, 1);
324    elm_box_horizontal_set(b->o_box, 1);
325    elm_box_align_set(b->o_box, 0.5, 0.5);
326    b->zone = zone;
327    return b;
328 }
329 
330 static void
_ibox_free(IBox * b)331 _ibox_free(IBox *b)
332 {
333    _ibox_empty(b);
334    evas_object_del(b->o_box);
335    if (b->o_drop) evas_object_del(b->o_drop);
336    if (b->o_drop_over) evas_object_del(b->o_drop_over);
337    if (b->o_empty) evas_object_del(b->o_empty);
338    free(b);
339 }
340 
341 static void
_ibox_cb_empty_mouse_down(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)342 _ibox_cb_empty_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
343 {
344    Evas_Event_Mouse_Down *ev;
345    IBox *b;
346    E_Menu *m;
347    E_Menu_Item *mi;
348    int cx, cy;
349 
350    ev = event_info;
351    b = data;
352    if (ev->button != 3) return;
353 
354    m = e_menu_new();
355    mi = e_menu_item_new(m);
356    e_menu_item_label_set(mi, _("Settings"));
357    e_util_menu_item_theme_icon_set(mi, "configure");
358    e_menu_item_callback_set(mi, _ibox_cb_menu_configuration, b);
359 
360    m = e_gadcon_client_util_menu_items_append(b->inst->gcc, m, 0);
361 
362    e_gadcon_canvas_zone_geometry_get(b->inst->gcc->gadcon,
363                                      &cx, &cy, NULL, NULL);
364    e_menu_activate_mouse(m,
365                          e_zone_current_get(),
366                          cx + ev->output.x, cy + ev->output.y, 1, 1,
367                          E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
368    evas_event_feed_mouse_up(b->inst->gcc->gadcon->evas, ev->button,
369                             EVAS_BUTTON_NONE, ev->timestamp, NULL);
370 }
371 
372 static void
_ibox_empty_handle(IBox * b)373 _ibox_empty_handle(IBox *b)
374 {
375    if (!b->o_empty)
376      {
377         b->o_empty = evas_object_rectangle_add(evas_object_evas_get(b->o_box));
378         evas_object_event_callback_add(b->o_empty, EVAS_CALLBACK_MOUSE_DOWN, _ibox_cb_empty_mouse_down, b);
379         evas_object_color_set(b->o_empty, 0, 0, 0, 0);
380         E_EXPAND(b->o_empty);
381         E_FILL(b->o_empty);
382      }
383    if (b->icons) return;
384    evas_object_show(b->o_empty);
385    elm_box_pack_end(b->o_box, b->o_empty);
386 }
387 
388 static void
_ibox_fill(IBox * b)389 _ibox_fill(IBox *b)
390 {
391    IBox_Icon *ic;
392    E_Client *ec;
393    int ok;
394    int mw, mh, h;
395 
396    E_CLIENT_FOREACH(ec)
397      {
398         if (e_client_util_ignored_get(ec)) continue;
399         ok = 0;
400         if ((b->inst->ci->show_zone == 0) && (ec->iconic))
401           {
402              ok = 1;
403           }
404         else if ((b->inst->ci->show_zone == 1) && (ec->iconic))
405           {
406              if (ec->sticky)
407                {
408                   ok = 1;
409                }
410              else if ((b->inst->ci->show_desk == 0) && (ec->zone == b->zone))
411                {
412                   ok = 1;
413                }
414              else if ((b->inst->ci->show_desk == 1) && (ec->zone == b->zone) &&
415                       (ec->desk == e_desk_current_get(b->zone)))
416                {
417                   ok = 1;
418                }
419           }
420 
421         if (ok)
422           {
423              ic = _ibox_icon_new(b, ec);
424              b->icons = eina_list_append(b->icons, ic);
425              elm_box_pack_end(b->o_box, ic->o_holder);
426           }
427      }
428 
429    _ibox_empty_handle(b);
430    _ibox_resize_handle(b);
431    if (!b->inst->gcc) return;
432    if (!b->inst->ci->expand_on_desktop) return;
433    if (!e_gadcon_site_is_desktop(b->inst->gcc->gadcon->location->site)) return;
434    elm_box_recalculate(b->o_box);
435    evas_object_size_hint_min_get(b->o_box, &mw, &mh);
436    if ((!mw) && (!mh))
437      evas_object_geometry_get(b->o_box, NULL, NULL, &mw, &mh);
438    evas_object_geometry_get(b->inst->gcc->o_frame, NULL, NULL, NULL, &h);
439    evas_object_resize(b->inst->gcc->o_frame, MIN(mw, b->inst->gcc->gadcon->zone->w), MAX(h, mh));
440 }
441 
442 static void
_ibox_empty(IBox * b)443 _ibox_empty(IBox *b)
444 {
445    E_FREE_LIST(b->icons, _ibox_icon_free);
446    _ibox_empty_handle(b);
447 }
448 
449 static void
_ibox_orient_set(IBox * b,int horizontal)450 _ibox_orient_set(IBox *b, int horizontal)
451 {
452    elm_box_horizontal_set(b->o_box, horizontal);
453    elm_box_align_set(b->o_box, 0.5, 0.5);
454 }
455 
456 static void
_ibox_resize_handle(IBox * b)457 _ibox_resize_handle(IBox *b)
458 {
459    Eina_List *l;
460    IBox_Icon *ic;
461    int w, h;
462 
463    evas_object_geometry_get(b->o_box, NULL, NULL, &w, &h);
464    if (elm_box_horizontal_get(b->o_box))
465      w = h;
466    else
467      h = w;
468    if (w || h)
469      evas_object_size_hint_min_set(b->o_empty, w, h);
470    if (b->icons && evas_object_visible_get(b->o_empty))
471      {
472         elm_box_unpack(b->o_box, b->o_empty);
473         evas_object_hide(b->o_empty);
474      }
475    EINA_LIST_FOREACH(b->icons, l, ic)
476      {
477         evas_object_size_hint_min_set(ic->o_holder, w, h);
478         evas_object_size_hint_max_set(ic->o_holder, w, h);
479      }
480 }
481 
482 static void
_ibox_instance_drop_zone_recalc(Instance * inst)483 _ibox_instance_drop_zone_recalc(Instance *inst)
484 {
485    Evas_Coord x, y, w, h;
486 
487    e_gadcon_client_viewport_geometry_get(inst->gcc, &x, &y, &w, &h);
488    e_drop_handler_geometry_set(inst->drop_handler, x, y, w, h);
489 }
490 
491 static IBox_Icon *
_ibox_icon_find(IBox * b,E_Client * ec)492 _ibox_icon_find(IBox *b, E_Client *ec)
493 {
494    Eina_List *l;
495    IBox_Icon *ic;
496 
497    EINA_LIST_FOREACH(b->icons, l, ic)
498      {
499         if (ic->client == ec) return ic;
500      }
501    return NULL;
502 }
503 
504 static IBox_Icon *
_ibox_icon_at_coord(IBox * b,Evas_Coord x,Evas_Coord y)505 _ibox_icon_at_coord(IBox *b, Evas_Coord x, Evas_Coord y)
506 {
507    Eina_List *l;
508    IBox_Icon *ic;
509 
510    EINA_LIST_FOREACH(b->icons, l, ic)
511      {
512         Evas_Coord dx, dy, dw, dh;
513 
514         evas_object_geometry_get(ic->o_holder, &dx, &dy, &dw, &dh);
515         if (E_INSIDE(x, y, dx, dy, dw, dh)) return ic;
516      }
517    return NULL;
518 }
519 
520 static IBox_Icon *
_ibox_icon_new(IBox * b,E_Client * ec)521 _ibox_icon_new(IBox *b, E_Client *ec)
522 {
523    IBox_Icon *ic;
524 
525    ic = E_NEW(IBox_Icon, 1);
526    e_object_ref(E_OBJECT(ec));
527    ic->ibox = b;
528    ic->client = ec;
529    ic->o_holder = edje_object_add(evas_object_evas_get(b->o_box));
530    E_FILL(ic->o_holder);
531    e_theme_edje_object_set(ic->o_holder, "base/theme/modules/ibox",
532                            "e/modules/ibox/icon");
533    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_IN, _ibox_cb_icon_mouse_in, ic);
534    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_OUT, _ibox_cb_icon_mouse_out, ic);
535    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_DOWN, _ibox_cb_icon_mouse_down, ic);
536    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_UP, _ibox_cb_icon_mouse_up, ic);
537    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_MOVE, _ibox_cb_icon_mouse_move, ic);
538    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOVE, _ibox_cb_icon_move, ic);
539    evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_RESIZE, _ibox_cb_icon_resize, ic);
540    evas_object_show(ic->o_holder);
541 
542    ic->o_holder2 = edje_object_add(evas_object_evas_get(b->o_box));
543    e_theme_edje_object_set(ic->o_holder2, "base/theme/modules/ibox",
544                            "e/modules/ibox/icon_overlay");
545    evas_object_layer_set(ic->o_holder2, 9999);
546    evas_object_pass_events_set(ic->o_holder2, 1);
547    evas_object_show(ic->o_holder2);
548 
549    _ibox_icon_fill(ic);
550    return ic;
551 }
552 
553 static void
_ibox_icon_free(IBox_Icon * ic)554 _ibox_icon_free(IBox_Icon *ic)
555 {
556    if (ic->ibox->ic_drop_before == ic)
557      ic->ibox->ic_drop_before = NULL;
558    _ibox_icon_empty(ic);
559    evas_object_del(ic->o_holder);
560    evas_object_del(ic->o_holder2);
561    e_object_unref(E_OBJECT(ic->client));
562    free(ic);
563 }
564 
565 static void
_ibox_icon_fill(IBox_Icon * ic)566 _ibox_icon_fill(IBox_Icon *ic)
567 {
568    ic->o_icon = e_client_icon_add(ic->client, evas_object_evas_get(ic->ibox->o_box));
569    edje_object_part_swallow(ic->o_holder, "e.swallow.content", ic->o_icon);
570    evas_object_pass_events_set(ic->o_icon, 1);
571    evas_object_show(ic->o_icon);
572    ic->o_icon2 = e_client_icon_add(ic->client, evas_object_evas_get(ic->ibox->o_box));
573    edje_object_part_swallow(ic->o_holder2, "e.swallow.content", ic->o_icon2);
574    evas_object_pass_events_set(ic->o_icon2, 1);
575    evas_object_show(ic->o_icon2);
576 
577    _ibox_icon_fill_label(ic);
578 
579    if (ic->client->urgent)
580      {
581         e_gadcon_urgent_show(ic->ibox->inst->gcc->gadcon);
582         edje_object_signal_emit(ic->o_holder, "e,state,urgent", "e");
583         edje_object_signal_emit(ic->o_holder2, "e,state,urgent", "e");
584      }
585 }
586 
587 static void
_ibox_icon_fill_label(IBox_Icon * ic)588 _ibox_icon_fill_label(IBox_Icon *ic)
589 {
590    const char *label = NULL;
591 
592    switch (ic->ibox->inst->ci->icon_label)
593      {
594       case 0:
595         label = ic->client->netwm.name;
596         if (!label)
597           label = ic->client->icccm.name;
598         break;
599 
600       case 1:
601         label = ic->client->icccm.title;
602         break;
603 
604       case 2:
605         label = ic->client->icccm.class;
606         break;
607 
608       case 3:
609         label = ic->client->netwm.icon_name;
610         if (!label)
611           label = ic->client->icccm.icon_name;
612         break;
613 
614       case 4:
615         label = e_client_util_name_get(ic->client);
616         break;
617      }
618 
619    if (!label) label = "?";
620    edje_object_part_text_set(ic->o_holder2, "e.text.label", label);
621 }
622 
623 static void
_ibox_icon_empty(IBox_Icon * ic)624 _ibox_icon_empty(IBox_Icon *ic)
625 {
626    if (ic->o_icon) evas_object_del(ic->o_icon);
627    if (ic->o_icon2) evas_object_del(ic->o_icon2);
628    ic->o_icon = NULL;
629    ic->o_icon2 = NULL;
630 }
631 
632 static void
_ibox_icon_signal_emit(IBox_Icon * ic,char * sig,char * src)633 _ibox_icon_signal_emit(IBox_Icon *ic, char *sig, char *src)
634 {
635    if (ic->o_holder)
636      edje_object_signal_emit(ic->o_holder, sig, src);
637    if (ic->o_icon && e_icon_edje_get(ic->o_icon))
638      e_icon_edje_emit(ic->o_icon, sig, src);
639    if (ic->o_holder2)
640      edje_object_signal_emit(ic->o_holder2, sig, src);
641    if (ic->o_icon2 && e_icon_edje_get(ic->o_icon2))
642      e_icon_edje_emit(ic->o_icon2, sig, src);
643 }
644 
645 static Eina_List *
_ibox_zone_find(E_Zone * zone)646 _ibox_zone_find(E_Zone *zone)
647 {
648    Eina_List *ibox = NULL;
649    Eina_List *l;
650    Instance *inst;
651 
652    EINA_LIST_FOREACH(ibox_config->instances, l, inst)
653      {
654         if (inst->ci->show_zone == 0)
655           ibox = eina_list_append(ibox, inst->ibox);
656         else if ((inst->ci->show_zone == 1) && (inst->ibox->zone == zone))
657           ibox = eina_list_append(ibox, inst->ibox);
658      }
659    return ibox;
660 }
661 
662 static void
_ibox_cb_obj_moveresize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)663 _ibox_cb_obj_moveresize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
664 {
665    Instance *inst;
666 
667    inst = data;
668    _ibox_resize_handle(inst->ibox);
669    _ibox_instance_drop_zone_recalc(inst);
670 }
671 
672 static void
_ibox_cb_icon_mouse_in(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)673 _ibox_cb_icon_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
674 {
675    IBox_Icon *ic;
676 
677    ic = data;
678    _ibox_icon_signal_emit(ic, "e,state,focused", "e");
679    if (ic->ibox->inst->ci->show_label)
680      {
681         _ibox_icon_fill_label(ic);
682         _ibox_icon_signal_emit(ic, "e,action,show,label", "e");
683      }
684 }
685 
686 static void
_ibox_cb_icon_mouse_out(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)687 _ibox_cb_icon_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
688 {
689    IBox_Icon *ic;
690 
691    ic = data;
692    _ibox_icon_signal_emit(ic, "e,state,unfocused", "e");
693    if (ic->ibox->inst->ci->show_label)
694      _ibox_icon_signal_emit(ic, "e,action,hide,label", "e");
695 }
696 
697 static void
_ibox_cb_icon_mouse_down(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)698 _ibox_cb_icon_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
699 {
700    Evas_Event_Mouse_Down *ev;
701    IBox_Icon *ic;
702 
703    ev = event_info;
704    ic = data;
705    if (ev->button == 1)
706      {
707         ic->drag.x = ev->output.x;
708         ic->drag.y = ev->output.y;
709         ic->drag.start = 1;
710         ic->drag.dnd = 0;
711      }
712    else if (ev->button == 3)
713      {
714         E_Menu *m;
715         E_Menu_Item *mi;
716         int cx, cy;
717 
718         m = e_menu_new();
719 
720         /* FIXME: other icon options go here too */
721         mi = e_menu_item_new(m);
722         e_menu_item_label_set(mi, _("Settings"));
723         e_util_menu_item_theme_icon_set(mi, "configure");
724         e_menu_item_callback_set(mi, _ibox_cb_menu_configuration, ic->ibox);
725 
726         m = e_gadcon_client_util_menu_items_append(ic->ibox->inst->gcc, m, 0);
727 
728         e_gadcon_canvas_zone_geometry_get(ic->ibox->inst->gcc->gadcon,
729                                           &cx, &cy, NULL, NULL);
730         e_menu_activate_mouse(m,
731                               e_zone_current_get(),
732                               cx + ev->output.x, cy + ev->output.y, 1, 1,
733                               E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
734      }
735 }
736 
737 static void
_ibox_cb_icon_mouse_up(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)738 _ibox_cb_icon_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
739 {
740    Evas_Event_Mouse_Up *ev;
741    IBox_Icon *ic;
742 
743    ev = event_info;
744    ic = data;
745    if ((ev->button == 1) && (!ic->drag.dnd))
746      {
747         e_client_uniconify(ic->client);
748         evas_object_focus_set(ic->client->frame, 1);
749      }
750 }
751 
752 static void
_ibox_cb_icon_mouse_move(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)753 _ibox_cb_icon_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
754 {
755    Evas_Event_Mouse_Move *ev;
756    IBox_Icon *ic;
757 
758    ev = event_info;
759    ic = data;
760    if (ic->drag.start)
761      {
762         int dx, dy;
763 
764         dx = ev->cur.output.x - ic->drag.x;
765         dy = ev->cur.output.y - ic->drag.y;
766         if (((dx * dx) + (dy * dy)) >
767             (e_config->drag_resist * e_config->drag_resist))
768           {
769              E_Drag *d;
770              Evas_Object *o;
771              Evas_Coord x, y, w, h;
772              const char *drag_types[] = { "enlightenment/border" };
773              E_Gadcon_Client *gcc;
774              ic->drag.dnd = 1;
775              ic->drag.start = 0;
776 
777              evas_object_geometry_get(ic->o_icon, &x, &y, &w, &h);
778              d = e_drag_new(x, y, drag_types, 1,
779                             ic->client, -1, NULL, _ibox_cb_drag_finished);
780              d->button_mask = evas_pointer_button_down_mask_get(e_comp->evas);
781              o = e_client_icon_add(ic->client, e_drag_evas_get(d));
782              e_drag_object_set(d, o);
783 
784              e_drag_resize(d, w, h);
785              e_drag_start(d, ic->drag.x, ic->drag.y);
786              e_object_ref(E_OBJECT(ic->client));
787              ic->ibox->icons = eina_list_remove(ic->ibox->icons, ic);
788              _ibox_resize_handle(ic->ibox);
789              gcc = ic->ibox->inst->gcc;
790              _gc_orient(gcc, -1);
791              _ibox_icon_free(ic);
792           }
793      }
794 }
795 
796 static void
_ibox_cb_icon_move(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)797 _ibox_cb_icon_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
798 {
799    IBox_Icon *ic;
800    Evas_Coord x, y;
801 
802    ic = data;
803    evas_object_geometry_get(ic->o_holder, &x, &y, NULL, NULL);
804    evas_object_move(ic->o_holder2, x, y);
805    evas_object_raise(ic->o_holder2);
806 }
807 
808 static void
_ibox_cb_icon_resize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)809 _ibox_cb_icon_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
810 {
811    IBox_Icon *ic;
812    Evas_Coord w, h;
813 
814    ic = data;
815    evas_object_geometry_get(ic->o_holder, NULL, NULL, &w, &h);
816    evas_object_resize(ic->o_holder2, w, h);
817    evas_object_raise(ic->o_holder2);
818 }
819 
820 static void
_ibox_cb_drag_finished(E_Drag * drag,int dropped)821 _ibox_cb_drag_finished(E_Drag *drag, int dropped)
822 {
823    E_Client *ec;
824 
825    ec = drag->data;
826    if (!dropped) e_client_uniconify(ec);
827    e_object_unref(E_OBJECT(ec));
828 }
829 
830 static void
_ibox_cb_drop_move(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)831 _ibox_cb_drop_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
832 {
833    IBox *b;
834    Evas_Coord x, y;
835 
836    b = data;
837    evas_object_geometry_get(b->o_drop, &x, &y, NULL, NULL);
838    evas_object_move(b->o_drop_over, x, y);
839 }
840 
841 static void
_ibox_cb_drop_resize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)842 _ibox_cb_drop_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
843 {
844    IBox *b;
845    Evas_Coord w, h;
846 
847    b = data;
848    evas_object_geometry_get(b->o_drop, NULL, NULL, &w, &h);
849    evas_object_resize(b->o_drop_over, w, h);
850 }
851 
852 static void
_ibox_inst_cb_scroll(void * data)853 _ibox_inst_cb_scroll(void *data)
854 {
855    Instance *inst;
856 
857    /* Update the position of the dnd to handle for autoscrolling
858     * gadgets. */
859    inst = data;
860    _ibox_drop_position_update(inst, inst->ibox->dnd_x, inst->ibox->dnd_y);
861 }
862 
863 static void
_ibox_drop_position_update(Instance * inst,Evas_Coord x,Evas_Coord y)864 _ibox_drop_position_update(Instance *inst, Evas_Coord x, Evas_Coord y)
865 {
866    IBox_Icon *ic;
867 
868    inst->ibox->dnd_x = x;
869    inst->ibox->dnd_y = y;
870 
871    if (inst->ibox->o_drop)
872      elm_box_unpack(inst->ibox->o_box, inst->ibox->o_drop);
873    ic = _ibox_icon_at_coord(inst->ibox, x, y);
874    inst->ibox->ic_drop_before = ic;
875    if (ic)
876      {
877         Evas_Coord ix, iy, iw, ih;
878         int before = 0;
879 
880         evas_object_geometry_get(ic->o_holder, &ix, &iy, &iw, &ih);
881         if (elm_box_horizontal_get(inst->ibox->o_box))
882           {
883              if (x < (ix + (iw / 2))) before = 1;
884           }
885         else
886           {
887              if (y < (iy + (ih / 2))) before = 1;
888           }
889         if (before)
890           elm_box_pack_before(inst->ibox->o_box, inst->ibox->o_drop, ic->o_holder);
891         else
892           elm_box_pack_after(inst->ibox->o_box, inst->ibox->o_drop, ic->o_holder);
893         inst->ibox->drop_before = before;
894      }
895    else elm_box_pack_end(inst->ibox->o_box, inst->ibox->o_drop);
896    evas_object_size_hint_min_set(inst->ibox->o_drop, 1, 1);
897    _ibox_resize_handle(inst->ibox);
898    _gc_orient(inst->gcc, -1);
899 }
900 
901 static void
_ibox_inst_cb_enter(void * data,const char * type EINA_UNUSED,void * event_info)902 _ibox_inst_cb_enter(void *data, const char *type EINA_UNUSED, void *event_info)
903 {
904    E_Event_Dnd_Enter *ev;
905    Instance *inst;
906    Evas_Object *o, *o2;
907 
908    ev = event_info;
909    inst = data;
910    o = edje_object_add(evas_object_evas_get(inst->ibox->o_box));
911    inst->ibox->o_drop = o;
912    E_EXPAND(inst->ibox->o_drop);
913    E_FILL(inst->ibox->o_drop);
914    o2 = edje_object_add(evas_object_evas_get(inst->ibox->o_box));
915    inst->ibox->o_drop_over = o2;
916    evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE, _ibox_cb_drop_move, inst->ibox);
917    evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _ibox_cb_drop_resize, inst->ibox);
918    e_theme_edje_object_set(o, "base/theme/modules/ibox",
919                            "e/modules/ibox/drop");
920    e_theme_edje_object_set(o2, "base/theme/modules/ibox",
921                            "e/modules/ibox/drop_overlay");
922    evas_object_layer_set(o2, 19999);
923    evas_object_show(o);
924    evas_object_show(o2);
925    _ibox_drop_position_update(inst, ev->x, ev->y);
926    e_gadcon_client_autoscroll_cb_set(inst->gcc, _ibox_inst_cb_scroll, inst);
927    e_gadcon_client_autoscroll_update(inst->gcc, ev->x, ev->y);
928 }
929 
930 static void
_ibox_inst_cb_move(void * data,const char * type EINA_UNUSED,void * event_info)931 _ibox_inst_cb_move(void *data, const char *type EINA_UNUSED, void *event_info)
932 {
933    E_Event_Dnd_Move *ev;
934    Instance *inst;
935 
936    ev = event_info;
937    inst = data;
938    _ibox_drop_position_update(inst, ev->x, ev->y);
939    e_gadcon_client_autoscroll_update(inst->gcc, ev->x, ev->y);
940 }
941 
942 static void
_ibox_inst_cb_leave(void * data,const char * type EINA_UNUSED,void * event_info EINA_UNUSED)943 _ibox_inst_cb_leave(void *data, const char *type EINA_UNUSED, void *event_info EINA_UNUSED)
944 {
945    Instance *inst;
946 
947    inst = data;
948    inst->ibox->ic_drop_before = NULL;
949    evas_object_del(inst->ibox->o_drop);
950    inst->ibox->o_drop = NULL;
951    evas_object_del(inst->ibox->o_drop_over);
952    inst->ibox->o_drop_over = NULL;
953    e_gadcon_client_autoscroll_cb_set(inst->gcc, NULL, NULL);
954    _ibox_resize_handle(inst->ibox);
955    _gc_orient(inst->gcc, -1);
956 }
957 
958 static void
_ibox_inst_cb_drop(void * data,const char * type,void * event_info)959 _ibox_inst_cb_drop(void *data, const char *type, void *event_info)
960 {
961    E_Event_Dnd_Drop *ev;
962    Instance *inst;
963    E_Client *ec = NULL;
964    IBox *b;
965    IBox_Icon *ic, *ic2;
966    Eina_List *l;
967 
968    ev = event_info;
969    inst = data;
970    if (!strcmp(type, "enlightenment/border"))
971      {
972         ec = ev->data;
973         if (!ec) return;
974      }
975    else return;
976 
977    if (!ec->iconic) e_client_iconify(ec);
978 
979    ic2 = inst->ibox->ic_drop_before;
980    if (ic2)
981      {
982         /* Add new eapp before this icon */
983         if (!inst->ibox->drop_before)
984           {
985              EINA_LIST_FOREACH(inst->ibox->icons, l, ic)
986                {
987                   if (ic == ic2)
988                     {
989                        ic2 = eina_list_data_get(l->next);
990                        break;
991                     }
992                }
993           }
994         if (!ic2) goto atend;
995         b = inst->ibox;
996         if (_ibox_icon_find(b, ec)) return;
997         ic = _ibox_icon_new(b, ec);
998         if (!ic) return;
999         b->icons = eina_list_prepend_relative(b->icons, ic, ic2);
1000         elm_box_pack_before(b->o_box, ic->o_holder, ic2->o_holder);
1001      }
1002    else
1003      {
1004 atend:
1005         b = inst->ibox;
1006         if (_ibox_icon_find(b, ec)) return;
1007         ic = _ibox_icon_new(b, ec);
1008         if (!ic) return;
1009         b->icons = eina_list_append(b->icons, ic);
1010         elm_box_pack_end(b->o_box, ic->o_holder);
1011      }
1012 
1013    evas_object_del(inst->ibox->o_drop);
1014    inst->ibox->o_drop = NULL;
1015    evas_object_del(inst->ibox->o_drop_over);
1016    inst->ibox->o_drop_over = NULL;
1017    _ibox_empty_handle(b);
1018    e_gadcon_client_autoscroll_cb_set(inst->gcc, NULL, NULL);
1019    _ibox_resize_handle(inst->ibox);
1020    _gc_orient(inst->gcc, -1);
1021 }
1022 
1023 static Eina_Bool
_ibox_cb_event_client_add(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1024 _ibox_cb_event_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1025 {
1026    E_Event_Client *ev = event;
1027    IBox *b;
1028    IBox_Icon *ic;
1029    E_Desk *desk;
1030    Eina_List *ibox;
1031 
1032    /* add if iconic */
1033    if (!ev->ec->iconic) return ECORE_CALLBACK_RENEW;
1034    if (!ev->ec->zone) return ECORE_CALLBACK_RENEW;
1035    desk = e_desk_current_get(ev->ec->zone);
1036 
1037    ibox = _ibox_zone_find(ev->ec->zone);
1038    EINA_LIST_FREE(ibox, b)
1039      {
1040         if (_ibox_icon_find(b, ev->ec)) continue;
1041         if ((b->inst->ci->show_desk) && (ev->ec->desk != desk) && (!ev->ec->sticky)) continue;
1042         ic = _ibox_icon_new(b, ev->ec);
1043         if (!ic) continue;
1044         b->icons = eina_list_append(b->icons, ic);
1045         elm_box_pack_end(b->o_box, ic->o_holder);
1046         _ibox_empty_handle(b);
1047         _ibox_resize_handle(b);
1048         _gc_orient(b->inst->gcc, -1);
1049      }
1050    return ECORE_CALLBACK_PASS_ON;
1051 }
1052 
1053 static Eina_Bool
_ibox_cb_event_client_remove(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1054 _ibox_cb_event_client_remove(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1055 {
1056    E_Event_Client *ev;
1057    IBox *b;
1058    IBox_Icon *ic;
1059    Eina_List *ibox;
1060 
1061    ev = event;
1062    /* find icon and remove if there */
1063    ibox = _ibox_zone_find(ev->ec->zone);
1064    EINA_LIST_FREE(ibox, b)
1065      {
1066         ic = _ibox_icon_find(b, ev->ec);
1067         if (!ic) continue;
1068         b->icons = eina_list_remove(b->icons, ic);
1069         _ibox_icon_free(ic);
1070         _ibox_empty_handle(b);
1071         _ibox_resize_handle(b);
1072         _gc_orient(b->inst->gcc, -1);
1073      }
1074 
1075    return ECORE_CALLBACK_PASS_ON;
1076 }
1077 
1078 static Eina_Bool
_ibox_cb_event_client_iconify(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1079 _ibox_cb_event_client_iconify(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1080 {
1081    E_Event_Client *ev;
1082    IBox *b;
1083    IBox_Icon *ic;
1084    Eina_List *ibox;
1085    E_Desk *desk;
1086 
1087    ev = event;
1088    /* add icon for ibox for right zone */
1089    /* do some sort of anim when iconifying */
1090    desk = e_desk_current_get(ev->ec->zone);
1091    ibox = _ibox_zone_find(ev->ec->zone);
1092    EINA_LIST_FREE(ibox, b)
1093      {
1094         int h, mw, mh;
1095         if (_ibox_icon_find(b, ev->ec)) continue;
1096         if ((b->inst->ci->show_desk) && (ev->ec->desk != desk) && (!ev->ec->sticky)) continue;
1097         ic = _ibox_icon_new(b, ev->ec);
1098         if (!ic) continue;
1099         b->icons = eina_list_append(b->icons, ic);
1100         elm_box_pack_end(b->o_box, ic->o_holder);
1101         _ibox_empty_handle(b);
1102         _ibox_resize_handle(b);
1103         _gc_orient(b->inst->gcc, -1);
1104         if (!b->inst->ci->expand_on_desktop) continue;
1105         if (!e_gadcon_site_is_desktop(b->inst->gcc->gadcon->location->site)) continue;
1106         elm_box_recalculate(b->o_box);
1107         evas_object_size_hint_min_get(b->o_box, &mw, &mh);
1108         if ((!mw) && (!mh))
1109           evas_object_geometry_get(b->o_box, NULL, NULL, &mw, &mh);
1110         evas_object_geometry_get(b->inst->gcc->o_frame, NULL, NULL, NULL, &h);
1111         evas_object_resize(b->inst->gcc->o_frame, MIN(mw, b->inst->gcc->gadcon->zone->w), MAX(h, mh));
1112      }
1113    return ECORE_CALLBACK_PASS_ON;
1114 }
1115 
1116 static Eina_Bool
_ibox_cb_event_client_uniconify(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1117 _ibox_cb_event_client_uniconify(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1118 {
1119    E_Event_Client *ev;
1120    IBox *b;
1121    IBox_Icon *ic;
1122    Eina_List *ibox;
1123 
1124    ev = event;
1125    /* del icon for ibox for right zone */
1126    /* do some sort of anim when uniconifying */
1127    ibox = _ibox_zone_find(ev->ec->zone);
1128    EINA_LIST_FREE(ibox, b)
1129      {
1130         int mw, mh, h;
1131         ic = _ibox_icon_find(b, ev->ec);
1132         if (!ic) continue;
1133         b->icons = eina_list_remove(b->icons, ic);
1134         _ibox_icon_free(ic);
1135         _ibox_empty_handle(b);
1136         _ibox_resize_handle(b);
1137         _gc_orient(b->inst->gcc, -1);
1138         if (!b->inst->ci->expand_on_desktop) continue;
1139         if (!e_gadcon_site_is_desktop(b->inst->gcc->gadcon->location->site)) continue;
1140         elm_box_recalculate(b->o_box);
1141         evas_object_size_hint_min_get(b->o_box, &mw, &mh);
1142         if ((!mw) && (!mh))
1143           evas_object_geometry_get(b->o_box, NULL, NULL, &mw, &mh);
1144         evas_object_geometry_get(b->inst->gcc->o_frame, NULL, NULL, NULL, &h);
1145         evas_object_resize(b->inst->gcc->o_frame, MIN(mw, b->inst->gcc->gadcon->zone->w), MAX(h, mh));
1146      }
1147 
1148    return ECORE_CALLBACK_PASS_ON;
1149 }
1150 
1151 static Eina_Bool
_ibox_cb_event_client_property(void * data EINA_UNUSED,int type EINA_UNUSED,E_Event_Client_Property * ev)1152 _ibox_cb_event_client_property(void *data EINA_UNUSED, int type EINA_UNUSED, E_Event_Client_Property *ev)
1153 {
1154    IBox *b;
1155    IBox_Icon *ic;
1156    Eina_List *ibox;
1157 
1158    if ((ev->property & ~E_CLIENT_PROPERTY_ICON) && (ev->property & ~E_CLIENT_PROPERTY_URGENCY)) return ECORE_CALLBACK_RENEW;
1159    ibox = _ibox_zone_find(ev->ec->zone);
1160    EINA_LIST_FREE(ibox, b)
1161      {
1162         ic = _ibox_icon_find(b, ev->ec);
1163         if (!ic) continue;
1164         if ((ev->property & E_CLIENT_PROPERTY_ICON))
1165           {
1166              _ibox_icon_empty(ic);
1167              _ibox_icon_fill(ic);
1168              continue;
1169           }
1170         if (ev->ec->urgent)
1171           {
1172              e_gadcon_urgent_show(b->inst->gcc->gadcon);
1173              edje_object_signal_emit(ic->o_holder, "e,state,urgent", "e");
1174              edje_object_signal_emit(ic->o_holder2, "e,state,urgent", "e");
1175           }
1176         else
1177           {
1178              edje_object_signal_emit(ic->o_holder, "e,state,not_urgent", "e");
1179              edje_object_signal_emit(ic->o_holder2, "e,state,not_urgent", "e");
1180           }
1181      }
1182 
1183    return ECORE_CALLBACK_PASS_ON;
1184 }
1185 
1186 static Eina_Bool
_ibox_cb_event_client_zone_set(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1187 _ibox_cb_event_client_zone_set(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1188 {
1189    E_Event_Client_Zone_Set *ev;
1190 
1191    ev = event;
1192    /* delete from current zone ibox, add to new one */
1193    if (ev->ec->iconic)
1194      {
1195      }
1196    return 1;
1197 }
1198 
1199 static Eina_Bool
_ibox_cb_event_desk_show(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)1200 _ibox_cb_event_desk_show(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1201 {
1202    E_Event_Desk_Show *ev;
1203    IBox *b;
1204    Eina_List *ibox;
1205 
1206    ev = event;
1207    /* delete all wins from ibox and add only for current desk */
1208    ibox = _ibox_zone_find(ev->desk->zone);
1209    EINA_LIST_FREE(ibox, b)
1210      {
1211         if (b->inst->ci->show_desk)
1212           {
1213              _ibox_empty(b);
1214              _ibox_fill(b);
1215              _ibox_resize_handle(b);
1216              _gc_orient(b->inst->gcc, -1);
1217           }
1218      }
1219 
1220    return ECORE_CALLBACK_PASS_ON;
1221 }
1222 
1223 static Config_Item *
_ibox_config_item_get(const char * id)1224 _ibox_config_item_get(const char *id)
1225 {
1226    Config_Item *ci;
1227 
1228    GADCON_CLIENT_CONFIG_GET(Config_Item, ibox_config->items, _gadcon_class, id);
1229 
1230    ci = E_NEW(Config_Item, 1);
1231    ci->id = eina_stringshare_add(id);
1232    ci->show_label = 0;
1233    ci->show_zone = 1;
1234    ci->show_desk = 0;
1235    ci->icon_label = 0;
1236    ibox_config->items = eina_list_append(ibox_config->items, ci);
1237    return ci;
1238 }
1239 
1240 void
_ibox_config_update(Config_Item * ci)1241 _ibox_config_update(Config_Item *ci)
1242 {
1243    Eina_List *l;
1244    Instance *inst;
1245 
1246    EINA_LIST_FOREACH(ibox_config->instances, l, inst)
1247      {
1248         if (inst->ci != ci) continue;
1249 
1250         _ibox_empty(inst->ibox);
1251         _ibox_fill(inst->ibox);
1252         _ibox_resize_handle(inst->ibox);
1253         _gc_orient(inst->gcc, -1);
1254      }
1255 }
1256 
1257 static void
_ibox_cb_menu_configuration(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1258 _ibox_cb_menu_configuration(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1259 {
1260    IBox *b;
1261    int ok = 1;
1262    Eina_List *l;
1263    E_Config_Dialog *cfd;
1264 
1265    b = data;
1266    EINA_LIST_FOREACH(ibox_config->config_dialog, l, cfd)
1267      {
1268         if (cfd->data == b->inst->ci)
1269           {
1270              ok = 0;
1271              break;
1272           }
1273      }
1274    if (ok) _config_ibox_module(b->inst->ci);
1275 }
1276 
1277 /***************************************************************************/
1278 /**/
1279 /* module setup */
1280 E_API E_Module_Api e_modapi =
1281 {
1282    E_MODULE_API_VERSION,
1283    "IBox"
1284 };
1285 
1286 E_API void *
e_modapi_init(E_Module * m)1287 e_modapi_init(E_Module *m)
1288 {
1289    conf_item_edd = E_CONFIG_DD_NEW("IBox_Config_Item", Config_Item);
1290    #undef T
1291    #undef D
1292    #define T Config_Item
1293    #define D conf_item_edd
1294    E_CONFIG_VAL(D, T, id, STR);
1295    E_CONFIG_VAL(D, T, expand_on_desktop, INT);
1296    E_CONFIG_VAL(D, T, show_label, INT);
1297    E_CONFIG_VAL(D, T, show_zone, INT);
1298    E_CONFIG_VAL(D, T, show_desk, INT);
1299    E_CONFIG_VAL(D, T, icon_label, INT);
1300 
1301    conf_edd = E_CONFIG_DD_NEW("IBox_Config", Config);
1302    #undef T
1303    #undef D
1304    #define T Config
1305    #define D conf_edd
1306    E_CONFIG_LIST(D, T, items, conf_item_edd);
1307 
1308    ibox_config = e_config_domain_load("module.ibox", conf_edd);
1309    if (!ibox_config)
1310      {
1311         Config_Item *ci;
1312 
1313         ibox_config = E_NEW(Config, 1);
1314 
1315         ci = E_NEW(Config_Item, 1);
1316         ci->id = eina_stringshare_add("ibox.1");
1317         ci->show_label = 0;
1318         ci->show_zone = 1;
1319         ci->show_desk = 0;
1320         ci->icon_label = 0;
1321         ibox_config->items = eina_list_append(ibox_config->items, ci);
1322      }
1323 
1324    ibox_config->module = m;
1325 
1326    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_ADD, _ibox_cb_event_client_add, NULL);
1327    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_REMOVE, _ibox_cb_event_client_remove, NULL);
1328    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_ICONIFY, _ibox_cb_event_client_iconify, NULL);
1329    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_UNICONIFY, _ibox_cb_event_client_uniconify, NULL);
1330    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_PROPERTY, _ibox_cb_event_client_property, NULL);
1331    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_CLIENT_ZONE_SET, _ibox_cb_event_client_zone_set, NULL);
1332    E_LIST_HANDLER_APPEND(ibox_config->handlers, E_EVENT_DESK_SHOW, _ibox_cb_event_desk_show, NULL);
1333 
1334 /* FIXME: add these later for things taskbar-like functionality
1335    ibox_config->handlers = eina_list_append
1336      (ibox_config->handlers, ecore_event_handler_add
1337       (E_EVENT_CLIENT_DESK_SET, _ibox_cb_event_client_zone_set, NULL));
1338    ibox_config->handlers = eina_list_append
1339      (ibox_config->handlers, ecore_event_handler_add
1340       (E_EVENT_CLIENT_SHOW, _ibox_cb_event_client_zone_set, NULL));
1341    ibox_config->handlers = eina_list_append
1342      (ibox_config->handlers, ecore_event_handler_add
1343       (E_EVENT_CLIENT_HIDE, _ibox_cb_event_client_zone_set, NULL));
1344    ibox_config->handlers = eina_list_append
1345      (ibox_config->handlers, ecore_event_handler_add
1346       (E_EVENT_CLIENT_STACK, _ibox_cb_event_client_zone_set, NULL));
1347    ibox_config->handlers = eina_list_append
1348      (ibox_config->handlers, ecore_event_handler_add
1349       (E_EVENT_CLIENT_STICK, _ibox_cb_event_client_zone_set, NULL));
1350  */
1351    e_gadcon_provider_register(&_gadcon_class);
1352    return m;
1353 }
1354 
1355 E_API int
e_modapi_shutdown(E_Module * m EINA_UNUSED)1356 e_modapi_shutdown(E_Module *m EINA_UNUSED)
1357 {
1358    Config_Item *ci;
1359    e_gadcon_provider_unregister(&_gadcon_class);
1360 
1361    E_FREE_LIST(ibox_config->handlers, ecore_event_handler_del);
1362 
1363    while (ibox_config->config_dialog)
1364      /* there is no need to eves_list_remove_list. It is done implicitly in
1365       * dialog _free_data function
1366       */
1367      e_object_del(E_OBJECT(ibox_config->config_dialog->data));
1368 
1369    EINA_LIST_FREE(ibox_config->items, ci)
1370      {
1371         eina_stringshare_del(ci->id);
1372         free(ci);
1373      }
1374 
1375    E_FREE(ibox_config);
1376    E_CONFIG_DD_FREE(conf_item_edd);
1377    E_CONFIG_DD_FREE(conf_edd);
1378    return 1;
1379 }
1380 
1381 E_API int
e_modapi_save(E_Module * m EINA_UNUSED)1382 e_modapi_save(E_Module *m EINA_UNUSED)
1383 {
1384    e_config_domain_save("module.ibox", conf_edd, ibox_config);
1385    return 1;
1386 }
1387 
1388