ibus-m17n/ibus-m17n-HEAD.patch

264 lines
8.2 KiB
Diff
Raw Normal View History

2011-06-03 02:36:37 +00:00
diff --git a/Makefile.am b/Makefile.am
index eac3b9d..14a674d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,7 +69,7 @@ debian/changelog:
version=@VERSION@; \
serie=$(serie); \
if test -z "$$serie"; then \
- serie=lucid; \
+ serie=maverick; \
fi; \
if test -z "$$release"; then \
release=1; \
diff --git a/configure.ac b/configure.ac
index 17077f2..4df68b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,7 +89,22 @@ fi
AM_CONDITIONAL([HAVE_GTK],[test x$with_gtk != xno])
# check if minput_list, which is available in m17n-lib 1.6.2+ (CVS)
+save_CFLAGS="$CFLAGS"
+save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $M17N_CFLAGS"
+LIBS="$LIBS $M17N_LIBS"
AC_REPLACE_FUNCS([minput_list])
+CFLAGS="$save_CFLAGS"
+LIBS="$save_LIBS"
+
+# check if ibus_engine_get_surrounding_text, which is available in ibus-1.3.99+ (git master)
+save_CFLAGS="$CFLAGS"
+save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $IBUS_CFLAGS"
+LIBS="$LIBS $IBUS_LIBS"
+AC_CHECK_FUNCS([ibus_engine_get_surrounding_text])
+CFLAGS="$save_CFLAGS"
+LIBS="$save_LIBS"
# define GETTEXT_* variables
GETTEXT_PACKAGE=ibus-m17n
diff --git a/src/engine.c b/src/engine.c
index 62359c1..60816b0 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1,4 +1,7 @@
/* vim:set et sts=4: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <ibus.h>
#include <m17n.h>
@@ -6,23 +9,6 @@
#include "m17nutil.h"
#include "engine.h"
-/* type module to assign different GType to each engine */
-#define IBUS_TYPE_M17N_TYPE_MODULE (ibus_m17n_type_module_get_type ())
-#define IBUS_M17N_TYPE_MODULE (module) (G_TYPE_CHECK_INSTANCE_CAST (module, IBUS_TYPE_M17N_TYPE_MODULE, IBusM17NTypeModule)
-
-typedef struct _IBusM17NTypeModule IBusM17NTypeModule;
-typedef struct _IBusM17NTypeModuleClass IBusM17NTypeModuleClass;
-
-struct _IBusM17NTypeModule
-{
- GTypeModule parent_instance;
-};
-
-struct _IBusM17NTypeModuleClass
-{
- GTypeModuleClass parent_class;
-};
-
typedef struct _IBusM17NEngine IBusM17NEngine;
typedef struct _IBusM17NEngineClass IBusM17NEngineClass;
@@ -53,10 +39,7 @@ struct _IBusM17NEngineClass {
};
/* functions prototype */
-static GType
- ibus_m17n_type_module_get_type (void);
static void ibus_m17n_engine_class_init (IBusM17NEngineClass *klass);
-static void ibus_m17n_engine_class_finalize (IBusM17NEngineClass *klass);
static void ibus_m17n_config_value_changed (IBusConfig *config,
const gchar *section,
const gchar *name,
@@ -119,7 +102,6 @@ static void ibus_m17n_engine_update_lookup_table
static IBusEngineClass *parent_class = NULL;
static IBusConfig *config = NULL;
-static IBusM17NTypeModule *module = NULL;
void
ibus_m17n_init (IBusBus *bus)
@@ -128,55 +110,6 @@ ibus_m17n_init (IBusBus *bus)
if (config)
g_object_ref_sink (config);
ibus_m17n_init_common ();
-
- module = g_object_new (IBUS_TYPE_M17N_TYPE_MODULE, NULL);
-}
-
-static gboolean
-ibus_m17n_type_module_load (GTypeModule *module)
-{
- return TRUE;
-}
-
-static void
-ibus_m17n_type_module_unload (GTypeModule *module)
-{
-}
-
-static void
-ibus_m17n_type_module_class_init (IBusM17NTypeModuleClass *klass)
-{
- GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
-
- module_class->load = ibus_m17n_type_module_load;
- module_class->unload = ibus_m17n_type_module_unload;
-}
-
-static GType
-ibus_m17n_type_module_get_type (void)
-{
- static GType type = 0;
-
- static const GTypeInfo type_info = {
- sizeof (IBusM17NTypeModuleClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) ibus_m17n_type_module_class_init,
- (GClassFinalizeFunc) NULL,
- NULL,
- sizeof (IBusM17NTypeModule),
- 0,
- (GInstanceInitFunc) NULL,
- };
-
- if (type == 0) {
- type = g_type_register_static (G_TYPE_TYPE_MODULE,
- "IBusM17NTypeModule",
- &type_info,
- (GTypeFlags) 0);
- }
-
- return type;
}
static gboolean
@@ -239,14 +172,14 @@ ibus_m17n_engine_get_type_for_name (const gchar *engine_name)
GTypeInfo type_info = {
sizeof (IBusM17NEngineClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) ibus_m17n_engine_class_init,
- (GClassFinalizeFunc)ibus_m17n_engine_class_finalize,
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) ibus_m17n_engine_class_init,
+ (GClassFinalizeFunc) NULL,
NULL,
sizeof (IBusM17NEngine),
0,
- (GInstanceInitFunc) ibus_m17n_engine_init,
+ (GInstanceInitFunc) ibus_m17n_engine_init,
};
if (!ibus_m17n_scan_engine_name (engine_name, &lang, &name)) {
@@ -264,11 +197,10 @@ ibus_m17n_engine_get_type_for_name (const gchar *engine_name)
g_assert (type == 0 || g_type_is_a (type, IBUS_TYPE_ENGINE));
if (type == 0) {
- type = g_type_module_register_type (G_TYPE_MODULE (module),
- IBUS_TYPE_ENGINE,
- type_name,
- &type_info,
- (GTypeFlags) 0);
+ type = g_type_register_static (IBUS_TYPE_ENGINE,
+ type_name,
+ &type_info,
+ (GTypeFlags) 0);
}
g_free (type_name);
@@ -408,14 +340,6 @@ ibus_m17n_config_value_changed (IBusConfig *config,
}
static void
-ibus_m17n_engine_class_finalize (IBusM17NEngineClass *klass)
-{
- if (klass->im)
- minput_close_im (klass->im);
- g_free (klass->config_section);
-}
-
-static void
ibus_m17n_engine_init (IBusM17NEngine *m17n)
{
IBusText* label;
@@ -986,8 +910,57 @@ ibus_m17n_engine_callback (MInputContext *context,
}
else if (command == Minput_reset) {
}
- else if (command == Minput_get_surrounding_text) {
- }
- else if (command == Minput_delete_surrounding_text) {
+ /* ibus_engine_get_surrounding_text is only available in the current
+ git master (1.3.99+) */
+#ifdef HAVE_IBUS_ENGINE_GET_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);
+ }
+#endif /* !HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT */
+ 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);
}
}