summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-08-14 12:30:55 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-08-14 12:30:55 +0000
commita684b21b577c4f7e8e638fdd5ad99e8d647c86d7 (patch)
tree3211acb23ae3bb88ea5d0ea909b3e014bd3afbfc /src
parentd99c9a920ab2c2c56e52e398c87ff7b0a9f181bb (diff)
add some infra for cmd-mode for terminology. only 1 working cmd atm
"f" (font changes) SVN revision: 75254
Diffstat (limited to 'src')
-rw-r--r--src/bin/Makefile.am1
-rw-r--r--src/bin/config.c13
-rw-r--r--src/bin/config.h5
-rw-r--r--src/bin/main.c99
-rw-r--r--src/bin/termcmd.c88
-rw-r--r--src/bin/termcmd.h9
-rw-r--r--src/bin/termio.c14
-rw-r--r--src/bin/termio.h1
8 files changed, 223 insertions, 7 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index f2dec31..416647c 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -25,6 +25,7 @@ options_video.c options_video.h \
25options_theme.c options_theme.h \ 25options_theme.c options_theme.h \
26options_wallpaper.c options_wallpaper.h \ 26options_wallpaper.c options_wallpaper.h \
27termio.c termio.h \ 27termio.c termio.h \
28termcmd.c termcmd.h \
28termiolink.c termiolink.h \ 29termiolink.c termiolink.h \
29termpty.c termpty.h \ 30termpty.c termpty.h \
30termptydbl.c termptydbl.h \ 31termptydbl.c termptydbl.h \
diff --git a/src/bin/config.c b/src/bin/config.c
index 0f40732..faa29ca 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -107,7 +107,7 @@ config_shutdown(void)
107} 107}
108 108
109void 109void
110config_save(const Config *config, const char *key) 110config_save(Config *config, const char *key)
111{ 111{
112 Eet_File *ef; 112 Eet_File *ef;
113 char buf[PATH_MAX], buf2[PATH_MAX]; 113 char buf[PATH_MAX], buf2[PATH_MAX];
@@ -118,7 +118,12 @@ config_save(const Config *config, const char *key)
118 118
119 if (config->temporary) return; 119 if (config->temporary) return;
120 if (!key) key = config->config_key; 120 if (!key) key = config->config_key;
121 121 config->font.orig_size = config->font.size;
122 eina_stringshare_del(config->font.orig_name);
123 config->font.orig_name = NULL;
124 if (config->font.name) config->font.orig_name = eina_stringshare_add(config->font.name);
125 config->font.orig_bitmap = config->font.bitmap;
126
122 cfgdir = _config_home_get(); 127 cfgdir = _config_home_get();
123 snprintf(buf, sizeof(buf), "%s/terminology/config/standard", cfgdir); 128 snprintf(buf, sizeof(buf), "%s/terminology/config/standard", cfgdir);
124 ecore_file_mkpath(buf); 129 ecore_file_mkpath(buf);
@@ -152,6 +157,9 @@ config_load(const char *key)
152 eet_close(ef); 157 eet_close(ef);
153 if (config) 158 if (config)
154 { 159 {
160 config->font.orig_size = config->font.size;
161 if (config->font.name) config->font.orig_name = eina_stringshare_add(config->font.name);
162 config->font.orig_bitmap = config->font.bitmap;
155 if (config->version < CONF_VER) 163 if (config->version < CONF_VER)
156 { 164 {
157 // currently no upgrade path so reset config. 165 // currently no upgrade path so reset config.
@@ -389,6 +397,7 @@ config_del(Config *config)
389 if (!config) return; 397 if (!config) return;
390 398
391 eina_stringshare_del(config->font.name); 399 eina_stringshare_del(config->font.name);
400 eina_stringshare_del(config->font.orig_name);
392 eina_stringshare_del(config->theme); 401 eina_stringshare_del(config->theme);
393 eina_stringshare_del(config->background); 402 eina_stringshare_del(config->background);
394 eina_stringshare_del(config->wordsep); 403 eina_stringshare_del(config->wordsep);
diff --git a/src/bin/config.h b/src/bin/config.h
index 231c5dc..c612c49 100644
--- a/src/bin/config.h
+++ b/src/bin/config.h
@@ -10,8 +10,11 @@ struct _Config
10 int version; 10 int version;
11 struct { 11 struct {
12 const char *name; 12 const char *name;
13 const char *orig_name;
13 int size; 14 int size;
15 int orig_size;
14 unsigned char bitmap; 16 unsigned char bitmap;
17 unsigned char orig_bitmap;
15 } font; 18 } font;
16 struct { 19 struct {
17 const char *email; 20 const char *email;
@@ -42,7 +45,7 @@ struct _Config
42 45
43void config_init(void); 46void config_init(void);
44void config_shutdown(void); 47void config_shutdown(void);
45void config_save(const Config *config, const char *key); 48void config_save(Config *config, const char *key);
46Config *config_load(const char *key); 49Config *config_load(const char *key);
47void config_del(Config *config); 50void config_del(Config *config);
48 51
diff --git a/src/bin/main.c b/src/bin/main.c
index f77a437..40ebd48 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -5,6 +5,7 @@
5#include "main.h" 5#include "main.h"
6#include "win.h" 6#include "win.h"
7#include "termio.h" 7#include "termio.h"
8#include "termcmd.h"
8#include "config.h" 9#include "config.h"
9#include "controls.h" 10#include "controls.h"
10#include "media.h" 11#include "media.h"
@@ -13,11 +14,13 @@
13int _log_domain = -1; 14int _log_domain = -1;
14 15
15static Evas_Object *win = NULL, *bg = NULL, *term = NULL, *media = NULL; 16static Evas_Object *win = NULL, *bg = NULL, *term = NULL, *media = NULL;
17static Evas_Object *cmdbox = NULL;
16static Evas_Object *popmedia = NULL; 18static Evas_Object *popmedia = NULL;
17static Evas_Object *conform = NULL; 19static Evas_Object *conform = NULL;
18static Ecore_Timer *flush_timer = NULL; 20static Ecore_Timer *flush_timer = NULL;
19static Eina_Bool focused = EINA_FALSE; 21static Eina_Bool focused = EINA_FALSE;
20static Eina_Bool hold = EINA_FALSE; 22static Eina_Bool hold = EINA_FALSE;
23static Eina_Bool cmdbox_up = EINA_FALSE;
21 24
22static void 25static void
23_cb_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) 26_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__)
31 if (!focused) elm_win_urgent_set(win, EINA_FALSE); 34 if (!focused) elm_win_urgent_set(win, EINA_FALSE);
32 focused = EINA_TRUE; 35 focused = EINA_TRUE;
33 edje_object_signal_emit(bg, "focus,in", "terminology"); 36 edje_object_signal_emit(bg, "focus,in", "terminology");
34 elm_object_focus_set(data, EINA_TRUE); 37 if (cmdbox_up)
38 elm_object_focus_set(cmdbox, EINA_TRUE);
39 else
40 elm_object_focus_set(data, EINA_TRUE);
35} 41}
36 42
37static void 43static void
@@ -39,7 +45,10 @@ _cb_focus_out(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
39{ 45{
40 focused = EINA_FALSE; 46 focused = EINA_FALSE;
41 edje_object_signal_emit(bg, "focus,out", "terminology"); 47 edje_object_signal_emit(bg, "focus,out", "terminology");
42 elm_object_focus_set(data, EINA_FALSE); 48 if (cmdbox_up)
49 elm_object_focus_set(cmdbox, EINA_FALSE);
50 else
51 elm_object_focus_set(data, EINA_FALSE);
43 elm_cache_all_flush(); 52 elm_cache_all_flush();
44} 53}
45 54
@@ -86,7 +95,6 @@ _cb_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNU
86static void 95static void
87_cb_exited(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) 96_cb_exited(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
88{ 97{
89 printf("hold = %i\n", hold);
90 if (!hold) elm_exit(); 98 if (!hold) elm_exit();
91} 99}
92 100
@@ -141,6 +149,71 @@ _cb_popup(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUS
141 edje_object_signal_emit(bg, "popmedia,movie", "terminology"); 149 edje_object_signal_emit(bg, "popmedia,movie", "terminology");
142} 150}
143 151
152static void
153_cb_cmdbox(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
154{
155 cmdbox_up = EINA_TRUE;
156 elm_object_focus_set(term, EINA_FALSE);
157 edje_object_signal_emit(bg, "cmdbox,show", "terminology");
158 elm_entry_entry_set(cmdbox, "");
159 evas_object_show(cmdbox);
160 elm_object_focus_set(cmdbox, EINA_TRUE);
161}
162
163static void
164_cb_cmd_activated(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
165{
166 char *cmd;
167
168 elm_object_focus_set(obj, EINA_FALSE);
169 edje_object_signal_emit(bg, "cmdbox,hide", "terminology");
170 elm_object_focus_set(term, EINA_TRUE);
171 cmd = (char *)elm_entry_entry_get(obj);
172 if (cmd)
173 {
174 cmd = elm_entry_markup_to_utf8(cmd);
175 if (cmd)
176 {
177 termcmd_do(term, win, bg, cmd);
178 free(cmd);
179 }
180 }
181 cmdbox_up = EINA_FALSE;
182}
183
184static void
185_cb_cmd_aborted(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
186{
187 elm_object_focus_set(obj, EINA_FALSE);
188 edje_object_signal_emit(bg, "cmdbox,hide", "terminology");
189 elm_object_focus_set(term, EINA_TRUE);
190 cmdbox_up = EINA_FALSE;
191}
192
193static void
194_cb_cmd_changed(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
195{
196 char *cmd;
197
198 cmd = (char *)elm_entry_entry_get(obj);
199 if (cmd)
200 {
201 cmd = elm_entry_markup_to_utf8(cmd);
202 if (cmd)
203 {
204 termcmd_watch(term, win, bg, cmd);
205 free(cmd);
206 }
207 }
208}
209
210static void
211_cb_cmd_hints_changed(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
212{
213 evas_object_show(obj);
214 edje_object_part_swallow(data, "terminology.cmdbox", obj);
215}
216
144void 217void
145main_trans_update(const Config *config) 218main_trans_update(const Config *config)
146{ 219{
@@ -554,7 +627,24 @@ elm_main(int argc, char **argv)
554 if (pos_y < 0) pos_y = screen_h + pos_y; 627 if (pos_y < 0) pos_y = screen_h + pos_y;
555 evas_object_move(win, pos_x, pos_y); 628 evas_object_move(win, pos_x, pos_y);
556 } 629 }
557 630
631 cmdbox = o = elm_entry_add(win);
632 elm_entry_single_line_set(o, EINA_TRUE);
633 elm_entry_scrollable_set(o, EINA_FALSE);
634 elm_entry_scrollbar_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
635 elm_entry_input_panel_layout_set(o, ELM_INPUT_PANEL_LAYOUT_TERMINAL);
636 elm_entry_autocapital_type_set(o, ELM_AUTOCAPITAL_TYPE_NONE);
637 elm_entry_input_panel_enabled_set(o, EINA_TRUE);
638 elm_entry_input_panel_language_set(o, ELM_INPUT_PANEL_LANG_ALPHABET);
639 elm_entry_input_panel_return_key_type_set(o, ELM_INPUT_PANEL_RETURN_KEY_TYPE_GO);
640 elm_entry_prediction_allow_set(o, EINA_FALSE);
641 evas_object_show(o);
642 evas_object_smart_callback_add(o, "activated", _cb_cmd_activated, bg);
643 evas_object_smart_callback_add(o, "aborted", _cb_cmd_aborted, bg);
644 evas_object_smart_callback_add(o, "changed,user", _cb_cmd_changed, bg);
645 evas_object_event_callback_add(o, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _cb_cmd_hints_changed, bg);
646 edje_object_part_swallow(bg, "terminology.cmdbox", o);
647
558 term = o = termio_add(win, config, cmd, cd, size_w, size_h); 648 term = o = termio_add(win, config, cmd, cd, size_w, size_h);
559 termio_win_set(o, win); 649 termio_win_set(o, win);
560 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 650 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -567,6 +657,7 @@ elm_main(int argc, char **argv)
567 evas_object_smart_callback_add(o, "exited", _cb_exited, NULL); 657 evas_object_smart_callback_add(o, "exited", _cb_exited, NULL);
568 evas_object_smart_callback_add(o, "bell", _cb_bell, NULL); 658 evas_object_smart_callback_add(o, "bell", _cb_bell, NULL);
569 evas_object_smart_callback_add(o, "popup", _cb_popup, NULL); 659 evas_object_smart_callback_add(o, "popup", _cb_popup, NULL);
660 evas_object_smart_callback_add(o, "cmdbox", _cb_cmdbox, NULL);
570 evas_object_show(o); 661 evas_object_show(o);
571 662
572 main_trans_update(config); 663 main_trans_update(config);
diff --git a/src/bin/termcmd.c b/src/bin/termcmd.c
new file mode 100644
index 0000000..a5dbf55
--- /dev/null
+++ b/src/bin/termcmd.c
@@ -0,0 +1,88 @@
1#include "private.h"
2
3#include <Elementary.h>
4#include "main.h"
5#include "win.h"
6#include "termio.h"
7#include "config.h"
8#include "controls.h"
9#include "media.h"
10#include "utils.h"
11#include "termcmd.h"
12
13// called as u type
14Eina_Bool
15termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
16{
17 if (!cmd) return EINA_FALSE;
18 if ((cmd[0] == '/') || (cmd[0] == 's')) // search
19 {
20 if (cmd[1] == 0) // clear search
21 {
22 printf("search clear\n");
23 return EINA_TRUE;
24 }
25 printf("search '%s'\n", cmd + 1);
26 return EINA_TRUE;
27 }
28 return EINA_FALSE;
29 obj = win = bg = NULL;
30}
31
32// called when you hit enter
33Eina_Bool
34termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd)
35{
36 if (!cmd) return EINA_FALSE;
37 if ((cmd[0] == '/') || (cmd[0] == 's')) // search
38 {
39 if (cmd[1] == 0) // clear search
40 {
41 printf("search clear\n");
42 return EINA_TRUE;
43 }
44 printf("search '%s'\n", cmd + 1);
45 return EINA_TRUE;
46 }
47 if ((cmd[0] == 'f') || (cmd[0] == 'F')) // font size
48 {
49 Config *config = termio_config_get(obj);
50
51 if (config)
52 {
53 if (cmd[1] == 0) // back to default
54 {
55 config->font.bitmap = config->font.orig_bitmap;
56 if (config->font.orig_name)
57 {
58 eina_stringshare_del(config->font.name);
59 config->font.name = eina_stringshare_add(config->font.orig_name);
60 }
61 termio_font_size_set(obj, config->font.orig_size);
62 return EINA_TRUE;
63 }
64 else if (cmd[1] == 'b') // big font size
65 {
66 if (config->font.orig_bitmap)
67 {
68 config->font.bitmap = 1;
69 eina_stringshare_del(config->font.name);
70 config->font.name = eina_stringshare_add("10x20.pcf");
71 termio_font_size_set(obj, 20);
72 }
73 }
74 else if (cmd[1] == '+') // size up
75 {
76 termio_font_size_set(obj, config->font.size + 1);
77 }
78 else if (cmd[1] == '-') // size down
79 {
80 termio_font_size_set(obj, config->font.size - 1);
81 }
82 }
83 return EINA_TRUE;
84 }
85 return EINA_FALSE;
86 obj = win = bg = NULL;
87}
88
diff --git a/src/bin/termcmd.h b/src/bin/termcmd.h
new file mode 100644
index 0000000..51b0ed2
--- /dev/null
+++ b/src/bin/termcmd.h
@@ -0,0 +1,9 @@
1#ifndef _TERMCMD_H__
2#define _TERMCMD_H__ 1
3
4#include "config.h"
5
6Eina_Bool termcmd_watch(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd);
7Eina_Bool termcmd_do(Evas_Object *obj, Evas_Object *win, Evas_Object *bg, const char *cmd);
8
9#endif
diff --git a/src/bin/termio.c b/src/bin/termio.c
index b26735a..77281f0 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -779,6 +779,12 @@ _font_size_set(Evas_Object *obj, int size)
779 } 779 }
780} 780}
781 781
782void
783termio_font_size_set(Evas_Object *obj, int size)
784{
785 _font_size_set(obj, size);
786}
787
782static void 788static void
783_smart_cb_key_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event) 789_smart_cb_key_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
784{ 790{
@@ -841,6 +847,14 @@ _smart_cb_key_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
841 } 847 }
842 } 848 }
843 } 849 }
850 if ((evas_key_modifier_is_set(ev->modifiers, "Alt")) &&
851 (!evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
852 (!evas_key_modifier_is_set(ev->modifiers, "Control")) &&
853 (!strcmp(ev->keyname, "grave")))
854 {
855 evas_object_smart_callback_call(data, "cmdbox", NULL);
856 goto end;
857 }
844 if (evas_key_modifier_is_set(ev->modifiers, "Shift")) 858 if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
845 { 859 {
846 if (ev->keyname) 860 if (ev->keyname)
diff --git a/src/bin/termio.h b/src/bin/termio.h
index 5fa3f0b..d1a39aa 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -14,5 +14,6 @@ const char *termio_link_get(const Evas_Object *obj);
14void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir); 14void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir);
15void termio_size_get(Evas_Object *obj, int *w, int *h); 15void termio_size_get(Evas_Object *obj, int *w, int *h);
16int termio_scroll_get(Evas_Object *obj); 16int termio_scroll_get(Evas_Object *obj);
17void termio_font_size_set(Evas_Object *obj, int size);
17 18
18#endif 19#endif