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
13 /* and actually define the gadcon class that this module provides (just 1) */
14 static const E_Gadcon_Client_Class _gadcon_class =
15 {
16 GADCON_CLIENT_CLASS_VERSION,
17 "ibar",
18 {
19 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, _gc_id_del,
20 e_gadcon_site_is_not_toolbar
21 },
22 E_GADCON_CLIENT_STYLE_INSET
23 };
24
25 /* actual module specifics */
26 typedef struct _Instance Instance;
27 typedef struct _IBar IBar;
28 typedef struct _IBar_Icon IBar_Icon;
29
30 struct _Instance
31 {
32 E_Gadcon_Client *gcc;
33 E_Comp_Object_Mover *iconify_provider;
34 IBar *ibar;
35 E_Drop_Handler *drop_handler;
36 Config_Item *ci;
37 E_Gadcon_Orient orient;
38 };
39
40 typedef struct
41 {
42 E_Order *eo;
43 Eina_Inlist *bars;
44 } IBar_Order;
45
46 struct _IBar
47 {
48 EINA_INLIST;
49 Instance *inst;
50 Ecore_Job *resize_job;
51 Evas_Object *o_outerbox;
52 Evas_Object *o_box, *o_drop;
53 Evas_Object *o_drop_over, *o_empty;
54 Evas_Object *o_sep;
55 unsigned int not_in_order_count;
56 IBar_Icon *ic_drop_before;
57 int drop_before;
58 Eina_Hash *icon_hash;
59 Eina_Inlist *icons;
60 IBar_Order *io;
61 Evas_Coord dnd_x, dnd_y;
62 IBar_Icon *menu_icon;
63 Eina_Bool focused E_BITFIELD;
64 };
65
66 struct _IBar_Icon
67 {
68 EINA_INLIST;
69 IBar *ibar;
70 Evas_Object *o_holder, *o_icon;
71 Evas_Object *o_holder2, *o_icon2;
72 Eina_List *client_objs;
73 Efreet_Desktop *app;
74 Ecore_Timer *reset_timer;
75 Ecore_Timer *timer;
76 Ecore_Timer *show_timer; //for menu
77 Ecore_Timer *hide_timer; //for menu
78 E_Exec_Instance *exe_inst;
79 Eina_List *exes; //all instances
80 Eina_List *menu_pending; //clients with menu items pending
81 E_Gadcon_Popup *menu;
82 const char *hashname;
83 int mouse_down;
84 struct
85 {
86 unsigned char start E_BITFIELD;
87 unsigned char dnd E_BITFIELD;
88 int x, y;
89 } drag;
90 Eina_Bool focused E_BITFIELD;
91 Eina_Bool not_in_order E_BITFIELD;
92 Eina_Bool menu_grabbed E_BITFIELD;
93 Eina_Bool starting E_BITFIELD;
94 };
95
96 static IBar *_ibar_new(Evas_Object *parent, Instance *inst);
97 static void _ibar_free(IBar *b);
98 static void _ibar_cb_empty_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
99 static void _ibar_empty_handle(IBar *b);
100 static void _ibar_instance_watch(void *data, E_Exec_Instance *inst, E_Exec_Watch_Type type);
101 static void _ibar_fill(IBar *b);
102 static void _ibar_empty(IBar *b);
103 static void _ibar_orient_set(IBar *b, int horizontal);
104 static void _ibar_resize_handle(IBar *b);
105 static void _ibar_instance_drop_zone_recalc(Instance *inst);
106 static Config_Item *_ibar_config_item_get(const char *id);
107 static IBar_Icon *_ibar_icon_at_coord(IBar *b, Evas_Coord x, Evas_Coord y);
108 static IBar_Icon *_ibar_icon_new(IBar *b, Efreet_Desktop *desktop, Eina_Bool notinorder);
109 static IBar_Icon *_ibar_icon_notinorder_new(IBar *b, E_Exec_Instance *exe);
110 static void _ibar_icon_free(IBar_Icon *ic);
111 static void _ibar_icon_fill(IBar_Icon *ic);
112 static void _ibar_icon_empty(IBar_Icon *ic);
113 static void _ibar_sep_create(IBar *b);
114 static void _ibar_icon_signal_emit(IBar_Icon *ic, const char *sig, const char *src);
115 static void _ibar_cb_app_change(void *data, E_Order *eo);
116 static void _ibar_cb_obj_moveresize(void *data, Evas *e, Evas_Object *obj, void *event_info);
117 static void _ibar_cb_menu_icon_action_exec(void *data, E_Menu *m, E_Menu_Item *mi);
118 static void _ibar_cb_menu_icon_new(void *data, E_Menu *m, E_Menu_Item *mi);
119 static void _ibar_cb_menu_icon_add(void *data, E_Menu *m, E_Menu_Item *mi);
120 static void _ibar_cb_menu_icon_properties(void *data, E_Menu *m, E_Menu_Item *mi);
121 static void _ibar_cb_menu_icon_remove(void *data, E_Menu *m, E_Menu_Item *mi);
122 static void _ibar_cb_menu_configuration(void *data, E_Menu *m, E_Menu_Item *mi);
123 static void _ibar_cb_icon_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
124 static void _ibar_cb_icon_mouse_out(void *data, Evas *e, Evas_Object *obj, void *event_info);
125 static void _ibar_cb_icon_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
126 static void _ibar_cb_icon_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
127 static void _ibar_cb_icon_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
128 static void _ibar_cb_icon_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
129 static void _ibar_cb_icon_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
130 static void _ibar_cb_icon_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
131 static void _ibar_inst_cb_enter(void *data, const char *type, void *event_info);
132 static void _ibar_inst_cb_move(void *data, const char *type, void *event_info);
133 static void _ibar_inst_cb_leave(void *data, const char *type, void *event_info);
134 static void _ibar_inst_cb_drop(void *data, const char *type, void *event_info);
135 static void _ibar_cb_drag_finished(E_Drag *data, int dropped);
136 static void _ibar_drop_position_update(Instance *inst, Evas_Coord x, Evas_Coord y);
137 static void _ibar_inst_cb_scroll(void *data);
138 static Eina_Bool _ibar_cb_config_icons(void *data, int ev_type, void *ev);
139 static void _ibar_exec_new_client_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
140 static Eina_Bool _ibar_cb_out_hide_delay(void *data);
141 static void _ibar_icon_menu_show(IBar_Icon *ic, Eina_Bool grab);
142 static void _ibar_icon_menu_hide(IBar_Icon *ic, Eina_Bool grab);
143 static void _ibar_cb_icon_menu_img_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
144 static void _ibar_cb_icon_frame_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
145
146 static E_Config_DD *conf_edd = NULL;
147 static E_Config_DD *conf_item_edd = NULL;
148
149 static Eina_Hash *ibar_orders = NULL;
150 static Eina_List *ibars = NULL;
151
152 EINTERN Config *ibar_config = NULL;
153
154 static inline const char *
_desktop_name_get(const Efreet_Desktop * desktop)155 _desktop_name_get(const Efreet_Desktop *desktop)
156 {
157 if (!desktop) return NULL;
158 return desktop->orig_path; //always return the orig_path
159 }
160
161 static IBar_Order *
_ibar_order_new(IBar * b,const char * path)162 _ibar_order_new(IBar *b, const char *path)
163 {
164 IBar_Order *io;
165
166 io = eina_hash_find(ibar_orders, path);
167 if (io)
168 {
169 io->bars = eina_inlist_append(io->bars, EINA_INLIST_GET(b));
170 return io;
171 }
172 io = E_NEW(IBar_Order, 1);
173 io->eo = e_order_new(path);
174 e_order_update_callback_set(io->eo, _ibar_cb_app_change, io);
175 eina_hash_add(ibar_orders, path, io);
176 io->bars = eina_inlist_append(io->bars, EINA_INLIST_GET(b));
177 return io;
178 }
179
180 static void
_ibar_order_del(IBar * b)181 _ibar_order_del(IBar *b)
182 {
183 IBar_Order *io;
184 if (!b->io) return;
185 io = b->io;
186 io->bars = eina_inlist_remove(io->bars, EINA_INLIST_GET(b));
187 b->io = NULL;
188 if (io->bars) return;
189 eina_hash_del_by_key(ibar_orders, io->eo->path);
190 e_order_update_callback_set(io->eo, NULL, NULL);
191 e_object_del(E_OBJECT(io->eo));
192 free(io);
193 }
194
195
196 static void
_ibar_order_refresh(IBar * b,const char * path)197 _ibar_order_refresh(IBar *b, const char *path)
198 {
199 IBar_Order *io;
200 IBar *bar;
201
202 io = eina_hash_find(ibar_orders, path);
203 if (io)
204 {
205 /* different order, remove/refresh */
206 if (io != b->io)
207 {
208 if (b->io) _ibar_order_del(b);
209 io->bars = eina_inlist_append(io->bars, EINA_INLIST_GET(b));
210 b->io = io;
211 }
212 /* else same order, refresh all users */
213 }
214 else
215 {
216 _ibar_order_del(b);
217 io = b->io = _ibar_order_new(b, path);
218 }
219 EINA_INLIST_FOREACH(io->bars, bar)
220 {
221 _ibar_empty(bar);
222 _ibar_fill(bar);
223 }
224 }
225
226 static void
_ibar_cb_iconify_end_cb(void * data,Evas_Object * obj EINA_UNUSED,const char * sig EINA_UNUSED,const char * src EINA_UNUSED)227 _ibar_cb_iconify_end_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
228 {
229 E_Client *ec = data;
230
231 evas_object_layer_set(ec->frame, ec->layer);
232 ec->layer_block = 0;
233 if (ec->iconic)
234 evas_object_hide(ec->frame);
235 }
236
237 static Eina_Bool
_ibar_cb_iconify_provider(void * data,Evas_Object * obj,const char * signal EINA_UNUSED)238 _ibar_cb_iconify_provider(void *data, Evas_Object *obj, const char *signal EINA_UNUSED)
239 {
240 Instance *inst = data;
241 IBar_Icon *ic;
242 int ox, oy, ow, oh;
243 E_Client *ec;
244
245 ec = e_comp_object_client_get(obj);
246 if (ec->zone != inst->gcc->gadcon->zone) return EINA_FALSE;
247 ic = eina_hash_find(inst->ibar->icon_hash, _desktop_name_get(ec->exe_inst ? ec->exe_inst->desktop : ec->desktop));
248 if (!ic) return EINA_FALSE;
249 ec->layer_block = 1;
250 evas_object_layer_set(ec->frame, E_LAYER_CLIENT_PRIO);
251 evas_object_geometry_get(ic->o_holder, &ox, &oy, &ow, &oh);
252 e_comp_object_effect_set(ec->frame, "iconify/ibar");
253 e_comp_object_effect_params_set(ec->frame, 1, (int[]){ec->x, ec->y, ec->w, ec->h, ox, oy, ow, oh}, 8);
254 e_comp_object_effect_params_set(ec->frame, 0, (int[]){!!strcmp(signal, "e,action,iconify")}, 1);
255 e_comp_object_effect_start(ec->frame, _ibar_cb_iconify_end_cb, ec);
256 return EINA_TRUE;
257 }
258
259 static E_Gadcon_Client *
_gc_init(E_Gadcon * gc,const char * name,const char * id,const char * style)260 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
261 {
262 IBar *b;
263 E_Gadcon_Client *gcc;
264 Instance *inst;
265 Evas_Coord x, y, w, h;
266 const char *drop[] = { "enlightenment/desktop", "enlightenment/border", "text/uri-list" };
267 Config_Item *ci;
268
269 inst = E_NEW(Instance, 1);
270
271 ci = _ibar_config_item_get(id);
272 inst->ci = ci;
273 if (!ci->dir) ci->dir = eina_stringshare_add("default");
274 b = _ibar_new(gc->o_container ?: e_comp->elm, inst);
275 gcc = e_gadcon_client_new(gc, name, id, style, b->o_outerbox);
276 e_gadcon_client_autoscroll_toggle_disabled_set(gcc, !ci->dont_add_nonorder);
277 gcc->data = inst;
278
279 inst->gcc = gcc;
280 inst->orient = E_GADCON_ORIENT_HORIZ;
281
282 evas_object_geometry_get(b->o_box, &x, &y, &w, &h);
283 inst->drop_handler =
284 e_drop_handler_add(E_OBJECT(inst->gcc), NULL, inst,
285 _ibar_inst_cb_enter, _ibar_inst_cb_move,
286 _ibar_inst_cb_leave, _ibar_inst_cb_drop,
287 drop, 3, x, y, w, h);
288 evas_object_event_callback_add(b->o_outerbox, EVAS_CALLBACK_MOVE,
289 _ibar_cb_obj_moveresize, inst);
290 evas_object_event_callback_add(b->o_outerbox, EVAS_CALLBACK_RESIZE,
291 _ibar_cb_obj_moveresize, inst);
292 ibar_config->instances = eina_list_append(ibar_config->instances, inst);
293 _ibar_resize_handle(b);
294 inst->iconify_provider = e_comp_object_effect_mover_add(80, "e,action,*iconify", _ibar_cb_iconify_provider, inst);
295 return gcc;
296 }
297
298 static void
_gc_shutdown(E_Gadcon_Client * gcc)299 _gc_shutdown(E_Gadcon_Client *gcc)
300 {
301 Instance *inst;
302
303 inst = gcc->data;
304 e_comp_object_effect_mover_del(inst->iconify_provider);
305 ibar_config->instances = eina_list_remove(ibar_config->instances, inst);
306 e_drop_handler_del(inst->drop_handler);
307 _ibar_free(inst->ibar);
308 E_FREE(inst);
309 }
310
311 static int
_convert_theme_ids(Instance * inst)312 _convert_theme_ids(Instance *inst)
313 {
314 switch (inst->orient)
315 {
316 case E_GADCON_ORIENT_FLOAT:
317 case E_GADCON_ORIENT_HORIZ:
318 case E_GADCON_ORIENT_VERT:
319 return -1;
320 case E_GADCON_ORIENT_BOTTOM:
321 case E_GADCON_ORIENT_CORNER_BL:
322 case E_GADCON_ORIENT_CORNER_BR:
323 return 0;
324 case E_GADCON_ORIENT_TOP:
325 case E_GADCON_ORIENT_CORNER_TL:
326 case E_GADCON_ORIENT_CORNER_TR:
327 return 1;
328 case E_GADCON_ORIENT_LEFT:
329 case E_GADCON_ORIENT_CORNER_LT:
330 case E_GADCON_ORIENT_CORNER_LB:
331 return 2;
332 case E_GADCON_ORIENT_RIGHT:
333 case E_GADCON_ORIENT_CORNER_RT:
334 case E_GADCON_ORIENT_CORNER_RB:
335 return 3;
336 default:
337 break;
338 }
339 return -1;
340 }
341
342 static Eina_Bool
_is_vertical(Instance * inst)343 _is_vertical(Instance *inst)
344 {
345 int pos = _convert_theme_ids(inst);
346 return (pos == 3 || pos == 2);
347 }
348
349 static void
_gc_orient(E_Gadcon_Client * gcc,E_Gadcon_Orient orient)350 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient)
351 {
352 Instance *inst;
353
354 inst = gcc->data;
355 if ((int)orient != -1) inst->orient = orient;
356
357 if (_is_vertical(inst))
358 {
359 _ibar_orient_set(inst->ibar, 0);
360 }
361 else
362 {
363 _ibar_orient_set(inst->ibar, 1);
364 }
365 }
366
367 static const char *
_gc_label(const E_Gadcon_Client_Class * client_class EINA_UNUSED)368 _gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
369 {
370 return _("IBar");
371 }
372
373 static Evas_Object *
_gc_icon(const E_Gadcon_Client_Class * client_class EINA_UNUSED,Evas * evas)374 _gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas *evas)
375 {
376 Evas_Object *o;
377 char buf[PATH_MAX];
378
379 o = edje_object_add(evas);
380 snprintf(buf, sizeof(buf), "%s/e-module-ibar.edj",
381 e_module_dir_get(ibar_config->module));
382 edje_object_file_set(o, buf, "icon");
383 return o;
384 }
385
386 static const char *
_gc_id_new(const E_Gadcon_Client_Class * client_class EINA_UNUSED)387 _gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
388 {
389 Config_Item *ci;
390
391 ci = _ibar_config_item_get(NULL);
392 return ci->id;
393 }
394
395 static void
_gc_id_del(const E_Gadcon_Client_Class * client_class EINA_UNUSED,const char * id EINA_UNUSED)396 _gc_id_del(const E_Gadcon_Client_Class *client_class EINA_UNUSED, const char *id EINA_UNUSED)
397 {
398 /* yes - don't do this. on shutdown gadgets are deleted and this means config
399 * for them is deleted - that means empty config is saved. keep them around
400 * as if u add a gadget back it can pick up its old config again
401 *
402 Config_Item *ci;
403
404 ci = _ibar_config_item_get(id);
405 if (ci)
406 {
407 if (ci->id) eina_stringshare_del(ci->id);
408 ibar_config->items = eina_list_remove(ibar_config->items, ci);
409 }
410 */
411 }
412
413 static IBar *
_ibar_new(Evas_Object * parent,Instance * inst)414 _ibar_new(Evas_Object *parent, Instance *inst)
415 {
416 IBar *b;
417 char buf[PATH_MAX];
418
419 b = E_NEW(IBar, 1);
420 inst->ibar = b;
421 b->inst = inst;
422 b->icon_hash = eina_hash_string_superfast_new(NULL);
423 b->o_outerbox = elm_box_add(e_win_evas_object_win_get(parent));
424 elm_box_horizontal_set(b->o_outerbox, 1);
425 elm_box_align_set(b->o_outerbox, 0.5, 0.5);
426 b->o_box = elm_box_add(e_win_evas_object_win_get(parent));
427 E_EXPAND(b->o_box);
428 E_ALIGN(b->o_box, 0, EVAS_HINT_FILL);
429 elm_box_homogeneous_set(b->o_box, 1);
430 elm_box_horizontal_set(b->o_box, 1);
431 elm_box_align_set(b->o_box, 0, 0.5);
432 elm_box_pack_end(b->o_outerbox, b->o_box);
433 if (inst->ci->dir[0] != '/')
434 e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order",
435 inst->ci->dir);
436 else
437 eina_strlcpy(buf, inst->ci->dir, sizeof(buf));
438 b->io = _ibar_order_new(b, buf);
439 _ibar_fill(b);
440 evas_object_show(b->o_box);
441 evas_object_show(b->o_outerbox);
442 ibars = eina_list_append(ibars, b);
443 return b;
444 }
445
446 static void
_ibar_free(IBar * b)447 _ibar_free(IBar *b)
448 {
449 _ibar_empty(b);
450 evas_object_del(b->o_box);
451 evas_object_del(b->o_outerbox);
452 if (b->o_drop) evas_object_del(b->o_drop);
453 if (b->o_drop_over) evas_object_del(b->o_drop_over);
454 if (b->o_empty) evas_object_del(b->o_empty);
455 E_FREE_FUNC(b->resize_job, ecore_job_del);
456 eina_hash_free(b->icon_hash);
457 _ibar_order_del(b);
458 ibars = eina_list_remove(ibars, b);
459 free(b);
460 }
461
462 static void
_ibar_cb_empty_mouse_down(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)463 _ibar_cb_empty_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
464 {
465 Evas_Event_Mouse_Down *ev;
466 IBar *b;
467 E_Menu *m;
468 E_Menu_Item *mi;
469 int cx, cy, cw, ch;
470
471 ev = event_info;
472 b = data;
473 if (ev->button != 3) return;
474
475 m = e_menu_new();
476
477 if (e_configure_registry_exists("applications/new_application"))
478 {
479 mi = e_menu_item_new(m);
480 e_menu_item_label_set(mi, _("Create new Icon"));
481 e_util_menu_item_theme_icon_set(mi, "document-new");
482 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_new, NULL);
483
484 mi = e_menu_item_new(m);
485 e_menu_item_separator_set(mi, 1);
486 }
487
488 if (e_configure_registry_exists("applications/ibar_applications"))
489 {
490 mi = e_menu_item_new(m);
491 e_menu_item_label_set(mi, _("Contents"));
492 e_util_menu_item_theme_icon_set(mi, "list-add");
493 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_add, b);
494 }
495
496 mi = e_menu_item_new(m);
497 e_menu_item_label_set(mi, _("Settings"));
498 e_util_menu_item_theme_icon_set(mi, "configure");
499 e_menu_item_callback_set(mi, _ibar_cb_menu_configuration, b);
500
501 m = e_gadcon_client_util_menu_items_append(b->inst->gcc, m, 0);
502
503 e_gadcon_canvas_zone_geometry_get(b->inst->gcc->gadcon,
504 &cx, &cy, &cw, &ch);
505 e_menu_activate_mouse(m,
506 e_zone_current_get(),
507 cx + ev->output.x, cy + ev->output.y, 1, 1,
508 E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
509 evas_event_feed_mouse_up(b->inst->gcc->gadcon->evas, ev->button,
510 EVAS_BUTTON_NONE, ev->timestamp, NULL);
511 }
512
513 static void
_ibar_empty_handle(IBar * b)514 _ibar_empty_handle(IBar *b)
515 {
516 if (!b->o_empty)
517 {
518 b->o_empty = evas_object_rectangle_add(evas_object_evas_get(b->o_box));
519 E_EXPAND(b->o_empty);
520 E_FILL(b->o_empty);
521 evas_object_event_callback_add(b->o_empty,
522 EVAS_CALLBACK_MOUSE_DOWN,
523 _ibar_cb_empty_mouse_down, b);
524 evas_object_color_set(b->o_empty, 0, 0, 0, 0);
525 }
526 if (b->icons) return;
527 evas_object_show(b->o_empty);
528 elm_box_pack_end(b->o_box, b->o_empty);
529 }
530
531 static void
_ibar_fill(IBar * b)532 _ibar_fill(IBar *b)
533 {
534 IBar_Icon *ic;
535 int w, h;
536
537 if (b->io->eo)
538 {
539 Efreet_Desktop *desktop;
540 const Eina_List *l;
541
542 EINA_LIST_FOREACH(b->io->eo->desktops, l, desktop)
543 {
544 const Eina_List *ll;
545 ic = _ibar_icon_new(b, desktop, 0);
546 ll = e_exec_desktop_instances_find(desktop);
547 if (ll)
548 {
549 ic->exes = eina_list_clone(ll);
550 _ibar_icon_signal_emit(ic, "e,state,on", "e");
551 }
552 }
553 }
554 if (!b->inst->ci->dont_add_nonorder)
555 {
556 const Eina_Hash *execs = e_exec_instances_get();
557 Eina_Iterator *it;
558 const Eina_List *l, *ll;
559 E_Exec_Instance *exe;
560
561 it = eina_hash_iterator_data_new(execs);
562 EINA_ITERATOR_FOREACH(it, l)
563 {
564 EINA_LIST_FOREACH(l, ll, exe)
565 {
566 E_Client *ec;
567 Eina_List *lll;
568 Eina_Bool skip = EINA_TRUE;
569
570 if (!exe->desktop) continue;
571 EINA_LIST_FOREACH(exe->clients, lll, ec)
572 if (!ec->netwm.state.skip_taskbar)
573 {
574 skip = EINA_FALSE;
575 break;
576 }
577 if (skip) continue;
578 ic = eina_hash_find(b->icon_hash, _desktop_name_get(exe->desktop));
579 if (ic)
580 {
581 if (!eina_list_data_find(ic->exes, exe))
582 ic->exes = eina_list_append(ic->exes, exe);
583 continue;
584 }
585 _ibar_sep_create(b);
586 _ibar_icon_notinorder_new(b, exe);
587 }
588 }
589 eina_iterator_free(it);
590 }
591
592 _ibar_empty_handle(b);
593 _ibar_resize_handle(b);
594 if (!b->inst->gcc) return;
595 evas_object_size_hint_min_get(b->o_box, &w, &h);
596 evas_object_size_hint_max_set(b->o_box, w, h);
597 }
598
599 static void
_ibar_empty(IBar * b)600 _ibar_empty(IBar *b)
601 {
602 while (b->icons)
603 _ibar_icon_free((IBar_Icon*)b->icons);
604
605 E_FREE_FUNC(b->o_sep, evas_object_del);
606 _ibar_empty_handle(b);
607 }
608
609 static void
_ibar_orient_set(IBar * b,int horizontal)610 _ibar_orient_set(IBar *b, int horizontal)
611 {
612 Evas_Coord w, h;
613
614 if (b->o_sep)
615 {
616 if (!horizontal)
617 e_theme_edje_object_set(b->o_sep, "base/theme/modules/ibar", "e/modules/ibar/separator/horizontal");
618 else
619 e_theme_edje_object_set(b->o_sep, "base/theme/modules/ibar", "e/modules/ibar/separator/default");
620 edje_object_size_min_calc(b->o_sep, &w, &h);
621 evas_object_size_hint_min_set(b->o_sep, w, h);
622 }
623 elm_box_horizontal_set(b->o_box, horizontal);
624 elm_box_horizontal_set(b->o_outerbox, horizontal);
625 }
626
627 static void
_ibar_resize_handle(IBar * b)628 _ibar_resize_handle(IBar *b)
629 {
630 IBar_Icon *ic;
631 Evas_Coord w, h;
632
633 if (!b->inst->gcc) return;
634 elm_box_recalculate(b->o_box);
635 elm_box_recalculate(b->o_outerbox);
636 if (!e_gadcon_site_is_desktop(b->inst->gcc->gadcon->location->site))
637 evas_object_size_hint_min_get(b->o_outerbox, &w, &h);
638 else
639 evas_object_geometry_get(b->o_outerbox, NULL, NULL, &w, &h);
640 if (b->inst->gcc->max.w)
641 w = MIN(w, b->inst->gcc->max.w);
642 if (b->inst->gcc->max.h)
643 h = MIN(h, b->inst->gcc->max.h);
644 if (elm_box_horizontal_get(b->o_box))
645 w = h;
646 else
647 h = w;
648 if (w || h)
649 evas_object_size_hint_min_set(b->o_empty, w, h);
650 if (b->icons && evas_object_visible_get(b->o_empty))
651 {
652 elm_box_unpack(b->o_box, b->o_empty);
653 evas_object_hide(b->o_empty);
654 }
655 EINA_INLIST_FOREACH(b->icons, ic)
656 {
657 evas_object_size_hint_min_set(ic->o_holder, w, h);
658 evas_object_size_hint_max_set(ic->o_holder, w, h);
659 }
660 if (b->o_sep)
661 {
662 if (_is_vertical(b->inst))
663 h = 16 * e_scale;
664 else
665 w = 16 * e_scale;
666 evas_object_size_hint_min_set(b->o_sep, 8, 8);
667 evas_object_size_hint_max_set(b->o_sep, w, h);
668 }
669 elm_box_recalculate(b->o_box);
670 elm_box_recalculate(b->o_outerbox);
671 evas_object_size_hint_min_get(b->o_outerbox, &w, &h);
672 if ((!w) || (!h)) return;
673 e_gadcon_client_min_size_set(b->inst->gcc, w, h);
674 e_gadcon_client_aspect_set(b->inst->gcc, w, h);
675 }
676
677 static void
_ibar_instance_drop_zone_recalc(Instance * inst)678 _ibar_instance_drop_zone_recalc(Instance *inst)
679 {
680 Evas_Coord x, y, w, h;
681
682 e_gadcon_client_viewport_geometry_get(inst->gcc, &x, &y, &w, &h);
683 e_drop_handler_geometry_set(inst->drop_handler, x, y, w, h);
684 }
685
686 static Config_Item *
_ibar_config_item_get(const char * id)687 _ibar_config_item_get(const char *id)
688 {
689 Config_Item *ci;
690
691 GADCON_CLIENT_CONFIG_GET(Config_Item, ibar_config->items, _gadcon_class, id);
692
693 ci = E_NEW(Config_Item, 1);
694 ci->id = eina_stringshare_add(id);
695 ci->dir = eina_stringshare_add("default");
696 ci->show_label = 1;
697 ci->eap_label = 0;
698 ci->lock_move = 0;
699 ci->dont_add_nonorder = 0;
700 ci->dont_track_launch = 0;
701 ci->dont_icon_menu_mouseover = 0;
702 ibar_config->items = eina_list_append(ibar_config->items, ci);
703 return ci;
704 }
705
706 void
_ibar_config_update(Config_Item * ci)707 _ibar_config_update(Config_Item *ci)
708 {
709 const Eina_List *l;
710 Instance *inst;
711 IBar_Icon *ic;
712
713 EINA_LIST_FOREACH(ibar_config->instances, l, inst)
714 {
715 char buf[PATH_MAX];
716
717 if (inst->ci != ci) continue;
718
719 if (inst->ci->dir[0] != '/')
720 e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s/.order",
721 inst->ci->dir);
722 else
723 eina_strlcpy(buf, inst->ci->dir, sizeof(buf));
724 _ibar_order_refresh(inst->ibar, buf);
725 _ibar_resize_handle(inst->ibar);
726 _gc_orient(inst->gcc, -1);
727 }
728 EINA_LIST_FOREACH(ibar_config->instances, l, inst)
729 EINA_INLIST_FOREACH(inst->ibar->icons, ic)
730 {
731 switch (ci->eap_label)
732 {
733 case 0:
734 edje_object_part_text_set(ic->o_holder2, "e.text.label",
735 ic->app->name);
736 break;
737
738 case 1:
739 edje_object_part_text_set(ic->o_holder2, "e.text.label",
740 ic->app->comment);
741 break;
742
743 case 2:
744 edje_object_part_text_set(ic->o_holder2, "e.text.label",
745 ic->app->generic_name);
746 break;
747 }
748 }
749 }
750
751 static void
_ibar_sep_create(IBar * b)752 _ibar_sep_create(IBar *b)
753 {
754 Evas_Coord w, h;
755 if (b->o_sep) return;
756
757 b->o_sep = edje_object_add(evas_object_evas_get(b->o_box));
758 E_FILL(b->o_sep);
759 if (_is_vertical(b->inst))
760 e_theme_edje_object_set(b->o_sep, "base/theme/modules/ibar", "e/modules/ibar/separator/horizontal");
761 else
762 e_theme_edje_object_set(b->o_sep, "base/theme/modules/ibar", "e/modules/ibar/separator/default");
763 evas_object_show(b->o_sep);
764 elm_box_pack_end(b->o_outerbox, b->o_sep);
765 edje_object_size_min_calc(b->o_sep, &w, &h);
766 evas_object_size_hint_min_set(b->o_sep, w, h);
767 }
768
769 static IBar_Icon *
_ibar_icon_at_coord(IBar * b,Evas_Coord x,Evas_Coord y)770 _ibar_icon_at_coord(IBar *b, Evas_Coord x, Evas_Coord y)
771 {
772 IBar_Icon *ic;
773
774 EINA_INLIST_FOREACH(b->icons, ic)
775 {
776 Evas_Coord dx, dy, dw, dh;
777
778 /* block drops in the non-order section */
779 if (ic->not_in_order) continue;
780 evas_object_geometry_get(ic->o_holder, &dx, &dy, &dw, &dh);
781 if (E_INSIDE(x, y, dx, dy, dw, dh))
782 return ic;
783 }
784 return NULL;
785 }
786
787 static IBar_Icon *
_ibar_icon_new(IBar * b,Efreet_Desktop * desktop,Eina_Bool notinorder)788 _ibar_icon_new(IBar *b, Efreet_Desktop *desktop, Eina_Bool notinorder)
789 {
790 IBar_Icon *ic;
791
792 ic = E_NEW(IBar_Icon, 1);
793 ic->ibar = b;
794 ic->app = desktop;
795 efreet_desktop_ref(desktop);
796 ic->o_holder = edje_object_add(evas_object_evas_get(b->o_box));
797 E_FILL(ic->o_holder);
798 e_theme_edje_object_set(ic->o_holder, "base/theme/modules/ibar",
799 "e/modules/ibar/icon");
800 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_IN,
801 _ibar_cb_icon_mouse_in, ic);
802 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_OUT,
803 _ibar_cb_icon_mouse_out, ic);
804 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_DOWN,
805 _ibar_cb_icon_mouse_down, ic);
806 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_UP,
807 _ibar_cb_icon_mouse_up, ic);
808 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_MOVE,
809 _ibar_cb_icon_mouse_move, ic);
810 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOUSE_WHEEL,
811 _ibar_cb_icon_wheel, ic);
812 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_MOVE,
813 _ibar_cb_icon_move, ic);
814 evas_object_event_callback_add(ic->o_holder, EVAS_CALLBACK_RESIZE,
815 _ibar_cb_icon_resize, ic);
816 evas_object_show(ic->o_holder);
817
818 ic->o_holder2 = edje_object_add(evas_object_evas_get(b->o_box));
819 evas_object_name_set(ic->o_holder2, "ibar_icon->o_holder2");
820 e_theme_edje_object_set(ic->o_holder2, "base/theme/modules/ibar",
821 "e/modules/ibar/icon_overlay");
822 evas_object_layer_set(ic->o_holder2, 9999);
823 evas_object_pass_events_set(ic->o_holder2, 1);
824 evas_object_show(ic->o_holder2);
825
826 _ibar_icon_fill(ic);
827 b->icons = eina_inlist_append(b->icons, EINA_INLIST_GET(ic));
828 if (eina_hash_find(b->icon_hash, _desktop_name_get(ic->app)))
829 {
830 char buf[PATH_MAX];
831
832 ERR("Ibar - Unexpected: icon with same desktop path created twice");
833 snprintf(buf, sizeof(buf), "%s::%1.20f",
834 _desktop_name_get(ic->app), ecore_time_get());
835 ic->hashname = eina_stringshare_add(buf);
836 }
837 else ic->hashname = eina_stringshare_add(_desktop_name_get(ic->app));
838 eina_hash_add(b->icon_hash, ic->hashname, ic);
839 if (notinorder)
840 {
841 ic->not_in_order = 1;
842 b->not_in_order_count++;
843 elm_box_pack_end(b->o_outerbox, ic->o_holder);
844 }
845 else
846 elm_box_pack_end(b->o_box, ic->o_holder);
847 return ic;
848 }
849
850 static IBar_Icon *
_ibar_icon_notinorder_new(IBar * b,E_Exec_Instance * exe)851 _ibar_icon_notinorder_new(IBar *b, E_Exec_Instance *exe)
852 {
853 IBar_Icon *ic;
854
855 ic = _ibar_icon_new(b, exe->desktop, 1);
856 ic->exes = eina_list_append(ic->exes, exe);
857 _ibar_icon_signal_emit(ic, "e,state,on", "e");
858 return ic;
859 }
860
861 static void
_ibar_cb_icon_menu_client_menu_del(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)862 _ibar_cb_icon_menu_client_menu_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
863 {
864 IBar *b = data;
865
866 evas_object_event_callback_del(obj, EVAS_CALLBACK_HIDE, _ibar_cb_icon_menu_client_menu_del);
867 if (!b->menu_icon) return;
868 if (b->menu_icon->hide_timer)
869 ecore_timer_loop_reset(b->menu_icon->hide_timer);
870 else
871 b->menu_icon->hide_timer = ecore_timer_loop_add(0.5, _ibar_cb_out_hide_delay, b->menu_icon);
872 }
873
874 static void
_ibar_icon_free(IBar_Icon * ic)875 _ibar_icon_free(IBar_Icon *ic)
876 {
877 E_Exec_Instance *inst;
878 Evas_Object *o;
879
880 EINA_LIST_FREE(ic->client_objs, o)
881 {
882 evas_object_event_callback_del(o, EVAS_CALLBACK_DEL,
883 _ibar_cb_icon_frame_del);
884 evas_object_event_callback_del(o, EVAS_CALLBACK_DEL,
885 _ibar_cb_icon_menu_img_del);
886 evas_object_del(o);
887 }
888 if (ic->ibar->menu_icon == ic) ic->ibar->menu_icon = NULL;
889 if (ic->ibar->ic_drop_before == ic) ic->ibar->ic_drop_before = NULL;
890 if (ic->menu) e_object_data_set(E_OBJECT(ic->menu), NULL);
891 E_FREE_FUNC(ic->menu, e_object_del);
892 E_FREE_FUNC(ic->timer, ecore_timer_del);
893 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
894 E_FREE_FUNC(ic->show_timer, ecore_timer_del);
895 ic->ibar->icons = eina_inlist_remove(ic->ibar->icons, EINA_INLIST_GET(ic));
896 eina_hash_del_by_key(ic->ibar->icon_hash, ic->hashname);
897 E_FREE_FUNC(ic->hashname, eina_stringshare_del);
898 E_FREE_FUNC(ic->reset_timer, ecore_timer_del);
899 if (ic->app) efreet_desktop_unref(ic->app);
900 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_IN,
901 _ibar_cb_icon_mouse_in, ic);
902 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_OUT,
903 _ibar_cb_icon_mouse_out, ic);
904 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_DOWN,
905 _ibar_cb_icon_mouse_down, ic);
906 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_UP,
907 _ibar_cb_icon_mouse_up, ic);
908 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_MOVE,
909 _ibar_cb_icon_mouse_move, ic);
910 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOUSE_WHEEL,
911 _ibar_cb_icon_wheel, ic);
912 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_MOVE,
913 _ibar_cb_icon_move, ic);
914 evas_object_event_callback_del_full(ic->o_holder, EVAS_CALLBACK_RESIZE,
915 _ibar_cb_icon_resize, ic);
916 ic->ibar->not_in_order_count -= ic->not_in_order;
917 if (ic->ibar->ic_drop_before == ic)
918 ic->ibar->ic_drop_before = NULL;
919 _ibar_icon_empty(ic);
920 EINA_LIST_FREE(ic->exes, inst)
921 {
922 E_Client *ec;
923 Eina_List *ll;
924
925 if (!ic->not_in_order)
926 e_exec_instance_watcher_del(inst, _ibar_instance_watch, ic);
927 EINA_LIST_FOREACH(inst->clients, ll, ec)
928 if (ec->border_menu)
929 evas_object_event_callback_del(ec->border_menu->comp_object, EVAS_CALLBACK_HIDE, _ibar_cb_icon_menu_client_menu_del);
930 }
931 evas_object_del(ic->o_holder);
932 evas_object_del(ic->o_holder2);
933 if (ic->exe_inst)
934 {
935 e_exec_instance_watcher_del(ic->exe_inst, _ibar_instance_watch, ic);
936 ic->exe_inst = NULL;
937 }
938 free(ic);
939 }
940
941 static void
_ibar_icon_fill(IBar_Icon * ic)942 _ibar_icon_fill(IBar_Icon *ic)
943 {
944 if (ic->o_icon) evas_object_del(ic->o_icon);
945 ic->o_icon = e_icon_add(evas_object_evas_get(ic->ibar->o_box));
946 evas_object_name_set(ic->o_icon, "icon");
947 e_icon_fdo_icon_set(ic->o_icon, ic->app->icon);
948 edje_object_part_swallow(ic->o_holder, "e.swallow.content", ic->o_icon);
949 evas_object_show(ic->o_icon);
950 if (ic->o_icon2) evas_object_del(ic->o_icon2);
951 ic->o_icon2 = e_icon_add(evas_object_evas_get(ic->ibar->o_box));
952 e_icon_fdo_icon_set(ic->o_icon2, ic->app->icon);
953 edje_object_part_swallow(ic->o_holder2, "e.swallow.content", ic->o_icon2);
954 evas_object_show(ic->o_icon2);
955
956 switch (ic->ibar->inst->ci->eap_label)
957 {
958 case 0: /* Eap Name */
959 edje_object_part_text_set(ic->o_holder2, "e.text.label", ic->app->name);
960 break;
961
962 case 1: /* Eap Comment */
963 edje_object_part_text_set(ic->o_holder2, "e.text.label", ic->app->comment);
964 break;
965
966 case 2: /* Eap Generic */
967 edje_object_part_text_set(ic->o_holder2, "e.text.label", ic->app->generic_name);
968 break;
969 }
970 }
971
972 static void
_ibar_icon_empty(IBar_Icon * ic)973 _ibar_icon_empty(IBar_Icon *ic)
974 {
975 if (ic->o_icon) evas_object_del(ic->o_icon);
976 if (ic->o_icon2) evas_object_del(ic->o_icon2);
977 ic->o_icon = NULL;
978 ic->o_icon2 = NULL;
979 }
980
981 static void
_ibar_icon_signal_emit(IBar_Icon * ic,const char * sig,const char * src)982 _ibar_icon_signal_emit(IBar_Icon *ic, const char *sig, const char *src)
983 {
984 if (ic->o_holder)
985 edje_object_signal_emit(ic->o_holder, sig, src);
986 if (ic->o_icon && e_icon_edje_get(ic->o_icon))
987 e_icon_edje_emit(ic->o_icon, sig, src);
988 if (ic->o_holder2)
989 edje_object_signal_emit(ic->o_holder2, sig, src);
990 if (ic->o_icon2 && e_icon_edje_get(ic->o_icon2))
991 e_icon_edje_emit(ic->o_icon2, sig, src);
992 }
993
994 static void
_ibar_cb_app_change(void * data,E_Order * eo EINA_UNUSED)995 _ibar_cb_app_change(void *data, E_Order *eo EINA_UNUSED)
996 {
997 IBar *b;
998 IBar_Order *io = data;
999
1000 EINA_INLIST_FOREACH(io->bars, b)
1001 {
1002 _ibar_empty(b);
1003 if (b->inst)
1004 {
1005 _ibar_fill(b);
1006 if (b->inst->gcc) _gc_orient(b->inst->gcc, -1);
1007 }
1008 }
1009 }
1010
1011 static void
_ibar_cb_resize_job(void * data)1012 _ibar_cb_resize_job(void *data)
1013 {
1014 Instance *inst = data;
1015 _ibar_resize_handle(inst->ibar);
1016 _ibar_instance_drop_zone_recalc(inst);
1017 inst->ibar->resize_job = NULL;
1018 }
1019
1020 static void
_ibar_cb_obj_moveresize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1021 _ibar_cb_obj_moveresize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1022 {
1023 Instance *inst = data;
1024
1025 if (inst->ibar->resize_job) return;
1026 inst->ibar->resize_job = ecore_job_add((Ecore_Cb)_ibar_cb_resize_job, inst);
1027 }
1028
1029 static void
_ibar_cb_menu_icon_action_exec(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1030 _ibar_cb_menu_icon_action_exec(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1031 {
1032 Efreet_Desktop_Action *action = (Efreet_Desktop_Action*)data;
1033 e_exec(NULL, NULL, action->exec, NULL, "ibar");
1034 }
1035
1036 static void
_ibar_cb_menu_icon_new(void * data EINA_UNUSED,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1037 _ibar_cb_menu_icon_new(void *data EINA_UNUSED, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1038 {
1039 if (!e_configure_registry_exists("applications/new_application")) return;
1040 e_configure_registry_call("applications/new_application", NULL, NULL);
1041 }
1042
1043 static void
_ibar_cb_menu_icon_add(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1044 _ibar_cb_menu_icon_add(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1045 {
1046 char path[PATH_MAX];
1047 IBar *b;
1048
1049 b = data;
1050 e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order",
1051 b->inst->ci->dir);
1052 e_configure_registry_call("internal/ibar_other", NULL, path);
1053 }
1054
1055 static void
_ibar_cb_menu_icon_properties(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1056 _ibar_cb_menu_icon_properties(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1057 {
1058 IBar_Icon *ic;
1059
1060 ic = data;
1061 e_desktop_edit(ic->app);
1062 }
1063
1064 static void
_ibar_cb_menu_icon_stick(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1065 _ibar_cb_menu_icon_stick(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1066 {
1067 IBar_Icon *ic = data;
1068
1069 e_order_append(ic->ibar->io->eo, ic->app);
1070 _ibar_icon_free(ic);
1071 }
1072
1073 static void
_ibar_cb_menu_icon_remove(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1074 _ibar_cb_menu_icon_remove(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1075 {
1076 IBar_Icon *ic = data;
1077 IBar *i;
1078
1079 i = ic->ibar;
1080 e_order_remove(i->io->eo, ic->app);
1081 _ibar_icon_free(ic);
1082 _ibar_resize_handle(i);
1083 }
1084
1085 static void
_ibar_cb_menu_configuration(void * data,E_Menu * m EINA_UNUSED,E_Menu_Item * mi EINA_UNUSED)1086 _ibar_cb_menu_configuration(void *data, E_Menu *m EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
1087 {
1088 IBar *b;
1089
1090 b = data;
1091 _config_ibar_module(b->inst->ci);
1092 }
1093
1094 static void
_ibar_cb_icon_menu_hide_begin(IBar_Icon * ic)1095 _ibar_cb_icon_menu_hide_begin(IBar_Icon *ic)
1096 {
1097 if (!ic->menu) return;
1098 evas_object_pass_events_set(ic->menu->comp_object, 1);
1099 edje_object_signal_emit(ic->menu->o_bg, "e,action,hide", "e");
1100 }
1101
1102 static void
_ibar_cb_icon_menu_mouse_up(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info)1103 _ibar_cb_icon_menu_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info)
1104 {
1105 IBar_Icon *ic;
1106 E_Client *ec = data;
1107 Evas_Event_Mouse_Up *ev = event_info;
1108
1109 ic = evas_object_data_get(obj, "ibar_icon");
1110 if (!ic) return;
1111 if (ev->button == 3)
1112 {
1113 e_int_client_menu_show(ec, ev->canvas.x, ev->canvas.y, 0, ev->timestamp);
1114 evas_object_event_callback_add(ec->border_menu->comp_object, EVAS_CALLBACK_HIDE, _ibar_cb_icon_menu_client_menu_del, ic->ibar);
1115 return;
1116 }
1117 e_client_activate(ec, 1);
1118 if (ic)
1119 _ibar_cb_icon_menu_hide_begin(ic);
1120 }
1121
1122 static void
_ibar_cb_icon_menu_del(void * obj)1123 _ibar_cb_icon_menu_del(void *obj)
1124 {
1125 IBar_Icon *ic = e_object_data_get(obj);
1126
1127 if (!ic) return;
1128 ic->menu = NULL;
1129 }
1130
1131 static void
_ibar_cb_icon_menu_autodel(void * data,Evas_Object * obj EINA_UNUSED)1132 _ibar_cb_icon_menu_autodel(void *data, Evas_Object *obj EINA_UNUSED)
1133 {
1134 _ibar_cb_icon_menu_hide_begin(data);
1135 }
1136
1137 static void
_ibar_cb_icon_menu_shown(void * data,Evas_Object * obj EINA_UNUSED,const char * sig EINA_UNUSED,const char * src EINA_UNUSED)1138 _ibar_cb_icon_menu_shown(void *data, Evas_Object *obj EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
1139 {
1140 IBar_Icon *ic = data;
1141
1142 evas_object_pass_events_set(ic->menu->o_bg, 0);
1143 }
1144
1145 static void
_ibar_cb_icon_menu_hidden(void * data,Evas_Object * obj EINA_UNUSED,const char * sig EINA_UNUSED,const char * src EINA_UNUSED)1146 _ibar_cb_icon_menu_hidden(void *data, Evas_Object *obj EINA_UNUSED, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
1147 {
1148 IBar_Icon *ic = data;
1149 E_Client *ec;
1150
1151 E_OBJECT_DEL_SET(ic->menu, NULL);
1152 E_FREE_FUNC(ic->menu, e_object_del);
1153 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1154 EINA_LIST_FREE(ic->menu_pending, ec)
1155 evas_object_event_callback_del_full(ec->frame, EVAS_CALLBACK_SHOW, _ibar_exec_new_client_show, ic);
1156 }
1157
1158 static void
_ibar_icon_menu_recalc(IBar_Icon * ic)1159 _ibar_icon_menu_recalc(IBar_Icon *ic)
1160 {
1161 int x, y, w, h, iw, ih, ox, oy;
1162 Evas_Object *o;
1163 E_Zone *zone;
1164
1165 o = ic->menu->o_bg;
1166
1167 edje_object_calc_force(o);
1168 edje_object_size_min_calc(o, &w, &h);
1169 zone = e_gadcon_zone_get(ic->ibar->inst->gcc->gadcon);
1170 evas_object_geometry_get(ic->o_holder, &x, &y, &iw, &ih);
1171 evas_object_size_hint_min_set(o, w, h);
1172 ic->menu->w = w, ic->menu->h = h;
1173 evas_object_resize(ic->menu->comp_object, w, h);
1174 e_gadcon_popup_show(ic->menu);
1175 evas_object_geometry_get(ic->menu->comp_object, &ox, &oy, NULL, NULL);
1176 if (elm_box_horizontal_get(ic->ibar->o_box))
1177 {
1178 ox = (x + (iw / 2)) - (w / 2);
1179 if (E_INTERSECTS(ox, oy, w, h, x, y, iw, ih))
1180 {
1181 if (y > h / 2)
1182 oy = y - h;
1183 else
1184 oy = y + ih;
1185 }
1186 }
1187 else
1188 oy = (y + (ih / 2)) - (h / 2);
1189 ox = E_CLAMP(ox, zone->x, zone->x + zone->w - w);
1190 evas_object_move(ic->menu->comp_object, ox, oy);
1191 }
1192
1193 static void
_ibar_cb_icon_menu_focus_change(void * data,Evas_Object * obj,const char * sig EINA_UNUSED,const char * src EINA_UNUSED)1194 _ibar_cb_icon_menu_focus_change(void *data, Evas_Object *obj, const char *sig EINA_UNUSED, const char *src EINA_UNUSED)
1195 {
1196 E_Client *ec;
1197
1198 ec = e_comp_object_client_get(obj);
1199 if (ec->focused)
1200 edje_object_signal_emit(data, "e,state,focused", "e");
1201 else
1202 edje_object_signal_emit(data, "e,state,unfocused", "e");
1203 }
1204
1205 static void
_ibar_cb_icon_menu_desk_change(void * data,Evas_Object * obj EINA_UNUSED,void * event_info)1206 _ibar_cb_icon_menu_desk_change(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
1207 {
1208 E_Client *ec = event_info;
1209 IBar_Icon *ic;
1210
1211 ic = evas_object_data_get(data, "ibar_icon");
1212 if (!ic) return;
1213
1214 if (ec->sticky || (ec->zone != ic->ibar->inst->gcc->gadcon->zone))
1215 edje_object_signal_emit(data, "e,state,other,screen", "e");
1216 else if (!ec->desk->visible)
1217 edje_object_signal_emit(data, "e,state,other,desk", "e");
1218 else
1219 edje_object_signal_emit(data, "e,state,other,none", "e");
1220 }
1221
1222 static void
_ibar_icon_menu_mouse_in(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1223 _ibar_icon_menu_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1224 {
1225 IBar_Icon *ic = data;
1226
1227 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1228 }
1229
1230 static void
_ibar_icon_menu_mouse_out(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1231 _ibar_icon_menu_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1232 {
1233 IBar_Icon *ic = data;
1234
1235 if (e_comp_util_mouse_grabbed()) return;
1236 if (ic->hide_timer)
1237 ecore_timer_loop_reset(ic->hide_timer);
1238 else
1239 ic->hide_timer = ecore_timer_loop_add(0.5, _ibar_cb_out_hide_delay, ic);
1240 }
1241
1242 static void
_ibar_cb_icon_menu_img_del(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)1243 _ibar_cb_icon_menu_img_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
1244 {
1245 int w, h;
1246 E_Client *ec;
1247 IBar_Icon *ic;
1248
1249 ic = evas_object_data_del(obj, "ibar_icon");
1250 if (!ic) return; //menu is closing
1251
1252 evas_object_data_del(obj, "ibar_icon");
1253 ic->client_objs = eina_list_remove(ic->client_objs, obj);
1254
1255 if (!ic->menu) return; //who knows
1256 edje_object_part_box_remove(ic->menu->o_bg, "e.box", data);
1257 ec = evas_object_data_get(obj, "E_Client");
1258 if (ec)
1259 {
1260 e_comp_object_signal_callback_del_full(ec->frame, "e,state,*focused", "e", _ibar_cb_icon_menu_focus_change, data);
1261 evas_object_smart_callback_del_full(ec->frame, "desk_change", _ibar_cb_icon_menu_desk_change, data);
1262 }
1263 evas_object_del(data);
1264 if (eina_list_count(ic->exes) <= 1)
1265 {
1266 E_Exec_Instance *inst = eina_list_data_get(ic->exes);
1267
1268 if ((!inst) || (!inst->clients))
1269 {
1270 _ibar_cb_icon_menu_hide_begin(ic);
1271 return;
1272 }
1273 }
1274 edje_object_calc_force(ic->menu->o_bg);
1275 edje_object_size_min_calc(ic->menu->o_bg, &w, &h);
1276 evas_object_size_hint_min_set(ic->menu->o_bg, w, h);
1277 if (elm_box_horizontal_get(ic->ibar->o_box))
1278 {
1279 int cx, cy, cw, ch, ny;
1280 E_Zone *zone;
1281
1282 evas_object_geometry_get(ic->menu->comp_object, &cx, &cy, &cw, &ch);
1283 zone = e_gadcon_zone_get(ic->ibar->inst->gcc->gadcon);
1284 if (cy > (zone->h / 2))
1285 ny = cy - (h - ch);
1286 else
1287 ny = cy;
1288 evas_object_geometry_set(ic->menu->comp_object, cx, ny, w, h);
1289 }
1290 else
1291 evas_object_resize(ic->menu->comp_object, w, h);
1292 }
1293
1294 static void
_ibar_cb_icon_frame_del(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)1295 _ibar_cb_icon_frame_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
1296 {
1297 IBar_Icon *ic = evas_object_data_del(obj, "ibar_icon");
1298
1299 if (ic)
1300 {
1301 evas_object_data_del(obj, "ibar_icon");
1302 ic->client_objs = eina_list_remove(ic->client_objs, obj);
1303 }
1304 e_comp_object_signal_callback_del_full(data, "e,state,*focused", "e", _ibar_cb_icon_menu_focus_change, obj);
1305 evas_object_smart_callback_del_full(data, "desk_change", _ibar_cb_icon_menu_desk_change, obj);
1306 }
1307
1308 static Eina_Bool
_ibar_menu_client_have(IBar_Icon * ic,E_Client * ec)1309 _ibar_menu_client_have(IBar_Icon *ic, E_Client *ec)
1310 {
1311 Eina_List *l;
1312 Evas_Object *o;
1313 E_Client *ec2;
1314
1315 EINA_LIST_FOREACH(ic->client_objs, l, o)
1316 {
1317 ec2 = evas_object_data_get(o, "client");
1318 if (ec2 == ec) return EINA_TRUE;
1319 }
1320 return EINA_FALSE;
1321 }
1322
1323 static Eina_Bool
_ibar_icon_menu_client_add(IBar_Icon * ic,E_Client * ec)1324 _ibar_icon_menu_client_add(IBar_Icon *ic, E_Client *ec)
1325 {
1326 Evas_Object *o, *it, *img;
1327 Eina_Stringshare *txt;
1328 E_Client *ec2;
1329 int w, h;
1330
1331 if (ec->netwm.state.skip_taskbar || e_client_util_ignored_get(ec)) return EINA_FALSE;
1332 if (e_client_util_is_popup(ec)) return EINA_FALSE;
1333 o = ic->menu->o_bg;
1334 it = edje_object_add(e_comp->evas);
1335 e_comp_object_util_del_list_append(ic->menu->comp_object, it);
1336 e_theme_edje_object_set(it, "base/theme/modules/ibar",
1337 "e/modules/ibar/menu/item");
1338 evas_object_data_set(it, "ibar_icon", ic);
1339 evas_object_data_set(it, "client", ec);
1340 ic->client_objs = eina_list_append(ic->client_objs, it);
1341 evas_object_event_callback_add(it, EVAS_CALLBACK_DEL,
1342 _ibar_cb_icon_frame_del, ec->frame);
1343
1344 ec2 = e_client_stack_active_adjust(ec);
1345
1346 img = e_comp_object_util_mirror_add(ec2->frame);
1347 evas_object_data_set(img, "ibar_icon", ic);
1348 ic->client_objs = eina_list_append(ic->client_objs, img);
1349 evas_object_event_callback_add(img, EVAS_CALLBACK_DEL,
1350 _ibar_cb_icon_menu_img_del, it);
1351
1352 e_comp_object_signal_callback_add(ec2->frame, "e,state,*focused", "e", _ibar_cb_icon_menu_focus_change, it);
1353 evas_object_smart_callback_add(ec2->frame, "desk_change", _ibar_cb_icon_menu_desk_change, it);
1354
1355 txt = e_client_util_name_get(ec2);
1356 w = ec->client.w;
1357 h = ec->client.h;
1358 e_comp_object_util_del_list_append(ic->menu->comp_object, img);
1359 evas_object_show(img);
1360 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_BOTH, w, h);
1361 edje_object_part_swallow(it, "e.swallow.icon", img);
1362 edje_object_part_text_set(it, "e.text.title", txt);
1363 if (ec->focused)
1364 edje_object_signal_emit(it, "e,state,focused", "e");
1365 if (ec->sticky || (ec->zone != ic->ibar->inst->gcc->gadcon->zone))
1366 edje_object_signal_emit(it, "e,state,other,screen", "e");
1367 else if (!ec->desk->visible)
1368 edje_object_signal_emit(it, "e,state,other,desk", "e");
1369 edje_object_calc_force(it);
1370 edje_object_size_min_calc(it, &w, &h);
1371 evas_object_size_hint_min_set(it, w, h);
1372 evas_object_show(it);
1373 evas_object_event_callback_add(it, EVAS_CALLBACK_MOUSE_UP, _ibar_cb_icon_menu_mouse_up, ec);
1374 edje_object_part_box_append(o, "e.box", it);
1375 return EINA_TRUE;
1376 }
1377
1378 static void
_ibar_icon_menu(IBar_Icon * ic,Eina_Bool grab)1379 _ibar_icon_menu(IBar_Icon *ic, Eina_Bool grab)
1380 {
1381 Evas_Object *o;
1382 Eina_List *l;
1383 E_Exec_Instance *exe;
1384 Evas *e;
1385 Eina_Bool empty = EINA_TRUE;
1386 E_Client *ec;
1387
1388 if (!ic->exes) return; //FIXME
1389 EINA_LIST_FREE(ic->menu_pending, ec)
1390 evas_object_event_callback_del_full(ec->frame, EVAS_CALLBACK_SHOW, _ibar_exec_new_client_show, ic);
1391 ic->menu = e_gadcon_popup_new(ic->ibar->inst->gcc, 1);
1392 e_object_data_set(E_OBJECT(ic->menu), ic);
1393 E_OBJECT_DEL_SET(ic->menu, _ibar_cb_icon_menu_del);
1394 e = e_comp->evas;
1395 o = edje_object_add(e);
1396 e_theme_edje_object_set(o, "base/theme/modules/ibar",
1397 "e/modules/ibar/menu");
1398 /* gadcon popups don't really prevent this,
1399 * so away we go!
1400 */
1401 evas_object_del(ic->menu->comp_object);
1402 ic->menu->o_bg = o;
1403 ic->menu->comp_object = e_comp_object_util_add(o, E_COMP_OBJECT_TYPE_NONE);
1404 evas_object_clip_set(ic->menu->comp_object, e_gadcon_zone_get(ic->ibar->inst->gcc->gadcon)->bg_clip_object);
1405 evas_object_layer_set(ic->menu->comp_object, E_LAYER_POPUP);
1406 EINA_LIST_FOREACH(ic->exes, l, exe)
1407 {
1408 Eina_List *ll;
1409
1410 EINA_LIST_FOREACH(exe->clients, ll, ec)
1411 {
1412 ec = e_client_stack_bottom_get(ec);
1413 if (!_ibar_menu_client_have(ic, ec))
1414 {
1415 if (_ibar_icon_menu_client_add(ic, ec))
1416 empty = EINA_FALSE;
1417 }
1418 }
1419 }
1420 if (empty)
1421 {
1422 /* something crazy happened */
1423 evas_object_del(o);
1424 e_object_del(E_OBJECT(ic->menu));
1425 return;
1426 }
1427
1428 if (!grab)
1429 {
1430 evas_object_event_callback_add(ic->menu->comp_object, EVAS_CALLBACK_MOUSE_IN, _ibar_icon_menu_mouse_in, ic);
1431 evas_object_event_callback_add(ic->menu->comp_object, EVAS_CALLBACK_MOUSE_OUT, _ibar_icon_menu_mouse_out, ic);
1432 }
1433
1434 edje_object_signal_callback_add(o, "e,action,show,done", "*",
1435 _ibar_cb_icon_menu_shown, ic);
1436 edje_object_signal_callback_add(o, "e,action,hide,done", "*",
1437 _ibar_cb_icon_menu_hidden, ic);
1438 edje_object_signal_emit(o, "e,state,hidden", "e");
1439 edje_object_message_signal_process(o);
1440 ic->ibar->menu_icon = ic;
1441 _ibar_icon_menu_recalc(ic);
1442
1443 evas_object_pass_events_set(o, 1);
1444 edje_object_signal_emit(o, "e,action,show", "e");
1445 ic->menu_grabbed = grab;
1446 if (grab)
1447 e_comp_object_util_autoclose(ic->menu->comp_object, _ibar_cb_icon_menu_autodel, NULL, ic);
1448 }
1449
1450 static void
_ibar_exec_new_client_show(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)1451 _ibar_exec_new_client_show(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
1452 {
1453 IBar_Icon *ic = data;
1454 E_Client *ec = e_comp_object_client_get(obj);
1455
1456 if (!ic->menu) return;
1457 if (_ibar_menu_client_have(ic, ec)) return;
1458 _ibar_icon_menu_client_add(ic, ec);
1459 _ibar_icon_menu_recalc(ic);
1460 ic->menu_pending = eina_list_remove(ic->menu_pending, ec);
1461 evas_object_event_callback_del_full(ec->frame, EVAS_CALLBACK_SHOW, _ibar_exec_new_client_show, ic);
1462 }
1463
1464 static void
_ibar_icon_menu_show(IBar_Icon * ic,Eina_Bool grab)1465 _ibar_icon_menu_show(IBar_Icon *ic, Eina_Bool grab)
1466 {
1467 if (ic->ibar->menu_icon && (ic->ibar->menu_icon != ic))
1468 _ibar_icon_menu_hide(ic->ibar->menu_icon, ic->ibar->menu_icon->menu_grabbed);
1469 if (ic->menu)
1470 {
1471 if (ic->ibar->menu_icon != ic)
1472 {
1473 edje_object_signal_emit(ic->menu->o_bg, "e,action,show", "e");
1474 ic->ibar->menu_icon = ic;
1475 }
1476 return;
1477 }
1478 ic->drag.start = 0;
1479 ic->drag.dnd = 0;
1480 ic->mouse_down = 0;
1481 _ibar_icon_menu(ic, grab);
1482 }
1483
1484 static void
_ibar_icon_menu_hide(IBar_Icon * ic,Eina_Bool grab)1485 _ibar_icon_menu_hide(IBar_Icon *ic, Eina_Bool grab)
1486 {
1487 if (!ic->menu) return;
1488 if (ic->menu_grabbed != grab) return;
1489 if (ic->ibar && (ic->ibar->menu_icon == ic))
1490 ic->ibar->menu_icon = NULL;
1491 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1492 ic->menu_grabbed = EINA_FALSE;
1493 _ibar_cb_icon_menu_hide_begin(ic);
1494 }
1495
1496 static Eina_Bool
_ibar_icon_mouse_in_timer(void * data)1497 _ibar_icon_mouse_in_timer(void *data)
1498 {
1499 IBar_Icon *ic = data;
1500
1501 ic->show_timer = NULL;
1502 _ibar_icon_menu_show(ic, EINA_FALSE);
1503 return EINA_FALSE;
1504 }
1505
1506 static void
_ibar_cb_icon_mouse_in(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1507 _ibar_cb_icon_mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1508 {
1509 IBar_Icon *ic;
1510
1511 ic = data;
1512 E_FREE_FUNC(ic->reset_timer, ecore_timer_del);
1513 ic->focused = EINA_TRUE;
1514 _ibar_icon_signal_emit(ic, "e,state,focused", "e");
1515 if (ic->ibar->inst->ci->show_label)
1516 _ibar_icon_signal_emit(ic, "e,action,show,label", "e");
1517 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1518 if (!ic->ibar->inst->ci->dont_icon_menu_mouseover)
1519 {
1520 if (ic->show_timer)
1521 ecore_timer_loop_reset(ic->show_timer);
1522 else
1523 ic->show_timer = ecore_timer_loop_add(0.2, _ibar_icon_mouse_in_timer, ic);
1524 }
1525 }
1526
1527 static Eina_Bool
_ibar_cb_out_hide_delay(void * data)1528 _ibar_cb_out_hide_delay(void *data)
1529 {
1530 IBar_Icon *ic = data;
1531
1532 ic->hide_timer = NULL;
1533 _ibar_icon_menu_hide(ic, EINA_FALSE);
1534 return EINA_FALSE;
1535 }
1536
1537 static void
_ibar_cb_icon_mouse_out(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1538 _ibar_cb_icon_mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1539 {
1540 IBar_Icon *ic;
1541
1542 ic = data;
1543 E_FREE_FUNC(ic->reset_timer, ecore_timer_del);
1544 E_FREE_FUNC(ic->show_timer, ecore_timer_del);
1545 ic->focused = EINA_FALSE;
1546 _ibar_icon_signal_emit(ic, "e,state,unfocused", "e");
1547 if (ic->ibar->inst->ci->show_label)
1548 _ibar_icon_signal_emit(ic, "e,action,hide,label", "e");
1549 if (!ic->ibar->inst->ci->dont_icon_menu_mouseover)
1550 {
1551 if (ic->hide_timer)
1552 ecore_timer_loop_reset(ic->hide_timer);
1553 else
1554 ic->hide_timer = ecore_timer_loop_add(0.75, _ibar_cb_out_hide_delay, ic);
1555 }
1556 }
1557
1558 static Eina_Bool
_ibar_cb_icon_menu_cb(void * data)1559 _ibar_cb_icon_menu_cb(void *data)
1560 {
1561 IBar_Icon *ic = data;
1562
1563 ic->timer = NULL;
1564 _ibar_icon_menu_show(ic, EINA_TRUE);
1565 return EINA_FALSE;
1566 }
1567
1568 static void
_ibar_cb_icon_menu_job_cb(void * data)1569 _ibar_cb_icon_menu_job_cb(void *data)
1570 {
1571 _ibar_cb_icon_menu_cb(data);
1572 }
1573
1574 static void
_ibar_cb_icon_mouse_down(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)1575 _ibar_cb_icon_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1576 {
1577 Evas_Event_Mouse_Down *ev;
1578 IBar_Icon *ic;
1579
1580 ev = event_info;
1581 ic = data;
1582 if (ev->button == 1)
1583 {
1584 ic->drag.x = ev->output.x;
1585 ic->drag.y = ev->output.y;
1586 ic->drag.start = 1;
1587 ic->drag.dnd = 0;
1588 ic->mouse_down = 1;
1589 if (!ic->timer)
1590 ic->timer = ecore_timer_loop_add(0.35, _ibar_cb_icon_menu_cb, ic);
1591 }
1592 else if (ev->button == 2)
1593 {
1594 E_FREE_FUNC(ic->show_timer, ecore_timer_del);
1595 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1596 E_FREE_FUNC(ic->timer, ecore_timer_del);
1597 _ibar_icon_menu_show(ic, EINA_TRUE);
1598 }
1599 else if (ev->button == 3)
1600 {
1601 Eina_List *it;
1602 E_Menu *m, *mo;
1603 E_Menu_Item *mi;
1604 Efreet_Desktop_Action *action;
1605 char buf[256];
1606 int cx, cy;
1607
1608 E_FREE_FUNC(ic->show_timer, ecore_timer_del);
1609 E_FREE_FUNC(ic->hide_timer, ecore_timer_del);
1610 E_FREE_FUNC(ic->timer, ecore_timer_del);
1611 if (ic->menu)
1612 _ibar_icon_menu_hide(ic, ic->menu_grabbed);
1613 m = e_menu_new();
1614
1615 /* FIXME: other icon options go here too */
1616 mo = e_menu_new();
1617
1618 if (e_configure_registry_exists("applications/new_application"))
1619 {
1620 mi = e_menu_item_new(m);
1621 e_menu_item_label_set(mi, _("Create new Icon"));
1622 e_util_menu_item_theme_icon_set(mi, "document-new");
1623 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_new, NULL);
1624
1625 mi = e_menu_item_new(m);
1626 e_menu_item_separator_set(mi, 1);
1627 }
1628
1629 if (e_configure_registry_exists("applications/ibar_applications"))
1630 {
1631 mi = e_menu_item_new(m);
1632 e_menu_item_label_set(mi, _("Contents"));
1633 e_util_menu_item_theme_icon_set(mi, "list-add");
1634 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_add, ic->ibar);
1635 }
1636
1637 mi = e_menu_item_new(m);
1638 e_menu_item_label_set(mi, _("Settings"));
1639 e_util_menu_item_theme_icon_set(mi, "configure");
1640 e_menu_item_callback_set(mi, _ibar_cb_menu_configuration, ic->ibar);
1641
1642 m = e_gadcon_client_util_menu_items_append(ic->ibar->inst->gcc, m, 0);
1643
1644 mi = e_menu_item_new(mo);
1645 e_menu_item_label_set(mi, _("Properties"));
1646 e_util_menu_item_theme_icon_set(mi, "configure");
1647 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_properties, ic);
1648
1649 mi = e_menu_item_new(mo);
1650 if (ic->not_in_order)
1651 {
1652 e_menu_item_label_set(mi, _("Add to bar"));
1653 e_util_menu_item_theme_icon_set(mi, "list-add");
1654 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_stick, ic);
1655 }
1656 else
1657 {
1658 e_menu_item_label_set(mi, _("Remove from bar"));
1659 e_util_menu_item_theme_icon_set(mi, "list-remove");
1660 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_remove, ic);
1661 }
1662
1663 mi = e_menu_item_new_relative(m, NULL);
1664 snprintf(buf, sizeof(buf), _("Icon %s"), ic->app->name);
1665 e_menu_item_label_set(mi, buf);
1666 e_util_desktop_menu_item_icon_add(ic->app,
1667 e_util_icon_size_normalize(96 * e_scale),
1668 mi);
1669 e_menu_item_submenu_set(mi, mo);
1670 e_object_unref(E_OBJECT(mo));
1671
1672 if (ic->app->actions)
1673 {
1674 mi = NULL;
1675 EINA_LIST_FOREACH(ic->app->actions, it, action)
1676 {
1677 mi = e_menu_item_new_relative(m, mi);
1678 e_menu_item_label_set(mi, action->name);
1679 e_util_menu_item_theme_icon_set(mi, action->icon);
1680 e_menu_item_callback_set(mi, _ibar_cb_menu_icon_action_exec, action);
1681 }
1682 mi = e_menu_item_new_relative(m, mi);
1683 e_menu_item_separator_set(mi, 1);
1684 }
1685
1686 e_gadcon_client_menu_set(ic->ibar->inst->gcc, m);
1687
1688 e_gadcon_canvas_zone_geometry_get(ic->ibar->inst->gcc->gadcon,
1689 &cx, &cy, NULL, NULL);
1690 e_menu_activate_mouse(m,
1691 e_zone_current_get(),
1692 cx + ev->output.x, cy + ev->output.y, 1, 1,
1693 E_MENU_POP_DIRECTION_DOWN, ev->timestamp);
1694 }
1695 }
1696
1697 static Eina_Bool
_ibar_cb_icon_reset(void * data)1698 _ibar_cb_icon_reset(void *data)
1699 {
1700 IBar_Icon *ic = data;
1701
1702 if (ic->focused)
1703 {
1704 _ibar_icon_signal_emit(ic, "e,state,focused", "e");
1705 if (ic->ibar->inst->ci->show_label)
1706 _ibar_icon_signal_emit(ic, "e,action,show,label", "e");
1707 }
1708 ic->reset_timer = NULL;
1709 return EINA_FALSE;
1710 }
1711
1712 static void
_ibar_cb_icon_wheel(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)1713 _ibar_cb_icon_wheel(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1714 {
1715 Evas_Event_Mouse_Wheel *ev = event_info;
1716 E_Exec_Instance *exe;
1717 IBar_Icon *ic = data;
1718 E_Client *cur, *sel = NULL;
1719 Eina_List *l, *exe_current = NULL;
1720
1721 if (!ic->exes) return;
1722
1723 cur = e_client_focused_get();
1724 cur = e_client_stack_bottom_get(cur);
1725 if (cur && cur->exe_inst)
1726 {
1727 EINA_LIST_FOREACH(ic->exes, l, exe)
1728 if (cur->exe_inst == exe)
1729 {
1730 exe_current = l;
1731 break;
1732 }
1733 }
1734 if (!exe_current)
1735 exe_current = ic->exes;
1736
1737 exe = eina_list_data_get(exe_current);
1738 if (ev->z < 0)
1739 {
1740 if (cur && (cur->exe_inst == exe))
1741 {
1742 l = eina_list_data_find_list(exe->clients, cur);
1743 if (l) sel = eina_list_data_get(eina_list_next(l));
1744 }
1745 if (!sel)
1746 {
1747 exe_current = eina_list_next(exe_current);
1748 if (!exe_current)
1749 exe_current = ic->exes;
1750 }
1751 }
1752 else if (ev->z > 0)
1753 {
1754 if (cur && (cur->exe_inst == exe))
1755 {
1756 l = eina_list_data_find_list(exe->clients, cur);
1757 if (l) sel = eina_list_data_get(eina_list_prev(l));
1758 }
1759 if (!sel)
1760 {
1761 exe_current = eina_list_prev(exe_current);
1762 if (!exe_current)
1763 exe_current = eina_list_last(ic->exes);
1764 }
1765 }
1766
1767 if (!sel)
1768 {
1769 exe = eina_list_data_get(exe_current);
1770 sel = eina_list_data_get(exe->clients);
1771 if (sel == cur)
1772 sel = eina_list_data_get(eina_list_next(exe->clients));
1773 }
1774
1775 if (sel)
1776 e_client_activate(sel, 1);
1777 }
1778
1779 static void
_ibar_instance_watch(void * data,E_Exec_Instance * inst,E_Exec_Watch_Type type)1780 _ibar_instance_watch(void *data, E_Exec_Instance *inst, E_Exec_Watch_Type type)
1781 {
1782 IBar_Icon *ic = data;
1783
1784 switch (type)
1785 {
1786 case E_EXEC_WATCH_STARTED:
1787 if (ic->starting) _ibar_icon_signal_emit(ic, "e,state,started", "e");
1788 ic->starting = EINA_FALSE;
1789 if (!ic->exes) _ibar_icon_signal_emit(ic, "e,state,on", "e");
1790 if (ic->exe_inst == inst) ic->exe_inst = NULL;
1791 if (!eina_list_data_find(ic->exes, inst))
1792 ic->exes = eina_list_append(ic->exes, inst);
1793 break;
1794 default:
1795 break;
1796 }
1797 }
1798
1799 static void
_ibar_icon_go(IBar_Icon * ic,Eina_Bool keep_going)1800 _ibar_icon_go(IBar_Icon *ic, Eina_Bool keep_going)
1801 {
1802 if (ic->not_in_order)
1803 {
1804 Eina_List *l, *ll;
1805 E_Exec_Instance *exe;
1806 E_Client *ec, *eclast = NULL;
1807 unsigned int count = 0;
1808
1809 EINA_LIST_FOREACH(ic->exes, l, exe)
1810 {
1811 EINA_LIST_FOREACH(exe->clients, ll, ec)
1812 {
1813 count++;
1814 if (count > 1)
1815 {
1816 ecore_job_add((Ecore_Cb)_ibar_cb_icon_menu_job_cb, ic);
1817 return;
1818 }
1819 eclast = ec;
1820 }
1821 }
1822 if (eclast)
1823 e_client_activate(eclast, 1);
1824 return;
1825 }
1826 if (ic->app->type == EFREET_DESKTOP_TYPE_APPLICATION)
1827 {
1828 if (ic->ibar->inst->ci->dont_track_launch)
1829 e_exec(ic->ibar->inst->gcc->gadcon->zone,
1830 ic->app, NULL, NULL, "ibar");
1831 else
1832 {
1833 E_Exec_Instance *einst;
1834
1835 einst = e_exec(ic->ibar->inst->gcc->gadcon->zone,
1836 ic->app, NULL, NULL, "ibar");
1837 if (einst)
1838 {
1839 ic->exe_inst = einst;
1840 e_exec_instance_watcher_add(einst, _ibar_instance_watch, ic);
1841 if (!ic->starting) _ibar_icon_signal_emit(ic, "e,state,starting", "e");
1842 ic->starting = EINA_TRUE;
1843 }
1844 }
1845 }
1846 else if (ic->app->type == EFREET_DESKTOP_TYPE_LINK)
1847 {
1848 if (!strncasecmp(ic->app->url, "file:", 5))
1849 {
1850 E_Action *act;
1851
1852 act = e_action_find("fileman");
1853 if (act) act->func.go(NULL, ic->app->url + 5);
1854 }
1855 }
1856 _ibar_icon_signal_emit(ic, "e,action,exec", "e");
1857 if (keep_going)
1858 ic->reset_timer = ecore_timer_loop_add(1.0, _ibar_cb_icon_reset, ic);
1859 }
1860
1861 static void
_ibar_cb_icon_mouse_up(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)1862 _ibar_cb_icon_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1863 {
1864 Evas_Event_Mouse_Up *ev;
1865 IBar_Icon *ic;
1866
1867 ev = event_info;
1868 ic = data;
1869
1870 if ((ev->button == 1) && (ic->mouse_down == 1))
1871 {
1872 if (!ic->drag.dnd) _ibar_icon_go(ic, EINA_FALSE);
1873 ic->drag.start = 0;
1874 ic->drag.dnd = 0;
1875 ic->mouse_down = 0;
1876 E_FREE_FUNC(ic->timer, ecore_timer_del);
1877 }
1878 }
1879
1880 static void
_ibar_cb_icon_mouse_move(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)1881 _ibar_cb_icon_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1882 {
1883 Evas_Event_Mouse_Move *ev = event_info;
1884 IBar_Icon *ic = data;
1885 int dx, dy;
1886
1887 E_FREE_FUNC(ic->timer, ecore_timer_del);
1888 if (!ic->drag.start) return;
1889
1890 dx = ev->cur.output.x - ic->drag.x;
1891 dy = ev->cur.output.y - ic->drag.y;
1892 if (((dx * dx) + (dy * dy)) >
1893 (e_config->drag_resist * e_config->drag_resist))
1894 {
1895 E_Drag *d;
1896 Evas_Object *o;
1897 Evas_Coord x, y, w, h;
1898 unsigned int size;
1899 IBar *i;
1900 const char *drag_types[] = { "enlightenment/desktop" };
1901
1902 ic->drag.dnd = 1;
1903 ic->drag.start = 0;
1904
1905 if (ic->ibar->inst->ci->lock_move) return;
1906
1907 evas_object_geometry_get(ic->o_icon, &x, &y, &w, &h);
1908 d = e_drag_new(x, y, drag_types, 1,
1909 ic->app, -1, NULL, _ibar_cb_drag_finished);
1910 d->button_mask = evas_pointer_button_down_mask_get(e_comp->evas);
1911 efreet_desktop_ref(ic->app);
1912 size = MAX(w, h);
1913 o = e_util_desktop_icon_add(ic->app, size, e_drag_evas_get(d));
1914 e_drag_object_set(d, o);
1915
1916 e_drag_resize(d, w, h);
1917 e_drag_start(d, ic->drag.x, ic->drag.y);
1918 i = ic->ibar;
1919 e_object_data_set(E_OBJECT(d), i);
1920 if (!ic->not_in_order)
1921 e_order_remove(i->io->eo, ic->app);
1922 _ibar_icon_free(ic);
1923 _ibar_resize_handle(i);
1924 _gc_orient(i->inst->gcc, -1);
1925 }
1926 }
1927
1928 static void
_ibar_cb_icon_move(void * data,Evas * e,Evas_Object * obj,void * event_info EINA_UNUSED)1929 _ibar_cb_icon_move(void *data, Evas *e, Evas_Object *obj, void *event_info EINA_UNUSED)
1930 {
1931 IBar_Icon *ic;
1932 int x, y, w, h, cw, chx, len = 0;
1933 const char *sig = "e,origin,center";
1934 E_Zone *zone;
1935
1936 ic = data;
1937 evas_object_geometry_get(ic->o_holder, &x, &y, &w, &h);
1938 evas_object_move(ic->o_holder2, x, y);
1939 evas_output_size_get(e, &cw, NULL);
1940
1941 edje_object_part_geometry_get(ic->o_holder2, "e.text.label", NULL, NULL, &len, NULL);
1942 chx = x + (w / 2);
1943 zone = e_comp_object_util_zone_get(obj);
1944 if (!zone)
1945 {
1946 if (x < 1)
1947 zone = e_comp_zone_xy_get(0, y);
1948 else
1949 zone = e_comp_zone_xy_get(e_comp->w - 5, y);
1950 if (!zone)
1951 zone = eina_list_data_get(e_comp->zones);
1952 }
1953 if (chx - (len / 2) < zone->x)
1954 sig = "e,origin,left";
1955 else if ((chx + (len / 2) > cw) || ((chx + (len / 2) > zone->x + zone->w)))
1956 sig = "e,origin,right";
1957 _ibar_icon_signal_emit(ic, sig, "e");
1958 }
1959
1960 static void
_ibar_cb_icon_resize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1961 _ibar_cb_icon_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1962 {
1963 IBar_Icon *ic;
1964 Evas_Coord w, h;
1965
1966 ic = data;
1967 evas_object_geometry_get(ic->o_holder, NULL, NULL, &w, &h);
1968 evas_object_resize(ic->o_holder2, w, h);
1969 }
1970
1971 static void
_ibar_cb_drop_move(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1972 _ibar_cb_drop_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1973 {
1974 IBar *b;
1975 Evas_Coord x, y;
1976
1977 b = data;
1978 evas_object_geometry_get(b->o_drop, &x, &y, NULL, NULL);
1979 evas_object_move(b->o_drop_over, x, y);
1980 }
1981
1982 static void
_ibar_cb_drop_resize(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)1983 _ibar_cb_drop_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1984 {
1985 IBar *b;
1986 Evas_Coord w, h;
1987
1988 b = data;
1989 evas_object_geometry_get(b->o_drop, NULL, NULL, &w, &h);
1990 evas_object_resize(b->o_drop_over, w, h);
1991 }
1992
1993 static void
_ibar_cb_drag_finished(E_Drag * drag,int dropped)1994 _ibar_cb_drag_finished(E_Drag *drag, int dropped)
1995 {
1996 IBar *i = e_object_data_get(E_OBJECT(drag));
1997
1998 efreet_desktop_unref(drag->data);
1999 if (!i) return;
2000 if (!dropped)
2001 {
2002 _ibar_empty(i);
2003 _ibar_fill(i);
2004 _ibar_resize_handle(i);
2005 }
2006 }
2007
2008 static void
_ibar_inst_cb_scroll(void * data)2009 _ibar_inst_cb_scroll(void *data)
2010 {
2011 Instance *inst;
2012
2013 /* Update the position of the dnd to handle for autoscrolling
2014 * gadgets. */
2015 inst = data;
2016 _ibar_drop_position_update(inst, inst->ibar->dnd_x, inst->ibar->dnd_y);
2017 }
2018
2019 static void
_ibar_drop_position_update(Instance * inst,Evas_Coord x,Evas_Coord y)2020 _ibar_drop_position_update(Instance *inst, Evas_Coord x, Evas_Coord y)
2021 {
2022 IBar_Icon *ic;
2023
2024 inst->ibar->dnd_x = x;
2025 inst->ibar->dnd_y = y;
2026
2027 ic = _ibar_icon_at_coord(inst->ibar, x, y);
2028 if (ic && (ic == inst->ibar->ic_drop_before)) return;
2029
2030 if (inst->ibar->o_drop)
2031 {
2032 int ox, oy, ow, oh;
2033
2034 evas_object_geometry_get(inst->ibar->o_drop, &ox, &oy, &ow, &oh);
2035 /* if cursor is still inside last drop area, do nothing */
2036 if (E_INSIDE(x, y, ox, oy, ow, oh)) return;
2037 elm_box_unpack(inst->ibar->o_box, inst->ibar->o_drop);
2038 }
2039
2040 inst->ibar->ic_drop_before = ic;
2041 if (ic)
2042 {
2043 Evas_Coord ix, iy, iw, ih;
2044 int before = 0;
2045
2046 evas_object_geometry_get(ic->o_holder, &ix, &iy, &iw, &ih);
2047 if (elm_box_horizontal_get(inst->ibar->o_box))
2048 {
2049 if (x < (ix + (iw / 2))) before = 1;
2050 }
2051 else
2052 {
2053 if (y < (iy + (ih / 2))) before = 1;
2054 }
2055 if (before)
2056 elm_box_pack_before(inst->ibar->o_box, inst->ibar->o_drop, ic->o_holder);
2057 else
2058 elm_box_pack_after(inst->ibar->o_box, inst->ibar->o_drop, ic->o_holder);
2059 inst->ibar->drop_before = before;
2060 }
2061 else elm_box_pack_end(inst->ibar->o_box, inst->ibar->o_drop);
2062 evas_object_size_hint_min_set(inst->ibar->o_drop, 1, 1);
2063 _ibar_resize_handle(inst->ibar);
2064 _gc_orient(inst->gcc, -1);
2065 }
2066
2067 static void
_ibar_inst_cb_enter(void * data,const char * type EINA_UNUSED,void * event_info)2068 _ibar_inst_cb_enter(void *data, const char *type EINA_UNUSED, void *event_info)
2069 {
2070 E_Event_Dnd_Enter *ev;
2071 Instance *inst;
2072 Evas_Object *o, *o2;
2073
2074 ev = event_info;
2075 inst = data;
2076 o = edje_object_add(evas_object_evas_get(inst->ibar->o_box));
2077 inst->ibar->o_drop = o;
2078 E_EXPAND(o);
2079 E_FILL(o);
2080 o2 = edje_object_add(evas_object_evas_get(inst->ibar->o_box));
2081 inst->ibar->o_drop_over = o2;
2082 evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE,
2083 _ibar_cb_drop_move, inst->ibar);
2084 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
2085 _ibar_cb_drop_resize, inst->ibar);
2086 e_theme_edje_object_set(o, "base/theme/modules/ibar",
2087 "e/modules/ibar/drop");
2088 e_theme_edje_object_set(o2, "base/theme/modules/ibar",
2089 "e/modules/ibar/drop_overlay");
2090 evas_object_layer_set(o2, 19999);
2091 evas_object_show(o);
2092 evas_object_show(o2);
2093
2094 _ibar_drop_position_update(inst, ev->x, ev->y);
2095 e_gadcon_client_autoscroll_cb_set(inst->gcc, _ibar_inst_cb_scroll, inst);
2096 e_gadcon_client_autoscroll_update(inst->gcc, ev->x, ev->y);
2097 }
2098
2099 static void
_ibar_inst_cb_move(void * data,const char * type EINA_UNUSED,void * event_info)2100 _ibar_inst_cb_move(void *data, const char *type EINA_UNUSED, void *event_info)
2101 {
2102 E_Event_Dnd_Move *ev;
2103 Instance *inst;
2104 int x, y;
2105
2106 ev = event_info;
2107 inst = data;
2108 _ibar_drop_position_update(inst, ev->x, ev->y);
2109 evas_object_geometry_get(inst->ibar->o_outerbox, &x, &y, NULL, NULL);
2110 e_gadcon_client_autoscroll_update(inst->gcc, ev->x - x, ev->y - y);
2111 }
2112
2113 static void
_ibar_inst_cb_leave(void * data,const char * type EINA_UNUSED,void * event_info EINA_UNUSED)2114 _ibar_inst_cb_leave(void *data, const char *type EINA_UNUSED, void *event_info EINA_UNUSED)
2115 {
2116 Instance *inst;
2117
2118 inst = data;
2119 inst->ibar->ic_drop_before = NULL;
2120 evas_object_del(inst->ibar->o_drop);
2121 inst->ibar->o_drop = NULL;
2122 evas_object_del(inst->ibar->o_drop_over);
2123 inst->ibar->o_drop_over = NULL;
2124 _ibar_resize_handle(inst->ibar);
2125 e_gadcon_client_autoscroll_cb_set(inst->gcc, NULL, NULL);
2126 _gc_orient(inst->gcc, -1);
2127 }
2128
2129 static void
_ibar_inst_cb_drop(void * data,const char * type,void * event_info)2130 _ibar_inst_cb_drop(void *data, const char *type, void *event_info)
2131 {
2132 E_Event_Dnd_Drop *ev;
2133 Instance *inst;
2134 Efreet_Desktop *app = NULL;
2135 Eina_List *fl = NULL;
2136 IBar_Icon *ic;
2137
2138 ev = event_info;
2139 inst = data;
2140
2141 if (!strcmp(type, "enlightenment/desktop"))
2142 app = ev->data;
2143 else if (!strcmp(type, "enlightenment/border"))
2144 {
2145 E_Client *ec;
2146
2147 ec = ev->data;
2148 app = ec->desktop;
2149 if (!app)
2150 {
2151 app = e_desktop_client_create(ec);
2152 efreet_desktop_save(app);
2153 e_desktop_edit(app);
2154 }
2155 }
2156 else if (!strcmp(type, "text/uri-list"))
2157 fl = ev->data;
2158
2159 ic = inst->ibar->ic_drop_before;
2160 if (ic)
2161 {
2162 /* Add new eapp before this icon */
2163 if (!inst->ibar->drop_before)
2164 {
2165 IBar_Icon *ic2;
2166
2167 EINA_INLIST_FOREACH(inst->ibar->icons, ic2)
2168 {
2169 if (ic2 == ic)
2170 {
2171 if (EINA_INLIST_GET(ic2)->next)
2172 ic = (IBar_Icon*)EINA_INLIST_GET(ic2)->next;
2173 else
2174 ic = NULL;
2175 break;
2176 }
2177 }
2178 }
2179 if (!ic) goto atend;
2180 if (app)
2181 e_order_prepend_relative(ic->ibar->io->eo, app, ic->app);
2182 else if (fl)
2183 e_order_files_prepend_relative(ic->ibar->io->eo, fl, ic->app);
2184 }
2185 else
2186 {
2187 atend:
2188 if (inst->ibar->io->eo)
2189 {
2190 if (app)
2191 e_order_append(inst->ibar->io->eo, app);
2192 else if (fl)
2193 e_order_files_append(inst->ibar->io->eo, fl);
2194 }
2195 }
2196 evas_object_del(inst->ibar->o_drop);
2197 inst->ibar->o_drop = NULL;
2198 evas_object_del(inst->ibar->o_drop_over);
2199 inst->ibar->o_drop_over = NULL;
2200 e_gadcon_client_autoscroll_cb_set(inst->gcc, NULL, NULL);
2201 _ibar_empty_handle(inst->ibar);
2202 _ibar_resize_handle(inst->ibar);
2203 _gc_orient(inst->gcc, -1);
2204 }
2205
2206 static E_Action *act_ibar_focus = NULL;
2207 static Ecore_X_Window _ibar_focus_win = 0;
2208 static Ecore_Event_Handler *_ibar_key_down_handler = NULL;
2209
2210 static void _ibar_go_unfocus(void);
2211
2212 static IBar *
_ibar_manager_find(void)2213 _ibar_manager_find(void)
2214 {
2215 E_Zone *z = e_zone_current_get();
2216 IBar *b;
2217 Eina_List *l;
2218
2219 if (!z) return NULL;
2220 // find iubar on current zone
2221 EINA_LIST_FOREACH(ibars, l, b)
2222 {
2223 if ((!b->inst) || (!b->inst->gcc) || (!b->inst->gcc->gadcon)) continue;
2224 if (b->inst->gcc->gadcon->zone == z) return b;
2225 }
2226 // no ibars on current zone - return any old ibar
2227 EINA_LIST_FOREACH(ibars, l, b)
2228 {
2229 return b;
2230 }
2231 // no ibars. null.
2232 return NULL;
2233 }
2234
2235 static void
_ibar_icon_unfocus_focus(IBar_Icon * ic1,IBar_Icon * ic2)2236 _ibar_icon_unfocus_focus(IBar_Icon *ic1, IBar_Icon *ic2)
2237 {
2238 if (ic1)
2239 {
2240 ic1->focused = EINA_FALSE;
2241 _ibar_icon_signal_emit(ic1, "e,state,unfocused", "e");
2242 if (ic1->ibar->inst->ci->show_label)
2243 _ibar_icon_signal_emit(ic1, "e,action,hide,label", "e");
2244 }
2245 if (ic2)
2246 {
2247 ic2->focused = EINA_TRUE;
2248 _ibar_icon_signal_emit(ic2, "e,state,focused", "e");
2249 if (ic2->ibar->inst->ci->show_label)
2250 _ibar_icon_signal_emit(ic2, "e,action,show,label", "e");
2251 }
2252 }
2253
2254 static IBar *
_ibar_focused_find(void)2255 _ibar_focused_find(void)
2256 {
2257 IBar *b;
2258 Eina_List *l;
2259
2260 EINA_LIST_FOREACH(ibars, l, b)
2261 {
2262 if (b->focused) return b;
2263 }
2264 return NULL;
2265 }
2266
2267 static int
_ibar_cb_sort(IBar * b1,IBar * b2)2268 _ibar_cb_sort(IBar *b1, IBar *b2)
2269 {
2270 E_Zone *z1 = NULL, *z2 = NULL;
2271
2272 if ((b1) && (b1->inst) && (b1->inst->gcc) && (b1->inst->gcc->gadcon))
2273 z1 = b1->inst->gcc->gadcon->zone;
2274 if ((b2) && (b2->inst) && (b2->inst->gcc) && (b2->inst->gcc->gadcon))
2275 z2 = b2->inst->gcc->gadcon->zone;
2276 if ((z1) && (!z2)) return -1;
2277 else if ((!z1) && (z2)) return 1;
2278 else if ((!z1) && (!z2)) return 0;
2279 else
2280 {
2281 int id1, id2;
2282
2283 id1 = z1->id;
2284 id2 = z2->id;
2285 return id2 - id1;
2286 }
2287 return 0;
2288 }
2289
2290 static IBar *
_ibar_focused_next_find(void)2291 _ibar_focused_next_find(void)
2292 {
2293 IBar *b, *bn = NULL;
2294 Eina_List *l;
2295 Eina_List *tmpl = NULL;
2296
2297 EINA_LIST_FOREACH(ibars, l, b)
2298 {
2299 if (!b->icons) continue;
2300 tmpl = eina_list_sorted_insert
2301 (tmpl, EINA_COMPARE_CB(_ibar_cb_sort), b);
2302 }
2303 if (!tmpl) tmpl = ibars;
2304 EINA_LIST_FOREACH(tmpl, l, b)
2305 {
2306 if (b->focused)
2307 {
2308 if (l->next)
2309 {
2310 bn = l->next->data;
2311 break;
2312 }
2313 else
2314 {
2315 bn = tmpl->data;
2316 break;
2317 }
2318 }
2319 }
2320 if (tmpl != ibars) eina_list_free(tmpl);
2321 return bn;
2322 }
2323
2324 static IBar *
_ibar_focused_prev_find(void)2325 _ibar_focused_prev_find(void)
2326 {
2327 IBar *b, *bn = NULL;
2328 Eina_List *l;
2329 Eina_List *tmpl = NULL;
2330
2331 EINA_LIST_FOREACH(ibars, l, b)
2332 {
2333 if (!b->icons) continue;
2334 tmpl = eina_list_sorted_insert
2335 (tmpl, EINA_COMPARE_CB(_ibar_cb_sort), b);
2336 }
2337 if (!tmpl) tmpl = ibars;
2338 EINA_LIST_FOREACH(tmpl, l, b)
2339 {
2340 if (b->focused)
2341 {
2342 if (l->prev)
2343 {
2344 bn = l->prev->data;
2345 break;
2346 }
2347 else
2348 {
2349 bn = eina_list_last_data_get(tmpl);
2350 break;
2351 }
2352 }
2353 }
2354 if (tmpl != ibars) eina_list_free(tmpl);
2355 return bn;
2356 }
2357
2358 static void
_ibar_focus(IBar * b)2359 _ibar_focus(IBar *b)
2360 {
2361 IBar_Icon *ic;
2362
2363 if (b->focused) return;
2364 b->focused = EINA_TRUE;
2365 EINA_INLIST_FOREACH(b->icons, ic)
2366 {
2367 if (ic->focused)
2368 {
2369 _ibar_icon_unfocus_focus(ic, NULL);
2370 break;
2371 }
2372 }
2373 if (b->icons)
2374 _ibar_icon_unfocus_focus(NULL, (IBar_Icon*)b->icons);
2375 }
2376
2377 static void
_ibar_unfocus(IBar * b)2378 _ibar_unfocus(IBar *b)
2379 {
2380 IBar_Icon *ic;
2381
2382 if (!b->focused) return;
2383 b->focused = EINA_FALSE;
2384 EINA_INLIST_FOREACH(b->icons, ic)
2385 {
2386 if (ic->focused)
2387 {
2388 _ibar_icon_unfocus_focus(ic, NULL);
2389 break;
2390 }
2391 }
2392 }
2393
2394 static void
_ibar_focus_next(IBar * b)2395 _ibar_focus_next(IBar *b)
2396 {
2397 IBar_Icon *ic, *ic1 = NULL, *ic2 = NULL;
2398
2399 if (!b->focused) return;
2400 if (!b->icons) return;
2401 EINA_INLIST_FOREACH(b->icons, ic)
2402 {
2403 if (!ic1)
2404 {
2405 if (ic->focused) ic1 = ic;
2406 }
2407 else
2408 {
2409 ic2 = ic;
2410 break;
2411 }
2412 }
2413 // wrap to start
2414 if ((ic1) && (!ic2)) ic2 = (IBar_Icon*)b->icons;
2415 if ((ic1) && (ic2) && (ic1 != ic2))
2416 _ibar_icon_unfocus_focus(ic1, ic2);
2417 }
2418
2419 static void
_ibar_focus_prev(IBar * b)2420 _ibar_focus_prev(IBar *b)
2421 {
2422 IBar_Icon *ic, *ic1 = NULL, *ic2 = NULL;
2423
2424 if (!b->focused) return;
2425 if (!b->icons) return;
2426 EINA_INLIST_FOREACH(b->icons, ic)
2427 {
2428 if (ic->focused)
2429 {
2430 ic1 = ic;
2431 break;
2432 }
2433 ic2 = ic;
2434 }
2435 // wrap to end
2436 if ((ic1) && (!ic2)) ic2 = (IBar_Icon*)b->icons;
2437 if ((ic1) && (ic2) && (ic1 != ic2))
2438 _ibar_icon_unfocus_focus(ic1, ic2);
2439 }
2440
2441 static void
_ibar_focus_launch(IBar * b)2442 _ibar_focus_launch(IBar *b)
2443 {
2444 IBar_Icon *ic;
2445
2446 if (!b->focused) return;
2447 EINA_INLIST_FOREACH(b->icons, ic)
2448 {
2449 if (ic->focused)
2450 {
2451 _ibar_icon_go(ic, EINA_TRUE);
2452 break;
2453 }
2454 }
2455 }
2456
2457 static Eina_Bool
_ibar_focus_cb_key_down(void * data EINA_UNUSED,int type EINA_UNUSED,void * event)2458 _ibar_focus_cb_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
2459 {
2460 Ecore_Event_Key *ev;
2461 IBar *b, *b2;
2462
2463 ev = event;
2464 if (ev->window != _ibar_focus_win) return ECORE_CALLBACK_PASS_ON;
2465 b = _ibar_focused_find();
2466 if (!b) return ECORE_CALLBACK_PASS_ON;
2467 if (!strcmp(ev->key, "Up"))
2468 {
2469 if (b->inst)
2470 {
2471 switch (b->inst->orient)
2472 {
2473 case E_GADCON_ORIENT_VERT:
2474 case E_GADCON_ORIENT_LEFT:
2475 case E_GADCON_ORIENT_RIGHT:
2476 case E_GADCON_ORIENT_CORNER_LT:
2477 case E_GADCON_ORIENT_CORNER_RT:
2478 case E_GADCON_ORIENT_CORNER_LB:
2479 case E_GADCON_ORIENT_CORNER_RB:
2480 _ibar_focus_prev(b);
2481 break;
2482 default:
2483 break;
2484 }
2485 }
2486 }
2487 else if (!strcmp(ev->key, "Down"))
2488 {
2489 if (b->inst)
2490 {
2491 switch (b->inst->orient)
2492 {
2493 case E_GADCON_ORIENT_VERT:
2494 case E_GADCON_ORIENT_LEFT:
2495 case E_GADCON_ORIENT_RIGHT:
2496 case E_GADCON_ORIENT_CORNER_LT:
2497 case E_GADCON_ORIENT_CORNER_RT:
2498 case E_GADCON_ORIENT_CORNER_LB:
2499 case E_GADCON_ORIENT_CORNER_RB:
2500 _ibar_focus_next(b);
2501 break;
2502 default:
2503 break;
2504 }
2505 }
2506 }
2507 else if (!strcmp(ev->key, "Left"))
2508 {
2509 if (b->inst)
2510 {
2511 switch (b->inst->orient)
2512 {
2513 case E_GADCON_ORIENT_FLOAT:
2514 case E_GADCON_ORIENT_HORIZ:
2515 case E_GADCON_ORIENT_TOP:
2516 case E_GADCON_ORIENT_BOTTOM:
2517 case E_GADCON_ORIENT_CORNER_TL:
2518 case E_GADCON_ORIENT_CORNER_TR:
2519 case E_GADCON_ORIENT_CORNER_BL:
2520 case E_GADCON_ORIENT_CORNER_BR:
2521 _ibar_focus_prev(b);
2522 break;
2523 default:
2524 break;
2525 }
2526 }
2527 }
2528 else if (!strcmp(ev->key, "Right"))
2529 {
2530 if (b->inst)
2531 {
2532 switch (b->inst->orient)
2533 {
2534 case E_GADCON_ORIENT_FLOAT:
2535 case E_GADCON_ORIENT_HORIZ:
2536 case E_GADCON_ORIENT_TOP:
2537 case E_GADCON_ORIENT_BOTTOM:
2538 case E_GADCON_ORIENT_CORNER_TL:
2539 case E_GADCON_ORIENT_CORNER_TR:
2540 case E_GADCON_ORIENT_CORNER_BL:
2541 case E_GADCON_ORIENT_CORNER_BR:
2542 _ibar_focus_next(b);
2543 break;
2544 default:
2545 break;
2546 }
2547 }
2548 }
2549 else if (!strcmp(ev->key, "space"))
2550 {
2551 _ibar_focus_launch(b);
2552 }
2553 else if ((!strcmp(ev->key, "Return")) ||
2554 (!strcmp(ev->key, "KP_Enter")))
2555 {
2556 _ibar_focus_launch(b);
2557 _ibar_go_unfocus();
2558 }
2559 else if (!strcmp(ev->key, "Escape"))
2560 {
2561 _ibar_go_unfocus();
2562 }
2563 else if (!strcmp(ev->key, "Tab"))
2564 {
2565 if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
2566 {
2567 b2 = _ibar_focused_prev_find();
2568 if ((b) && (b2) && (b != b2))
2569 {
2570 _ibar_unfocus(b);
2571 _ibar_focus(b2);
2572 }
2573 }
2574 else
2575 {
2576 b2 = _ibar_focused_next_find();
2577 if ((b) && (b2) && (b != b2))
2578 {
2579 _ibar_unfocus(b);
2580 _ibar_focus(b2);
2581 }
2582 }
2583 }
2584 else if (!strcmp(ev->key, "ISO_Left_Tab"))
2585 {
2586 b2 = _ibar_focused_prev_find();
2587 if ((b) && (b2) && (b != b2))
2588 {
2589 _ibar_unfocus(b);
2590 _ibar_focus(b2);
2591 }
2592 }
2593 return ECORE_CALLBACK_PASS_ON;
2594 }
2595
2596 static void
_ibar_go_focus(void)2597 _ibar_go_focus(void)
2598 {
2599 IBar *b;
2600
2601 if (_ibar_focus_win) return;
2602 b = _ibar_manager_find();
2603 if (!b) return;
2604 if (!e_comp_grab_input(0, 1)) return;
2605 _ibar_focus_win = e_comp->ee_win;
2606 _ibar_key_down_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
2607 _ibar_focus_cb_key_down, NULL);
2608 _ibar_focus(b);
2609 }
2610
2611 static void
_ibar_go_unfocus(void)2612 _ibar_go_unfocus(void)
2613 {
2614 IBar *b;
2615
2616 if (!_ibar_focus_win) return;
2617 b = _ibar_focused_find();
2618 if (b) _ibar_unfocus(b);
2619 e_comp_ungrab_input(0, 1);
2620 _ibar_focus_win = 0;
2621 ecore_event_handler_del(_ibar_key_down_handler);
2622 _ibar_key_down_handler = NULL;
2623 }
2624
2625 static void
_ibar_cb_action_focus(E_Object * obj EINA_UNUSED,const char * params EINA_UNUSED,Ecore_Event_Key * ev EINA_UNUSED)2626 _ibar_cb_action_focus(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED, Ecore_Event_Key *ev EINA_UNUSED)
2627 {
2628 _ibar_go_focus();
2629 }
2630
2631 static Eina_Bool
_ibar_cb_client_prop(void * d EINA_UNUSED,int t EINA_UNUSED,E_Event_Client_Property * ev)2632 _ibar_cb_client_prop(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Client_Property *ev)
2633 {
2634 IBar *b;
2635 Eina_List *l;
2636 E_Client *ec;
2637 Eina_Bool skip = EINA_TRUE;
2638
2639 if (e_client_util_ignored_get(ev->ec) || (!ev->ec->exe_inst) ||
2640 (!ev->ec->exe_inst->desktop)) return ECORE_CALLBACK_RENEW;
2641 if ((!(ev->property & E_CLIENT_PROPERTY_NETWM_STATE)) && (!(ev->property & E_CLIENT_PROPERTY_ICON)))
2642 return ECORE_CALLBACK_RENEW;
2643 EINA_LIST_FOREACH(ev->ec->exe_inst->clients, l, ec)
2644 if (!ec->netwm.state.skip_taskbar)
2645 {
2646 skip = EINA_FALSE;
2647 break;
2648 }
2649 ec = e_client_stack_active_adjust(ev->ec);
2650 EINA_LIST_FOREACH(ibars, l, b)
2651 {
2652 IBar_Icon *ic;
2653
2654 ic = eina_hash_find(b->icon_hash, _desktop_name_get(ec->exe_inst->desktop));
2655 if (skip && (!ic)) continue;
2656 if (!skip)
2657 {
2658 if (ic)
2659 {
2660 if (ic->starting) _ibar_icon_signal_emit(ic, "e,state,started", "e");
2661 ic->starting = EINA_FALSE;
2662 if (!ic->exes) _ibar_icon_signal_emit(ic, "e,state,on", "e");
2663 if (!eina_list_data_find(ic->exes, ec->exe_inst))
2664 ic->exes = eina_list_append(ic->exes, ec->exe_inst);
2665 }
2666 else if (!b->inst->ci->dont_add_nonorder)
2667 {
2668 _ibar_sep_create(b);
2669 _ibar_icon_notinorder_new(b, ec->exe_inst);
2670 _ibar_resize_handle(b);
2671 }
2672 }
2673 else
2674 {
2675 ic->exes = eina_list_remove(ic->exes, ec->exe_inst);
2676 if (ic->exe_inst == ec->exe_inst) ic->exe_inst = NULL;
2677 if (!ic->exes)
2678 {
2679 if (ic->not_in_order)
2680 {
2681 _ibar_icon_free(ic);
2682 if (!b->not_in_order_count)
2683 {
2684 E_FREE_FUNC(b->o_sep, evas_object_del);
2685 }
2686 _ibar_resize_handle(b);
2687 }
2688 else
2689 _ibar_icon_signal_emit(ic, "e,state,off", "e");
2690 }
2691 }
2692 }
2693 return ECORE_CALLBACK_RENEW;
2694 }
2695
2696 static Eina_Bool
_ibar_cb_exec_del(void * d EINA_UNUSED,int t EINA_UNUSED,E_Exec_Instance * exe)2697 _ibar_cb_exec_del(void *d EINA_UNUSED, int t EINA_UNUSED, E_Exec_Instance *exe)
2698 {
2699 IBar *b;
2700 Eina_List *l;
2701
2702 if (!exe->desktop) return ECORE_CALLBACK_RENEW; //can't do anything here :(
2703 EINA_LIST_FOREACH(ibars, l, b)
2704 {
2705 IBar_Icon *ic;
2706
2707 ic = eina_hash_find(b->icon_hash, _desktop_name_get(exe->desktop));
2708 if (ic)
2709 {
2710 if (ic->starting) _ibar_icon_signal_emit(ic, "e,state,started", "e");
2711 ic->starting = EINA_FALSE;
2712 ic->exes = eina_list_remove(ic->exes, exe);
2713 if (ic->exe_inst == exe) ic->exe_inst = NULL;
2714 if (!ic->exes)
2715 {
2716 if (ic->not_in_order)
2717 {
2718 _ibar_icon_free(ic);
2719 if (!b->not_in_order_count)
2720 {
2721 E_FREE_FUNC(b->o_sep, evas_object_del);
2722 }
2723 _ibar_resize_handle(b);
2724 }
2725 else
2726 _ibar_icon_signal_emit(ic, "e,state,off", "e");
2727 }
2728 }
2729 }
2730 return ECORE_CALLBACK_RENEW;
2731 }
2732
2733 static Eina_Bool
_ibar_cb_exec_new_client(void * d EINA_UNUSED,int t EINA_UNUSED,E_Exec_Instance * exe)2734 _ibar_cb_exec_new_client(void *d EINA_UNUSED, int t EINA_UNUSED, E_Exec_Instance *exe)
2735 {
2736 IBar *b;
2737 E_Client *ec;
2738 Eina_List *l;
2739 Eina_Bool skip;
2740
2741 if (!exe->desktop) return ECORE_CALLBACK_RENEW; //can't do anything here :(
2742 if (!exe->desktop->icon) return ECORE_CALLBACK_RENEW;
2743 ec = eina_list_last_data_get(exe->clients); //only care about last (new) one
2744 skip = ec->netwm.state.skip_taskbar;
2745 EINA_LIST_FOREACH(ibars, l, b)
2746 {
2747 IBar_Icon *ic;
2748
2749 ic = eina_hash_find(b->icon_hash, _desktop_name_get(exe->desktop));
2750 if (ic)
2751 {
2752 if (ic->starting) _ibar_icon_signal_emit(ic, "e,state,started", "e");
2753 ic->starting = EINA_FALSE;
2754 if (!ic->exes) _ibar_icon_signal_emit(ic, "e,state,on", "e");
2755 if (skip) continue;
2756 if (!eina_list_data_find(ic->exes, exe))
2757 ic->exes = eina_list_append(ic->exes, exe);
2758 if (ic->menu)
2759 {
2760 /* adding will fail if client hasn't been shown yet */
2761 ic->menu_pending = eina_list_append(ic->menu_pending, ec);
2762 evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _ibar_exec_new_client_show, ic);
2763 }
2764 }
2765 else if (!b->inst->ci->dont_add_nonorder)
2766 {
2767 if (skip) continue;
2768 _ibar_sep_create(b);
2769 _ibar_icon_notinorder_new(b, exe);
2770 _ibar_resize_handle(b);
2771 }
2772 }
2773 return ECORE_CALLBACK_RENEW;
2774 }
2775
2776 static Eina_Bool
_ibar_cb_exec_new(void * d EINA_UNUSED,int t EINA_UNUSED,E_Exec_Instance * exe)2777 _ibar_cb_exec_new(void *d EINA_UNUSED, int t EINA_UNUSED, E_Exec_Instance *exe)
2778 {
2779 IBar *b;
2780 E_Client *ec;
2781 Eina_List *l;
2782 Eina_Bool skip = EINA_TRUE;
2783
2784 if (!exe->desktop) return ECORE_CALLBACK_RENEW; //can't do anything here :(
2785 if (!exe->desktop->icon) return ECORE_CALLBACK_RENEW;
2786 EINA_LIST_FOREACH(exe->clients, l, ec)
2787 if (!ec->netwm.state.skip_taskbar)
2788 {
2789 skip = EINA_FALSE;
2790 break;
2791 }
2792 EINA_LIST_FOREACH(ibars, l, b)
2793 {
2794 IBar_Icon *ic;
2795
2796 ic = eina_hash_find(b->icon_hash, _desktop_name_get(exe->desktop));
2797 if (ic)
2798 {
2799 if (!ic->exes) _ibar_icon_signal_emit(ic, "e,state,on", "e");
2800 if (skip) continue;
2801 if (!eina_list_data_find(ic->exes, exe))
2802 ic->exes = eina_list_append(ic->exes, exe);
2803 if (ic->menu)
2804 {
2805 /* adding will fail if client hasn't been shown yet */
2806 ic->menu_pending = eina_list_append(ic->menu_pending, ec);
2807 evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW, _ibar_exec_new_client_show, ic);
2808 }
2809 }
2810 else if (!b->inst->ci->dont_add_nonorder)
2811 {
2812 if (skip) continue;
2813 _ibar_sep_create(b);
2814 ic = _ibar_icon_notinorder_new(b, exe);
2815 _ibar_resize_handle(b);
2816 }
2817 }
2818 return ECORE_CALLBACK_RENEW;
2819 }
2820
2821 /* module setup */
2822 E_API E_Module_Api e_modapi =
2823 {
2824 E_MODULE_API_VERSION, "IBar"
2825 };
2826
2827 E_API void *
e_modapi_init(E_Module * m)2828 e_modapi_init(E_Module *m)
2829 {
2830 conf_item_edd = E_CONFIG_DD_NEW("IBar_Config_Item", Config_Item);
2831 #undef T
2832 #undef D
2833 #define T Config_Item
2834 #define D conf_item_edd
2835 E_CONFIG_VAL(D, T, id, STR);
2836 E_CONFIG_VAL(D, T, dir, STR);
2837 E_CONFIG_VAL(D, T, show_label, INT);
2838 E_CONFIG_VAL(D, T, eap_label, INT);
2839 E_CONFIG_VAL(D, T, lock_move, INT);
2840 E_CONFIG_VAL(D, T, dont_add_nonorder, INT);
2841 E_CONFIG_VAL(D, T, dont_track_launch, UCHAR);
2842 E_CONFIG_VAL(D, T, dont_icon_menu_mouseover, UCHAR);
2843
2844 conf_edd = E_CONFIG_DD_NEW("IBar_Config", Config);
2845 #undef T
2846 #undef D
2847 #define T Config
2848 #define D conf_edd
2849 E_CONFIG_LIST(D, T, items, conf_item_edd);
2850
2851 ibar_config = e_config_domain_load("module.ibar", conf_edd);
2852
2853 if (!ibar_config)
2854 {
2855 Config_Item *ci;
2856
2857 ibar_config = E_NEW(Config, 1);
2858
2859 ci = E_NEW(Config_Item, 1);
2860 ci->id = eina_stringshare_add("ibar.1");
2861 ci->dir = eina_stringshare_add("default");
2862 ci->show_label = 1;
2863 ci->eap_label = 0;
2864 ci->lock_move = 0;
2865 ci->dont_add_nonorder = 0;
2866 ci->dont_track_launch = 0;
2867 ci->dont_icon_menu_mouseover = 0;
2868 ibar_config->items = eina_list_append(ibar_config->items, ci);
2869 }
2870
2871 ibar_config->module = m;
2872
2873 E_LIST_HANDLER_APPEND(ibar_config->handlers, E_EVENT_CONFIG_ICON_THEME,
2874 _ibar_cb_config_icons, NULL);
2875 E_LIST_HANDLER_APPEND(ibar_config->handlers, EFREET_EVENT_ICON_CACHE_UPDATE,
2876 _ibar_cb_config_icons, NULL);
2877 E_LIST_HANDLER_APPEND(ibar_config->handlers, E_EVENT_EXEC_NEW,
2878 _ibar_cb_exec_new, NULL);
2879 E_LIST_HANDLER_APPEND(ibar_config->handlers, E_EVENT_EXEC_NEW_CLIENT,
2880 _ibar_cb_exec_new_client, NULL);
2881 E_LIST_HANDLER_APPEND(ibar_config->handlers, E_EVENT_EXEC_DEL,
2882 _ibar_cb_exec_del, NULL);
2883 E_LIST_HANDLER_APPEND(ibar_config->handlers, E_EVENT_CLIENT_PROPERTY,
2884 _ibar_cb_client_prop, NULL);
2885
2886 e_gadcon_provider_register(&_gadcon_class);
2887 ibar_orders = eina_hash_string_superfast_new(NULL);
2888
2889 act_ibar_focus = e_action_add("ibar_focus");
2890 if (act_ibar_focus)
2891 {
2892 act_ibar_focus->func.go_key = _ibar_cb_action_focus;
2893 e_action_predef_name_set(N_("IBar"), N_("Focus IBar"),
2894 "ibar_focus", "<none>", NULL, 0);
2895 }
2896
2897 return m;
2898 }
2899
2900 E_API int
e_modapi_shutdown(E_Module * m EINA_UNUSED)2901 e_modapi_shutdown(E_Module *m EINA_UNUSED)
2902 {
2903 Ecore_Event_Handler *eh;
2904 Config_Item *ci;
2905
2906 _ibar_go_unfocus();
2907
2908 e_action_del("ibar_focus");
2909 e_action_predef_name_del("IBar", "Focus IBar");
2910 act_ibar_focus = NULL;
2911
2912 e_gadcon_provider_unregister(&_gadcon_class);
2913
2914 if (ibar_config->config_dialog)
2915 e_object_del(E_OBJECT(ibar_config->config_dialog));
2916
2917 EINA_LIST_FREE(ibar_config->handlers, eh)
2918 ecore_event_handler_del(eh);
2919
2920 EINA_LIST_FREE(ibar_config->items, ci)
2921 {
2922 if (ci->id) eina_stringshare_del(ci->id);
2923 if (ci->dir) eina_stringshare_del(ci->dir);
2924 E_FREE(ci);
2925 }
2926 E_FREE(ibar_config);
2927 ibar_config = NULL;
2928 eina_hash_free(ibar_orders);
2929 ibar_orders = NULL;
2930 E_CONFIG_DD_FREE(conf_item_edd);
2931 E_CONFIG_DD_FREE(conf_edd);
2932 return 1;
2933 }
2934
2935 E_API int
e_modapi_save(E_Module * m EINA_UNUSED)2936 e_modapi_save(E_Module *m EINA_UNUSED)
2937 {
2938 e_config_domain_save("module.ibar", conf_edd, ibar_config);
2939 return 1;
2940 }
2941
2942 static Eina_Bool
_ibar_cb_config_icons(EINA_UNUSED void * data,EINA_UNUSED int ev_type,EINA_UNUSED void * ev)2943 _ibar_cb_config_icons(EINA_UNUSED void *data, EINA_UNUSED int ev_type, EINA_UNUSED void *ev)
2944 {
2945 const Eina_List *l;
2946 Instance *inst;
2947
2948 EINA_LIST_FOREACH(ibar_config->instances, l, inst)
2949 {
2950 IBar_Icon *icon;
2951
2952 EINA_INLIST_FOREACH(inst->ibar->icons, icon)
2953 _ibar_icon_fill(icon);
2954 }
2955 return ECORE_CALLBACK_PASS_ON;
2956 }
2957
2958