From a684b21b577c4f7e8e638fdd5ad99e8d647c86d7 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Tue, 14 Aug 2012 12:30:55 +0000 Subject: [PATCH] add some infra for cmd-mode for terminology. only 1 working cmd atm "f" (font changes) SVN revision: 75254 --- README | 1 + TODO | 4 +- data/themes/default.edc | 68 ++++++++++++++++++++++++++++ src/bin/Makefile.am | 1 + src/bin/config.c | 13 +++++- src/bin/config.h | 5 ++- src/bin/main.c | 99 +++++++++++++++++++++++++++++++++++++++-- src/bin/termcmd.c | 88 ++++++++++++++++++++++++++++++++++++ src/bin/termcmd.h | 9 ++++ src/bin/termio.c | 14 ++++++ src/bin/termio.h | 1 + 11 files changed, 293 insertions(+), 10 deletions(-) create mode 100644 src/bin/termcmd.c create mode 100644 src/bin/termcmd.h diff --git a/README b/README index c84f953a..7c3aa009 100644 --- a/README +++ b/README @@ -52,6 +52,7 @@ Shift+Keypad-Plus = Font size up 1 Shift+Keypad-Minus = Font size down 1 Shift+Keypad-Multiply = Reset font size to 10 Shift+Keypad-Divide = Copy highlight to Clipboard (same as ctrl+c in gui apps) +Alt+backtick(grave) = Enter command mode Mouse controls: diff --git a/TODO b/TODO index bb20c3f3..1cef35e3 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,9 @@ here's a short list of things i think we can do in the short to medium term to make it a first-class terminal: -[ ] finish off remote http fetch code for media -[ ] filenames is `xxx' quotes not recognized (as ` different to ') [ ] blink and blink2 attributes need to be supported [ ] dnd text (to/from terminal) +[ ] dnd file uri's too as text etc. [ ] general input mode handling improvements (keypad, other key input, etc.) [ ] selection of themes @@ -18,7 +17,6 @@ make it a first-class terminal: on_hold flags, etc.) [ ] selection off edge scrolls in that direction (as per selection mode too if it gets NEAR an edge) -[ ] selection should become single edje object so it can be styled nicely [ ] selection should have handles on the start/end so u can drag and change its size once there [ ] improve selection text extraction logic so its reliable diff --git a/data/themes/default.edc b/data/themes/default.edc index 54a6e535..7da39591 100644 --- a/data/themes/default.edc +++ b/data/themes/default.edc @@ -182,6 +182,74 @@ collections { } } + //////////////////////////////////////////////////////////////////// + // a place terminology will place an entry box for internal commands + part { name: "cmdclip"; type: RECT; + description { state: "default" 0.0; + color: 255 255 255 255; + rel1.to: "terminology.cmdbox"; + rel1.offset: -100 -100; + rel2.to: "terminology.cmdbox"; + rel2.offset: 99 99; + color: 255 255 255 0; + visible: 0; + } + description { state: "visible" 0.0; + inherit: "default" 0.0; + color: 255 255 255 255; + visible: 1; + } + } + part { name: "cmdback"; type: RECT; + clip_to: "cmdclip"; + description { state: "default" 0.0; + color: 255 255 255 255; + rel1.to: "terminology.cmdbox"; + rel1.offset: -2 -2; + rel2.to: "terminology.cmdbox"; + rel2.offset: 1 1; + } + } + part { name: "terminology.cmdbox"; type: SWALLOW; + clip_to: "cmdclip"; + description { state: "default" 0.0; + fixed: 1 1; + min: 8 8; + rel1.relative: 0.0 1.0; + rel1.offset: 8 9; + rel2.offset: -9 9; + align: 0.5 0.0; + } + description { state: "visible" 0.0; + inherit: "default" 0.0; + rel1.offset: 8 -9; + rel2.offset: -9 -9; + align: 0.5 1.0; + } + } + program { name: "cmdshow0"; + signal: "cmdbox,show"; + source: "terminology"; + action: STATE_SET "visible" 0.0; + transition: DECELERATE 0.4; + target: "cmdclip"; + } + program { name: "cmdshow"; + signal: "cmdbox,show"; + source: "terminology"; + action: STATE_SET "visible" 0.0; + transition: SPRING 0.4 0.5 4; + target: "terminology.cmdbox"; + } + program { name: "cmdhide"; + signal: "cmdbox,hide"; + source: "terminology"; + action: STATE_SET "default" 0.0; + transition: ACCELERATE 0.5; + target: "terminology.cmdbox"; + target: "cmdclip"; + } + //////////////////////////////////////////////////////////////////// // visual bell - spinning red siren light part { name: "bell_glow"; diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index f2dec318..416647c2 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -25,6 +25,7 @@ options_video.c options_video.h \ options_theme.c options_theme.h \ options_wallpaper.c options_wallpaper.h \ termio.c termio.h \ +termcmd.c termcmd.h \ termiolink.c termiolink.h \ termpty.c termpty.h \ termptydbl.c termptydbl.h \ diff --git a/src/bin/config.c b/src/bin/config.c index 0f407323..faa29cad 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -107,7 +107,7 @@ config_shutdown(void) } void -config_save(const Config *config, const char *key) +config_save(Config *config, const char *key) { Eet_File *ef; char buf[PATH_MAX], buf2[PATH_MAX]; @@ -118,7 +118,12 @@ config_save(const Config *config, const char *key) if (config->temporary) return; if (!key) key = config->config_key; - + config->font.orig_size = config->font.size; + eina_stringshare_del(config->font.orig_name); + config->font.orig_name = NULL; + if (config->font.name) config->font.orig_name = eina_stringshare_add(config->font.name); + config->font.orig_bitmap = config->font.bitmap; + cfgdir = _config_home_get(); snprintf(buf, sizeof(buf), "%s/terminology/config/standard", cfgdir); ecore_file_mkpath(buf); @@ -152,6 +157,9 @@ config_load(const char *key) eet_close(ef); if (config) { + config->font.orig_size = config->font.size; + if (config->font.name) config->font.orig_name = eina_stringshare_add(config->font.name); + config->font.orig_bitmap = config->font.bitmap; if (config->version < CONF_VER) { // currently no upgrade path so reset config. @@ -389,6 +397,7 @@ config_del(Config *config) if (!config) return; eina_stringshare_del(config->font.name); + eina_stringshare_del(config->font.orig_name); eina_stringshare_del(config->theme); eina_stringshare_del(config->background); eina_stringshare_del(config->wordsep); diff --git a/src/bin/config.h b/src/bin/config.h index 231c5dce..c612c492 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -10,8 +10,11 @@ struct _Config int version; struct { const char *name; + const char *orig_name; int size; + int orig_size; unsigned char bitmap; + unsigned char orig_bitmap; } font; struct { const char *email; @@ -42,7 +45,7 @@ struct _Config void config_init(void); void config_shutdown(void); -void config_save(const Config *config, const char *key); +void config_save(Config *config, const char *key); Config *config_load(const char *key); void config_del(Config *config); diff --git a/src/bin/main.c b/src/bin/main.c index f77a4378..40ebd48b 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -5,6 +5,7 @@ #include "main.h" #include "win.h" #include "termio.h" +#include "termcmd.h" #include "config.h" #include "controls.h" #include "media.h" @@ -13,11 +14,13 @@ int _log_domain = -1; static Evas_Object *win = NULL, *bg = NULL, *term = NULL, *media = NULL; +static Evas_Object *cmdbox = NULL; static Evas_Object *popmedia = NULL; static Evas_Object *conform = NULL; static Ecore_Timer *flush_timer = NULL; static Eina_Bool focused = EINA_FALSE; static Eina_Bool hold = EINA_FALSE; +static Eina_Bool cmdbox_up = EINA_FALSE; static void _cb_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) @@ -31,7 +34,10 @@ _cb_focus_in(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__) if (!focused) elm_win_urgent_set(win, EINA_FALSE); focused = EINA_TRUE; edje_object_signal_emit(bg, "focus,in", "terminology"); - elm_object_focus_set(data, EINA_TRUE); + if (cmdbox_up) + elm_object_focus_set(cmdbox, EINA_TRUE); + else + elm_object_focus_set(data, EINA_TRUE); } static void @@ -39,7 +45,10 @@ _cb_focus_out(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__) { focused = EINA_FALSE; edje_object_signal_emit(bg, "focus,out", "terminology"); - elm_object_focus_set(data, EINA_FALSE); + if (cmdbox_up) + elm_object_focus_set(cmdbox, EINA_FALSE); + else + elm_object_focus_set(data, EINA_FALSE); elm_cache_all_flush(); } @@ -86,7 +95,6 @@ _cb_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNU static void _cb_exited(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) { - printf("hold = %i\n", hold); if (!hold) elm_exit(); } @@ -141,6 +149,71 @@ _cb_popup(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUS edje_object_signal_emit(bg, "popmedia,movie", "terminology"); } +static void +_cb_cmdbox(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) +{ + cmdbox_up = EINA_TRUE; + elm_object_focus_set(term, EINA_FALSE); + edje_object_signal_emit(bg, "cmdbox,show", "terminology"); + elm_entry_entry_set(cmdbox, ""); + evas_object_show(cmdbox); + elm_object_focus_set(cmdbox, EINA_TRUE); +} + +static void +_cb_cmd_activated(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__) +{ + char *cmd; + + elm_object_focus_set(obj, EINA_FALSE); + edje_object_signal_emit(bg, "cmdbox,hide", "terminology"); + elm_object_focus_set(term, EINA_TRUE); + cmd = (char *)elm_entry_entry_get(obj); + if (cmd) + { + cmd = elm_entry_markup_to_utf8(cmd); + if (cmd) + { + termcmd_do(term, win, bg, cmd); + free(cmd); + } + } + cmdbox_up = EINA_FALSE; +} + +static void +_cb_cmd_aborted(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__) +{ + elm_object_focus_set(obj, EINA_FALSE); + edje_object_signal_emit(bg, "cmdbox,hide", "terminology"); + elm_object_focus_set(term, EINA_TRUE); + cmdbox_up = EINA_FALSE; +} + +static void +_cb_cmd_changed(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__) +{ + char *cmd; + + cmd = (char *)elm_entry_entry_get(obj); + if (cmd) + { + cmd = elm_entry_markup_to_utf8(cmd); + if (cmd) + { + termcmd_watch(term, win, bg, cmd); + free(cmd); + } + } +} + +static void +_cb_cmd_hints_changed(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__) +{ + evas_object_show(obj); + edje_object_part_swallow(data, "terminology.cmdbox", obj); +} + void main_trans_update(const Config *config) { @@ -554,7 +627,24 @@ elm_main(int argc, char **argv) if (pos_y < 0) pos_y = screen_h + pos_y; evas_object_move(win, pos_x, pos_y); } - + + cmdbox = o = elm_entry_add(win); + elm_entry_single_line_set(o, EINA_TRUE); + elm_entry_scrollable_set(o, EINA_FALSE); + elm_entry_scrollbar_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF); + elm_entry_input_panel_layout_set(o, ELM_INPUT_PANEL_LAYOUT_TERMINAL); + elm_entry_autocapital_type_set(o, ELM_AUTOCAPITAL_TYPE_NONE); + elm_entry_input_panel_enabled_set(o, EINA_TRUE); + elm_entry_input_panel_language_set(o, ELM_INPUT_PANEL_LANG_ALPHABET); + elm_entry_input_panel_return_key_type_set(o, ELM_INPUT_PANEL_RETURN_KEY_TYPE_GO); + elm_entry_prediction_allow_set(o, EINA_FALSE); + evas_object_show(o); + evas_object_smart_callback_add(o, "activated", _cb_cmd_activated, bg); + evas_object_smart_callback_add(o, "aborted", _cb_cmd_aborted, bg); + evas_object_smart_callback_add(o, "changed,user", _cb_cmd_changed, bg); + evas_object_event_callback_add(o, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _cb_cmd_hints_changed, bg); + edje_object_part_swallow(bg, "terminology.cmdbox", o); + term = o = termio_add(win, config, cmd, cd, size_w, size_h); termio_win_set(o, win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -567,6 +657,7 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(o, "exited", _cb_exited, NULL); evas_object_smart_callback_add(o, "bell", _cb_bell, NULL); evas_object_smart_callback_add(o, "popup", _cb_popup, NULL); + evas_object_smart_callback_add(o, "cmdbox", _cb_cmdbox, NULL); evas_object_show(o); main_trans_update(config); diff --git a/src/bin/termcmd.c b/src/bin/termcmd.c new file mode 100644 index 00000000..a5dbf55b --- /dev/null +++ b/src/bin/termcmd.c @@ -0,0 +1,88 @@ +#include "private.h" + +#include +#include "main.h" +#include "win.h" +#include "termio.h" +#include "config.h" +#include "controls.h" +#include "media.h" +#include "utils.h" +#include "termcmd.h" + +// called as u type +Eina_Bool +termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd) +{ + if (!cmd) return EINA_FALSE; + if ((cmd[0] == '/') || (cmd[0] == 's')) // search + { + if (cmd[1] == 0) // clear search + { + printf("search clear\n"); + return EINA_TRUE; + } + printf("search '%s'\n", cmd + 1); + return EINA_TRUE; + } + return EINA_FALSE; + obj = win = bg = NULL; +} + +// called when you hit enter +Eina_Bool +termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd) +{ + if (!cmd) return EINA_FALSE; + if ((cmd[0] == '/') || (cmd[0] == 's')) // search + { + if (cmd[1] == 0) // clear search + { + printf("search clear\n"); + return EINA_TRUE; + } + printf("search '%s'\n", cmd + 1); + return EINA_TRUE; + } + if ((cmd[0] == 'f') || (cmd[0] == 'F')) // font size + { + Config *config = termio_config_get(obj); + + if (config) + { + if (cmd[1] == 0) // back to default + { + config->font.bitmap = config->font.orig_bitmap; + if (config->font.orig_name) + { + eina_stringshare_del(config->font.name); + config->font.name = eina_stringshare_add(config->font.orig_name); + } + termio_font_size_set(obj, config->font.orig_size); + return EINA_TRUE; + } + else if (cmd[1] == 'b') // big font size + { + if (config->font.orig_bitmap) + { + config->font.bitmap = 1; + eina_stringshare_del(config->font.name); + config->font.name = eina_stringshare_add("10x20.pcf"); + termio_font_size_set(obj, 20); + } + } + else if (cmd[1] == '+') // size up + { + termio_font_size_set(obj, config->font.size + 1); + } + else if (cmd[1] == '-') // size down + { + termio_font_size_set(obj, config->font.size - 1); + } + } + return EINA_TRUE; + } + return EINA_FALSE; + obj = win = bg = NULL; +} + diff --git a/src/bin/termcmd.h b/src/bin/termcmd.h new file mode 100644 index 00000000..51b0ed2d --- /dev/null +++ b/src/bin/termcmd.h @@ -0,0 +1,9 @@ +#ifndef _TERMCMD_H__ +#define _TERMCMD_H__ 1 + +#include "config.h" + +Eina_Bool termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd); +Eina_Bool termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd); + +#endif diff --git a/src/bin/termio.c b/src/bin/termio.c index b26735a3..77281f07 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -779,6 +779,12 @@ _font_size_set(Evas_Object *obj, int size) } } +void +termio_font_size_set(Evas_Object *obj, int size) +{ + _font_size_set(obj, size); +} + static void _smart_cb_key_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event) { @@ -841,6 +847,14 @@ _smart_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, } } } + if ((evas_key_modifier_is_set(ev->modifiers, "Alt")) && + (!evas_key_modifier_is_set(ev->modifiers, "Shift")) && + (!evas_key_modifier_is_set(ev->modifiers, "Control")) && + (!strcmp(ev->keyname, "grave"))) + { + evas_object_smart_callback_call(data, "cmdbox", NULL); + goto end; + } if (evas_key_modifier_is_set(ev->modifiers, "Shift")) { if (ev->keyname) diff --git a/src/bin/termio.h b/src/bin/termio.h index 5fa3f0bd..d1a39aab 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -14,5 +14,6 @@ const char *termio_link_get(const Evas_Object *obj); void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir); void termio_size_get(Evas_Object *obj, int *w, int *h); int termio_scroll_get(Evas_Object *obj); +void termio_font_size_set(Evas_Object *obj, int size); #endif