add wizard to set scaling when config does not exist

terminology-1.6
Boris Faure 3 years ago
parent 48a8a93900
commit 67805411a4
  1. 19
      src/bin/main.c
  2. 30
      src/bin/utils.c
  3. 1
      src/bin/utils.h
  4. 144
      src/bin/win.c
  5. 1
      src/bin/win.h

@ -94,10 +94,10 @@ main_ipc_new(Ipc_Instance *inst)
if (inst->xterm_256color) nargc += 1;
if (inst->active_links) nargc += 1;
if (inst->cmd) nargc += 2;
nargv = calloc(nargc + 1, sizeof(char *));
if (!nargv) return;
i = 0;
nargv[i++] = pargv[0];
if (inst->cd)
@ -261,13 +261,13 @@ main_ipc_new(Ipc_Instance *inst)
{
char *fname = alloca(strlen(inst->font) + 1);
char *p;
strcpy(fname, inst->font);
p = strrchr(fname, '/');
if (p)
{
int sz;
*p = 0;
p++;
sz = atoi(p);
@ -281,7 +281,7 @@ main_ipc_new(Ipc_Instance *inst)
char buf[4096], *file;
Eina_List *files;
int n = strlen(inst->font);
snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get());
files = ecore_file_ls(buf);
EINA_LIST_FREE(files, file)
@ -809,7 +809,7 @@ elm_main(int argc, char **argv)
pos_set = 1;
}
}
if (!size_set)
{
if (config->custom_geometry)
@ -839,9 +839,9 @@ remote:
{
Ipc_Instance inst;
char cwdbuf[4096];
memset(&inst, 0, sizeof(Ipc_Instance));
inst.cmd = cmd;
if (cd) inst.cd = cd;
else inst.cd = getcwd(cwdbuf, sizeof(cwdbuf));
@ -970,6 +970,9 @@ remote:
ecore_con_url_init();
controls_init();
win_scale_wizard(win, term);
terminology_starting_up = EINA_FALSE;
elm_run();

@ -144,6 +144,36 @@ homedir_get(char *buf, size_t size)
return eina_strlcpy(buf, home, size) < size;
}
Eina_Bool
utils_need_scale_wizard(void)
{
static char path[PATH_MAX] = "";
struct stat st;
int res;
char *tmp;
Eina_Bool use_xdg_config;
snprintf(path, sizeof(path) -1, "%s/terminology/config/",
efreet_config_home_get());
res = stat(path, &st);
if (res == 0)
return EINA_FALSE;
use_xdg_config = (getenv("ELM_CONFIG_DIR_XDG") != NULL);
if (use_xdg_config)
tmp = eina_vpath_resolve("(:usr.config:)/elementary");
else
tmp = eina_vpath_resolve("(:home:)/" ".elementary");
res = stat(tmp, &st);
free(tmp);
if (res == 0)
return EINA_FALSE;
return EINA_TRUE;
}
Eina_Bool
link_is_protocol(const char *str)
{

@ -12,6 +12,7 @@ void theme_auto_reload_enable(Evas_Object *edje);
const char *theme_path_get(const char *name);
Eina_Bool homedir_get(char *buf, size_t size);
Eina_Bool utils_need_scale_wizard(void);
Eina_Bool link_is_protocol(const char *str);
Eina_Bool link_is_url(const char *str);

@ -199,6 +199,150 @@ static void _term_tabregion_free(Term *term);
static void _set_trans(Config *config, Evas_Object *bg, Evas_Object *base);
static void _imf_event_commit_cb(void *data, Ecore_IMF_Context *_ctx EINA_UNUSED, void *event);
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 _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, NULL);
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);
if (!utils_need_scale_wizard())
return;
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);
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 prefered size so that is text is readable"));
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_box_pack_end(bx, lbl);
evas_object_show(lbl);
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);
evas_object_show(ctx->hv);
elm_object_focus_set(ctx->hv, EINA_TRUE);
}
/* {{{ Solo */

@ -50,6 +50,7 @@ void win_toggle_visible_group(Win *wn);
void win_toggle_all_group(Win *wn);
Eina_Bool win_is_group_action_handled(Win *wn);
Eina_Bool win_is_group_input(Win *wn);
void win_scale_wizard(Evas_Object *win, Term *term);
void term_ref(Term *term);

Loading…
Cancel
Save