2010-12-22 09:03:38 +00:00
|
|
|
From e4f14d6d0755dc315c850eaef6f46fd1596b2da7 Mon Sep 17 00:00:00 2001
|
2010-10-07 06:15:32 +00:00
|
|
|
From: Daiki Ueno <ueno@unixuser.org>
|
|
|
|
Date: Wed, 15 Sep 2010 12:21:35 +0900
|
|
|
|
Subject: [PATCH] Support surrounding-text commands.
|
|
|
|
|
|
|
|
---
|
2010-12-22 09:03:38 +00:00
|
|
|
src/engine.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
|
|
src/m17nutil.c | 8 ++++++++
|
|
|
|
2 files changed, 56 insertions(+), 3 deletions(-)
|
2010-10-07 06:15:32 +00:00
|
|
|
|
|
|
|
diff --git a/src/engine.c b/src/engine.c
|
2010-12-22 09:03:38 +00:00
|
|
|
index 5fbe46f..e5dad3e 100644
|
2010-10-07 06:15:32 +00:00
|
|
|
--- a/src/engine.c
|
|
|
|
+++ b/src/engine.c
|
2010-12-22 09:03:38 +00:00
|
|
|
@@ -966,8 +966,53 @@ ibus_m17n_engine_callback (MInputContext *context,
|
2010-10-07 06:15:32 +00:00
|
|
|
}
|
|
|
|
else if (command == Minput_reset) {
|
|
|
|
}
|
|
|
|
- else if (command == Minput_get_surrounding_text) {
|
|
|
|
- }
|
|
|
|
- else if (command == Minput_delete_surrounding_text) {
|
|
|
|
+ else if (command == Minput_get_surrounding_text &&
|
|
|
|
+ (((IBusEngine *) m17n)->client_capabilities &
|
|
|
|
+ IBUS_CAP_SURROUNDING_TEXT) != 0) {
|
|
|
|
+ IBusText *text;
|
|
|
|
+ guint cursor_pos, nchars, nbytes;
|
|
|
|
+ MText *mt, *surround;
|
|
|
|
+ int len, pos;
|
|
|
|
+
|
|
|
|
+ ibus_engine_get_surrounding_text ((IBusEngine *) m17n,
|
|
|
|
+ &text,
|
|
|
|
+ &cursor_pos);
|
|
|
|
+ nchars = ibus_text_get_length (text);
|
|
|
|
+ nbytes = g_utf8_offset_to_pointer (text->text, nchars) - text->text;
|
|
|
|
+ mt = mconv_decode_buffer (Mcoding_utf_8, text->text, nbytes);
|
|
|
|
+ g_object_unref (text);
|
|
|
|
+
|
|
|
|
+ len = (long) mplist_value (m17n->context->plist);
|
|
|
|
+ if (len < 0) {
|
|
|
|
+ pos = cursor_pos + len;
|
|
|
|
+ if (pos < 0)
|
|
|
|
+ pos = 0;
|
|
|
|
+ surround = mtext_duplicate (mt, pos, cursor_pos);
|
|
|
|
+ }
|
|
|
|
+ else if (len > 0) {
|
|
|
|
+ pos = cursor_pos + len;
|
|
|
|
+ if (pos > nchars)
|
|
|
|
+ pos = nchars;
|
|
|
|
+ surround = mtext_duplicate (mt, cursor_pos, pos);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ surround = mtext ();
|
|
|
|
+ }
|
|
|
|
+ m17n_object_unref (mt);
|
|
|
|
+ mplist_set (m17n->context->plist, Mtext, surround);
|
|
|
|
+ m17n_object_unref (surround);
|
|
|
|
+ }
|
|
|
|
+ else if (command == Minput_delete_surrounding_text &&
|
|
|
|
+ (((IBusEngine *) m17n)->client_capabilities &
|
|
|
|
+ IBUS_CAP_SURROUNDING_TEXT) != 0) {
|
|
|
|
+ int len;
|
|
|
|
+
|
|
|
|
+ len = (long) mplist_value (m17n->context->plist);
|
|
|
|
+ if (len < 0)
|
|
|
|
+ ibus_engine_delete_surrounding_text ((IBusEngine *) m17n,
|
|
|
|
+ len, -len);
|
|
|
|
+ else if (len > 0)
|
|
|
|
+ ibus_engine_delete_surrounding_text ((IBusEngine *) m17n,
|
|
|
|
+ 0, len);
|
|
|
|
}
|
|
|
|
}
|
2010-12-22 09:03:38 +00:00
|
|
|
diff --git a/src/m17nutil.c b/src/m17nutil.c
|
|
|
|
index 8fac1fe..3865931 100644
|
|
|
|
--- a/src/m17nutil.c
|
|
|
|
+++ b/src/m17nutil.c
|
|
|
|
@@ -96,6 +96,13 @@ ibus_m17n_parse_color (const gchar *hex)
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#define DEFAULT_REQUIRES (IBUS_CAP_PREEDIT_TEXT | \
|
|
|
|
+ IBUS_CAP_AUXILIARY_TEXT | \
|
|
|
|
+ IBUS_CAP_LOOKUP_TABLE | \
|
|
|
|
+ IBUS_CAP_FOCUS | \
|
|
|
|
+ IBUS_CAP_PROPERTY | \
|
|
|
|
+ IBUS_CAP_SURROUNDING_TEXT)
|
|
|
|
+
|
|
|
|
static IBusEngineDesc *
|
|
|
|
ibus_m17n_engine_new (MSymbol lang,
|
|
|
|
MSymbol name,
|
|
|
|
@@ -127,6 +134,7 @@ ibus_m17n_engine_new (MSymbol lang,
|
|
|
|
"icon", engine_icon ? engine_icon : "",
|
|
|
|
"layout", "us",
|
|
|
|
"rank", config->rank,
|
|
|
|
+ "requires", DEFAULT_REQUIRES,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (engine_name);
|
2010-10-07 06:15:32 +00:00
|
|
|
--
|
2010-12-22 09:03:38 +00:00
|
|
|
1.7.3.4
|
2010-10-07 06:15:32 +00:00
|
|
|
|