summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2014-08-22 18:14:21 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2014-08-28 13:28:19 -0400
commitb499a6676491dad68c28600b3b56e12cc3dc75b8 (patch)
tree60ea16bd9030df4a12052d97bbe36f229a463e58
parentca5a6f3857f041cc8ebfbc03a8aed72e4feb85b7 (diff)
add magnifier
-rw-r--r--src/Makefile.am1
-rw-r--r--src/e_mod_main.c2
-rw-r--r--src/e_mod_main.h3
-rw-r--r--src/magnify.c157
4 files changed, 163 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ae1affb..a3e5990 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ module_la_SOURCES = e_mod_main.h \
16 moveresize.c \ 16 moveresize.c \
17 pip.c \ 17 pip.c \
18 zoom.c \ 18 zoom.c \
19 magnify.c \
19 desksanity.c 20 desksanity.c
20 21
21module_la_LIBADD = @E_LIBS@ 22module_la_LIBADD = @E_LIBS@
diff --git a/src/e_mod_main.c b/src/e_mod_main.c
index a50adeb..57e4a76 100644
--- a/src/e_mod_main.c
+++ b/src/e_mod_main.c
@@ -85,6 +85,7 @@ e_modapi_init(E_Module *m)
85 85
86 pip_init(); 86 pip_init();
87 zoom_init(); 87 zoom_init();
88 mag_init();
88 89
89 return m; 90 return m;
90} 91}
@@ -92,6 +93,7 @@ e_modapi_init(E_Module *m)
92EAPI int 93EAPI int
93e_modapi_shutdown(E_Module *m EINA_UNUSED) 94e_modapi_shutdown(E_Module *m EINA_UNUSED)
94{ 95{
96 mag_shutdown();
95 zoom_shutdown(); 97 zoom_shutdown();
96 pip_shutdown(); 98 pip_shutdown();
97 if (!ds_config->disable_maximize) 99 if (!ds_config->disable_maximize)
diff --git a/src/e_mod_main.h b/src/e_mod_main.h
index 09d1744..8db856a 100644
--- a/src/e_mod_main.h
+++ b/src/e_mod_main.h
@@ -103,4 +103,7 @@ EINTERN void ds_config_shutdown(void);
103 103
104EINTERN void zoom_init(void); 104EINTERN void zoom_init(void);
105EINTERN void zoom_shutdown(void); 105EINTERN void zoom_shutdown(void);
106
107EINTERN void mag_init(void);
108EINTERN void mag_shutdown(void);
106#endif 109#endif
diff --git a/src/magnify.c b/src/magnify.c
new file mode 100644
index 0000000..7dd0789
--- /dev/null
+++ b/src/magnify.c
@@ -0,0 +1,157 @@
1#include "e_mod_main.h"
2
3static E_Action *act_magnify = NULL;
4static int current_mag = -1;
5static Evas_Object **magnifiers = {NULL};
6static Evas_Object *clip = NULL;
7
8static Ecore_Event_Handler *handler = NULL;
9static Ecore_Event_Handler *deskflip = NULL;
10static Ecore_Timer *timer = NULL;
11
12#define MAG_SIZE_FACTOR 10
13
14static void
15_magnify_end(void)
16{
17 unsigned int n;
18 E_Comp *comp;
19
20 if (!magnifiers) return;
21 comp = e_comp_get(NULL);
22 for (n = 0; n < eina_list_count(comp->zones); n++)
23 E_FREE_FUNC(magnifiers[n], evas_object_del);
24 E_FREE(magnifiers);
25 E_FREE_FUNC(clip, evas_object_del);
26 E_FREE_FUNC(handler, ecore_event_handler_del);
27 E_FREE_FUNC(timer, ecore_timer_del);
28 current_mag = -1;
29}
30
31static void
32_current_update(int n)
33{
34 if (current_mag != -1)
35 efx_zoom_reset(magnifiers[current_mag]);
36 current_mag = n;
37}
38
39static void
40_magnify_update(int x, int y)
41{
42 int w, h;
43 E_Zone *zone;
44
45 zone = e_comp_zone_xy_get(e_comp_get(NULL), x, y);
46 if ((int)zone->num != current_mag)
47 _current_update(zone->num);
48
49 w = zone->w / MAG_SIZE_FACTOR;
50 h = zone->h / MAG_SIZE_FACTOR;
51 evas_object_geometry_set(clip, x - (w / 2), y - (h / 2), w, h);
52 efx_zoom(magnifiers[zone->num], EFX_EFFECT_SPEED_LINEAR, 0, 2.0, EFX_POINT(x, y), 0, NULL, NULL);
53}
54
55static Eina_Bool
56_magnify_move(void *data EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Move *ev)
57{
58 _magnify_update(ev->root.x, ev->root.y);
59 return ECORE_CALLBACK_RENEW;
60}
61
62static Eina_Bool
63_magnify_poll(void *d EINA_UNUSED)
64{
65 int x, y;
66
67 ecore_evas_pointer_xy_get(e_comp_get(NULL)->ee, &x, &y);
68 _magnify_update(x, y);
69 return ECORE_CALLBACK_RENEW;
70}
71
72static void
73_magnify_new(E_Desk *desk)
74{
75 int n = desk->zone->num;
76
77 magnifiers[n] = e_deskmirror_add(desk, 0, 0);
78 evas_object_pass_events_set(magnifiers[n], 1);
79 evas_object_data_set(magnifiers[n], "comp_skip", (void*)1);
80 evas_object_geometry_set(magnifiers[n], desk->zone->x, desk->zone->y, desk->zone->w, desk->zone->h);
81 evas_object_layer_set(magnifiers[n], E_LAYER_MENU + 1);
82 evas_object_show(magnifiers[n]);
83
84 evas_object_clip_set(magnifiers[n], clip);
85}
86
87static void
88_magnify_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
89{
90 E_Comp *comp;
91 E_Zone *zone;
92 unsigned int n;
93 int x, y, w, h;
94 Eina_List *l;
95
96 comp = e_comp_get(NULL);
97 if (magnifiers)
98 {
99 _magnify_end();
100 return;
101 }
102
103 clip = evas_object_rectangle_add(comp->evas);
104 evas_object_show(clip);
105 ecore_evas_pointer_xy_get(comp->ee, &x, &y);
106 magnifiers = malloc(sizeof(void*) * eina_list_count(comp->zones));
107 for (n = 0, l = comp->zones, zone = eina_list_data_get(l);
108 n < eina_list_count(comp->zones);
109 n++, l = eina_list_next(l), zone = eina_list_data_get(l))
110 {
111 _magnify_new(e_desk_current_get(zone));
112
113 evas_object_clip_set(magnifiers[n], clip);
114 if (zone != e_zone_current_get(comp)) continue;
115 w = zone->w / MAG_SIZE_FACTOR;
116 h = zone->h / MAG_SIZE_FACTOR;
117 evas_object_geometry_set(clip, x - (w / 2), y - (h / 2), w, h);
118 _current_update(n);
119 }
120 if (comp->comp_type == E_PIXMAP_TYPE_X)
121 timer = ecore_timer_add(0.05, _magnify_poll, NULL);
122 else
123 handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, (Ecore_Event_Handler_Cb)_magnify_move, NULL);
124}
125
126static Eina_Bool
127_magnify_deskflip(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Desk_Show *ev)
128{
129 if (!magnifiers) return ECORE_CALLBACK_RENEW;
130 evas_object_del(magnifiers[ev->desk->zone->num]);
131 _magnify_new(ev->desk);
132 _current_update(ev->desk->zone->num);
133 return ECORE_CALLBACK_RENEW;
134}
135
136EINTERN void
137mag_init(void)
138{
139 act_magnify = e_action_add("magnify");
140 if (act_magnify)
141 {
142 act_magnify->func.go = _magnify_cb;
143 e_action_predef_name_set(D_("Compositor"), D_("Toggle magnification"),
144 "magnify", NULL, NULL, 0);
145 }
146 deskflip = ecore_event_handler_add(E_EVENT_DESK_SHOW, (Ecore_Event_Handler_Cb)_magnify_deskflip, NULL);
147}
148
149EINTERN void
150mag_shutdown(void)
151{
152 _magnify_end();
153 e_action_predef_name_del(D_("Compositor"), D_("Toggle magnification"));
154 e_action_del("magnify");
155 act_magnify = NULL;
156 E_FREE_FUNC(deskflip, ecore_event_handler_del);
157}