Refactor systray to have only one box

This is simpler and avoid some edje erros.

This patch depends on a patch on elementary to update systray edj.
This commit is contained in:
José Roberto de Souza 2013-12-18 18:51:08 -02:00 committed by Mike Blumenkrantz
parent f2e20b2052
commit dc74938241
5 changed files with 84 additions and 109 deletions

View File

@ -96,6 +96,7 @@ _cfg_data_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
systray_xembed_shutdown(); systray_xembed_shutdown();
inst->xembed = NULL; inst->xembed = NULL;
} }
systray_size_updated(inst); systray_size_updated(inst);
ctx->config->use_xembed = cfdata->use_xembed; ctx->config->use_xembed = cfdata->use_xembed;
@ -514,31 +515,29 @@ systray_edje_get(const Instance *inst)
return inst->ui.gadget; return inst->ui.gadget;
} }
void const Evas_Object *
systray_edje_emit(const Instance *inst, const char *sig) systray_box_get(const Instance *inst)
{ {
EINA_SAFETY_ON_NULL_RETURN(inst); EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
edje_object_signal_emit(inst->ui.gadget, sig, _sig_source); return edje_object_part_object_get(inst->ui.gadget, "box");
} }
void void
systray_edje_box_append(const Instance *inst, const char *part, systray_edje_box_append(const Instance *inst, Evas_Object *child)
Evas_Object *child)
{ {
EINA_SAFETY_ON_NULL_RETURN(inst); edje_object_part_box_append(inst->ui.gadget, "box", child);
EINA_SAFETY_ON_NULL_RETURN(part);
EINA_SAFETY_ON_NULL_RETURN(child);
edje_object_part_box_append(inst->ui.gadget, part, child);
} }
void void
systray_edje_box_remove(const Instance *inst, const char *part, systray_edje_box_prepend(const Instance *inst, Evas_Object *child)
Evas_Object *child)
{ {
EINA_SAFETY_ON_NULL_RETURN(inst); edje_object_part_box_prepend(inst->ui.gadget, "box", child);
EINA_SAFETY_ON_NULL_RETURN(part); }
EINA_SAFETY_ON_NULL_RETURN(child);
edje_object_part_box_remove(inst->ui.gadget, part, child); void
systray_edje_box_remove(const Instance *inst, Evas_Object *child)
{
edje_object_part_box_remove(inst->ui.gadget, "box", child);
} }
int int
@ -560,12 +559,12 @@ _systray_size_apply_do(Instance *inst)
{ {
Evas_Coord w, h; Evas_Coord w, h;
if (inst->xembed)
systray_xembed_size_updated(inst->xembed);
edje_object_message_signal_process(inst->ui.gadget); edje_object_message_signal_process(inst->ui.gadget);
edje_object_size_min_calc(inst->ui.gadget, &w, &h); edje_object_size_min_calc(inst->ui.gadget, &w, &h);
e_gadcon_client_min_size_set(inst->gcc, MAX(w, SYSTRAY_MIN_W), MAX(h, SYSTRAY_MIN_H)); e_gadcon_client_min_size_set(inst->gcc, MAX(w, SYSTRAY_MIN_W), MAX(h, SYSTRAY_MIN_H));
if (inst->xembed)
systray_xembed_size_updated(inst->xembed);
} }
static void static void

View File

@ -42,9 +42,10 @@ const char *systray_style_get(const Instance *inst);
void systray_size_updated(Instance *inst); void systray_size_updated(Instance *inst);
Evas *systray_evas_get(const Instance *inst); Evas *systray_evas_get(const Instance *inst);
Evas_Object *systray_edje_get(const Instance *inst); Evas_Object *systray_edje_get(const Instance *inst);
void systray_edje_emit(const Instance *inst, const char *sig); const Evas_Object *systray_box_get(const Instance *inst);
void systray_edje_box_append(const Instance *inst, const char *part, Evas_Object *child); void systray_edje_box_append(const Instance *inst, Evas_Object *child);
void systray_edje_box_remove(const Instance *inst, const char *part, Evas_Object *child); void systray_edje_box_remove(const Instance *inst, Evas_Object *child);
void systray_edje_box_prepend(const Instance *inst, Evas_Object *child);
int systray_manager_number_get(const Instance *inst); int systray_manager_number_get(const Instance *inst);
Ecore_X_Window systray_root_get(const Instance *inst); Ecore_X_Window systray_root_get(const Instance *inst);

View File

@ -14,7 +14,6 @@ const char *Status_Names[] = {
"unknown", "Active", "Passive", "NeedsAttention", NULL "unknown", "Active", "Passive", "NeedsAttention", NULL
}; };
static const char *box_part_name = "e.dbus_notifier.box";
static Context_Notifier_Host *ctx = NULL; static Context_Notifier_Host *ctx = NULL;
void void
@ -247,8 +246,7 @@ jump_search:
image_load(item->icon_name, item->icon_path, ii->icon); image_load(item->icon_name, item->icon_path, ii->icon);
if (!evas_object_visible_get(ii->icon)) if (!evas_object_visible_get(ii->icon))
{ {
systray_edje_box_append(host_inst->inst, box_part_name, systray_edje_box_append(host_inst->inst, ii->icon);
ii->icon);
evas_object_show(ii->icon); evas_object_show(ii->icon);
} }
break; break;
@ -257,8 +255,7 @@ jump_search:
{ {
if (evas_object_visible_get(ii->icon)) if (evas_object_visible_get(ii->icon))
{ {
systray_edje_box_remove(host_inst->inst, box_part_name, systray_edje_box_remove(host_inst->inst, ii->icon);
ii->icon);
evas_object_hide(ii->icon); evas_object_hide(ii->icon);
} }
break; break;
@ -268,8 +265,7 @@ jump_search:
image_load(item->attention_icon_name, item->icon_path, ii->icon); image_load(item->attention_icon_name, item->icon_path, ii->icon);
if (!evas_object_visible_get(ii->icon)) if (!evas_object_visible_get(ii->icon))
{ {
systray_edje_box_append(host_inst->inst, box_part_name, systray_edje_box_append(host_inst->inst, ii->icon);
ii->icon);
evas_object_show(ii->icon); evas_object_show(ii->icon);
} }
break; break;

View File

@ -44,7 +44,7 @@ typedef struct _Icon Icon;
struct _Icon struct _Icon
{ {
Ecore_X_Window win; Ecore_X_Window win;
Evas_Object *o; Evas_Object *rect;
Instance_Xembed *xembed; Instance_Xembed *xembed;
}; };
@ -83,39 +83,39 @@ static Ecore_X_Atom _atom_xembed_info = 0;
static Ecore_X_Atom _atom_st_num = 0; static Ecore_X_Atom _atom_st_num = 0;
static int _last_st_num = -1; static int _last_st_num = -1;
/* TODO: remove me later: */ static void
static const char _part_box[] = "e.xembed.box"; _xembed_win_resize(Instance_Xembed *xembed)
static const char _part_size[] = "e.xembed.size"; {
static const char _sig_enable[] = "e,action,xembed,enable"; Evas_Coord first_x, first_y, first_w, first_h, last_x, last_y;
static const char _sig_disable[] = "e,action,xembed,disable"; Icon *icon;
/* END TODO: remove me later */
if (!xembed->icons)
return;
icon = eina_list_data_get(xembed->icons);
evas_object_geometry_get(icon->rect, &first_x,
&first_y, &first_w, &first_h);
icon = eina_list_last_data_get(xembed->icons);
evas_object_geometry_get(icon->rect, &last_x,
&last_y, NULL, NULL);
//because we always prepend xembed icons
ecore_x_window_move_resize(xembed->win.base, last_x, last_y,
(first_x+first_w) - last_x,
(first_y+first_h) - last_y);
}
void void
systray_xembed_size_updated(Instance_Xembed *xembed) systray_xembed_size_updated(Instance_Xembed *xembed)
{ {
const Evas_Object *o;
Evas_Object *ui = systray_edje_get(xembed->inst);
Evas_Coord x, y, w, h, mw = 1, mh = 1;
/* this hack is required so we resize the base xwindow */
edje_object_message_signal_process(ui);
o = edje_object_part_object_get(ui, _part_box);
if (!o) return;
evas_object_size_hint_min_get(o, &w, &h);
if (w < 1) w = 1;
if (h < 1) h = 1;
if (eina_list_count(xembed->icons) == 0) if (eina_list_count(xembed->icons) == 0)
ecore_x_window_hide(xembed->win.base); {
else ecore_x_window_hide(xembed->win.base);
ecore_x_window_show(xembed->win.base); return;
edje_object_size_min_calc(systray_edje_get(xembed->inst), &mw, &mh); }
e_gadcon_client_min_size_set(systray_gadcon_client_get(xembed->inst), mw, mh); ecore_x_window_show(xembed->win.base);
_xembed_win_resize(xembed);
evas_object_geometry_get(o, &x, &y, &w, &h);
ecore_x_window_move_resize(xembed->win.base, x, y, w, h);
} }
static void static void
@ -135,15 +135,15 @@ _systray_xembed_cb_resize(void *data, Evas *evas __UNUSED__, Evas_Object *o __UN
static void static void
_systray_xembed_icon_geometry_apply(Icon *icon) _systray_xembed_icon_geometry_apply(Icon *icon)
{ {
const Evas_Object *o, *ui = systray_edje_get(icon->xembed->inst); const Evas_Object *box;
Evas_Coord x, y, w, h, wx, wy; Evas_Coord x, y, w, h, wx, wy;
/* hack required so we reposition x window inside parent */ /* hack required so we reposition x window inside parent */
o = edje_object_part_object_get(ui, _part_size); box = systray_box_get(icon->xembed->inst);
if (!o) return; if (!box) return;
evas_object_geometry_get(icon->o, &x, &y, &w, &h); evas_object_geometry_get(icon->rect, &x, &y, &w, &h);
evas_object_geometry_get(o, &wx, &wy, NULL, NULL); evas_object_geometry_get(box, &wx, &wy, NULL, NULL);
ecore_x_window_move_resize(icon->win, x - wx, y - wy, w, h); ecore_x_window_move_resize(icon->win, x - wx, y - wy, w, h);
} }
@ -220,17 +220,10 @@ static Icon *
_systray_xembed_icon_add(Instance_Xembed *xembed, const Ecore_X_Window win) _systray_xembed_icon_add(Instance_Xembed *xembed, const Ecore_X_Window win)
{ {
Ecore_X_Gravity gravity; Ecore_X_Gravity gravity;
Evas_Object *o; Evas_Object *rect;
Evas_Coord w, h, sz = 48; Evas_Coord w, h, sz = 48;
Icon *icon; Icon *icon;
edje_object_part_geometry_get(systray_edje_get(xembed->inst), _part_size,
NULL, NULL, &w, &h);
if (w > h)
w = h;
else
h = w;
/* assuming systray must be on a shelf here */ /* assuming systray must be on a shelf here */
switch (systray_gadcon_get(xembed->inst)->orient) switch (systray_gadcon_get(xembed->inst)->orient)
{ {
@ -252,32 +245,31 @@ _systray_xembed_icon_add(Instance_Xembed *xembed, const Ecore_X_Window win)
case E_GADCON_ORIENT_CORNER_LB: case E_GADCON_ORIENT_CORNER_LB:
case E_GADCON_ORIENT_CORNER_RB: case E_GADCON_ORIENT_CORNER_RB:
sz = systray_gadcon_get(xembed->inst)->shelf->w; sz = systray_gadcon_get(xembed->inst)->shelf->w;
break;
default: default:
break; break;
} }
if ((w < 16) && (sz > 16))
w = h = sz - 5;
w = h = e_util_icon_size_normalize(w); sz = sz - 5;
if (w > sz - 5) w = h = e_util_icon_size_normalize(sz);
w = h = e_util_icon_size_normalize(sz - 5);
o = evas_object_rectangle_add(systray_evas_get(xembed->inst)); rect = evas_object_rectangle_add(systray_evas_get(xembed->inst));
if (!o) if (!rect)
return NULL; return NULL;
evas_object_color_set(o, 0, 0, 0, 0); evas_object_color_set(rect, 0, 0, 0, 0);
evas_object_resize(o, w, h); evas_object_resize(rect, w, h);
evas_object_show(o); evas_object_show(rect);
icon = malloc(sizeof(*icon)); icon = malloc(sizeof(Icon));
if (!icon) if (!icon)
{ {
evas_object_del(o); evas_object_del(rect);
return NULL; return NULL;
} }
icon->win = win; icon->win = win;
icon->xembed = xembed; icon->xembed = xembed;
icon->o = o; icon->rect = rect;
gravity = _systray_xembed_gravity(xembed); gravity = _systray_xembed_gravity(xembed);
ecore_x_icccm_size_pos_hints_set(win, 1, gravity, ecore_x_icccm_size_pos_hints_set(win, 1, gravity,
@ -290,15 +282,13 @@ _systray_xembed_icon_add(Instance_Xembed *xembed, const Ecore_X_Window win)
ecore_x_window_save_set_add(win); ecore_x_window_save_set_add(win);
ecore_x_window_shape_events_select(win, 1); ecore_x_window_shape_events_select(win, 1);
//ecore_x_window_geometry_get(win, NULL, NULL, &w, &h);
evas_object_event_callback_add evas_object_event_callback_add
(o, EVAS_CALLBACK_MOVE, _systray_xembed_icon_cb_move, icon); (rect, EVAS_CALLBACK_MOVE, _systray_xembed_icon_cb_move, icon);
evas_object_event_callback_add evas_object_event_callback_add
(o, EVAS_CALLBACK_RESIZE, _systray_xembed_icon_cb_resize, icon); (rect, EVAS_CALLBACK_RESIZE, _systray_xembed_icon_cb_resize, icon);
xembed->icons = eina_list_append(xembed->icons, icon); xembed->icons = eina_list_append(xembed->icons, icon);
systray_edje_box_append(xembed->inst, _part_box, o); systray_edje_box_prepend(xembed->inst, rect);
systray_size_updated(xembed->inst); systray_size_updated(xembed->inst);
_systray_xembed_icon_geometry_apply(icon); _systray_xembed_icon_geometry_apply(icon);
@ -314,7 +304,7 @@ _systray_xembed_icon_del_list(Instance_Xembed *xembed, Eina_List *l, Icon *icon)
ecore_x_window_save_set_del(icon->win); ecore_x_window_save_set_del(icon->win);
ecore_x_window_reparent(icon->win, 0, 0, 0); ecore_x_window_reparent(icon->win, 0, 0, 0);
evas_object_del(icon->o); evas_object_del(icon->rect);
free(icon); free(icon);
systray_size_updated(xembed->inst); systray_size_updated(xembed->inst);
@ -366,8 +356,6 @@ _systray_xembed_deactivate(Instance_Xembed *xembed)
{ {
if (xembed->win.selection == 0) return; if (xembed->win.selection == 0) return;
systray_edje_emit(xembed->inst, _sig_disable);
while (xembed->icons) while (xembed->icons)
_systray_xembed_icon_del_list(xembed, xembed->icons, xembed->icons->data); _systray_xembed_icon_del_list(xembed, xembed->icons, xembed->icons->data);
@ -381,8 +369,8 @@ _systray_xembed_deactivate(Instance_Xembed *xembed)
static Eina_Bool static Eina_Bool
_systray_xembed_base_create(Instance_Xembed *xembed) _systray_xembed_base_create(Instance_Xembed *xembed)
{ {
const Evas_Object *o, *ui = systray_edje_get(xembed->inst); const Evas_Object *box;
Evas_Coord x, y, w, h; Evas_Coord x, y;
unsigned short r, g, b; unsigned short r, g, b;
const char *color; const char *color;
Eina_Bool invis = EINA_FALSE; Eina_Bool invis = EINA_FALSE;
@ -392,7 +380,8 @@ _systray_xembed_base_create(Instance_Xembed *xembed)
invis = EINA_TRUE; invis = EINA_TRUE;
else else
{ {
color = edje_object_data_get(ui, systray_style_get(xembed->inst)); color = edje_object_data_get(systray_edje_get(xembed->inst),
systray_style_get(xembed->inst));
if (color && (sscanf(color, "%hu %hu %hu", &r, &g, &b) == 3)) if (color && (sscanf(color, "%hu %hu %hu", &r, &g, &b) == 3))
{ {
@ -404,14 +393,12 @@ _systray_xembed_base_create(Instance_Xembed *xembed)
r = g = b = (unsigned short)65535; r = g = b = (unsigned short)65535;
} }
o = edje_object_part_object_get(ui, _part_size); box = systray_box_get(xembed->inst);
if (!o) if (!box)
return EINA_FALSE; return EINA_FALSE;
evas_object_geometry_get(o, &x, &y, &w, &h); evas_object_geometry_get(box, &x, &y, NULL, NULL);
if (w < 1) w = 1; xembed->win.base = ecore_x_window_new(0, x, y, 1, 1);
if (h < 1) h = 1;
xembed->win.base = ecore_x_window_new(0, x, y, w, h);
ecore_x_icccm_title_set(xembed->win.base, "noshadow_systray_base"); ecore_x_icccm_title_set(xembed->win.base, "noshadow_systray_base");
ecore_x_icccm_name_class_set(xembed->win.base, "systray", "holder"); ecore_x_icccm_name_class_set(xembed->win.base, "systray", "holder");
ecore_x_netwm_name_set(xembed->win.base, "noshadow_systray_base"); ecore_x_netwm_name_set(xembed->win.base, "noshadow_systray_base");
@ -480,8 +467,6 @@ _systray_xembed_activate(Instance_Xembed *xembed)
ecore_x_current_time_get(), atom, ecore_x_current_time_get(), atom,
xembed->win.selection, 0, 0); xembed->win.selection, 0, 0);
systray_edje_emit(xembed->inst, _sig_enable);
return 1; return 1;
} }
@ -529,8 +514,6 @@ _systray_xembed_activate_retry_first(void *data)
return ECORE_CALLBACK_CANCEL; return ECORE_CALLBACK_CANCEL;
} }
systray_edje_emit(xembed->inst, _sig_disable);
fprintf(stderr, "SYSTRAY: activate failure! retrying in %0.1f seconds\n", fprintf(stderr, "SYSTRAY: activate failure! retrying in %0.1f seconds\n",
RETRY_TIMEOUT); RETRY_TIMEOUT);
@ -737,8 +720,6 @@ _systray_xembed_cb_selection_clear(void *data, int type __UNUSED__, void *event)
(ev->atom == _systray_xembed_atom_st_get(manager)) && (ev->atom == _systray_xembed_atom_st_get(manager)) &&
(ecore_x_selection_owner_get(ev->atom) != xembed->win.selection)) (ecore_x_selection_owner_get(ev->atom) != xembed->win.selection))
{ {
systray_edje_emit(xembed->inst, _sig_disable);
while (xembed->icons) while (xembed->icons)
_systray_xembed_icon_del_list(xembed, xembed->icons, _systray_xembed_icon_del_list(xembed, xembed->icons,
xembed->icons->data); xembed->icons->data);
@ -850,8 +831,6 @@ systray_xembed_new(Instance *inst)
if (!xembed->timer.retry) if (!xembed->timer.retry)
xembed->timer.retry = ecore_timer_add xembed->timer.retry = ecore_timer_add
(0.1, _systray_xembed_activate_retry_first, xembed); (0.1, _systray_xembed_activate_retry_first, xembed);
else
systray_edje_emit(xembed->inst, _sig_disable);
} }
evas_object_event_callback_add(ui, EVAS_CALLBACK_MOVE, evas_object_event_callback_add(ui, EVAS_CALLBACK_MOVE,