aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/options.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-01-05 00:16:14 +0100
committerBoris Faure <billiob@gmail.com>2018-01-05 00:27:25 +0100
commitfd150de2226bdde9d9bba6a50721492ea6a93316 (patch)
tree616cf82e9e45f52cb893de5ca6c166c90ee1d473 /src/bin/options.c
parentabout: simplify code and no more globals (diff)
downloadterminology-fd150de2226bdde9d9bba6a50721492ea6a93316.tar.gz
options: simplify code and no more globals
Diffstat (limited to 'src/bin/options.c')
-rw-r--r--src/bin/options.c377
1 files changed, 198 insertions, 179 deletions
diff --git a/src/bin/options.c b/src/bin/options.c
index 381a22d..c4ee74c 100644
--- a/src/bin/options.c
+++ b/src/bin/options.c
@@ -1,6 +1,7 @@
#include "private.h"
#include <Elementary.h>
+#include <assert.h>
#include "options.h"
#include "options_font.h"
#include "options_theme.h"
@@ -14,17 +15,8 @@
#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,
- *op_over = NULL;
-static Eina_Bool op_out = EINA_FALSE;
-static Ecore_Timer *op_del_timer = NULL;
-static Evas_Object *saved_win = NULL;
-static Evas_Object *saved_bg = NULL;
-static void (*op_donecb) (void *data) = NULL;
-static void *op_donedata = NULL;
-
-static enum option_mode {
+
+enum option_mode {
OPTION_NONE = 0,
OPTION_FONT,
OPTION_THEME,
@@ -34,229 +26,256 @@ static enum option_mode {
OPTION_BEHAVIOR,
OPTION_KEYS,
OPTION_HELPERS,
- OPTION_ELM
-} _mode = 0;
+ OPTION_ELM,
+
+ OPTIONS_MODE_NB
+};
+
+struct options_ctx {
+ enum option_mode mode;
+ Evas_Object *frame;
+ Evas_Object *toolbar;
+ Evas_Object *opbox;
+ Evas_Object *over;
+ Evas_Object *win;
+ Evas_Object *bg;
+ Evas_Object *term;
+ Config *config;
+ void (*donecb) (void *data);
+ void *donedata;
+ struct options_ctx *modes[OPTIONS_MODE_NB];
+};
static void
_cb_op(void *data,
Evas_Object *_obj EINA_UNUSED,
void *_event EINA_UNUSED)
{
- enum option_mode mode = (intptr_t) data;
+ struct options_ctx **pctx = data;
+ struct options_ctx *ctx = *pctx;
+ enum option_mode mode = pctx - ctx->modes;
+
+ if (mode == ctx->mode)
+ return;
- if (_mode == mode) return;
- _mode = mode;
- edje_object_signal_emit(saved_bg, "optdetails,hide", "terminology");
+ ctx->mode = mode;
+
+ edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology");
}
static void
_cb_op_tmp_chg(void *data, Evas_Object *obj, void *_event EINA_UNUSED)
{
- Config *config = data;
+ struct options_ctx *ctx = data;
+ Config *config = ctx->config;
+
config->temporary = elm_check_state_get(obj);
}
static Eina_Bool
-_cb_op_del_delay(void *_data EINA_UNUSED)
+_cb_op_del_delay(void *data)
{
- evas_object_del(op_opbox);
- evas_object_del(op_frame);
+ struct options_ctx *ctx = data;
+
+ evas_object_del(ctx->opbox);
+ evas_object_del(ctx->frame);
options_font_clear();
options_background_clear();
options_theme_clear();
- op_opbox = NULL;
- op_frame = NULL;
- op_del_timer = NULL;
+
+ free(ctx);
elm_cache_all_flush();
return EINA_FALSE;
}
static void
-_cb_mouse_down(void *data,
- Evas *_e EINA_UNUSED,
- Evas_Object *_obj EINA_UNUSED,
- void *_ev EINA_UNUSED)
-{
- options_toggle(saved_win, saved_bg, data, op_donecb, op_donedata);
-}
-
-static void
_cb_opdt_hide_done(void *data,
Evas_Object *_obj EINA_UNUSED,
const char *_sig EINA_UNUSED,
const char *_src EINA_UNUSED)
{
- elm_box_clear(op_opbox);
- switch (_mode)
+ struct options_ctx *ctx = data;
+
+ elm_box_clear(ctx->opbox);
+ switch (ctx->mode)
{
case OPTION_NONE: break;
- case OPTION_FONT: options_font(op_opbox, data); break;
- case OPTION_THEME: options_theme(op_opbox, data); break;
- case OPTION_BACKGROUND: options_background(op_opbox, data); break;
- case OPTION_COLORS: options_colors(op_opbox, data); break;
- case OPTION_VIDEO: options_video(op_opbox, data); break;
- case OPTION_BEHAVIOR: options_behavior(op_opbox, data); break;
- case OPTION_KEYS: options_keys(op_opbox, data); break;
- case OPTION_HELPERS: options_helpers(op_opbox, data); break;
- case OPTION_ELM: options_elm(op_opbox, data); break;
+ case OPTION_FONT: options_font(ctx->opbox, ctx->term); break;
+ case OPTION_THEME: options_theme(ctx->opbox, ctx->term); break;
+ case OPTION_BACKGROUND: options_background(ctx->opbox, ctx->term); break;
+ case OPTION_COLORS: options_colors(ctx->opbox, ctx->term); break;
+ case OPTION_VIDEO: options_video(ctx->opbox, ctx->term); break;
+ case OPTION_BEHAVIOR: options_behavior(ctx->opbox, ctx->term); break;
+ case OPTION_KEYS: options_keys(ctx->opbox, ctx->term); break;
+ case OPTION_HELPERS: options_helpers(ctx->opbox, ctx->term); break;
+ case OPTION_ELM: options_elm(ctx->opbox, ctx->term); break;
+ case OPTIONS_MODE_NB: assert(0 && "should not occur");
}
- edje_object_signal_emit(saved_bg, "optdetails,show", "terminology");
+ edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology");
}
static void
-_cb_opdt_hide_done2(void *_data EINA_UNUSED,
+_cb_opdt_hide_done2(void *data,
Evas_Object *_obj EINA_UNUSED,
const char *_sig EINA_UNUSED,
const char *_src EINA_UNUSED)
{
- if (op_del_timer)
- {
- ecore_timer_del(op_del_timer);
- op_del_timer = NULL;
- }
- _cb_op_del_delay(NULL);
- edje_object_signal_callback_del(saved_bg, "optdetails,hide,done",
+ struct options_ctx *ctx = data;
+
+ edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done",
"terminology",
_cb_opdt_hide_done2);
+ ecore_timer_add(10.0, _cb_op_del_delay, ctx);
+}
+
+static void
+options_hide(struct options_ctx *ctx)
+{
+ edje_object_part_swallow(ctx->bg, "terminology.optdetails", ctx->opbox);
+ edje_object_part_swallow(ctx->bg, "terminology.options", ctx->frame);
+ edje_object_signal_emit(ctx->bg, "optdetails,show", "terminology");
+ edje_object_signal_emit(ctx->bg, "options,show", "terminology");
+
+ edje_object_signal_callback_del(ctx->bg, "optdetails,hide,done",
+ "terminology",
+ _cb_opdt_hide_done);
+ edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done",
+ "terminology",
+ _cb_opdt_hide_done2, ctx);
+ elm_object_focus_set(ctx->frame, EINA_FALSE);
+ elm_object_focus_set(ctx->opbox, EINA_FALSE);
+ elm_object_focus_set(ctx->toolbar, EINA_FALSE);
+
+ evas_object_del(ctx->over);
+ ctx->over = NULL;
+
+ edje_object_signal_emit(ctx->bg, "options,hide", "terminology");
+ edje_object_signal_emit(ctx->bg, "optdetails,hide", "terminology");
+
+ if (ctx->donecb)
+ ctx->donecb(ctx->donedata);
+}
+
+static void
+_cb_mouse_down(void *data,
+ Evas *_e EINA_UNUSED,
+ Evas_Object *_obj EINA_UNUSED,
+ void *_ev EINA_UNUSED)
+{
+ struct options_ctx *ctx = data;
+
+ options_hide(ctx);
}
+
void
-options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
+options_show(Evas_Object *win, Evas_Object *bg, Evas_Object *term,
void (*donecb) (void *data), void *donedata)
{
- Evas_Object *o;
+ Evas_Object *o, *op_box, *op_tbox;
+ struct options_ctx *ctx;
+ int i = 0;
- _mode = OPTION_NONE;
- if (!op_frame)
- {
- Elm_Object_Item *it_fn;
- Config *config = termio_config_get(term);
-
- if (!config) return;
- saved_win = win;
- saved_bg = bg;
-
- op_opbox = o = elm_box_add(win);
- evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
- edje_object_part_swallow(bg, "terminology.optdetails", o);
- evas_object_show(o);
-
- op_frame = o = elm_frame_add(win);
- evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_text_set(o, _("Options"));
-
- op_box = o = elm_box_add(win);
- elm_box_horizontal_set(o, EINA_TRUE);
- elm_object_content_set(op_frame, o);
- evas_object_show(o);
-
- op_tbox = o = elm_box_add(win);
- evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(o, 1.0, EVAS_HINT_FILL);
- elm_box_pack_end(op_box, o);
- evas_object_show(o);
-
- op_toolbar = o = elm_toolbar_add(win);
- evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL);
- elm_toolbar_horizontal_set(o, EINA_FALSE);
- elm_object_style_set(o, "item_horizontal");
- elm_toolbar_icon_size_set(o, 16 * elm_config_scale_get());
- elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL);
- elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS);
- elm_toolbar_menu_parent_set(o, win);
- elm_toolbar_homogeneous_set(o, EINA_FALSE);
+ Elm_Object_Item *it_fn;
+ Config *config = termio_config_get(term);
+
+ if (!config) return;
+
+ ctx = malloc(sizeof(*ctx));
+ assert(ctx);
+ ctx->mode = OPTION_NONE;
+ ctx->win = win;
+ ctx->bg = bg;
+ ctx->term = term;
+ ctx->donecb = donecb;
+ ctx->donedata = donedata;
+ ctx->config = config;
+
+ for (i = 0; i < OPTIONS_MODE_NB; i++)
+ ctx->modes[i] = ctx;
+
+ ctx->opbox = o = elm_box_add(win);
+ evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ edje_object_part_swallow(ctx->bg, "terminology.optdetails", o);
+ evas_object_show(o);
+
+ ctx->frame = o = elm_frame_add(win);
+ evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_text_set(o, _("Options"));
+
+ op_box = o = elm_box_add(win);
+ elm_box_horizontal_set(o, EINA_TRUE);
+ elm_object_content_set(ctx->frame, o);
+ evas_object_show(o);
+
+ op_tbox = o = elm_box_add(win);
+ evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(o, 1.0, EVAS_HINT_FILL);
+ elm_box_pack_end(op_box, o);
+ evas_object_show(o);
+
+ ctx->toolbar = o = elm_toolbar_add(win);
+ evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(o, 0.5, EVAS_HINT_FILL);
+ elm_toolbar_horizontal_set(o, EINA_FALSE);
+ elm_object_style_set(o, "item_horizontal");
+ elm_toolbar_icon_size_set(o, 16 * elm_config_scale_get());
+ elm_toolbar_shrink_mode_set(o, ELM_TOOLBAR_SHRINK_SCROLL);
+ elm_toolbar_select_mode_set(o, ELM_OBJECT_SELECT_MODE_ALWAYS);
+ elm_toolbar_menu_parent_set(o, win);
+ elm_toolbar_homogeneous_set(o, EINA_FALSE);
#define ITEM_APPEND(_icon_name, _name, _option_mode) \
- elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \
- (void*) OPTION_##_option_mode)
-
- it_fn =
- ITEM_APPEND("preferences-desktop-font", _("Font"), FONT);
- ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME);
- ITEM_APPEND("preferences-desktop-background", _("Background"), BACKGROUND);
- ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS);
- ITEM_APPEND("video-display", _("Video"), VIDEO);
- ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR);
- ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS);
- ITEM_APPEND("system-run", _("Helpers"), HELPERS);
- ITEM_APPEND("preferences-color", _("Toolkit"), ELM);
+ elm_toolbar_item_append(o, _icon_name, _name, _cb_op, \
+ (void*) &ctx->modes[OPTION_##_option_mode])
+
+ it_fn =
+ ITEM_APPEND("preferences-desktop-font", _("Font"), FONT);
+ ITEM_APPEND("preferences-desktop-theme", _("Theme"), THEME);
+ ITEM_APPEND("preferences-desktop-background", _("Background"), BACKGROUND);
+ ITEM_APPEND("preferences-desktop-theme", _("Colors"), COLORS);
+ ITEM_APPEND("video-display", _("Video"), VIDEO);
+ ITEM_APPEND("preferences-system", _("Behavior"), BEHAVIOR);
+ ITEM_APPEND("preferences-desktop-keyboard-shortcuts", _("Keys"), KEYS);
+ ITEM_APPEND("system-run", _("Helpers"), HELPERS);
+ ITEM_APPEND("preferences-color", _("Toolkit"), ELM);
#undef ITEM_APPEND
- elm_box_pack_end(op_tbox, o);
- evas_object_show(o);
-
- elm_toolbar_item_selected_set(it_fn, EINA_TRUE);
-
- op_temp = o = elm_check_add(win);
- evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
- evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 1.0);
- elm_object_text_set(o, _("Temporary"));
- 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, config);
-
- edje_object_part_swallow(bg, "terminology.options", op_frame);
- evas_object_show(op_frame);
- }
- else if ((op_opbox) && (!op_out))
- {
- edje_object_part_swallow(bg, "terminology.optdetails", op_opbox);
- edje_object_part_swallow(bg, "terminology.options", op_frame);
- edje_object_signal_emit(bg, "optdetails,show", "terminology");
- edje_object_signal_emit(bg, "options,show", "terminology");
- }
-
- if (!op_out)
- {
- edje_object_signal_callback_add(bg, "optdetails,hide,done",
- "terminology",
- _cb_opdt_hide_done, term);
- op_over = o = evas_object_rectangle_add(evas_object_evas_get(win));
- evas_object_color_set(o, 0, 0, 0, 0);
- edje_object_part_swallow(bg, "terminology.dismiss", o);
- evas_object_show(o);
- evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
- _cb_mouse_down, term);
-
- edje_object_signal_emit(bg, "options,show", "terminology");
- op_out = EINA_TRUE;
- op_donecb = donecb;
- op_donedata = donedata;
- elm_object_focus_set(op_toolbar, EINA_TRUE);
- if (op_del_timer)
- {
- ecore_timer_del(op_del_timer);
- op_del_timer = NULL;
- }
- }
- else
- {
- edje_object_signal_callback_del(bg, "optdetails,hide,done",
- "terminology",
- _cb_opdt_hide_done);
- edje_object_signal_callback_add(bg, "optdetails,hide,done",
- "terminology",
- _cb_opdt_hide_done2, term);
- elm_object_focus_set(op_frame, EINA_FALSE);
- elm_object_focus_set(op_opbox, EINA_FALSE);
- elm_object_focus_set(op_toolbar, EINA_FALSE);
- if (op_donecb) op_donecb(op_donedata);
- evas_object_del(op_over);
- op_over = NULL;
- edje_object_signal_emit(bg, "options,hide", "terminology");
- edje_object_signal_emit(bg, "optdetails,hide", "terminology");
- op_out = EINA_FALSE;
- if (op_del_timer) ecore_timer_del(op_del_timer);
- op_del_timer = ecore_timer_add(10.0, _cb_op_del_delay, NULL);
- }
+ elm_box_pack_end(op_tbox, o);
+ evas_object_show(o);
+
+ elm_toolbar_item_selected_set(it_fn, EINA_TRUE);
+
+ o = elm_check_add(win);
+ evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
+ evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 1.0);
+ elm_object_text_set(o, _("Temporary"));
+ 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, ctx);
+
+ edje_object_part_swallow(bg, "terminology.options", ctx->frame);
+ evas_object_show(ctx->frame);
+
+ edje_object_signal_callback_add(ctx->bg, "optdetails,hide,done",
+ "terminology",
+ _cb_opdt_hide_done, ctx);
+ ctx->over = o = evas_object_rectangle_add(evas_object_evas_get(win));
+ evas_object_color_set(o, 0, 0, 0, 0);
+ edje_object_part_swallow(ctx->bg, "terminology.dismiss", o);
+ evas_object_show(o);
+ evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
+ _cb_mouse_down, ctx);
+
+ edje_object_signal_emit(ctx->bg, "options,show", "terminology");
+ elm_object_focus_set(ctx->toolbar, EINA_TRUE);
}
Eina_Bool
options_is_active(Evas_Object *win EINA_UNUSED)
{
- return op_out;
+ return EINA_FALSE;
}