summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-10-10 22:29:30 +0200
committerBoris Faure <billiob@gmail.com>2019-10-10 22:29:30 +0200
commit6b8e6f05169e976aa4931a57638546a3a36a38da (patch)
treea8e98625f49a4d0c5fba68da191e2232dd078736 /src
parente0fde8a9e225f094139b7c5f70092e6c0d2fab5b (diff)
win: reorganize code to have popup media fold
Diffstat (limited to 'src')
-rw-r--r--src/bin/win.c665
1 files changed, 334 insertions, 331 deletions
diff --git a/src/bin/win.c b/src/bin/win.c
index e7e3958..6ff4daa 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -4016,80 +4016,11 @@ _tabs_new(Term_Container *child, Term_Container *parent)
4016 4016
4017 4017
4018/* }}} */ 4018/* }}} */
4019/* {{{ Term */ 4019/* {{{ Popup Media */
4020 4020struct Pop_Media {
4021Eina_Bool 4021 const char *src;
4022term_is_visible(Term *term) 4022 Eina_Bool from_user_interaction;
4023{ 4023};
4024 Term_Container *tc;
4025
4026 if (!term)
4027 return EINA_FALSE;
4028
4029 tc = term->container;
4030 if (!tc)
4031 return EINA_FALSE;
4032
4033 return tc->is_visible(tc, tc);
4034}
4035
4036void
4037background_set_shine(Config *config, Evas_Object *bg)
4038{
4039 Edje_Message_Int msg;
4040
4041 if (config)
4042 msg.val = config->shine;
4043 else
4044 msg.val = 255;
4045
4046 if (bg)
4047 edje_object_message_send(bg, EDJE_MESSAGE_INT, 2, &msg);
4048}
4049
4050void
4051term_apply_shine(Term *term, int shine)
4052{
4053 Config *config = term->config;
4054
4055 if (config->shine != shine)
4056 {
4057 config->shine = shine;
4058 background_set_shine(config, term->bg);
4059 config_save(config);
4060 }
4061}
4062
4063
4064static void
4065_set_trans(Config *config, Evas_Object *bg, Evas_Object *base)
4066{
4067 Edje_Message_Int msg;
4068
4069 if (config && config->translucent)
4070 msg.val = config->opacity;
4071 else
4072 msg.val = 100;
4073
4074 if (bg)
4075 edje_object_message_send(bg, EDJE_MESSAGE_INT, 1, &msg);
4076 if (base) {
4077 Evas_Object *edje = elm_layout_edje_get(base);
4078 edje_object_message_send(edje, EDJE_MESSAGE_INT, 1, &msg);
4079 }
4080}
4081
4082static void
4083_term_config_set(Term *term, Config *config)
4084{
4085 Config *old_config = term->config;
4086
4087 term->config = config;
4088 termio_config_set(term->termio, config);
4089 _term_media_update(term, term->config);
4090 if (old_config != term->wn->config)
4091 config_del(old_config);
4092}
4093 4024
4094Eina_Bool 4025Eina_Bool
4095term_has_popmedia(const Term *term) 4026term_has_popmedia(const Term *term)
@@ -4104,181 +4035,6 @@ term_popmedia_close(Term *term)
4104 edje_object_signal_emit(term->bg, "popmedia,off", "terminology"); 4035 edje_object_signal_emit(term->bg, "popmedia,off", "terminology");
4105} 4036}
4106 4037
4107
4108Eina_Bool
4109term_is_focused(Term *term)
4110{
4111 Term_Container *tc;
4112
4113 if (!term)
4114 return EINA_FALSE;
4115
4116 tc = term->container;
4117 if (!tc)
4118 return EINA_FALSE;
4119
4120 DBG("tc:%p tc->is_focused:%d", tc, tc->is_focused);
4121 return tc->is_focused;
4122}
4123
4124void change_theme(Evas_Object *win, Config *config)
4125{
4126 const Eina_List *terms, *l;
4127 Term *term;
4128
4129 terms = terms_from_win_object(win);
4130 if (!terms) return;
4131
4132 EINA_LIST_FOREACH(terms, l, term)
4133 {
4134 Evas_Object *edje = term->bg;
4135
4136 if (!theme_apply(edje, config, "terminology/background"))
4137 ERR("Couldn't find terminology theme!");
4138 colors_term_init(termio_textgrid_get(term->termio), edje, config);
4139 termio_config_set(term->termio, config);
4140 }
4141
4142 l = elm_theme_overlay_list_get(NULL);
4143 if (l) l = eina_list_last(l);
4144 if (l) elm_theme_overlay_del(NULL, l->data);
4145 elm_theme_overlay_add(NULL, config_theme_path_get(config));
4146 main_trans_update(config);
4147}
4148
4149void
4150term_focus(Term *term)
4151{
4152 Term_Container *tc;
4153
4154 DBG("is focused? tc:%p", term->container);
4155 if (term_is_focused(term))
4156 return;
4157
4158 tc = term->container;
4159 DBG("tc:%p", tc);
4160 tc->focus(tc, tc);
4161}
4162
4163void
4164term_unfocus(Term *term)
4165{
4166 Term_Container *tc;
4167
4168 DBG("is focused? tc:%p", term->container);
4169 if (!term_is_focused(term))
4170 return;
4171
4172 tc = term->container;
4173 DBG("tc:%p", tc);
4174 tc->unfocus(tc, tc);
4175}
4176
4177enum term_to_direction {
4178 TERM_TO_PREV,
4179 TERM_TO_NEXT,
4180 TERM_TO_UP,
4181 TERM_TO_DOWN,
4182 TERM_TO_LEFT,
4183 TERM_TO_RIGHT,
4184};
4185
4186static void
4187term_go_to(Term *from, enum term_to_direction dir)
4188{
4189 Term *new_term, *focused_term;
4190 Win *wn = from->wn;
4191 Term_Container *tc;
4192
4193 tc = (Term_Container *) wn;
4194
4195 focused_term = tc->focused_term_get(tc);
4196 if (!focused_term)
4197 focused_term = from;
4198 tc = focused_term->container;
4199
4200 switch (dir)
4201 {
4202 case TERM_TO_PREV:
4203 new_term = tc->term_prev(tc, tc);
4204 break;
4205 case TERM_TO_NEXT:
4206 new_term = tc->term_next(tc, tc);
4207 break;
4208 case TERM_TO_UP:
4209 new_term = tc->term_up(tc, tc);
4210 break;
4211 case TERM_TO_DOWN:
4212 new_term = tc->term_down(tc, tc);
4213 break;
4214 case TERM_TO_LEFT:
4215 new_term = tc->term_left(tc, tc);
4216 break;
4217 case TERM_TO_RIGHT:
4218 new_term = tc->term_right(tc, tc);
4219 break;
4220 }
4221
4222 if (new_term && new_term != focused_term)
4223 term_focus(new_term);
4224
4225 /* TODO: get rid of it? */
4226 _term_miniview_check(from);
4227}
4228
4229void
4230term_prev(Term *term)
4231{
4232 term_go_to(term, TERM_TO_PREV);
4233}
4234
4235void
4236term_next(Term *term)
4237{
4238 term_go_to(term, TERM_TO_NEXT);
4239}
4240
4241void
4242term_up(Term *term)
4243{
4244 term_go_to(term, TERM_TO_UP);
4245}
4246
4247void
4248term_down(Term *term)
4249{
4250 term_go_to(term, TERM_TO_DOWN);
4251}
4252
4253void
4254term_left(Term *term)
4255{
4256 term_go_to(term, TERM_TO_LEFT);
4257}
4258
4259void
4260term_right(Term *term)
4261{
4262 term_go_to(term, TERM_TO_RIGHT);
4263}
4264
4265Term *
4266term_prev_get(const Term *term)
4267{
4268 Term_Container *tc = term->container;
4269
4270 return tc->term_prev(tc, tc);
4271}
4272
4273Term *
4274term_next_get(const Term *term)
4275{
4276 Term_Container *tc = term->container;
4277
4278 return tc->term_next(tc, tc);
4279}
4280
4281
4282static void 4038static void
4283_cb_popmedia_del(void *data, 4039_cb_popmedia_del(void *data,
4284 Evas *_e EINA_UNUSED, 4040 Evas *_e EINA_UNUSED,
@@ -4551,6 +4307,335 @@ error:
4551 } 4307 }
4552} 4308}
4553 4309
4310
4311
4312static void
4313_popmedia_queue_process(Term *term)
4314{
4315 struct Pop_Media *pm;
4316
4317 if (!term->popmedia_queue)
4318 return;
4319 pm = term->popmedia_queue->data;
4320 term->popmedia_queue = eina_list_remove_list(term->popmedia_queue,
4321 term->popmedia_queue);
4322 if (!pm)
4323 return;
4324 _popmedia(term, pm->src, pm->from_user_interaction);
4325 eina_stringshare_del(pm->src);
4326 free(pm);
4327}
4328
4329static void
4330_popmedia_queue_add(Term *term, const char *src,
4331 Eina_Bool from_user_interaction)
4332{
4333 struct Pop_Media *pm = calloc(1, sizeof(struct Pop_Media));
4334
4335 if (!pm)
4336 return;
4337
4338 pm->src = eina_stringshare_add(src);
4339 pm->from_user_interaction = from_user_interaction;
4340
4341 term->popmedia_queue = eina_list_append(term->popmedia_queue, pm);
4342 if (!term->popmedia)
4343 _popmedia_queue_process(term);
4344}
4345
4346static void
4347_cb_popup(void *data,
4348 Evas_Object *_obj EINA_UNUSED,
4349 void *event)
4350{
4351 Term *term = data;
4352 const char *src = event;
4353 Eina_Bool from_user_interaction = EINA_FALSE;
4354
4355 if (!src)
4356 {
4357 /* Popup a link, there was user interaction on it. */
4358 from_user_interaction = EINA_TRUE;
4359 src = termio_link_get(term->termio, NULL);
4360 }
4361 if (!src)
4362 return;
4363 _popmedia(term, src, from_user_interaction);
4364 if (!event)
4365 free((void*)src);
4366}
4367
4368static void
4369_cb_popup_queue(void *data,
4370 Evas_Object *_obj EINA_UNUSED,
4371 void *event)
4372{
4373 Term *term = data;
4374 const char *src = event;
4375 Eina_Bool from_user_interaction = EINA_FALSE;
4376
4377 if (!src)
4378 {
4379 from_user_interaction = EINA_TRUE;
4380 src = termio_link_get(term->termio, NULL);
4381 }
4382 if (!src)
4383 return;
4384 _popmedia_queue_add(term, src, from_user_interaction);
4385 if (!event)
4386 free((void*)src);
4387}
4388
4389/* }}} */
4390/* {{{ Term */
4391
4392Eina_Bool
4393term_is_visible(Term *term)
4394{
4395 Term_Container *tc;
4396
4397 if (!term)
4398 return EINA_FALSE;
4399
4400 tc = term->container;
4401 if (!tc)
4402 return EINA_FALSE;
4403
4404 return tc->is_visible(tc, tc);
4405}
4406
4407void
4408background_set_shine(Config *config, Evas_Object *bg)
4409{
4410 Edje_Message_Int msg;
4411
4412 if (config)
4413 msg.val = config->shine;
4414 else
4415 msg.val = 255;
4416
4417 if (bg)
4418 edje_object_message_send(bg, EDJE_MESSAGE_INT, 2, &msg);
4419}
4420
4421void
4422term_apply_shine(Term *term, int shine)
4423{
4424 Config *config = term->config;
4425
4426 if (config->shine != shine)
4427 {
4428 config->shine = shine;
4429 background_set_shine(config, term->bg);
4430 config_save(config);
4431 }
4432}
4433
4434
4435static void
4436_set_trans(Config *config, Evas_Object *bg, Evas_Object *base)
4437{
4438 Edje_Message_Int msg;
4439
4440 if (config && config->translucent)
4441 msg.val = config->opacity;
4442 else
4443 msg.val = 100;
4444
4445 if (bg)
4446 edje_object_message_send(bg, EDJE_MESSAGE_INT, 1, &msg);
4447 if (base) {
4448 Evas_Object *edje = elm_layout_edje_get(base);
4449 edje_object_message_send(edje, EDJE_MESSAGE_INT, 1, &msg);
4450 }
4451}
4452
4453static void
4454_term_config_set(Term *term, Config *config)
4455{
4456 Config *old_config = term->config;
4457
4458 term->config = config;
4459 termio_config_set(term->termio, config);
4460 _term_media_update(term, term->config);
4461 if (old_config != term->wn->config)
4462 config_del(old_config);
4463}
4464
4465Eina_Bool
4466term_is_focused(Term *term)
4467{
4468 Term_Container *tc;
4469
4470 if (!term)
4471 return EINA_FALSE;
4472
4473 tc = term->container;
4474 if (!tc)
4475 return EINA_FALSE;
4476
4477 DBG("tc:%p tc->is_focused:%d", tc, tc->is_focused);
4478 return tc->is_focused;
4479}
4480
4481void change_theme(Evas_Object *win, Config *config)
4482{
4483 const Eina_List *terms, *l;
4484 Term *term;
4485
4486 terms = terms_from_win_object(win);
4487 if (!terms) return;
4488
4489 EINA_LIST_FOREACH(terms, l, term)
4490 {
4491 Evas_Object *edje = term->bg;
4492
4493 if (!theme_apply(edje, config, "terminology/background"))
4494 ERR("Couldn't find terminology theme!");
4495 colors_term_init(termio_textgrid_get(term->termio), edje, config);
4496 termio_config_set(term->termio, config);
4497 }
4498
4499 l = elm_theme_overlay_list_get(NULL);
4500 if (l) l = eina_list_last(l);
4501 if (l) elm_theme_overlay_del(NULL, l->data);
4502 elm_theme_overlay_add(NULL, config_theme_path_get(config));
4503 main_trans_update(config);
4504}
4505
4506void
4507term_focus(Term *term)
4508{
4509 Term_Container *tc;
4510
4511 DBG("is focused? tc:%p", term->container);
4512 if (term_is_focused(term))
4513 return;
4514
4515 tc = term->container;
4516 DBG("tc:%p", tc);
4517 tc->focus(tc, tc);
4518}
4519
4520void
4521term_unfocus(Term *term)
4522{
4523 Term_Container *tc;
4524
4525 DBG("is focused? tc:%p", term->container);
4526 if (!term_is_focused(term))
4527 return;
4528
4529 tc = term->container;
4530 DBG("tc:%p", tc);
4531 tc->unfocus(tc, tc);
4532}
4533
4534enum term_to_direction {
4535 TERM_TO_PREV,
4536 TERM_TO_NEXT,
4537 TERM_TO_UP,
4538 TERM_TO_DOWN,
4539 TERM_TO_LEFT,
4540 TERM_TO_RIGHT,
4541};
4542
4543static void
4544term_go_to(Term *from, enum term_to_direction dir)
4545{
4546 Term *new_term, *focused_term;
4547 Win *wn = from->wn;
4548 Term_Container *tc;
4549
4550 tc = (Term_Container *) wn;
4551
4552 focused_term = tc->focused_term_get(tc);
4553 if (!focused_term)
4554 focused_term = from;
4555 tc = focused_term->container;
4556
4557 switch (dir)
4558 {
4559 case TERM_TO_PREV:
4560 new_term = tc->term_prev(tc, tc);
4561 break;
4562 case TERM_TO_NEXT:
4563 new_term = tc->term_next(tc, tc);
4564 break;
4565 case TERM_TO_UP:
4566 new_term = tc->term_up(tc, tc);
4567 break;
4568 case TERM_TO_DOWN:
4569 new_term = tc->term_down(tc, tc);
4570 break;
4571 case TERM_TO_LEFT:
4572 new_term = tc->term_left(tc, tc);
4573 break;
4574 case TERM_TO_RIGHT:
4575 new_term = tc->term_right(tc, tc);
4576 break;
4577 }
4578
4579 if (new_term && new_term != focused_term)
4580 term_focus(new_term);
4581
4582 /* TODO: get rid of it? */
4583 _term_miniview_check(from);
4584}
4585
4586void
4587term_prev(Term *term)
4588{
4589 term_go_to(term, TERM_TO_PREV);
4590}
4591
4592void
4593term_next(Term *term)
4594{
4595 term_go_to(term, TERM_TO_NEXT);
4596}
4597
4598void
4599term_up(Term *term)
4600{
4601 term_go_to(term, TERM_TO_UP);
4602}
4603
4604void
4605term_down(Term *term)
4606{
4607 term_go_to(term, TERM_TO_DOWN);
4608}
4609
4610void
4611term_left(Term *term)
4612{
4613 term_go_to(term, TERM_TO_LEFT);
4614}
4615
4616void
4617term_right(Term *term)
4618{
4619 term_go_to(term, TERM_TO_RIGHT);
4620}
4621
4622Term *
4623term_prev_get(const Term *term)
4624{
4625 Term_Container *tc = term->container;
4626
4627 return tc->term_prev(tc, tc);
4628}
4629
4630Term *
4631term_next_get(const Term *term)
4632{
4633 Term_Container *tc = term->container;
4634
4635 return tc->term_next(tc, tc);
4636}
4637
4638
4554static void 4639static void
4555_term_miniview_check(Term *term) 4640_term_miniview_check(Term *term)
4556{ 4641{
@@ -4721,88 +4806,6 @@ term_set_title(Term *term)
4721 elm_object_focus_set(o, EINA_TRUE); 4806 elm_object_focus_set(o, EINA_TRUE);
4722} 4807}
4723 4808
4724struct Pop_Media {
4725 const char *src;
4726 Eina_Bool from_user_interaction;
4727};
4728
4729static void
4730_popmedia_queue_process(Term *term)
4731{
4732 struct Pop_Media *pm;
4733
4734 if (!term->popmedia_queue)
4735 return;
4736 pm = term->popmedia_queue->data;
4737 term->popmedia_queue = eina_list_remove_list(term->popmedia_queue,
4738 term->popmedia_queue);
4739 if (!pm)
4740 return;
4741 _popmedia(term, pm->src, pm->from_user_interaction);
4742 eina_stringshare_del(pm->src);
4743 free(pm);
4744}
4745
4746static void
4747_popmedia_queue_add(Term *term, const char *src,
4748 Eina_Bool from_user_interaction)
4749{
4750 struct Pop_Media *pm = calloc(1, sizeof(struct Pop_Media));
4751
4752 if (!pm)
4753 return;
4754
4755 pm->src = eina_stringshare_add(src);
4756 pm->from_user_interaction = from_user_interaction;
4757
4758 term->popmedia_queue = eina_list_append(term->popmedia_queue, pm);
4759 if (!term->popmedia)
4760 _popmedia_queue_process(term);
4761}
4762
4763static void
4764_cb_popup(void *data,
4765 Evas_Object *_obj EINA_UNUSED,
4766 void *event)
4767{
4768 Term *term = data;
4769 const char *src = event;
4770 Eina_Bool from_user_interaction = EINA_FALSE;
4771
4772 if (!src)
4773 {
4774 /* Popup a link, there was user interaction on it. */
4775 from_user_interaction = EINA_TRUE;
4776 src = termio_link_get(term->termio, NULL);
4777 }
4778 if (!src)
4779 return;
4780 _popmedia(term, src, from_user_interaction);
4781 if (!event)
4782 free((void*)src);
4783}
4784
4785static void
4786_cb_popup_queue(void *data,
4787 Evas_Object *_obj EINA_UNUSED,
4788 void *event)
4789{
4790 Term *term = data;
4791 const char *src = event;
4792 Eina_Bool from_user_interaction = EINA_FALSE;
4793
4794 if (!src)
4795 {
4796 from_user_interaction = EINA_TRUE;
4797 src = termio_link_get(term->termio, NULL);
4798 }
4799 if (!src)
4800 return;
4801 _popmedia_queue_add(term, src, from_user_interaction);
4802 if (!event)
4803 free((void*)src);
4804}
4805
4806static void 4809static void
4807_set_alpha(Config *config, const char *val, Eina_Bool save) 4810_set_alpha(Config *config, const char *val, Eina_Bool save)
4808{ 4811{