From 39fb41024be68f71d04f6f3a6ef234d2c08d40a3 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 13 Nov 2017 23:48:05 +0100 Subject: [PATCH 01/36] early work on multi-input support --- src/bin/config.c | 13 ++- src/bin/keyin.c | 88 +++++++++++++---- src/bin/termio.c | 67 +++++-------- src/bin/termio.h | 5 + src/bin/win.c | 245 ++++++++++++++++++++++++++++++++++++++++++++++- src/bin/win.h | 5 + 6 files changed, 354 insertions(+), 69 deletions(-) diff --git a/src/bin/config.c b/src/bin/config.c index 60e5079d..20334871 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -7,7 +7,7 @@ #include "col.h" #include "utils.h" -#define CONF_VER 17 +#define CONF_VER 18 #define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;} @@ -343,6 +343,7 @@ _add_default_keys(Config *config) ADD_KB("Down", 0, 1, 0, 0, "term_down"); ADD_KB("Left", 0, 1, 0, 0, "term_left"); ADD_KB("Right", 0, 1, 0, 0, "term_right"); + ADD_KB("g", 0, 1, 0, 0, "visible_group"); /* Ctrl-Shift- */ ADD_KB("Prior", 1, 0, 1, 0, "split_h"); @@ -377,6 +378,9 @@ _add_default_keys(Config *config) ADD_KB("Right", 0, 0, 1, 0, "term_next"); ADD_KB("Home", 0, 0, 1, 0, "top_backlog"); ADD_KB("End", 0, 0, 1, 0, "reset_scroll"); + + /* Alt-Shift */ + ADD_KB("g", 0, 1, 1, 0, "all_group"); } void @@ -653,7 +657,12 @@ config_load(const char *key) config->shine = 255; EINA_FALLTHROUGH; /*pass through*/ - case CONF_VER: /* 17 */ + case 17: + _add_key(config, "g", 0, 1, 0, 0, "visible_group"); + _add_key(config, "g", 0, 1, 1, 0, "all_group"); + EINA_FALLTHROUGH; + /*pass through*/ + case CONF_VER: /* 18 */ config->version = CONF_VER; break; default: diff --git a/src/bin/keyin.c b/src/bin/keyin.c index 900d289a..78601afc 100644 --- a/src/bin/keyin.c +++ b/src/bin/keyin.c @@ -343,18 +343,62 @@ keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev) { Ecore_IMF_Event_Key_Up imf_ev; ecore_imf_evas_event_key_up_wrap(ev, &imf_ev); - if (ecore_imf_context_filter_event - (khdl->imf, ECORE_IMF_EVENT_KEY_UP, (Ecore_IMF_Event *)&imf_ev)) - return; + ecore_imf_context_filter_event + (khdl->imf, ECORE_IMF_EVENT_KEY_UP, (Ecore_IMF_Event *)&imf_ev); } } /* }}} */ /* {{{ Callbacks */ +#define RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED \ + Win *wn; \ + Term *term = termio_term_get(termio_obj); \ + if (!term) \ + return EINA_FALSE; \ + wn = term_win_get(term); \ + if (!wn) \ + return EINA_FALSE; \ + if (win_is_group_action_handled(wn)) \ + return EINA_FALSE; \ + +#define RETURN_FALSE_ON_GROUP_INPUT \ + Win *wn; \ + Term *term = termio_term_get(termio_obj); \ + if (!term) \ + return EINA_FALSE; \ + wn = term_win_get(term); \ + if (!wn) \ + return EINA_FALSE; \ + if (win_is_group_input(wn)) \ + return EINA_FALSE; \ + +static Eina_Bool +cb_all_group(Evas_Object *termio_obj) +{ + RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED; + + win_toggle_all_group(wn); + + ERR("ALL GROUP"); + return EINA_TRUE; +} + +static Eina_Bool +cb_visible_group(Evas_Object *termio_obj) +{ + RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED; + + win_toggle_visible_group(wn); + + ERR("VISIBLE GROUP"); + return EINA_TRUE; +} static Eina_Bool cb_term_prev(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; + evas_object_smart_callback_call(termio_obj, "prev", NULL); return EINA_TRUE; } @@ -362,6 +406,8 @@ cb_term_prev(Evas_Object *termio_obj) static Eina_Bool cb_term_next(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; + evas_object_smart_callback_call(termio_obj, "next", NULL); return EINA_TRUE; } @@ -369,9 +415,8 @@ cb_term_next(Evas_Object *termio_obj) static Eina_Bool cb_term_up(Evas_Object *termio_obj) { - Term *term = termio_term_get(termio_obj); - if (!term) - return EINA_FALSE; + RETURN_FALSE_ON_GROUP_INPUT; + term_up(term); return EINA_TRUE; } @@ -379,9 +424,8 @@ cb_term_up(Evas_Object *termio_obj) static Eina_Bool cb_term_down(Evas_Object *termio_obj) { - Term *term = termio_term_get(termio_obj); - if (!term) - return EINA_FALSE; + RETURN_FALSE_ON_GROUP_INPUT; + term_down(term); return EINA_TRUE; } @@ -389,9 +433,8 @@ cb_term_down(Evas_Object *termio_obj) static Eina_Bool cb_term_left(Evas_Object *termio_obj) { - Term *term = termio_term_get(termio_obj); - if (!term) - return EINA_FALSE; + RETURN_FALSE_ON_GROUP_INPUT; + term_left(term); return EINA_TRUE; } @@ -399,9 +442,8 @@ cb_term_left(Evas_Object *termio_obj) static Eina_Bool cb_term_right(Evas_Object *termio_obj) { - Term *term = termio_term_get(termio_obj); - if (!term) - return EINA_FALSE; + RETURN_FALSE_ON_GROUP_INPUT; + term_right(term); return EINA_TRUE; } @@ -409,6 +451,8 @@ cb_term_right(Evas_Object *termio_obj) static Eina_Bool cb_term_new(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED; + char path[PATH_MAX], cwd[PATH_MAX], *cmd; const char *template = "%s -d %s"; int length; @@ -450,10 +494,8 @@ cb_tab_set_title(Evas_Object *termio_obj) static Eina_Bool \ cb_tab_##N(Evas_Object *termio_obj) \ { \ + RETURN_FALSE_ON_GROUP_INPUT; \ int n = (N == 0) ? 9 : N - 1; \ - Term *term = termio_term_get(termio_obj); \ - if (!term) \ - return EINA_FALSE; \ return term_tab_go(term, n); \ } @@ -472,6 +514,7 @@ CB_TAB(9) static Eina_Bool cb_cmd_box(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED; evas_object_smart_callback_call(termio_obj, "cmdbox", NULL); return EINA_TRUE; } @@ -479,6 +522,7 @@ cb_cmd_box(Evas_Object *termio_obj) static Eina_Bool cb_split_h(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; evas_object_smart_callback_call(termio_obj, "split,h", NULL); return EINA_TRUE; } @@ -486,6 +530,7 @@ cb_split_h(Evas_Object *termio_obj) static Eina_Bool cb_split_v(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; evas_object_smart_callback_call(termio_obj, "split,v", NULL); return EINA_TRUE; } @@ -493,6 +538,7 @@ cb_split_v(Evas_Object *termio_obj) static Eina_Bool cb_tab_new(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; evas_object_smart_callback_call(termio_obj, "new", NULL); return EINA_TRUE; } @@ -500,6 +546,7 @@ cb_tab_new(Evas_Object *termio_obj) static Eina_Bool cb_close(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; evas_object_smart_callback_call(termio_obj, "close", NULL); return EINA_TRUE; } @@ -507,6 +554,7 @@ cb_close(Evas_Object *termio_obj) static Eina_Bool cb_tab_select(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_INPUT; evas_object_smart_callback_call(termio_obj, "select", NULL); return EINA_TRUE; } @@ -557,6 +605,7 @@ cb_miniview(Evas_Object *termio_obj) static Eina_Bool cb_win_fullscreen(Evas_Object *termio_obj) { + RETURN_FALSE_ON_GROUP_ACTION_ALREADY_HANDLED; Evas_Object *win = termio_win_get(termio_obj); Eina_Bool fullscreen; @@ -707,6 +756,9 @@ static Shortcut_Action _actions[] = {"tab_9", gettext_noop("Switch to terminal tab 9"), cb_tab_9}, {"tab_10", gettext_noop("Switch to terminal tab 10"), cb_tab_0}, {"tab_title", gettext_noop("Change title"), cb_tab_set_title}, + {"visible_group", gettext_noop("Toggle whether input goes to all visible terminals"), cb_visible_group}, + {"all_group", gettext_noop("Toggle whether input goes to all visible terminals"), cb_all_group}, + {"group", gettext_noop("Font size"), NULL}, {"increase_font_size", gettext_noop("Font size up 1"), cb_increase_font_size}, diff --git a/src/bin/termio.c b/src/bin/termio.c index 93c636b9..01e5227c 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -101,6 +101,7 @@ struct _Termio unsigned char bottom_right : 1; unsigned char top_left : 1; unsigned char reset_sel : 1; + unsigned char cb_added : 1; double gesture_zoom_start_size; }; @@ -2029,6 +2030,8 @@ _smart_cb_key_down(void *data, evas_key_modifier_is_set(ev->modifiers, "AltGr") || evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"); hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper"); + ERR("ctrl:%d alt:%d shift:%d win:%d meta:%d hyper:%d", + ctrl, alt, shift, win, meta, hyper); if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win, meta, hyper)) goto end; @@ -3508,13 +3511,10 @@ _imf_cursor_set(Termio *sd) */ } -static void -_smart_cb_focus_in(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_event EINA_UNUSED) +void +termio_focus_in(Evas_Object *termio) { - Termio *sd = evas_object_smart_data_get(data); + Termio *sd = evas_object_smart_data_get(termio); EINA_SAFETY_ON_NULL_RETURN(sd); if (sd->config->disable_cursor_blink) @@ -3532,13 +3532,10 @@ _smart_cb_focus_in(void *data, } } -static void -_smart_cb_focus_out(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *obj, - void *_event EINA_UNUSED) +void +termio_focus_out(Evas_Object *termio) { - Termio *sd = evas_object_smart_data_get(data); + Termio *sd = evas_object_smart_data_get(termio); EINA_SAFETY_ON_NULL_RETURN(sd); if (!sd->config->disable_focus_visuals) @@ -3554,7 +3551,7 @@ _smart_cb_focus_out(void *data, ecore_imf_context_input_panel_hide(sd->khdl.imf); } if (!sd->ctxpopup) - _remove_links(sd, obj); + _remove_links(sd, termio); term_unfocus(sd->term); } @@ -5371,15 +5368,6 @@ _smart_add(Evas_Object *obj) evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL, _smart_cb_mouse_wheel, obj); - evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, - _smart_cb_key_down, obj); - evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP, - _smart_cb_key_up, obj); - evas_object_event_callback_add(obj, EVAS_CALLBACK_FOCUS_IN, - _smart_cb_focus_in, obj); - evas_object_event_callback_add(obj, EVAS_CALLBACK_FOCUS_OUT, - _smart_cb_focus_out, obj); - sd->link.suspend = 1; if (ecore_imf_init()) @@ -5432,6 +5420,7 @@ _smart_add(Evas_Object *obj) imf_done: if (sd->khdl.imf) DBG("Ecore IMF Setup"); else WRN(_("Ecore IMF failed")); + } terms = eina_list_append(terms, obj); } @@ -5470,17 +5459,6 @@ _smart_del(Evas_Object *obj) evas_object_del(sd->event); sd->event = NULL; } - if (sd->self) - { - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_KEY_DOWN, - _smart_cb_key_down); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_KEY_UP, - _smart_cb_key_up); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_FOCUS_IN, - _smart_cb_focus_in); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_FOCUS_OUT, - _smart_cb_focus_out); - } if (sd->sel.top) evas_object_del(sd->sel.top); if (sd->sel.bottom) evas_object_del(sd->sel.bottom); if (sd->sel.theme) evas_object_del(sd->sel.theme); @@ -5682,17 +5660,6 @@ _smart_pty_exited(void *data) evas_object_del(sd->event); sd->event = NULL; } - if (sd->self) - { - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_KEY_DOWN, - _smart_cb_key_down); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_KEY_UP, - _smart_cb_key_up); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_FOCUS_IN, - _smart_cb_focus_in); - evas_object_event_callback_del(sd->self, EVAS_CALLBACK_FOCUS_OUT, - _smart_cb_focus_out); - } term_close(sd->win, sd->self, EINA_TRUE); } @@ -6305,3 +6272,15 @@ termio_add(Evas_Object *win, Config *config, _smart_size(obj, w, h, EINA_FALSE); return obj; } + +void +termio_key_down(Evas_Object *termio, void *event) +{ + _smart_cb_key_down(termio, NULL, NULL, event); +} + +void +termio_key_up(Evas_Object *termio, void *event) +{ + _smart_cb_key_up(termio, NULL, NULL, event); +} diff --git a/src/bin/termio.h b/src/bin/termio.h index f930393b..7ee9c85b 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -53,4 +53,9 @@ Termpty *termio_pty_get(const Evas_Object *obj); Evas_Object * termio_miniview_get(const Evas_Object *obj); Term* termio_term_get(const Evas_Object *obj); +void termio_key_down(Evas_Object *termio, void *event); +void termio_key_up(Evas_Object *termio, void *event); +void termio_focus_in(Evas_Object *termio); +void termio_focus_out(Evas_Object *termio); + #endif diff --git a/src/bin/win.c b/src/bin/win.c index ccaaeddc..54f9dbd9 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -170,6 +170,9 @@ struct _Win Ecore_Timer *cmdbox_focus_timer; unsigned char focused : 1; unsigned char cmdbox_up : 1; + unsigned char group_input : 1; + unsigned char group_only_visible : 1; + unsigned char group_once_handled : 1; }; /* }}} */ @@ -404,6 +407,7 @@ _solo_unfocus(Term_Container *tc, Term_Container *relative) return; tc->is_focused = EINA_FALSE; + termio_focus_out(term->termio); if (tc->parent != relative) tc->parent->unfocus(tc->parent, tc); @@ -453,10 +457,11 @@ _solo_focus(Term_Container *tc, Term_Container *relative) edje_object_signal_emit(term->bg, "focus,in", "terminology"); edje_object_signal_emit(term->base, "focus,in", "terminology"); } + termio_focus_in(term->termio); if (term->wn->cmdbox) elm_object_focus_set(term->wn->cmdbox, EINA_FALSE); - elm_object_focus_set(term->termio, EINA_TRUE); - termio_event_feed_mouse_in(term->termio); + //elm_object_focus_set(term->termio, EINA_TRUE); + //termio_event_feed_mouse_in(term->termio); title = termio_title_get(term->termio); if (title) @@ -530,7 +535,7 @@ _cb_win_focus_in(void *data, Term_Container *tc = (Term_Container*) wn; Term *term; - DBG("tc:%p tc->is_focused:%d", + DBG("FOCUS_IN tc:%p tc->is_focused:%d", tc, tc->is_focused); if (!tc->is_focused) elm_win_urgent_set(wn->win, EINA_FALSE); @@ -577,7 +582,7 @@ _cb_win_focus_out(void *data, Win *wn = data; Term_Container *tc = (Term_Container*) wn; - DBG("tc:%p tc->is_focused:%d", + DBG("FOCUS OUT tc:%p tc->is_focused:%d", tc, tc->is_focused); tc->unfocus(tc, NULL); } @@ -1106,6 +1111,154 @@ _win_update(Term_Container *tc) wn->child->update(wn->child); } +static void +_cb_win_key_up(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *event_info) +{ + Win *wn = data; + Eina_List *l; + Term *term; + const Evas_Event_Key_Up *ev = event_info; + + DBG("GROUP key up (%p) (ctrl:%d)", + wn, evas_key_modifier_is_set(ev->modifiers, "Control")); + if (wn->group_input) + { + wn->group_once_handled = EINA_FALSE; + EINA_LIST_FOREACH(wn->terms, l, term) + { + termio_key_up(term->termio, event_info); + if (!wn->group_input) + return; + } + } + else + { + Term_Container *tc = (Term_Container*) wn; + + term = tc->focused_term_get(tc); + if (term) + termio_key_up(term->termio, event_info); + } +} + +static void +_cb_win_key_down(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *event_info) +{ + Win *wn = data; + Eina_List *l; + Term *term; + const Evas_Event_Key_Down *ev = event_info; + + DBG("GROUP key down (%p) (ctrl:%d)", + wn, evas_key_modifier_is_set(ev->modifiers, "Control")); + + int ctrl, alt, shift, win, meta, hyper; + ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); + alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); + shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); + win = evas_key_modifier_is_set(ev->modifiers, "Super"); + meta = evas_key_modifier_is_set(ev->modifiers, "Meta") || + evas_key_modifier_is_set(ev->modifiers, "AltGr") || + evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"); + hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper"); + DBG("ctrl:%d alt:%d shift:%d win:%d meta:%d hyper:%d", + ctrl, alt, shift, win, meta, hyper); + + + if (wn->group_input) + { + wn->group_once_handled = EINA_FALSE; + EINA_LIST_FOREACH(wn->terms, l, term) + { + termio_key_down(term->termio, event_info); + if (!wn->group_input) + return; + } + } + else + { + Term_Container *tc = (Term_Container*) wn; + + term = tc->focused_term_get(tc); + if (term) + termio_key_down(term->termio, event_info); + } +} + +static void +_cb_win_mouse_down(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *event) +{ + Win *wn = data; + Evas_Event_Mouse_Down *ev = event; + Term *term, *term_mouse; + Term_Container *tc = (Term_Container*) wn; + Term_Container *tc_child; + + DBG("mouse down"); + if (wn->group_input) + return; + + term_mouse = tc->find_term_at_coords(tc, ev->canvas.x, ev->canvas.y); + term = tc->focused_term_get(tc); + if (term_mouse == term) + return; + + if (term) + { + tc_child = term->container; + tc_child->unfocus(tc_child, tc); + } + + tc_child = term_mouse->container; + tc_child->focus(tc_child, tc); +} + +static void +_cb_win_mouse_move(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, + void *event) +{ + Win *wn = data; + Evas_Event_Mouse_Move *ev = event; + Term *term, *term_mouse; + Term_Container *tc = (Term_Container*) wn; + Term_Container *tc_child; + + if (wn->group_input) + return; + + if (!wn->config->mouse_over_focus) + return; + + term_mouse = tc->find_term_at_coords(tc, + ev->cur.canvas.x, ev->cur.canvas.y); + term = tc->focused_term_get(tc); + if (term_mouse == term) + return; + + DBG("mouse move"); + if (term) + { + tc_child = term->container; + tc_child->unfocus(tc_child, tc); + } + + tc_child = term_mouse->container; + DBG("need to focus"); + tc_child->focus(tc_child, tc); +} + + Win * win_new(const char *name, const char *role, const char *title, const char *icon_name, Config *config, @@ -1187,6 +1340,23 @@ win_new(const char *name, const char *role, const char *title, evas_object_smart_callback_add(wn->win, "focus,in", _cb_win_focus_in, wn); evas_object_smart_callback_add(wn->win, "focus,out", _cb_win_focus_out, wn); + evas_object_event_callback_add(wn->win, + EVAS_CALLBACK_KEY_DOWN, + _cb_win_key_down, + wn); + evas_object_event_callback_add(wn->win, + EVAS_CALLBACK_KEY_UP, + _cb_win_key_up, + wn); + evas_object_event_callback_add(wn->win, + EVAS_CALLBACK_MOUSE_DOWN, + _cb_win_mouse_down, + wn); + evas_object_event_callback_add(wn->win, + EVAS_CALLBACK_MOUSE_MOVE, + _cb_win_mouse_move, + wn); + wins = eina_list_append(wins, wn); return wn; } @@ -1216,6 +1386,71 @@ term_close(Evas_Object *win, Evas_Object *term, Eina_Bool hold_if_requested) term_unref(tm); } +/* Returns True if action is permitted */ +Eina_Bool +win_is_group_action_handled(Win *wn) +{ + DBG("wn->group_input:%d wn->group_once_handled:%d wn:%p", + wn->group_input, wn->group_once_handled, wn); + if (!wn->group_input) + return EINA_FALSE; + if (wn->group_once_handled) + return EINA_TRUE; + wn->group_once_handled = EINA_TRUE; + return EINA_FALSE; +} + +Eina_Bool +win_is_group_input(Win *wn) +{ + return wn->group_input; +} + + + +static void +_win_toggle_group(Win *wn) +{ + Eina_List *l; + Term *term; + + DBG("WIN TOGGLE"); + if (!wn->group_input) + { + EINA_LIST_FOREACH(wn->terms, l, term) + { + edje_object_signal_emit(term->bg, "focus,in", "terminology"); + } + wn->group_input = EINA_TRUE; + DBG("GROUP INPUT is now TRUE"); + } + else + { + wn->group_input = EINA_TRUE; + DBG("GROUP INPUT is now FALSE"); + EINA_LIST_FOREACH(wn->terms, l, term) + { + edje_object_signal_emit(term->bg, "focus,out", "terminology"); + } + term = wn->child->term_first(wn->child); + wn->child->focus(wn->child, &wn->tc); + } +} + + +void +win_toggle_all_group(Win *wn) +{ + wn->group_only_visible = EINA_FALSE; + _win_toggle_group(wn); +} +void +win_toggle_visible_group(Win *wn) +{ + wn->group_only_visible = EINA_TRUE; + _win_toggle_group(wn); +} + /* }}} */ /* {{{ Splits */ @@ -4799,7 +5034,7 @@ _cb_options_done(void *data) return; } } - DBG("tc:%p", tc); + DBG("focus tc:%p", tc); tc->focus(tc, tc); } diff --git a/src/bin/win.h b/src/bin/win.h index e496acf3..113ed71c 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -47,6 +47,11 @@ Config *win_config_get(const Win *wn); void win_term_swallow(Win *wn, Term *term); void win_add_split(Win *wn, Term *term); void win_sizing_handle(Win *wn); +void win_toggle_visible_group(Win *wn); +void win_toggle_all_group(Win *wn); +Eina_Bool win_is_group_action_handled(Win *wn); +Eina_Bool win_is_group_input(Win *wn); + void term_ref(Term *term); void term_unref(Term *term); From 561e1b09417551a1643849cc3f9cf3758e2a05f7 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 17 Dec 2017 22:57:00 +0100 Subject: [PATCH 02/36] splits: fix focus issue when splitting a split --- src/bin/win.c | 84 +++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 54f9dbd9..ecebd5fc 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1232,7 +1232,7 @@ _cb_win_mouse_move(void *data, Evas_Event_Mouse_Move *ev = event; Term *term, *term_mouse; Term_Container *tc = (Term_Container*) wn; - Term_Container *tc_child; + Term_Container *tc_child = NULL; if (wn->group_input) return; @@ -1851,50 +1851,50 @@ _split_split(Term_Container *tc, Term_Container *child, { Split *split; Win *wn; + Term *tm_new, *tm; + char *wdir = NULL; + char buf[PATH_MAX]; + Term_Container *tc_split, *tc_solo_new; + Evas_Object *obj_split; + DBG(" "); assert (tc->type == TERM_CONTAINER_TYPE_SPLIT); split = (Split *)tc; wn = tc->wn; - if (_term_container_is_splittable(tc, is_horizontal)) + if (!_term_container_is_splittable(tc, is_horizontal)) + return; + + // copy the current path to wdir if we should change the directory, + // passing wdir NULL otherwise: + if (wn->config->changedir_to_current) { - Term *tm_new, *tm; - char *wdir = NULL; - char buf[PATH_MAX]; - Term_Container *tc_split, *tc_solo_new; - Evas_Object *obj_split; - - // copy the current path to wdir if we should change the directory, - // passing wdir NULL otherwise: - if (wn->config->changedir_to_current) - { - if (from) - tm = from; - else - tm = child->focused_term_get(child); - if (tm && termio_cwd_get(tm->termio, buf, sizeof(buf))) - wdir = buf; - } - tm_new = term_new(wn, wn->config, - cmd, wn->config->login_shell, wdir, - 80, 24, EINA_FALSE, NULL); - tc_solo_new = _solo_new(tm_new, wn); - evas_object_data_set(tm_new->termio, "sizedone", tm_new->termio); - - if (child == split->tc1) - elm_object_part_content_unset(split->panes, PANES_TOP); + if (from) + tm = from; else - elm_object_part_content_unset(split->panes, PANES_BOTTOM); - - tc_split = _split_new(child, tc_solo_new, is_horizontal); - - obj_split = tc_split->get_evas_object(tc_split); - - tc_split->is_focused = tc->is_focused; - tc->swallow(tc, child, tc_split); - - evas_object_show(obj_split); + tm = child->focused_term_get(child); + if (tm && termio_cwd_get(tm->termio, buf, sizeof(buf))) + wdir = buf; } + tm_new = term_new(wn, wn->config, + cmd, wn->config->login_shell, wdir, + 80, 24, EINA_FALSE, NULL); + tc_solo_new = _solo_new(tm_new, wn); + evas_object_data_set(tm_new->termio, "sizedone", tm_new->termio); + + if (child == split->tc1) + elm_object_part_content_unset(split->panes, PANES_TOP); + else + elm_object_part_content_unset(split->panes, PANES_BOTTOM); + + tc_split = _split_new(child, tc_solo_new, is_horizontal); + + obj_split = tc_split->get_evas_object(tc_split); + + tc_split->is_focused = tc->is_focused; + tc->swallow(tc, child, tc_split); + + evas_object_show(obj_split); } static Term_Container * @@ -1944,9 +1944,13 @@ _split_new(Term_Container *tc1, Term_Container *tc2, split->tc1 = tc1; split->tc2 = tc2; if (tc1->is_focused) - tc1->unfocus(tc1, tc); - tc2->focus(tc2, tc); - split->last_focus = tc2; + { + tc1->unfocus(tc1, tc); + tc2->focus(tc2, tc); + split->last_focus = tc2; + } + else + split->last_focus = tc1; o = split->panes = elm_panes_add(tc1->wn->win); elm_object_style_set(o, "flush"); From d7bc232806c06f84b1a7146c087484b00105e59a Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 17 Dec 2017 22:58:12 +0100 Subject: [PATCH 03/36] win: remove useless callbacks --- src/bin/win.c | 45 --------------------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index ecebd5fc..5573e7c6 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -3322,46 +3322,6 @@ term_popmedia_close(Term *term) } -static void -_cb_term_mouse_in(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_event EINA_UNUSED) -{ - Term *term = data; - Config *config; - - if ((!term) || (!term->termio)) - return; - - config = termio_config_get(term->termio); - if ((!config) || (!config->mouse_over_focus)) - return; - if (!_win_is_focused(term->wn)) - return; - - _term_focus(term); -} - -static void -_cb_term_mouse_down(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *event) -{ - Evas_Event_Mouse_Down *ev = event; - Term *term = data; - Term *term2; - Term_Container *tc; - - tc = (Term_Container*) term->wn; - term2 = tc->focused_term_get(tc); - if (term == term2) return; - term->down.x = ev->canvas.x; - term->down.y = ev->canvas.y; - _term_focus(term); -} - static Eina_Bool _term_is_focused(Term *term) { @@ -5177,11 +5137,6 @@ term_new(Win *wn, Config *config, const char *cmd, evas_object_smart_callback_add(o, "send,end", _cb_send_end, term); evas_object_show(o); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_term_mouse_down, term); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN, - _cb_term_mouse_in, term); - wn->terms = eina_list_append(wn->terms, term); _term_bg_config(term); From d20e32c26f71caacf523db3d5117fce7ee75db06 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 27 Dec 2017 23:07:02 +0100 Subject: [PATCH 04/36] options: rename options_active_get() to options_is_active() --- src/bin/controls.c | 2 +- src/bin/options.c | 2 +- src/bin/options.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/controls.c b/src/bin/controls.c index 69e3ae1c..a1f67c33 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -264,7 +264,7 @@ controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, if (!ct_out) { - if (options_active_get()) + if (options_is_active()) { options_toggle(win, bg, term, ct_donecb, ct_donedata); return; diff --git a/src/bin/options.c b/src/bin/options.c index 9aacaa0b..9034a0ed 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -256,7 +256,7 @@ options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, } Eina_Bool -options_active_get(void) +options_is_active(void) { return op_out; } diff --git a/src/bin/options.h b/src/bin/options.h index 4076af39..1d23fc98 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -3,7 +3,7 @@ void options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); -Eina_Bool options_active_get(void); +Eina_Bool options_is_active(void); #endif From 080ff8e261e4ed94485f17ece87762812b28c9d4 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 1 Jan 2018 22:57:54 +0100 Subject: [PATCH 05/36] controls: simplify code --- src/bin/controls.c | 401 +++++++++++++++++++-------------------------- src/bin/controls.h | 4 +- src/bin/win.c | 4 +- 3 files changed, 172 insertions(+), 237 deletions(-) diff --git a/src/bin/controls.c b/src/bin/controls.c index a1f67c33..f6a01adf 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include "controls.h" #include "options.h" #include "about.h" @@ -9,12 +10,13 @@ static Evas_Object *ct_frame = NULL, *ct_boxh = NULL, *ct_boxv = NULL; static Evas_Object *ct_box = NULL, *ct_box2 = NULL, *ct_box3 = NULL, *ct_over = NULL; -static Eina_Bool ct_out = EINA_FALSE; -static Ecore_Timer *ct_del_timer = NULL; static Evas_Object *ct_win = NULL, *ct_bg = NULL, *ct_term = NULL; static void (*ct_donecb) (void *data) = NULL; static void *ct_donedata = NULL; +static void +controls_hide(Eina_Bool call_cb); + static void _cb_sel_on(void *_data EINA_UNUSED, Evas_Object *_term EINA_UNUSED, @@ -36,19 +38,10 @@ _cb_sel_off(void *_data EINA_UNUSED, } static Eina_Bool -_cb_ct_del_delay(void *_data EINA_UNUSED) +_cb_ct_del_delay(void *data) { - if (ct_over) - { - evas_object_del(ct_over); - ct_over = NULL; - } - if (ct_frame) - { - evas_object_del(ct_frame); - ct_frame = NULL; - } - ct_del_timer = NULL; + Evas_Object *frame = data; + evas_object_del(frame); elm_cache_all_flush(); return EINA_FALSE; } @@ -58,8 +51,8 @@ _cb_ct_copy(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { + controls_hide(EINA_TRUE); termio_take_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); } static void @@ -67,8 +60,8 @@ _cb_ct_paste(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { + controls_hide(EINA_TRUE); termio_paste_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); } static void @@ -108,7 +101,8 @@ _cb_ct_set_title(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - term_set_title(termio_term_get(ct_term)); + controls_hide(EINA_TRUE); + term_set_title(termio_term_get(ct_term)); } static void @@ -116,6 +110,7 @@ _cb_ct_close(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { + controls_hide(EINA_TRUE); term_close(ct_win, ct_term, EINA_FALSE); } @@ -124,7 +119,7 @@ _cb_ct_options(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); + controls_hide(EINA_FALSE); options_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); } @@ -133,7 +128,7 @@ _cb_ct_about(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); + controls_hide(EINA_FALSE); about_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); } @@ -143,82 +138,34 @@ _cb_mouse_down(void *_data EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); + controls_hide(EINA_TRUE); } static void -_cb_frame_del(void *_data EINA_UNUSED, +_cb_saved_del(void *data, Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, void *_ev EINA_UNUSED) { - if (ct_win) - { - evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on); - evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off); - } - ct_frame = NULL; -} + if (data == ct_win) + ct_win = NULL; + else if (data == ct_term) + ct_term = NULL; -static void -_cb_over_del(void *_data EINA_UNUSED, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_ev EINA_UNUSED) -{ - ct_over = NULL; -} - -static void -_cb_saved_del(void *_data EINA_UNUSED, - Evas *_e EINA_UNUSED, - Evas_Object *obj, - void *_ev EINA_UNUSED) -{ - if ((obj == ct_win) || (obj == ct_term)) - { - if (obj == ct_term) - { - if (ct_out) - controls_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); - ct_term = NULL; - } - else - { - if (ct_frame) - { - evas_object_del(ct_frame); - ct_frame = NULL; - } - if (ct_del_timer) - { - ecore_timer_del(ct_del_timer); - ct_del_timer = NULL; - } - if (ct_over) - { - evas_object_del(ct_over); - ct_over = NULL; - } - evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del); - ct_win = NULL; - } - evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del); - ct_bg = NULL; - } + controls_hide(EINA_FALSE); } static Evas_Object * _button_add(Evas_Object *win, const char *label, const char *icon, Evas_Smart_Cb cb, void *cbdata) { Evas_Object *o, *bt; - + bt = o = elm_button_add(win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); if (label) elm_object_text_set(o, label); evas_object_smart_callback_add(o, "clicked", cb, cbdata); - + if (icon) { o = elm_icon_add(win); @@ -227,7 +174,7 @@ _button_add(Evas_Object *win, const char *label, const char *icon, Evas_Smart_Cb elm_object_part_content_set(bt, "icon", o); evas_object_show(o); } - + evas_object_show(bt); return bt; } @@ -236,7 +183,7 @@ static Evas_Object * _sep_add_v(Evas_Object *win) { Evas_Object *o = elm_separator_add(win); - + evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL); elm_separator_horizontal_set(o, EINA_FALSE); @@ -248,7 +195,7 @@ static Evas_Object * _sep_add_h(Evas_Object *win) { Evas_Object *o = elm_separator_add(win); - + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_separator_horizontal_set(o, EINA_TRUE); @@ -256,167 +203,155 @@ _sep_add_h(Evas_Object *win) return o; } -void -controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, - void (*donecb) (void *data), void *donedata) +static void +controls_hide(Eina_Bool call_cb) { - Evas_Object *o; - - if (!ct_out) - { - if (options_is_active()) - { - options_toggle(win, bg, term, ct_donecb, ct_donedata); - return; - } - } - if ((win != ct_win) && (ct_frame)) - { - evas_object_del(ct_frame); - ct_frame = NULL; - ct_win = NULL; - ct_term = NULL; - } if (!ct_frame) - { - ct_frame = o = elm_frame_add(win); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_text_set(o, _("Controls")); + return; - ct_boxv = o = elm_box_add(win); - elm_box_horizontal_set(o, EINA_FALSE); - elm_object_content_set(ct_frame, o); - evas_object_show(o); - - ct_boxh = o = elm_box_add(win); - elm_box_pack_end(ct_boxv, o); - elm_box_horizontal_set(o, EINA_TRUE); - evas_object_show(o); - - ct_box = o = elm_box_add(win); - elm_box_pack_end(ct_boxh, o); - evas_object_show(o); - - o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL); - elm_box_pack_end(ct_box, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_box, o); - - o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL); - elm_box_pack_end(ct_box, o); - o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL); - elm_box_pack_end(ct_box, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_box, o); - - o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL); - elm_box_pack_end(ct_box, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_box, o); - - o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL); - elm_box_pack_end(ct_box, o); - - o = _sep_add_v(win); - elm_box_pack_end(ct_boxh, o); - - ct_box2 = o = elm_box_add(win); - elm_box_pack_end(ct_boxh, o); - evas_object_show(o); - - o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL); - evas_object_data_set(ct_frame, "bt_copy", o); - if (!termio_selection_exists(term)) - elm_object_disabled_set(o, EINA_TRUE); - elm_box_pack_end(ct_box2, o); - - o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL); - elm_box_pack_end(ct_box2, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_box2, o); - - o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL); - elm_box_pack_end(ct_box2, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_box2, o); - - o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL); - elm_box_pack_end(ct_box2, o); - - o = _sep_add_h(win); - elm_box_pack_end(ct_boxv, o); - - ct_box3 = o = elm_box_add(win); - elm_box_pack_end(ct_boxv, o); - evas_object_show(o); - - o = _button_add(win, _("Close Terminal"), "window-close", _cb_ct_close, NULL); - elm_box_pack_end(ct_box3, o); - - evas_object_event_callback_add(ct_frame, EVAS_CALLBACK_DEL, - _cb_frame_del, NULL); - - evas_object_smart_callback_add(win, "selection,on", _cb_sel_on, - NULL); - evas_object_smart_callback_add(win, "selection,off", _cb_sel_off, - NULL); - } - if (!ct_out) - { - edje_object_part_swallow(bg, "terminology.controls", ct_frame); - evas_object_show(ct_frame); - ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); - evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(bg, "terminology.dismiss", o); - evas_object_show(o); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down, NULL); - evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, - _cb_over_del, NULL); - - ct_win = win; - ct_bg = bg; - ct_term = term; - ct_donecb = donecb; - ct_donedata = donedata; - edje_object_signal_emit(bg, "controls,show", "terminology"); - ct_out = EINA_TRUE; - elm_object_focus_set(ct_frame, EINA_TRUE); - if (ct_del_timer) - { - ecore_timer_del(ct_del_timer); - ct_del_timer = NULL; - } - } - else - { - if (ct_over) - { - evas_object_del(ct_over); - ct_over = NULL; - } - edje_object_signal_emit(ct_bg, "controls,hide", "terminology"); - ct_out = EINA_FALSE; - elm_object_focus_set(ct_frame, EINA_FALSE); - if (ct_donecb) ct_donecb(ct_donedata); -// elm_object_focus_set(ct_term, EINA_TRUE); - if (ct_del_timer) ecore_timer_del(ct_del_timer); - ct_del_timer = ecore_timer_add(10.0, _cb_ct_del_delay, NULL); - } if (ct_win) { evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del); + evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on); + evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off); + } + if (ct_term) + { evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del); } - if (ct_out) + + if (ct_over) { - evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, NULL); - evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, NULL); + evas_object_del(ct_over); } + ct_over = NULL; + edje_object_signal_emit(ct_bg, "controls,hide", "terminology"); + elm_object_focus_set(ct_frame, EINA_FALSE); + + ecore_timer_add(10.0, _cb_ct_del_delay, ct_frame); + ct_frame = NULL; + + ct_win = NULL; + + if (call_cb && ct_donecb) + ct_donecb(ct_donedata); + ct_donecb = NULL; + ct_donedata = NULL; +} + +void +controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, + void (*donecb) (void *data), void *donedata) +{ + Evas_Object *o; + + if ((options_is_active()) || (ct_win && win != ct_win) || (ct_frame)) + { + donecb(donedata); + return; + } + + ct_frame = o = elm_frame_add(win); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_text_set(o, _("Controls")); + + ct_boxv = o = elm_box_add(win); + elm_box_horizontal_set(o, EINA_FALSE); + elm_object_content_set(ct_frame, o); + evas_object_show(o); + + ct_boxh = o = elm_box_add(win); + elm_box_pack_end(ct_boxv, o); + elm_box_horizontal_set(o, EINA_TRUE); + evas_object_show(o); + + ct_box = o = elm_box_add(win); + elm_box_pack_end(ct_boxh, o); + evas_object_show(o); + + o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL); + elm_box_pack_end(ct_box, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_box, o); + + o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL); + elm_box_pack_end(ct_box, o); + o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL); + elm_box_pack_end(ct_box, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_box, o); + + o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL); + elm_box_pack_end(ct_box, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_box, o); + + o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL); + elm_box_pack_end(ct_box, o); + + o = _sep_add_v(win); + elm_box_pack_end(ct_boxh, o); + + ct_box2 = o = elm_box_add(win); + elm_box_pack_end(ct_boxh, o); + evas_object_show(o); + + o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL); + evas_object_data_set(ct_frame, "bt_copy", o); + if (!termio_selection_exists(term)) + elm_object_disabled_set(o, EINA_TRUE); + elm_box_pack_end(ct_box2, o); + + o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL); + elm_box_pack_end(ct_box2, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_box2, o); + + o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL); + elm_box_pack_end(ct_box2, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_box2, o); + + o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL); + elm_box_pack_end(ct_box2, o); + + o = _sep_add_h(win); + elm_box_pack_end(ct_boxv, o); + + ct_box3 = o = elm_box_add(win); + elm_box_pack_end(ct_boxv, o); + evas_object_show(o); + + o = _button_add(win, _("Close Terminal"), "window-close", _cb_ct_close, NULL); + elm_box_pack_end(ct_box3, o); + + evas_object_smart_callback_add(win, "selection,on", _cb_sel_on, + NULL); + evas_object_smart_callback_add(win, "selection,off", _cb_sel_off, + NULL); + + edje_object_part_swallow(bg, "terminology.controls", ct_frame); + evas_object_show(ct_frame); + ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); + evas_object_color_set(o, 0, 0, 0, 0); + edje_object_part_swallow(bg, "terminology.dismiss", o); + evas_object_show(o); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + _cb_mouse_down, NULL); + + ct_win = win; + ct_bg = bg; + ct_term = term; + ct_donecb = donecb; + ct_donedata = donedata; + edje_object_signal_emit(bg, "controls,show", "terminology"); + elm_object_focus_set(ct_frame, EINA_TRUE); + evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, ct_win); + evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, ct_term); } diff --git a/src/bin/controls.h b/src/bin/controls.h index 078d15ba..d41f903a 100644 --- a/src/bin/controls.h +++ b/src/bin/controls.h @@ -1,7 +1,7 @@ #ifndef _CONTROLS_H__ #define _CONTROLS_H__ 1 -void controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, - void (*donecb) (void *data), void *donedata); +void controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, + void (*donecb) (void *data), void *donedata); #endif diff --git a/src/bin/win.c b/src/bin/win.c index 5573e7c6..67763616 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -5009,8 +5009,8 @@ _cb_options(void *data, { Term *term = data; - controls_toggle(term->wn->win, term->wn->base, term->termio, - _cb_options_done, term->wn); + controls_show(term->wn->win, term->wn->base, term->termio, + _cb_options_done, term->wn); } void From eaaae01745d05f5b4d2b4c3b80b8d1f5a01305e4 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 2 Jan 2018 00:09:14 +0100 Subject: [PATCH 06/36] controls: less globals, controls per window --- src/bin/controls.c | 244 ++++++++++++++++++++++++++++----------------- src/bin/controls.h | 3 + src/bin/main.c | 3 + src/bin/options.c | 2 +- src/bin/options.h | 2 +- 5 files changed, 159 insertions(+), 95 deletions(-) diff --git a/src/bin/controls.c b/src/bin/controls.c index f6a01adf..d16e29e0 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -8,31 +8,42 @@ #include "termio.h" #include "main.h" -static Evas_Object *ct_frame = NULL, *ct_boxh = NULL, *ct_boxv = NULL; -static Evas_Object *ct_box = NULL, *ct_box2 = NULL, *ct_box3 = NULL, *ct_over = NULL; -static Evas_Object *ct_win = NULL, *ct_bg = NULL, *ct_term = NULL; -static void (*ct_donecb) (void *data) = NULL; -static void *ct_donedata = NULL; +static Eina_Hash *controls = NULL; + +struct controls_ctx { + Evas_Object *frame; + Evas_Object *over; + Evas_Object *win; + Evas_Object *bg; + Evas_Object *term; + void (*donecb) (void *data); + void *donedata; +}; + static void -controls_hide(Eina_Bool call_cb); +controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb); + + static void -_cb_sel_on(void *_data EINA_UNUSED, +_cb_sel_on(void *data, Evas_Object *_term EINA_UNUSED, void *_ev EINA_UNUSED) { - Evas_Object *bt_copy = evas_object_data_get(ct_frame, "bt_copy"); + struct controls_ctx *ctx = data; + Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy"); if (bt_copy) elm_object_disabled_set(bt_copy, EINA_FALSE); } static void -_cb_sel_off(void *_data EINA_UNUSED, +_cb_sel_off(void *data, Evas_Object *_term EINA_UNUSED, void *_ev EINA_UNUSED) { - Evas_Object *bt_copy = evas_object_data_get(ct_frame, "bt_copy"); + struct controls_ctx *ctx = data; + Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy"); if (bt_copy) elm_object_disabled_set(bt_copy, EINA_TRUE); } @@ -47,112 +58,136 @@ _cb_ct_del_delay(void *data) } static void -_cb_ct_copy(void *_data EINA_UNUSED, +_cb_ct_copy(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_TRUE); - termio_take_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); + struct controls_ctx *ctx = data; + Evas_Object *term = ctx->term; + + controls_hide(ctx, EINA_TRUE); + termio_take_selection(term, ELM_SEL_TYPE_CLIPBOARD); } static void -_cb_ct_paste(void *_data EINA_UNUSED, +_cb_ct_paste(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_TRUE); - termio_paste_selection(ct_term, ELM_SEL_TYPE_CLIPBOARD); + struct controls_ctx *ctx = data; + Evas_Object *term = ctx->term; + + controls_hide(ctx, EINA_TRUE); + termio_paste_selection(term, ELM_SEL_TYPE_CLIPBOARD); } static void -_cb_ct_new(void *_data EINA_UNUSED, +_cb_ct_new(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - main_new(ct_win, ct_term); + struct controls_ctx *ctx = data; + main_new(ctx->win, ctx->term); } static void -_cb_ct_split_v(void *_data EINA_UNUSED, +_cb_ct_split_v(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - split_vertically(ct_win, ct_term, NULL); + struct controls_ctx *ctx = data; + split_vertically(ctx->win, ctx->term, NULL); } static void -_cb_ct_split_h(void *_data EINA_UNUSED, +_cb_ct_split_h(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - split_horizontally(ct_win, ct_term, NULL); + struct controls_ctx *ctx = data; + split_horizontally(ctx->win, ctx->term, NULL); } static void -_cb_ct_miniview(void *_data EINA_UNUSED, +_cb_ct_miniview(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - term_miniview_toggle(termio_term_get(ct_term)); + struct controls_ctx *ctx = data; + term_miniview_toggle(termio_term_get(ctx->term)); } static void -_cb_ct_set_title(void *_data EINA_UNUSED, +_cb_ct_set_title(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_TRUE); - term_set_title(termio_term_get(ct_term)); + struct controls_ctx *ctx = data; + Evas_Object *term = ctx->term; + controls_hide(ctx, EINA_TRUE); + term_set_title(termio_term_get(term)); } static void -_cb_ct_close(void *_data EINA_UNUSED, +_cb_ct_close(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_TRUE); - term_close(ct_win, ct_term, EINA_FALSE); + struct controls_ctx *ctx = data; + Evas_Object *term = ctx->term; + Evas_Object *win = ctx->win; + + controls_hide(ctx, EINA_TRUE); + term_close(win, term, EINA_FALSE); } static void -_cb_ct_options(void *_data EINA_UNUSED, +_cb_ct_options(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_FALSE); - options_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); + struct controls_ctx *ctx = data; + + options_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + controls_hide(ctx, EINA_FALSE); } static void -_cb_ct_about(void *_data EINA_UNUSED, +_cb_ct_about(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - controls_hide(EINA_FALSE); - about_toggle(ct_win, ct_bg, ct_term, ct_donecb, ct_donedata); + struct controls_ctx *ctx = data; + + about_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + controls_hide(ctx, EINA_FALSE); } static void -_cb_mouse_down(void *_data EINA_UNUSED, +_cb_mouse_down(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - controls_hide(EINA_TRUE); + struct controls_ctx *ctx = data; + + controls_hide(ctx, EINA_TRUE); } static void _cb_saved_del(void *data, Evas *_e EINA_UNUSED, - Evas_Object *obj EINA_UNUSED, + Evas_Object *obj, void *_ev EINA_UNUSED) { - if (data == ct_win) - ct_win = NULL; - else if (data == ct_term) - ct_term = NULL; + struct controls_ctx *ctx = data; - controls_hide(EINA_FALSE); + if (obj == ctx->win) + ctx->win = NULL; + else if (obj == ctx->term) + ctx->term = NULL; + + controls_hide(ctx, EINA_FALSE); } static Evas_Object * @@ -204,61 +239,71 @@ _sep_add_h(Evas_Object *win) } static void -controls_hide(Eina_Bool call_cb) +controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb) { - if (!ct_frame) - return; - - if (ct_win) + if (ctx->win) { - evas_object_event_callback_del(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del); - evas_object_smart_callback_del(ct_win, "selection,on", _cb_sel_on); - evas_object_smart_callback_del(ct_win, "selection,off", _cb_sel_off); + evas_object_event_callback_del(ctx->win, EVAS_CALLBACK_DEL, _cb_saved_del); + evas_object_smart_callback_del(ctx->win, "selection,on", _cb_sel_on); + evas_object_smart_callback_del(ctx->win, "selection,off", _cb_sel_off); } - if (ct_term) + if (ctx->term) { - evas_object_event_callback_del(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del); + evas_object_event_callback_del(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del); + edje_object_signal_emit(ctx->bg, "controls,hide", "terminology"); } - if (ct_over) + if (ctx->over) { - evas_object_del(ct_over); + evas_object_del(ctx->over); } - ct_over = NULL; - edje_object_signal_emit(ct_bg, "controls,hide", "terminology"); - elm_object_focus_set(ct_frame, EINA_FALSE); + elm_object_focus_set(ctx->frame, EINA_FALSE); - ecore_timer_add(10.0, _cb_ct_del_delay, ct_frame); - ct_frame = NULL; + ecore_timer_add(10.0, _cb_ct_del_delay, ctx->frame); + ctx->frame = NULL; - ct_win = NULL; + if (call_cb && ctx->donecb) + ctx->donecb(ctx->donedata); - if (call_cb && ct_donecb) - ct_donecb(ct_donedata); - ct_donecb = NULL; - ct_donedata = NULL; + eina_hash_del(controls, &ctx->win, ctx); + + free(ctx); } + void controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o; + Evas_Object *ct_boxh, *ct_boxv, *ct_box, *ct_box2, *ct_box3; + struct controls_ctx *ctx; - if ((options_is_active()) || (ct_win && win != ct_win) || (ct_frame)) + if (eina_hash_find(controls, &win)) { donecb(donedata); return; } - ct_frame = o = elm_frame_add(win); + + ctx = malloc(sizeof(*ctx)); + assert(ctx); + ctx->win = win; + ctx->bg = bg; + ctx->term = term; + ctx->donecb = donecb; + ctx->donedata = donedata; + + eina_hash_add(controls, &win, ctx); + + ctx->frame = o = elm_frame_add(win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Controls")); ct_boxv = o = elm_box_add(win); elm_box_horizontal_set(o, EINA_FALSE); - elm_object_content_set(ct_frame, o); + elm_object_content_set(ctx->frame, o); evas_object_show(o); ct_boxh = o = elm_box_add(win); @@ -270,27 +315,32 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, elm_box_pack_end(ct_boxh, o); evas_object_show(o); - o = _button_add(win, _("New"), "window-new", _cb_ct_new, NULL); + o = _button_add(win, _("New"), "window-new", + _cb_ct_new, ctx); elm_box_pack_end(ct_box, o); o = _sep_add_h(win); elm_box_pack_end(ct_box, o); - o = _button_add(win, _("Split V"), "object-flip-vertical", _cb_ct_split_v, NULL); + o = _button_add(win, _("Split V"), "object-flip-vertical", + _cb_ct_split_v, ctx); elm_box_pack_end(ct_box, o); - o = _button_add(win, _("Split H"), "object-flip-horizontal", _cb_ct_split_h, NULL); + o = _button_add(win, _("Split H"), "object-flip-horizontal", + _cb_ct_split_h, ctx); elm_box_pack_end(ct_box, o); o = _sep_add_h(win); elm_box_pack_end(ct_box, o); - o = _button_add(win, _("Miniview"), "view-restore", _cb_ct_miniview, NULL); + o = _button_add(win, _("Miniview"), "view-restore", + _cb_ct_miniview, ctx); elm_box_pack_end(ct_box, o); o = _sep_add_h(win); elm_box_pack_end(ct_box, o); - o = _button_add(win, _("Set title"), "format-text-underline", _cb_ct_set_title, NULL); + o = _button_add(win, _("Set title"), "format-text-underline", + _cb_ct_set_title, ctx); elm_box_pack_end(ct_box, o); o = _sep_add_v(win); @@ -300,25 +350,25 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, elm_box_pack_end(ct_boxh, o); evas_object_show(o); - o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, NULL); - evas_object_data_set(ct_frame, "bt_copy", o); + o = _button_add(win, _("Copy"), "edit-copy", _cb_ct_copy, ctx); + evas_object_data_set(ctx->frame, "bt_copy", o); if (!termio_selection_exists(term)) elm_object_disabled_set(o, EINA_TRUE); elm_box_pack_end(ct_box2, o); - o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, NULL); + o = _button_add(win, _("Paste"), "edit-paste", _cb_ct_paste, ctx); elm_box_pack_end(ct_box2, o); o = _sep_add_h(win); elm_box_pack_end(ct_box2, o); - o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, NULL); + o = _button_add(win, _("Settings"), "preferences-desktop", _cb_ct_options, ctx); elm_box_pack_end(ct_box2, o); o = _sep_add_h(win); elm_box_pack_end(ct_box2, o); - o = _button_add(win, _("About"), "help-about", _cb_ct_about, NULL); + o = _button_add(win, _("About"), "help-about", _cb_ct_about, ctx); elm_box_pack_end(ct_box2, o); o = _sep_add_h(win); @@ -332,26 +382,34 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, elm_box_pack_end(ct_box3, o); evas_object_smart_callback_add(win, "selection,on", _cb_sel_on, - NULL); + ctx); evas_object_smart_callback_add(win, "selection,off", _cb_sel_off, - NULL); + ctx); - edje_object_part_swallow(bg, "terminology.controls", ct_frame); - evas_object_show(ct_frame); - ct_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); + edje_object_part_swallow(bg, "terminology.controls", ctx->frame); + evas_object_show(ctx->frame); + ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); evas_object_color_set(o, 0, 0, 0, 0); edje_object_part_swallow(bg, "terminology.dismiss", o); evas_object_show(o); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down, NULL); + _cb_mouse_down, ctx); - ct_win = win; - ct_bg = bg; - ct_term = term; - ct_donecb = donecb; - ct_donedata = donedata; edje_object_signal_emit(bg, "controls,show", "terminology"); - elm_object_focus_set(ct_frame, EINA_TRUE); - evas_object_event_callback_add(ct_win, EVAS_CALLBACK_DEL, _cb_saved_del, ct_win); - evas_object_event_callback_add(ct_term, EVAS_CALLBACK_DEL, _cb_saved_del, ct_term); + elm_object_focus_set(ctx->frame, EINA_TRUE); + evas_object_event_callback_add(ctx->win, EVAS_CALLBACK_DEL, _cb_saved_del, ctx); + evas_object_event_callback_add(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del, ctx); +} + +void +controls_init(void) +{ + controls = eina_hash_pointer_new(NULL); +} + +void +controls_shutdown(void) +{ + eina_hash_free(controls); + controls = NULL; } diff --git a/src/bin/controls.h b/src/bin/controls.h index d41f903a..d3f029b2 100644 --- a/src/bin/controls.h +++ b/src/bin/controls.h @@ -4,4 +4,7 @@ void controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); +void controls_init(void); +void controls_shutdown(void); + #endif diff --git a/src/bin/main.c b/src/bin/main.c index 51c37316..b00c436b 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -978,6 +978,7 @@ remote: ecore_con_init(); ecore_con_url_init(); + controls_init(); terminology_starting_up = EINA_FALSE; elm_run(); @@ -1008,9 +1009,11 @@ remote: config_del(_main_config); key_bindings_shutdown(); config_shutdown(); + controls_shutdown(); eina_log_domain_unregister(_log_domain); _log_domain = -1; + #if HAVE_GETTEXT && ENABLE_NLS eina_stringshare_del(options.copyright); #endif diff --git a/src/bin/options.c b/src/bin/options.c index 9034a0ed..381a22d4 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -256,7 +256,7 @@ options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, } Eina_Bool -options_is_active(void) +options_is_active(Evas_Object *win EINA_UNUSED) { return op_out; } diff --git a/src/bin/options.h b/src/bin/options.h index 1d23fc98..007361c8 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -3,7 +3,7 @@ void options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); -Eina_Bool options_is_active(void); +Eina_Bool options_is_active(Evas_Object *win); #endif From 983dadeba4f822430fab8964bec5caed94db4ac6 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 2 Jan 2018 23:44:44 +0100 Subject: [PATCH 07/36] about: simplify code and no more globals --- src/bin/about.c | 332 ++++++++++++++++++++++----------------------- src/bin/about.h | 2 +- src/bin/controls.c | 6 +- 3 files changed, 170 insertions(+), 170 deletions(-) diff --git a/src/bin/about.c b/src/bin/about.c index 4e864bdd..fa544179 100644 --- a/src/bin/about.c +++ b/src/bin/about.c @@ -1,24 +1,28 @@ #include "private.h" #include +#include #include "about.h" #include "config.h" #include "termio.h" -static Evas_Object *ab_layout = NULL, *ab_over = NULL; -static Eina_Bool ab_out = EINA_FALSE; -static Ecore_Timer *ab_del_timer = NULL; -static Evas_Object *saved_win = NULL; -static Evas_Object *saved_bg = NULL; -static void (*ab_donecb) (void *data) = NULL; -static void *ab_donedata = NULL; + +struct about_ctx { + Evas_Object *layout; + Evas_Object *over; + Evas_Object *win; + Evas_Object *bg; + Evas_Object *term; + void (*donecb) (void *data); + void *donedata; +}; + static Eina_Bool -_cb_ab_del_delay(void *_data EINA_UNUSED) +_cb_del_delay(void *data) { - evas_object_del(ab_layout); - ab_layout = NULL; - ab_del_timer = NULL; + Evas_Object *layout = data; + evas_object_del(layout); elm_cache_all_flush(); return EINA_FALSE; } @@ -29,170 +33,166 @@ _cb_mouse_down(void *data, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - about_toggle(saved_win, saved_bg, data, ab_donecb, ab_donedata); + struct about_ctx *ctx = data; + + if (ctx->over) + { + evas_object_del(ctx->over); + } + elm_object_focus_set(ctx->layout, EINA_FALSE); + edje_object_signal_emit(ctx->bg, "about,hide", "terminology"); + + ecore_timer_add(10.0, _cb_del_delay, ctx->layout); + ctx->layout = NULL; + + if (ctx->donecb) + ctx->donecb(ctx->donedata); + + free(ctx); } void -about_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o; + struct about_ctx *ctx; + Config *config = termio_config_get(term); + char buf[PATH_MAX]; + const char *txt; - saved_win = win; - saved_bg = bg; - if (!ab_layout) - { - Config *config = termio_config_get(term); - char buf[PATH_MAX]; - const char *txt; + ctx = malloc(sizeof(*ctx)); + assert(ctx); - ab_layout = o = elm_layout_add(win); - if (elm_layout_file_set(o, config_theme_path_get(config), - "terminology/about") == 0) - { - snprintf(buf, sizeof(buf), "%s/themes/default.edj", - elm_app_data_dir_get()); - elm_layout_file_set(o, buf, "terminology/about"); - } + ctx->win = win; + ctx->bg = bg; + ctx->term = term; + ctx->donecb = donecb; + ctx->donedata = donedata; - txt = eina_stringshare_printf(_( - "Terminology %s
" - "Why should terminals be boring?
" - "
" - "This terminal was written for Enlightenment, to use EFL " - "and otherwise push the boundaries of what a modern terminal " - "emulator should be. We hope you enjoy it.
" - "
" - "Copyright Ā© 2012-%d by:
" - "
" - "%s" // AUTHORS - "
" - "
" - "Distributed under the 2-clause BSD license detailed below:
" - "
" - "%s" // LICENSE - ), - PACKAGE_VERSION, 2017, - "Boris Faure
" - "Carsten Haitzler
" - "Gustavo Sverzut Barbieri
" - "Cedric BAIL
" - "Sebastian Dransfeld
" - "Wonguk Jeong
" - "Christopher Michael
" - "Daniel Juyung Seo
" - "Panagiotis Galatsanos
" - "Mike Blumenkrantz
" - "Aleksandar Popadić
" - "Massimo Maiurana
" - "Stefan Schmidt
" - "Davide Andreoli
" - "Gustavo Lima Chaves
" - "Jean-Philippe ANDRƉ
" - "Tom Hacohen
" - "Alex-P. Natsios
" - "Lee Gwang-O
" - "Jean Guyomarc'h
" - "Jihoon Kim
" - "Kai Huuhko
" - "Mike McCormack
" - "IvƔn Briano
" - "Jerome Pinot
" - "JosƩ Roberto de Souza
" - "Leandro Pereira
" - "Leif Middelschulte
" - "Markus Tƶrnqvist
" - "Thibaut Broggi
" - "Lucas De Marchi
" - "Marcel Hollerbach
" - "Anisse Astier
" - "Daniel Zaoui
" - "Doug Newgard
" - "Flavio Vinicius Alvares Ceolin
" - "Samuel F. Baggen
" - "Amitesh Singh
" - "Anthony F McInerney
" - "AurƩlien Larcher
" - "Bruno Dilly
" - "Conrad Meyer
" - "Daniel Kolesa
" - "Eduardo Lima
" - "Flavio Ceolin
" - "Jason L. Cook
" - "JƩrƩmy Anger
" - "Michael BOUCHAUD
" - "Michael Jennings
" - "Nicholas Hughart
" - "Rafael Antognolli
" - "Rui Seabra
" - "Sanjeev BA
" - "Theodor van Nahl
" - "Vincent Torri
" - "tantSinnister
", - "All rights reserved.
" - "
" - "Redistribution and use in source and binary forms, with or " - "without modification, are permitted provided that the " - "following conditions are met:
" - "
" - "1. Redistributions of source code must retain the above " - "copyright notice, this list of conditions and the following " - "disclaimer.
" - "2. Redistributions in binary form must reproduce the above " - "copyright notice, this list of conditions and the following " - "disclaimer in the documentation and/or other materials " - "provided with the distribution.
" - "
" - "THIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY EXPRESS OR " - "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED " - "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR " - "PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER " - "OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, " - "INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES " - "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE " - "GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS " - "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " - "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING " - "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF " - "THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH " - "DAMAGE."); - elm_object_part_text_set(o, "terminology.text", txt); - eina_stringshare_del(txt); - evas_object_show(o); - edje_object_part_swallow(bg, "terminology.about", ab_layout); - } - if (!ab_out) + ctx->layout = o = elm_layout_add(win); + if (elm_layout_file_set(o, config_theme_path_get(config), + "terminology/about") == 0) { - ab_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); - evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(bg, "terminology.dismiss", o); - evas_object_show(o); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down, term); - - edje_object_signal_emit(bg, "about,show", "terminology"); - elm_object_signal_emit(ab_layout, "begin" ,"terminology"); - ab_out = EINA_TRUE; - ab_donecb = donecb; - ab_donedata = donedata; - elm_object_focus_set(ab_layout, EINA_TRUE); - if (ab_del_timer) - { - ecore_timer_del(ab_del_timer); - ab_del_timer = NULL; - } - } - else - { - evas_object_del(ab_over); - ab_over = NULL; - - edje_object_signal_emit(bg, "about,hide", "terminology"); - ab_out = EINA_FALSE; - elm_object_focus_set(ab_layout, EINA_FALSE); - if (ab_donecb) ab_donecb(ab_donedata); -// elm_object_focus_set(term, EINA_TRUE); - if (ab_del_timer) ecore_timer_del(ab_del_timer); - ab_del_timer = ecore_timer_add(10.0, _cb_ab_del_delay, NULL); + snprintf(buf, sizeof(buf), "%s/themes/default.edj", + elm_app_data_dir_get()); + elm_layout_file_set(o, buf, "terminology/about"); } + + txt = eina_stringshare_printf(_( + "Terminology %s
" + "Why should terminals be boring?
" + "
" + "This terminal was written for Enlightenment, to use EFL " + "and otherwise push the boundaries of what a modern terminal " + "emulator should be. We hope you enjoy it.
" + "
" + "Copyright Ā© 2012-%d by:
" + "
" + "%s" // AUTHORS + "
" + "
" + "Distributed under the 2-clause BSD license detailed below:
" + "
" + "%s" // LICENSE + ), + PACKAGE_VERSION, 2017, + "Boris Faure
" + "Carsten Haitzler
" + "Gustavo Sverzut Barbieri
" + "Cedric BAIL
" + "Sebastian Dransfeld
" + "Wonguk Jeong
" + "Christopher Michael
" + "Daniel Juyung Seo
" + "Panagiotis Galatsanos
" + "Mike Blumenkrantz
" + "Aleksandar Popadić
" + "Massimo Maiurana
" + "Stefan Schmidt
" + "Davide Andreoli
" + "Gustavo Lima Chaves
" + "Jean-Philippe ANDRƉ
" + "Tom Hacohen
" + "Alex-P. Natsios
" + "Lee Gwang-O
" + "Jean Guyomarc'h
" + "Jihoon Kim
" + "Kai Huuhko
" + "Mike McCormack
" + "IvƔn Briano
" + "Jerome Pinot
" + "JosƩ Roberto de Souza
" + "Leandro Pereira
" + "Leif Middelschulte
" + "Markus Tƶrnqvist
" + "Thibaut Broggi
" + "Lucas De Marchi
" + "Marcel Hollerbach
" + "Anisse Astier
" + "Daniel Zaoui
" + "Doug Newgard
" + "Flavio Vinicius Alvares Ceolin
" + "Samuel F. Baggen
" + "Amitesh Singh
" + "Anthony F McInerney
" + "AurƩlien Larcher
" + "Bruno Dilly
" + "Conrad Meyer
" + "Daniel Kolesa
" + "Eduardo Lima
" + "Flavio Ceolin
" + "Jason L. Cook
" + "JƩrƩmy Anger
" + "Michael BOUCHAUD
" + "Michael Jennings
" + "Nicholas Hughart
" + "Rafael Antognolli
" + "Rui Seabra
" + "Sanjeev BA
" + "Theodor van Nahl
" + "Vincent Torri
" + "tantSinnister
", + "All rights reserved.
" + "
" + "Redistribution and use in source and binary forms, with or " + "without modification, are permitted provided that the " + "following conditions are met:
" + "
" + "1. Redistributions of source code must retain the above " + "copyright notice, this list of conditions and the following " + "disclaimer.
" + "2. Redistributions in binary form must reproduce the above " + "copyright notice, this list of conditions and the following " + "disclaimer in the documentation and/or other materials " + "provided with the distribution.
" + "
" + "THIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY EXPRESS OR " + "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED " + "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR " + "PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER " + "OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, " + "INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES " + "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE " + "GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS " + "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " + "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING " + "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF " + "THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH " + "DAMAGE."); + elm_object_part_text_set(o, "terminology.text", txt); + eina_stringshare_del(txt); + evas_object_show(o); + edje_object_part_swallow(bg, "terminology.about", ctx->layout); + + ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); + evas_object_color_set(o, 0, 0, 0, 0); + edje_object_part_swallow(bg, "terminology.dismiss", o); + evas_object_show(o); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + _cb_mouse_down, ctx); + + edje_object_signal_emit(bg, "about,show", "terminology"); + elm_object_signal_emit(ctx->layout, "begin" ,"terminology"); + elm_object_focus_set(ctx->layout, EINA_TRUE); } diff --git a/src/bin/about.h b/src/bin/about.h index 54e03acd..71138e15 100644 --- a/src/bin/about.h +++ b/src/bin/about.h @@ -1,7 +1,7 @@ #ifndef _ABOUT_H__ #define _ABOUT_H__ 1 -void about_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +void about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); #endif diff --git a/src/bin/controls.c b/src/bin/controls.c index d16e29e0..15335a53 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -49,7 +49,7 @@ _cb_sel_off(void *data, } static Eina_Bool -_cb_ct_del_delay(void *data) +_cb_del_delay(void *data) { Evas_Object *frame = data; evas_object_del(frame); @@ -159,7 +159,7 @@ _cb_ct_about(void *data, { struct controls_ctx *ctx = data; - about_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + about_show(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); controls_hide(ctx, EINA_FALSE); } @@ -259,7 +259,7 @@ controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb) } elm_object_focus_set(ctx->frame, EINA_FALSE); - ecore_timer_add(10.0, _cb_ct_del_delay, ctx->frame); + ecore_timer_add(10.0, _cb_del_delay, ctx->frame); ctx->frame = NULL; if (call_cb && ctx->donecb) From fd150de2226bdde9d9bba6a50721492ea6a93316 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 5 Jan 2018 00:16:14 +0100 Subject: [PATCH 08/36] options: simplify code and no more globals --- src/bin/controls.c | 2 +- src/bin/options.c | 361 ++++++++++++++++++++++++--------------------- src/bin/options.h | 2 +- 3 files changed, 192 insertions(+), 173 deletions(-) diff --git a/src/bin/controls.c b/src/bin/controls.c index 15335a53..98d64681 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -148,7 +148,7 @@ _cb_ct_options(void *data, { struct controls_ctx *ctx = data; - options_toggle(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + options_show(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); controls_hide(ctx, EINA_FALSE); } diff --git a/src/bin/options.c b/src/bin/options.c index 381a22d4..c4ee74c9 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include "options.h" #include "options_font.h" #include "options_theme.h" @@ -14,17 +15,8 @@ #include "config.h" #include "termio.h" -static Evas_Object *op_frame, *op_box = NULL, *op_toolbar = NULL, - *op_opbox = NULL, *op_tbox = NULL, *op_temp = NULL, - *op_over = NULL; -static Eina_Bool op_out = EINA_FALSE; -static Ecore_Timer *op_del_timer = NULL; -static Evas_Object *saved_win = NULL; -static Evas_Object *saved_bg = NULL; -static void (*op_donecb) (void *data) = NULL; -static void *op_donedata = NULL; -static enum option_mode { +enum option_mode { OPTION_NONE = 0, OPTION_FONT, OPTION_THEME, @@ -34,229 +26,256 @@ static enum option_mode { OPTION_BEHAVIOR, OPTION_KEYS, OPTION_HELPERS, - OPTION_ELM -} _mode = 0; + OPTION_ELM, + + OPTIONS_MODE_NB +}; + +struct options_ctx { + enum option_mode mode; + Evas_Object *frame; + Evas_Object *toolbar; + Evas_Object *opbox; + Evas_Object *over; + Evas_Object *win; + Evas_Object *bg; + Evas_Object *term; + Config *config; + void (*donecb) (void *data); + void *donedata; + struct options_ctx *modes[OPTIONS_MODE_NB]; +}; static void _cb_op(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - enum option_mode mode = (intptr_t) data; + struct options_ctx **pctx = data; + struct options_ctx *ctx = *pctx; + enum option_mode mode = pctx - ctx->modes; - if (_mode == mode) return; - _mode = mode; - edje_object_signal_emit(saved_bg, "optdetails,hide", "terminology"); + if (mode == ctx->mode) + return; + + ctx->mode = mode; + + edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology"); } static void _cb_op_tmp_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Config *config = data; + struct options_ctx *ctx = data; + Config *config = ctx->config; + config->temporary = elm_check_state_get(obj); } static Eina_Bool -_cb_op_del_delay(void *_data EINA_UNUSED) +_cb_op_del_delay(void *data) { - evas_object_del(op_opbox); - evas_object_del(op_frame); + struct options_ctx *ctx = data; + + evas_object_del(ctx->opbox); + evas_object_del(ctx->frame); options_font_clear(); options_background_clear(); options_theme_clear(); - op_opbox = NULL; - op_frame = NULL; - op_del_timer = NULL; + + free(ctx); elm_cache_all_flush(); return EINA_FALSE; } -static void -_cb_mouse_down(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_ev EINA_UNUSED) -{ - options_toggle(saved_win, saved_bg, data, op_donecb, op_donedata); -} - static void _cb_opdt_hide_done(void *data, Evas_Object *_obj EINA_UNUSED, const char *_sig EINA_UNUSED, const char *_src EINA_UNUSED) { - elm_box_clear(op_opbox); - switch (_mode) + struct options_ctx *ctx = data; + + elm_box_clear(ctx->opbox); + switch (ctx->mode) { case OPTION_NONE: break; - case OPTION_FONT: options_font(op_opbox, data); break; - case OPTION_THEME: options_theme(op_opbox, data); break; - case OPTION_BACKGROUND: options_background(op_opbox, data); break; - case OPTION_COLORS: options_colors(op_opbox, data); break; - case OPTION_VIDEO: options_video(op_opbox, data); break; - case OPTION_BEHAVIOR: options_behavior(op_opbox, data); break; - case OPTION_KEYS: options_keys(op_opbox, data); break; - case OPTION_HELPERS: options_helpers(op_opbox, data); break; - case OPTION_ELM: options_elm(op_opbox, data); break; + case OPTION_FONT: options_font(ctx->opbox, ctx->term); break; + case OPTION_THEME: options_theme(ctx->opbox, ctx->term); break; + case OPTION_BACKGROUND: options_background(ctx->opbox, ctx->term); break; + case OPTION_COLORS: options_colors(ctx->opbox, ctx->term); break; + case OPTION_VIDEO: options_video(ctx->opbox, ctx->term); break; + case OPTION_BEHAVIOR: options_behavior(ctx->opbox, ctx->term); break; + case OPTION_KEYS: options_keys(ctx->opbox, ctx->term); break; + case OPTION_HELPERS: options_helpers(ctx->opbox, ctx->term); break; + case OPTION_ELM: options_elm(ctx->opbox, ctx->term); break; + case OPTIONS_MODE_NB: assert(0 && "should not occur"); } - edje_object_signal_emit(saved_bg, "optdetails,show", "terminology"); + edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology"); } static void -_cb_opdt_hide_done2(void *_data EINA_UNUSED, +_cb_opdt_hide_done2(void *data, Evas_Object *_obj EINA_UNUSED, const char *_sig EINA_UNUSED, const char *_src EINA_UNUSED) { - if (op_del_timer) - { - ecore_timer_del(op_del_timer); - op_del_timer = NULL; - } - _cb_op_del_delay(NULL); - edje_object_signal_callback_del(saved_bg, "optdetails,hide,done", + struct options_ctx *ctx = data; + + edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done", "terminology", _cb_opdt_hide_done2); + ecore_timer_add(10.0, _cb_op_del_delay, ctx); } +static void +options_hide(struct options_ctx *ctx) +{ + edje_object_part_swallow(ctx->bg, "terminology.optdetails", ctx->opbox); + edje_object_part_swallow(ctx->bg, "terminology.options", ctx->frame); + edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology"); + edje_object_signal_emit(ctx->bg, "options,show", "terminology"); + + edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done", + "terminology", + _cb_opdt_hide_done); + edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done", + "terminology", + _cb_opdt_hide_done2, ctx); + elm_object_focus_set(ctx->frame, EINA_FALSE); + elm_object_focus_set(ctx->opbox, EINA_FALSE); + elm_object_focus_set(ctx->toolbar, EINA_FALSE); + + evas_object_del(ctx->over); + ctx->over = NULL; + + edje_object_signal_emit(ctx->bg, "options,hide", "terminology"); + edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology"); + + if (ctx->donecb) + ctx->donecb(ctx->donedata); +} + +static void +_cb_mouse_down(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_ev EINA_UNUSED) +{ + struct options_ctx *ctx = data; + + options_hide(ctx); +} + + void -options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { - Evas_Object *o; + Evas_Object *o, *op_box, *op_tbox; + struct options_ctx *ctx; + int i = 0; - _mode = OPTION_NONE; - if (!op_frame) - { - Elm_Object_Item *it_fn; - Config *config = termio_config_get(term); - - if (!config) return; - saved_win = win; - saved_bg = bg; - - op_opbox = o = elm_box_add(win); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - edje_object_part_swallow(bg, "terminology.optdetails", o); - evas_object_show(o); + Elm_Object_Item *it_fn; + Config *config = termio_config_get(term); - op_frame = o = elm_frame_add(win); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_text_set(o, _("Options")); + if (!config) return; - op_box = o = elm_box_add(win); - elm_box_horizontal_set(o, EINA_TRUE); - elm_object_content_set(op_frame, o); - evas_object_show(o); + ctx = malloc(sizeof(*ctx)); + assert(ctx); + ctx->mode = OPTION_NONE; + ctx->win = win; + ctx->bg = bg; + ctx->term = term; + ctx->donecb = donecb; + ctx->donedata = donedata; + ctx->config = config; - op_tbox = o = elm_box_add(win); - evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, 1.0, EVAS_HINT_FILL); - elm_box_pack_end(op_box, o); - evas_object_show(o); - - op_toolbar = o = elm_toolbar_add(win); - evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL); - elm_toolbar_horizontal_set(o, EINA_FALSE); - elm_object_style_set(o, "item_horizontal"); - elm_toolbar_icon_size_set(o, 16 * elm_config_scale_get()); - elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL); - elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS); - elm_toolbar_menu_parent_set(o, win); - elm_toolbar_homogeneous_set(o, EINA_FALSE); + for (i = 0; i < OPTIONS_MODE_NB; i++) + ctx->modes[i] = ctx; + + ctx->opbox = o = elm_box_add(win); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + edje_object_part_swallow(ctx->bg, "terminology.optdetails", o); + evas_object_show(o); + + ctx->frame = o = elm_frame_add(win); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_text_set(o, _("Options")); + + op_box = o = elm_box_add(win); + elm_box_horizontal_set(o, EINA_TRUE); + elm_object_content_set(ctx->frame, o); + evas_object_show(o); + + op_tbox = o = elm_box_add(win); + evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, 1.0, EVAS_HINT_FILL); + elm_box_pack_end(op_box, o); + evas_object_show(o); + + ctx->toolbar = o = elm_toolbar_add(win); + evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL); + elm_toolbar_horizontal_set(o, EINA_FALSE); + elm_object_style_set(o, "item_horizontal"); + elm_toolbar_icon_size_set(o, 16 * elm_config_scale_get()); + elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL); + elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS); + elm_toolbar_menu_parent_set(o, win); + elm_toolbar_homogeneous_set(o, EINA_FALSE); #define ITEM_APPEND(_icon_name, _name, _option_mode) \ - elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \ - (void*) OPTION_##_option_mode) + elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \ + (void*) &ctx->modes[OPTION_##_option_mode]) - it_fn = - ITEM_APPEND("preferences-desktop-font", _("Font"), FONT); - ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME); - ITEM_APPEND("preferences-desktop-background", _("Background"), BACKGROUND); - ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS); - ITEM_APPEND("video-display", _("Video"), VIDEO); - ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR); - ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS); - ITEM_APPEND("system-run", _("Helpers"), HELPERS); - ITEM_APPEND("preferences-color", _("Toolkit"), ELM); + it_fn = + ITEM_APPEND("preferences-desktop-font", _("Font"), FONT); + ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME); + ITEM_APPEND("preferences-desktop-background", _("Background"), BACKGROUND); + ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS); + ITEM_APPEND("video-display", _("Video"), VIDEO); + ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR); + ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS); + ITEM_APPEND("system-run", _("Helpers"), HELPERS); + ITEM_APPEND("preferences-color", _("Toolkit"), ELM); #undef ITEM_APPEND - elm_box_pack_end(op_tbox, o); - evas_object_show(o); + elm_box_pack_end(op_tbox, o); + evas_object_show(o); - elm_toolbar_item_selected_set(it_fn, EINA_TRUE); - - op_temp = o = elm_check_add(win); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 1.0); - elm_object_text_set(o, _("Temporary")); - elm_check_state_set(o, config->temporary); - elm_box_pack_end(op_tbox, o); - evas_object_show(o); - evas_object_smart_callback_add(o, "changed", _cb_op_tmp_chg, config); + elm_toolbar_item_selected_set(it_fn, EINA_TRUE); - edje_object_part_swallow(bg, "terminology.options", op_frame); - evas_object_show(op_frame); - } - else if ((op_opbox) && (!op_out)) - { - edje_object_part_swallow(bg, "terminology.optdetails", op_opbox); - edje_object_part_swallow(bg, "terminology.options", op_frame); - edje_object_signal_emit(bg, "optdetails,show", "terminology"); - edje_object_signal_emit(bg, "options,show", "terminology"); - } - - if (!op_out) - { - edje_object_signal_callback_add(bg, "optdetails,hide,done", - "terminology", - _cb_opdt_hide_done, term); - op_over = o = evas_object_rectangle_add(evas_object_evas_get(win)); - evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(bg, "terminology.dismiss", o); - evas_object_show(o); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down, term); + o = elm_check_add(win); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 1.0); + elm_object_text_set(o, _("Temporary")); + elm_check_state_set(o, config->temporary); + elm_box_pack_end(op_tbox, o); + evas_object_show(o); + evas_object_smart_callback_add(o, "changed", _cb_op_tmp_chg, ctx); - edje_object_signal_emit(bg, "options,show", "terminology"); - op_out = EINA_TRUE; - op_donecb = donecb; - op_donedata = donedata; - elm_object_focus_set(op_toolbar, EINA_TRUE); - if (op_del_timer) - { - ecore_timer_del(op_del_timer); - op_del_timer = NULL; - } - } - else - { - edje_object_signal_callback_del(bg, "optdetails,hide,done", - "terminology", - _cb_opdt_hide_done); - edje_object_signal_callback_add(bg, "optdetails,hide,done", - "terminology", - _cb_opdt_hide_done2, term); - elm_object_focus_set(op_frame, EINA_FALSE); - elm_object_focus_set(op_opbox, EINA_FALSE); - elm_object_focus_set(op_toolbar, EINA_FALSE); - if (op_donecb) op_donecb(op_donedata); - evas_object_del(op_over); - op_over = NULL; - edje_object_signal_emit(bg, "options,hide", "terminology"); - edje_object_signal_emit(bg, "optdetails,hide", "terminology"); - op_out = EINA_FALSE; - if (op_del_timer) ecore_timer_del(op_del_timer); - op_del_timer = ecore_timer_add(10.0, _cb_op_del_delay, NULL); - } + edje_object_part_swallow(bg, "terminology.options", ctx->frame); + evas_object_show(ctx->frame); + + edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done", + "terminology", + _cb_opdt_hide_done, ctx); + ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); + evas_object_color_set(o, 0, 0, 0, 0); + edje_object_part_swallow(ctx->bg, "terminology.dismiss", o); + evas_object_show(o); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + _cb_mouse_down, ctx); + + edje_object_signal_emit(ctx->bg, "options,show", "terminology"); + elm_object_focus_set(ctx->toolbar, EINA_TRUE); } Eina_Bool options_is_active(Evas_Object *win EINA_UNUSED) { - return op_out; + return EINA_FALSE; } diff --git a/src/bin/options.h b/src/bin/options.h index 007361c8..a530a42c 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -1,7 +1,7 @@ #ifndef _TERMINOLOGY_OPTIONS_H__ #define _TERMINOLOGY_OPTIONS_H__ 1 -void options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +void options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); Eina_Bool options_is_active(Evas_Object *win); From 08b5c20a27a8436f39083cd0d72315a376c42d51 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 5 Jan 2018 23:42:14 +0100 Subject: [PATCH 09/36] controls: keep ctx when on about/options --- src/bin/controls.c | 36 ++++++++++++++++++++++++++++-------- src/bin/options.c | 6 ------ src/bin/options.h | 2 -- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/bin/controls.c b/src/bin/controls.c index 98d64681..a472114d 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -141,6 +141,22 @@ _cb_ct_close(void *data, term_close(win, term, EINA_FALSE); } +static void +_on_sub_done(void *data) +{ + struct controls_ctx *ctx = data; + + ecore_timer_add(10.0, _cb_del_delay, ctx->frame); + ctx->frame = NULL; + + if (ctx->donecb) + ctx->donecb(ctx->donedata); + + eina_hash_del(controls, &ctx->win, ctx); + + free(ctx); +} + static void _cb_ct_options(void *data, Evas_Object *_obj EINA_UNUSED, @@ -148,10 +164,11 @@ _cb_ct_options(void *data, { struct controls_ctx *ctx = data; - options_show(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + options_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); } + static void _cb_ct_about(void *data, Evas_Object *_obj EINA_UNUSED, @@ -159,7 +176,7 @@ _cb_ct_about(void *data, { struct controls_ctx *ctx = data; - about_show(ctx->win, ctx->bg, ctx->term, ctx->donecb, ctx->donedata); + about_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); } @@ -259,15 +276,18 @@ controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb) } elm_object_focus_set(ctx->frame, EINA_FALSE); - ecore_timer_add(10.0, _cb_del_delay, ctx->frame); - ctx->frame = NULL; + if (call_cb) + { + ecore_timer_add(10.0, _cb_del_delay, ctx->frame); + ctx->frame = NULL; - if (call_cb && ctx->donecb) - ctx->donecb(ctx->donedata); + if (ctx->donecb) + ctx->donecb(ctx->donedata); - eina_hash_del(controls, &ctx->win, ctx); + eina_hash_del(controls, &ctx->win, ctx); - free(ctx); + free(ctx); + } } diff --git a/src/bin/options.c b/src/bin/options.c index c4ee74c9..63ef8638 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -273,9 +273,3 @@ options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, edje_object_signal_emit(ctx->bg, "options,show", "terminology"); elm_object_focus_set(ctx->toolbar, EINA_TRUE); } - -Eina_Bool -options_is_active(Evas_Object *win EINA_UNUSED) -{ - return EINA_FALSE; -} diff --git a/src/bin/options.h b/src/bin/options.h index a530a42c..e02a039e 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -3,7 +3,5 @@ void options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); -Eina_Bool options_is_active(Evas_Object *win); - #endif From 29db075729416e2f7ad77a49d5a013266c16cc39 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 7 Jan 2018 23:11:18 +0100 Subject: [PATCH 10/36] options_keys: rewrite it to have multiple widgets at the same time --- src/bin/options_keys.c | 212 +++++++++++++++++++++++------------------ 1 file changed, 118 insertions(+), 94 deletions(-) diff --git a/src/bin/options_keys.c b/src/bin/options_keys.c index 95997d1c..0776dcc4 100644 --- a/src/bin/options_keys.c +++ b/src/bin/options_keys.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include "config.h" #include "termio.h" #include "options.h" @@ -8,12 +9,14 @@ #include "keyin.h" #include "utils.h" -/*XXX: can have only one widget at a timeā€¦ */ -static Config *_config; -static Evas_Object *_fr; -static Evas_Object *_layout; +struct keys_ctx { + Config *config; + Evas_Object *frame; + Evas_Object *gl; + Evas_Object *layout; +}; -static void _hover_del(Evas_Object *o); +static void _hover_del(struct keys_ctx *ctx); static void _shortcut_delete(void *data, @@ -23,12 +26,17 @@ _shortcut_delete(void *data, Evas_Object *hs, *bx; Config_Keys *cfg_key; Evas_Coord w, min_w, min_h; + struct keys_ctx *ctx; hs = data; bx = evas_object_data_get(hs, "bx"); + assert(bx); cfg_key = evas_object_data_get(hs, "cfg"); + assert(cfg_key); + ctx = evas_object_data_get(hs, "ctx"); + assert(ctx); - _config->keys = eina_list_remove(_config->keys, cfg_key); + ctx->config->keys = eina_list_remove(ctx->config->keys, cfg_key); evas_object_size_hint_min_get(hs, &w, NULL); evas_object_size_hint_min_get(bx, &min_w, &min_h); min_w -= w; @@ -41,11 +49,13 @@ _shortcut_delete(void *data, eina_stringshare_del(cfg_key->cb); free(cfg_key); - config_save(_config, NULL); + config_save(ctx->config, NULL); } static Evas_Object * -_shortcut_button_add(Evas_Object *bx, const Config_Keys *key) +_shortcut_button_add(struct keys_ctx *ctx, + Evas_Object *bx, + const Config_Keys *key) { const char *txt; Evas_Object *hs; @@ -58,11 +68,13 @@ _shortcut_button_add(Evas_Object *bx, const Config_Keys *key) key->meta ? _("Meta+") : "", key->hyper ? _("Hyper+") : "", key->keyname); - hs = elm_hoversel_add(_fr); - elm_hoversel_hover_parent_set(hs, _fr); + hs = elm_hoversel_add(ctx->frame); + elm_hoversel_hover_parent_set(hs, ctx->frame); evas_object_data_set(hs, "bx", bx); evas_object_data_set(hs, "cfg", key); + evas_object_data_set(hs, "ctx", ctx); + elm_layout_text_set(hs, NULL, txt); elm_hoversel_item_add(hs, _("Delete"), "delete", ELM_ICON_STANDARD, @@ -75,17 +87,22 @@ _shortcut_button_add(Evas_Object *bx, const Config_Keys *key) static void _cb_key_up(void *data, Evas *_e EINA_UNUSED, - Evas_Object *obj, void *event) + Evas_Object *obj EINA_UNUSED, + void *event) { Evas_Event_Key_Up *ev = event; int ctrl, alt, shift, win, meta, hyper, res; Config_Keys *cfg_key; Shortcut_Action *action; Evas_Object *bx = data; + struct keys_ctx *ctx; if (key_is_modifier(ev->keyname)) return; + ctx = evas_object_data_get(bx, "ctx"); + assert(ctx); + ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); @@ -95,7 +112,7 @@ _cb_key_up(void *data, evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"); hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper"); - _hover_del(obj); + _hover_del(ctx); action = evas_object_data_get(bx, "action"); if (!action) @@ -123,8 +140,8 @@ _cb_key_up(void *data, Evas_Coord w, h, min_w, min_h; last = evas_object_data_get(bx, "last"); - _config->keys = eina_list_append(_config->keys, cfg_key); - bt = _shortcut_button_add(bx, cfg_key); + ctx->config->keys = eina_list_append(ctx->config->keys, cfg_key); + bt = _shortcut_button_add(ctx, bx, cfg_key); evas_object_show(bt); evas_object_size_hint_min_get(bt, &w, &h); evas_object_size_hint_min_get(bx, &min_w, &min_h); @@ -133,7 +150,7 @@ _cb_key_up(void *data, evas_object_size_hint_min_set(bx, min_w, min_h); elm_box_pack_before(bx, bt, last); - config_save(_config, NULL); + config_save(ctx->config, NULL); } else { @@ -144,44 +161,49 @@ _cb_key_up(void *data, } static void -_cb_mouse_down(void *_data EINA_UNUSED, +_cb_mouse_down(void *data, Evas *_e EINA_UNUSED, - Evas_Object *obj, + Evas_Object *obj EINA_UNUSED, void *_event EINA_UNUSED) { - _hover_del(obj); + struct keys_ctx *ctx = data; + + _hover_del(ctx); } static void -_hover_sizing_eval(void) +_hover_sizing_eval(struct keys_ctx *ctx) { Evas_Coord x = 0, y = 0, w = 0, h = 0; - evas_object_geometry_get(_fr, &x, &y, &w, &h); + + evas_object_geometry_get(ctx->frame, &x, &y, &w, &h); #if (ECORE_VERSION_MAJOR > 1) || (ECORE_VERSION_MINOR >= 8) - evas_object_geometry_set(_layout, x, y, w, h); + evas_object_geometry_set(ctx->layout, x, y, w, h); #else - evas_object_move(_layout, x, y); - evas_object_resize(_layout, w, h); + evas_object_move(ctx->layout, x, y); + evas_object_resize(ctx->layout, w, h); #endif } static void -_parent_move_cb(void *_data EINA_UNUSED, +_parent_move_cb(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - _hover_sizing_eval(); + struct keys_ctx *ctx = data; + _hover_sizing_eval(ctx); } static void -_parent_resize_cb(void *_data EINA_UNUSED, +_parent_resize_cb(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - _hover_sizing_eval(); + struct keys_ctx *ctx = data; + _hover_sizing_eval(ctx); } static void @@ -190,88 +212,74 @@ _parent_hide_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - _hover_del(data); + struct keys_ctx *ctx = data; + _hover_del(ctx); } + static void _parent_del_cb(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - _hover_del(data); -} + struct keys_ctx *ctx = data; + _hover_del(ctx); -static void -_hover_del(Evas_Object *o) -{ - evas_object_event_callback_del(o, EVAS_CALLBACK_KEY_UP, - _cb_key_up); - evas_object_event_callback_del(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down); - evas_object_event_callback_del(_fr, EVAS_CALLBACK_MOVE, - _parent_move_cb); - evas_object_event_callback_del(_fr, EVAS_CALLBACK_RESIZE, - _parent_resize_cb); - evas_object_event_callback_del(_fr, EVAS_CALLBACK_HIDE, - _parent_hide_cb); - evas_object_event_callback_del(_fr, EVAS_CALLBACK_DEL, + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_DEL, _parent_del_cb); - evas_object_del(o); - _layout = NULL; + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_HIDE, + _parent_hide_cb); + free(ctx); } static void -_cb_focused(void *_data EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_event EINA_UNUSED) +_hover_del(struct keys_ctx *ctx) { - DBG("focused"); -} -static void -_cb_unfocused(void *_data EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *_event EINA_UNUSED) -{ - DBG("unfocused"); - if (_layout) - elm_object_focus_set(_layout, EINA_TRUE); + if (ctx->layout) + { + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_KEY_UP, + _cb_key_up); + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_MOUSE_DOWN, + _cb_mouse_down); + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_MOVE, + _parent_move_cb); + evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_RESIZE, + _parent_resize_cb); + evas_object_del(ctx->layout); + } + ctx->layout = NULL; } static void -on_shortcut_add(void *data, - Evas_Object *bt, - void *_event_info EINA_UNUSED) +_on_shortcut_add(void *data, + Evas_Object *bt, + void *_event_info EINA_UNUSED) { Evas_Object *o, *oe; Evas_Object *bx = data; + struct keys_ctx *ctx; - _layout = o = elm_layout_add(bt); + ctx = evas_object_data_get(bx, "ctx"); + assert(ctx); + + assert(ctx->layout == NULL); + ctx->layout = o = elm_layout_add(bt); + evas_object_data_set(ctx->layout, "ctx", ctx); oe = elm_layout_edje_get(o); - theme_apply(oe, _config, "terminology/keybinding"); + theme_apply(oe, ctx->config, "terminology/keybinding"); theme_auto_reload_enable(oe); elm_layout_text_set(o, "label", _("Please press key sequence")); evas_object_show(o); - elm_object_focus_allow_set(o, EINA_TRUE); - evas_object_smart_callback_add(o, "focused", - _cb_focused, NULL); - evas_object_smart_callback_add(o, "unfocused", - _cb_unfocused, NULL); - elm_object_focus_set(o, EINA_TRUE); - _hover_sizing_eval(); - - evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_UP, + evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_KEY_UP, _cb_key_up, bx); - evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - _cb_mouse_down, o); - evas_object_event_callback_add(_fr, EVAS_CALLBACK_MOVE, - _parent_move_cb, o); - evas_object_event_callback_add(_fr, EVAS_CALLBACK_RESIZE, - _parent_resize_cb, o); - evas_object_event_callback_add(_fr, EVAS_CALLBACK_HIDE, - _parent_hide_cb, o); - evas_object_event_callback_add(_fr, EVAS_CALLBACK_DEL, - _parent_del_cb, o); + evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_MOUSE_DOWN, + _cb_mouse_down, ctx); + elm_object_focus_set(ctx->frame, EINA_TRUE); + elm_object_focus_allow_set(ctx->frame, EINA_TRUE); + + _hover_sizing_eval(ctx); + } static Evas_Object * @@ -282,11 +290,16 @@ gl_content_get(void *data, Evas_Object *obj, const char *_part EINA_UNUSED) Evas_Object *bx, *bt, *lbl, *sep; Config_Keys *key; Eina_List *l; + struct keys_ctx *ctx; + + ctx = evas_object_data_get(obj, "ctx"); + assert(ctx); bx = elm_box_add(obj); elm_box_horizontal_set(bx, EINA_TRUE); elm_box_homogeneous_set(bx, EINA_FALSE); evas_object_size_hint_align_set(bx, 0, 0); + evas_object_data_set(bx, "ctx", ctx); lbl = elm_label_add(obj); elm_layout_text_set(lbl, NULL, action->description); @@ -304,11 +317,11 @@ gl_content_get(void *data, Evas_Object *obj, const char *_part EINA_UNUSED) if (h > min_h) min_h = h; // TODO: have a better data structure - EINA_LIST_FOREACH(_config->keys, l, key) + EINA_LIST_FOREACH(ctx->config->keys, l, key) { if (!strcmp(key->cb, action->action)) { - bt = _shortcut_button_add(bx, key); + bt = _shortcut_button_add(ctx, bx, key); evas_object_show(bt); evas_object_size_hint_min_get(bt, &w, &h); min_w += w; @@ -318,7 +331,7 @@ gl_content_get(void *data, Evas_Object *obj, const char *_part EINA_UNUSED) } bt = elm_button_add(obj); - evas_object_smart_callback_add(bt, "clicked", on_shortcut_add, bx); + evas_object_smart_callback_add(bt, "clicked", _on_shortcut_add, bx); elm_layout_text_set(bt, NULL, "+"); evas_object_size_hint_min_get(bt, &w, &h); min_w += w; @@ -350,10 +363,10 @@ _cb_reset_keys(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - Evas_Object *gl = data; + struct keys_ctx *ctx = data; - config_reset_keys(_config); - elm_genlist_realized_items_update(gl); + config_reset_keys(ctx->config); + elm_genlist_realized_items_update(ctx->gl); } void @@ -363,23 +376,33 @@ options_keys(Evas_Object *opbox, Evas_Object *term) const Shortcut_Action *action; Elm_Genlist_Item_Class *itc, *itc_group; Elm_Object_Item *git = NULL; + Config *config = termio_config_get(term); + struct keys_ctx *ctx; - _config = termio_config_get(term); + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); - _fr = o = elm_frame_add(opbox); + ctx->config = config; + + ctx->frame = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Key Bindings")); elm_box_pack_end(opbox, o); evas_object_show(o); + evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_HIDE, + _parent_hide_cb, ctx); + bx = elm_box_add(opbox); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(bx, 0.0, 0.0); - elm_object_content_set(_fr, bx); + elm_object_content_set(ctx->frame, bx); evas_object_show(bx); - gl = elm_genlist_add(opbox); + ctx->gl = gl = elm_genlist_add(opbox); evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_scroller_policy_set(gl, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_AUTO); @@ -387,6 +410,7 @@ options_keys(Evas_Object *opbox, Evas_Object *term) elm_genlist_homogeneous_set(gl, EINA_FALSE); elm_box_pack_end(bx, gl); evas_object_show(gl); + evas_object_data_set(gl, "ctx", ctx); itc = elm_genlist_item_class_new(); itc->item_style = "one_icon"; @@ -434,5 +458,5 @@ options_keys(Evas_Object *opbox, Evas_Object *term) elm_object_text_set(o, _("Reset bindings")); elm_box_pack_end(bx, o); evas_object_show(o); - evas_object_smart_callback_add(o, "clicked", _cb_reset_keys, gl); + evas_object_smart_callback_add(o, "clicked", _cb_reset_keys, ctx); } From 69e3176f4e36a0d8d18c716386ada69969720a30 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 8 Jan 2018 23:17:02 +0100 Subject: [PATCH 11/36] options_background: rewrite to have multiple widgets --- src/bin/options.c | 1 - src/bin/options_background.c | 383 ++++++++++++++++++++--------------- 2 files changed, 222 insertions(+), 162 deletions(-) diff --git a/src/bin/options.c b/src/bin/options.c index 63ef8638..2798718b 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -80,7 +80,6 @@ _cb_op_del_delay(void *data) evas_object_del(ctx->opbox); evas_object_del(ctx->frame); options_font_clear(); - options_background_clear(); options_theme_clear(); free(ctx); diff --git a/src/bin/options_background.c b/src/bin/options_background.c index 29ca431d..05fe49a9 100644 --- a/src/bin/options_background.c +++ b/src/bin/options_background.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include "config.h" #include "termio.h" #include "media.h" @@ -11,6 +12,24 @@ #include "main.h" #include +typedef struct _Background_Ctx { + Config *config; + Evas_Object *frame; + Evas_Object *flip; + Evas_Object *bg_grid; + Evas_Object *term; + Evas_Object *entry; + Evas_Object *bubble; + Evas_Object *op_trans; + Evas_Object *op_opacity; + Evas_Object *op_shine_slider; + + Eina_Stringshare *system_path; + Eina_Stringshare *user_path; + Eina_List *background_list; + Ecore_Timer *bubble_disappear; +} Background_Ctx; + typedef struct _Background_Item { const char *path; @@ -25,31 +44,14 @@ typedef struct _Insert_Gen_Grid_Item_Notify } Insert_Gen_Grid_Item_Notify; -static Eina_Stringshare *_system_path, - *_user_path; - -static Evas_Object *_bg_grid = NULL, - *_term = NULL, - *_entry = NULL, - *_flip = NULL, - *_bubble = NULL; - -static Eina_List *_backgroundlist = NULL; - -static Ecore_Timer *_bubble_disappear; - -static Ecore_Thread *_thread; -static Evas_Object *op_trans, *op_opacity; -static Evas_Object *op_shine_slider = NULL; - static void _cb_op_shine_sel(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *termio_obj = data; - Config *config = termio_config_get(termio_obj); - Term *term = termio_term_get(termio_obj); + Background_Ctx *ctx = data; + Config *config = ctx->config; + Term *term = termio_term_get(ctx->term); Win *wn = term_win_get(term); int shine = elm_slider_value_get(obj); Eina_List *l, *wn_list; @@ -69,10 +71,11 @@ _cb_op_video_trans_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Background_Ctx *ctx = data; + Config *config = ctx->config; + config->translucent = elm_check_state_get(obj); - elm_object_disabled_set(op_opacity, !config->translucent); + elm_object_disabled_set(ctx->op_opacity, !config->translucent); main_trans_update(config); config_save(config, NULL); } @@ -82,64 +85,70 @@ _cb_op_video_opacity_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Background_Ctx *ctx = data; + Config *config = ctx->config; + config->opacity = elm_slider_value_get(obj); - if (!config->translucent) return; + if (!config->translucent) + return; main_trans_update(config); config_save(config, NULL); } static void -_cb_fileselector(void *_data EINA_UNUSED, +_cb_fileselector(void *data, Evas_Object *obj, void *event) { + Background_Ctx *ctx = data; - if (event) - { - elm_object_text_set(_entry, elm_fileselector_path_get(obj)); - elm_flip_go_to(_flip, EINA_TRUE, ELM_FLIP_PAGE_LEFT); - } - else - { - elm_flip_go_to(_flip, EINA_TRUE, ELM_FLIP_PAGE_LEFT); - } + if (event) + { + elm_object_text_set(ctx->entry, elm_fileselector_path_get(obj)); + elm_flip_go_to(ctx->flip, EINA_TRUE, ELM_FLIP_PAGE_LEFT); + } + else + { + elm_flip_go_to(ctx->flip, EINA_TRUE, ELM_FLIP_PAGE_LEFT); + } } static Eina_Bool -_cb_timer_bubble_disappear(void *_data EINA_UNUSED) +_cb_timer_bubble_disappear(void *data) { - evas_object_del(_bubble); - _bubble_disappear = NULL; + Background_Ctx *ctx = data; + evas_object_del(ctx->bubble); + ctx->bubble = NULL; + ctx->bubble_disappear = NULL; return ECORE_CALLBACK_CANCEL; } static void -_bubble_show(char *text) +_bubble_show(Background_Ctx *ctx, char *text) { - Evas_Object *opbox = elm_object_top_widget_get(_bg_grid); + Evas_Object *opbox = elm_object_top_widget_get(ctx->bg_grid); Evas_Object *o; int x = 0, y = 0, w , h; - evas_object_geometry_get(_bg_grid, &x, &y, &w ,&h); - if (_bubble_disappear) + evas_object_geometry_get(ctx->bg_grid, &x, &y, &w ,&h); + if (ctx->bubble_disappear) { - ecore_timer_del(_bubble_disappear); - _cb_timer_bubble_disappear(NULL); + ecore_timer_del(ctx->bubble_disappear); + _cb_timer_bubble_disappear(ctx); } - _bubble = elm_bubble_add(opbox); - elm_bubble_pos_set(_bubble, ELM_BUBBLE_POS_BOTTOM_RIGHT); - evas_object_resize(_bubble, 200, 50); - evas_object_move(_bubble, (x + w - 200), (y + h - 50)); - evas_object_show(_bubble); + ctx->bubble = elm_bubble_add(opbox); + elm_bubble_pos_set(ctx->bubble, ELM_BUBBLE_POS_BOTTOM_RIGHT); + evas_object_resize(ctx->bubble, 200, 50); + evas_object_move(ctx->bubble, (x + w - 200), (y + h - 50)); + evas_object_show(ctx->bubble); - o = elm_label_add(_bubble); + o = elm_label_add(ctx->bubble); elm_object_text_set(o, text); - elm_object_content_set(_bubble, o); + elm_object_content_set(ctx->bubble, o); - _bubble_disappear = ecore_timer_add(2.0, _cb_timer_bubble_disappear, NULL); + ctx->bubble_disappear = ecore_timer_add(2.0, + _cb_timer_bubble_disappear, ctx); } static char * @@ -150,18 +159,22 @@ _grid_text_get(void *data, Background_Item *item = data; const char *s; - if (!item->path) return strdup(_("None")); + if (!item->path) + return strdup(_("None")); s = ecore_file_file_get(item->path); - if (s) return strdup(s); + if (s) + return strdup(s); return NULL; } static Evas_Object * _grid_content_get(void *data, Evas_Object *obj, const char *part) { + Background_Ctx *ctx = evas_object_data_get(obj, "ctx"); + assert(ctx); Background_Item *item = data; Evas_Object *o, *oe; - Config *config = termio_config_get(_term); + Config *config = ctx->config; char path[PATH_MAX]; if (!strcmp(part, "elm.swallow.icon")) @@ -181,7 +194,8 @@ _grid_content_get(void *data, Evas_Object *obj, const char *part) } else { - if (!config->theme) return NULL; + if (!config->theme) + return NULL; snprintf(path, PATH_MAX, "%s/themes/%s", elm_app_data_dir_get(), config->theme); o = elm_layout_add(obj); @@ -200,11 +214,12 @@ _grid_content_get(void *data, Evas_Object *obj, const char *part) static void _item_selected(void *data, - Evas_Object *_obj EINA_UNUSED, + Evas_Object *obj, void *_event EINA_UNUSED) { + Background_Ctx *ctx = evas_object_data_get(obj, "ctx"); Background_Item *item = data; - Config *config = termio_config_get(_term); + Config *config = ctx->config; if (!config) return; if (!item->path) @@ -223,17 +238,18 @@ _item_selected(void *data, } static void -_insert_gengrid_item(Insert_Gen_Grid_Item_Notify *msg_data) +_insert_gengrid_item(Background_Ctx *ctx, + Insert_Gen_Grid_Item_Notify *msg_data) { Insert_Gen_Grid_Item_Notify *insert_msg = msg_data; - Config *config = termio_config_get(_term); + Config *config = ctx->config; if (insert_msg && insert_msg->item && insert_msg->class && config) { Background_Item *item = insert_msg->item; Elm_Gengrid_Item_Class *item_class = insert_msg->class; - item->item = elm_gengrid_item_append(_bg_grid, item_class, item, + item->item = elm_gengrid_item_append(ctx->bg_grid, item_class, item, _item_selected, item); if ((!item->path) && (!config->background)) { @@ -255,8 +271,8 @@ _insert_gengrid_item(Insert_Gen_Grid_Item_Notify *msg_data) } static Eina_List* -_rec_read_directorys(Eina_List *list, const char *root_path, - Elm_Gengrid_Item_Class *class) +_rec_read_directorys(Background_Ctx *ctx, Eina_List *list, + const char *root_path, Elm_Gengrid_Item_Class *class) { Eina_List *childs = ecore_file_ls(root_path); char *file_name, path[PATH_MAX]; @@ -296,7 +312,7 @@ _rec_read_directorys(Eina_List *list, const char *root_path, notify->class = class; notify->item = item; //ecore_thread_feedback(th, notify); - _insert_gengrid_item(notify); + _insert_gengrid_item(ctx, notify); } } break; @@ -310,31 +326,30 @@ _rec_read_directorys(Eina_List *list, const char *root_path, } static void -_refresh_directory(const char* data) +_refresh_directory(Background_Ctx *ctx, const char* data) { Background_Item *item; Elm_Gengrid_Item_Class *item_class; - // This will run elm_gengrid_clear - elm_gengrid_clear(_bg_grid); + elm_gengrid_clear(ctx->bg_grid); - if (_backgroundlist) + if (ctx->background_list) { - EINA_LIST_FREE(_backgroundlist, item) + EINA_LIST_FREE(ctx->background_list, item) { if (item->path) eina_stringshare_del(item->path); free(item); } - _backgroundlist = NULL; + ctx->background_list = NULL; } item_class = elm_gengrid_item_class_new(); item_class->func.text_get = _grid_text_get; item_class->func.content_get = _grid_content_get; item = calloc(1, sizeof(Background_Item)); - _backgroundlist = eina_list_append(_backgroundlist, item); + ctx->background_list = eina_list_append(ctx->background_list, item); //Insert None Item Insert_Gen_Grid_Item_Notify *notify = calloc(1, @@ -344,66 +359,92 @@ _refresh_directory(const char* data) notify->class = item_class; notify->item = item; - _insert_gengrid_item(notify); + _insert_gengrid_item(ctx, notify); } - _backgroundlist = _rec_read_directorys(_backgroundlist, data, + ctx->background_list = _rec_read_directorys(ctx, ctx->background_list, data, item_class); elm_gengrid_item_class_free(item_class); - _thread = NULL; } static void -_gengrid_refresh_samples(const char *path) +_gengrid_refresh_samples(Background_Ctx *ctx, const char *path) { if(!ecore_file_exists(path)) return; - _refresh_directory(path); + _refresh_directory(ctx, path); } static void -_cb_entry_changed(void *_data EINA_UNUSED, +_cb_entry_changed(void *data, Evas_Object *parent, void *_event EINA_UNUSED) { + Background_Ctx *ctx = data; const char *path = elm_object_text_get(parent); - _gengrid_refresh_samples(path); + _gengrid_refresh_samples(ctx, path); } static void -_cb_hoversel_select(void *data, - Evas_Object *_hoversel EINA_UNUSED, - void *_event EINA_UNUSED) +_cb_hoversel_select(Background_Ctx *ctx, const Eina_Stringshare *path) { Evas_Object *o; - char *path = data; if (path) { - elm_object_text_set(_entry, path); + elm_object_text_set(ctx->entry, path); } else { - o = elm_object_part_content_get(_flip, "back"); - elm_fileselector_path_set(o, elm_object_text_get(_entry)); - elm_flip_go_to(_flip, EINA_FALSE, ELM_FLIP_PAGE_RIGHT); + o = elm_object_part_content_get(ctx->flip, "back"); + elm_fileselector_path_set(o, elm_object_text_get(ctx->entry)); + elm_flip_go_to(ctx->flip, EINA_FALSE, ELM_FLIP_PAGE_RIGHT); } } static void -_system_background_dir_init(void) +_cb_hoversel_select_system(void *data, + Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Background_Ctx *ctx = data; + + _cb_hoversel_select(ctx, ctx->system_path); +} +static void +_cb_hoversel_select_user(void *data, + Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Background_Ctx *ctx = data; + + _cb_hoversel_select(ctx, ctx->user_path); +} + +static void +_cb_hoversel_select_none(void *data, + Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Background_Ctx *ctx = data; + _cb_hoversel_select(ctx, NULL); +} + +static void +_system_background_dir_init(Background_Ctx *ctx) { char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/backgrounds/", elm_app_data_dir_get()); - if (_system_path) - eina_stringshare_replace(&_system_path, path); + if (ctx->system_path) + eina_stringshare_replace(&ctx->system_path, path); else - _system_path = eina_stringshare_add(path); + ctx->system_path = eina_stringshare_add(path); } static const char* -_user_background_dir_init(void){ +_user_background_dir_init(Background_Ctx *ctx) +{ char path[PATH_MAX], *user; user = getenv("HOME"); @@ -412,52 +453,53 @@ _user_background_dir_init(void){ snprintf(path, PATH_MAX, "%s/.config/terminology/background/", user); if (!ecore_file_exists(path)) ecore_file_mkpath(path); - if (!_user_path) - _user_path = eina_stringshare_add(path); + if (!ctx->user_path) + ctx->user_path = eina_stringshare_add(path); else - eina_stringshare_replace(&_user_path, path); - return _user_path; + eina_stringshare_replace(&ctx->user_path, path); + return ctx->user_path; } static const char* -_import_background(const char* background) +_import_background(Background_Ctx *ctx, const char* background) { char path[PATH_MAX]; const char *filename = ecore_file_file_get(background); if (!filename) return NULL; - if (!_user_background_dir_init()) + if (!_user_background_dir_init(ctx)) return NULL; - snprintf(path, PATH_MAX, "%s/%s", _user_path, filename); + snprintf(path, PATH_MAX, "%s/%s", ctx->user_path, filename); if (!ecore_file_cp(background, path)) return NULL; return eina_stringshare_add(path); } static void -_cb_grid_doubleclick(void *_data EINA_UNUSED, +_cb_grid_doubleclick(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - Config *config = termio_config_get(_term); + Background_Ctx *ctx = data; + Config *config = ctx->config; char *config_background_dir = ecore_file_dir_get(config->background); - if (!_user_path) { - if (!_user_background_dir_init()) + if (!ctx->user_path) { + if (!_user_background_dir_init(ctx)) return; } if (!config->background) return; - if (strncmp(config_background_dir, _user_path, + if (strncmp(config_background_dir, ctx->user_path, strlen(config_background_dir)) == 0) { - _bubble_show(_("Source file is target file")); + _bubble_show(ctx, _("Source file is target file")); free(config_background_dir); return; } - const char *newfile = _import_background(config->background); + const char *newfile = _import_background(ctx, config->background); if (newfile) { @@ -465,50 +507,88 @@ _cb_grid_doubleclick(void *_data EINA_UNUSED, config_save(config, NULL); main_media_update(config); eina_stringshare_del(newfile); - _bubble_show(_("Picture imported")); - elm_object_text_set(_entry, config_background_dir); + _bubble_show(ctx, _("Picture imported")); + elm_object_text_set(ctx->entry, config_background_dir); } else { - _bubble_show(_("Failed")); + _bubble_show(ctx, _("Failed")); } free(config_background_dir); } +static void +_parent_del_cb(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_event_info EINA_UNUSED) +{ + Background_Ctx *ctx = data; + Background_Item *item; + + EINA_LIST_FREE(ctx->background_list, item) + { + if (item->path) + eina_stringshare_del(item->path); + free(item); + } + ctx->background_list = NULL; + if (ctx->user_path) + { + eina_stringshare_del(ctx->user_path); + ctx->user_path = NULL; + } + if (ctx->system_path) + { + eina_stringshare_del(ctx->system_path); + ctx->system_path = NULL; + } + free(ctx); +} + + void options_background(Evas_Object *opbox, Evas_Object *term) { - Evas_Object *frame, *o, *bx, *bx2; + Evas_Object *o, *bx, *bx2; Config *config = termio_config_get(term); char path[PATH_MAX], *config_background_dir; + Background_Ctx *ctx; - _term = term; + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); - frame = o = elm_frame_add(opbox); + ctx->config = config; + ctx->term = term; + + ctx->frame = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Background")); evas_object_show(o); elm_box_pack_end(opbox, o); - _flip = o = elm_flip_add(opbox); + evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + + ctx->flip = o = elm_flip_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_content_set(frame, o); + elm_object_content_set(ctx->frame, o); evas_object_show(o); o = elm_fileselector_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_part_content_set(_flip, "back", o); + elm_object_part_content_set(ctx->flip, "back", o); elm_fileselector_folder_only_set(o, EINA_TRUE); - evas_object_smart_callback_add(o, "done", _cb_fileselector, NULL); + evas_object_smart_callback_add(o, "done", _cb_fileselector, ctx); evas_object_show(o); bx = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_part_content_set(_flip, "front", bx); + elm_object_part_content_set(ctx->flip, "front", bx); evas_object_show(o); o = elm_label_add(opbox); @@ -518,7 +598,7 @@ options_background(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); - op_shine_slider = o = elm_slider_add(opbox); + ctx->op_shine_slider = o = elm_slider_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_slider_span_size_set(o, 40); @@ -533,11 +613,11 @@ options_background(Evas_Object *opbox, Evas_Object *term) evas_object_show(o); evas_object_smart_callback_add(o, "delay,changed", - _cb_op_shine_sel, term); + _cb_op_shine_sel, ctx); - op_trans = o = elm_check_add(opbox); + ctx->op_trans = o = elm_check_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_object_text_set(o, _("Translucent")); @@ -545,9 +625,9 @@ options_background(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_op_video_trans_chg, term); + _cb_op_video_trans_chg, ctx); - op_opacity = o = elm_slider_add(opbox); + ctx->op_opacity = o = elm_slider_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_slider_span_size_set(o, 40); @@ -559,7 +639,7 @@ options_background(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_op_video_opacity_chg, term); + _cb_op_video_opacity_chg, ctx); o = elm_separator_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); @@ -576,13 +656,15 @@ options_background(Evas_Object *opbox, Evas_Object *term) evas_object_show(o); - _entry = o = elm_entry_add(opbox); + ctx->entry = o = elm_entry_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); elm_entry_single_line_set(o, EINA_TRUE); elm_entry_scrollable_set(o, EINA_TRUE); - elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); - evas_object_smart_callback_add(_entry, "changed", _cb_entry_changed, NULL); + elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, + ELM_SCROLLER_POLICY_OFF); + evas_object_smart_callback_add(ctx->entry, "changed", + _cb_entry_changed, ctx); elm_box_pack_start(bx2, o); evas_object_show(o); @@ -594,20 +676,22 @@ options_background(Evas_Object *opbox, Evas_Object *term) evas_object_show(o); snprintf(path, PATH_MAX, "%s/backgrounds/", elm_app_data_dir_get()); - _system_background_dir_init(); - elm_hoversel_item_add(o, _("System"), NULL, ELM_ICON_NONE, _cb_hoversel_select , - _system_path); - if (_user_background_dir_init()) - elm_hoversel_item_add(o, _("User"), NULL, ELM_ICON_NONE, _cb_hoversel_select , - _user_path); + _system_background_dir_init(ctx); + elm_hoversel_item_add(o, _("System"), NULL, ELM_ICON_NONE, + _cb_hoversel_select_system, ctx); + if (_user_background_dir_init(ctx)) + elm_hoversel_item_add(o, _("User"), NULL, ELM_ICON_NONE, + _cb_hoversel_select_user, ctx); //In the other case it has failed, so dont show the user item - elm_hoversel_item_add(o, _("Other"), NULL, ELM_ICON_NONE, _cb_hoversel_select , - NULL); + elm_hoversel_item_add(o, _("Other"), NULL, ELM_ICON_NONE, + _cb_hoversel_select_none, ctx); - _bg_grid = o = elm_gengrid_add(opbox); + ctx->bg_grid = o = elm_gengrid_add(opbox); + evas_object_data_set(ctx->bg_grid, "ctx", ctx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_smart_callback_add(o, "clicked,double", _cb_grid_doubleclick, NULL); + evas_object_smart_callback_add(o, "clicked,double", + _cb_grid_doubleclick, ctx); elm_gengrid_item_size_set(o, elm_config_scale_get() * 100, elm_config_scale_get() * 80); elm_box_pack_end(bx, o); @@ -623,34 +707,11 @@ options_background(Evas_Object *opbox, Evas_Object *term) if (config->background) { config_background_dir = ecore_file_dir_get(config->background); - elm_object_text_set(_entry, config_background_dir); + elm_object_text_set(ctx->entry, config_background_dir); free(config_background_dir); } else { - elm_object_text_set(_entry, _system_path); - } -} - -void -options_background_clear(void) -{ - Background_Item *item; - - EINA_LIST_FREE(_backgroundlist, item) - { - if (item->path) eina_stringshare_del(item->path); - free(item); - } - _backgroundlist = NULL; - if (_user_path) - { - eina_stringshare_del(_user_path); - _user_path = NULL; - } - if (_system_path) - { - eina_stringshare_del(_system_path); - _system_path = NULL; + elm_object_text_set(ctx->entry, ctx->system_path); } } From c7fe3ca9643b38df83434ab01f0a449782c9b854 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 9 Jan 2018 23:21:48 +0100 Subject: [PATCH 12/36] fix coding style wrt _Ctx types --- src/bin/about.c | 8 ++++---- src/bin/controls.c | 40 ++++++++++++++++++++-------------------- src/bin/options.c | 24 ++++++++++++------------ src/bin/options_keys.c | 34 +++++++++++++++++----------------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/bin/about.c b/src/bin/about.c index fa544179..514533b6 100644 --- a/src/bin/about.c +++ b/src/bin/about.c @@ -7,7 +7,7 @@ #include "termio.h" -struct about_ctx { +typedef struct _about_ctx { Evas_Object *layout; Evas_Object *over; Evas_Object *win; @@ -15,7 +15,7 @@ struct about_ctx { Evas_Object *term; void (*donecb) (void *data); void *donedata; -}; +} About_Ctx; static Eina_Bool @@ -33,7 +33,7 @@ _cb_mouse_down(void *data, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - struct about_ctx *ctx = data; + About_Ctx *ctx = data; if (ctx->over) { @@ -56,7 +56,7 @@ about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o; - struct about_ctx *ctx; + About_Ctx *ctx; Config *config = termio_config_get(term); char buf[PATH_MAX]; const char *txt; diff --git a/src/bin/controls.c b/src/bin/controls.c index a472114d..89fbc8d8 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -10,7 +10,7 @@ static Eina_Hash *controls = NULL; -struct controls_ctx { +typedef struct _Controls_Ctx { Evas_Object *frame; Evas_Object *over; Evas_Object *win; @@ -18,11 +18,11 @@ struct controls_ctx { Evas_Object *term; void (*donecb) (void *data); void *donedata; -}; +} Controls_Ctx; static void -controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb); +controls_hide(Controls_Ctx *ctx, Eina_Bool call_cb); @@ -31,7 +31,7 @@ _cb_sel_on(void *data, Evas_Object *_term EINA_UNUSED, void *_ev EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy"); if (bt_copy) elm_object_disabled_set(bt_copy, EINA_FALSE); @@ -42,7 +42,7 @@ _cb_sel_off(void *data, Evas_Object *_term EINA_UNUSED, void *_ev EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *bt_copy = evas_object_data_get(ctx->frame, "bt_copy"); if (bt_copy) elm_object_disabled_set(bt_copy, EINA_TRUE); @@ -62,7 +62,7 @@ _cb_ct_copy(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *term = ctx->term; controls_hide(ctx, EINA_TRUE); @@ -74,7 +74,7 @@ _cb_ct_paste(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *term = ctx->term; controls_hide(ctx, EINA_TRUE); @@ -86,7 +86,7 @@ _cb_ct_new(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; main_new(ctx->win, ctx->term); } @@ -95,7 +95,7 @@ _cb_ct_split_v(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; split_vertically(ctx->win, ctx->term, NULL); } @@ -104,7 +104,7 @@ _cb_ct_split_h(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; split_horizontally(ctx->win, ctx->term, NULL); } @@ -113,7 +113,7 @@ _cb_ct_miniview(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; term_miniview_toggle(termio_term_get(ctx->term)); } @@ -122,7 +122,7 @@ _cb_ct_set_title(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *term = ctx->term; controls_hide(ctx, EINA_TRUE); term_set_title(termio_term_get(term)); @@ -133,7 +133,7 @@ _cb_ct_close(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; Evas_Object *term = ctx->term; Evas_Object *win = ctx->win; @@ -144,7 +144,7 @@ _cb_ct_close(void *data, static void _on_sub_done(void *data) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; ecore_timer_add(10.0, _cb_del_delay, ctx->frame); ctx->frame = NULL; @@ -162,7 +162,7 @@ _cb_ct_options(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; options_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); @@ -174,7 +174,7 @@ _cb_ct_about(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; about_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); @@ -186,7 +186,7 @@ _cb_mouse_down(void *data, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; controls_hide(ctx, EINA_TRUE); } @@ -197,7 +197,7 @@ _cb_saved_del(void *data, Evas_Object *obj, void *_ev EINA_UNUSED) { - struct controls_ctx *ctx = data; + Controls_Ctx *ctx = data; if (obj == ctx->win) ctx->win = NULL; @@ -256,7 +256,7 @@ _sep_add_h(Evas_Object *win) } static void -controls_hide(struct controls_ctx *ctx, Eina_Bool call_cb) +controls_hide(Controls_Ctx *ctx, Eina_Bool call_cb) { if (ctx->win) { @@ -297,7 +297,7 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, { Evas_Object *o; Evas_Object *ct_boxh, *ct_boxv, *ct_box, *ct_box2, *ct_box3; - struct controls_ctx *ctx; + Controls_Ctx *ctx; if (eina_hash_find(controls, &win)) { diff --git a/src/bin/options.c b/src/bin/options.c index 2798718b..6d79666b 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -31,7 +31,7 @@ enum option_mode { OPTIONS_MODE_NB }; -struct options_ctx { +typedef struct _Options_Ctx { enum option_mode mode; Evas_Object *frame; Evas_Object *toolbar; @@ -43,16 +43,16 @@ struct options_ctx { Config *config; void (*donecb) (void *data); void *donedata; - struct options_ctx *modes[OPTIONS_MODE_NB]; -}; + struct _Options_Ctx *modes[OPTIONS_MODE_NB]; +} Options_Ctx; static void _cb_op(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct options_ctx **pctx = data; - struct options_ctx *ctx = *pctx; + Options_Ctx **pctx = data; + Options_Ctx *ctx = *pctx; enum option_mode mode = pctx - ctx->modes; if (mode == ctx->mode) @@ -66,7 +66,7 @@ _cb_op(void *data, static void _cb_op_tmp_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - struct options_ctx *ctx = data; + Options_Ctx *ctx = data; Config *config = ctx->config; config->temporary = elm_check_state_get(obj); @@ -75,7 +75,7 @@ _cb_op_tmp_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) static Eina_Bool _cb_op_del_delay(void *data) { - struct options_ctx *ctx = data; + Options_Ctx *ctx = data; evas_object_del(ctx->opbox); evas_object_del(ctx->frame); @@ -93,7 +93,7 @@ _cb_opdt_hide_done(void *data, const char *_sig EINA_UNUSED, const char *_src EINA_UNUSED) { - struct options_ctx *ctx = data; + Options_Ctx *ctx = data; elm_box_clear(ctx->opbox); switch (ctx->mode) @@ -119,7 +119,7 @@ _cb_opdt_hide_done2(void *data, const char *_sig EINA_UNUSED, const char *_src EINA_UNUSED) { - struct options_ctx *ctx = data; + Options_Ctx *ctx = data; edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done", "terminology", @@ -128,7 +128,7 @@ _cb_opdt_hide_done2(void *data, } static void -options_hide(struct options_ctx *ctx) +options_hide(Options_Ctx *ctx) { edje_object_part_swallow(ctx->bg, "terminology.optdetails", ctx->opbox); edje_object_part_swallow(ctx->bg, "terminology.options", ctx->frame); @@ -161,7 +161,7 @@ _cb_mouse_down(void *data, Evas_Object *_obj EINA_UNUSED, void *_ev EINA_UNUSED) { - struct options_ctx *ctx = data; + Options_Ctx *ctx = data; options_hide(ctx); } @@ -172,7 +172,7 @@ options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o, *op_box, *op_tbox; - struct options_ctx *ctx; + Options_Ctx *ctx; int i = 0; Elm_Object_Item *it_fn; diff --git a/src/bin/options_keys.c b/src/bin/options_keys.c index 0776dcc4..01a64dfd 100644 --- a/src/bin/options_keys.c +++ b/src/bin/options_keys.c @@ -9,14 +9,14 @@ #include "keyin.h" #include "utils.h" -struct keys_ctx { +typedef struct _Keys_Ctx { Config *config; Evas_Object *frame; Evas_Object *gl; Evas_Object *layout; -}; +} Keys_Ctx; -static void _hover_del(struct keys_ctx *ctx); +static void _hover_del(Keys_Ctx *ctx); static void _shortcut_delete(void *data, @@ -26,7 +26,7 @@ _shortcut_delete(void *data, Evas_Object *hs, *bx; Config_Keys *cfg_key; Evas_Coord w, min_w, min_h; - struct keys_ctx *ctx; + Keys_Ctx *ctx; hs = data; bx = evas_object_data_get(hs, "bx"); @@ -53,7 +53,7 @@ _shortcut_delete(void *data, } static Evas_Object * -_shortcut_button_add(struct keys_ctx *ctx, +_shortcut_button_add(Keys_Ctx *ctx, Evas_Object *bx, const Config_Keys *key) { @@ -95,7 +95,7 @@ _cb_key_up(void *data, Config_Keys *cfg_key; Shortcut_Action *action; Evas_Object *bx = data; - struct keys_ctx *ctx; + Keys_Ctx *ctx; if (key_is_modifier(ev->keyname)) return; @@ -166,14 +166,14 @@ _cb_mouse_down(void *data, Evas_Object *obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; _hover_del(ctx); } static void -_hover_sizing_eval(struct keys_ctx *ctx) +_hover_sizing_eval(Keys_Ctx *ctx) { Evas_Coord x = 0, y = 0, w = 0, h = 0; @@ -192,7 +192,7 @@ _parent_move_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; _hover_sizing_eval(ctx); } @@ -202,7 +202,7 @@ _parent_resize_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; _hover_sizing_eval(ctx); } @@ -212,7 +212,7 @@ _parent_hide_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; _hover_del(ctx); } @@ -222,7 +222,7 @@ _parent_del_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; _hover_del(ctx); evas_object_event_callback_del(ctx->frame, EVAS_CALLBACK_DEL, @@ -233,7 +233,7 @@ _parent_del_cb(void *data, } static void -_hover_del(struct keys_ctx *ctx) +_hover_del(Keys_Ctx *ctx) { if (ctx->layout) { @@ -257,7 +257,7 @@ _on_shortcut_add(void *data, { Evas_Object *o, *oe; Evas_Object *bx = data; - struct keys_ctx *ctx; + Keys_Ctx *ctx; ctx = evas_object_data_get(bx, "ctx"); assert(ctx); @@ -290,7 +290,7 @@ gl_content_get(void *data, Evas_Object *obj, const char *_part EINA_UNUSED) Evas_Object *bx, *bt, *lbl, *sep; Config_Keys *key; Eina_List *l; - struct keys_ctx *ctx; + Keys_Ctx *ctx; ctx = evas_object_data_get(obj, "ctx"); assert(ctx); @@ -363,7 +363,7 @@ _cb_reset_keys(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - struct keys_ctx *ctx = data; + Keys_Ctx *ctx = data; config_reset_keys(ctx->config); elm_genlist_realized_items_update(ctx->gl); @@ -377,7 +377,7 @@ options_keys(Evas_Object *opbox, Evas_Object *term) Elm_Genlist_Item_Class *itc, *itc_group; Elm_Object_Item *git = NULL; Config *config = termio_config_get(term); - struct keys_ctx *ctx; + Keys_Ctx *ctx; ctx = calloc(1, sizeof(*ctx)); assert(ctx); From 1745e77c93cd90a452281cbcc293101132b58ea5 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 9 Jan 2018 23:39:02 +0100 Subject: [PATCH 13/36] options_background: fix segfault due to flip destroying hoversel --- src/bin/options_background.c | 83 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/bin/options_background.c b/src/bin/options_background.c index 05fe49a9..c99423f9 100644 --- a/src/bin/options_background.c +++ b/src/bin/options_background.c @@ -550,7 +550,7 @@ _parent_del_cb(void *data, void options_background(Evas_Object *opbox, Evas_Object *term) { - Evas_Object *o, *bx, *bx2; + Evas_Object *o, *bx, *bx_front; Config *config = termio_config_get(term); char path[PATH_MAX], *config_background_dir; Background_Ctx *ctx; @@ -571,24 +571,10 @@ options_background(Evas_Object *opbox, Evas_Object *term) evas_object_event_callback_add(ctx->frame, EVAS_CALLBACK_DEL, _parent_del_cb, ctx); - ctx->flip = o = elm_flip_add(opbox); + bx = o = elm_box_add(ctx->frame); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_content_set(ctx->frame, o); - evas_object_show(o); - - o = elm_fileselector_add(opbox); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_part_content_set(ctx->flip, "back", o); - elm_fileselector_folder_only_set(o, EINA_TRUE); - evas_object_smart_callback_add(o, "done", _cb_fileselector, ctx); - evas_object_show(o); - - bx = o = elm_box_add(opbox); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_part_content_set(ctx->flip, "front", bx); + elm_object_content_set(ctx->frame, bx); evas_object_show(o); o = elm_label_add(opbox); @@ -648,31 +634,11 @@ options_background(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); - bx2 = o = elm_box_add(opbox); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); - elm_box_horizontal_set(o, EINA_TRUE); - elm_box_pack_end(bx, o); - evas_object_show(o); - - - ctx->entry = o = elm_entry_add(opbox); - evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); - elm_entry_single_line_set(o, EINA_TRUE); - elm_entry_scrollable_set(o, EINA_TRUE); - elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, - ELM_SCROLLER_POLICY_OFF); - evas_object_smart_callback_add(ctx->entry, "changed", - _cb_entry_changed, ctx); - elm_box_pack_start(bx2, o); - evas_object_show(o); - o = elm_hoversel_add(opbox); evas_object_size_hint_weight_set(o, 0.0, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); elm_object_text_set(o, _("Select Path")); - elm_box_pack_end(bx2, o); + elm_box_pack_end(bx, o); evas_object_show(o); snprintf(path, PATH_MAX, "%s/backgrounds/", elm_app_data_dir_get()); @@ -686,6 +652,31 @@ options_background(Evas_Object *opbox, Evas_Object *term) elm_hoversel_item_add(o, _("Other"), NULL, ELM_ICON_NONE, _cb_hoversel_select_none, ctx); + ctx->flip = o = elm_flip_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(bx, o); + evas_object_show(o); + + bx_front = o = elm_box_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); + elm_box_horizontal_set(o, EINA_FALSE); + elm_object_part_content_set(ctx->flip, "front", o); + evas_object_show(o); + + ctx->entry = o = elm_entry_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); + elm_entry_single_line_set(o, EINA_TRUE); + elm_entry_scrollable_set(o, EINA_TRUE); + elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, + ELM_SCROLLER_POLICY_OFF); + evas_object_smart_callback_add(ctx->entry, "changed", + _cb_entry_changed, ctx); + elm_box_pack_end(bx_front, o); + evas_object_show(o); + ctx->bg_grid = o = elm_gengrid_add(opbox); evas_object_data_set(ctx->bg_grid, "ctx", ctx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -694,14 +685,24 @@ options_background(Evas_Object *opbox, Evas_Object *term) _cb_grid_doubleclick, ctx); elm_gengrid_item_size_set(o, elm_config_scale_get() * 100, elm_config_scale_get() * 80); - elm_box_pack_end(bx, o); + elm_box_pack_end(bx_front, o); evas_object_show(o); o = elm_label_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); - elm_object_text_set(o, _("Double click on a picture to import it")); - elm_box_pack_end(bx, o); + elm_object_text_set(o, _("Click on a picture to use it as background")); + elm_box_pack_end(bx_front, o); + evas_object_show(o); + + + + o = elm_fileselector_add(opbox); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_part_content_set(ctx->flip, "back", o); + elm_fileselector_folder_only_set(o, EINA_TRUE); + evas_object_smart_callback_add(o, "done", _cb_fileselector, ctx); evas_object_show(o); if (config->background) From 22e3731c966ffe46e39b3a15731340da0bbd8277 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 10 Jan 2018 23:26:40 +0100 Subject: [PATCH 14/36] options_behavior: be able to have multiple instances --- src/bin/options_behavior.c | 129 +++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 47 deletions(-) diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c index c5c51ae2..ed45722d 100644 --- a/src/bin/options_behavior.c +++ b/src/bin/options_behavior.c @@ -1,26 +1,34 @@ #include "private.h" #include +#include #include "config.h" #include "termio.h" #include "options.h" #include "options_behavior.h" #include "main.h" -static Evas_Object *op_w, *op_h, *op_wh_current; +typedef struct _Behavior_Ctx { + Evas_Object *op_w; + Evas_Object *op_h; + Evas_Object *op_wh_current; + Evas_Object *term; + Config *config; +} Behavior_Ctx; + #define CB(_cfg_name, _inv) \ static void \ _cb_op_behavior_##_cfg_name(void *data, Evas_Object *obj, \ void *_event EINA_UNUSED) \ { \ - Evas_Object *term = data; \ - Config *config = termio_config_get(term); \ + Behavior_Ctx *ctx = data; \ + Config *config = ctx->config; \ if (_inv) \ config->_cfg_name = !elm_check_state_get(obj); \ else \ config->_cfg_name = elm_check_state_get(obj); \ - termio_config_update(term); \ + termio_config_update(ctx->term); \ windows_update(); \ config_save(config, NULL); \ } @@ -74,11 +82,11 @@ _cb_op_behavior_sback_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; config->scrollback = (double) sback_double_to_expo_int(elm_slider_value_get(obj)); - termio_config_update(term); + termio_config_update(ctx->term); config_save(config, NULL); } @@ -87,11 +95,11 @@ _cb_op_behavior_tab_zoom_slider_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; config->tab_zoom = (double)(int)round(elm_slider_value_get(obj) * 10.0) / 10.0; - termio_config_update(term); + termio_config_update(ctx->term); config_save(config, NULL); } @@ -100,15 +108,16 @@ _cb_op_behavior_custom_geometry_current_set(void *data, Evas_Object *obj EINA_UNUSED, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); - if (config->custom_geometry) - { - termio_size_get(term, &config->cg_width, &config->cg_height); - elm_spinner_value_set(op_w, config->cg_width); - elm_spinner_value_set(op_h, config->cg_height); - } - config_save(config, NULL); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; + + if (config->custom_geometry) + { + termio_size_get(ctx->term, &config->cg_width, &config->cg_height); + elm_spinner_value_set(ctx->op_w, config->cg_width); + elm_spinner_value_set(ctx->op_h, config->cg_height); + } + config_save(config, NULL); } static void @@ -116,20 +125,20 @@ _cb_op_behavior_custom_geometry(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; config->custom_geometry = elm_check_state_get(obj); if (config->custom_geometry) { - config->cg_width = (int) elm_spinner_value_get(op_w); - config->cg_height = (int) elm_spinner_value_get(op_h); + config->cg_width = (int) elm_spinner_value_get(ctx->op_w); + config->cg_height = (int) elm_spinner_value_get(ctx->op_h); } config_save(config, NULL); - elm_object_disabled_set(op_w, !config->custom_geometry); - elm_object_disabled_set(op_h, !config->custom_geometry); - elm_object_disabled_set(op_wh_current, !config->custom_geometry); + elm_object_disabled_set(ctx->op_w, !config->custom_geometry); + elm_object_disabled_set(ctx->op_h, !config->custom_geometry); + elm_object_disabled_set(ctx->op_wh_current, !config->custom_geometry); } static void @@ -137,8 +146,8 @@ _cb_op_behavior_cg_width(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; if (config->custom_geometry) { @@ -152,8 +161,8 @@ _cb_op_behavior_cg_height(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Behavior_Ctx *ctx = data; + Config *config = ctx->config; if (config->custom_geometry) { @@ -162,28 +171,49 @@ _cb_op_behavior_cg_height(void *data, } } +static void +_parent_del_cb(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_event_info EINA_UNUSED) +{ + Behavior_Ctx *ctx = data; + + free(ctx); +} + void options_behavior(Evas_Object *opbox, Evas_Object *term) { Config *config = termio_config_get(term); - Evas_Object *o, *bx, *sc, *fr; + Evas_Object *o, *bx, *sc, *frame; int w, h; const char *tooltip; + Behavior_Ctx *ctx; termio_size_get(term, &w, &h); - fr = o = elm_frame_add(opbox); + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); + + ctx->config = config; + ctx->term = term; + + frame = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Behavior")); elm_box_pack_end(opbox, o); evas_object_show(o); + evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + sc = o = elm_scroller_add(opbox); elm_scroller_content_min_limit(sc, EINA_TRUE, EINA_FALSE); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_object_content_set(fr, o); + elm_object_content_set(frame, o); evas_object_show(o); bx = o = elm_box_add(opbox); @@ -201,7 +231,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); \ evas_object_show(o); \ evas_object_smart_callback_add(o, "changed", \ - _cb_op_behavior_##_cfg_name, term) + _cb_op_behavior_##_cfg_name, ctx) CX(_("Scroll to bottom on new content"), jump_on_change, 0); CX(_("Scroll to bottom when a key is pressed"), jump_on_keypress, 0); @@ -235,9 +265,9 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_op_behavior_custom_geometry, term); + _cb_op_behavior_custom_geometry, ctx); - op_wh_current = o = elm_button_add(bx); + ctx->op_wh_current = o = elm_button_add(bx); evas_object_size_hint_weight_set(o, 0.0, 0.0); evas_object_size_hint_align_set(o, 0.0, 0.5); elm_object_text_set(o, _("Set Current:")); @@ -245,7 +275,8 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) evas_object_show(o); elm_object_disabled_set(o, !config->custom_geometry); evas_object_smart_callback_add(o, "clicked", - _cb_op_behavior_custom_geometry_current_set, term); + _cb_op_behavior_custom_geometry_current_set, + ctx); o = elm_label_add(bx); evas_object_size_hint_weight_set(o, 0.0, 0.0); @@ -254,18 +285,20 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); - op_w = o = elm_spinner_add(bx); + ctx->op_w = o = elm_spinner_add(bx); elm_spinner_editable_set(o, EINA_TRUE); elm_spinner_min_max_set(o, 2.0, 350.0); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); - if (config->custom_geometry) elm_spinner_value_set(o, config->cg_width); - else elm_spinner_value_set(o, w); + if (config->custom_geometry) + elm_spinner_value_set(o, config->cg_width); + else + elm_spinner_value_set(o, w); elm_object_disabled_set(o, !config->custom_geometry); elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_op_behavior_cg_width, term); + _cb_op_behavior_cg_width, ctx); o = elm_label_add(bx); evas_object_size_hint_weight_set(o, 0.0, 0.0); @@ -274,18 +307,20 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); - op_h = o = elm_spinner_add(bx); + ctx->op_h = o = elm_spinner_add(bx); elm_spinner_editable_set(o, EINA_TRUE); elm_spinner_min_max_set(o, 1.0, 150.0); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); - if (config->custom_geometry) elm_spinner_value_set(o, config->cg_height); - else elm_spinner_value_set(o, h); + if (config->custom_geometry) + elm_spinner_value_set(o, config->cg_height); + else + elm_spinner_value_set(o, h); elm_object_disabled_set(o, !config->custom_geometry); elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_op_behavior_cg_height, term); + _cb_op_behavior_cg_height, ctx); o = elm_separator_add(bx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); @@ -326,7 +361,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "delay,changed", - _cb_op_behavior_sback_chg, term); + _cb_op_behavior_sback_chg, ctx); o = elm_label_add(bx); evas_object_size_hint_weight_set(o, 0.0, 0.0); @@ -352,7 +387,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx, o); evas_object_show(o); evas_object_smart_callback_add(o, "delay,changed", - _cb_op_behavior_tab_zoom_slider_chg, term); + _cb_op_behavior_tab_zoom_slider_chg, ctx); evas_object_size_hint_weight_set(opbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(opbox, EVAS_HINT_FILL, EVAS_HINT_FILL); From 32209a6dfdebd7ea27e411f1e43a0109ad5e58a6 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 10 Jan 2018 23:28:50 +0100 Subject: [PATCH 15/36] options_video: be able to have multiple instances --- src/bin/options_video.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bin/options_video.c b/src/bin/options_video.c index 8baae484..f3f83d38 100644 --- a/src/bin/options_video.c +++ b/src/bin/options_video.c @@ -8,8 +8,6 @@ #include "main.h" -static Evas_Object *op_vidmod; - static void _cb_op_video_mute_chg(void *data, Evas_Object *obj, @@ -51,7 +49,7 @@ _cb_op_video_vidmod_chg(void *data, void options_video(Evas_Object *opbox, Evas_Object *term) { - Evas_Object *o, *fr, *bx0; + Evas_Object *o, *fr, *bx0, *op_vidmod; Config *config = termio_config_get(term); fr = o = elm_frame_add(opbox); From 85ba7447715b9c00108ab252471ee1263b2f6715 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 12 Jan 2018 23:27:19 +0100 Subject: [PATCH 16/36] options_font: be able to have multiple instances --- src/bin/options.c | 1 - src/bin/options_font.c | 234 +++++++++++++++++++++++------------------ src/bin/options_font.h | 1 - 3 files changed, 132 insertions(+), 104 deletions(-) diff --git a/src/bin/options.c b/src/bin/options.c index 6d79666b..65f7d9c0 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -79,7 +79,6 @@ _cb_op_del_delay(void *data) evas_object_del(ctx->opbox); evas_object_del(ctx->frame); - options_font_clear(); options_theme_clear(); free(ctx); diff --git a/src/bin/options_font.c b/src/bin/options_font.c index f856c713..b329b8d8 100644 --- a/src/bin/options_font.c +++ b/src/bin/options_font.c @@ -1,6 +1,7 @@ #include "private.h" #include +#include #include "config.h" #include "termio.h" #include "options.h" @@ -12,37 +13,47 @@ #define FONT_MAX 45 #define FONT_STEP (1.0 / (FONT_MAX - FONT_MIN)) -static Evas_Object *op_fontslider, *op_fontlist, *op_fsml, *op_fbig; -typedef struct _Font Font; +typedef struct _Font_Ctx +{ + Evas_Object *op_fontslider; + Evas_Object *op_fontlist; + Evas_Object *op_fsml; + Evas_Object *op_fbig; + Evas_Object *term; + Eina_List *fonts; + Eina_Hash *fonthash; + Config *config; + Evas_Coord tsize_w; + Evas_Coord tsize_h; + int expecting_resize; +} Font_Ctx; -struct _Font +typedef struct _Font { Elm_Object_Item *item; const char *pretty_name; const char *full_name; - Evas_Object *term; + Font_Ctx *ctx; unsigned char bitmap : 1; -}; +} Font; -static Eina_List *fonts = NULL; -static Eina_Hash *fonthash = NULL; -static Evas_Coord tsize_w = 0, tsize_h = 0; -static int expecting_resize = 0; static void -_update_sizing(Evas_Object *term) +_update_sizing(Font_Ctx *ctx) { Evas_Coord mw = 1, mh = 1, w, h; - termio_config_update(term); - evas_object_size_hint_min_get(term, &mw, &mh); - if (mw < 1) mw = 1; - if (mh < 1) mh = 1; - w = tsize_w / mw; - h = tsize_h / mh; - evas_object_size_hint_request_set(term, w * mw, h * mh); - expecting_resize = 1; + termio_config_update(ctx->term); + evas_object_size_hint_min_get(ctx->term, &mw, &mh); + if (mw < 1) + mw = 1; + if (mh < 1) + mh = 1; + w = ctx->tsize_w / mw; + h = ctx->tsize_h / mh; + evas_object_size_hint_request_set(ctx->term, w * mw, h * mh); + ctx->expecting_resize = 1; } static int @@ -133,18 +144,19 @@ _cb_op_font_sel(void *data, void *_event EINA_UNUSED) { Font *f = data; - Config *config = termio_config_get(f->term); - Term *term = termio_term_get(f->term); + Font_Ctx *ctx = f->ctx; + Config *config = ctx->config; + Term *term = termio_term_get(ctx->term); if ((config->font.name) && (!strcmp(f->full_name, config->font.name))) return; if (config->font.name) eina_stringshare_del(config->font.name); config->font.name = eina_stringshare_add(f->full_name); config->font.bitmap = f->bitmap; - _update_sizing(f->term); - elm_object_disabled_set(op_fsml, f->bitmap); - elm_object_disabled_set(op_fontslider, f->bitmap); - elm_object_disabled_set(op_fbig, f->bitmap); + _update_sizing(ctx); + elm_object_disabled_set(ctx->op_fsml, f->bitmap); + elm_object_disabled_set(ctx->op_fontslider, f->bitmap); + elm_object_disabled_set(ctx->op_fbig, f->bitmap); config_save(config, NULL); win_font_update(term); } @@ -154,15 +166,16 @@ _cb_op_fontsize_sel(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *termio_obj = data; - Config *config = termio_config_get(termio_obj); - Term *term = termio_term_get(termio_obj); + Font_Ctx *ctx = data; + Config *config = ctx->config; + Term *term = termio_term_get(ctx->term); int size = elm_slider_value_get(obj) + 0.5; - if (config->font.size == size) return; + if (config->font.size == size) + return; config->font.size = size; - _update_sizing(termio_obj); - elm_genlist_realized_items_update(op_fontlist); + _update_sizing(ctx); + elm_genlist_realized_items_update(ctx->op_fontlist); config_save(config, NULL); win_font_update(term); } @@ -181,7 +194,7 @@ _cb_op_font_preview_del(void *_data EINA_UNUSED, { Evas_Object *o; Ecore_Timer *timer = evas_object_data_get(obj, "delay"); - + if (timer) { ecore_timer_del(timer); @@ -203,22 +216,27 @@ _cb_op_font_preview_delayed_eval(void *data) Evas_Object *o; Evas_Coord ox, oy, ow, oh, vx, vy, vw, vh; Config *config; - - if (!evas_object_visible_get(obj)) goto done; - if (edje_object_part_swallow_get(obj, "terminology.text.preview")) goto done; + + if (!evas_object_visible_get(obj)) + goto done; + if (edje_object_part_swallow_get(obj, "terminology.text.preview")) + goto done; evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); - if ((ow < 2) || (oh < 2)) goto done; + if ((ow < 2) || (oh < 2)) + goto done; evas_output_viewport_get(evas_object_evas_get(obj), &vx, &vy, &vw, &vh); f = evas_object_data_get(obj, "font"); - if (!f) goto done; - config = termio_config_get(f->term); - if (!config) goto done; + if (!f) + goto done; + config = f->ctx->config; + if (!config) + goto done; if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, vx, vy, vw, vh)) { char buf[4096]; int r, g, b, a; Evas *evas = evas_object_evas_get(obj); - Evas_Object *textgrid = termio_textgrid_get(f->term); + Evas_Object *textgrid = termio_textgrid_get(f->ctx->term); evas_object_textgrid_palette_get(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, 0, &r, &g, &b, &a); @@ -252,11 +270,14 @@ _cb_op_font_preview_eval(void *data, { Font *f = data; Evas_Coord ox, oy, ow, oh, vx, vy, vw, vh; - - if (!evas_object_visible_get(obj)) return; - if (edje_object_part_swallow_get(obj, "terminology.text.preview")) return; + + if (!evas_object_visible_get(obj)) + return; + if (edje_object_part_swallow_get(obj, "terminology.text.preview")) + return; evas_object_geometry_get(obj, &ox, &oy, &ow, &oh); - if ((ow < 2) || (oh < 2)) return; + if ((ow < 2) || (oh < 2)) + return; evas_output_viewport_get(evas_object_evas_get(obj), &vx, &vy, &vw, &vh); if (ELM_RECTS_INTERSECT(ox, oy, ow, oh, vx, vy, vw, vh)) { @@ -264,8 +285,10 @@ _cb_op_font_preview_eval(void *data, double rnd = 0.2; timer = evas_object_data_get(obj, "delay"); - if (timer) return; - else evas_object_data_set(obj, "font", f); + if (timer) + return; + else + evas_object_data_set(obj, "font", f); rnd += (double)(rand() % 100) / 500.0; timer = ecore_timer_add(rnd, _cb_op_font_preview_delayed_eval, obj); evas_object_data_set(obj, "delay", timer); @@ -280,8 +303,8 @@ _cb_op_font_content_get(void *data, Evas_Object *obj, const char *part) if (!strcmp(part, "elm.swallow.icon")) { Evas_Object *o; - Config *config = termio_config_get(f->term); - + Config *config = f->ctx->config; + o = edje_object_add(evas_object_evas_get(obj)); theme_apply(o, config, "terminology/fontpreview"); theme_auto_reload_enable(o); @@ -324,13 +347,14 @@ _cb_term_resize(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - Evas_Object *term = data; - if (expecting_resize) + Font_Ctx *ctx = data; + + if (ctx->expecting_resize) { - expecting_resize = 0; + ctx->expecting_resize = 0; return; } - evas_object_geometry_get(term, NULL, NULL, &tsize_w, &tsize_h); + evas_object_geometry_get(ctx->term, NULL, NULL, &ctx->tsize_w, &ctx->tsize_h); } static void @@ -339,32 +363,29 @@ _cb_font_del(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - Evas_Object *term = data; - evas_object_event_callback_del_full(term, EVAS_CALLBACK_RESIZE, - _cb_term_resize, term); + Font_Ctx *ctx = data; + evas_object_event_callback_del_full(ctx->term, EVAS_CALLBACK_RESIZE, + _cb_term_resize, ctx); } -void -options_font_clear(void) +static void +_parent_del_cb(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_event_info EINA_UNUSED) { + Font_Ctx *ctx = data; Font *f; - op_fontslider = NULL; - op_fontlist = NULL; - op_fsml = NULL; - op_fbig = NULL; - - EINA_LIST_FREE(fonts, f) + EINA_LIST_FREE(ctx->fonts, f) { eina_stringshare_del(f->full_name); eina_stringshare_del(f->pretty_name); free(f); } - if (fonthash) - { - eina_hash_free(fonthash); - fonthash = NULL; - } + eina_hash_free(ctx->fonthash); + + free(ctx); } static void @@ -372,11 +393,11 @@ _cb_font_bolditalic(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Font_Ctx *ctx = data; + Config *config = ctx->config; config->font.bolditalic = elm_check_state_get(obj); - termio_config_update(term); + termio_config_update(ctx->term); config_save(config, NULL); } @@ -390,33 +411,41 @@ options_font(Evas_Object *opbox, Evas_Object *term) Elm_Object_Item *it, *sel_it = NULL, *sel_it2 = NULL, *grp_it = NULL; Elm_Genlist_Item_Class *it_class, *it_group; Config *config = termio_config_get(term); + Font_Ctx *ctx; + + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); + + ctx->config = config; + ctx->term = term; - options_font_clear(); - fr = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Font")); elm_box_pack_end(opbox, o); evas_object_show(o); - + + evas_object_event_callback_add(fr, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + bx0 = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_content_set(fr, o); evas_object_show(o); - + bx = o = elm_box_add(opbox); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.5); elm_box_horizontal_set(o, EINA_TRUE); - - op_fsml = o = elm_label_add(opbox); + + ctx->op_fsml = o = elm_label_add(opbox); elm_object_text_set(o, "A"); elm_box_pack_end(bx, o); evas_object_show(o); - op_fontslider = o = elm_slider_add(opbox); + ctx->op_fontslider = o = elm_slider_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_slider_span_size_set(o, 40); @@ -429,28 +458,28 @@ options_font(Evas_Object *opbox, Evas_Object *term) elm_slider_value_set(o, config->font.size); elm_box_pack_end(bx, o); evas_object_show(o); - - evas_object_smart_callback_add(o, "delay,changed", - _cb_op_fontsize_sel, term); - op_fbig = o = elm_label_add(opbox); + evas_object_smart_callback_add(o, "delay,changed", + _cb_op_fontsize_sel, ctx); + + ctx->op_fbig = o = elm_label_add(opbox); elm_object_text_set(o, "A"); elm_box_pack_end(bx, o); evas_object_show(o); - + elm_box_pack_end(bx0, bx); evas_object_show(bx); - + it_class = elm_genlist_item_class_new(); it_class->item_style = "end_icon"; it_class->func.text_get = _cb_op_font_text_get; it_class->func.content_get = _cb_op_font_content_get; - + it_group = elm_genlist_item_class_new(); it_group->item_style = "group_index"; it_group->func.text_get = _cb_op_font_group_text_get; - op_fontlist = o = elm_genlist_add(opbox); + ctx->op_fontlist = o = elm_genlist_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_genlist_mode_set(o, ELM_LIST_COMPRESS); @@ -476,9 +505,9 @@ options_font(Evas_Object *opbox, Evas_Object *term) s = strchr(file, '.'); if (s != NULL) *s = '\0'; f->pretty_name = eina_stringshare_add(file); - f->term = term; + f->ctx = ctx; f->bitmap = EINA_TRUE; - fonts = eina_list_append(fonts, f); + ctx->fonts = eina_list_append(ctx->fonts, f); f->item = it = elm_genlist_item_append(o, it_class, f, grp_it, ELM_GENLIST_ITEM_NONE, @@ -488,9 +517,9 @@ options_font(Evas_Object *opbox, Evas_Object *term) (!strcmp(config->font.name, file)))) { sel_it = it; - elm_object_disabled_set(op_fsml, EINA_TRUE); - elm_object_disabled_set(op_fontslider, EINA_TRUE); - elm_object_disabled_set(op_fbig, EINA_TRUE); + elm_object_disabled_set(ctx->op_fsml, EINA_TRUE); + elm_object_disabled_set(ctx->op_fontslider, EINA_TRUE); + elm_object_disabled_set(ctx->op_fbig, EINA_TRUE); } free(file); } @@ -499,8 +528,8 @@ options_font(Evas_Object *opbox, Evas_Object *term) fontlist = evas_font_available_list(evas_object_evas_get(opbox)); fontlist = eina_list_sort(fontlist, eina_list_count(fontlist), _cb_op_font_sort); - fonthash = eina_hash_string_superfast_new(NULL); - if (fonts) + ctx->fonthash = eina_hash_string_superfast_new(NULL); + if (ctx->fonts) { grp_it = elm_genlist_item_append(o, it_group, _("Standard"), NULL, ELM_GENLIST_ITEM_GROUP, @@ -510,19 +539,20 @@ options_font(Evas_Object *opbox, Evas_Object *term) } EINA_LIST_FOREACH(fontlist, l, fname) { - if (!eina_hash_find(fonthash, fname)) + if (!eina_hash_find(ctx->fonthash, fname)) { f = calloc(1, sizeof(Font)); - if (!f) break; + if (!f) + break; if (_parse_font_name(fname, &f->full_name, &f->pretty_name) <0) { free(f); continue; } - f->term = term; + f->ctx = ctx; f->bitmap = EINA_FALSE; - eina_hash_add(fonthash, eina_stringshare_add(fname), f); - fonts = eina_list_append(fonts, f); + eina_hash_add(ctx->fonthash, eina_stringshare_add(fname), f); + ctx->fonts = eina_list_append(ctx->fonts, f); f->item = it = elm_genlist_item_append(o, it_class, f, grp_it, ELM_GENLIST_ITEM_NONE, _cb_op_font_sel, f); @@ -568,12 +598,12 @@ options_font(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(bx0, o); evas_object_show(o); evas_object_smart_callback_add(o, "changed", - _cb_font_bolditalic, term); + _cb_font_bolditalic, ctx); - expecting_resize = 0; - evas_object_geometry_get(term, NULL, NULL, &tsize_w, &tsize_h); + ctx->expecting_resize = 0; + evas_object_geometry_get(term, NULL, NULL, &ctx->tsize_w, &ctx->tsize_h); evas_object_event_callback_add(term, EVAS_CALLBACK_RESIZE, - _cb_term_resize, term); + _cb_term_resize, ctx); evas_object_event_callback_add(opbox, EVAS_CALLBACK_DEL, - _cb_font_del, term); + _cb_font_del, ctx); } diff --git a/src/bin/options_font.h b/src/bin/options_font.h index 6976c27a..5ff2c5eb 100644 --- a/src/bin/options_font.h +++ b/src/bin/options_font.h @@ -1,7 +1,6 @@ #ifndef _OPTIONS_FONT_H__ #define _OPTIONS_FONT_H__ 1 -void options_font_clear(void); void options_font(Evas_Object *opbox, Evas_Object *term); #endif From 8b26cd4149dee21b9c4e8dc36ef22ccc6c8edc03 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sat, 13 Jan 2018 18:52:40 +0100 Subject: [PATCH 17/36] options_background: go to image grid when selecting user/system in hoversel --- src/bin/options_background.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/options_background.c b/src/bin/options_background.c index c99423f9..71b4c1b4 100644 --- a/src/bin/options_background.c +++ b/src/bin/options_background.c @@ -392,6 +392,7 @@ _cb_hoversel_select(Background_Ctx *ctx, const Eina_Stringshare *path) Evas_Object *o; if (path) { + elm_flip_go_to(ctx->flip, EINA_TRUE, ELM_FLIP_PAGE_LEFT); elm_object_text_set(ctx->entry, path); } else From 64502fa8f34bf8e3a6c4309cffb9f0183a988824 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sat, 13 Jan 2018 19:25:31 +0100 Subject: [PATCH 18/36] options_theme: be able to have multiple instances --- src/bin/options.c | 1 - src/bin/options_theme.c | 101 ++++++++++++++++++++++++---------------- src/bin/options_theme.h | 1 - 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/src/bin/options.c b/src/bin/options.c index 65f7d9c0..845f7e92 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -79,7 +79,6 @@ _cb_op_del_delay(void *data) evas_object_del(ctx->opbox); evas_object_del(ctx->frame); - options_theme_clear(); free(ctx); elm_cache_all_flush(); diff --git a/src/bin/options_theme.c b/src/bin/options_theme.c index d3733684..32abeeb6 100644 --- a/src/bin/options_theme.c +++ b/src/bin/options_theme.c @@ -2,6 +2,7 @@ #include #include +#include #include "config.h" #include "termio.h" #include "options.h" @@ -10,18 +11,23 @@ #include "utils.h" #include "main.h" +typedef struct _Theme_Ctx +{ + Evas_Object *term; + Config *config; + Evas_Object *op_themelist; + Eina_List *themes; + Ecore_Timer *seltimer; +} Theme_Ctx; + typedef struct _Theme Theme; struct _Theme { Elm_Object_Item *item; const char *name; - Evas_Object *term; + Theme_Ctx *ctx; }; -static Evas_Object *op_themelist; -static Eina_List *themes = NULL; -static Ecore_Timer *seltimer = NULL; - static char * _cb_op_theme_text_get(void *data, Evas_Object *_obj EINA_UNUSED, @@ -32,7 +38,8 @@ _cb_op_theme_text_get(void *data, eina_strlcpy(buf, t->name, sizeof(buf)); p = strrchr(buf, '.'); - if (p) *p = 0; + if (p) + *p = 0; return strdup(buf); } @@ -45,7 +52,7 @@ _cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part) if (!strcmp(part, "elm.swallow.icon")) { Evas_Object *o; - Config *config = termio_config_get(t->term); + Config *config = t->ctx->config; if (config) { @@ -66,14 +73,14 @@ _cb_op_theme_sel(void *data, void *_event EINA_UNUSED) { Theme *t = data; - Config *config = termio_config_get(t->term); + Config *config = t->ctx->config; if ((config->theme) && (!strcmp(t->name, config->theme))) return; eina_stringshare_replace(&(config->theme), t->name); config_save(config, NULL); - change_theme(termio_win_get(t->term), config); + change_theme(termio_win_get(t->ctx->term), config); } static int @@ -92,10 +99,35 @@ _cb_sel_item(void *data) elm_gengrid_item_selected_set(t->item, EINA_TRUE); elm_gengrid_item_bring_in(t->item, ELM_GENGRID_ITEM_SCROLLTO_MIDDLE); } - seltimer = NULL; + t->ctx->seltimer = NULL; return EINA_FALSE; } +static void +_parent_del_cb(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_event_info EINA_UNUSED) +{ + Theme_Ctx *ctx = data; + Theme *t; + + ctx->op_themelist = NULL; + + if (ctx->seltimer) + { + ecore_timer_del(ctx->seltimer); + ctx->seltimer = NULL; + } + EINA_LIST_FREE(ctx->themes, t) + { + eina_stringshare_del(t->name); + free(t); + } + + free(ctx); +} + void options_theme(Evas_Object *opbox, Evas_Object *term) { @@ -108,8 +140,13 @@ options_theme(Evas_Object *opbox, Evas_Object *term) Config *config = termio_config_get(term); Eina_Bool to_skip = EINA_FALSE; double scale = elm_config_scale_get(); + Theme_Ctx *ctx; - options_theme_clear(); + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); + + ctx->config = config; + ctx->term = term; fr = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -118,6 +155,9 @@ options_theme(Evas_Object *opbox, Evas_Object *term) elm_box_pack_end(opbox, o); evas_object_show(o); + evas_object_event_callback_add(fr, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + box = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -130,7 +170,7 @@ options_theme(Evas_Object *opbox, Evas_Object *term) it_class->func.text_get = _cb_op_theme_text_get; it_class->func.content_get = _cb_op_theme_content_get; - op_themelist = o = elm_gengrid_add(opbox); + ctx->op_themelist = o = elm_gengrid_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_gengrid_item_size_set(o, scale * 160, scale * 180); @@ -152,10 +192,10 @@ options_theme(Evas_Object *opbox, Evas_Object *term) else if (userfiles) files = userfiles; - if (seltimer) + if (ctx->seltimer) { - ecore_timer_del(seltimer); - seltimer = NULL; + ecore_timer_del(ctx->seltimer); + ctx->seltimer = NULL; } EINA_LIST_FOREACH_SAFE(files, l, l_next, file) @@ -185,19 +225,21 @@ options_theme(Evas_Object *opbox, Evas_Object *term) } t = calloc(1, sizeof(Theme)); - if (!t) break; + if (!t) + break; t->name = eina_stringshare_add(file); - t->term = term; + t->ctx = ctx; t->item = elm_gengrid_item_append(o, it_class, t, _cb_op_theme_sel, t); if (t->item) { - themes = eina_list_append(themes, t); + ctx->themes = eina_list_append(ctx->themes, t); if ((config) && (config->theme) && (!strcmp(config->theme, t->name))) { - if (seltimer) ecore_timer_del(seltimer); - seltimer = ecore_timer_add(0.2, _cb_sel_item, t); + if (ctx->seltimer) + ecore_timer_del(ctx->seltimer); + ctx->seltimer = ecore_timer_add(0.2, _cb_sel_item, t); } } else @@ -217,22 +259,3 @@ options_theme(Evas_Object *opbox, Evas_Object *term) evas_object_size_hint_align_set(opbox, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(o); } - -void -options_theme_clear(void) -{ - Theme *t; - - op_themelist = NULL; - - if (seltimer) - { - ecore_timer_del(seltimer); - seltimer = NULL; - } - EINA_LIST_FREE(themes, t) - { - eina_stringshare_del(t->name); - free(t); - } -} diff --git a/src/bin/options_theme.h b/src/bin/options_theme.h index fe2b66ce..dcd8c1ab 100644 --- a/src/bin/options_theme.h +++ b/src/bin/options_theme.h @@ -1,7 +1,6 @@ #ifndef _OPTIONS_THEME_H__ #define _OPTIONS_THEME_H__ 1 -void options_theme_clear(void); void options_theme(Evas_Object *opbox, Evas_Object *term); #endif From a66225dc87e4a82d8ed33e241cb9bb642a3558e6 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 14 Jan 2018 12:52:46 +0100 Subject: [PATCH 19/36] options_colors: be able to have multiple instances --- src/bin/options_colors.c | 157 ++++++++++++++++++++++++--------------- 1 file changed, 96 insertions(+), 61 deletions(-) diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index 6353a92f..f600f8e0 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -1,6 +1,7 @@ -#include - #include "private.h" + +#include +#include #include "config.h" #include "termio.h" #include "options.h" @@ -23,49 +24,59 @@ static const char *mapping_names[] = gettext_noop("Inverse Base") }; -static Elm_Object_Item *colitem[4][11] = { { NULL } }; -static Evas_Object *colorsel = NULL; -static Elm_Object_Item *curitem = NULL; -static Evas_Object *colpal[4] = { NULL }; -static Evas_Object *label = NULL, *reset = NULL; +typedef struct _Colors_Ctx { + Elm_Object_Item *colitem[4][11]; + Evas_Object *colorsel; + Elm_Object_Item *curitem; + Evas_Object *colpal[4]; + Evas_Object *label; + Evas_Object *reset; + Config *config; + Evas_Object *term; +} Colors_Ctx; static void _cb_op_use_custom_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Colors_Ctx *ctx = data; + Evas_Object *term = ctx->term; + Config *config = ctx->config; Eina_Bool state = EINA_FALSE; int i; - + state = elm_check_state_get(obj); - elm_object_disabled_set(colorsel, !state); - for (i = 0; i < 4; i++) elm_object_disabled_set(colpal[i], !state); - elm_object_disabled_set(label, !state); + elm_object_disabled_set(ctx->colorsel, !state); + + for (i = 0; i < 4; i++) + elm_object_disabled_set(ctx->colpal[i], !state); + + elm_object_disabled_set(ctx->label, !state); config->colors_use = state; termio_config_update(term); config_save(config, NULL); } static void -_cb_op_color_item_sel(void *_data EINA_UNUSED, +_cb_op_color_item_sel(void *data, Evas_Object *_obj EINA_UNUSED, void *event) { + Colors_Ctx *ctx = data; Elm_Object_Item *it = event; int r = 0, g = 0, b = 0, a = 0; int i, j; - - curitem = it; + + ctx->curitem = it; elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a); - elm_colorselector_color_set(colorsel, r, g, b, a); + elm_colorselector_color_set(ctx->colorsel, r, g, b, a); for (j = 0; j < 4; j++) { for (i = 0; i < 11; i++) { - if (colitem[j][i] == it) - elm_object_text_set(label, + if (ctx->colitem[j][i] == it) + elm_object_text_set(ctx->label, #if HAVE_GETTEXT && ENABLE_NLS gettext(mapping_names[i]) #else @@ -81,29 +92,29 @@ _cb_op_color_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Colors_Ctx *ctx = data; + Config *config = ctx->config; int r = 0, g = 0, b = 0, a = 0, rr = 0, gg = 0, bb = 0, aa = 0; int i, j; - elm_colorselector_palette_item_color_get(curitem, &rr, &gg, &bb, &aa); + elm_colorselector_palette_item_color_get(ctx->curitem, &rr, &gg, &bb, &aa); elm_colorselector_color_get(obj, &r, &g, &b, &a); if ((r != rr) || (g != gg) || (b != bb) || (a != aa)) { - if (curitem) - elm_colorselector_palette_item_color_set(curitem, r, g, b, a); - elm_object_disabled_set(reset, EINA_FALSE); + if (ctx->curitem) + elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a); + elm_object_disabled_set(ctx->reset, EINA_FALSE); for (j = 0; j < 4; j++) { for (i = 0; i < 11; i++) { - if (colitem[j][i] == curitem) + if (ctx->colitem[j][i] == ctx->curitem) { config->colors[(j * 12) + mapping[i]].r = r; config->colors[(j * 12) + mapping[i]].g = g; config->colors[(j * 12) + mapping[i]].b = b; config->colors[(j * 12) + mapping[i]].a = a; - termio_config_update(term); + termio_config_update(ctx->term); config_save(config, NULL); return; } @@ -117,17 +128,18 @@ _cb_op_reset(void *data, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - Evas_Object *term = data; - Config *config = termio_config_get(term); + Colors_Ctx *ctx = data; + Evas_Object *term = ctx->term; + Config *config = ctx->config; int r = 0, g = 0, b = 0, a = 0; int i, j; - + for (j = 0; j < 4; j++) { for (i = 0; i < 12; i++) { unsigned char rr = 0, gg = 0, bb = 0, aa = 0; - + colors_standard_get(j, i, &rr, &gg, &bb, &aa); config->colors[(j * 12) + i].r = rr; config->colors[(j * 12) + i].g = gg; @@ -137,30 +149,43 @@ _cb_op_reset(void *data, for (i = 0; i < 11; i++) { elm_colorselector_palette_item_color_set - (colitem[j][i], + (ctx->colitem[j][i], config->colors[(j * 12) + mapping[i]].r, config->colors[(j * 12) + mapping[i]].g, config->colors[(j * 12) + mapping[i]].b, config->colors[(j * 12) + mapping[i]].a); } } - elm_object_disabled_set(reset, EINA_TRUE); - elm_colorselector_palette_item_color_get(curitem, &r, &g, &b, &a); - elm_colorselector_color_set(colorsel, r, g, b, a); + elm_object_disabled_set(ctx->reset, EINA_TRUE); + elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a); + elm_colorselector_color_set(ctx->colorsel, r, g, b, a); termio_config_update(term); config_save(config, NULL); } +/* make color palettes wrap back. :) works with elm git. */ static void -_cb_op_scroller_resize(void *_data EINA_UNUSED, +_cb_op_scroller_resize(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, void *_event EINA_UNUSED) { - // make color palettes wrap back. :) works with elm git. + Colors_Ctx *ctx = data; int i; - - for (i = 0; i < 4; i++) evas_object_resize(colpal[i], 1, 1); + + for (i = 0; i < 4; i++) + evas_object_resize(ctx->colpal[i], 1, 1); +} + +static void +_parent_del_cb(void *data, + Evas *_e EINA_UNUSED, + Evas_Object *_obj EINA_UNUSED, + void *_event_info EINA_UNUSED) +{ + Colors_Ctx *ctx = data; + + free(ctx); } void @@ -170,29 +195,39 @@ options_colors(Evas_Object *opbox, Evas_Object *term) Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4; int i, j; int r = 0, g = 0, b = 0, a = 0; - + Colors_Ctx *ctx; + + ctx = calloc(1, sizeof(*ctx)); + assert(ctx); + + ctx->config = config; + ctx->term = term; + fr = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_object_text_set(o, _("Colors")); elm_box_pack_end(opbox, o); evas_object_show(o); - + + evas_object_event_callback_add(fr, EVAS_CALLBACK_DEL, + _parent_del_cb, ctx); + bx = o = elm_box_add(opbox); elm_box_horizontal_set(o, EINA_TRUE); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); elm_object_content_set(fr, o); evas_object_show(o); - + sc = o = elm_scroller_add(opbox); evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, - _cb_op_scroller_resize, NULL); + _cb_op_scroller_resize, ctx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_box_pack_end(bx, o); evas_object_show(o); - + bx3 = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); @@ -210,25 +245,25 @@ options_colors(Evas_Object *opbox, Evas_Object *term) evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_box_pack_end(bx3, o); evas_object_show(o); - - colpal[j] = o = elm_colorselector_add(opbox); + + ctx->colpal[j] = o = elm_colorselector_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE); for (i = 0; i < 11; i++) { Elm_Object_Item *it; - + it = elm_colorselector_palette_color_add (o, config->colors[(j * 12) + mapping[i]].r, config->colors[(j * 12) + mapping[i]].g, config->colors[(j * 12) + mapping[i]].b, config->colors[(j * 12) + mapping[i]].a); - colitem[j][i] = it; + ctx->colitem[j][i] = it; } evas_object_smart_callback_add(o, "color,item,selected", - _cb_op_color_item_sel, term); + _cb_op_color_item_sel, ctx); elm_box_pack_end(bx3, o); evas_object_show(o); if (j == 1) @@ -242,15 +277,15 @@ options_colors(Evas_Object *opbox, Evas_Object *term) } } - curitem = colitem[0][0]; - + ctx->curitem = ctx->colitem[0][0]; + bx2 = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); elm_box_pack_end(bx, o); evas_object_show(o); - - label = o = elm_label_add(opbox); + + ctx->label = o = elm_label_add(opbox); elm_object_text_set(o, #if HAVE_GETTEXT && ENABLE_NLS gettext(mapping_names[0]) @@ -262,16 +297,16 @@ options_colors(Evas_Object *opbox, Evas_Object *term) evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_box_pack_end(bx2, o); evas_object_show(o); - - colorsel = o = elm_colorselector_add(opbox); - elm_colorselector_palette_item_color_get(colitem[0][0], &r, &g, &b, &a); + + ctx->colorsel = o = elm_colorselector_add(opbox); + elm_colorselector_palette_item_color_get(ctx->colitem[0][0], &r, &g, &b, &a); elm_colorselector_color_set(o, r, g, b, a); elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_box_pack_end(bx2, o); evas_object_show(o); - evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, term); + evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, ctx); bx4 = o = elm_box_add(opbox); elm_box_horizontal_set(o, EINA_TRUE); @@ -279,7 +314,7 @@ options_colors(Evas_Object *opbox, Evas_Object *term) evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); elm_box_pack_end(bx2, o); evas_object_show(o); - + o = elm_check_add(opbox); evas_object_size_hint_weight_set(o, 1.0, 0.0); evas_object_size_hint_align_set(o, 0.0, 0.5); @@ -287,14 +322,14 @@ options_colors(Evas_Object *opbox, Evas_Object *term) elm_check_state_set(o, config->colors_use); elm_box_pack_end(bx4, o); evas_object_show(o); - evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, term); + evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, ctx); - reset = o = elm_button_add(opbox); + ctx->reset = o = elm_button_add(opbox); elm_object_disabled_set(o, EINA_TRUE); evas_object_size_hint_weight_set(o, 1.0, 0.0); evas_object_size_hint_align_set(o, 1.0, 0.5); elm_object_text_set(o, _("Reset")); elm_box_pack_end(bx4, o); evas_object_show(o); - evas_object_smart_callback_add(o, "clicked", _cb_op_reset, term); + evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx); } From 820a5440fe348fabe78fed3aeb87c6a53b5a4855 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 15 Jan 2018 22:45:32 +0100 Subject: [PATCH 20/36] controls: use both "bg" and "base" evas objects --- src/bin/about.c | 14 +++++++------- src/bin/about.h | 2 +- src/bin/controls.c | 18 ++++++++++-------- src/bin/controls.h | 3 ++- src/bin/options.c | 38 ++++++++++++++++++++------------------ src/bin/options.h | 5 +++-- src/bin/options_colors.c | 3 ++- src/bin/options_colors.h | 2 +- src/bin/win.c | 2 +- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/bin/about.c b/src/bin/about.c index 514533b6..3b9ea3f0 100644 --- a/src/bin/about.c +++ b/src/bin/about.c @@ -11,7 +11,7 @@ typedef struct _about_ctx { Evas_Object *layout; Evas_Object *over; Evas_Object *win; - Evas_Object *bg; + Evas_Object *base; Evas_Object *term; void (*donecb) (void *data); void *donedata; @@ -40,7 +40,7 @@ _cb_mouse_down(void *data, evas_object_del(ctx->over); } elm_object_focus_set(ctx->layout, EINA_FALSE); - edje_object_signal_emit(ctx->bg, "about,hide", "terminology"); + edje_object_signal_emit(ctx->base, "about,hide", "terminology"); ecore_timer_add(10.0, _cb_del_delay, ctx->layout); ctx->layout = NULL; @@ -52,7 +52,7 @@ _cb_mouse_down(void *data, } void -about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +about_show(Evas_Object *win, Evas_Object *base, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o; @@ -65,7 +65,7 @@ about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, assert(ctx); ctx->win = win; - ctx->bg = bg; + ctx->base = base; ctx->term = term; ctx->donecb = donecb; ctx->donedata = donedata; @@ -183,16 +183,16 @@ about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, elm_object_part_text_set(o, "terminology.text", txt); eina_stringshare_del(txt); evas_object_show(o); - edje_object_part_swallow(bg, "terminology.about", ctx->layout); + edje_object_part_swallow(base, "terminology.about", ctx->layout); ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(bg, "terminology.dismiss", o); + edje_object_part_swallow(base, "terminology.dismiss", o); evas_object_show(o); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down, ctx); - edje_object_signal_emit(bg, "about,show", "terminology"); + edje_object_signal_emit(base, "about,show", "terminology"); elm_object_signal_emit(ctx->layout, "begin" ,"terminology"); elm_object_focus_set(ctx->layout, EINA_TRUE); } diff --git a/src/bin/about.h b/src/bin/about.h index 71138e15..05bda9e0 100644 --- a/src/bin/about.h +++ b/src/bin/about.h @@ -1,7 +1,7 @@ #ifndef _ABOUT_H__ #define _ABOUT_H__ 1 -void about_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +void about_show(Evas_Object *win, Evas_Object *base, Evas_Object *term, void (*donecb) (void *data), void *donedata); #endif diff --git a/src/bin/controls.c b/src/bin/controls.c index 89fbc8d8..f51a1c06 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -14,6 +14,7 @@ typedef struct _Controls_Ctx { Evas_Object *frame; Evas_Object *over; Evas_Object *win; + Evas_Object *base; Evas_Object *bg; Evas_Object *term; void (*donecb) (void *data); @@ -164,7 +165,7 @@ _cb_ct_options(void *data, { Controls_Ctx *ctx = data; - options_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); + options_show(ctx->win, ctx->base, ctx->bg, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); } @@ -176,7 +177,7 @@ _cb_ct_about(void *data, { Controls_Ctx *ctx = data; - about_show(ctx->win, ctx->bg, ctx->term, _on_sub_done, ctx); + about_show(ctx->win, ctx->base, ctx->term, _on_sub_done, ctx); controls_hide(ctx, EINA_FALSE); } @@ -267,7 +268,7 @@ controls_hide(Controls_Ctx *ctx, Eina_Bool call_cb) if (ctx->term) { evas_object_event_callback_del(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del); - edje_object_signal_emit(ctx->bg, "controls,hide", "terminology"); + edje_object_signal_emit(ctx->base, "controls,hide", "terminology"); } if (ctx->over) @@ -292,8 +293,8 @@ controls_hide(Controls_Ctx *ctx, Eina_Bool call_cb) void -controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, - void (*donecb) (void *data), void *donedata) +controls_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, + Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o; Evas_Object *ct_boxh, *ct_boxv, *ct_box, *ct_box2, *ct_box3; @@ -309,6 +310,7 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, ctx = malloc(sizeof(*ctx)); assert(ctx); ctx->win = win; + ctx->base = base; ctx->bg = bg; ctx->term = term; ctx->donecb = donecb; @@ -406,16 +408,16 @@ controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, evas_object_smart_callback_add(win, "selection,off", _cb_sel_off, ctx); - edje_object_part_swallow(bg, "terminology.controls", ctx->frame); + edje_object_part_swallow(base, "terminology.controls", ctx->frame); evas_object_show(ctx->frame); ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(bg, "terminology.dismiss", o); + edje_object_part_swallow(base, "terminology.dismiss", o); evas_object_show(o); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down, ctx); - edje_object_signal_emit(bg, "controls,show", "terminology"); + edje_object_signal_emit(base, "controls,show", "terminology"); elm_object_focus_set(ctx->frame, EINA_TRUE); evas_object_event_callback_add(ctx->win, EVAS_CALLBACK_DEL, _cb_saved_del, ctx); evas_object_event_callback_add(ctx->term, EVAS_CALLBACK_DEL, _cb_saved_del, ctx); diff --git a/src/bin/controls.h b/src/bin/controls.h index d3f029b2..7a50fc13 100644 --- a/src/bin/controls.h +++ b/src/bin/controls.h @@ -1,7 +1,8 @@ #ifndef _CONTROLS_H__ #define _CONTROLS_H__ 1 -void controls_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +void controls_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, + Evas_Object *term, void (*donecb) (void *data), void *donedata); void controls_init(void); diff --git a/src/bin/options.c b/src/bin/options.c index 845f7e92..0d08ba7b 100644 --- a/src/bin/options.c +++ b/src/bin/options.c @@ -38,6 +38,7 @@ typedef struct _Options_Ctx { Evas_Object *opbox; Evas_Object *over; Evas_Object *win; + Evas_Object *base; Evas_Object *bg; Evas_Object *term; Config *config; @@ -60,7 +61,7 @@ _cb_op(void *data, ctx->mode = mode; - edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology"); + edje_object_signal_emit(ctx->base, "optdetails,hide", "terminology"); } static void @@ -100,7 +101,7 @@ _cb_opdt_hide_done(void *data, case OPTION_FONT: options_font(ctx->opbox, ctx->term); break; case OPTION_THEME: options_theme(ctx->opbox, ctx->term); break; case OPTION_BACKGROUND: options_background(ctx->opbox, ctx->term); break; - case OPTION_COLORS: options_colors(ctx->opbox, ctx->term); break; + case OPTION_COLORS: options_colors(ctx->opbox, ctx->term, ctx->bg); break; case OPTION_VIDEO: options_video(ctx->opbox, ctx->term); break; case OPTION_BEHAVIOR: options_behavior(ctx->opbox, ctx->term); break; case OPTION_KEYS: options_keys(ctx->opbox, ctx->term); break; @@ -108,7 +109,7 @@ _cb_opdt_hide_done(void *data, case OPTION_ELM: options_elm(ctx->opbox, ctx->term); break; case OPTIONS_MODE_NB: assert(0 && "should not occur"); } - edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology"); + edje_object_signal_emit(ctx->base, "optdetails,show", "terminology"); } static void @@ -119,7 +120,7 @@ _cb_opdt_hide_done2(void *data, { Options_Ctx *ctx = data; - edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done", + edje_object_signal_callback_del(ctx->base, "optdetails,hide,done", "terminology", _cb_opdt_hide_done2); ecore_timer_add(10.0, _cb_op_del_delay, ctx); @@ -128,15 +129,15 @@ _cb_opdt_hide_done2(void *data, static void options_hide(Options_Ctx *ctx) { - edje_object_part_swallow(ctx->bg, "terminology.optdetails", ctx->opbox); - edje_object_part_swallow(ctx->bg, "terminology.options", ctx->frame); - edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology"); - edje_object_signal_emit(ctx->bg, "options,show", "terminology"); + edje_object_part_swallow(ctx->base, "terminology.optdetails", ctx->opbox); + edje_object_part_swallow(ctx->base, "terminology.options", ctx->frame); + edje_object_signal_emit(ctx->base, "optdetails,show", "terminology"); + edje_object_signal_emit(ctx->base, "options,show", "terminology"); - edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done", + edje_object_signal_callback_del(ctx->base, "optdetails,hide,done", "terminology", _cb_opdt_hide_done); - edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done", + edje_object_signal_callback_add(ctx->base, "optdetails,hide,done", "terminology", _cb_opdt_hide_done2, ctx); elm_object_focus_set(ctx->frame, EINA_FALSE); @@ -146,8 +147,8 @@ options_hide(Options_Ctx *ctx) evas_object_del(ctx->over); ctx->over = NULL; - edje_object_signal_emit(ctx->bg, "options,hide", "terminology"); - edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology"); + edje_object_signal_emit(ctx->base, "options,hide", "terminology"); + edje_object_signal_emit(ctx->base, "optdetails,hide", "terminology"); if (ctx->donecb) ctx->donecb(ctx->donedata); @@ -166,7 +167,7 @@ _cb_mouse_down(void *data, void -options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, +options_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata) { Evas_Object *o, *op_box, *op_tbox; @@ -182,6 +183,7 @@ options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, assert(ctx); ctx->mode = OPTION_NONE; ctx->win = win; + ctx->base = base; ctx->bg = bg; ctx->term = term; ctx->donecb = donecb; @@ -194,7 +196,7 @@ options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, ctx->opbox = o = elm_box_add(win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); - edje_object_part_swallow(ctx->bg, "terminology.optdetails", o); + edje_object_part_swallow(ctx->base, "terminology.optdetails", o); evas_object_show(o); ctx->frame = o = elm_frame_add(win); @@ -254,19 +256,19 @@ options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, evas_object_show(o); evas_object_smart_callback_add(o, "changed", _cb_op_tmp_chg, ctx); - edje_object_part_swallow(bg, "terminology.options", ctx->frame); + edje_object_part_swallow(base, "terminology.options", ctx->frame); evas_object_show(ctx->frame); - edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done", + edje_object_signal_callback_add(ctx->base, "optdetails,hide,done", "terminology", _cb_opdt_hide_done, ctx); ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win)); evas_object_color_set(o, 0, 0, 0, 0); - edje_object_part_swallow(ctx->bg, "terminology.dismiss", o); + edje_object_part_swallow(ctx->base, "terminology.dismiss", o); evas_object_show(o); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down, ctx); - edje_object_signal_emit(ctx->bg, "options,show", "terminology"); + edje_object_signal_emit(ctx->base, "options,show", "terminology"); elm_object_focus_set(ctx->toolbar, EINA_TRUE); } diff --git a/src/bin/options.h b/src/bin/options.h index e02a039e..12aa8413 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -1,7 +1,8 @@ #ifndef _TERMINOLOGY_OPTIONS_H__ #define _TERMINOLOGY_OPTIONS_H__ 1 -void options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term, - void (*donecb) (void *data), void *donedata); +void options_show(Evas_Object *win, Evas_Object *base, Evas_Object *bg, + Evas_Object *term, + void (*donecb) (void *data), void *donedata); #endif diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index f600f8e0..092ebbc1 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -189,7 +189,7 @@ _parent_del_cb(void *data, } void -options_colors(Evas_Object *opbox, Evas_Object *term) +options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) { Config *config = termio_config_get(term); Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4; @@ -202,6 +202,7 @@ options_colors(Evas_Object *opbox, Evas_Object *term) ctx->config = config; ctx->term = term; + ctx->bg = bg; fr = o = elm_frame_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/src/bin/options_colors.h b/src/bin/options_colors.h index 0512d989..d335439c 100644 --- a/src/bin/options_colors.h +++ b/src/bin/options_colors.h @@ -1,6 +1,6 @@ #ifndef _OPTIONS_COLORS_H__ #define _OPTIONS_COLORS_H__ 1 -void options_colors(Evas_Object *opbox, Evas_Object *term); +void options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg); #endif diff --git a/src/bin/win.c b/src/bin/win.c index 67763616..38b84bd8 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -5009,7 +5009,7 @@ _cb_options(void *data, { Term *term = data; - controls_show(term->wn->win, term->wn->base, term->termio, + controls_show(term->wn->win, term->wn->base, term->bg, term->termio, _cb_options_done, term->wn); } From f33e898e291e95d133358e5f79083fb374eaa1b4 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 15 Jan 2018 22:51:16 +0100 Subject: [PATCH 21/36] options_colors: clean up a bit and have a global reset button --- src/bin/options_colors.c | 161 ++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 70 deletions(-) diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index 092ebbc1..88bea6ee 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -7,8 +7,6 @@ #include "options.h" #include "options_colors.h" - -static const char mapping[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 }; static const char *mapping_names[] = { gettext_noop("Default"), @@ -20,12 +18,13 @@ static const char *mapping_names[] = gettext_noop("Magenta"), gettext_noop("Cyan"), gettext_noop("White"), + gettext_noop("Invisible"), gettext_noop("Inverse"), - gettext_noop("Inverse Base") + gettext_noop("Inverse Background") }; typedef struct _Colors_Ctx { - Elm_Object_Item *colitem[4][11]; + Elm_Object_Item *colitem[4][12]; Evas_Object *colorsel; Elm_Object_Item *curitem; Evas_Object *colpal[4]; @@ -33,31 +32,9 @@ typedef struct _Colors_Ctx { Evas_Object *reset; Config *config; Evas_Object *term; + Evas_Object *bg; } Colors_Ctx; -static void -_cb_op_use_custom_chg(void *data, - Evas_Object *obj, - void *_event EINA_UNUSED) -{ - Colors_Ctx *ctx = data; - Evas_Object *term = ctx->term; - Config *config = ctx->config; - Eina_Bool state = EINA_FALSE; - int i; - - state = elm_check_state_get(obj); - elm_object_disabled_set(ctx->colorsel, !state); - - for (i = 0; i < 4; i++) - elm_object_disabled_set(ctx->colpal[i], !state); - - elm_object_disabled_set(ctx->label, !state); - config->colors_use = state; - termio_config_update(term); - config_save(config, NULL); -} - static void _cb_op_color_item_sel(void *data, Evas_Object *_obj EINA_UNUSED, @@ -73,8 +50,10 @@ _cb_op_color_item_sel(void *data, elm_colorselector_color_set(ctx->colorsel, r, g, b, a); for (j = 0; j < 4; j++) { - for (i = 0; i < 11; i++) + for (i = 0; i < 12; i++) { + if (i == COL_INVIS) + continue; if (ctx->colitem[j][i] == it) elm_object_text_set(ctx->label, #if HAVE_GETTEXT && ENABLE_NLS @@ -104,16 +83,19 @@ _cb_op_color_chg(void *data, if (ctx->curitem) elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a); elm_object_disabled_set(ctx->reset, EINA_FALSE); + config->colors_use = EINA_TRUE; for (j = 0; j < 4; j++) { - for (i = 0; i < 11; i++) + for (i = 0; i < 12; i++) { + if (i == COL_INVIS) + continue; if (ctx->colitem[j][i] == ctx->curitem) { - config->colors[(j * 12) + mapping[i]].r = r; - config->colors[(j * 12) + mapping[i]].g = g; - config->colors[(j * 12) + mapping[i]].b = b; - config->colors[(j * 12) + mapping[i]].a = a; + config->colors[(j * 12) + i].r = r; + config->colors[(j * 12) + i].g = g; + config->colors[(j * 12) + i].b = b; + config->colors[(j * 12) + i].a = a; termio_config_update(ctx->term); config_save(config, NULL); return; @@ -123,6 +105,48 @@ _cb_op_color_chg(void *data, } } +static void +_reset_config_colors(Colors_Ctx *ctx) +{ + int i, j; + + for (j = 0; j < 4; j++) + { + for (i = 0; i < 12; i++) + { + int r, g, b, a; + unsigned char rr = 0, gg = 0, bb = 0, aa = 0; + char buf[32]; + + if (i == COL_INVIS) + continue; + + snprintf(buf, sizeof(buf) - 1, "c%i", j * 12 + i); + if (!edje_object_color_class_get(ctx->bg, buf, + &r, + &g, + &b, + &a, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL)) + { + colors_standard_get(j, i, &rr, &gg, &bb, &aa); + } + else + { + rr = r; + gg = g; + bb = b; + aa = a; + } + ctx->config->colors[(j * 12) + i].r = rr; + ctx->config->colors[(j * 12) + i].g = gg; + ctx->config->colors[(j * 12) + i].b = bb; + ctx->config->colors[(j * 12) + i].a = aa; + } + } +} + static void _cb_op_reset(void *data, Evas_Object *_obj EINA_UNUSED, @@ -134,29 +158,24 @@ _cb_op_reset(void *data, int r = 0, g = 0, b = 0, a = 0; int i, j; + _reset_config_colors(ctx); for (j = 0; j < 4; j++) { for (i = 0; i < 12; i++) { - unsigned char rr = 0, gg = 0, bb = 0, aa = 0; + if (i == COL_INVIS) + continue; - colors_standard_get(j, i, &rr, &gg, &bb, &aa); - config->colors[(j * 12) + i].r = rr; - config->colors[(j * 12) + i].g = gg; - config->colors[(j * 12) + i].b = bb; - config->colors[(j * 12) + i].a = aa; - } - for (i = 0; i < 11; i++) - { elm_colorselector_palette_item_color_set (ctx->colitem[j][i], - config->colors[(j * 12) + mapping[i]].r, - config->colors[(j * 12) + mapping[i]].g, - config->colors[(j * 12) + mapping[i]].b, - config->colors[(j * 12) + mapping[i]].a); + config->colors[(j * 12) + i].r, + config->colors[(j * 12) + i].g, + config->colors[(j * 12) + i].b, + config->colors[(j * 12) + i].a); } } elm_object_disabled_set(ctx->reset, EINA_TRUE); + config->colors_use = EINA_FALSE; elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a); elm_colorselector_color_set(ctx->colorsel, r, g, b, a); termio_config_update(term); @@ -222,12 +241,12 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) evas_object_show(o); sc = o = elm_scroller_add(opbox); - evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, - _cb_op_scroller_resize, ctx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); elm_box_pack_end(bx, o); evas_object_show(o); + evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, + _cb_op_scroller_resize, ctx); bx3 = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); @@ -235,13 +254,21 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) elm_object_content_set(sc, o); evas_object_show(o); + if (!config->colors_use) + { + _reset_config_colors(ctx); + } for (j = 0; j < 4; j++) { o = elm_label_add(opbox); - if (j == 0) elm_object_text_set(o, _("Normal")); - else if (j == 1) elm_object_text_set(o, _("Bright/Bold")); - else if (j == 2) elm_object_text_set(o, _("Intense")); - else if (j == 3) elm_object_text_set(o, _("Intense Bright/Bold")); + if (j == 0) + elm_object_text_set(o, _("Normal")); + else if (j == 1) + elm_object_text_set(o, _("Bright/Bold")); + else if (j == 2) + elm_object_text_set(o, _("Intense")); + else if (j == 3) + elm_object_text_set(o, _("Intense Bright/Bold")); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_box_pack_end(bx3, o); @@ -251,22 +278,25 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE); - for (i = 0; i < 11; i++) + for (i = 0; i < 12; i++) { Elm_Object_Item *it; + if (i == COL_INVIS) + continue; + it = elm_colorselector_palette_color_add (o, - config->colors[(j * 12) + mapping[i]].r, - config->colors[(j * 12) + mapping[i]].g, - config->colors[(j * 12) + mapping[i]].b, - config->colors[(j * 12) + mapping[i]].a); + config->colors[(j * 12) + i].r, + config->colors[(j * 12) + i].g, + config->colors[(j * 12) + i].b, + config->colors[(j * 12) + i].a); ctx->colitem[j][i] = it; } - evas_object_smart_callback_add(o, "color,item,selected", - _cb_op_color_item_sel, ctx); elm_box_pack_end(bx3, o); evas_object_show(o); + evas_object_smart_callback_add(o, "color,item,selected", + _cb_op_color_item_sel, ctx); if (j == 1) { o = elm_separator_add(opbox); @@ -316,20 +346,11 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) elm_box_pack_end(bx2, o); evas_object_show(o); - o = elm_check_add(opbox); - evas_object_size_hint_weight_set(o, 1.0, 0.0); - evas_object_size_hint_align_set(o, 0.0, 0.5); - elm_object_text_set(o, _("Use")); - elm_check_state_set(o, config->colors_use); - elm_box_pack_end(bx4, o); - evas_object_show(o); - evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, ctx); - ctx->reset = o = elm_button_add(opbox); - elm_object_disabled_set(o, EINA_TRUE); + elm_object_disabled_set(o, !config->colors_use); evas_object_size_hint_weight_set(o, 1.0, 0.0); evas_object_size_hint_align_set(o, 1.0, 0.5); - elm_object_text_set(o, _("Reset")); + elm_object_text_set(o, _("Reset all the colors")); elm_box_pack_end(bx4, o); evas_object_show(o); evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx); From 8c09ee5c88069d8f343913f62688aade0a038131 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 15 Jan 2018 23:28:18 +0100 Subject: [PATCH 22/36] options_colors: compute pre-multiplied colors --- src/bin/options_colors.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index 88bea6ee..192c224d 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -92,9 +92,9 @@ _cb_op_color_chg(void *data, continue; if (ctx->colitem[j][i] == ctx->curitem) { - config->colors[(j * 12) + i].r = r; - config->colors[(j * 12) + i].g = g; - config->colors[(j * 12) + i].b = b; + config->colors[(j * 12) + i].r = r * a / 256; + config->colors[(j * 12) + i].g = g * a / 256; + config->colors[(j * 12) + i].b = b * a / 256; config->colors[(j * 12) + i].a = a; termio_config_update(ctx->term); config_save(config, NULL); From 527859f4c409a5e9c7a7ba62e4248de2a4702426 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 15 Jan 2018 23:49:03 +0100 Subject: [PATCH 23/36] options_colors: fix selected item showing on multiple rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit makes the selector barely more usableā€¦ --- src/bin/options_colors.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index 192c224d..f3b56a8b 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -45,6 +45,10 @@ _cb_op_color_item_sel(void *data, int r = 0, g = 0, b = 0, a = 0; int i, j; + if (ctx->curitem == it) + return; + if (ctx->curitem) + elm_colorselector_palette_item_selected_set(ctx->curitem, EINA_FALSE); ctx->curitem = it; elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a); elm_colorselector_color_set(ctx->colorsel, r, g, b, a); @@ -147,6 +151,7 @@ _reset_config_colors(Colors_Ctx *ctx) } } + static void _cb_op_reset(void *data, Evas_Object *_obj EINA_UNUSED, @@ -292,6 +297,11 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) config->colors[(j * 12) + i].b, config->colors[(j * 12) + i].a); ctx->colitem[j][i] = it; + if (i == 0 && j == 0) + { + ctx->curitem = ctx->colitem[0][0]; + elm_colorselector_palette_item_selected_set(ctx->curitem, EINA_TRUE); + } } elm_box_pack_end(bx3, o); evas_object_show(o); @@ -308,8 +318,6 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) } } - ctx->curitem = ctx->colitem[0][0]; - bx2 = o = elm_box_add(opbox); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); @@ -330,7 +338,7 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg) evas_object_show(o); ctx->colorsel = o = elm_colorselector_add(opbox); - elm_colorselector_palette_item_color_get(ctx->colitem[0][0], &r, &g, &b, &a); + elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a); elm_colorselector_color_set(o, r, g, b, a); elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); From 93106d11487cfd8b4f23292c4ca08462f7ecadd1 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 30 Jan 2018 23:31:26 +0100 Subject: [PATCH 24/36] win: set flag on_options when settings/about/controls are up --- src/bin/win.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 38b84bd8..18e2fa2c 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -173,6 +173,7 @@ struct _Win unsigned char group_input : 1; unsigned char group_only_visible : 1; unsigned char group_once_handled : 1; + unsigned char on_options : 1; }; /* }}} */ @@ -1122,6 +1123,9 @@ _cb_win_key_up(void *data, Term *term; const Evas_Event_Key_Up *ev = event_info; + if (wn->on_options) + return; + DBG("GROUP key up (%p) (ctrl:%d)", wn, evas_key_modifier_is_set(ev->modifiers, "Control")); if (wn->group_input) @@ -1158,6 +1162,9 @@ _cb_win_key_down(void *data, DBG("GROUP key down (%p) (ctrl:%d)", wn, evas_key_modifier_is_set(ev->modifiers, "Control")); + if (wn->on_options) + return; + int ctrl, alt, shift, win, meta, hyper; ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); @@ -1203,6 +1210,10 @@ _cb_win_mouse_down(void *data, Term_Container *tc = (Term_Container*) wn; Term_Container *tc_child; + if (wn->on_options) + return; + + /* TODO: boris: maybe not so strict */ DBG("mouse down"); if (wn->group_input) return; @@ -1234,6 +1245,10 @@ _cb_win_mouse_move(void *data, Term_Container *tc = (Term_Container*) wn; Term_Container *tc_child = NULL; + if (wn->on_options) + return; + + /* TODO: boris: maybe not so strict */ if (wn->group_input) return; @@ -4982,24 +4997,29 @@ _cb_bell(void *data, static void _cb_options_done(void *data) { - Win *wn = data; + Term *orig_term = data; + Win *wn = orig_term->wn; Term_Container *tc = (Term_Container*) wn; Eina_List *l; Term *term; - if (!_win_is_focused(wn)) return; + wn->on_options = EINA_FALSE; + + if (!_win_is_focused(wn)) + goto end; EINA_LIST_FOREACH(wn->terms, l, term) { DBG("is focused? tc:%p", term->container); if (_term_is_focused(term)) { - elm_object_focus_set(term->termio, EINA_TRUE); - termio_event_feed_mouse_in(term->termio); - return; + goto end; } } DBG("focus tc:%p", tc); tc->focus(tc, tc); + +end: + term_unref(orig_term); } static void @@ -5008,9 +5028,15 @@ _cb_options(void *data, void *_event EINA_UNUSED) { Term *term = data; + Term_Container *tc = term->container; + + term->wn->on_options = EINA_TRUE; + + term_ref(term); + tc->unfocus(tc, NULL); controls_show(term->wn->win, term->wn->base, term->bg, term->termio, - _cb_options_done, term->wn); + _cb_options_done, term); } void From b75d5b7e9c60b710a33d11b06289fc93ecdb2c18 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 30 Jan 2018 23:36:16 +0100 Subject: [PATCH 25/36] win: do not focus termio --- src/bin/win.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 18e2fa2c..8165f233 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -418,9 +418,6 @@ _solo_unfocus(Term_Container *tc, Term_Container *relative) edje_object_signal_emit(term->bg, "focus,out", "terminology"); edje_object_signal_emit(term->base, "focus,out", "terminology"); } - - if (!tc->wn->cmdbox_up) - elm_object_focus_set(term->termio, EINA_FALSE); } static void @@ -458,11 +455,8 @@ _solo_focus(Term_Container *tc, Term_Container *relative) edje_object_signal_emit(term->bg, "focus,in", "terminology"); edje_object_signal_emit(term->base, "focus,in", "terminology"); } - termio_focus_in(term->termio); if (term->wn->cmdbox) elm_object_focus_set(term->wn->cmdbox, EINA_FALSE); - //elm_object_focus_set(term->termio, EINA_TRUE); - //termio_event_feed_mouse_in(term->termio); title = termio_title_get(term->termio); if (title) @@ -562,8 +556,6 @@ _cb_win_focus_in(void *data, edje_object_signal_emit(term->bg, "focus,out", "terminology"); edje_object_signal_emit(term->base, "focus,out", "terminology"); } - if (!wn->cmdbox_up) - elm_object_focus_set(term->termio, EINA_FALSE); } term = term_mouse; } @@ -4201,7 +4193,6 @@ _sendfile_request(Term *term, const char *path) edje_object_part_swallow(term->bg, "terminology.sendfile.request", o); evas_object_show(o); edje_object_signal_emit(term->bg, "sendfile,request,on", "terminology"); - elm_object_focus_set(term->termio, EINA_FALSE); elm_object_focus_set(o, EINA_TRUE); } @@ -4389,11 +4380,8 @@ _cb_cmd_focus(void *data) wn->cmdbox_focus_timer = NULL; tc = (Term_Container*) wn; term = tc->focused_term_get(tc); - if (term) - { - elm_object_focus_set(term->termio, EINA_FALSE); - if (term->wn->cmdbox) elm_object_focus_set(wn->cmdbox, EINA_TRUE); - } + if (term && term->wn->cmdbox) + elm_object_focus_set(wn->cmdbox, EINA_TRUE); return EINA_FALSE; } @@ -4425,7 +4413,6 @@ _cb_cmd_activated(void *data, edje_object_signal_emit(wn->base, "cmdbox,hide", "terminology"); tc = (Term_Container *) wn; term = tc->focused_term_get(tc); - if (term) elm_object_focus_set(term->termio, EINA_TRUE); if (wn->cmdbox) cmd = (char *)elm_entry_entry_get(wn->cmdbox); if (cmd) { @@ -4452,14 +4439,9 @@ _cb_cmd_aborted(void *data, void *_event EINA_UNUSED) { Win *wn = data; - Term *term; - Term_Container *tc; if (wn->cmdbox) elm_object_focus_set(wn->cmdbox, EINA_FALSE); edje_object_signal_emit(wn->base, "cmdbox,hide", "terminology"); - tc = (Term_Container*) wn; - term = tc->focused_term_get(tc); - if (term) elm_object_focus_set(term->termio, EINA_TRUE); if (wn->cmdbox_focus_timer) { ecore_timer_del(wn->cmdbox_focus_timer); @@ -4542,7 +4524,6 @@ _cb_cmdbox(void *data, edje_object_part_swallow(wn->base, "terminology.cmdbox", o); } edje_object_signal_emit(term->wn->base, "cmdbox,show", "terminology"); - elm_object_focus_set(term->termio, EINA_FALSE); elm_entry_entry_set(term->wn->cmdbox, ""); evas_object_show(term->wn->cmdbox); if (term->wn->cmdbox_focus_timer) @@ -4902,7 +4883,6 @@ _term_bg_config(Term *term) } if (term->wn->cmdbox) elm_object_focus_set(term->wn->cmdbox, EINA_FALSE); - elm_object_focus_set(term->termio, EINA_TRUE); } if (term->miniview_shown) edje_object_signal_emit(term->bg, "miniview,on", "terminology"); From e5c580aa267dde164a6d7b1ef3c9e9a1d80dcf8c Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Tue, 30 Jan 2018 23:37:00 +0100 Subject: [PATCH 26/36] win: getting events through conform is more reliable --- src/bin/win.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 8165f233..399d9d5c 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1344,22 +1344,27 @@ win_new(const char *name, const char *role, const char *title, elm_object_content_set(wn->conform, o); evas_object_show(o); + elm_object_focus_allow_set(wn->conform, EINA_TRUE); + elm_object_tree_focus_allow_set(wn->win, EINA_TRUE); + evas_object_show(wn->win); + elm_object_focus_set(wn->conform, EINA_TRUE); + evas_object_smart_callback_add(wn->win, "focus,in", _cb_win_focus_in, wn); evas_object_smart_callback_add(wn->win, "focus,out", _cb_win_focus_out, wn); - evas_object_event_callback_add(wn->win, + evas_object_event_callback_add(wn->conform, EVAS_CALLBACK_KEY_DOWN, _cb_win_key_down, wn); - evas_object_event_callback_add(wn->win, + evas_object_event_callback_add(wn->conform, EVAS_CALLBACK_KEY_UP, _cb_win_key_up, wn); - evas_object_event_callback_add(wn->win, + evas_object_event_callback_add(wn->conform, EVAS_CALLBACK_MOUSE_DOWN, _cb_win_mouse_down, wn); - evas_object_event_callback_add(wn->win, + evas_object_event_callback_add(wn->conform, EVAS_CALLBACK_MOUSE_MOVE, _cb_win_mouse_move, wn); From d7432a52d6a38bc5d8fbb47b58bfa3fd41cd0d3f Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Mon, 5 Feb 2018 00:07:47 +0100 Subject: [PATCH 27/36] move input handling to win.c --- src/bin/keyin.c | 84 +--------- src/bin/keyin.h | 13 +- src/bin/termio.c | 240 ++++----------------------- src/bin/termio.h | 6 +- src/bin/termpty.c | 24 +++ src/bin/win.c | 409 +++++++++++++++++++++++++++++++++++++++++++--- src/bin/win.h | 3 + 7 files changed, 464 insertions(+), 315 deletions(-) diff --git a/src/bin/keyin.c b/src/bin/keyin.c index 78601afc..c5bc7f24 100644 --- a/src/bin/keyin.c +++ b/src/bin/keyin.c @@ -102,9 +102,9 @@ keyin_compose_seq_reset(Keys_Handler *khdl) #include "tty_keys.h" -static void -_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev, - int alt, int shift, int ctrl) +void +keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev, + const int alt, const int shift, const int ctrl) { if (!ev->key) return; @@ -228,92 +228,24 @@ key_binding_lookup(const char *keyname, } Eina_Bool -keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev, - Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win, - Eina_Bool meta, Eina_Bool hyper) +keyin_handle_key_binding(Evas_Object *termio, const Evas_Event_Key_Down *ev, + Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, + Eina_Bool win, Eina_Bool meta, Eina_Bool hyper) { Key_Binding *kb; kb = key_binding_lookup(ev->keyname, ctrl, alt, shift, win, meta, hyper); if (kb) { - if (kb->cb(ty->obj)) + if (kb->cb(termio)) { - keyin_compose_seq_reset(khdl); return EINA_TRUE; } } - - /* composing */ - if (khdl->imf) - { - // EXCEPTION. Don't filter modifiers alt+shift -> breaks emacs - // and jed (alt+shift+5 for search/replace for example) - // Don't filter modifiers alt, is used by shells - if ((!alt) && (!ctrl)) - { - Ecore_IMF_Event_Key_Down imf_ev; - - ecore_imf_evas_event_key_down_wrap((Evas_Event_Key_Down*)ev, &imf_ev); - if (!khdl->composing) - { - if (ecore_imf_context_filter_event - (khdl->imf, ECORE_IMF_EVENT_KEY_DOWN, (Ecore_IMF_Event *)&imf_ev)) - goto end; - } - } - } - - // if term app asked for kbd lock - dont handle here - if (ty->termstate.kbd_lock) return EINA_TRUE; - // if app asked us to not do autorepeat - ignore press if is it is the same - // timestamp as last one - if ((ty->termstate.no_autorepeat) && - (ev->timestamp == khdl->last_keyup)) return EINA_TRUE; - if (!khdl->composing) - { - Ecore_Compose_State state; - char *compres = NULL; - - keyin_compose_seq_reset(khdl); - khdl->seq = eina_list_append(khdl->seq, eina_stringshare_add(ev->key)); - state = ecore_compose_get(khdl->seq, &compres); - if (state == ECORE_COMPOSE_MIDDLE) khdl->composing = EINA_TRUE; - else khdl->composing = EINA_FALSE; - if (!khdl->composing) keyin_compose_seq_reset(khdl); - else goto end; - } - else - { - Ecore_Compose_State state; - char *compres = NULL; - - if (key_is_modifier(ev->key)) goto end; - khdl->seq = eina_list_append(khdl->seq, eina_stringshare_add(ev->key)); - state = ecore_compose_get(khdl->seq, &compres); - if (state == ECORE_COMPOSE_NONE) keyin_compose_seq_reset(khdl); - else if (state == ECORE_COMPOSE_DONE) - { - keyin_compose_seq_reset(khdl); - if (compres) - { - termpty_write(ty, compres, strlen(compres)); - free(compres); - compres = NULL; - } - goto end; - } - else goto end; - } - - - _handle_key_to_pty(ty, ev, alt, shift, ctrl); - - -end: return EINA_FALSE; } + Eina_Bool key_is_modifier(const char *key) { diff --git a/src/bin/keyin.h b/src/bin/keyin.h index d9127a17..ccfa644d 100644 --- a/src/bin/keyin.h +++ b/src/bin/keyin.h @@ -11,12 +11,19 @@ struct _Keys_Handler unsigned char composing : 1; }; +void +keyin_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev, + const int alt, const int shift, const int ctrl); +Eina_Bool +termpty_can_handle_key(const Termpty *ty, + const Keys_Handler *khdl, + const Evas_Event_Key_Down *ev); void keyin_compose_seq_reset(Keys_Handler *khdl); Eina_Bool key_is_modifier(const char *key); Eina_Bool -keyin_handle(Keys_Handler *khdl, Termpty *ty, const Evas_Event_Key_Down *ev, - Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win, - Eina_Bool meta, Eina_Bool hyper); +keyin_handle_key_binding(Evas_Object *termio, const Evas_Event_Key_Down *ev, + Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, + Eina_Bool win, Eina_Bool meta, Eina_Bool hyper); void keyin_handle_up(Keys_Handler *khdl, Evas_Event_Key_Up *ev); diff --git a/src/bin/termio.c b/src/bin/termio.c index 01e5227c..f7f178e1 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -86,12 +86,10 @@ struct _Termio Evas_Object *win, *theme, *glayer; Config *config; const char *sel_str; - const char *preedit_str; Eina_List *cur_chids; Ecore_Job *sel_reset_job; double set_sel_at; Elm_Sel_Type sel_type; - Keys_Handler khdl; unsigned char jump_on_change : 1; unsigned char jump_on_keypress : 1; unsigned char have_sel : 1; @@ -1983,72 +1981,6 @@ _block_obj_del(Termblock *blk) blk->obj = NULL; } -/* }}} */ -/* {{{ Keys */ - -static void -_smart_cb_key_up(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *event) -{ - Evas_Event_Key_Up *ev = event; - Termio *sd = evas_object_smart_data_get(data); - - EINA_SAFETY_ON_NULL_RETURN(sd); - - keyin_handle_up(&sd->khdl, ev); -} - -static void -_smart_cb_key_down(void *data, - Evas *_e EINA_UNUSED, - Evas_Object *_obj EINA_UNUSED, - void *event) -{ - const Evas_Event_Key_Down *ev = event; - Termio *sd = evas_object_smart_data_get(data); - int ctrl, alt, shift, win, meta, hyper; - - EINA_SAFETY_ON_NULL_RETURN(sd); - EINA_SAFETY_ON_NULL_RETURN(ev->key); - - if (miniview_handle_key(term_miniview_get(sd->term), ev)) - return; - - if (term_has_popmedia(sd->term) && !strcmp(ev->key, "Escape")) - { - term_popmedia_close(sd->term); - return; - } - - ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); - alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); - shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); - win = evas_key_modifier_is_set(ev->modifiers, "Super"); - meta = evas_key_modifier_is_set(ev->modifiers, "Meta") || - evas_key_modifier_is_set(ev->modifiers, "AltGr") || - evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift"); - hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper"); - ERR("ctrl:%d alt:%d shift:%d win:%d meta:%d hyper:%d", - ctrl, alt, shift, win, meta, hyper); - - if (keyin_handle(&sd->khdl, sd->pty, ev, ctrl, alt, shift, win, meta, hyper)) - goto end; - - if (sd->jump_on_keypress) - { - if (!key_is_modifier(ev->key)) - { - sd->scroll = 0; - _smart_update_queue(data, sd); - } - } -end: - if (sd->config->flicker_on_key) - edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology"); -} - /* }}} */ /* {{{ Selection */ @@ -3496,16 +3428,19 @@ termio_event_feed_mouse_in(Evas_Object *obj) evas_event_feed_mouse_in(e, 0, NULL); } -static void -_imf_cursor_set(Termio *sd) +void +termio_imf_cursor_set(Evas_Object *obj, Ecore_IMF_Context *imf) { - /* TODO */ + Termio *sd = evas_object_smart_data_get(obj); Evas_Coord cx, cy, cw, ch; + + if (!imf) + return; + + EINA_SAFETY_ON_NULL_RETURN(sd); evas_object_geometry_get(sd->cursor.obj, &cx, &cy, &cw, &ch); - if (sd->khdl.imf) - ecore_imf_context_cursor_location_set(sd->khdl.imf, cx, cy, cw, ch); - if (sd->khdl.imf) ecore_imf_context_cursor_position_set - (sd->khdl.imf, (sd->cursor.y * sd->grid.w) + sd->cursor.x); + ecore_imf_context_cursor_location_set(imf, cx, cy, cw, ch); + ecore_imf_context_cursor_position_set(imf, (sd->cursor.y * sd->grid.w) + sd->cursor.x); /* ecore_imf_context_cursor_position_set(sd->imf, 0); // how to get it? */ @@ -3522,14 +3457,6 @@ termio_focus_in(Evas_Object *termio) else edje_object_signal_emit(sd->cursor.obj, "focus,in", "terminology"); if (!sd->win) return; - elm_win_keyboard_mode_set(sd->win, ELM_WIN_KEYBOARD_TERMINAL); - if (sd->khdl.imf) - { - ecore_imf_context_input_panel_show(sd->khdl.imf); - ecore_imf_context_reset(sd->khdl.imf); - ecore_imf_context_focus_in(sd->khdl.imf); - _imf_cursor_set(sd); - } } void @@ -3542,14 +3469,6 @@ termio_focus_out(Evas_Object *termio) edje_object_signal_emit(sd->cursor.obj, "focus,out", "terminology"); if (!sd->win) return; sd->pty->selection.last_click = 0; - elm_win_keyboard_mode_set(sd->win, ELM_WIN_KEYBOARD_OFF); - if (sd->khdl.imf) - { - ecore_imf_context_reset(sd->khdl.imf); - _imf_cursor_set(sd); - ecore_imf_context_focus_out(sd->khdl.imf); - ecore_imf_context_input_panel_hide(sd->khdl.imf); - } if (!sd->ctxpopup) _remove_links(sd, termio); term_unfocus(sd->term); @@ -4807,6 +4726,7 @@ _smart_apply(Evas_Object *obj) Eina_List *l, *ln; Termblock *blk; int x, y, ch1 = 0, ch2 = 0, inv = 0, preedit_x = 0, preedit_y = 0; + char *preedit_str; ssize_t w; EINA_SAFETY_ON_NULL_RETURN(sd); @@ -4993,7 +4913,9 @@ _smart_apply(Evas_Object *obj) evas_object_textgrid_update_add(sd->grid.obj, ch1, y, ch2 - ch1 + 1, 1); } - if (sd->preedit_str && sd->preedit_str[0]) + + preedit_str = term_preedit_str_get(sd->term); + if (preedit_str && preedit_str[0]) { Eina_Unicode *uni, g; int len = 0, i, jump, xx, backx; @@ -5001,7 +4923,7 @@ _smart_apply(Evas_Object *obj) Evas_Textgrid_Cell *tc; x = sd->cursor.x, y = sd->cursor.y; - uni = eina_unicode_utf8_to_unicode(sd->preedit_str, &len); + uni = eina_unicode_utf8_to_unicode(preedit_str, &len); if (uni) { for (i = 0; i < len; i++) @@ -5251,52 +5173,8 @@ _cursor_cb_move(void *data, { Termio *sd = evas_object_smart_data_get(data); EINA_SAFETY_ON_NULL_RETURN(sd); - _imf_cursor_set(sd); -} - -static void -_imf_event_commit_cb(void *data, - Ecore_IMF_Context *_ctx EINA_UNUSED, - void *event) -{ - Termio *sd = data; - char *str = event; - DBG("IMF committed '%s'", str); - if (!str) return; - termpty_write(sd->pty, str, strlen(str)); - if (sd->preedit_str) - { - eina_stringshare_del(sd->preedit_str); - sd->preedit_str = NULL; - } - _smart_update_queue(sd->self, sd); -} - -static void -_imf_event_delete_surrounding_cb(void *data, - Ecore_IMF_Context *_ctx EINA_UNUSED, - void *event) -{ - Termio *sd = data; - Ecore_IMF_Event_Delete_Surrounding *ev = event; - DBG("IMF del surrounding %p %i %i", sd, ev->offset, ev->n_chars); -} - -static void -_imf_event_preedit_changed_cb(void *data, - Ecore_IMF_Context *ctx, - void *_event EINA_UNUSED) -{ - Termio *sd = data; - char *preedit_string; - int cursor_pos; - ecore_imf_context_preedit_string_get(ctx, &preedit_string, &cursor_pos); - if (!preedit_string) return; - DBG("IMF preedit str '%s'", preedit_string); - if (sd->preedit_str) eina_stringshare_del(sd->preedit_str); - sd->preedit_str = eina_stringshare_add(preedit_string); - _smart_update_queue(sd->self, sd); - free(preedit_string); + /* TODO: boris */ + //_imf_cursor_set(sd); } @@ -5370,58 +5248,6 @@ _smart_add(Evas_Object *obj) sd->link.suspend = 1; - if (ecore_imf_init()) - { - const char *imf_id = ecore_imf_context_default_id_get(); - Evas *e; - - if (!imf_id) sd->khdl.imf = NULL; - else - { - const Ecore_IMF_Context_Info *imf_info; - - imf_info = ecore_imf_context_info_by_id_get(imf_id); - if ((!imf_info->canvas_type) || - (strcmp(imf_info->canvas_type, "evas") == 0)) - sd->khdl.imf = ecore_imf_context_add(imf_id); - else - { - imf_id = ecore_imf_context_default_id_by_canvas_type_get("evas"); - if (imf_id) sd->khdl.imf = ecore_imf_context_add(imf_id); - } - } - - if (!sd->khdl.imf) goto imf_done; - - e = evas_object_evas_get(o); - ecore_imf_context_client_window_set - (sd->khdl.imf, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(e))); - ecore_imf_context_client_canvas_set(sd->khdl.imf, e); - - ecore_imf_context_event_callback_add - (sd->khdl.imf, ECORE_IMF_CALLBACK_COMMIT, _imf_event_commit_cb, sd); - ecore_imf_context_event_callback_add - (sd->khdl.imf, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _imf_event_delete_surrounding_cb, sd); - ecore_imf_context_event_callback_add - (sd->khdl.imf, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _imf_event_preedit_changed_cb, sd); - /* make IMF usable by a terminal - no preedit, prediction... */ - ecore_imf_context_prediction_allow_set - (sd->khdl.imf, EINA_FALSE); - ecore_imf_context_autocapital_type_set - (sd->khdl.imf, ECORE_IMF_AUTOCAPITAL_TYPE_NONE); - ecore_imf_context_input_panel_layout_set - (sd->khdl.imf, ECORE_IMF_INPUT_PANEL_LAYOUT_TERMINAL); - ecore_imf_context_input_mode_set - (sd->khdl.imf, ECORE_IMF_INPUT_MODE_FULL); - ecore_imf_context_input_panel_language_set - (sd->khdl.imf, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET); - ecore_imf_context_input_panel_return_key_type_set - (sd->khdl.imf, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT); -imf_done: - if (sd->khdl.imf) DBG("Ecore IMF Setup"); - else WRN(_("Ecore IMF failed")); - - } terms = eina_list_append(terms, obj); } @@ -5434,12 +5260,6 @@ _smart_del(Evas_Object *obj) EINA_SAFETY_ON_NULL_RETURN(sd); terms = eina_list_remove(terms, obj); - if (sd->khdl.imf) - { - ecore_imf_context_event_callback_del - (sd->khdl.imf, ECORE_IMF_CALLBACK_COMMIT, _imf_event_commit_cb); - ecore_imf_context_del(sd->khdl.imf); - } if (sd->cursor.obj) evas_object_del(sd->cursor.obj); if (sd->event) { @@ -5495,13 +5315,10 @@ _smart_del(Evas_Object *obj) } sd->sendfile.active = EINA_FALSE; } - keyin_compose_seq_reset(&sd->khdl); if (sd->sel_str) eina_stringshare_del(sd->sel_str); - if (sd->preedit_str) eina_stringshare_del(sd->preedit_str); if (sd->sel_reset_job) ecore_job_del(sd->sel_reset_job); EINA_LIST_FREE(sd->cur_chids, chid) eina_stringshare_del(chid); sd->sel_str = NULL; - sd->preedit_str = NULL; sd->sel_reset_job = NULL; sd->link.down.dndobj = NULL; sd->cursor.obj = NULL; @@ -5513,10 +5330,8 @@ _smart_del(Evas_Object *obj) sd->delayed_size_timer = NULL; sd->font.name = NULL; sd->pty = NULL; - sd->khdl.imf = NULL; sd->win = NULL; sd->glayer = NULL; - ecore_imf_shutdown(); _parent_sc.del(obj); } @@ -6274,13 +6089,20 @@ termio_add(Evas_Object *win, Config *config, } void -termio_key_down(Evas_Object *termio, void *event) +termio_key_down(Evas_Object *termio, + const Evas_Event_Key_Down *ev) { - _smart_cb_key_down(termio, NULL, NULL, event); -} + Termio *sd = evas_object_smart_data_get(termio); -void -termio_key_up(Evas_Object *termio, void *event) -{ - _smart_cb_key_up(termio, NULL, NULL, event); + EINA_SAFETY_ON_NULL_RETURN(sd); + if (sd->jump_on_keypress) + { + if (!key_is_modifier(ev->key)) + { + sd->scroll = 0; + _smart_update_queue(termio, sd); + } + } + if (sd->config->flicker_on_key) + edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology"); } diff --git a/src/bin/termio.h b/src/bin/termio.h index 7ee9c85b..5e4a4031 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -49,12 +49,14 @@ Eina_Bool termio_file_send_ok(const Evas_Object *obj, const char *file); void termio_file_send_cancel(const Evas_Object *obj); double termio_file_send_progress_get(const Evas_Object *obj); +void +termio_imf_cursor_set(Evas_Object *obj, Ecore_IMF_Context *imf); + Termpty *termio_pty_get(const Evas_Object *obj); Evas_Object * termio_miniview_get(const Evas_Object *obj); Term* termio_term_get(const Evas_Object *obj); -void termio_key_down(Evas_Object *termio, void *event); -void termio_key_up(Evas_Object *termio, void *event); +void termio_key_down(Evas_Object *termio, const Evas_Event_Key_Down *ev); void termio_focus_in(Evas_Object *termio); void termio_focus_out(Evas_Object *termio); diff --git a/src/bin/termpty.c b/src/bin/termpty.c index 4251e8aa..e8576769 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -1,10 +1,14 @@ #include "private.h" #include +#include +#include +#include #include "termpty.h" #include "termptyesc.h" #include "termptyops.h" #include "termptysave.h" #include "termio.h" +#include "keyin.h" #include #include #include @@ -54,6 +58,26 @@ termpty_shutdown(void) _termpty_log_dom = -1; } + +Eina_Bool +termpty_can_handle_key(const Termpty *ty, + const Keys_Handler *khdl, + const Evas_Event_Key_Down *ev) +{ + // if term app asked for kbd lock - dont handle here + if (ty->termstate.kbd_lock) + return EINA_FALSE; + // if app asked us to not do autorepeat - ignore press if is it is the same + // timestamp as last one + if ((ty->termstate.no_autorepeat) && + (ev->timestamp == khdl->last_keyup)) + return EINA_FALSE; + return EINA_TRUE; +} + + + + void termpty_handle_buf(Termpty *ty, const Eina_Unicode *codepoints, int len) { diff --git a/src/bin/win.c b/src/bin/win.c index 399d9d5c..41e2d219 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include "win.h" #include "termcmd.h" #include "config.h" @@ -12,6 +15,7 @@ #include "private.h" #include "sel.h" #include "controls.h" +#include "keyin.h" #include "term_container.h" @@ -154,8 +158,10 @@ struct _Split struct _Win { - Term_Container tc; + Term_Container tc; /* has to be first field */ + Keys_Handler khdl; + const char *preedit_str; Term_Container *child; Evas_Object *win; Evas_Object *conform; @@ -195,6 +201,7 @@ static Tab_Item* tab_item_new(Tabs *tabs, Term_Container *child); static void _tabs_refresh(Tabs *tabs); static void _term_tabregion_free(Term *term); static void _set_trans(Config *config, Evas_Object *bg, Evas_Object *base); +static void _imf_event_commit_cb(void *data, Ecore_IMF_Context *_ctx EINA_UNUSED, void *event); /* {{{ Solo */ @@ -749,8 +756,20 @@ win_free(Win *wn) evas_object_event_callback_del_full(wn->win, EVAS_CALLBACK_DEL, _cb_del, wn); evas_object_del(wn->win); } - if (wn->size_job) ecore_job_del(wn->size_job); - if (wn->config) config_del(wn->config); + if (wn->size_job) + ecore_job_del(wn->size_job); + if (wn->config) + config_del(wn->config); + if (wn->preedit_str) + eina_stringshare_del(wn->preedit_str); + keyin_compose_seq_reset(&wn->khdl); + if (wn->khdl.imf) + { + ecore_imf_context_event_callback_del + (wn->khdl.imf, ECORE_IMF_CALLBACK_COMMIT, _imf_event_commit_cb); + ecore_imf_context_del(wn->khdl.imf); + } + ecore_imf_shutdown(); free(wn); } @@ -958,9 +977,25 @@ _win_focus(Term_Container *tc, Term_Container *relative) DBG("tc:%p tc->is_focused:%d from_child:%d", tc, tc->is_focused, wn->child == relative); if (relative != wn->child) - wn->child->focus(wn->child, tc); + { + wn->child->focus(wn->child, tc); + elm_win_keyboard_mode_set(wn->win, ELM_WIN_KEYBOARD_TERMINAL); + if (wn->khdl.imf) + { + Term *focused; - if (!tc->is_focused) elm_win_urgent_set(wn->win, EINA_FALSE); + ecore_imf_context_input_panel_show(wn->khdl.imf); + ecore_imf_context_reset(wn->khdl.imf); + ecore_imf_context_focus_in(wn->khdl.imf); + + focused = tc->focused_term_get(tc); + if (focused) + termio_imf_cursor_set(focused->termio, wn->khdl.imf); + } + } + + if (!tc->is_focused) + elm_win_urgent_set(wn->win, EINA_FALSE); tc->is_focused = EINA_TRUE; } @@ -974,8 +1009,20 @@ _win_unfocus(Term_Container *tc, Term_Container *relative) DBG("tc:%p tc->is_focused:%d from_child:%d", tc, tc->is_focused, wn->child == relative); + elm_win_keyboard_mode_set(wn->win, ELM_WIN_KEYBOARD_OFF); if (relative != wn->child && wn->child) { + if (wn->khdl.imf) + { + Term *focused; + + ecore_imf_context_reset(wn->khdl.imf); + focused = tc->focused_term_get(tc); + if (focused) + termio_imf_cursor_set(focused->termio, wn->khdl.imf); + ecore_imf_context_focus_out(wn->khdl.imf); + ecore_imf_context_input_panel_hide(wn->khdl.imf); + } tc->is_focused = EINA_FALSE; wn->child->unfocus(wn->child, tc); @@ -1108,26 +1155,55 @@ static void _cb_win_key_up(void *data, Evas *_e EINA_UNUSED, Evas_Object *_obj EINA_UNUSED, - void *event_info) + void *event) { Win *wn = data; - Eina_List *l; - Term *term; - const Evas_Event_Key_Up *ev = event_info; - - if (wn->on_options) - return; + Evas_Event_Key_Up *ev = event; DBG("GROUP key up (%p) (ctrl:%d)", wn, evas_key_modifier_is_set(ev->modifiers, "Control")); + keyin_handle_up(&wn->khdl, ev); +} + +char * +term_preedit_str_get(Term *term) +{ + Win *wn = term->wn; + Term_Container *tc = (Term_Container*) wn; + + if (wn->on_options) + return NULL; + tc = (Term_Container*) wn; + term = tc->focused_term_get(tc); + if (term) + { + return wn->preedit_str; + } + return NULL; +} + +static void +_imf_event_commit_cb(void *data, + Ecore_IMF_Context *_ctx EINA_UNUSED, + void *event) +{ + Eina_List *l; + Term *term; + Win *wn = data; + Termpty *ty; + char *str = event; + int len; + DBG("IMF committed '%s'", str); + if (!str) + return; + len = strlen(str); if (wn->group_input) { - wn->group_once_handled = EINA_FALSE; EINA_LIST_FOREACH(wn->terms, l, term) { - termio_key_up(term->termio, event_info); - if (!wn->group_input) - return; + ty = termio_pty_get(term->termio); + if (ty) + termpty_write(ty, str, len); } } else @@ -1136,10 +1212,51 @@ _cb_win_key_up(void *data, term = tc->focused_term_get(tc); if (term) - termio_key_up(term->termio, event_info); + { + ty = termio_pty_get(term->termio); + if (ty) + termpty_write(ty, str, len); + } + } + if (wn->preedit_str) + { + eina_stringshare_del(wn->preedit_str); + wn->preedit_str = NULL; } } + + +static void +_imf_event_delete_surrounding_cb(void *data, + Ecore_IMF_Context *_ctx EINA_UNUSED, + void *event) +{ + Win *wn = data; + Ecore_IMF_Event_Delete_Surrounding *ev = event; + DBG("IMF del surrounding %p %i %i", wn, ev->offset, ev->n_chars); +} + +static void +_imf_event_preedit_changed_cb(void *data, + Ecore_IMF_Context *ctx, + void *_event EINA_UNUSED) +{ + Win *wn = data; + char *preedit_string; + int cursor_pos; + + ecore_imf_context_preedit_string_get(ctx, &preedit_string, &cursor_pos); + if (!preedit_string) + return; + DBG("IMF preedit str '%s'", preedit_string); + if (wn->preedit_str) + eina_stringshare_del(wn->preedit_str); + wn->preedit_str = eina_stringshare_add(preedit_string); + free(preedit_string); +} + + static void _cb_win_key_down(void *data, Evas *_e EINA_UNUSED, @@ -1147,9 +1264,12 @@ _cb_win_key_down(void *data, void *event_info) { Win *wn = data; - Eina_List *l; - Term *term; - const Evas_Event_Key_Down *ev = event_info; + Eina_List *l = NULL; + Term *term = NULL; + Termpty *ty = NULL; + Evas_Event_Key_Down *ev = event_info; + Eina_Bool done = EINA_FALSE; + int ctrl, alt, shift, win, meta, hyper; DBG("GROUP key down (%p) (ctrl:%d)", wn, evas_key_modifier_is_set(ev->modifiers, "Control")); @@ -1157,7 +1277,6 @@ _cb_win_key_down(void *data, if (wn->on_options) return; - int ctrl, alt, shift, win, meta, hyper; ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); alt = evas_key_modifier_is_set(ev->modifiers, "Alt"); shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); @@ -1169,13 +1288,12 @@ _cb_win_key_down(void *data, DBG("ctrl:%d alt:%d shift:%d win:%d meta:%d hyper:%d", ctrl, alt, shift, win, meta, hyper); - + /* 1st/ Miniview */ if (wn->group_input) { - wn->group_once_handled = EINA_FALSE; EINA_LIST_FOREACH(wn->terms, l, term) { - termio_key_down(term->termio, event_info); + done = miniview_handle_key(term_miniview_get(term), ev); if (!wn->group_input) return; } @@ -1185,8 +1303,191 @@ _cb_win_key_down(void *data, Term_Container *tc = (Term_Container*) wn; term = tc->focused_term_get(tc); + if (!term) + return; + done = miniview_handle_key(term_miniview_get(term), ev); + } + if (done) + { + keyin_compose_seq_reset(&wn->khdl); + goto end; + } + + + /* 2nd/ PopMedia */ + done = EINA_FALSE; + if (wn->group_input) + { + EINA_LIST_FOREACH(wn->terms, l, term) + { + if (term_has_popmedia(term) && !strcmp(ev->key, "Escape")) + { + term_popmedia_close(term); + done = EINA_TRUE; + } + } + } + else + { + Term_Container *tc = (Term_Container*) wn; + + term = tc->focused_term_get(tc); + if (!term) + return; + if (term_has_popmedia(term) && !strcmp(ev->key, "Escape")) + { + term_popmedia_close(term); + done = EINA_TRUE; + } + } + if (done) + { + keyin_compose_seq_reset(&wn->khdl); + goto end; + } + + /* 3rd/ Handle key bindings */ + done = EINA_FALSE; + if (wn->group_input) + { + wn->group_once_handled = EINA_FALSE; + EINA_LIST_FOREACH(wn->terms, l, term) + { + done = keyin_handle_key_binding(term->termio, ev, ctrl, alt, + shift, win, meta, hyper); + if (!wn->group_input) + return; + } + } + else + { + Term_Container *tc = (Term_Container*) wn; + + term = tc->focused_term_get(tc); + if (!term) + return; + done = keyin_handle_key_binding(term->termio, ev, ctrl, alt, + shift, win, meta, hyper); + } + if (done) + { + keyin_compose_seq_reset(&wn->khdl); + goto end; + } + done = EINA_FALSE; + + /* 4th/ Composing */ + /* composing */ + if (&wn->khdl.imf) + { + // EXCEPTION. Don't filter modifiers alt+shift -> breaks emacs + // and jed (alt+shift+5 for search/replace for example) + // Don't filter modifiers alt, is used by shells + if ((!alt) && (!ctrl)) + { + Ecore_IMF_Event_Key_Down imf_ev; + + ecore_imf_evas_event_key_down_wrap(ev, &imf_ev); + if (!wn->khdl.composing) + { + if (ecore_imf_context_filter_event(wn->khdl.imf, + ECORE_IMF_EVENT_KEY_DOWN, + (Ecore_IMF_Event *)&imf_ev)) + goto end; + } + } + } + if (!wn->khdl.composing) + { + Ecore_Compose_State state; + char *compres = NULL; + + keyin_compose_seq_reset(&wn->khdl); + wn->khdl.seq = eina_list_append(wn->khdl.seq, + eina_stringshare_add(ev->key)); + state = ecore_compose_get(wn->khdl.seq, &compres); + if (state == ECORE_COMPOSE_MIDDLE) + wn->khdl.composing = EINA_TRUE; + else + wn->khdl.composing = EINA_FALSE; + if (!wn->khdl.composing) + keyin_compose_seq_reset(&wn->khdl); + else + goto end; + } + else + { + Ecore_Compose_State state; + char *compres = NULL; + + if (key_is_modifier(ev->key)) + goto end; + wn->khdl.seq = eina_list_append(wn->khdl.seq, + eina_stringshare_add(ev->key)); + state = ecore_compose_get(wn->khdl.seq, &compres); + if (state == ECORE_COMPOSE_NONE) + keyin_compose_seq_reset(&wn->khdl); + else if (state == ECORE_COMPOSE_DONE) + { + keyin_compose_seq_reset(&wn->khdl); + if (compres) + { + int len = strlen(compres); + if (wn->group_input) + { + EINA_LIST_FOREACH(wn->terms, l, term) + { + ty = termio_pty_get(term->termio); + if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) + termpty_write(ty, compres, len); + } + } + else + { + ty = termio_pty_get(term->termio); + if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) + termpty_write(ty, compres, len); + } + free(compres); + compres = NULL; + } + goto end; + } + else + goto end; + } + + /* 5th/ send key to pty */ + if (wn->group_input) + { + EINA_LIST_FOREACH(wn->terms, l, term) + { + ty = termio_pty_get(term->termio); + if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) + keyin_handle_key_to_pty(ty, ev, alt, shift, ctrl); + } + } + else + { + ty = termio_pty_get(term->termio); + if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) + keyin_handle_key_to_pty(ty, ev, alt, shift, ctrl); + } + + /* 6th: specifics: jump on keypress / flicker on key */ +end: + if (wn->group_input) + { + EINA_LIST_FOREACH(wn->terms, l, term) + { + if (term) + termio_key_down(term->termio, ev); + } + } + else + { if (term) - termio_key_down(term->termio, event_info); + termio_key_down(term->termio, ev); } } @@ -1369,6 +1670,64 @@ win_new(const char *name, const char *role, const char *title, _cb_win_mouse_move, wn); + if (ecore_imf_init()) + { + const char *imf_id = ecore_imf_context_default_id_get(); + Evas *e; + + if (!imf_id) + wn->khdl.imf = NULL; + else + { + const Ecore_IMF_Context_Info *imf_info; + + imf_info = ecore_imf_context_info_by_id_get(imf_id); + if ((!imf_info->canvas_type) || + (strcmp(imf_info->canvas_type, "evas") == 0)) + wn->khdl.imf = ecore_imf_context_add(imf_id); + else + { + imf_id = ecore_imf_context_default_id_by_canvas_type_get("evas"); + if (imf_id) + wn->khdl.imf = ecore_imf_context_add(imf_id); + } + } + + if (!wn->khdl.imf) + goto imf_done; + + e = evas_object_evas_get(o); + ecore_imf_context_client_window_set + (wn->khdl.imf, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(e))); + ecore_imf_context_client_canvas_set(wn->khdl.imf, e); + + ecore_imf_context_event_callback_add + (wn->khdl.imf, ECORE_IMF_CALLBACK_COMMIT, _imf_event_commit_cb, wn); + ecore_imf_context_event_callback_add + (wn->khdl.imf, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _imf_event_delete_surrounding_cb, wn); + ecore_imf_context_event_callback_add + (wn->khdl.imf, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _imf_event_preedit_changed_cb, wn); + /* make IMF usable by a terminal - no preedit, prediction... */ + ecore_imf_context_prediction_allow_set + (wn->khdl.imf, EINA_FALSE); + ecore_imf_context_autocapital_type_set + (wn->khdl.imf, ECORE_IMF_AUTOCAPITAL_TYPE_NONE); + ecore_imf_context_input_panel_layout_set + (wn->khdl.imf, ECORE_IMF_INPUT_PANEL_LAYOUT_TERMINAL); + ecore_imf_context_input_mode_set + (wn->khdl.imf, ECORE_IMF_INPUT_MODE_FULL); + ecore_imf_context_input_panel_language_set + (wn->khdl.imf, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET); + ecore_imf_context_input_panel_return_key_type_set + (wn->khdl.imf, ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT); +imf_done: + if (wn->khdl.imf) + DBG("Ecore IMF Setup"); + else + WRN(_("Ecore IMF failed")); + + } + wins = eina_list_append(wins, wn); return wn; } diff --git a/src/bin/win.h b/src/bin/win.h index 113ed71c..4c7aa7d4 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -66,6 +66,9 @@ void term_down(Term *term); void term_left(Term *term); void term_right(Term *term); +char * +term_preedit_str_get(Term *term); + void win_font_size_set(Win *wn, int new_size); void win_font_update(Term *term); From 34f19bf4dd8ee043f3833599809bab80ce38d26e Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 8 Feb 2018 18:40:06 +0100 Subject: [PATCH 28/36] win: constify term_preedit_str_get() --- src/bin/win.c | 2 +- src/bin/win.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 41e2d219..ac37cb79 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1165,7 +1165,7 @@ _cb_win_key_up(void *data, keyin_handle_up(&wn->khdl, ev); } -char * +const char * term_preedit_str_get(Term *term) { Win *wn = term->wn; diff --git a/src/bin/win.h b/src/bin/win.h index 4c7aa7d4..b1ac57fc 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -66,7 +66,7 @@ void term_down(Term *term); void term_left(Term *term); void term_right(Term *term); -char * +const char * term_preedit_str_get(Term *term); void win_font_size_set(Win *wn, int new_size); From 7cb67a2bced4673d3ef1b1dfe2e6a62ab455fbb3 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 8 Feb 2018 18:40:27 +0100 Subject: [PATCH 29/36] win: get out of grouped-input --- src/bin/win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/win.c b/src/bin/win.c index ac37cb79..81675edb 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1797,7 +1797,7 @@ _win_toggle_group(Win *wn) } else { - wn->group_input = EINA_TRUE; + wn->group_input = EINA_FALSE; DBG("GROUP INPUT is now FALSE"); EINA_LIST_FOREACH(wn->terms, l, term) { From ddb8e8160d0d94dace89bdab7bf6696187835d08 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 8 Feb 2018 22:38:02 +0100 Subject: [PATCH 30/36] termio: really constify preedit_str --- src/bin/termio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index f7f178e1..21b24926 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -4726,7 +4726,7 @@ _smart_apply(Evas_Object *obj) Eina_List *l, *ln; Termblock *blk; int x, y, ch1 = 0, ch2 = 0, inv = 0, preedit_x = 0, preedit_y = 0; - char *preedit_str; + const char *preedit_str; ssize_t w; EINA_SAFETY_ON_NULL_RETURN(sd); From 55b4eeb3a24c238e314ee4eeb9cd60d8f81fa179 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Thu, 8 Feb 2018 22:38:55 +0100 Subject: [PATCH 31/36] win: focus the termio objects, at least to have mouse work --- src/bin/win.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/win.c b/src/bin/win.c index 81675edb..c492f666 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -465,6 +465,9 @@ _solo_focus(Term_Container *tc, Term_Container *relative) if (term->wn->cmdbox) elm_object_focus_set(term->wn->cmdbox, EINA_FALSE); + elm_object_focus_set(term->termio, EINA_TRUE); + termio_event_feed_mouse_in(term->termio); + title = termio_title_get(term->termio); if (title) tc->set_title(tc, tc, title); @@ -1791,6 +1794,7 @@ _win_toggle_group(Win *wn) EINA_LIST_FOREACH(wn->terms, l, term) { edje_object_signal_emit(term->bg, "focus,in", "terminology"); + termio_event_feed_mouse_in(term->termio); } wn->group_input = EINA_TRUE; DBG("GROUP INPUT is now TRUE"); From c31c1cbd9b605588824863e5030ae72d7da03c9f Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 9 Feb 2018 22:02:19 +0100 Subject: [PATCH 32/36] termio: focus_in to show blinking cursor --- src/bin/win.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/win.c b/src/bin/win.c index c492f666..a11ce5ae 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -467,6 +467,7 @@ _solo_focus(Term_Container *tc, Term_Container *relative) elm_object_focus_set(term->termio, EINA_TRUE); termio_event_feed_mouse_in(term->termio); + termio_focus_in(term->termio); title = termio_title_get(term->termio); if (title) @@ -1510,7 +1511,6 @@ _cb_win_mouse_down(void *data, return; /* TODO: boris: maybe not so strict */ - DBG("mouse down"); if (wn->group_input) return; @@ -1795,6 +1795,7 @@ _win_toggle_group(Win *wn) { edje_object_signal_emit(term->bg, "focus,in", "terminology"); termio_event_feed_mouse_in(term->termio); + termio_focus_in(term->termio); } wn->group_input = EINA_TRUE; DBG("GROUP INPUT is now TRUE"); @@ -1806,6 +1807,7 @@ _win_toggle_group(Win *wn) EINA_LIST_FOREACH(wn->terms, l, term) { edje_object_signal_emit(term->bg, "focus,out", "terminology"); + termio_focus_out(term->termio); } term = wn->child->term_first(wn->child); wn->child->focus(wn->child, &wn->tc); From 4f261e922eb9c9f1e4dbd48fdb5fbad2a836e23d Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 9 Feb 2018 23:18:03 +0100 Subject: [PATCH 33/36] imf: handle cursor move --- src/bin/termio.c | 10 +++++----- src/bin/win.c | 14 ++++++++++++++ src/bin/win.h | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index 21b24926..ec6b5975 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -3441,9 +3441,6 @@ termio_imf_cursor_set(Evas_Object *obj, Ecore_IMF_Context *imf) evas_object_geometry_get(sd->cursor.obj, &cx, &cy, &cw, &ch); ecore_imf_context_cursor_location_set(imf, cx, cy, cw, ch); ecore_imf_context_cursor_position_set(imf, (sd->cursor.y * sd->grid.w) + sd->cursor.x); - /* - ecore_imf_context_cursor_position_set(sd->imf, 0); // how to get it? - */ } void @@ -5172,9 +5169,12 @@ _cursor_cb_move(void *data, void *_event EINA_UNUSED) { Termio *sd = evas_object_smart_data_get(data); + Ecore_IMF_Context *imf; EINA_SAFETY_ON_NULL_RETURN(sd); - /* TODO: boris */ - //_imf_cursor_set(sd); + + imf = term_imf_context_get(sd->term); + if (imf) + termio_imf_cursor_set(sd->self, imf); } diff --git a/src/bin/win.c b/src/bin/win.c index a11ce5ae..0dc8a111 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1186,6 +1186,20 @@ term_preedit_str_get(Term *term) return NULL; } +Ecore_IMF_Context * +term_imf_context_get(Term *term) +{ + Win *wn = term->wn; + Term_Container *tc = (Term_Container*) wn; + Term *focused; + + tc = (Term_Container*) wn; + focused = tc->focused_term_get(tc); + if (term == focused) + return wn->khdl.imf; + return NULL; +} + static void _imf_event_commit_cb(void *data, Ecore_IMF_Context *_ctx EINA_UNUSED, diff --git a/src/bin/win.h b/src/bin/win.h index b1ac57fc..58a72d61 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -68,6 +68,8 @@ void term_right(Term *term); const char * term_preedit_str_get(Term *term); +Ecore_IMF_Context * +term_imf_context_get(Term *term); void win_font_size_set(Win *wn, int new_size); void win_font_update(Term *term); From 26b19dc31d32db0fffbb302c3610e652a6d8710e Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sat, 10 Feb 2018 17:28:58 +0100 Subject: [PATCH 34/36] win: remove useless comments --- src/bin/win.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/bin/win.c b/src/bin/win.c index 0dc8a111..6a166109 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -1521,11 +1521,7 @@ _cb_win_mouse_down(void *data, Term_Container *tc = (Term_Container*) wn; Term_Container *tc_child; - if (wn->on_options) - return; - - /* TODO: boris: maybe not so strict */ - if (wn->group_input) + if (wn->on_options || wn->group_input) return; term_mouse = tc->find_term_at_coords(tc, ev->canvas.x, ev->canvas.y); @@ -1555,11 +1551,7 @@ _cb_win_mouse_move(void *data, Term_Container *tc = (Term_Container*) wn; Term_Container *tc_child = NULL; - if (wn->on_options) - return; - - /* TODO: boris: maybe not so strict */ - if (wn->group_input) + if (wn->on_options || wn->group_input) return; if (!wn->config->mouse_over_focus) From 19cca3e2f23e1accd5a6e9da8c79e5469efdf2a4 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 11 Feb 2018 11:48:06 +0100 Subject: [PATCH 35/36] group input: handle only_visible or all terms --- src/bin/term_container.h | 1 + src/bin/win.c | 75 +++++++++++++++++++++++++++++++++++----- src/bin/win.h | 2 ++ 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/bin/term_container.h b/src/bin/term_container.h index 1f392e8c..0e066e69 100644 --- a/src/bin/term_container.h +++ b/src/bin/term_container.h @@ -60,6 +60,7 @@ struct _Term_Container { void (*bell)(Term_Container *tc, Term_Container *child); void (*close)(Term_Container *container, Term_Container *child); void (*update)(Term_Container *tc); + Eina_Bool (*is_visible)(Term_Container *tc, Term_Container *child); }; #endif diff --git a/src/bin/win.c b/src/bin/win.c index 6a166109..a35a81db 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -483,6 +483,13 @@ _solo_update(Term_Container *tc) assert (tc->type == TERM_CONTAINER_TYPE_SOLO); } +static Eina_Bool +_solo_is_visible(Term_Container *tc, Term_Container *_child EINA_UNUSED) +{ + assert (tc->type == TERM_CONTAINER_TYPE_SOLO); + return tc->parent->is_visible(tc->parent, tc); +} + static Term_Container * _solo_new(Term *term, Win *wn) { @@ -517,6 +524,7 @@ _solo_new(Term *term, Win *wn) tc->close = _solo_close; tc->update = _solo_update; tc->title = eina_stringshare_add("Terminology"); + tc->is_visible = _solo_is_visible; tc->type = TERM_CONTAINER_TYPE_SOLO; tc->parent = NULL; @@ -1169,6 +1177,11 @@ _cb_win_key_up(void *data, keyin_handle_up(&wn->khdl, ev); } +#define GROUPED_INPUT_TERM_FOREACH(_wn, _list, _term) \ + EINA_LIST_FOREACH(_wn->terms, _list, _term) \ + if (!_wn->group_only_visible || term_is_visible(_term)) + + const char * term_preedit_str_get(Term *term) { @@ -1217,7 +1230,7 @@ _imf_event_commit_cb(void *data, len = strlen(str); if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { ty = termio_pty_get(term->termio); if (ty) @@ -1309,7 +1322,7 @@ _cb_win_key_down(void *data, /* 1st/ Miniview */ if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { done = miniview_handle_key(term_miniview_get(term), ev); if (!wn->group_input) @@ -1336,7 +1349,7 @@ _cb_win_key_down(void *data, done = EINA_FALSE; if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { if (term_has_popmedia(term) && !strcmp(ev->key, "Escape")) { @@ -1369,7 +1382,7 @@ _cb_win_key_down(void *data, if (wn->group_input) { wn->group_once_handled = EINA_FALSE; - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { done = keyin_handle_key_binding(term->termio, ev, ctrl, alt, shift, win, meta, hyper); @@ -1453,7 +1466,7 @@ _cb_win_key_down(void *data, int len = strlen(compres); if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { ty = termio_pty_get(term->termio); if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) @@ -1478,7 +1491,7 @@ _cb_win_key_down(void *data, /* 5th/ send key to pty */ if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { ty = termio_pty_get(term->termio); if (ty && termpty_can_handle_key(ty, &wn->khdl, ev)) @@ -1496,7 +1509,7 @@ _cb_win_key_down(void *data, end: if (wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { if (term) termio_key_down(term->termio, ev); @@ -1575,6 +1588,12 @@ _cb_win_mouse_move(void *data, tc_child->focus(tc_child, tc); } +static Eina_Bool +_win_is_visible(Term_Container *tc, Term_Container *_child EINA_UNUSED) +{ + assert (tc->type == TERM_CONTAINER_TYPE_WIN); + return EINA_TRUE; +} Win * win_new(const char *name, const char *role, const char *title, @@ -1618,6 +1637,7 @@ win_new(const char *name, const char *role, const char *title, tc->bell = _win_bell; tc->close = _win_close; tc->update = _win_update; + tc->is_visible = _win_is_visible; tc->title = eina_stringshare_add(title? title : "Terminology"); tc->type = TERM_CONTAINER_TYPE_WIN; tc->wn = wn; @@ -1797,7 +1817,7 @@ _win_toggle_group(Win *wn) DBG("WIN TOGGLE"); if (!wn->group_input) { - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { edje_object_signal_emit(term->bg, "focus,in", "terminology"); termio_event_feed_mouse_in(term->termio); @@ -1810,7 +1830,7 @@ _win_toggle_group(Win *wn) { wn->group_input = EINA_FALSE; DBG("GROUP INPUT is now FALSE"); - EINA_LIST_FOREACH(wn->terms, l, term) + GROUPED_INPUT_TERM_FOREACH(wn, l, term) { edje_object_signal_emit(term->bg, "focus,out", "terminology"); termio_focus_out(term->termio); @@ -2280,6 +2300,15 @@ _split_split(Term_Container *tc, Term_Container *child, evas_object_show(obj_split); } +static Eina_Bool +_split_is_visible(Term_Container *tc, Term_Container *_child EINA_UNUSED) +{ + assert (tc->type == TERM_CONTAINER_TYPE_SPLIT); + /* Could return True with the current design because splits are at a higher + * level than tabs */ + return tc->parent->is_visible(tc->parent, tc); +} + static Term_Container * _split_new(Term_Container *tc1, Term_Container *tc2, Eina_Bool is_horizontal) @@ -2315,6 +2344,7 @@ _split_new(Term_Container *tc1, Term_Container *tc2, tc->bell = _split_bell; tc->close = _split_close; tc->update = _split_update; + tc->is_visible = _split_is_visible; tc->title = eina_stringshare_add("Terminology"); tc->type = TERM_CONTAINER_TYPE_SPLIT; @@ -3575,6 +3605,16 @@ _tabs_split(Term_Container *tc, tc->parent->split(tc->parent, tc, from, cmd, is_horizontal); } +static Eina_Bool +_tabs_is_visible(Term_Container *tc, Term_Container *child) +{ + Tabs *tabs; + assert (tc->type == TERM_CONTAINER_TYPE_TABS); + tabs = (Tabs*) tc; + return child == tabs->current->tc; +} + + static Term_Container * _tabs_new(Term_Container *child, Term_Container *parent) { @@ -3613,6 +3653,7 @@ _tabs_new(Term_Container *child, Term_Container *parent) tc->bell = _tabs_bell; tc->close = _tabs_close; tc->update = _tabs_update; + tc->is_visible = _tabs_is_visible; tc->title = eina_stringshare_add("Terminology"); tc->type = TERM_CONTAINER_TYPE_TABS; @@ -3635,6 +3676,22 @@ _tabs_new(Term_Container *child, Term_Container *parent) /* }}} */ /* {{{ Term */ +Eina_Bool +term_is_visible(Term *term) +{ + /* TODO: boris */ + Term_Container *tc; + + if (!term) + return EINA_FALSE; + + tc = term->container; + if (!tc) + return EINA_FALSE; + + return tc->is_visible(tc, tc); +} + void background_set_shine(Config *config, Evas_Object *bg) { diff --git a/src/bin/win.h b/src/bin/win.h index 58a72d61..f6fa332e 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -71,6 +71,8 @@ term_preedit_str_get(Term *term); Ecore_IMF_Context * term_imf_context_get(Term *term); +Eina_Bool term_is_visible(Term *term); + void win_font_size_set(Win *wn, int new_size); void win_font_update(Term *term); From 85a8638859375ee7d3c22d8322f30926b9239d8e Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 11 Feb 2018 11:53:46 +0100 Subject: [PATCH 36/36] Add doc on group input Closes T6176 --- README | 2 ++ man/terminology.1 | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README b/README index f6bb079b..02b20c9a 100644 --- a/README +++ b/README @@ -63,6 +63,8 @@ Ctrl+Shift+c = copy current selection to clipboard Ctrl+Shift+v = paste current clipboard selection Alt+Home = Enter command mode (enter commands to control terminology itself) Alt+Return = Paste primary selection +Alt+g = Group input: send input to all visible terminals in the window +Alt+Shift+g = Group input: send input to all terminals in the window Alt+w = Copy selection to primary Alt+Up = Focus the terminal above Alt+Down = Focus the terminal below diff --git a/man/terminology.1 b/man/terminology.1 index 3c714b99..57ee764d 100644 --- a/man/terminology.1 +++ b/man/terminology.1 @@ -1,5 +1,5 @@ .\" Manpage for Terminology -.TH man 1 "02 Sep 2017" "1.1.1" "Terminology man page" +.TH man 1 "11 Feb 2018" "1.2.0" "Terminology man page" .SH NAME Terminology \- Terminal Emulator written with EFL (Enlightenment Foundation Libraries). .SH SYNOPSIS @@ -288,6 +288,14 @@ Enter command mode (enter commands to control terminology itself). Paste primary selection. . .TP +.B Alt+g +Group input: send input to all visible terminals in the window +. +.TP +.B Alt+Shift+g +Group input: send input to all terminals in the window +. +.TP .B Alt+w Copy selection to primary. .