This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efm2.
View the commit online.
commit 838076859faf4759ef28a3393ede4ab4632ab58f
Author: Carsten Haitzler (Rasterman) <[email protected]>
AuthorDate: Wed Jan 21 00:03:48 2026 +0000
move typebuf stuff to its own file
this will expand so it deserves its own file. also detect
a cmd and hilight the cmdd and set up infra for tab completion
and history etc.
---
src/efm/efm.c | 109 +---------------------------
src/efm/efm_structs.h | 2 +-
src/efm/efm_typebuf.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/efm/efm_typebuf.h | 11 +++
src/efm/meson.build | 1 +
5 files changed, 208 insertions(+), 108 deletions(-)
diff --git a/src/efm/efm.c b/src/efm/efm.c
index e32255e..35a9eb9 100644
--- a/src/efm/efm.c
+++ b/src/efm/efm.c
@@ -16,6 +16,7 @@
#include "efm_custom.h"
#include "efm_private.h"
#include "efm_key.h"
+#include "efm_typebuf.h"
int _log_dom = -1;
@@ -39,112 +40,6 @@ _cb_header_change(void *data)
evas_object_smart_callback_call(sd->o_smart, "header_change", NULL);
}
-static void
-_typebuf_del(Smart_Data *sd)
-{
- Evas_Object *o = sd->o_typebuf;
-
- printf("XXX: hide typebuf\n");
- sd->o_typebuf = NULL;
- evas_object_del(o);
- evas_object_focus_set(sd->o_clip, EINA_TRUE);
-}
-
-static void
-_cb_typebuf_aborted(void *data, Evas_Object *obj EINA_UNUSED,
- void *event_info EINA_UNUSED)
-{
- Smart_Data *sd = data;
-
- printf("XXX: typebuf aborted\n");
- _typebuf_del(sd);
-}
-
-static void
-_cb_typebuf_activated(void *data, Evas_Object *obj EINA_UNUSED,
- void *event_info EINA_UNUSED)
-{
- Smart_Data *sd = data;
-
- printf("XXX: typebuf activated\n");
- _typebuf_del(sd);
-}
-
-static void
-_cb_typebuf_changed(void *data, Evas_Object *obj EINA_UNUSED,
- void *event_info EINA_UNUSED)
-{
- Smart_Data *sd = data;
- const char *str = elm_entry_entry_get(sd->o_typebuf);
- char *s = elm_entry_markup_to_utf8(str);
-
- printf("XXX: typebuf changed[%s]\n", s);
- free(s);
-}
-
-static void
-_cb_typebuf_cursor(void *data, Evas_Object *obj EINA_UNUSED,
- void *event_info EINA_UNUSED)
-{
- Smart_Data *sd = data;
- int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
- int x, y, w, h;
-
- if (sd->typebuf_cursor_ignore) return;
- elm_entry_cursor_geometry_get(sd->o_typebuf, &x, &y, &w, &h);
- printf("XXX: typebuf cursor %i @ %i,%i %ix%i\n", cpos, x, y, w, h);
-}
-
-static Eina_Bool
-_cb_typebuf_key(void *data, Evas_Object *obj EINA_UNUSED,
- Evas_Event_Key_Down *ev)
-{
- Smart_Data *sd = data;
- int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
- int cpos2;
-
- if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
- if (!ev->key) return EINA_FALSE;
- printf("INTERTCEPT %s\n", ev->key);
- if (!strcmp(ev->key, "Tab")) return EINA_TRUE;
- if (!strcmp(ev->key, "Up")) return EINA_TRUE;
- if (!strcmp(ev->key, "Down")) return EINA_TRUE;
- sd->typebuf_cursor_ignore++;
- elm_entry_cursor_end_set(sd->o_typebuf);
- cpos2 = elm_entry_cursor_pos_get(sd->o_typebuf);
- elm_entry_cursor_pos_set(sd->o_typebuf, cpos);
- sd->typebuf_cursor_ignore--;
- if ((cpos == 0) && (!strcmp(ev->key, "Left"))) return EINA_TRUE;
- if ((cpos == cpos2) && (!strcmp(ev->key, "Right"))) return EINA_TRUE;
- return EINA_FALSE;
-}
-
-static void
-_typebuf_add(Smart_Data *sd, Evas_Event_Key_Down *ev)
-{
- Evas_Object *o;
-
- if (sd->o_typebuf) return;
- elm_object_focus_set(sd->o_scroller, EINA_TRUE);
- sd->o_typebuf = o = elm_entry_add(sd->o_scroller);
- elm_grid_pack(sd->o_overlay_grid, o, 10, 40, 400, 20);
- elm_entry_single_line_set(o, EINA_TRUE);
- elm_entry_key_down_intercept_set(o, _cb_typebuf_key, sd);
- elm_entry_scrollable_set(o, EINA_TRUE);
- elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
- evas_object_move(o, 100, 100);
- evas_object_resize(o, 200, 40);
- elm_entry_entry_insert(o, ev->string);
- evas_object_smart_callback_add(o, "aborted", _cb_typebuf_aborted, sd);
- evas_object_smart_callback_add(o, "activated", _cb_typebuf_activated, sd);
- evas_object_smart_callback_add(o, "changed,user", _cb_typebuf_changed, sd);
- evas_object_smart_callback_add(o, "cursor,changed", _cb_typebuf_cursor, sd);
- evas_object_show(o);
- elm_object_focus_set(o, EINA_TRUE);
- // handle first initial text
- _cb_typebuf_changed(sd, o, NULL);
-}
-
static void
_cb_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info)
@@ -162,7 +57,7 @@ _cb_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
sd->key_control = EINA_TRUE;
}
- else if (ev->string) _typebuf_add(sd, ev);
+ else if (ev->string) typebuf_add(sd, ev);
}
else elm_object_focus_set(sd->o_typebuf, EINA_TRUE);
// XXX: if we're dnding - modify dnd action based on shift, ctrl etc.
diff --git a/src/efm/efm_structs.h b/src/efm/efm_structs.h
index 76eef57..75ad352 100644
--- a/src/efm/efm_structs.h
+++ b/src/efm/efm_structs.h
@@ -80,7 +80,7 @@ struct _Smart_Data
Icon *rename_icon;
Icon *dnd_over_icon;
- int typebuf_cursor_ignore;
+ int typebuf_cursor_ignore;
Evas_Coord icon_min_w, icon_min_h;
Evas_Coord list_min_w, list_min_h;
diff --git a/src/efm/efm_typebuf.c b/src/efm/efm_typebuf.c
new file mode 100644
index 0000000..afdc998
--- /dev/null
+++ b/src/efm/efm_typebuf.c
@@ -0,0 +1,193 @@
+#include "efm_typebuf.h"
+
+static int
+_typebuf_command_detect(const char *str)
+{
+ int i = 0;
+ Eina_Unicode cp;
+
+ for (i = 0; (cp = eina_unicode_utf8_next_get(str, &i));)
+ {
+ if (cp == ' ') return i;
+ }
+ return -1;
+}
+
+static void
+_typebuf_command_clear(Smart_Data *sd, int cpos, const char *str)
+{
+ elm_entry_entry_set(sd->o_typebuf, str);
+}
+
+static void
+_typebuf_command_str_build_hilight(Eina_Strbuf *buf, const char *str,
+ int cmdendpos)
+{ // make cmd hilight and appear different
+ eina_strbuf_append(buf, "<hilight>");
+ eina_strbuf_append_n(buf, str, cmdendpos - 1);
+ eina_strbuf_append(buf, "</>");
+}
+
+static void
+_typebuf_command_str_build_args(Eina_Strbuf *buf, const char *str,
+ int cmdendpos)
+{ // process arguments after cmd and put them back in the string
+ // e.g. hilight them as appropriate. here just dumbly appending
+ eina_strbuf_append(buf, str + cmdendpos - 1);
+}
+
+static void
+_typebuf_complete(Smart_Data *sd)
+{ // find where cursor is (just after) and complete it if possible
+ int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
+}
+
+static void
+_typebuf_history(Smart_Data *sd, int dir)
+{ // replace typebuf with history typebuf item in direction given
+}
+
+static void
+_cb_typebuf_aborted(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ Smart_Data *sd = data;
+
+ printf("XXX: typebuf aborted\n");
+ typebuf_del(sd);
+}
+
+static void
+_cb_typebuf_activated(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ Smart_Data *sd = data;
+
+ printf("XXX: typebuf activated\n");
+ // XXX: "run" the cmd (eg run selected files or run detected cmd)
+ typebuf_del(sd);
+}
+
+static void
+_cb_typebuf_changed(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ Smart_Data *sd = data;
+ const char *str = elm_entry_entry_get(sd->o_typebuf);
+ char *s = elm_entry_markup_to_utf8(str);
+ int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
+ int pos;
+
+ printf("XXX: typebuf changed [%s]\n", s);
+ pos = _typebuf_command_detect(s);
+ if (pos > 0)
+ { // add hilights to the found command
+ Eina_Strbuf *buf = eina_strbuf_new();
+
+ printf("XXX: found cmd end at %i\n", pos);
+ if (buf)
+ {
+ _typebuf_command_str_build_hilight(buf, s, pos);
+ _typebuf_command_str_build_args(buf, s, pos);
+ elm_entry_entry_set(sd->o_typebuf, eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
+ }
+ }
+ // strip out markup used to hilight stuff
+ else if (pos <= 0) _typebuf_command_clear(sd, cpos, s);
+ // pur cursor back where it was
+ elm_entry_cursor_pos_set(sd->o_typebuf, cpos);
+ free(s);
+}
+
+static void
+_cb_typebuf_cursor(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ Smart_Data *sd = data;
+ int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
+ int x, y, w, h;
+
+ if (sd->typebuf_cursor_ignore) return;
+ elm_entry_cursor_geometry_get(sd->o_typebuf, &x, &y, &w, &h);
+ printf("XXX: typebuf cursor %i @ %i,%i %ix%i\n", cpos, x, y, w, h);
+}
+
+static Eina_Bool
+_cb_typebuf_key(void *data, Evas_Object *obj EINA_UNUSED,
+ Evas_Event_Key_Down *ev)
+{
+ Smart_Data *sd = data;
+ int cpos = elm_entry_cursor_pos_get(sd->o_typebuf);
+ int cpos2;
+
+ if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
+ if (!ev->key) return EINA_FALSE;
+ printf("XXX: intercept [%s]\n", ev->key);
+ // intercept keys that change focus and steal them to not do that
+ // XXX: later we need to do special things here like typebuf history
+ // XXX: and tab completion
+ if (!strcmp(ev->key, "Tab"))
+ {
+ _typebuf_complete(sd);
+ return EINA_TRUE;
+ }
+ if (!strcmp(ev->key, "Up"))
+ {
+ _typebuf_history(sd, -1);
+ return EINA_TRUE;
+ }
+ if (!strcmp(ev->key, "Down"))
+ {
+ _typebuf_history(sd, 1);
+ return EINA_TRUE;
+ }
+ // allow left/right arrow through if the cursor is not at the start/end
+ sd->typebuf_cursor_ignore++;
+ elm_entry_cursor_end_set(sd->o_typebuf);
+ cpos2 = elm_entry_cursor_pos_get(sd->o_typebuf);
+ elm_entry_cursor_pos_set(sd->o_typebuf, cpos);
+ sd->typebuf_cursor_ignore--;
+ // here if at start or end - swallow left/right that goes out of entry
+ if ((cpos == 0) && (!strcmp(ev->key, "Left"))) return EINA_TRUE;
+ if ((cpos == cpos2) && (!strcmp(ev->key, "Right"))) return EINA_TRUE;
+ // allow key press to be processed as normal
+ return EINA_FALSE;
+}
+
+void
+typebuf_del(Smart_Data *sd)
+{
+ Evas_Object *o = sd->o_typebuf;
+
+ printf("XXX: hide typebuf\n");
+ sd->o_typebuf = NULL;
+ evas_object_del(o);
+ evas_object_focus_set(sd->o_clip, EINA_TRUE);
+}
+
+void
+typebuf_add(Smart_Data *sd, Evas_Event_Key_Down *ev)
+{
+ Evas_Object *o;
+
+ if (sd->o_typebuf) return;
+ elm_object_focus_set(sd->o_scroller, EINA_TRUE);
+ sd->o_typebuf = o = elm_entry_add(sd->o_scroller);
+ elm_grid_pack(sd->o_overlay_grid, o, 10, 40, 400, 20);
+ elm_entry_single_line_set(o, EINA_TRUE);
+ elm_entry_key_down_intercept_set(o, _cb_typebuf_key, sd);
+ elm_entry_scrollable_set(o, EINA_TRUE);
+ elm_scroller_policy_set(o, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
+ evas_object_move(o, 100, 100);
+ evas_object_resize(o, 200, 40);
+ elm_entry_entry_insert(o, ev->string);
+ evas_object_smart_callback_add(o, "aborted", _cb_typebuf_aborted, sd);
+ evas_object_smart_callback_add(o, "activated", _cb_typebuf_activated, sd);
+ evas_object_smart_callback_add(o, "changed,user", _cb_typebuf_changed, sd);
+ evas_object_smart_callback_add(o, "cursor,changed", _cb_typebuf_cursor, sd);
+ evas_object_show(o);
+ elm_object_focus_set(o, EINA_TRUE);
+ // handle first initial text
+ _cb_typebuf_changed(sd, o, NULL);
+}
\ No newline at end of file
diff --git a/src/efm/efm_typebuf.h b/src/efm/efm_typebuf.h
new file mode 100644
index 0000000..6f26538
--- /dev/null
+++ b/src/efm/efm_typebuf.h
@@ -0,0 +1,11 @@
+#ifndef EFM_TYPEBUF_H
+#define EFM_TYPEBUF_H 1
+
+#include <Elementary.h>
+
+#include "efm_structs.h"
+
+void typebuf_del(Smart_Data *sd);
+void typebuf_add(Smart_Data *sd, Evas_Event_Key_Down *ev);
+
+#endif
\ No newline at end of file
diff --git a/src/efm/meson.build b/src/efm/meson.build
index 1807477..2854f2c 100644
--- a/src/efm/meson.build
+++ b/src/efm/meson.build
@@ -20,6 +20,7 @@ executable('efm', [
'efm_menu.c',
'efm_popup_menu.c',
'efm_key.c',
+ 'efm_typebuf.c',
'main.c'
],
include_directories: inc,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.