options infrastructure refactor.

There is no global config option anymore, we have option instances
that are set to the termio and media for future queries.

The idea is that we can later have different configuration per termio,
like multiple windows or tabs with different font size, background,
etc.

It's just a refactor. It would be better to define if things like
background is up to the whole terminal and then save to a different
config entry... or just save the global and copy it for next termio,
defining the other instances as 'temporary'. Anyway: policy to be defined.



SVN revision: 72315
This commit is contained in:
Gustavo Sverzut Barbieri 2012-06-17 20:24:23 +00:00
parent 35e7dbbf4e
commit 652df62d45
12 changed files with 273 additions and 146 deletions

View File

@ -4,8 +4,6 @@
#define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;}
static Eet_Data_Descriptor *edd_base = NULL;
Config *config = NULL;
Eina_Bool config_tmp = EINA_FALSE;
static const char *
_homedir(void)
@ -22,8 +20,6 @@ void
config_init(void)
{
Eet_Data_Descriptor_Class eddc;
Eet_File *ef;
char buf[4096], *home;
eet_eina_stream_data_descriptor_class_set
(&eddc, sizeof(eddc), "Config", sizeof(Config));
@ -51,13 +47,61 @@ config_init(void)
(edd_base, Config, "vidmod", vidmod, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "mute", mute, EET_T_UCHAR);
}
home = (char *)_homedir();
void
config_shutdown(void)
{
if (edd_base)
{
eet_data_descriptor_free(edd_base);
edd_base = NULL;
}
}
void
config_save(const Config *config, const char *key)
{
Eet_File *ef;
char buf[PATH_MAX], buf2[PATH_MAX];
const char *home;
int ok;
EINA_SAFETY_ON_NULL_RETURN(config);
if (config->temporary) return;
if (!key) key = config->config_key;
home = _homedir();
snprintf(buf, sizeof(buf), "%s/.terminology/config/standard", home);
ecore_file_mkpath(buf);
snprintf(buf, sizeof(buf), "%s/.terminology/config/standard/base.cfg.tmp", home);
snprintf(buf2, sizeof(buf2), "%s/.terminology/config/standard/base.cfg", home);
ef = eet_open(buf, EET_FILE_MODE_WRITE);
if (ef)
{
ok = eet_data_write(ef, edd_base, key, config, 1);
eet_close(ef);
if (ok) ecore_file_mv(buf, buf2);
}
}
Config *
config_load(const char *key)
{
Eet_File *ef;
char buf[PATH_MAX];
const char *home;
Config *config;
EINA_SAFETY_ON_NULL_RETURN_VAL(key, NULL);
home = _homedir();
snprintf(buf, sizeof(buf), "%s/.terminology/config/standard/base.cfg", home);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
{
config = eet_data_read(ef, edd_base, "config");
config = eet_data_read(ef, edd_base, key);
eet_close(ef);
if (config)
{
@ -67,57 +111,50 @@ config_init(void)
if (!config)
{
config = calloc(1, sizeof(Config));
config->font.bitmap = 1;
config->font.bitmap = EINA_TRUE;
config->font.name = eina_stringshare_add("nexus.pcf");
config->font.size = 10;
config->scrollback = 2000;
config->theme = eina_stringshare_add("default.edj");
config->background = NULL;
config->translucent = 0;
config->jump_on_change = 0;
config->translucent = EINA_FALSE;
config->jump_on_change = EINA_FALSE;
config->wordsep = eina_stringshare_add(" '\"()[]{}=*!#$^\\:;,?`");
config->vidmod = 0;
config->mute = 0;
config->mute = EINA_FALSE;
}
config->config_key = eina_stringshare_add(key); /* not in eet */
return config;
}
void
config_shutdown(void)
config_del(Config *config)
{
if (config)
{
if (config->font.name) eina_stringshare_del(config->font.name);
if (config->theme) eina_stringshare_del(config->theme);
if (config->background) eina_stringshare_del(config->background);
if (config->wordsep) eina_stringshare_del(config->wordsep);
free(config);
config = NULL;
}
if (edd_base)
{
eet_data_descriptor_free(edd_base);
edd_base = NULL;
}
if (!config) return;
eina_stringshare_del(config->font.name);
eina_stringshare_del(config->theme);
eina_stringshare_del(config->background);
eina_stringshare_del(config->wordsep);
eina_stringshare_del(config->config_key); /* not in eet */
free(config);
}
void
config_save(void)
const char *
config_theme_path_get(const Config *config)
{
Eet_File *ef;
char buf[4096], buf2[4096], *home;
int ok;
static char path[PATH_MAX];
if (config_tmp) return;
home = (char *)_homedir();
snprintf(buf, sizeof(buf), "%s/.terminology/config/standard", home);
ecore_file_mkpath(buf);
snprintf(buf, sizeof(buf), "%s/.terminology/config/standard/base.cfg.tmp", home);
snprintf(buf2, sizeof(buf2), "%s/.terminology/config/standard/base.cfg", home);
ef = eet_open(buf, EET_FILE_MODE_WRITE);
if (ef)
{
ok = eet_data_write(ef, edd_base, "config", config, 1);
eet_close(ef);
if (ok) ecore_file_mv(buf, buf2);
}
EINA_SAFETY_ON_NULL_RETURN_VAL(config, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(config->theme, NULL);
if (strchr(config->theme, '/'))
return config->theme;
snprintf(path, sizeof(path), "%s/themes/%s",
elm_app_data_dir_get(), config->theme);
return path;
}

View File

@ -1,5 +1,10 @@
#ifndef _CONFIG_H__
#define _CONFIG_H__ 1
typedef struct _Config Config;
/* TODO: separate config per terminal (tab, window) and global. */
struct _Config
{
struct {
@ -7,19 +12,24 @@ struct _Config
int size;
unsigned char bitmap;
} font;
int scrollback;
const char *theme;
const char *background;
unsigned char jump_on_change;
unsigned char translucent;
const char *wordsep;
int scrollback;
int vidmod;
unsigned char mute;
Eina_Bool jump_on_change;
Eina_Bool translucent;
Eina_Bool mute;
Eina_Bool temporary; /* not in EET */
const char *config_key; /* not in EET, the key that config was loaded */
};
extern Config *config;
extern Eina_Bool config_tmp;
void config_init(void);
void config_shutdown(void);
void config_save(void);
void config_save(const Config *config, const char *key);
Config *config_load(const char *key);
void config_del(Config *config);
const char *config_theme_path_get(const Config *config);
#endif

View File

@ -70,7 +70,7 @@ _cb_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNU
}
void
main_trans_update(void)
main_trans_update(const Config *config)
{
if (config->translucent)
{
@ -85,7 +85,7 @@ main_trans_update(void)
}
void
main_media_update(void)
main_media_update(const Config *config)
{
Evas_Object *o;
int type = 0;
@ -93,7 +93,7 @@ main_media_update(void)
if ((config->background) && (config->background[0]))
{
if (media) evas_object_del(media);
o = media = media_add(win, config->background, MEDIA_BG, &type);
o = media = media_add(win, config->background, config, MEDIA_BG, &type);
edje_object_part_swallow(bg, "terminology.background", o);
if (type == TYPE_IMG)
edje_object_signal_emit(bg, "media,image", "terminology");
@ -117,7 +117,7 @@ main_media_update(void)
}
void
main_media_mute_update(void)
main_media_mute_update(const Config *config)
{
if (media) media_mute_set(media, config->mute);
}
@ -178,6 +178,7 @@ elm_main(int argc, char **argv)
ECORE_GETOPT_VALUE_NONE
};
int args, retval = EXIT_SUCCESS;
Config *config;
Evas_Object *o;
@ -190,6 +191,9 @@ elm_main(int argc, char **argv)
}
config_init();
config = config_load("config");
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
@ -222,13 +226,13 @@ elm_main(int argc, char **argv)
elm_app_data_dir_get(), name);
eina_stringshare_replace(&(config->theme), path);
config_tmp = EINA_TRUE;
config->temporary = EINA_TRUE;
}
if (background)
{
eina_stringshare_replace(&(config->background), background);
config_tmp = EINA_TRUE;
config->temporary = EINA_TRUE;
}
if (video_module)
@ -243,13 +247,13 @@ elm_main(int argc, char **argv)
if (i == EINA_C_ARRAY_LENGTH(emotion_choices))
i = 0; /* ecore getopt shouldn't let this happen, but... */
config->vidmod = i;
config_tmp = EINA_TRUE;
config->temporary = EINA_TRUE;
}
if (video_mute != 0xff)
{
config->mute = video_mute;
config_tmp = EINA_TRUE;
config->temporary = EINA_TRUE;
}
win = tg_win_add();
@ -257,11 +261,12 @@ elm_main(int argc, char **argv)
bg = o = edje_object_add(evas_object_evas_get(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);
edje_object_file_set(o, config->theme, "terminology/background");
edje_object_file_set(o, config_theme_path_get(config),
"terminology/background");
elm_win_resize_object_add(win, o);
evas_object_show(o);
term = o = termio_add(win, cmd, 80, 24);
term = o = termio_add(win, config, cmd, 80, 24);
termio_win_set(o, 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);
@ -272,8 +277,8 @@ elm_main(int argc, char **argv)
evas_object_smart_callback_add(o, "change", _cb_change, NULL);
evas_object_show(o);
main_trans_update();
main_media_update();
main_trans_update(config);
main_media_update(config);
evas_object_smart_callback_add(win, "focus,in", _cb_focus_in, term);
evas_object_smart_callback_add(win, "focus,out", _cb_focus_out, term);
@ -283,6 +288,8 @@ elm_main(int argc, char **argv)
elm_run();
end:
config_del(config);
config_shutdown();
eina_log_domain_unregister(_log_domain);

View File

@ -1,3 +1,10 @@
void main_trans_update(void);
void main_media_update(void);
void main_media_mute_update(void);
#ifndef _MAIN_H__
#define _MAIN_H__ 1
#include "config.h"
void main_trans_update(const Config *config);
void main_media_update(const Config *config);
void main_media_mute_update(const Config *config);
#endif

View File

@ -14,6 +14,7 @@ struct _Media
Ecore_Timer *anim;
Ecore_Job *restart_job;
const char *src;
const Config *config;
int iw, ih;
int sw, sh;
int fr, frnum;
@ -378,9 +379,9 @@ _type_mov_init(Evas_Object *obj)
sd->type = TYPE_MOV;
emotion_init();
o = sd->o_img = emotion_object_add(evas_object_evas_get(obj));
if ((config->vidmod >= 0) &&
(config->vidmod < (int)EINA_C_ARRAY_LENGTH(modules)))
mod = modules[config->vidmod];
if ((sd->config->vidmod >= 0) &&
(sd->config->vidmod < (int)EINA_C_ARRAY_LENGTH(modules)))
mod = modules[sd->config->vidmod];
if (!emotion_object_init(o, mod))
{
ERR("can't init emotion module '%s'", mod);
@ -405,7 +406,7 @@ _type_mov_init(Evas_Object *obj)
evas_object_clip_set(o, sd->clip);
emotion_object_position_set(o, 0.0);
emotion_object_play_set(o, EINA_TRUE);
if (config->mute) emotion_object_audio_mute_set(o, EINA_TRUE);
if (sd->config->mute) emotion_object_audio_mute_set(o, EINA_TRUE);
}
static void
@ -538,7 +539,7 @@ _smart_init(void)
}
Evas_Object *
media_add(Evas_Object *parent, const char *src, int mode, int *type)
media_add(Evas_Object *parent, const char *src, const Config *config, int mode, int *type)
{
Evas *e;
Evas_Object *obj;
@ -552,8 +553,9 @@ media_add(Evas_Object *parent, const char *src, int mode, int *type)
obj = evas_object_smart_add(e, _smart);
sd = evas_object_smart_data_get(obj);
if (!sd) return obj;
sd->src = eina_stringshare_add(src);
sd->config = config;
sd->mode = mode;
if (_is_fmt(src, extn_img))
{

View File

@ -1,3 +1,6 @@
#ifndef _MEDIA_H__
#define _MEDIA_H__ 1
#define MEDIA_BG 0
#define TYPE_IMG 0
@ -5,5 +8,9 @@
#define TYPE_EDJE 2
#define TYPE_MOV 3
Evas_Object *media_add(Evas_Object *parent, const char *src, int mode, int *type);
#include "config.h"
Evas_Object *media_add(Evas_Object *parent, const char *src, const Config *config, int mode, int *type);
void media_mute_set(Evas_Object *obj, Eina_Bool mute);
#endif

View File

@ -6,6 +6,7 @@
#include "options_behavior.h"
#include "options_video.h"
#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;
@ -48,9 +49,10 @@ _cb_op_behavior(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
}
static void
_cb_op_tmp_chg(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
_cb_op_tmp_chg(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
config_tmp = elm_check_state_get(obj);
Config *config = data;
config->temporary = elm_check_state_get(obj);
}
static Eina_Bool
@ -72,6 +74,7 @@ options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term)
if (!op_frame)
{
Elm_Object_Item *it_fn, *it_th, *it_wp, *it_bh;
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);
@ -128,10 +131,10 @@ options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term)
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 1.0);
elm_object_text_set(o, "Temporary");
elm_check_state_set(o, config_tmp);
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, NULL);
evas_object_smart_callback_add(o, "changed", _cb_op_tmp_chg, config);
edje_object_part_swallow(bg, "terminology.options", op_frame);
evas_object_show(o);

View File

@ -12,16 +12,20 @@ static Evas_Object *op_sbslider, *op_jumpcheck, *op_wordsep;
static void
_cb_op_behavior_jump_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
config->jump_on_change = elm_check_state_get(obj);
termio_config_update(data);
config_save();
termio_config_update(term);
config_save(config, NULL);
}
static void
_cb_op_behavior_wsep_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
char *txt;
if (config->wordsep)
{
eina_stringshare_del(config->wordsep);
@ -33,21 +37,25 @@ _cb_op_behavior_wsep_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
config->wordsep = eina_stringshare_add(txt);
free(txt);
}
termio_config_update(data);
config_save();
termio_config_update(term);
config_save(config, NULL);
}
static void
_cb_op_behavior_sback_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
config->scrollback = elm_slider_value_get(obj) + 0.5;
termio_config_update(data);
config_save();
termio_config_update(term);
config_save(config, NULL);
}
void
options_behavior(Evas_Object *opbox, Evas_Object *term)
{
Config *config = termio_config_get(term);
Evas_Object *o;
char *txt;

View File

@ -41,25 +41,28 @@ static void
_cb_op_font_sel(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
{
Font *f = data;
Config *config = termio_config_get(f->term);
if ((config->font.name) && (!strcmp(f->name, config->font.name)))
return;
if (config->font.name) eina_stringshare_del(config->font.name);
config->font.name = eina_stringshare_add(f->name);
config->font.bitmap = f->bitmap;
_update_sizing(f->term);
config_save();
config_save(config, NULL);
}
static void
_cb_op_fontsize_sel(void *data, Evas_Object *obj, void *event __UNUSED__)
{
int size = elm_slider_value_get(obj) + 0.5;
Evas_Object *term = data;
Config *config = termio_config_get(term);
int size = elm_slider_value_get(obj) + 0.5;
if (config->font.size == size) return;
config->font.size = size;
_update_sizing(data);
_update_sizing(term);
elm_genlist_realized_items_update(op_fontlist);
config_save();
config_save(config, NULL);
}
static int
@ -84,6 +87,7 @@ _cb_op_font_preview_eval(void *data, Evas *e __UNUSED__, Evas_Object *obj, void
Evas_Object *o;
Evas_Coord ox, oy, ow, oh, vx, vy, vw, vh;
char buf[4096];
Config *config = termio_config_get(f->term);
if (!evas_object_visible_get(obj)) return;
if (edje_object_part_swallow_get(obj, "terminology.content")) return;
@ -116,13 +120,16 @@ static Evas_Object *
_cb_op_font_content_get(void *data, Evas_Object *obj, const char *part)
{
Font *f = data;
Config *config = termio_config_get(f->term);
if ((!strcmp(part, "elm.swallow.icon")) ||
(!strcmp(part, "elm.swallow.end")))
{
Evas_Object *o;
o = edje_object_add(evas_object_evas_get(obj));
edje_object_file_set(o, config->theme, "terminology/fontpreview");
edje_object_file_set(o, config_theme_path_get(config),
"terminology/fontpreview");
evas_object_size_hint_min_set(o,
40 * elm_config_scale_get(),
40 * elm_config_scale_get());
@ -186,6 +193,7 @@ options_font(Evas_Object *opbox, Evas_Object *term)
Font *f;
Elm_Object_Item *it, *sel_it = NULL, *grp_it = NULL;
Elm_Genlist_Item_Class *it_class, *it_group;
Config *config = termio_config_get(term);
options_font_clear();

View File

@ -10,35 +10,42 @@
static Evas_Object *op_trans, *op_mute, *op_vidmod;
static void
_cb_op_video_trans_chg(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
_cb_op_video_trans_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
config->translucent = elm_check_state_get(obj);
main_trans_update();
config_save();
main_trans_update(config);
config_save(config, NULL);
}
static void
_cb_op_video_mute_chg(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
_cb_op_video_mute_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
config->mute = elm_check_state_get(obj);
main_media_mute_update();
config_save();
main_media_mute_update(config);
config_save(config, NULL);
}
static void
_cb_op_video_vidmod_chg(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
_cb_op_video_vidmod_chg(void *data, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
int v = elm_radio_value_get(obj);
if (v == config->vidmod) return;
config->vidmod = v;
main_media_update();
config_save();
main_media_update(config);
config_save(config, NULL);
}
void
options_video(Evas_Object *opbox, Evas_Object *term)
{
Evas_Object *o;
Config *config = termio_config_get(term);
op_trans = o = elm_check_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -48,7 +55,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_trans_chg, NULL);
_cb_op_video_trans_chg, term);
o = elm_separator_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -65,7 +72,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_mute_chg, NULL);
_cb_op_video_mute_chg, term);
o = elm_separator_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);
@ -88,7 +95,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_vidmod_chg, NULL);
_cb_op_video_vidmod_chg, term);
o = elm_radio_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -99,7 +106,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_vidmod_chg, NULL);
_cb_op_video_vidmod_chg, term);
o = elm_radio_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -110,7 +117,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_vidmod_chg, NULL);
_cb_op_video_vidmod_chg, term);
o = elm_radio_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -121,7 +128,7 @@ options_video(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(opbox, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed",
_cb_op_video_vidmod_chg, NULL);
_cb_op_video_vidmod_chg, term);
elm_radio_value_set(o, config->vidmod);

View File

@ -37,11 +37,12 @@ struct _Termio
Ecore_Job *job;
Ecore_Timer *delayed_size_timer;
Evas_Object *win;
Config *config;
Eina_Bool jump_on_change : 1;
};
static Evas_Smart *_smart = NULL;
static Evas_Smart_Class _termio_sc = EVAS_SMART_CLASS_INIT_NULL;
static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
static void _smart_calculate(Evas_Object *obj);
@ -464,7 +465,7 @@ _sel_line(Evas_Object *obj, int cx, int cy)
}
static Eina_Bool
_glyph_is_wordsep(int g)
_glyph_is_wordsep(const Config *config, int g)
{
int i;
@ -499,7 +500,7 @@ _sel_word(Evas_Object *obj, int cx, int cy)
for (x = sd->cur.sel1.x; x >= 0; x--)
{
if (x >= w) break;
if (_glyph_is_wordsep(cells[x].glyph)) break;
if (_glyph_is_wordsep(sd->config, cells[x].glyph)) break;
sd->cur.sel1.x = x;
}
sd->cur.sel2.x = cx;
@ -507,7 +508,7 @@ _sel_word(Evas_Object *obj, int cx, int cy)
for (x = sd->cur.sel2.x; x < sd->grid.w; x++)
{
if (x >= w) break;
if (_glyph_is_wordsep(cells[x].glyph)) break;
if (_glyph_is_wordsep(sd->config, cells[x].glyph)) break;
sd->cur.sel2.x = x;
}
}
@ -633,17 +634,50 @@ _win_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNU
}
}
static void
_termio_config_set(Evas_Object *obj, Config *config)
{
Termio *sd = evas_object_smart_data_get(obj);
Evas_Coord w = 2, h = 2;
sd->config = config;
sd->jump_on_change = config->jump_on_change;
if (config->font.bitmap)
{
char buf[PATH_MAX];
snprintf(buf, sizeof(buf), "%s/fonts/%s",
elm_app_data_dir_get(), config->font.name);
sd->font.name = eina_stringshare_add(buf);
}
else
sd->font.name = eina_stringshare_add(config->font.name);
sd->font.size = config->font.size;
evas_object_textgrid_font_set(sd->grid.obj, sd->font.name, sd->font.size);
evas_object_textgrid_size_set(sd->grid.obj, 1, 1);
evas_object_textgrid_cell_size_get(sd->grid.obj, &w, &h);
if (w < 1) w = 1;
if (h < 1) h = 1;
sd->font.chw = w;
sd->font.chh = h;
edje_object_file_set(sd->cur.obj,
config_theme_path_get(config), "terminology/cursor");
evas_object_resize(sd->cur.obj, sd->font.chw, sd->font.chh);
evas_object_show(sd->cur.obj);
}
static void
_smart_add(Evas_Object *obj)
{
Termio *sd;
Evas_Object_Smart_Clipped_Data *cd;
Evas_Object *o;
Evas_Coord w = 2, h = 2;
char buf[4096];
int i, j, k, n;
_termio_sc.add(obj);
_parent_sc.add(obj);
cd = evas_object_smart_data_get(obj);
if (!cd) return;
sd = calloc(1, sizeof(Termio));
@ -652,32 +686,13 @@ _smart_add(Evas_Object *obj)
free(cd);
evas_object_smart_data_set(obj, sd);
sd->jump_on_change = config->jump_on_change;
if (config->font.bitmap)
{
snprintf(buf, sizeof(buf), "%s/fonts/%s",
elm_app_data_dir_get(), config->font.name);
sd->font.name = eina_stringshare_add(buf);
}
else
sd->font.name = eina_stringshare_add(config->font.name);
sd->font.size = config->font.size;
o = evas_object_textgrid_add(evas_object_evas_get(obj));
evas_object_pass_events_set(o, EINA_TRUE);
evas_object_propagate_events_set(o, EINA_FALSE);
evas_object_smart_member_add(o, obj);
evas_object_show(o);
sd->grid.obj = o;
evas_object_textgrid_font_set(o, sd->font.name, sd->font.size);
evas_object_textgrid_size_set(o, 1, 1);
evas_object_textgrid_cell_size_get(o, &w, &h);
if (w < 1) w = 1;
if (h < 1) h = 1;
sd->font.chw = w;
sd->font.chh = h;
for (n = 0, k = 0; k < 2; k++)
{
for (j = 0; j < 2; j++)
@ -720,9 +735,6 @@ _smart_add(Evas_Object *obj)
evas_object_propagate_events_set(o, EINA_FALSE);
evas_object_smart_member_add(o, obj);
sd->cur.obj = o;
edje_object_file_set(o, config->theme, "terminology/cursor");
evas_object_resize(o, sd->font.chw, sd->font.chh);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(obj));
evas_object_smart_member_add(o, obj);
@ -770,7 +782,7 @@ _smart_del(Evas_Object *obj)
sd->delayed_size_timer = NULL;
sd->font.name = NULL;
sd->pty = NULL;
_termio_sc.del(obj);
_parent_sc.del(obj);
evas_object_smart_data_set(obj, NULL);
}
@ -822,8 +834,8 @@ _smart_init(void)
{
static Evas_Smart_Class sc;
evas_object_smart_clipped_smart_set(&_termio_sc);
sc = _termio_sc;
evas_object_smart_clipped_smart_set(&_parent_sc);
sc = _parent_sc;
sc.name = "termio";
sc.version = EVAS_SMART_CLASS_VERSION;
sc.add = _smart_add;
@ -921,7 +933,7 @@ _smart_pty_cancel_sel(void *data)
}
Evas_Object *
termio_add(Evas_Object *parent, const char *cmd, int w, int h)
termio_add(Evas_Object *parent, Config *config, const char *cmd, int w, int h)
{
Evas *e;
Evas_Object *obj;
@ -935,6 +947,9 @@ termio_add(Evas_Object *parent, const char *cmd, int w, int h)
obj = evas_object_smart_add(e, _smart);
sd = evas_object_smart_data_get(obj);
if (!sd) return obj;
_termio_config_set(obj, config);
sd->pty = termpty_new(cmd, w, h, config->scrollback);
sd->pty->cb.change.func = _smart_pty_change;
sd->pty->cb.change.data = obj;
@ -1063,19 +1078,19 @@ termio_config_update(Evas_Object *obj)
if (sd->font.name) eina_stringshare_del(sd->font.name);
sd->font.name = NULL;
if (config->font.bitmap)
if (sd->config->font.bitmap)
{
snprintf(buf, sizeof(buf), "%s/fonts/%s",
elm_app_data_dir_get(), config->font.name);
elm_app_data_dir_get(), sd->config->font.name);
sd->font.name = eina_stringshare_add(buf);
}
else
sd->font.name = eina_stringshare_add(config->font.name);
sd->font.size = config->font.size;
sd->font.name = eina_stringshare_add(sd->config->font.name);
sd->font.size = sd->config->font.size;
sd->jump_on_change = config->jump_on_change;
sd->jump_on_change = sd->config->jump_on_change;
termpty_backscroll_set(sd->pty, config->scrollback);
termpty_backscroll_set(sd->pty, sd->config->scrollback);
sd->scroll = 0;
evas_object_textgrid_font_set(sd->grid.obj, sd->font.name, sd->font.size);
@ -1086,3 +1101,11 @@ termio_config_update(Evas_Object *obj)
sd->font.chh = h;
_smart_size(obj, sd->grid.w, sd->grid.h, EINA_TRUE);
}
Config *
termio_config_get(const Evas_Object *obj)
{
Termio *sd = evas_object_smart_data_get(obj);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
return sd->config;
}

View File

@ -1,4 +1,12 @@
Evas_Object *termio_add(Evas_Object *parent, const char *cmd, int w, int h);
#ifndef _TERMIO_H__
#define _TERMIO_H__ 1
#include "config.h"
Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, int w, int h);
void termio_win_set(Evas_Object *obj, Evas_Object *win);
char *termio_selection_get(Evas_Object *obj, int c1x, int c1y, int c2x, int c2y);
void termio_config_update(Evas_Object *obj);
Config *termio_config_get(const Evas_Object *obj);
#endif