enlightenment/src/bin/e_popup.c

346 lines
9.2 KiB
C
Raw Normal View History

#include "e.h"
/* local subsystem functions */
static void _e_popup_free(E_Popup *pop);
static Eina_Bool _e_popup_idle_enterer(void *data);
static Eina_Bool _e_popup_cb_window_shape(void *data, int ev_type, void *ev);
/* local subsystem globals */
static Ecore_Event_Handler *_e_popup_window_shape_handler = NULL;
static Eina_List *_e_popup_list = NULL;
static Eina_Hash *_e_popup_hash = NULL;
/* externally accessible functions */
2006-01-07 02:39:46 -08:00
EAPI int
e_popup_init(void)
{
_e_popup_window_shape_handler =
ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHAPE,
_e_popup_cb_window_shape, NULL);
if (!_e_popup_hash) _e_popup_hash = eina_hash_string_superfast_new(NULL);
return 1;
}
2006-01-07 02:39:46 -08:00
EAPI int
e_popup_shutdown(void)
{
if (_e_popup_hash)
{
eina_hash_free(_e_popup_hash);
_e_popup_hash = NULL;
}
E_FN_DEL(ecore_event_handler_del, _e_popup_window_shape_handler);
return 1;
}
2006-01-07 02:39:46 -08:00
EAPI E_Popup *
e_popup_new(E_Zone *zone, int x, int y, int w, int h)
{
E_Popup *pop;
pop = E_OBJECT_ALLOC(E_Popup, E_POPUP_TYPE, _e_popup_free);
if (!pop) return NULL;
pop->zone = zone;
pop->x = x;
pop->y = y;
pop->w = w;
pop->h = h;
pop->layer = 250;
pop->ecore_evas = e_canvas_new(e_config->evas_engine_popups, pop->zone->container->win,
pop->zone->x + pop->x, pop->zone->y + pop->y, pop->w, pop->h, 1, 1,
&(pop->evas_win));
if (!pop->ecore_evas)
{
free(pop);
return NULL;
}
/* avoid excess exposes when shaped - set damage avoid to 1 */
e: 1. configure/build changes to allow cross-compiling painlessly 2. pager module namespace changes - this was still dirty afdter the namespace cleanup, so clean it up 3. add a powersave subsystem - doesnt have an "automatic" way to turn on and off right now, this i think is best provided by modules (that do things like monitor acpi status's (eg close lid of laptop), AC power status etc. etc. this allows e to nicely defer "power" expensive actions to avoid disk spinups etc. 4. move to use the new ecore poller system - discussed long ago as part of power management/saving issues. now it exists 5. add a canvas idle flush call that helsp cope with the new shm greedy software x11 engine stuff 6. use the new powersave subsystem where appropriate 7. fix non-zeroed/initted memory access in e_fm_main 8. fix mem leak for e menus 9. remove ipc handlers for changed/removed config values 10. use animaotr not timer for menu scrolls - then menu scrolls obey the fps config 11. fix up timer/poll happienss of cursor idle stuff 12. remove avoid damage from popups for now - causing problems 13. change battery and temp readouts to b e shorter so they fit 14. pager can emit signals on focus change for mini-windows now 15. temperature module now uses a slave process and uses stdin/out to talk to it and get output - this makes e smoother as in my expereicne i found getting the temp on my laptop actually took like 200ms so e "hang" for 200ms while reading the acpi files - so now the subprocess does it and just writesa back to e when it gets it. ecore: 1. add ecore_pollers. see the documentation on them in doxygen comments :) 2. fix timers to only go off when they have to - bug there that made e's select time out a LOT more than it needed to. defensive coding hid the problem. now fixed. e should be much more power friendly now. 3. formatting/niceness in ecore_exe stuff 4. some comments on comments with SIGIO ideas vs. select 5. add call to be able to add an idle enterer at the start of the list of them, not just the end (as has been the default) 6. fix ecore_evas to support auto evas idler calls after 0.5 secs of idle in all canvases - and to do it right 7. if argb destination - set the shape EVENT shape (to mask out events in transparent regions much like shape does withotu translucency) 8. in ecore_x add support for the event shape evas: 1. fix cache to work properly and not just always fill up (as it seemed to like to think cahce useage dropped below 0 when it didnt and thus just over-fill) 2. software x11 engine now ONLY uses shm segments - no ximages over the socket. this ximage hack was there to avoid the 2 round trips involved in setting up an shm image - now i mitigated that wih an shm image cache pool. it keeps shm images around and repurposes them for new update regions if appropriate. this means many fewer shm creates (about 1/100th the number) and since we recycle the memory less 0 memory page filling by the kernel - in the end, i recorded about a 10-20% speedup over the old software x11 engine. simple tests i have seen up to 120% speedups. idle flush now does something - it frees all the cached shm segments. it has a hard-coded limit of 4mb worth of shm segments (or 32 segments - whichever comes first) to keep around. once can never complain much about speedups methinks :). also evas will defer sync until the NEXT frame is written - this means evas can calculate the next frame of data while x dma's/copies the images to the screen at the same time (if you hve a dual core or multi-cpu machnike or your xserver is able to use DMA to copy image data to the screen/video ram then this should see a decent speedup). SVN revision: 33448
2008-01-10 23:33:57 -08:00
// ecore_evas_avoid_damage_set(pop->ecore_evas, 1);
e_canvas_add(pop->ecore_evas);
pop->shape = e_container_shape_add(pop->zone->container);
e_container_shape_move(pop->shape, pop->zone->x + pop->x, pop->zone->y + pop->y);
e_container_shape_resize(pop->shape, pop->w, pop->h);
pop->evas = ecore_evas_get(pop->ecore_evas);
e_container_window_raise(pop->zone->container, pop->evas_win, pop->layer);
ecore_x_window_shape_events_select(pop->evas_win, 1);
ecore_evas_name_class_set(pop->ecore_evas, "E", "_e_popup_window");
ecore_evas_title_set(pop->ecore_evas, "E Popup");
e_object_ref(E_OBJECT(pop->zone));
pop->zone->popups = eina_list_append(pop->zone->popups, pop);
_e_popup_list = eina_list_append(_e_popup_list, pop);
eina_hash_add(_e_popup_hash, e_util_winid_str_get(pop->evas_win), pop);
return pop;
}
EAPI void
e_popup_name_set(E_Popup *pop, const char *name)
{
if (eina_stringshare_replace(&pop->name, name))
ecore_evas_name_class_set(pop->ecore_evas, "E", pop->name);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_show(E_Popup *pop)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
if (pop->visible) return;
pop->visible = 1;
if ((pop->shaped) && (!e_config->use_composite))
{
ecore_evas_move(pop->ecore_evas,
pop->zone->container->manager->w,
pop->zone->container->manager->h);
ecore_evas_show(pop->ecore_evas);
if (pop->idle_enterer) ecore_idle_enterer_del(pop->idle_enterer);
pop->idle_enterer = ecore_idle_enterer_add(_e_popup_idle_enterer, pop);
}
else
{
ecore_evas_show(pop->ecore_evas);
if (!(pop->shaped && e_config->use_composite))
e_container_shape_show(pop->shape);
}
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_hide(E_Popup *pop)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
if (!pop->visible) return;
if (pop->idle_enterer) ecore_idle_enterer_del(pop->idle_enterer);
pop->idle_enterer = NULL;
pop->visible = 0;
ecore_evas_hide(pop->ecore_evas);
e_container_shape_hide(pop->shape);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_move(E_Popup *pop, int x, int y)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
if ((pop->x == x) && (pop->y == y)) return;
pop->x = x;
pop->y = y;
ecore_evas_move(pop->ecore_evas,
pop->zone->x + pop->x,
pop->zone->y + pop->y);
e_container_shape_move(pop->shape,
pop->zone->x + pop->x,
pop->zone->y + pop->y);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_resize(E_Popup *pop, int w, int h)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
if ((pop->w == w) && (pop->h == h)) return;
pop->w = w;
pop->h = h;
ecore_evas_resize(pop->ecore_evas, pop->w, pop->h);
e_container_shape_resize(pop->shape, pop->w, pop->h);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_move_resize(E_Popup *pop, int x, int y, int w, int h)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
if ((pop->x == x) && (pop->y == y) &&
(pop->w == w) && (pop->h == h)) return;
pop->x = x;
pop->y = y;
pop->w = w;
pop->h = h;
ecore_evas_move_resize(pop->ecore_evas,
pop->zone->x + pop->x,
pop->zone->y + pop->y,
pop->w, pop->h);
e_container_shape_move(pop->shape,
pop->zone->x + pop->x,
pop->zone->y + pop->y);
e_container_shape_resize(pop->shape, pop->w, pop->h);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_ignore_events_set(E_Popup *pop, int ignore)
{
ecore_evas_ignore_events_set(pop->ecore_evas, ignore);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_edje_bg_object_set(E_Popup *pop, Evas_Object *o)
{
const char *shape_option;
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
shape_option = edje_object_data_get(o, "shaped");
if (shape_option)
{
if (!strcmp(shape_option, "1"))
pop->shaped = 1;
else
pop->shaped = 0;
if (e_config->use_composite)
{
ecore_evas_alpha_set(pop->ecore_evas, pop->shaped);
eina_hash_del(_e_popup_hash, e_util_winid_str_get(pop->evas_win), pop);
pop->evas_win = ecore_evas_software_x11_window_get(pop->ecore_evas);
eina_hash_add(_e_popup_hash, e_util_winid_str_get(pop->evas_win), pop);
e_container_window_raise(pop->zone->container, pop->evas_win, pop->layer);
}
else
ecore_evas_shaped_set(pop->ecore_evas, pop->shaped);
}
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_layer_set(E_Popup *pop, int layer)
{
E_OBJECT_CHECK(pop);
E_OBJECT_TYPE_CHECK(pop, E_POPUP_TYPE);
pop->layer = layer;
e_container_window_raise(pop->zone->container, pop->evas_win, pop->layer);
}
2006-01-07 02:39:46 -08:00
EAPI void
e_popup_idler_before(void)
{
Eina_List *l;
E_Popup *pop;
EINA_LIST_FOREACH(_e_popup_list, l, pop)
{
if (pop->need_shape_export)
{
Ecore_X_Rectangle *rects, *orects;
int num;
rects = ecore_x_window_shape_rectangles_get(pop->evas_win, &num);
if (rects)
{
int changed;
changed = 1;
if ((num == pop->shape_rects_num) && (pop->shape_rects))
{
int i;
orects = pop->shape_rects;
changed = 0;
for (i = 0; i < num; i++)
{
if (rects[i].x < 0)
{
rects[i].width -= rects[i].x;
rects[i].x = 0;
}
if ((rects[i].x + (int) rects[i].width) > pop->w)
rects[i].width = rects[i].width - rects[i].x;
if (rects[i].y < 0)
{
rects[i].height -= rects[i].y;
rects[i].y = 0;
}
if ((rects[i].y + (int) rects[i].height) > pop->h)
rects[i].height = rects[i].height - rects[i].y;
if ((orects[i].x != rects[i].x) ||
(orects[i].y != rects[i].y) ||
(orects[i].width != rects[i].width) ||
(orects[i].height != rects[i].height))
{
changed = 1;
break;
}
}
}
if (changed)
{
2005-09-05 08:24:07 -07:00
E_FREE(pop->shape_rects);
pop->shape_rects = rects;
pop->shape_rects_num = num;
e_container_shape_rects_set(pop->shape, rects, num);
}
else
free(rects);
}
else
{
2005-09-05 08:24:07 -07:00
E_FREE(pop->shape_rects);
pop->shape_rects = NULL;
pop->shape_rects_num = 0;
e_container_shape_rects_set(pop->shape, NULL, 0);
}
pop->need_shape_export = 0;
}
if ((pop->visible) && (!pop->idle_enterer) &&
(!pop->shaped && e_config->use_composite))
e_container_shape_show(pop->shape);
}
}
EAPI E_Popup *
e_popup_find_by_window(Ecore_X_Window win)
{
E_Popup *pop;
pop = eina_hash_find(_e_popup_hash, e_util_winid_str_get(win));
if ((pop) && (pop->evas_win != win))
return NULL;
return pop;
}
/* local subsystem functions */
static void
_e_popup_free(E_Popup *pop)
{
if (pop->idle_enterer) ecore_idle_enterer_del(pop->idle_enterer);
pop->idle_enterer = NULL;
2005-09-05 08:24:07 -07:00
E_FREE(pop->shape_rects);
pop->shape_rects_num = 0;
e_container_shape_hide(pop->shape);
e_object_del(E_OBJECT(pop->shape));
e_canvas_del(pop->ecore_evas);
ecore_evas_free(pop->ecore_evas);
e_object_unref(E_OBJECT(pop->zone));
pop->zone->popups = eina_list_remove(pop->zone->popups, pop);
_e_popup_list = eina_list_remove(_e_popup_list, pop);
eina_hash_del(_e_popup_hash, e_util_winid_str_get(pop->evas_win), pop);
if (pop->name) eina_stringshare_del(pop->name);
free(pop);
}
static Eina_Bool
_e_popup_idle_enterer(void *data)
{
E_Popup *pop;
if (!(pop = data)) return ECORE_CALLBACK_CANCEL;
ecore_evas_move(pop->ecore_evas,
pop->zone->x + pop->x,
pop->zone->y + pop->y);
e_container_shape_show(pop->shape);
pop->idle_enterer = NULL;
return ECORE_CALLBACK_CANCEL;
}
static Eina_Bool
_e_popup_cb_window_shape(__UNUSED__ void *data, __UNUSED__ int ev_type, void *ev)
{
E_Popup *pop;
Ecore_X_Event_Window_Shape *e;
e = ev;
pop = e_popup_find_by_window(e->win);
if (pop) pop->need_shape_export = 1;
return ECORE_CALLBACK_PASS_ON;
}