diff --git a/src/bin/controls.c b/src/bin/controls.c index d75041ac..29af2552 100644 --- a/src/bin/controls.c +++ b/src/bin/controls.c @@ -91,6 +91,12 @@ _cb_ct_miniview(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *even term_miniview_toggle(termio_term_get(ct_term)); } +static void +_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)); +} + static void _cb_ct_close(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED) { @@ -277,6 +283,12 @@ controls_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, o = _button_add(win, _("Miniview"), "mini-view", _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", "mini-view", _cb_ct_set_title, NULL); + elm_box_pack_end(ct_box, o); + o = _sep_add_v(win); elm_box_pack_end(ct_boxh, o); diff --git a/src/bin/termio.c b/src/bin/termio.c index 20d5759d..2d3a9417 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -348,9 +348,25 @@ termio_title_get(Evas_Object *obj) { Termio *sd = evas_object_smart_data_get(obj); EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL); + if (sd->pty->prop.user_title) + return sd->pty->prop.user_title; return sd->pty->prop.title; } +void +termio_user_title_set(Evas_Object *obj, const char *title) +{ + Termio *sd = evas_object_smart_data_get(obj); + EINA_SAFETY_ON_NULL_RETURN(sd); + + if (sd->pty->prop.user_title) + eina_stringshare_del(sd->pty->prop.user_title); + + sd->pty->prop.user_title = eina_stringshare_add(title); + if (sd->pty->cb.set_title.func) + sd->pty->cb.set_title.func(sd->pty->cb.set_title.data); +} + const char * termio_icon_name_get(Evas_Object *obj) { diff --git a/src/bin/termio.h b/src/bin/termio.h index e4d8df64..3b660e99 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -35,6 +35,7 @@ Eina_Bool termio_cwd_get(const Evas_Object *obj, char *buf, size_t size); Evas_Object *termio_textgrid_get(Evas_Object *obj); Evas_Object *termio_win_get(Evas_Object *obj); const char *termio_title_get(Evas_Object *obj); +void termio_user_title_set(Evas_Object *obj, const char *title); const char *termio_icon_name_get(Evas_Object *obj); void termio_media_mute_set(Evas_Object *obj, Eina_Bool mute); void termio_media_visualize_set(Evas_Object *obj, Eina_Bool visualize); diff --git a/src/bin/termpty.c b/src/bin/termpty.c index 612c0e99..d9373ae7 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -603,6 +603,7 @@ termpty_free(Termpty *ty) if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); if (ty->prop.title) eina_stringshare_del(ty->prop.title); + if (ty->prop.user_title) eina_stringshare_del(ty->prop.user_title); if (ty->prop.icon) eina_stringshare_del(ty->prop.icon); if (ty->back) { diff --git a/src/bin/termpty.h b/src/bin/termpty.h index e8412457..ac1f5532 100644 --- a/src/bin/termpty.h +++ b/src/bin/termpty.h @@ -85,7 +85,7 @@ struct _Termpty } change, set_title, set_icon, cancel_sel, exited, bell, command; } cb; struct { - const char *title, *icon; + const char *title, *icon, *user_title; } prop; const char *cur_cmd; Termcell *screen, *screen2; diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index 3b0552fd..0daeda4e 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -1326,7 +1326,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce) ty->prop.title = NULL; ty->prop.icon = NULL; } - if (ty->cb.set_title.func) ty->cb.set_title.func(ty->cb.set_title.data); + if (ty->cb.set_title.func && !ty->prop.user_title) + ty->cb.set_title.func(ty->cb.set_title.data); if (ty->cb.set_icon.func) ty->cb.set_icon.func(ty->cb.set_icon.data); } break; diff --git a/src/bin/win.c b/src/bin/win.c index 143984ec..91ba3106 100644 --- a/src/bin/win.c +++ b/src/bin/win.c @@ -3208,6 +3208,60 @@ term_miniview_toggle(Term *term) } } +static void +_set_title_ok_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *popup = data; + Term *term = evas_object_data_get(popup, "term"); + Evas_Object *entry = elm_object_content_get(popup); + const char *title = elm_entry_entry_get(entry); + + if (!strlen(title)) + title = NULL; + + termio_user_title_set(term->termio, title); + evas_object_del(popup); +} + +static void +_set_title_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + evas_object_del(data); +} + +void +term_set_title(Term *term) +{ + Evas_Object *o; + Evas_Object *popup; + + EINA_SAFETY_ON_NULL_RETURN(term); + + popup = elm_popup_add(term->wn->win); + evas_object_data_set(popup, "term", term); + elm_object_part_text_set(popup, "title,text", "Set title:"); + + o = elm_button_add(popup); + evas_object_smart_callback_add(o, "clicked", _set_title_ok_cb, popup); + elm_object_text_set(o, "OK"); + elm_object_part_content_set(popup, "button1", o); + + o = elm_button_add(popup); + evas_object_smart_callback_add(o, "clicked", _set_title_cancel_cb, popup); + elm_object_text_set(o, "Cancel"); + elm_object_part_content_set(popup, "button2", o); + + o = elm_entry_add(popup); + elm_entry_single_line_set(o, EINA_TRUE); + evas_object_smart_callback_add(o, "activated", _set_title_ok_cb, popup); + evas_object_smart_callback_add(o, "aborted", _set_title_cancel_cb, popup); + elm_object_content_set(popup, o); + evas_object_show(o); + elm_object_focus_set(o, EINA_TRUE); + + evas_object_show(popup); +} + static void _popmedia_queue_process(Term *term) { diff --git a/src/bin/win.h b/src/bin/win.h index 62c3c4b4..9c5a91e5 100644 --- a/src/bin/win.h +++ b/src/bin/win.h @@ -14,6 +14,7 @@ void term_unfocus(Term *term); Evas_Object *term_termio_get(Term *term); Evas_Object *term_miniview_get(Term *term); void term_miniview_toggle(Term *term); +void term_set_title(Term *term); void term_miniview_hide(Term *term); Eina_Bool term_tab_go(Term *term, int tnum);