summaryrefslogtreecommitdiff
path: root/src/bin/controls.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-01-02 00:09:14 +0100
committerBoris Faure <billiob@gmail.com>2018-01-05 00:27:25 +0100
commiteaaae01745d05f5b4d2b4c3b80b8d1f5a01305e4 (patch)
treea7db66b015f82ba933e8bff00f80bae7ab351712 /src/bin/controls.c
parent080ff8e261e4ed94485f17ece87762812b28c9d4 (diff)
controls: less globals, controls per window
Diffstat (limited to 'src/bin/controls.c')
-rw-r--r--src/bin/controls.c244
1 files changed, 151 insertions, 93 deletions
diff --git a/src/bin/controls.c b/src/bin/controls.c
index f6a01ad..d16e29e 100644
--- a/src/bin/controls.c
+++ b/src/bin/controls.c
@@ -8,31 +8,42 @@
8#include "termio.h" 8#include "termio.h"
9#include "main.h" 9#include "main.h"
10 10
11static Evas_Object *ct_frame = NULL, *ct_boxh = NULL, *ct_boxv = NULL; 11static Eina_Hash *controls = NULL;
12static Evas_Object *ct_box = NULL, *ct_box2 = NULL, *ct_box3 = NULL, *ct_over = NULL; 12
13static Evas_Object *ct_win = NULL, *ct_bg = NULL, *ct_term = NULL; 13struct controls_ctx {
14static void (*ct_donecb) (void *data) = NULL; 14 Evas_Object *frame;
15static void *ct_donedata = NULL; 15 Evas_Object *over;
16 Evas_Object *win;
17 Evas_Object *bg;
18 Evas_Object *term;
19 void (*donecb) (void *data);
20 void *donedata;
21};
22
16 23
17static void 24static void
18controls_hide(Eina_Bool call_cb); 25controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb);
26
27
19 28
20static void 29static void
21_cb_sel_on(void *_data EINA_UNUSED, 30_cb_sel_on(void *data,
22 Evas_Object *_term EINA_UNUSED, 31 Evas_Object *_term EINA_UNUSED,
23 void *_ev EINA_UNUSED) 32 void *_ev EINA_UNUSED)
24{ 33{
25 Evas_Object *bt_copy = evas_object_data_get(ct_frame, "bt_copy"); 34 struct controls_ctx *ctx = data;
35 Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy");
26 if (bt_copy) 36 if (bt_copy)
27 elm_object_disabled_set(bt_copy, EINA_FALSE); 37 elm_object_disabled_set(bt_copy, EINA_FALSE);
28} 38}
29 39
30static void 40static void
31_cb_sel_off(void *_data EINA_UNUSED, 41_cb_sel_off(void *data,
32 Evas_Object *_term EINA_UNUSED, 42 Evas_Object *_term EINA_UNUSED,
33 void *_ev EINA_UNUSED) 43 void *_ev EINA_UNUSED)
34{ 44{
35 Evas_Object *bt_copy = evas_object_data_get(ct_frame, "bt_copy"); 45 struct controls_ctx *ctx = data;
46 Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy");
36 if (bt_copy) 47 if (bt_copy)
37 elm_object_disabled_set(bt_copy, EINA_TRUE); 48 elm_object_disabled_set(bt_copy, EINA_TRUE);
38} 49}
@@ -47,112 +58,136 @@ _cb_ct_del_delay(void *data)
47} 58}
48 59
49static void 60static void
50_cb_ct_copy(void *_data EINA_UNUSED, 61_cb_ct_copy(void *data,
51 Evas_Object *_obj EINA_UNUSED, 62 Evas_Object *_obj EINA_UNUSED,
52 void *_event EINA_UNUSED) 63 void *_event EINA_UNUSED)
53{ 64{
54 controls_hide(EINA_TRUE); 65 struct controls_ctx *ctx = data;
55 termio_take_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); 66 Evas_Object *term = ctx->term;
67
68 controls_hide(ctx, EINA_TRUE);
69 termio_take_selection(term, ELM_SEL_TYPE_CLIPBOARD);
56} 70}
57 71
58static void 72static void
59_cb_ct_paste(void *_data EINA_UNUSED, 73_cb_ct_paste(void *data,
60 Evas_Object *_obj EINA_UNUSED, 74 Evas_Object *_obj EINA_UNUSED,
61 void *_event EINA_UNUSED) 75 void *_event EINA_UNUSED)
62{ 76{
63 controls_hide(EINA_TRUE); 77 struct controls_ctx *ctx = data;
64 termio_paste_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); 78 Evas_Object *term = ctx->term;
79
80 controls_hide(ctx, EINA_TRUE);
81 termio_paste_selection(term, ELM_SEL_TYPE_CLIPBOARD);
65} 82}
66 83
67static void 84static void
68_cb_ct_new(void *_data EINA_UNUSED, 85_cb_ct_new(void *data,
69 Evas_Object *_obj EINA_UNUSED, 86 Evas_Object *_obj EINA_UNUSED,
70 void *_event EINA_UNUSED) 87 void *_event EINA_UNUSED)
71{ 88{
72 main_new(ct_win, ct_term); 89 struct controls_ctx *ctx = data;
90 main_new(ctx->win, ctx->term);
73} 91}
74 92
75static void 93static void
76_cb_ct_split_v(void *_data EINA_UNUSED, 94_cb_ct_split_v(void *data,
77 Evas_Object *_obj EINA_UNUSED, 95 Evas_Object *_obj EINA_UNUSED,
78 void *_event EINA_UNUSED) 96 void *_event EINA_UNUSED)
79{ 97{
80 split_vertically(ct_win, ct_term, NULL); 98 struct controls_ctx *ctx = data;
99 split_vertically(ctx->win, ctx->term, NULL);
81} 100}
82 101
83static void 102static void
84_cb_ct_split_h(void *_data EINA_UNUSED, 103_cb_ct_split_h(void *data,
85 Evas_Object *_obj EINA_UNUSED, 104 Evas_Object *_obj EINA_UNUSED,
86 void *_event EINA_UNUSED) 105 void *_event EINA_UNUSED)
87{ 106{
88 split_horizontally(ct_win, ct_term, NULL); 107 struct controls_ctx *ctx = data;
108 split_horizontally(ctx->win, ctx->term, NULL);
89} 109}
90 110
91static void 111static void
92_cb_ct_miniview(void *_data EINA_UNUSED, 112_cb_ct_miniview(void *data,
93 Evas_Object *_obj EINA_UNUSED, 113 Evas_Object *_obj EINA_UNUSED,
94 void *_event EINA_UNUSED) 114 void *_event EINA_UNUSED)
95{ 115{
96 term_miniview_toggle(termio_term_get(ct_term)); 116 struct controls_ctx *ctx = data;
117 term_miniview_toggle(termio_term_get(ctx->term));
97} 118}
98 119
99static void 120static void
100_cb_ct_set_title(void *_data EINA_UNUSED, 121_cb_ct_set_title(void *data,
101 Evas_Object *_obj EINA_UNUSED, 122 Evas_Object *_obj EINA_UNUSED,
102 void *_event EINA_UNUSED) 123 void *_event EINA_UNUSED)
103{ 124{
104 controls_hide(EINA_TRUE); 125 struct controls_ctx *ctx = data;
105 term_set_title(termio_term_get(ct_term)); 126 Evas_Object *term = ctx->term;
127 controls_hide(ctx, EINA_TRUE);
128 term_set_title(termio_term_get(term));
106} 129}
107 130
108static void 131static void
109_cb_ct_close(void *_data EINA_UNUSED, 132_cb_ct_close(void *data,
110 Evas_Object *_obj EINA_UNUSED, 133 Evas_Object *_obj EINA_UNUSED,
111 void *_event EINA_UNUSED) 134 void *_event EINA_UNUSED)
112{ 135{
113 controls_hide(EINA_TRUE); 136 struct controls_ctx *ctx = data;
114 term_close(ct_win, ct_term, EINA_FALSE); 137 Evas_Object *term = ctx->term;
138 Evas_Object *win = ctx->win;
139
140 controls_hide(ctx, EINA_TRUE);
141 term_close(win, term, EINA_FALSE);
115} 142}
116 143
117static void 144static void
118_cb_ct_options(void *_data EINA_UNUSED, 145_cb_ct_options(void *data,
119 Evas_Object *_obj EINA_UNUSED, 146 Evas_Object *_obj EINA_UNUSED,
120 void *_event EINA_UNUSED) 147 void *_event EINA_UNUSED)
121{ 148{
122 controls_hide(EINA_FALSE); 149 struct controls_ctx *ctx = data;
123 options_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); 150
151 options_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata);
152 controls_hide(ctx, EINA_FALSE);
124} 153}
125 154
126static void 155static void
127_cb_ct_about(void *_data EINA_UNUSED, 156_cb_ct_about(void *data,
128 Evas_Object *_obj EINA_UNUSED, 157 Evas_Object *_obj EINA_UNUSED,
129 void *_event EINA_UNUSED) 158 void *_event EINA_UNUSED)
130{ 159{
131 controls_hide(EINA_FALSE); 160 struct controls_ctx *ctx = data;
132 about_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); 161
162 about_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata);
163 controls_hide(ctx, EINA_FALSE);
133} 164}
134 165
135static void 166static void
136_cb_mouse_down(void *_data EINA_UNUSED, 167_cb_mouse_down(void *data,
137 Evas *_e EINA_UNUSED, 168 Evas *_e EINA_UNUSED,
138 Evas_Object *_obj EINA_UNUSED, 169 Evas_Object *_obj EINA_UNUSED,
139 void *_ev EINA_UNUSED) 170 void *_ev EINA_UNUSED)
140{ 171{
141 controls_hide(EINA_TRUE); 172 struct controls_ctx *ctx = data;
173
174 controls_hide(ctx, EINA_TRUE);
142} 175}
143 176
144static void 177static void
145_cb_saved_del(void *data, 178_cb_saved_del(void *data,
146 Evas *_e EINA_UNUSED, 179 Evas *_e EINA_UNUSED,
147 Evas_Object *obj EINA_UNUSED, 180 Evas_Object *obj,
148 void *_ev EINA_UNUSED) 181 void *_ev EINA_UNUSED)
149{ 182{
150 if (data == ct_win) 183 struct controls_ctx *ctx = data;
151 ct_win = NULL;
152 else if (data == ct_term)
153 ct_term = NULL;
154 184
155 controls_hide(EINA_FALSE); 185 if (obj == ctx->win)
186 ctx->win = NULL;
187 else if (obj == ctx->term)
188 ctx->term = NULL;
189
190 controls_hide(ctx, EINA_FALSE);
156} 191}
157 192
158static Evas_Object * 193static Evas_Object *
@@ -204,61 +239,71 @@ _sep_add_h(Evas_Object *win)
204} 239}
205 240
206static void 241static void
207controls_hide(Eina_Bool call_cb) 242controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb)
208{ 243{
209 if (!ct_frame) 244 if (ctx->win)
210 return;
211
212 if (ct_win)
213 { 245 {
214 evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del); 246 evas_object_event_callback_del(ctx->win, EVAS_CALLBACK_DEL, _cb_saved_del);
215 evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on); 247 evas_object_smart_callback_del(ctx->win, "selection,on", _cb_sel_on);
216 evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off); 248 evas_object_smart_callback_del(ctx->win, "selection,off", _cb_sel_off);
217 } 249 }
218 if (ct_term) 250 if (ctx->term)
219 { 251 {
220 evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del); 252 evas_object_event_callback_del(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del);
253 edje_object_signal_emit(ctx->bg, "controls,hide", "terminology");
221 } 254 }
222 255
223 if (ct_over) 256 if (ctx->over)
224 { 257 {
225 evas_object_del(ct_over); 258 evas_object_del(ctx->over);
226 } 259 }
227 ct_over = NULL; 260 elm_object_focus_set(ctx->frame, EINA_FALSE);
228 edje_object_signal_emit(ct_bg, "controls,hide", "terminology"); 261
229 elm_object_focus_set(ct_frame, EINA_FALSE); 262 ecore_timer_add(10.0, _cb_ct_del_delay, ctx->frame);
263 ctx->frame = NULL;
230 264
231 ecore_timer_add(10.0, _cb_ct_del_delay, ct_frame); 265 if (call_cb && ctx->donecb)
232 ct_frame = NULL; 266 ctx->donecb(ctx->donedata);
233 267
234 ct_win = NULL; 268 eina_hash_del(controls, &ctx->win, ctx);
235 269
236 if (call_cb && ct_donecb) 270 free(ctx);
237 ct_donecb(ct_donedata);
238 ct_donecb = NULL;
239 ct_donedata = NULL;
240} 271}
241 272
273
242void 274void
243controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, 275controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
244 void (*donecb) (void *data), void *donedata) 276 void (*donecb) (void *data), void *donedata)
245{ 277{
246 Evas_Object *o; 278 Evas_Object *o;
279 Evas_Object *ct_boxh, *ct_boxv, *ct_box, *ct_box2, *ct_box3;
280 struct controls_ctx *ctx;
247 281
248 if ((options_is_active()) || (ct_win && win != ct_win) || (ct_frame)) 282 if (eina_hash_find(controls, &win))
249 { 283 {
250 donecb(donedata); 284 donecb(donedata);
251 return; 285 return;
252 } 286 }
253 287
254 ct_frame = o = elm_frame_add(win); 288
289 ctx = malloc(sizeof(*ctx));
290 assert(ctx);
291 ctx->win = win;
292 ctx->bg = bg;
293 ctx->term = term;
294 ctx->donecb = donecb;
295 ctx->donedata = donedata;
296
297 eina_hash_add(controls, &win, ctx);
298
299 ctx->frame = o = elm_frame_add(win);
255 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 300 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
256 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 301 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
257 elm_object_text_set(o, _("Controls")); 302 elm_object_text_set(o, _("Controls"));
258 303
259 ct_boxv = o = elm_box_add(win); 304 ct_boxv = o = elm_box_add(win);
260 elm_box_horizontal_set(o, EINA_FALSE); 305 elm_box_horizontal_set(o, EINA_FALSE);
261 elm_object_content_set(ct_frame, o); 306 elm_object_content_set(ctx->frame, o);
262 evas_object_show(o); 307 evas_object_show(o);
263 308
264 ct_boxh = o = elm_box_add(win); 309 ct_boxh = o = elm_box_add(win);
@@ -270,27 +315,32 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
270 elm_box_pack_end(ct_boxh, o); 315 elm_box_pack_end(ct_boxh, o);
271 evas_object_show(o); 316 evas_object_show(o);
272 317
273 o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL); 318 o = _button_add(win, _("New"), "window-new",
319 _cb_ct_new, ctx);
274 elm_box_pack_end(ct_box, o); 320 elm_box_pack_end(ct_box, o);
275 321
276 o = _sep_add_h(win); 322 o = _sep_add_h(win);
277 elm_box_pack_end(ct_box, o); 323 elm_box_pack_end(ct_box, o);
278 324
279 o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL); 325 o = _button_add(win, _("Split V"), "object-flip-vertical",
326 _cb_ct_split_v, ctx);
280 elm_box_pack_end(ct_box, o); 327 elm_box_pack_end(ct_box, o);
281 o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL); 328 o = _button_add(win, _("Split H"), "object-flip-horizontal",
329 _cb_ct_split_h, ctx);
282 elm_box_pack_end(ct_box, o); 330 elm_box_pack_end(ct_box, o);
283 331
284 o = _sep_add_h(win); 332 o = _sep_add_h(win);
285 elm_box_pack_end(ct_box, o); 333 elm_box_pack_end(ct_box, o);
286 334
287 o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL); 335 o = _button_add(win, _("Miniview"), "view-restore",
336 _cb_ct_miniview, ctx);
288 elm_box_pack_end(ct_box, o); 337 elm_box_pack_end(ct_box, o);
289 338
290 o = _sep_add_h(win); 339 o = _sep_add_h(win);
291 elm_box_pack_end(ct_box, o); 340 elm_box_pack_end(ct_box, o);
292 341
293 o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL); 342 o = _button_add(win, _("Set title"), "format-text-underline",
343 _cb_ct_set_title, ctx);
294 elm_box_pack_end(ct_box, o); 344 elm_box_pack_end(ct_box, o);
295 345
296 o = _sep_add_v(win); 346 o = _sep_add_v(win);
@@ -300,25 +350,25 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
300 elm_box_pack_end(ct_boxh, o); 350 elm_box_pack_end(ct_boxh, o);
301 evas_object_show(o); 351 evas_object_show(o);
302 352
303 o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL); 353 o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, ctx);
304 evas_object_data_set(ct_frame, "bt_copy", o); 354 evas_object_data_set(ctx->frame, "bt_copy", o);
305 if (!termio_selection_exists(term)) 355 if (!termio_selection_exists(term))
306 elm_object_disabled_set(o, EINA_TRUE); 356 elm_object_disabled_set(o, EINA_TRUE);
307 elm_box_pack_end(ct_box2, o); 357 elm_box_pack_end(ct_box2, o);
308 358
309 o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL); 359 o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, ctx);
310 elm_box_pack_end(ct_box2, o); 360 elm_box_pack_end(ct_box2, o);
311 361
312 o = _sep_add_h(win); 362 o = _sep_add_h(win);
313 elm_box_pack_end(ct_box2, o); 363 elm_box_pack_end(ct_box2, o);
314 364
315 o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL); 365 o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, ctx);
316 elm_box_pack_end(ct_box2, o); 366 elm_box_pack_end(ct_box2, o);
317 367
318 o = _sep_add_h(win); 368 o = _sep_add_h(win);
319 elm_box_pack_end(ct_box2, o); 369 elm_box_pack_end(ct_box2, o);
320 370
321 o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL); 371 o = _button_add(win, _("About"), "help-about", _cb_ct_about, ctx);
322 elm_box_pack_end(ct_box2, o); 372 elm_box_pack_end(ct_box2, o);
323 373
324 o = _sep_add_h(win); 374 o = _sep_add_h(win);
@@ -332,26 +382,34 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
332 elm_box_pack_end(ct_box3, o); 382 elm_box_pack_end(ct_box3, o);
333 383
334 evas_object_smart_callback_add(win, "selection,on", _cb_sel_on, 384 evas_object_smart_callback_add(win, "selection,on", _cb_sel_on,
335 NULL); 385 ctx);
336 evas_object_smart_callback_add(win, "selection,off", _cb_sel_off, 386 evas_object_smart_callback_add(win, "selection,off", _cb_sel_off,
337 NULL); 387 ctx);
338 388
339 edje_object_part_swallow(bg, "terminology.controls", ct_frame); 389 edje_object_part_swallow(bg, "terminology.controls", ctx->frame);
340 evas_object_show(ct_frame); 390 evas_object_show(ctx->frame);
341 ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); 391 ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win));
342 evas_object_color_set(o, 0, 0, 0, 0); 392 evas_object_color_set(o, 0, 0, 0, 0);
343 edje_object_part_swallow(bg, "terminology.dismiss", o); 393 edje_object_part_swallow(bg, "terminology.dismiss", o);
344 evas_object_show(o); 394 evas_object_show(o);
345 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, 395 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
346 _cb_mouse_down, NULL); 396 _cb_mouse_down, ctx);
347 397
348 ct_win = win;
349 ct_bg = bg;
350 ct_term = term;
351 ct_donecb = donecb;
352 ct_donedata = donedata;
353 edje_object_signal_emit(bg, "controls,show", "terminology"); 398 edje_object_signal_emit(bg, "controls,show", "terminology");
354 elm_object_focus_set(ct_frame, EINA_TRUE); 399 elm_object_focus_set(ctx->frame, EINA_TRUE);
355 evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, ct_win); 400 evas_object_event_callback_add(ctx->win, EVAS_CALLBACK_DEL, _cb_saved_del, ctx);
356 evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, ct_term); 401 evas_object_event_callback_add(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del, ctx);
402}
403
404void
405controls_init(void)
406{
407 controls = eina_hash_pointer_new(NULL);
408}
409
410void
411controls_shutdown(void)
412{
413 eina_hash_free(controls);
414 controls = NULL;
357} 415}