1 #include "e.h"
2 #include "e_mod_main.h"
3 #include "e_kbd_int.h"
4 #include "e_kbd_send.h"
5
6 /* local function prototypes */
7 static void _il_kbd_stop(void);
8 static void _il_kbd_start(void);
9 static Eina_Bool _il_ki_delay_cb(void *data EINA_UNUSED);
10
11 /* local variables */
12 static E_Kbd_Int *ki = NULL;
13 static Ecore_Timer *ki_delay_timer = NULL;
14 static E_Config_DD *cd = NULL;
15
16 E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Virtual Keyboard" };
17
18 Il_Kbd_Config *il_kbd_cfg = NULL;
19
20 static void
_cb_act_vkbd_show(E_Object * obj EINA_UNUSED,const char * params EINA_UNUSED)21 _cb_act_vkbd_show(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
22 {
23 if (ki) e_kbd_int_show(ki);
24 }
25
26 static void
_cb_act_vkbd_hide(E_Object * obj EINA_UNUSED,const char * params EINA_UNUSED)27 _cb_act_vkbd_hide(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
28 {
29 if (ki) e_kbd_int_hide(ki);
30 }
31
32 static void
_cb_act_vkbd_toggle(E_Object * obj EINA_UNUSED,const char * params EINA_UNUSED)33 _cb_act_vkbd_toggle(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
34 {
35 if (ki)
36 {
37 if (ki->visible) e_kbd_int_hide(ki);
38 else e_kbd_int_show(ki);
39 }
40 }
41
42 E_API void *
e_modapi_init(E_Module * m)43 e_modapi_init(E_Module *m)
44 {
45 cd = E_CONFIG_DD_NEW("Il_Kbd_Config", Il_Kbd_Config);
46 E_CONFIG_VAL(cd, Il_Kbd_Config, dict, STR);
47 E_CONFIG_VAL(cd, Il_Kbd_Config, zone_id, STR);
48 E_CONFIG_VAL(cd, Il_Kbd_Config, zone_num, INT);
49 E_CONFIG_VAL(cd, Il_Kbd_Config, size, DOUBLE);
50 E_CONFIG_VAL(cd, Il_Kbd_Config, fill_mode, INT);
51 E_CONFIG_VAL(cd, Il_Kbd_Config, px, DOUBLE);
52 E_CONFIG_VAL(cd, Il_Kbd_Config, py, DOUBLE);
53
54 il_kbd_cfg = e_config_domain_load("module.vkbd", cd);
55 if (!il_kbd_cfg)
56 {
57 il_kbd_cfg = E_NEW(Il_Kbd_Config, 1);
58 il_kbd_cfg->dict = eina_stringshare_add("English_US.dic");
59 il_kbd_cfg->zone_num = 0;
60 il_kbd_cfg->size = 4.0;
61 il_kbd_cfg->fill_mode = 0;
62 }
63
64 il_kbd_cfg->mod_dir = eina_stringshare_add(m->dir);
65 il_kbd_cfg->slide_dim = 15;
66 il_kbd_cfg->act_kbd_show = e_action_add("vkbd_show");
67 if (il_kbd_cfg->act_kbd_show)
68 {
69 il_kbd_cfg->act_kbd_show->func.go = _cb_act_vkbd_show;
70 e_action_predef_name_set("Virtual Keyboard", _("Show"),
71 "vkbd_show", NULL, NULL, 0);
72 }
73 il_kbd_cfg->act_kbd_hide = e_action_add("vkbd_hide");
74 if (il_kbd_cfg->act_kbd_hide)
75 {
76 il_kbd_cfg->act_kbd_hide->func.go = _cb_act_vkbd_hide;
77 e_action_predef_name_set("Virtual Keyboard", _("Hide"),
78 "vkbd_hide", NULL, NULL, 0);
79 }
80 il_kbd_cfg->act_kbd_toggle = e_action_add("vkbd_toggle");
81 if (il_kbd_cfg->act_kbd_toggle)
82 {
83 il_kbd_cfg->act_kbd_toggle->func.go = _cb_act_vkbd_toggle;
84 e_action_predef_name_set("Virtual Keyboard", _("Toggle"),
85 "vkbd_toggle", NULL, NULL, 0);
86 }
87
88 ki_delay_timer = ecore_timer_add(1.0, _il_ki_delay_cb, NULL);
89 e_kbd_send_init();
90 return m;
91 }
92
93 E_API int
e_modapi_shutdown(E_Module * m EINA_UNUSED)94 e_modapi_shutdown(E_Module *m EINA_UNUSED)
95 {
96 e_kbd_send_shutdown();
97 e_config_domain_save("module.vkbd", cd, il_kbd_cfg);
98 if (ki_delay_timer)
99 {
100 ecore_timer_del(ki_delay_timer);
101 ki_delay_timer = NULL;
102 }
103 _il_kbd_stop();
104 eina_stringshare_del(il_kbd_cfg->dict);
105 eina_stringshare_del(il_kbd_cfg->mod_dir);
106
107 if (il_kbd_cfg->act_kbd_show)
108 {
109 e_action_predef_name_del("Virtual Keyboard", _("Show"));
110 e_action_del("vkbd_show");
111 }
112 if (il_kbd_cfg->act_kbd_hide)
113 {
114 e_action_predef_name_del("Virtual Keyboard", _("Hide"));
115 e_action_del("vkbd_hide");
116 }
117 if (il_kbd_cfg->act_kbd_toggle)
118 {
119 e_action_predef_name_del("Virtual Keyboard", _("Toggle"));
120 e_action_del("vkbg_toggle");
121 }
122 E_FREE(il_kbd_cfg);
123 E_CONFIG_DD_FREE(cd);
124 return 1;
125 }
126
127 E_API int
e_modapi_save(E_Module * m EINA_UNUSED)128 e_modapi_save(E_Module *m EINA_UNUSED)
129 {
130 return e_config_domain_save("module.vkbd", cd, il_kbd_cfg);
131 }
132
133 static void
_il_kbd_stop(void)134 _il_kbd_stop(void)
135 {
136 if (ki) e_kbd_int_free(ki);
137 ki = NULL;
138 }
139
140 static void
_il_kbd_start(void)141 _il_kbd_start(void)
142 {
143 ki = e_kbd_int_new(il_kbd_cfg->zone_num,
144 il_kbd_cfg->zone_id,
145 il_kbd_cfg->mod_dir,
146 il_kbd_cfg->mod_dir,
147 il_kbd_cfg->mod_dir);
148 ki->px = il_kbd_cfg->px;
149 ki->py = il_kbd_cfg->py;
150 e_kbd_int_update(ki);
151 e_kbd_int_show(ki);
152 }
153
154 static Eina_Bool
_il_ki_delay_cb(void * data EINA_UNUSED)155 _il_ki_delay_cb(void *data EINA_UNUSED)
156 {
157 ki_delay_timer = NULL;
158 _il_kbd_start();
159 return EINA_FALSE;
160 }
161