handle textgrid font size changes properly
save and load config now (font size/font changes stick now) SVN revision: 72216
This commit is contained in:
parent
7443e137c4
commit
776e0b2e96
115
src/bin/config.c
115
src/bin/config.c
|
@ -1,26 +1,117 @@
|
||||||
#include <Elementary.h>
|
#include <Elementary.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#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;
|
Config *config = NULL;
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
_homedir(void)
|
||||||
|
{
|
||||||
|
const char *home;
|
||||||
|
|
||||||
|
home = getenv("HOME");
|
||||||
|
if (!home) home = getenv("TMP");
|
||||||
|
if (!home) home = "/tmp";
|
||||||
|
return home;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
config_init(void)
|
config_init(void)
|
||||||
{
|
{
|
||||||
// XXX: need to load config and only if not found use this
|
Eet_Data_Descriptor_Class eddc;
|
||||||
config = calloc(1, sizeof(Config));
|
Eet_File *ef;
|
||||||
// config->font.bitmap = 0;
|
char buf[4096], *home;
|
||||||
// config->font.name = eina_stringshare_add("Monospace");
|
|
||||||
config->font.bitmap = 1;
|
eet_eina_stream_data_descriptor_class_set
|
||||||
config->font.name = eina_stringshare_add("nex6x10.pcf");
|
(&eddc, sizeof(eddc), "Config", sizeof(Config));
|
||||||
config->font.size = 10;
|
edd_base = eet_data_descriptor_stream_new(&eddc);
|
||||||
config->scrollback = 4096;
|
|
||||||
config->theme = "default.edj";
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
config->jump_on_change = 1;
|
(edd_base, Config, "font.name", font.name, EET_T_STRING);
|
||||||
config->wordsep = "'\"()[]{}=*!#$^\\:;,?` ";
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "font.size", font.size, EET_T_INT);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "font.bitmap", font.bitmap, EET_T_UCHAR);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "scrollback", scrollback, EET_T_INT);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "theme", theme, EET_T_STRING);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "background", background, EET_T_STRING);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "jump_on_change", jump_on_change, EET_T_UCHAR);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "translucent", translucent, EET_T_UCHAR);
|
||||||
|
EET_DATA_DESCRIPTOR_ADD_BASIC
|
||||||
|
(edd_base, Config, "wordsep", wordsep, EET_T_STRING);
|
||||||
|
|
||||||
|
home = (char *)_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");
|
||||||
|
eet_close(ef);
|
||||||
|
if (config)
|
||||||
|
{
|
||||||
|
LIM(config->font.size, 3, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!config)
|
||||||
|
{
|
||||||
|
config = calloc(1, sizeof(Config));
|
||||||
|
// config->font.bitmap = 0;
|
||||||
|
// config->font.name = eina_stringshare_add("Monospace");
|
||||||
|
config->font.bitmap = 1;
|
||||||
|
config->font.name = eina_stringshare_add("nex6x10.pcf");
|
||||||
|
config->font.size = 10;
|
||||||
|
config->scrollback = 4096;
|
||||||
|
config->theme = eina_stringshare_add("default.edj");
|
||||||
|
config->background = NULL;
|
||||||
|
config->translucent = 0;
|
||||||
|
config->jump_on_change = 1;
|
||||||
|
config->wordsep = eina_stringshare_add("'\"()[]{}=*!#$^\\:;,?` ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
config_shutdown(void)
|
config_shutdown(void)
|
||||||
{
|
{
|
||||||
// XXX: free 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
config_save(void)
|
||||||
|
{
|
||||||
|
Eet_File *ef;
|
||||||
|
char buf[4096], buf2[4096], *home;
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ struct _Config
|
||||||
} font;
|
} font;
|
||||||
int scrollback;
|
int scrollback;
|
||||||
const char *theme;
|
const char *theme;
|
||||||
|
const char *background;
|
||||||
unsigned char jump_on_change;
|
unsigned char jump_on_change;
|
||||||
|
unsigned char translucent;
|
||||||
const char *wordsep;
|
const char *wordsep;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,4 +19,4 @@ extern Config *config;
|
||||||
|
|
||||||
void config_init(void);
|
void config_init(void);
|
||||||
void config_shutdown(void);
|
void config_shutdown(void);
|
||||||
|
void config_save(void);
|
||||||
|
|
|
@ -97,8 +97,8 @@ elm_main(int argc, char **argv)
|
||||||
evas_object_show(win);
|
evas_object_show(win);
|
||||||
|
|
||||||
elm_run();
|
elm_run();
|
||||||
elm_shutdown();
|
|
||||||
config_shutdown();
|
config_shutdown();
|
||||||
|
elm_shutdown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ELM_MAIN()
|
ELM_MAIN()
|
||||||
|
|
|
@ -45,6 +45,7 @@ _cb_op_font_sel(void *data, Evas_Object *obj, void *event)
|
||||||
config->font.name = eina_stringshare_add(f->name);
|
config->font.name = eina_stringshare_add(f->name);
|
||||||
config->font.bitmap = f->bitmap;
|
config->font.bitmap = f->bitmap;
|
||||||
_update_sizing(f->term);
|
_update_sizing(f->term);
|
||||||
|
config_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -55,6 +56,7 @@ _cb_op_fontsize_sel(void *data, Evas_Object *obj, void *event)
|
||||||
if (config->font.size == size) return;
|
if (config->font.size == size) return;
|
||||||
config->font.size = size;
|
config->font.size = size;
|
||||||
_update_sizing(data);
|
_update_sizing(data);
|
||||||
|
config_save();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -791,7 +791,7 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
|
||||||
if ((ow == w) && (oh == h)) return;
|
if ((ow == w) && (oh == h)) return;
|
||||||
evas_object_smart_changed(obj);
|
evas_object_smart_changed(obj);
|
||||||
if (sd->delayed_size_timer) ecore_timer_del(sd->delayed_size_timer);
|
if (sd->delayed_size_timer) ecore_timer_del(sd->delayed_size_timer);
|
||||||
sd->delayed_size_timer = ecore_timer_add(0.02, _smart_cb_delayed_size, obj);
|
sd->delayed_size_timer = ecore_timer_add(0.0, _smart_cb_delayed_size, obj);
|
||||||
evas_object_resize(sd->event, ow, oh);
|
evas_object_resize(sd->event, ow, oh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,7 +1061,6 @@ void
|
||||||
termio_config_update(Evas_Object *obj)
|
termio_config_update(Evas_Object *obj)
|
||||||
{
|
{
|
||||||
Termio *sd = evas_object_smart_data_get(obj);
|
Termio *sd = evas_object_smart_data_get(obj);
|
||||||
Evas_Object *o;
|
|
||||||
Evas_Coord w, h;
|
Evas_Coord w, h;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
|
@ -1080,11 +1079,8 @@ termio_config_update(Evas_Object *obj)
|
||||||
sd->font.name = eina_stringshare_add(config->font.name);
|
sd->font.name = eina_stringshare_add(config->font.name);
|
||||||
sd->font.size = config->font.size;
|
sd->font.size = config->font.size;
|
||||||
|
|
||||||
o = evas_object_text_add(evas_object_evas_get(obj));
|
evas_object_textgrid_font_set(sd->grid.obj, sd->font.name, sd->font.size);
|
||||||
evas_object_text_font_set(o, sd->font.name, sd->font.size);
|
evas_object_textgrid_cell_size_get(sd->grid.obj, &w, &h);
|
||||||
evas_object_text_text_set(o, "X");
|
|
||||||
evas_object_geometry_get(o, NULL, NULL, &w, &h);
|
|
||||||
evas_object_del(o);
|
|
||||||
if (w < 1) w = 1;
|
if (w < 1) w = 1;
|
||||||
if (h < 1) h = 1;
|
if (h < 1) h = 1;
|
||||||
sd->font.chw = w;
|
sd->font.chw = w;
|
||||||
|
|
Loading…
Reference in New Issue