Terminal emulator with all the bells and whistles https://www.enlightenment.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

7581 lines
197 KiB

#include "private.h"
#include <assert.h>
#include <Elementary.h>
#include <Elementary_Cursor.h>
#include <Ecore_Input.h>
#include <Ecore_IMF.h>
#include <Ecore_IMF_Evas.h>
#include "win.h"
#include "termcmd.h"
#include "config.h"
#include "main.h"
#include "miniview.h"
#include "gravatar.h"
#include "media.h"
#include "termio.h"
#include "theme.h"
#include "sel.h"
#include "controls.h"
#include "keyin.h"
#include "term_container.h"
/**
* Design:
* A terminal widget is Term. It hosts various Evas_Object, like a `termio`
* handling the textgrid.
* It is hosted in a Term_Container of type Solo.
* On Term_Container:
* It is a generic structure with a set of function pointers. It is a simple
* way to objectify and have genericity between a Window, a Split or Tabs.
* Solo, Win, Split, Tabs have a Term_Container as their first field and thus
* can be casted to Term_Container to have access to those APIs.
*
* Solo is the simplest container, hosting just a Term.
* Win is a window and has only one container child.
* Split is a widget to separate an area of the screen in 2 and thus has 2
* children that can be either Solo or Tabs.
* Tabs is a Term_Container containing many containers (at the moment, only
* Solo ones) and have a system of tabs.
*
* All the windows are in the `wins` list.
*/
/* specific log domain to help debug code in that file */
int _win_log_dom = -1;
#undef CRITICAL
#undef ERR
#undef WRN
#undef INF
#undef DBG
#define CRITICAL(...) EINA_LOG_DOM_CRIT(_win_log_dom, __VA_ARGS__)
#define ERR(...) EINA_LOG_DOM_ERR(_win_log_dom, __VA_ARGS__)
#define WRN(...) EINA_LOG_DOM_WARN(_win_log_dom, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_win_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG(_win_log_dom, __VA_ARGS__)
#define PANES_TOP "top"
#define PANES_BOTTOM "bottom"
#define DRAG_TIMEOUT 0.4
/* {{{ Structs */
typedef struct tag_Split Split;
typedef struct tag_Tabbar Tabbar;
typedef struct tag_Solo Solo;
typedef struct tag_Tabs Tabs;
typedef struct tag_Tab_Item Tab_Item;
typedef struct tag_Tab_Drag Tab_Drag;
struct tag_Tab_Drag
{
Evas_Coord mdx; /* Mouse-down x */
Evas_Coord mdy; /* Mouse-down y */
Split_Direction split_direction;
Term *term_over;
Term *term;
Evas_Object *icon;
Evas_Object *img;
Evas *e;
Ecore_Timer *timer;
/* To be able to restore */
Term_Container_Type parent_type;
union {
struct {
int previous_position;
Term_Container *tabs_child;
};
struct {
Term_Container *other;
double left_size;
Eina_Bool is_horizontal;
Eina_Bool is_first_child;
}; };
};
struct tag_Tabbar
{
struct {
Evas_Object *box;
} l, r;
};
struct tag_Term
{
Win *wn;
Config *config;
Term_Container *container;
Evas_Object *bg;
Evas_Object *bg_edj;
Evas_Object *core;
Evas_Object *termio;
Evas_Object *media;
Evas_Object *popmedia;
Evas_Object *miniview;
Evas_Object *sel;
Evas_Object *sendfile_request;
Evas_Object *sendfile_progress;
Evas_Object *sendfile_progress_bar;
Evas_Object *tab_spacer;
Evas_Object *tab_region_base;
Evas_Object *tab_region_bg;
Evas_Object *tab_inactive;
Tab_Item *tab_item;
Eina_List *popmedia_queue;
Ecore_Timer *sendfile_request_hide_timer;
Ecore_Timer *sendfile_progress_hide_timer;
const char *sendfile_dir;
Media_Type poptype, mediatype;
Tabbar tabbar;
int step_x, step_y, min_w, min_h, req_w, req_h;
struct {
int x, y;
} down;
int refcnt;
unsigned char hold : 1;
unsigned char unswallowed : 1;
unsigned char missed_bell : 1;
unsigned char miniview_shown : 1;
unsigned char popmedia_deleted : 1;
unsigned char has_bg_cursor : 1;
unsigned char core_cursor_set: 1;
Eina_Bool sendfile_request_enabled : 1;
Eina_Bool sendfile_progress_enabled : 1;
};
struct tag_Solo {
Term_Container tc;
Term *term;
};
struct tag_Tab_Item {
Term_Container *tc;
Evas_Object *obj;
void *selector_entry;
};
struct tag_Tabs {
Term_Container tc;
Evas_Object *selector;
Evas_Object *selector_bg;
Eina_List *tabs; // Tab_Item
Tab_Item *current;
double v1_orig;
double v2_orig;
};
struct tag_Split
{
Term_Container tc;
Term_Container *tc1, *tc2; // left/right or top/bottom child splits, null if leaf
Evas_Object *panes;
Term_Container *last_focus;
unsigned char is_horizontal : 1;
};
struct tag_Win
{
Term_Container tc; /* has to be first field */
Keys_Handler khdl;
const char *preedit_str;
Term_Container *child;
Evas_Object *win;
Evas_Object *conform;
Evas_Object *backbg;
Evas_Object *base;
Config *config;
Eina_List *terms;
Split *split;
Ecore_Job *size_job;
Evas_Object *cmdbox;
Ecore_Timer *cmdbox_del_timer;
Ecore_Timer *hide_cursor_timer;
Ecore_Event_Handler *config_elm_handler;
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;
unsigned char translucent : 1;
unsigned int on_popover;
};
/* }}} */
/* {{{ static */
static Eina_List *wins = NULL;
static Tab_Drag *_tab_drag = NULL;
static Eina_Bool _win_is_focused(Win *wn);
static Term_Container *_solo_new(Term *term, Win *wn);
static Term_Container *_split_new(Term_Container *tc1, Term_Container *tc2,
double left_size, Eina_Bool is_horizontal);
static Term_Container *_tabs_new(Term_Container *child, Term_Container *parent);
static void _term_free(Term *term);
static void _term_media_update(Term *term, const Config *config);
static void _term_miniview_check(Term *term);
static void _popmedia_queue_process(Term *term);
static void _cb_size_hint(void *data, Evas *_e EINA_UNUSED, Evas_Object *obj, void *_event EINA_UNUSED);
static void _tab_new_cb(void *data, Evas_Object *_obj EINA_UNUSED, void *_event_info EINA_UNUSED);
static Tab_Item* tab_item_new(Tabs *tabs, Term_Container *child);
static void _tabs_recreate(Tabs *tabs);
static void _tab_drag_free(void);
static void _term_tabregion_free(Term *term);
static void _imf_event_commit_cb(void *data, Ecore_IMF_Context *_ctx EINA_UNUSED, void *event);
/* }}} */
/* {{{ Utils */
#ifndef NDEBUG
static void
_focus_validator(void)
{
Win *wn;
Term *term;
Eina_List *l, *ll;
EINA_LIST_FOREACH(wins, l, wn)
{
Term_Container *focused_found = NULL;
if (wn->group_input)
continue;
EINA_LIST_FOREACH(wn->terms, ll, term)
{
Term_Container *tc = term->container;
if (focused_found)
{
assert(!tc->is_focused);
}
else
{
if (tc->is_focused)
{
Term *term_focused;
Term_Container *tc_parent = tc;
focused_found = tc;
do
{
assert (tc_parent->is_focused);
tc_parent = tc_parent->parent;
if (tc_parent->type == TERM_CONTAINER_TYPE_TABS)
{
Tabs *tabs = (Tabs*) tc_parent;
if (tabs->selector_bg)
return;
}
}
while (tc_parent->type != TERM_CONTAINER_TYPE_WIN);
assert (tc_parent->is_focused);
term_focused = tc_parent->focused_term_get(tc_parent);
assert(term_focused == term);
}
}
}
}
}
#else
static void
_focus_validator(void)
{}
#endif
#define GROUPED_INPUT_TERM_FOREACH(_wn, _list, _term) \
EINA_LIST_FOREACH(_wn->terms, _list, _term) \
if (!_wn->group_only_visible || term_is_visible(_term))
/* }}} */
/* {{{ Scale */
static void
_scale_round(void *data EINA_UNUSED,
Evas_Object *obj,
void *event_info EINA_UNUSED)
{
double val = elm_slider_value_get(obj);
double v;
v = ((double)((int)(val * 10.0))) / 10.0;
if (v != val) elm_slider_value_set(obj, v);
}
static void
_scale_change(void *data EINA_UNUSED,
Evas_Object *obj,
void *event_info EINA_UNUSED)
{
double scale = elm_config_scale_get();
double val = elm_slider_value_get(obj);
if (scale == val)
return;
elm_config_scale_set(val);
elm_config_all_flush();
}
typedef struct tag_Scale_Ctx
{
Evas_Object *hv;
Term *term;
} Scale_Ctx;
static void
_scale_done(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Scale_Ctx *ctx = data;
evas_object_smart_callback_del_full(ctx->hv, "dismissed",
_scale_done, ctx);
evas_object_del(ctx->hv);
ctx->term->wn->on_popover--;
term_unref(ctx->term);
elm_config_save();
config_save(ctx->term->config);
free(ctx);
}
void
win_scale_wizard(Evas_Object *win, Term *term)
{
Evas_Object *bx, *lbl, *sl, *fr, *bt;
const char *txt;
Scale_Ctx *ctx;
EINA_SAFETY_ON_NULL_RETURN(term);
ctx = calloc(1, sizeof(*ctx));
if (!ctx)
return;
ctx->term = term;
term->wn->on_popover++;
term_ref(term);
ctx->hv = elm_hover_add(win);
evas_object_size_hint_weight_set(ctx->hv, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(ctx->hv, EVAS_HINT_FILL, 0.5);
elm_hover_parent_set(ctx->hv, win);
elm_hover_target_set(ctx->hv, win);
evas_object_smart_callback_add(ctx->hv, "dismissed", _scale_done, ctx);
fr = elm_frame_add(win);
evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, 0.5);
elm_object_text_set(fr, _("Scale"));
elm_object_part_content_set(ctx->hv, "middle", fr);
evas_object_show(fr);
bx = elm_box_add(win);
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_object_content_set(fr, bx);
evas_object_show(bx);
fr = elm_frame_add(win);
evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, 0.5);
elm_object_style_set(fr, "pad_medium");
elm_box_pack_end(bx, fr);
evas_object_show(fr);
lbl = elm_label_add(win);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, 0.5);
txt = eina_stringshare_printf("<hilight>%s</>",_("Scale"));
elm_object_text_set(lbl, txt);
eina_stringshare_del(txt);
elm_object_content_set(fr, lbl);
elm_box_pack_end(bx, lbl);
evas_object_show(lbl);
sl = elm_slider_add(win);
evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
elm_slider_span_size_set(sl, 120);
elm_slider_unit_format_set(sl, "%1.2f");
elm_slider_indicator_format_set(sl, "%1.2f");
elm_slider_min_max_set(sl, 0.25, 5.0);
elm_slider_value_set(sl, elm_config_scale_get());
elm_box_pack_end(bx, sl);
evas_object_show(sl);
evas_object_smart_callback_add(sl, "changed", _scale_round, NULL);
evas_object_smart_callback_add(sl, "delay,changed", _scale_change, NULL);
bt = elm_button_add(win);
elm_object_text_set(bt, _("Done"));
elm_box_pack_end(bx, bt);
evas_object_smart_callback_add(bt, "clicked", _scale_done, ctx);
evas_object_show(bt);
lbl = elm_label_add(win);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, 0.5);
elm_object_text_set(lbl, _("Select preferred size so that this text is readable"));
elm_label_line_wrap_set(lbl, ELM_WRAP_WORD);
elm_box_pack_end(bx, lbl);
evas_object_show(lbl);
lbl = elm_label_add(win);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, 0.5);
elm_object_text_set(lbl, _("The scale configuration can be changed in the Settings (right click on the terminal) → Toolkit, or by starting the command <keyword>elementary_config</keyword>"));
elm_label_line_wrap_set(lbl, ELM_WRAP_WORD);
elm_box_pack_end(bx, lbl);
evas_object_show(lbl);
evas_object_show(ctx->hv);
elm_object_focus_set(ctx->hv, EINA_TRUE);
elm_object_focus_set(bt, EINA_TRUE);
}
/* }}} */
/* {{{ Solo */
static Evas_Object *
_solo_get_evas_object(const Term_Container *tc)
{
Solo *solo;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
return solo->term->bg;
}
static Term *
_solo_focused_term_get(const Term_Container *tc)
{
Solo *solo;
Term *term = NULL;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*)tc;
if (tc->is_focused)
term = solo->term;
return term;
}
static Term *
_solo_find_term_at_coords(const Term_Container *tc,
Evas_Coord _mx EINA_UNUSED,
Evas_Coord _my EINA_UNUSED)
{
Solo *solo;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
return solo->term;
}
static void
_solo_size_eval(Term_Container *container, Sizeinfo *info)
{
Term *term;
int mw = 0, mh = 0;
Solo *solo;
assert (container->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*)container;
term = solo->term;
info->min_w = term->min_w;
info->min_h = term->min_h;
info->step_x = term->step_x;
info->step_y = term->step_y;
info->req_w = term->req_w;
info->req_h = term->req_h;
if (!evas_object_data_get(term->termio, "sizedone"))
{
evas_object_data_set(term->termio, "sizedone", term->termio);
info->req = 1;
}
evas_object_size_hint_min_get(term->bg, &mw, &mh);
info->bg_min_w = mw;
info->bg_min_h = mh;
}
static void
_solo_close(Term_Container *tc,
Term_Container *_child EINA_UNUSED)
{
Solo *solo;
Term *term;
DBG("close");
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
tc->parent->close(tc->parent, tc);
eina_stringshare_del(tc->title);
term = solo->term;
term->container = NULL;
free(tc);
}
static void
_solo_tabs_new(Term_Container *tc)
{
if (tc->parent->type != TERM_CONTAINER_TYPE_TABS)
_tabs_new(tc, tc->parent);
_tab_new_cb(tc->parent, NULL, NULL);
}
static void
_solo_split(Term_Container *tc,
Term_Container *_child EINA_UNUSED,
Term *from,
const char *cmd,
Eina_Bool is_horizontal)
{
tc->parent->split(tc->parent, tc, from, cmd, is_horizontal);
}
static int
_solo_split_direction(Term_Container *tc,
Term_Container *child_orig EINA_UNUSED,
Term_Container *child_new,
Split_Direction direction)
{
return tc->parent->split_direction(tc->parent, tc, child_new, direction);
}
static Term *
_solo_term_next(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_next(tc->parent, tc);
}
static Term *
_solo_term_prev(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_prev(tc->parent, tc);
}
static Term *
_solo_term_up(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_up(tc->parent, tc);
}
static Term *
_solo_term_down(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_down(tc->parent, tc);
}
static Term *
_solo_term_left(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_left(tc->parent, tc);
}
static Term *
_solo_term_right(const Term_Container *tc,
const Term_Container *_child EINA_UNUSED)
{
return tc->parent->term_right(tc->parent, tc);
}
static Term *
_solo_term_first(const Term_Container *tc)
{
Solo *solo;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
return solo->term;
}
static Term *
_solo_term_last(const Term_Container *tc)
{
Solo *solo;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
return solo->term;
}
static void
_solo_set_title(Term_Container *tc,
Term_Container *_child EINA_UNUSED,
const char *title)
{
Solo *solo;
Term *term;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
eina_stringshare_del(tc->title);
tc->title = eina_stringshare_add(title);
if (term->config->show_tabs)
{
elm_layout_text_set(term->bg, "terminology.tab.title", title);
}
if (_tab_drag && _tab_drag->term == term && _tab_drag->icon)
{
elm_layout_text_set(_tab_drag->icon,
"terminology.title", title);
}
tc->parent->set_title(tc->parent, tc, title);
}
static void
_solo_bell(Term_Container *tc,
Term_Container *_child EINA_UNUSED)
{
Solo *solo;
Term *term;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
if (!tc->is_focused)
term->missed_bell = EINA_TRUE;
if (!tc->wn->config->disable_visual_bell)
{
elm_layout_signal_emit(term->bg, "bell", "terminology");
elm_layout_signal_emit(term->core, "bell", "terminology");
if (tc->wn->config->bell_rings)
{
elm_layout_signal_emit(term->bg, "bell,ring", "terminology");
elm_layout_signal_emit(term->core, "bell,ring", "terminology");
}
if ((_tab_drag != NULL) && (_tab_drag->term == term))
{
elm_layout_signal_emit(_tab_drag->icon, "bell", "terminology");
}
}
if ((term->missed_bell) && (term->config->show_tabs)
&& (tc->parent->type == TERM_CONTAINER_TYPE_SPLIT))
{
elm_layout_signal_emit(term->bg, "tab,bell,on", "terminology");
}
edje_object_message_signal_process(term->bg_edj);
tc->parent->bell(tc->parent, tc);
}
static void
_solo_unfocus(Term_Container *tc, Term_Container *relative)
{
Solo *solo;
Term *term;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
DBG("tc:%p tc->is_focused:%d from_parent:%d term:%p",
tc, tc->is_focused, tc->parent == relative, term);
if (!tc->is_focused)
return;
tc->is_focused = EINA_FALSE;
termio_focus_out(term->termio);
if (tc->parent != relative)
tc->parent->unfocus(tc->parent, tc);
if (!term->config->disable_focus_visuals)
{
elm_layout_signal_emit(term->bg, "focus,out", "terminology");
elm_layout_signal_emit(term->core, "focus,out", "terminology");
}
}
static void
_solo_focus(Term_Container *tc, Term_Container *relative)
{
Solo *solo;
Term *term;
const char *title;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
if (!tc->parent)
return;
DBG("tc:%p tc->is_focused:%d from_parent:%d term:%p",
tc, tc->is_focused, tc->parent == relative, term);
if (tc->is_focused)
return;
term->missed_bell = EINA_FALSE;
if ((term->config->show_tabs)
&& (tc->parent->type == TERM_CONTAINER_TYPE_SPLIT))
{
elm_layout_signal_emit(term->bg, "tab,bell,off", "terminology");
}
if (term->config->disable_focus_visuals)
{
elm_layout_signal_emit(term->bg, "focused,set", "terminology");
elm_layout_signal_emit(term->core, "focused,set", "terminology");
}
else
{
elm_layout_signal_emit(term->bg, "focus,in", "terminology");
elm_layout_signal_emit(term->core, "focus,in", "terminology");
}
termio_event_feed_mouse_in(term->termio);
termio_focus_in(term->termio);
title = termio_title_get(term->termio);
if (title)
tc->set_title(tc, tc, title);
if (term->missed_bell)
term->missed_bell = EINA_FALSE;
edje_object_message_signal_process(term->bg_edj);
if (!tc->is_focused && relative != tc->parent)
{
tc->is_focused = EINA_TRUE;
tc->parent->focus(tc->parent, tc);
}
tc->is_focused = EINA_TRUE;
_focus_validator();
}
static Eina_Bool
_solo_is_visible(const Term_Container *tc, const Term_Container *_child EINA_UNUSED)
{
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
return tc->parent->is_visible(tc->parent, tc);
}
static void
_solo_tab_show(Term_Container *tc)
{
Solo *solo;
Term *term;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
DBG("tab show tc:%p", tc);
if (!term->tab_spacer)
{
Evas_Coord w = 0, h = 0;
term->tab_spacer = evas_object_rectangle_add(
evas_object_evas_get(term->bg));
evas_object_color_set(term->tab_spacer, 0, 0, 0, 0);
elm_coords_finger_size_adjust(1, &w, 1, &h);
evas_object_size_hint_min_set(term->tab_spacer, w, h);
elm_layout_content_set(term->bg, "terminology.tab", term->tab_spacer);
edje_object_part_drag_value_set(term->bg_edj,
"terminology.tabl", 0.0, 0.0);
edje_object_part_drag_value_set(term->bg_edj,
"terminology.tabr", 1.0, 0.0);
elm_layout_text_set(term->bg, "terminology.tab.title",
solo->tc.title);
elm_layout_signal_emit(term->bg, "tabbar,on", "terminology");
edje_object_message_signal_process(term->bg_edj);
}
else
{
edje_object_part_drag_value_set(term->bg_edj, "terminology.tabl", 0.0, 0.0);
edje_object_part_drag_value_set(term->bg_edj, "terminology.tabr", 1.0, 0.0);
edje_object_message_signal_process(term->bg_edj);
}
}
static void
_solo_tab_hide(Term_Container *tc)
{
Solo *solo;
Term *term;
DBG("title hide tc:%p", tc);
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
if (term->tab_spacer)
{
elm_layout_signal_emit(term->bg, "tabbar,off", "terminology");
edje_object_message_signal_process(term->bg_edj);
elm_layout_content_unset(term->bg, "terminology.tab");
evas_object_del(term->tab_spacer);
term->tab_spacer = NULL;
}
}
static void
_solo_update(Term_Container *tc)
{
Solo *solo;
Term *term;
Term_Container *tc_parent = tc->parent;
assert (tc->type == TERM_CONTAINER_TYPE_SOLO);
solo = (Solo*) tc;
term = solo->term;
if (tc_parent->type == TERM_CONTAINER_TYPE_SPLIT)
{
if (term->config->show_tabs)
_solo_tab_show(tc);
else
_solo_tab_hide(tc);
}
}
static Term_Container *
_solo_new(Term *term, Win *wn)
{
Term_Container *tc = NULL;
Solo *solo = NULL;
solo = calloc(1, sizeof(Solo));
if (!solo)
{
free(solo);
return NULL;
}
tc = (Term_Container*)solo;
tc->term_next = _solo_term_next;
tc->term_prev = _solo_term_prev;
tc->term_up = _solo_term_up;
tc->term_down = _solo_term_down;
tc->term_left = _solo_term_left;
tc->term_right = _solo_term_right;
tc->term_first = _solo_term_first;
tc->term_last = _solo_term_last;
tc->focused_term_get = _solo_focused_term_get;
tc->get_evas_object = _solo_get_evas_object;
tc->split = _solo_split;
tc->split_direction = _solo_split_direction;
tc->find_term_at_coords = _solo_find_term_at_coords;
tc->size_eval = _solo_size_eval;
tc->swallow = NULL;
tc->focus = _solo_focus;
tc->unfocus = _solo_unfocus;
tc->set_title = _solo_set_title;
tc->bell = _solo_bell;
tc->close = _solo_close;
tc->update = _solo_update;
tc->title = eina_stringshare_add("Terminology");
tc->is_visible = _solo_is_visible;
tc->detach = NULL;
tc->type = TERM_CONTAINER_TYPE_SOLO;
tc->parent = NULL;
tc->wn = wn;
solo->term = term;
term->container = tc;
return tc;
}
/* }}} */
/* {{{ Win */
static void
_cb_win_focus_in(void *data,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
Win *wn = data;
Term_Container *tc = (Term_Container*) wn;
Term *term;
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);
tc->is_focused = EINA_TRUE;
if (wn->on_popover)
return;
term = tc->focused_term_get(tc);
if (wn->group_input)
{
Eina_List *l;
Term *t;
GROUPED_INPUT_TERM_FOREACH(wn, l, t)
{
elm_layout_signal_emit(t->bg, "focus,in", "terminology");
termio_event_feed_mouse_in(t->termio);
termio_focus_in(t->termio);
}
}
else if ( wn->config->mouse_over_focus )
{
Term *term_mouse;
Evas_Coord mx, my;
evas_pointer_canvas_xy_get(evas_object_evas_get(wn->win), &mx, &my);
term_mouse = tc->find_term_at_coords(tc, mx, my);
if ((term_mouse) && (term_mouse != term))
{
if (term)
{
if (!term->config->disable_focus_visuals)
{
elm_layout_signal_emit(term->bg, "focus,out", "terminology");
elm_layout_signal_emit(term->core, "focus,out", "terminology");
}
}
term = term_mouse;
}
}
if (term)
{
term_focus(term);
}
else
{
DBG("focus tc:%p", tc);
tc->focus(tc, tc);
}
}
static void
_cb_win_focus_out(void *data,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
Win *wn = data;
Term_Container *tc = (Term_Container*) wn;
if (wn->on_popover)
return;
DBG("FOCUS OUT tc:%p tc->is_focused:%d",
tc, tc->is_focused);
tc->unfocus(tc, NULL);
if (wn->group_input)
{
Eina_List *l;
Term *term;
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
{
elm_layout_signal_emit(term->bg, "focus,out", "terminology");
termio_focus_out(term->termio);
}
}
}
static Eina_Bool
_win_is_focused(Win *wn)
{
Term_Container *tc;
if (!wn)
return EINA_FALSE;
tc = (Term_Container*) wn;
DBG("tc:%p tc->is_focused:%d",
tc, tc->is_focused);
return tc->is_focused;
}
int win_term_set(Win *wn, Term *term)
{
Term_Container *tc_win = NULL, *tc_child = NULL;
tc_child = _solo_new(term, wn);
if (!tc_child)
goto bad;
tc_win = (Term_Container*) wn;
tc_win->swallow(tc_win, NULL, tc_child);
_cb_size_hint(term, NULL, term->termio, NULL);
return 0;
bad:
free(tc_child);
return -1;
}
Config *
win_config_get(const Win *wn)
{
return wn->config;
}
Eina_List *
win_terms_get(const Win *wn)
{
return wn->terms;
}
Evas_Object *
win_evas_object_get(const Win *wn)
{
return wn->win;
}
static void
_term_trans(Term *term)
{
Edje_Message_Int msg;
Evas_Object *edje = elm_layout_edje_get(term->core);
Win *wn = term->wn;
if (term->config->translucent)
msg.val = term->config->opacity;
else
msg.val = 100;
edje_object_message_send(term->bg_edj, EDJE_MESSAGE_INT, 1, &msg);
edje_object_message_send(edje, EDJE_MESSAGE_INT, 1, &msg);
if (term->config->translucent != wn->translucent)
{
if (term->config->translucent)
{
elm_win_alpha_set(wn->win, EINA_TRUE);
evas_object_hide(wn->backbg);
wn->translucent = EINA_TRUE;
}
else
{
elm_win_alpha_set(wn->win, EINA_FALSE);
evas_object_show(wn->backbg);
wn->translucent = EINA_FALSE;
}
}
}
void
main_trans_update(void)
{
Win *wn;
Term *term;
Eina_List *l, *ll;
EINA_LIST_FOREACH(wins, l, wn)
{
EINA_LIST_FOREACH(wn->terms, ll, term)
{
_term_trans(term);
}
}
}
static void
_cb_del(void *data,
Evas *_e EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
Win *wn = data;
// already obj here is deleted - dont do it again
wn->win = NULL;
win_free(wn);
}
void
win_free(Win *wn)
{
Term *term;
wins = eina_list_remove(wins, wn);
if (wn->config_elm_handler)
{
ecore_event_handler_del(wn->config_elm_handler);
wn->config_elm_handler = NULL;
}
EINA_LIST_FREE(wn->terms, term)
{
term_unref(term);
}
if (wn->cmdbox_del_timer)
{
ecore_timer_del(wn->cmdbox_del_timer);
wn->cmdbox_del_timer = NULL;
}
if (wn->cmdbox)
{
evas_object_del(wn->cmdbox);
wn->cmdbox = NULL;
}
if (wn->win)
{
evas_object_smart_callback_del_full(wn->win, "focus,in", _cb_win_focus_in, wn);
evas_object_smart_callback_del_full(wn->win, "focus,out", _cb_win_focus_out, 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);
config_del(wn->config);
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);
}
if (wn->hide_cursor_timer)
{
ecore_timer_del(wn->hide_cursor_timer);
}
ecore_imf_shutdown();
free(wn);
}
Win *
win_evas_object_to_win(const Evas_Object *win)
{
Win *wn;
Eina_List *l;
EINA_LIST_FOREACH(wins, l, wn)
{
if (wn->win == win) return wn;
}
return NULL;
}
Eina_List *
terms_from_win_object(Evas_Object *win)
{
Win *wn;
wn = win_evas_object_to_win(win);
if (!wn) return NULL;
return wn->terms;
}
static Evas_Object *
win_add(const char *name, const char *role,
const char *title, const char *icon_name)
{
Evas_Object *win;
if (!name) name = "main";
if (!title) title = "Terminology";
if (!icon_name) icon_name = "terminology";
win = elm_win_add(NULL, name, ELM_WIN_BASIC);
elm_win_title_set(win, title);
elm_win_icon_name_set(win, icon_name);
if (role) elm_win_role_set(win, role);
elm_win_autodel_set(win, EINA_TRUE);
return win;
}
static Evas_Object *
_win_get_evas_object(const Term_Container *tc)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
return wn->win;
}
static Term *
_win_term_next(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child)
{
return child->term_first(child);
}
static Term *
_win_term_prev(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child)
{
return child->term_last(child);
}
static Term *
_win_term_up(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child EINA_UNUSED)
{
return NULL;
}
static Term *
_win_term_down(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child EINA_UNUSED)
{
return NULL;
}
static Term *
_win_term_left(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child EINA_UNUSED)
{
return NULL;
}
static Term *
_win_term_right(const Term_Container *_tc EINA_UNUSED,
const Term_Container *child EINA_UNUSED)
{
return NULL;
}
static Term *
_win_term_first(const Term_Container *tc)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
return wn->child->term_first(wn->child);
}
static Term *
_win_term_last(const Term_Container *tc)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
return wn->child->term_last(wn->child);
}
static Term *
_win_focused_term_get(const Term_Container *tc)
{
Win *wn;
Term *term = NULL;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (tc->is_focused && wn->child)
term = wn->child->focused_term_get(wn->child);
return term;
}
static Term *
_win_find_term_at_coords(const Term_Container *tc,
Evas_Coord mx, Evas_Coord my)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (!wn->child)
return NULL;
return wn->child->find_term_at_coords(wn->child, mx, my);
}
static void
_win_size_eval(Term_Container *tc, Sizeinfo *info)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
assert(wn->child);
wn->child->size_eval(wn->child, info);
}
static void
_win_swallow(Term_Container *tc, Term_Container *orig,
Term_Container *new_child)
{
Win *wn;
Evas_Object *o;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
DBG("orig:%p", orig);
if (orig)
{
elm_layout_content_unset(wn->base, "terminology.content");
}
o = new_child->get_evas_object(new_child);
elm_layout_content_set(wn->base, "terminology.content", o);
if ((new_child->type == TERM_CONTAINER_TYPE_SOLO)
&& (wn->config->show_tabs))
{
if (_tab_drag && _tab_drag->term && (_tab_drag->term->wn == wn) &&
_tab_drag->icon)
_solo_tab_show(new_child);
else
_solo_tab_hide(new_child);
}
evas_object_show(o);
new_child->parent = tc;
wn->child = new_child;
if (_tab_drag && _tab_drag->icon)
{
evas_object_raise(_tab_drag->icon);
}
}
static void
_win_close(Term_Container *tc,
Term_Container *_child EINA_UNUSED)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
DBG("win close");
if (_tab_drag && _tab_drag->term && (_tab_drag->term->wn == wn))
{
_tab_drag->parent_type = TERM_CONTAINER_TYPE_WIN;
_tab_drag_free();
return;
}
eina_stringshare_del(tc->title);
win_free(wn);
}
static void
_win_focus(Term_Container *tc, Term_Container *relative)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
elm_object_focus_allow_set(wn->base, EINA_TRUE);
DBG("tc:%p tc->is_focused:%d from_child:%d",
tc, tc->is_focused, wn->child == relative);
elm_object_focus_set(wn->base, EINA_TRUE);
if (!tc->is_focused)
elm_win_urgent_set(wn->win, EINA_FALSE);
tc->is_focused = EINA_TRUE;
if ((relative != wn->child) || (!wn->focused))
{
DBG("focus tc:%p", tc);
wn->child->focus(wn->child, tc);
elm_win_keyboard_mode_set(wn->win, ELM_WIN_KEYBOARD_TERMINAL);
if (wn->khdl.imf)
{
Term *focused;
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);
}
}
}
static void
_win_unfocus(Term_Container *tc, Term_Container *relative)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
elm_object_focus_set(wn->base, EINA_FALSE);
elm_object_focus_allow_set(wn->base, EINA_FALSE);
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);
}
}
static void
_win_bell(Term_Container *tc,
Term_Container *_child EINA_UNUSED)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (tc->is_focused) return;
if (wn->config->urg_bell)
{
elm_win_urgent_set(wn->win, EINA_TRUE);
}
}
static void
_win_set_title(Term_Container *tc,
Term_Container *_child EINA_UNUSED,
const char *title)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
eina_stringshare_del(tc->title);
tc->title = eina_stringshare_ref(title);
elm_win_title_set(wn->win, title);
}
Eina_Bool
_term_container_is_splittable(Term_Container *tc, Eina_Bool is_horizontal)
{
int w = 0, h = 0, c_w = 0, c_h = 0;
Term *tm;
if (terminology_starting_up)
return EINA_TRUE;
tm = tc->term_first(tc);
evas_object_geometry_get(tm->bg, NULL, NULL, &w, &h);
evas_object_textgrid_cell_size_get(termio_textgrid_get(tm->termio),
&c_w, &c_h);
if (is_horizontal)
{
if (c_h * 2 > h)
return EINA_FALSE;
}
else
{
if (c_w * 2 > w)
return EINA_FALSE;
}
return EINA_TRUE;
}
static void
_win_split(Term_Container *tc, Term_Container *child,
Term *from, const char *cmd, Eina_Bool is_horizontal)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (_term_container_is_splittable(tc, is_horizontal))
{
Term *tm_new, *tm;
Term_Container *tc_split, *tc_solo_new;
char *wdir = NULL;
char buf[PATH_MAX];
// 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 = tc->focused_term_get(tc);
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);
elm_layout_content_unset(wn->base, "terminology.content");
tc_split = _split_new(child, tc_solo_new, 0.5, is_horizontal);
if (wn->config->show_tabs)
{
if (child->type == TERM_CONTAINER_TYPE_SOLO)
{
_solo_tab_show(child);
}
_solo_tab_show(tc_solo_new);
}
child->unfocus(child, tc_split);
tc->swallow(tc, NULL, tc_split);
tc_split->is_focused = EINA_TRUE;
tc_split->focus(tc_split, tc_solo_new);
tc_solo_new->focus(tc_solo_new, tc_split);
}
else
{
ERR("term is not splittable");
}
}
static int
_win_split_direction(Term_Container *tc,
Term_Container *child_orig,
Term_Container *child_new,
Split_Direction direction)
{
Term_Container *child1, *child2, *tc_split;
Win *wn;
Eina_Bool is_horizontal =
(direction == SPLIT_DIRECTION_LEFT) || (direction == SPLIT_DIRECTION_RIGHT) ?
EINA_FALSE : EINA_TRUE;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (!_term_container_is_splittable(tc, is_horizontal))
{
ERR("term is not splittable");
return -1;
}
if ((direction == SPLIT_DIRECTION_TOP) ||
(direction == SPLIT_DIRECTION_LEFT))
{
child1 = child_new;
child2 = child_orig;
}
else
{
child1 = child_orig;
child2 = child_new;
}
wn->tc.unfocus(&wn->tc, NULL); /* unfocus from top */
tc_split = _split_new(child1, child2, 0.5, is_horizontal);
if (wn->config->show_tabs)
{
if (child_orig->type == TERM_CONTAINER_TYPE_SOLO)
{
_solo_tab_show(child_orig);
}
_solo_tab_show(child_new);
}
tc_split->is_focused = tc->is_focused;
tc->swallow(tc, NULL, tc_split);
child_new->focus(child_new, NULL); /* refocus from bottom */
return 0;
}
static Eina_Bool
_set_cursor(Term *term, void *data)
{
const char *cursor = data;
assert(term->core);
if (cursor)
{
elm_object_cursor_set(term->core, cursor);
term->core_cursor_set = 1;
}
else
{
if (term->core_cursor_set)
elm_object_cursor_unset(term->core);
term->core_cursor_set = 0;
}
return ECORE_CALLBACK_PASS_ON;
}
static void
_win_update(Term_Container *tc)
{
Win *wn;
assert (tc->type == TERM_CONTAINER_TYPE_WIN);
wn = (Win*) tc;
if (wn->config->hide_cursor >= CONFIG_CURSOR_IDLE_TIMEOUT_MAX)
{
ecore_timer_del(wn->hide_cursor_timer);
wn->hide_cursor_timer = NULL;
for_each_term_do(wn, &_set_cursor, NULL);
}
wn->child->update(wn->child);
}
Eina_Bool
win_has_single_child(const Win *wn)
{
const Term_Container *child = wn->child;
return (child->type == TERM_CONTAINER_TYPE_SOLO);
}
static void
_cb_win_key_up(void *data,
Evas *_e EINA_UNUSED,
Evas_Object *_obj EINA_UNUSED,
void *event)
{
Win *wn = data;
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);
}
const char *
term_preedit_str_get(Term *term)
{
Win *wn = term->wn;
Term_Container *tc = (Term_Container*) wn;
if (wn->on_popover)
return NULL;
tc = (Term_Container*) wn;
term = tc->focused_term_get(tc);
if (term)
{
return wn->preedit_str;
}
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,
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)
{
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
{
ty = termio_pty_get(term->termio);
if (ty)
termpty_write(ty, str, len);
}
}
else
{
Term_Container *tc = (Term_Container*) wn;
term = tc->focused_term_get(tc);
if (term)
{
ty = termio_pty_get(term->termio);
if (ty)
termpty_write(ty, str, len);
}
}
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);
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,
Evas_Object *_obj EINA_UNUSED,
void *event_info)
{
Win *wn = data;
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"));
_focus_validator();
if ((wn->on_popover) || (wn->cmdbox_up)) 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");
/* 1st/ Tab selector */
{
Term_Container *tc = (Term_Container*) wn;
term = tc->focused_term_get(tc);
if (term)
{
Term_Container *tc_parent = tc->parent;
tc = term->container;
tc_parent = tc->parent;
if (tc_parent->type == TERM_CONTAINER_TYPE_TABS)
{
Tabs *tabs = (Tabs*) tc_parent;
if (tabs->selector != NULL)
{
sel_key_down(tabs->selector, ev);
return;
}
}
}
}
/* 2nd/ Miniview */
if (wn->group_input)
{
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
{
done = miniview_handle_key(term_miniview_get(term), ev);
if (!wn->group_input)
return;
}
}
else
{
Term_Container *tc = (Term_Container*) wn;
term = tc->focused_term_get(tc);
if (!term)
{
DBG("no focused term");
return;
}
done = miniview_handle_key(term_miniview_get(term), ev);
}
if (done)
{
keyin_compose_seq_reset(&wn->khdl);
goto end;
}
/* 3rd/ PopMedia */
done = EINA_FALSE;
if (wn->group_input)
{
GROUPED_INPUT_TERM_FOREACH(wn, 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)
{
DBG("no focused 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;
}
/* 4th/ Handle key bindings */
done = EINA_FALSE;
if (wn->group_input)
{
wn->group_once_handled = EINA_FALSE;
GROUPED_INPUT_TERM_FOREACH(wn, 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;
/* 5th/ 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)
{
GROUPED_INPUT_TERM_FOREACH(wn, 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;
}
/* 6th/ send key to pty */
if (wn->group_input)
{
GROUPED_INPUT_TERM_FOREACH(wn, 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);
DBG("ty:%p", ty);
if (ty && termpty_can_handle_key(ty, &wn->khdl, ev))
keyin_handle_key_to_pty(ty, ev, alt, shift, ctrl);
}
/* 7th: specifics: jump on keypress / flicker on key */
end:
if (wn->group_input)
{
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
{
if (term)
termio_key_down(term->termio, ev, done);
}
}
else
{
if (term)
termio_key_down(term->termio, ev, done);
}
}
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;
if (wn->on_popover || wn->group_input)
return;
/* Focus In event will handle that */
if (!tc->is_focused)
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;
DBG("focus tc_child:%p", tc_child);
tc_child->focus(tc_child, tc);
}
static Eina_Bool
_hide_cursor(void *data)
{
Win *wn = data;
wn->hide_cursor_timer = NULL;
for_each_term_do(wn, &_set_cursor, (void*)"blank");
return ECORE_CALLBACK_CANCEL;
}
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 = NULL;
if (wn->on_popover)
return;
if (wn->config->hide_cursor < CONFIG_CURSOR_IDLE_TIMEOUT_MAX)
{
if (wn->hide_cursor_timer)
{
ecore_timer_interval_set(wn->hide_cursor_timer,
wn->config->hide_cursor);
}
else
{
for_each_term_do(wn, &_set_cursor, NULL);
wn->hide_cursor_timer = ecore_timer_add(
wn->config->hide_cursor, _hide_cursor, wn);
}
}
if (wn->group_input || !tc->is_focused || !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);
}
static Eina_Bool
_config_font_size_set(Term *term, void *data EINA_UNUSED)
{
Config *config = termio_config_get(term->termio);
termio_font_size_set(term->termio, config->font.size);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_cb_elm_config_change(void *data, int event EINA_UNUSED, void *info EINA_UNUSED)
{
Win *wn = data;
for_each_term_do(wn, &_config_font_size_set, NULL);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_win_is_visible(const Term_Container *tc, const 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,
const char *icon_name, Config *config,
Eina_Bool fullscreen, Eina_Bool iconic,
Eina_Bool borderless, Eina_Bool override,
Eina_Bool maximized)
{
Win *wn;
Evas_Object *o;
Term_Container *tc;
wn = calloc(1, sizeof(Win));
if (!wn) return NULL;
wn->win = win_add(name, role, title, icon_name);
if (!wn->win)
{
free(wn);
return NULL;
}
if (_win_log_dom < 0)
{
_win_log_dom = eina_log_domain_register("win", NULL);
if (_win_log_dom < 0)
EINA_LOG_CRIT("Could not create logging domain '%s'", "win");
}
tc = (Term_Container*) wn;
tc->term_next = _win_term_next;
tc->term_prev = _win_term_prev;
tc->term_up = _win_term_up;
tc->term_down = _win_term_down;
tc->term_left = _win_term_left;
tc->term_right = _win_term_right;
tc->term_first = _win_term_first;
tc->term_last = _win_term_last;
tc->focused_term_get = _win_focused_term_get;
tc->get_evas_object = _win_get_evas_object;
tc->split = _win_split;
tc->split_direction = _win_split_direction;
tc->find_term_at_coords = _win_find_term_at_coords;
tc->size_eval = _win_size_eval;
tc->swallow = _win_swallow;
tc->focus = _win_focus;
tc->unfocus = _win_unfocus;
tc->set_title = _win_set_title;
tc->bell = _win_bell;
tc->close = _win_close;
tc->update = _win_update;
tc->is_visible = _win_is_visible;
tc->detach = NULL;
tc->title = eina_stringshare_add(title? title : "Terminology");
tc->type = TERM_CONTAINER_TYPE_WIN;
tc->wn = wn;
config_default_font_set(config, evas_object_evas_get(wn->win));
wn->config = config_fork(config);
evas_object_event_callback_add(wn->win, EVAS_CALLBACK_DEL, _cb_del, wn);
if (fullscreen) elm_win_fullscreen_set(wn->win, EINA_TRUE);
if (iconic) elm_win_iconified_set(wn->win, EINA_TRUE);
if (borderless) elm_win_borderless_set(wn->win, EINA_TRUE);
if (override) elm_win_override_set(wn->win, EINA_TRUE);
if (maximized) elm_win_maximized_set(wn->win, EINA_TRUE);
wn->backbg = o = evas_object_rectangle_add(evas_object_evas_get(wn->win));
evas_object_color_set(o, 0, 0, 0, 255);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_resize_object_add(wn->win, o);
evas_object_show(o);
wn->conform = o = elm_conformant_add(wn->win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_resize_object_add(wn->win, o);
evas_object_show(o);
wn->base = o = elm_layout_add(wn->win);
elm_object_focus_allow_set(o, EINA_TRUE);
theme_apply(o, config, "terminology/base", NULL, NULL, EINA_TRUE);
evas_object_propagate_events_set(o, EINA_FALSE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(wn->conform, o);
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->base,
EVAS_CALLBACK_KEY_DOWN,
_cb_win_key_down,
wn);
evas_object_event_callback_add(wn->base,
EVAS_CALLBACK_KEY_UP,
_cb_win_key_up,
wn);
evas_object_event_callback_add(wn->base,
EVAS_CALLBACK_MOUSE_DOWN,
_cb_win_mouse_down,
wn);
evas_object_event_callback_add(wn->base,
EVAS_CALLBACK_MOUSE_MOVE,
_cb_win_mouse_move,
wn);
evas_object_show(o);
elm_object_focus_highlight_style_set(o, "blank");
elm_object_focus_set(o, EINA_TRUE);
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"));
}
if (wn->config->hide_cursor < CONFIG_CURSOR_IDLE_TIMEOUT_MAX)
{
wn->hide_cursor_timer = ecore_timer_add(
wn->config->hide_cursor, _hide_cursor, wn);
}
wins = eina_list_append(wins, wn);
wn->tc.is_focused = EINA_TRUE;
wn->config_elm_handler = ecore_event_handler_add
(ELM_EVENT_CONFIG_ALL_CHANGED, _cb_elm_config_change, wn);
return wn;
}
void
term_close(Evas_Object *win, Evas_Object *term, Eina_Bool hold_if_requested)
{
Term *tm;
Term_Container *tc;
Win *wn = win_evas_object_to_win(win);
if (!wn)
return;
tm = evas_object_data_get(term, "term");
if (!tm)
return;
if (tm->hold && hold_if_requested)
return;
wn->terms = eina_list_remove(wn->terms, tm);
tc = tm->container;
tc->close(tc, tc);
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(const 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)
{
GROUPED_INPUT_TERM_FOREACH(wn, l, term)
{
elm_layout_signal_emit(term->bg, "focus,in", "terminology");
elm_layout_signal_emit(term->bg, "grouped,on", "terminology");
if (term->tab_inactive)
edje_object_signal_emit(term->tab_inactive,
"grouped,on", "terminology");
termio_event_feed_mouse_in(term->termio);
termio_focus_in(term->termio);
}
wn->group_input = EINA_TRUE;
DBG("GROUP INPUT is now TRUE");
}
else
{
wn->group_input = EINA_FALSE;
DBG("GROUP INPUT is now FALSE");
/* Better disable it for all of them in case of change of policy
* between only visible or all.
* Using the GROUPED_INPUT_TERM_FOREACH macro would miss some terms */
EINA_LIST_FOREACH(wn->terms, l, term)
{
elm_layout_signal_emit(term->bg, "focus,out", "terminology");
elm_layout_signal_emit(term->bg, "grouped,off", "terminology");
if (term->tab_inactive)
edje_object_signal_emit(term->tab_inactive,
"grouped,off", "terminology");
termio_focus_out(term->termio);
}
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 */
static Term *
_split_term_next(const Term_Container *tc, const Term_Container *child)
{
Split *split;