aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-11-20 22:45:44 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-11-20 22:45:44 +0100
commit44e631d9db8da132aeecc4d2850b41d3d1fe298d (patch)
tree6e760490ee4d40912e1173a2dcaaf17dd13fa49e
parent6988907dd554aff4097700331764b1e7631a1442 (diff)
downloadd2tk-master.tar.xz
base: support unicode input CTRL-SHIFT-u-CODE-SPACE.HEADmaster
-rw-r--r--VERSION2
-rw-r--r--src/base.c38
-rw-r--r--src/base_internal.h2
3 files changed, 39 insertions, 3 deletions
diff --git a/VERSION b/VERSION
index 07779b2..e1c7232 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.1151
+0.1.1153
diff --git a/src/base.c b/src/base.c
index bca1113..9af6c0f 100644
--- a/src/base.c
+++ b/src/base.c
@@ -391,8 +391,8 @@ _d2tk_base_clear_chars(d2tk_base_t *base)
base->keys.nchars = 0;
}
-D2TK_API void
-d2tk_base_append_utf8(d2tk_base_t *base, utf8_int32_t utf8)
+static void
+_d2tk_base_append_utf8(d2tk_base_t *base, utf8_int32_t utf8)
{
if(base->keys.nchars < sizeof(base->keys.nchars))
{
@@ -401,6 +401,40 @@ d2tk_base_append_utf8(d2tk_base_t *base, utf8_int32_t utf8)
}
D2TK_API void
+d2tk_base_append_utf8(d2tk_base_t *base, utf8_int32_t utf8)
+{
+ if( !base->unicode_mode
+ && d2tk_base_get_modmask(base, D2TK_MODMASK_CTRL, false)
+ && d2tk_base_get_modmask(base, D2TK_MODMASK_SHIFT, false)
+ && (utf8 == 'u' - 0x60) ) // FIXME where the hello does the offset come from?
+ {
+ base->unicode_acc = 0;
+ base->unicode_mode = true;
+ }
+ else if(base->unicode_mode)
+ {
+ if(utf8 == ' ')
+ {
+ _d2tk_base_append_utf8(base, base->unicode_acc);
+
+ base->unicode_mode = false;
+ }
+ else
+ {
+ char str [2] = { utf8, 0x0 };
+ const uint32_t fig = strtol(str, NULL, 16);
+
+ base->unicode_acc <<= 4;
+ base->unicode_acc |= fig;
+ }
+ }
+ else
+ {
+ _d2tk_base_append_utf8(base, utf8);
+ }
+}
+
+D2TK_API void
d2tk_base_get_utf8(d2tk_base_t *base, ssize_t *len, const utf8_int32_t **utf8)
{
if(len)
diff --git a/src/base_internal.h b/src/base_internal.h
index 35c0691..6fda4a9 100644
--- a/src/base_internal.h
+++ b/src/base_internal.h
@@ -68,6 +68,8 @@ struct _d2tk_base_t {
d2tk_id_t lastitem;
bool not_first_time;
+ bool unicode_mode;
+ uint32_t unicode_acc;
struct {
d2tk_coord_t x;