summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-07-03 15:25:19 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-07-03 15:25:19 +0000
commit2f57d0c7a9d3fb84faaabe8c551ae72fb9ca0c85 (patch)
treef767aa58c04784b5d74ee4b31184f0915478c1c8 /src/bin
parent9b476039cf9d6cc1ccdc7b6fb0fbbf3c8b4becae (diff)
add to READMe and... add logic to find urls under the mouse. also
email addresses. seems to work well imho. :) SVN revision: 73243
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/termio.c199
1 files changed, 199 insertions, 0 deletions
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 4633e2d..3813b69 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -35,6 +35,9 @@ struct _Termio
35 Eina_Bool makesel : 1; 35 Eina_Bool makesel : 1;
36 } cur; 36 } cur;
37 struct { 37 struct {
38 int cx, cy;
39 } mouse;
40 struct {
38 struct { 41 struct {
39 int x, y; 42 int x, y;
40 } sel1, sel2; 43 } sel1, sel2;
@@ -48,6 +51,7 @@ struct _Termio
48 Termpty *pty; 51 Termpty *pty;
49 Ecore_Animator *anim; 52 Ecore_Animator *anim;
50 Ecore_Timer *delayed_size_timer; 53 Ecore_Timer *delayed_size_timer;
54 Ecore_Job *mouse_move_job;
51 Evas_Object *win; 55 Evas_Object *win;
52 Config *config; 56 Config *config;
53 Ecore_IMF_Context *imf; 57 Ecore_IMF_Context *imf;
@@ -62,6 +66,179 @@ static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
62 66
63static void _smart_calculate(Evas_Object *obj); 67static void _smart_calculate(Evas_Object *obj);
64 68
69static Eina_Bool
70coord_back(Termio *sd, int *x, int *y)
71{
72 (*x)--;
73 if ((*x) < 0)
74 {
75 if ((*y) <= 0)
76 {
77 (*x)++;
78 return EINA_FALSE;
79 }
80 (*x) = sd->grid.w - 1;
81 (*y)--;
82 }
83 return EINA_TRUE;
84}
85
86static Eina_Bool
87coord_forward(Termio *sd, int *x, int *y)
88{
89 (*x)++;
90 if ((*x) >= sd->grid.w)
91 {
92 if ((*y) >= (sd->grid.h - 1))
93 {
94 (*x)--;
95 return EINA_FALSE;
96 }
97 (*x) = 0;
98 (*y)++;
99 }
100 return EINA_TRUE;
101}
102
103static void
104_smart_mouseover_apply(Evas_Object *obj)
105{
106 Termio *sd = evas_object_smart_data_get(obj);
107 char *s;
108 char endmatch = 0;
109 int x1, x2, y1, y2, len;
110 Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, extend = EINA_FALSE;
111
112 if (!sd) return;
113 x1 = sd->mouse.cx;
114 y1 = sd->mouse.cy;
115 x2 = sd->mouse.cx;
116 y2 = sd->mouse.cy;
117 if (!coord_back(sd, &x1, &y1)) goback = EINA_FALSE;
118 for (;;)
119 {
120 s = termio_selection_get(obj,
121 x1, y1 - sd->scroll,
122 x2, y2 - sd->scroll);
123 if (!s) break;
124 if (goback)
125 {
126 if ((!strncasecmp(s, "http://", 7))||
127 (!strncasecmp(s, "https://", 8)) ||
128 (!strncasecmp(s, "ftp://", 6)))
129 {
130 goback = EINA_FALSE;
131 coord_back(sd, &x1, &y1);
132 free(s);
133 s = termio_selection_get(obj,
134 x1, y1 - sd->scroll,
135 x2, y2 - sd->scroll);
136 if (!s) break;
137 if (s[0] == '"') endmatch = '"';
138 else if (s[0] == '\'') endmatch = '\'';
139 else if (s[0] == '<') endmatch = '>';
140 coord_forward(sd, &x1, &y1);
141 free(s);
142 s = termio_selection_get(obj,
143 x1, y1 - sd->scroll,
144 x2, y2 - sd->scroll);
145 if (!s) break;
146 }
147 else if ((isspace(s[0])) ||
148 (s[0] == '"') ||
149 (s[0] == '\'') ||
150 (s[0] == '<') ||
151 (s[0] == '='))
152 {
153 if (s[0] == '"') endmatch = '"';
154 else if (s[0] == '\'') endmatch = '\'';
155 else if (s[0] == '<') endmatch = '>';
156 if ((!strncasecmp((s + 1), "www.", 4)) ||
157 (!strncasecmp((s + 1), "ftp.", 4)))
158 {
159 goback = EINA_FALSE;
160 coord_forward(sd, &x1, &y1);
161 }
162 else if (strchr((s + 2), '@'))
163 {
164 goback = EINA_FALSE;
165 coord_forward(sd, &x1, &y1);
166 }
167 else
168 {
169 free(s);
170 s = NULL;
171 break;
172 }
173 }
174 }
175 if (goforward)
176 {
177 len = strlen(s);
178 if (len > 1)
179 {
180 if (((endmatch) && (s[len - 1] == endmatch)) ||
181 ((!endmatch) && (isspace(s[len - 1]))))
182 {
183 goforward = EINA_FALSE;
184 coord_back(sd, &x2, &y2);
185 }
186 }
187 }
188
189 if (goforward)
190 {
191 if (!coord_forward(sd, &x2, &y2)) goforward = EINA_FALSE;
192 }
193 if (goback)
194 {
195 if (!coord_back(sd, &x1, &y1)) goback = EINA_FALSE;
196 }
197 else if (!extend)
198 {
199 goforward = EINA_TRUE;
200 extend = EINA_TRUE;
201 }
202 if ((!goback) && (!goforward))
203 {
204 free(s);
205 s = termio_selection_get(obj,
206 x1, y1 - sd->scroll,
207 x2, y2 - sd->scroll);
208 break;
209 }
210 free(s);
211 s = NULL;
212 }
213 if (s)
214 {
215 len = strlen(s);
216 while (len > 1)
217 {
218 if (isspace(s[len - 1]))
219 {
220 s[len - 1] = 0;
221 len--;
222 }
223 else break;
224 }
225 if (!isspace(s[0]))
226 {
227 if ((strchr(s, '@')) ||
228 (!strncasecmp(s, "http://", 7))||
229 (!strncasecmp(s, "https://", 8)) ||
230 (!strncasecmp(s, "ftp://", 6)) ||
231 (!strncasecmp(s, "www.", 4)) ||
232 (!strncasecmp(s, "ftp.", 4)))
233 {
234 printf("FOUND: '%s' @ %i,%i -> %i,%i\n", s, x1, y1, x2, y2);
235 // XXX: record coords and url string
236 }
237 }
238 free(s);
239 }
240}
241
65static void 242static void
66_smart_apply(Evas_Object *obj) 243_smart_apply(Evas_Object *obj)
67{ 244{
@@ -288,6 +465,7 @@ _smart_apply(Evas_Object *obj)
288 evas_object_hide(sd->cur.selo2); 465 evas_object_hide(sd->cur.selo2);
289 evas_object_hide(sd->cur.selo3); 466 evas_object_hide(sd->cur.selo3);
290 } 467 }
468 _smart_mouseover_apply(obj);
291} 469}
292 470
293static void 471static void
@@ -1073,6 +1251,17 @@ _selection_dbl_fix(Evas_Object *obj)
1073} 1251}
1074 1252
1075static void 1253static void
1254_smart_cb_mouse_move_job(void *data)
1255{
1256 Termio *sd;
1257
1258 sd = evas_object_smart_data_get(data);
1259 if (!sd) return;
1260 sd->mouse_move_job = NULL;
1261 _smart_mouseover_apply(data);
1262}
1263
1264static void
1076_smart_cb_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event) 1265_smart_cb_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
1077{ 1266{
1078 Evas_Event_Mouse_Down *ev = event; 1267 Evas_Event_Mouse_Down *ev = event;
@@ -1162,10 +1351,14 @@ _smart_cb_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__
1162 Evas_Event_Mouse_Move *ev = event; 1351 Evas_Event_Mouse_Move *ev = event;
1163 Termio *sd; 1352 Termio *sd;
1164 int cx, cy; 1353 int cx, cy;
1354 Eina_Bool mc_change = EINA_FALSE;
1165 1355
1166 sd = evas_object_smart_data_get(data); 1356 sd = evas_object_smart_data_get(data);
1167 if (!sd) return; 1357 if (!sd) return;
1168 _smart_xy_to_cursor(data, ev->cur.canvas.x, ev->cur.canvas.y, &cx, &cy); 1358 _smart_xy_to_cursor(data, ev->cur.canvas.x, ev->cur.canvas.y, &cx, &cy);
1359 if ((sd->mouse.cx != cx) || (sd->mouse.cy != cy)) mc_change = EINA_TRUE;
1360 sd->mouse.cx = cx;
1361 sd->mouse.cy = cy;
1169 _rep_mouse_move(data, ev, cx, cy); 1362 _rep_mouse_move(data, ev, cx, cy);
1170 if (sd->cur.makesel) 1363 if (sd->cur.makesel)
1171 { 1364 {
@@ -1180,6 +1373,11 @@ _smart_cb_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__
1180 _selection_dbl_fix(data); 1373 _selection_dbl_fix(data);
1181 _smart_update_queue(data, sd); 1374 _smart_update_queue(data, sd);
1182 } 1375 }
1376 if (mc_change)
1377 {
1378 if (sd->mouse_move_job) ecore_job_del(sd->mouse_move_job);
1379 sd->mouse_move_job = ecore_job_add(_smart_cb_mouse_move_job, data);
1380 }
1183} 1381}
1184 1382
1185static void 1383static void
@@ -1516,6 +1714,7 @@ _smart_del(Evas_Object *obj)
1516 if (sd->cur.selo3) evas_object_del(sd->cur.selo3); 1714 if (sd->cur.selo3) evas_object_del(sd->cur.selo3);
1517 if (sd->anim) ecore_animator_del(sd->anim); 1715 if (sd->anim) ecore_animator_del(sd->anim);
1518 if (sd->delayed_size_timer) ecore_timer_del(sd->delayed_size_timer); 1716 if (sd->delayed_size_timer) ecore_timer_del(sd->delayed_size_timer);
1717 if (sd->mouse_move_job) ecore_job_del(sd->mouse_move_job);
1519 if (sd->font.name) eina_stringshare_del(sd->font.name); 1718 if (sd->font.name) eina_stringshare_del(sd->font.name);
1520 if (sd->pty) termpty_free(sd->pty); 1719 if (sd->pty) termpty_free(sd->pty);
1521 EINA_LIST_FREE(sd->seq, str) eina_stringshare_del(str); 1720 EINA_LIST_FREE(sd->seq, str) eina_stringshare_del(str);