enlightenment-module-desksa.../src/magnify.c

154 lines
4.1 KiB
C
Raw Normal View History

2014-08-22 15:14:21 -07:00
#include "e_mod_main.h"
static E_Action *act_magnify = NULL;
static int current_mag = -1;
static Evas_Object **magnifiers = {NULL};
static Evas_Object *clip = NULL;
static Ecore_Event_Handler *handler = NULL;
static Ecore_Event_Handler *deskflip = NULL;
static Ecore_Timer *timer = NULL;
#define MAG_SIZE_FACTOR 10
static void
_magnify_end(void)
{
unsigned int n;
if (!magnifiers) return;
2015-03-13 17:02:46 -07:00
for (n = 0; n < eina_list_count(e_comp->zones); n++)
2014-08-22 15:14:21 -07:00
E_FREE_FUNC(magnifiers[n], evas_object_del);
E_FREE(magnifiers);
E_FREE_FUNC(clip, evas_object_del);
E_FREE_FUNC(handler, ecore_event_handler_del);
E_FREE_FUNC(timer, ecore_timer_del);
current_mag = -1;
}
static void
_current_update(int n)
{
if (current_mag != -1)
2017-06-30 13:14:12 -07:00
e_efx_zoom_reset(magnifiers[current_mag]);
2014-08-22 15:14:21 -07:00
current_mag = n;
}
static void
_magnify_update(int x, int y)
{
int w, h;
E_Zone *zone;
2015-03-13 17:02:46 -07:00
zone = e_comp_zone_xy_get(x, y);
2014-08-22 15:14:21 -07:00
if ((int)zone->num != current_mag)
_current_update(zone->num);
w = zone->w / MAG_SIZE_FACTOR;
h = zone->h / MAG_SIZE_FACTOR;
evas_object_geometry_set(clip, x - (w / 2), y - (h / 2), w, h);
2017-06-30 13:14:12 -07:00
e_efx_zoom(magnifiers[zone->num], E_EFX_EFFECT_SPEED_LINEAR, 0, 2.0, E_EFX_POINT(x, y), 0, NULL, NULL);
2014-08-22 15:14:21 -07:00
}
static Eina_Bool
_magnify_move(void *data EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Move *ev)
{
2015-03-13 17:02:46 -07:00
_magnify_update(e_comp_canvas_x_root_adjust(ev->root.x), e_comp_canvas_y_root_adjust(ev->root.y));
2014-08-22 15:14:21 -07:00
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_magnify_poll(void *d EINA_UNUSED)
{
int x, y;
2015-01-15 13:51:11 -08:00
ecore_evas_pointer_xy_get(e_comp->ee, &x, &y);
2014-08-22 15:14:21 -07:00
_magnify_update(x, y);
return ECORE_CALLBACK_RENEW;
}
static void
_magnify_new(E_Desk *desk)
{
int n = desk->zone->num;
magnifiers[n] = e_deskmirror_add(desk, 0, 0);
evas_object_pass_events_set(magnifiers[n], 1);
evas_object_data_set(magnifiers[n], "comp_skip", (void*)1);
evas_object_geometry_set(magnifiers[n], desk->zone->x, desk->zone->y, desk->zone->w, desk->zone->h);
evas_object_layer_set(magnifiers[n], E_LAYER_MENU + 1);
evas_object_show(magnifiers[n]);
evas_object_clip_set(magnifiers[n], clip);
}
static void
_magnify_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
{
E_Zone *zone;
unsigned int n;
int x, y, w, h;
Eina_List *l;
if (magnifiers)
{
_magnify_end();
return;
}
2015-03-13 17:02:46 -07:00
clip = evas_object_rectangle_add(e_comp->evas);
2014-08-22 15:14:21 -07:00
evas_object_show(clip);
2015-03-13 17:02:46 -07:00
ecore_evas_pointer_xy_get(e_comp->ee, &x, &y);
magnifiers = malloc(sizeof(void*) * eina_list_count(e_comp->zones));
for (n = 0, l = e_comp->zones, zone = eina_list_data_get(l);
n < eina_list_count(e_comp->zones);
2014-08-22 15:14:21 -07:00
n++, l = eina_list_next(l), zone = eina_list_data_get(l))
{
_magnify_new(e_desk_current_get(zone));
evas_object_clip_set(magnifiers[n], clip);
2015-03-13 17:02:46 -07:00
if (zone != e_zone_current_get()) continue;
2014-08-22 15:14:21 -07:00
w = zone->w / MAG_SIZE_FACTOR;
h = zone->h / MAG_SIZE_FACTOR;
evas_object_geometry_set(clip, x - (w / 2), y - (h / 2), w, h);
_current_update(n);
}
2015-03-13 17:02:46 -07:00
if (e_comp->comp_type == E_PIXMAP_TYPE_X)
2014-08-22 15:14:21 -07:00
timer = ecore_timer_add(0.05, _magnify_poll, NULL);
else
handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, (Ecore_Event_Handler_Cb)_magnify_move, NULL);
}
static Eina_Bool
_magnify_deskflip(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Desk_Show *ev)
{
if (!magnifiers) return ECORE_CALLBACK_RENEW;
evas_object_del(magnifiers[ev->desk->zone->num]);
_magnify_new(ev->desk);
_current_update(ev->desk->zone->num);
return ECORE_CALLBACK_RENEW;
}
EINTERN void
mag_init(void)
{
act_magnify = e_action_add("magnify");
if (act_magnify)
{
act_magnify->func.go = _magnify_cb;
e_action_predef_name_set(D_("Compositor"), D_("Toggle magnification"),
"magnify", NULL, NULL, 0);
}
deskflip = ecore_event_handler_add(E_EVENT_DESK_SHOW, (Ecore_Event_Handler_Cb)_magnify_deskflip, NULL);
}
EINTERN void
mag_shutdown(void)
{
_magnify_end();
e_action_predef_name_del(D_("Compositor"), D_("Toggle magnification"));
e_action_del("magnify");
act_magnify = NULL;
E_FREE_FUNC(deskflip, ecore_event_handler_del);
}