|
Packit Service |
1d8f1c |
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
|
Packit Service |
1d8f1c |
/* vim:set et sts=4: */
|
|
Packit Service |
1d8f1c |
/* ibus - The Input Bus
|
|
Packit Service |
1d8f1c |
* Copyright (C) 2014 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit Service |
1d8f1c |
* Copyright (C) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
Packit Service |
1d8f1c |
* Copyright (C) 2014-2017 Red Hat, Inc.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
1d8f1c |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
1d8f1c |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
1d8f1c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
1d8f1c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
1d8f1c |
* Lesser General Public License for more details.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
1d8f1c |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit Service |
1d8f1c |
* USA
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
1d8f1c |
# include "config.h"
|
|
Packit Service |
1d8f1c |
#endif
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#include "ibuscomposetable.h"
|
|
Packit Service |
1d8f1c |
#include "ibusemoji.h"
|
|
Packit Service |
1d8f1c |
#include "ibusenginesimple.h"
|
|
Packit Service |
1d8f1c |
#include "ibusenginesimpleprivate.h"
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#include "ibuskeys.h"
|
|
Packit Service |
1d8f1c |
#include "ibuskeysyms.h"
|
|
Packit Service |
1d8f1c |
#include "ibusutil.h"
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* This file contains the table of the compose sequences,
|
|
Packit Service |
1d8f1c |
* static const guint16 gtk_compose_seqs_compact[] = {}
|
|
Packit Service |
1d8f1c |
* It is generated from the compose-parse.py script.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
#include "gtkimcontextsimpleseqs.h"
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#include <memory.h>
|
|
Packit Service |
1d8f1c |
#include <stdlib.h>
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#define X11_DATADIR X11_DATA_PREFIX "/share/X11/locale"
|
|
Packit Service |
1d8f1c |
#define EMOJI_SOURCE_LEN 100
|
|
Packit Service |
1d8f1c |
#define IBUS_ENGINE_SIMPLE_GET_PRIVATE(o) \
|
|
Packit Service |
1d8f1c |
(G_TYPE_INSTANCE_GET_PRIVATE ((o), IBUS_TYPE_ENGINE_SIMPLE, IBusEngineSimplePrivate))
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#define SET_COMPOSE_BUFFER_ELEMENT_NEXT(buffer, index, value) { \
|
|
Packit Service |
1d8f1c |
if ((index) < EMOJI_SOURCE_LEN) { \
|
|
Packit Service |
1d8f1c |
(buffer)[(index)] = (value); \
|
|
Packit Service |
1d8f1c |
(index) += 1; \
|
|
Packit Service |
1d8f1c |
} \
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#define SET_COMPOSE_BUFFER_ELEMENT_END(buffer, index, value) { \
|
|
Packit Service |
1d8f1c |
if ((index) >= EMOJI_SOURCE_LEN) { \
|
|
Packit Service |
1d8f1c |
(index) = EMOJI_SOURCE_LEN; \
|
|
Packit Service |
1d8f1c |
(buffer)[EMOJI_SOURCE_LEN - 1] = (value); \
|
|
Packit Service |
1d8f1c |
} else { \
|
|
Packit Service |
1d8f1c |
(buffer)[(index)] = (value); \
|
|
Packit Service |
1d8f1c |
} \
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
#define CHECK_COMPOSE_BUFFER_LENGTH(index) { \
|
|
Packit Service |
1d8f1c |
if ((index) > EMOJI_SOURCE_LEN) \
|
|
Packit Service |
1d8f1c |
(index) = EMOJI_SOURCE_LEN; \
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
typedef struct {
|
|
Packit Service |
1d8f1c |
GHashTable *dict;
|
|
Packit Service |
1d8f1c |
int max_seq_len;
|
|
Packit Service |
1d8f1c |
} IBusEngineDict;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
struct _IBusEngineSimplePrivate {
|
|
Packit Service |
1d8f1c |
guint16 compose_buffer[EMOJI_SOURCE_LEN];
|
|
Packit Service |
1d8f1c |
gunichar tentative_match;
|
|
Packit Service |
1d8f1c |
gchar *tentative_emoji;
|
|
Packit Service |
1d8f1c |
gint tentative_match_len;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
guint hex_mode_enabled : 1;
|
|
Packit Service |
1d8f1c |
guint in_hex_sequence : 1;
|
|
Packit Service |
1d8f1c |
guint in_emoji_sequence : 1;
|
|
Packit Service |
1d8f1c |
guint modifiers_dropped : 1;
|
|
Packit Service |
1d8f1c |
IBusEngineDict *emoji_dict;
|
|
Packit Service |
1d8f1c |
IBusLookupTable *lookup_table;
|
|
Packit Service |
1d8f1c |
gboolean lookup_table_visible;
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* From the values below, the value 30 means the number of different first keysyms
|
|
Packit Service |
1d8f1c |
* that exist in the Compose file (from Xorg). When running compose-parse.py without
|
|
Packit Service |
1d8f1c |
* parameters, you get the count that you can put here. Needed when updating the
|
|
Packit Service |
1d8f1c |
* gtkimcontextsimpleseqs.h header file (contains the compose sequences).
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
const IBusComposeTableCompact ibus_compose_table_compact = {
|
|
Packit Service |
1d8f1c |
gtk_compose_seqs_compact,
|
|
Packit Service |
1d8f1c |
5,
|
|
Packit Service |
1d8f1c |
30,
|
|
Packit Service |
1d8f1c |
6
|
|
Packit Service |
1d8f1c |
};
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static GSList *global_tables;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* functions prototype */
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_destroy (IBusEngineSimple *simple);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_reset (IBusEngine *engine);
|
|
Packit Service |
1d8f1c |
static gboolean ibus_engine_simple_process_key_event
|
|
Packit Service |
1d8f1c |
(IBusEngine *engine,
|
|
Packit Service |
1d8f1c |
guint keyval,
|
|
Packit Service |
1d8f1c |
guint keycode,
|
|
Packit Service |
1d8f1c |
guint modifiers);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_page_down (IBusEngine *engine);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_page_up (IBusEngine *engine);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_candidate_clicked
|
|
Packit Service |
1d8f1c |
(IBusEngine *engine,
|
|
Packit Service |
1d8f1c |
guint index,
|
|
Packit Service |
1d8f1c |
guint button,
|
|
Packit Service |
1d8f1c |
guint state);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_commit_char (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
gunichar ch);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_commit_str (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const gchar *str);
|
|
Packit Service |
1d8f1c |
static void ibus_engine_simple_update_preedit_text
|
|
Packit Service |
1d8f1c |
(IBusEngineSimple *simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
G_DEFINE_TYPE (IBusEngineSimple, ibus_engine_simple, IBUS_TYPE_ENGINE)
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_class_init (IBusEngineSimpleClass *class)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (class);
|
|
Packit Service |
1d8f1c |
IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (class);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_object_class->destroy =
|
|
Packit Service |
1d8f1c |
(IBusObjectDestroyFunc) ibus_engine_simple_destroy;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
engine_class->reset = ibus_engine_simple_reset;
|
|
Packit Service |
1d8f1c |
engine_class->process_key_event
|
|
Packit Service |
1d8f1c |
= ibus_engine_simple_process_key_event;
|
|
Packit Service |
1d8f1c |
engine_class->page_down = ibus_engine_simple_page_down;
|
|
Packit Service |
1d8f1c |
engine_class->page_up = ibus_engine_simple_page_up;
|
|
Packit Service |
1d8f1c |
engine_class->candidate_clicked
|
|
Packit Service |
1d8f1c |
= ibus_engine_simple_candidate_clicked;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_type_class_add_private (class, sizeof (IBusEngineSimplePrivate));
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_init (IBusEngineSimple *simple)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
simple->priv = IBUS_ENGINE_SIMPLE_GET_PRIVATE (simple);
|
|
Packit Service |
1d8f1c |
simple->priv->hex_mode_enabled =
|
|
Packit Service |
1d8f1c |
g_getenv("IBUS_ENABLE_CTRL_SHIFT_U") != NULL ||
|
|
Packit Service |
1d8f1c |
g_getenv("IBUS_ENABLE_CONTROL_SHIFT_U") != NULL;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_destroy (IBusEngineSimple *simple)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->emoji_dict) {
|
|
Packit Service |
1d8f1c |
if (priv->emoji_dict->dict)
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->emoji_dict->dict, g_hash_table_destroy);
|
|
Packit Service |
1d8f1c |
g_slice_free (IBusEngineDict, priv->emoji_dict);
|
|
Packit Service |
1d8f1c |
priv->emoji_dict = NULL;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->lookup_table, g_object_unref);
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
IBUS_OBJECT_CLASS(ibus_engine_simple_parent_class)->destroy (
|
|
Packit Service |
1d8f1c |
IBUS_OBJECT (simple));
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_reset (IBusEngine *engine)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimple *simple = (IBusEngineSimple *)engine;
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match || priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_hide_preedit_text ((IBusEngine *)simple);
|
|
Packit Service |
1d8f1c |
} else if (priv->tentative_emoji || priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
ibus_engine_hide_preedit_text ((IBusEngine *)simple);
|
|
Packit Service |
1d8f1c |
} else if (!priv->in_hex_sequence && !priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
ibus_engine_hide_preedit_text ((IBusEngine *)simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
gunichar ch)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
g_return_if_fail (g_unichar_validate (ch));
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match || priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji || priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
ibus_engine_commit_text ((IBusEngine *)simple,
|
|
Packit Service |
1d8f1c |
ibus_text_new_from_unichar (ch));
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gunichar
|
|
Packit Service |
1d8f1c |
ibus_keysym_to_unicode (guint16 keysym,
|
|
Packit Service |
1d8f1c |
gboolean combining) {
|
|
Packit Service |
1d8f1c |
#define CASE(keysym_suffix, unicode) \
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_dead_##keysym_suffix: return unicode
|
|
Packit Service |
1d8f1c |
#define CASE_COMBINE(keysym_suffix, combined_unicode, isolated_unicode) \
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_dead_##keysym_suffix: \
|
|
Packit Service |
1d8f1c |
if (combining) \
|
|
Packit Service |
1d8f1c |
return combined_unicode; \
|
|
Packit Service |
1d8f1c |
else \
|
|
Packit Service |
1d8f1c |
return isolated_unicode
|
|
Packit Service |
1d8f1c |
switch (keysym) {
|
|
Packit Service |
1d8f1c |
CASE (a, 0x03041);
|
|
Packit Service |
1d8f1c |
CASE (A, 0x03042);
|
|
Packit Service |
1d8f1c |
CASE (i, 0x03043);
|
|
Packit Service |
1d8f1c |
CASE (I, 0x03044);
|
|
Packit Service |
1d8f1c |
CASE (u, 0x03045);
|
|
Packit Service |
1d8f1c |
CASE (U, 0x03046);
|
|
Packit Service |
1d8f1c |
CASE (e, 0x03047);
|
|
Packit Service |
1d8f1c |
CASE (E, 0x03048);
|
|
Packit Service |
1d8f1c |
CASE (o, 0x03049);
|
|
Packit Service |
1d8f1c |
CASE (O, 0x0304A);
|
|
Packit Service |
1d8f1c |
CASE (abovecomma, 0x0313);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (abovedot, 0x0307, 0x02D9);
|
|
Packit Service |
1d8f1c |
CASE (abovereversedcomma, 0x0314);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (abovering, 0x030A, 0x02DA);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (acute, 0x0301, 0x00B4);
|
|
Packit Service |
1d8f1c |
CASE (belowbreve, 0x032E);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowcircumflex, 0x032D, 0xA788);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowcomma, 0x0326, 0x002C);
|
|
Packit Service |
1d8f1c |
CASE (belowdiaeresis, 0x0324);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowdot, 0x0323, 0x002E);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowmacron, 0x0331, 0x02CD);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowring, 0x030A, 0x02F3);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (belowtilde, 0x0330, 0x02F7);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (breve, 0x0306, 0x02D8);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (capital_schwa, 0x018F, 0x04D8);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (caron, 0x030C, 0x02C7);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (cedilla, 0x0327, 0x00B8);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (circumflex, 0x0302, 0x005E);
|
|
Packit Service |
1d8f1c |
CASE (currency, 0x00A4);
|
|
Packit Service |
1d8f1c |
// IBUS_KEY_dead_dasia == IBUS_KEY_dead_abovereversedcomma
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (diaeresis, 0x0308, 0x00A8);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (doubleacute, 0x030B, 0x02DD);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (doublegrave, 0x030F, 0x02F5);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (grave, 0x0300, 0x0060);
|
|
Packit Service |
1d8f1c |
CASE (greek, 0x03BC);
|
|
Packit Service |
1d8f1c |
CASE (hook, 0x0309);
|
|
Packit Service |
1d8f1c |
CASE (horn, 0x031B);
|
|
Packit Service |
1d8f1c |
CASE (invertedbreve, 0x032F);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (iota, 0x0345, 0x037A);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (macron, 0x0304, 0x00AF);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (ogonek, 0x0328, 0x02DB);
|
|
Packit Service |
1d8f1c |
// IBUS_KEY_dead_perispomeni == IBUS_KEY_dead_tilde
|
|
Packit Service |
1d8f1c |
// IBUS_KEY_dead_psili == IBUS_KEY_dead_abovecomma
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (semivoiced_sound, 0x309A, 0x309C);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (small_schwa, 0x1D4A, 0x04D9);
|
|
Packit Service |
1d8f1c |
CASE (stroke, 0x002F);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (tilde, 0x0303, 0x007E);
|
|
Packit Service |
1d8f1c |
CASE_COMBINE (voiced_sound, 0x3099, 0x309B);
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_Multi_key:
|
|
Packit Service |
1d8f1c |
return 0x2384;
|
|
Packit Service |
1d8f1c |
default:;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return 0x0;
|
|
Packit Service |
1d8f1c |
#undef CASE
|
|
Packit Service |
1d8f1c |
#undef CASE_COMBINE
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const gchar *str)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
gchar *backup_str;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_return_if_fail (str && *str);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
backup_str = g_strdup (str);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match || priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji || priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_commit_text ((IBusEngine *)simple,
|
|
Packit Service |
1d8f1c |
ibus_text_new_from_string (backup_str));
|
|
Packit Service |
1d8f1c |
g_free (backup_str);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (IBusEngineSimple *simple)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gunichar outbuf[EMOJI_SOURCE_LEN + 1];
|
|
Packit Service |
1d8f1c |
int len = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence || priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
int hexchars = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence)
|
|
Packit Service |
1d8f1c |
outbuf[0] = L'u';
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
outbuf[0] = L'@';
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
len = 1;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
while (priv->compose_buffer[hexchars] != 0) {
|
|
Packit Service |
1d8f1c |
outbuf[len] = ibus_keyval_to_unicode (
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[hexchars]);
|
|
Packit Service |
1d8f1c |
++len;
|
|
Packit Service |
1d8f1c |
++hexchars;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence)
|
|
Packit Service |
1d8f1c |
g_assert (len <= IBUS_MAX_COMPOSE_LEN + 1);
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
g_assert (len <= EMOJI_SOURCE_LEN + 1);
|
|
Packit Service |
1d8f1c |
} else if (priv->tentative_match) {
|
|
Packit Service |
1d8f1c |
outbuf[len++] = priv->tentative_match;
|
|
Packit Service |
1d8f1c |
} else if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
IBusText *text = ibus_text_new_from_string (priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
len = strlen (priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
ibus_text_append_attribute (text,
|
|
Packit Service |
1d8f1c |
IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, len);
|
|
Packit Service |
1d8f1c |
ibus_engine_update_preedit_text ((IBusEngine *)simple, text, len, TRUE);
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
int hexchars = 0;
|
|
Packit Service |
1d8f1c |
while (priv->compose_buffer[hexchars] != 0) {
|
|
Packit Service |
1d8f1c |
guint16 keysym= priv->compose_buffer[hexchars];
|
|
Packit Service |
1d8f1c |
gunichar unichar = ibus_keysym_to_unicode (keysym, FALSE);
|
|
Packit Service |
1d8f1c |
if (unichar > 0)
|
|
Packit Service |
1d8f1c |
outbuf[len] = unichar;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
outbuf[len] = ibus_keyval_to_unicode (keysym);
|
|
Packit Service |
1d8f1c |
if (!outbuf[len]) {
|
|
Packit Service |
1d8f1c |
g_warning (
|
|
Packit Service |
1d8f1c |
"Not found alternative character of compose key 0x%X",
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[hexchars]);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
++len;
|
|
Packit Service |
1d8f1c |
++hexchars;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
g_assert (len <= IBUS_MAX_COMPOSE_LEN + 1);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
outbuf[len] = L'\0';
|
|
Packit Service |
1d8f1c |
if (len == 0) {
|
|
Packit Service |
1d8f1c |
ibus_engine_hide_preedit_text ((IBusEngine *)simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else {
|
|
Packit Service |
1d8f1c |
IBusText *text = ibus_text_new_from_ucs4 (outbuf);
|
|
Packit Service |
1d8f1c |
ibus_text_append_attribute (text,
|
|
Packit Service |
1d8f1c |
IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, len);
|
|
Packit Service |
1d8f1c |
ibus_engine_update_preedit_text ((IBusEngine *)simple, text, len, TRUE);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* In addition to the table-driven sequences, we allow Unicode hex
|
|
Packit Service |
1d8f1c |
* codes to be entered. The method chosen here is similar to the
|
|
Packit Service |
1d8f1c |
* one recommended in ISO 14755, but not exactly the same, since we
|
|
Packit Service |
1d8f1c |
* don't want to steal 16 valuable key combinations.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* A hex Unicode sequence must be started with Ctrl-Shift-U, followed
|
|
Packit Service |
1d8f1c |
* by a sequence of hex digits entered with Ctrl-Shift still held.
|
|
Packit Service |
1d8f1c |
* Releasing one of the modifiers or pressing space while the modifiers
|
|
Packit Service |
1d8f1c |
* are still held commits the character. It is possible to erase
|
|
Packit Service |
1d8f1c |
* digits using backspace.
|
|
Packit Service |
1d8f1c |
*
|
|
Packit Service |
1d8f1c |
* As an extension to the above, we also allow to start the sequence
|
|
Packit Service |
1d8f1c |
* with Ctrl-Shift-U, then release the modifiers before typing any
|
|
Packit Service |
1d8f1c |
* digits, and enter the digits without modifiers.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
#define HEX_MOD_MASK (IBUS_CONTROL_MASK | IBUS_SHIFT_MASK)
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
check_hex (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
gint n_compose)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
GString *str;
|
|
Packit Service |
1d8f1c |
gulong n;
|
|
Packit Service |
1d8f1c |
gchar *nptr = NULL;
|
|
Packit Service |
1d8f1c |
gchar buf[7];
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
str = g_string_new (NULL);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
i = 0;
|
|
Packit Service |
1d8f1c |
while (i < n_compose) {
|
|
Packit Service |
1d8f1c |
gunichar ch;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ch = ibus_keyval_to_unicode (priv->compose_buffer[i]);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (ch == 0)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (!g_unichar_isxdigit (ch))
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
buf[g_unichar_to_utf8 (ch, buf)] = '\0';
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_string_append (str, buf);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
++i;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
n = strtoul (str->str, &nptr, 16);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* if strtoul fails it probably means non-latin digits were used;
|
|
Packit Service |
1d8f1c |
* we should in principle handle that, but we probably don't.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
if (nptr - str->str < str->len) {
|
|
Packit Service |
1d8f1c |
g_string_free (str, TRUE);
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
} else
|
|
Packit Service |
1d8f1c |
g_string_free (str, TRUE);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (g_unichar_validate (n)) {
|
|
Packit Service |
1d8f1c |
priv->tentative_match = n;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = n_compose;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static IBusEngineDict *
|
|
Packit Service |
1d8f1c |
load_emoji_dict ()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineDict *emoji_dict;
|
|
Packit Service |
1d8f1c |
GList *keys;
|
|
Packit Service |
1d8f1c |
int max_length = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
emoji_dict = g_slice_new0 (IBusEngineDict);
|
|
Packit Service |
1d8f1c |
emoji_dict->dict = ibus_emoji_dict_load (IBUS_DATA_DIR "/dicts/emoji.dict");
|
|
Packit Service |
1d8f1c |
if (!emoji_dict->dict)
|
|
Packit Service |
1d8f1c |
return emoji_dict;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
keys = g_hash_table_get_keys (emoji_dict->dict);
|
|
Packit Service |
1d8f1c |
for (; keys; keys = keys->next) {
|
|
Packit Service |
1d8f1c |
int length = strlen (keys->data);
|
|
Packit Service |
1d8f1c |
if (max_length < length)
|
|
Packit Service |
1d8f1c |
max_length = length;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
emoji_dict->max_seq_len = max_length;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return emoji_dict;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
check_emoji_table (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
gint n_compose,
|
|
Packit Service |
1d8f1c |
gint index)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
IBusEngineDict *emoji_dict = priv->emoji_dict;
|
|
Packit Service |
1d8f1c |
GString *str = NULL;
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
gchar buf[7];
|
|
Packit Service |
1d8f1c |
GSList *words = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_assert (IBUS_IS_ENGINE_SIMPLE (simple));
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table == NULL) {
|
|
Packit Service |
1d8f1c |
priv->lookup_table = ibus_lookup_table_new (10, 0, TRUE, TRUE);
|
|
Packit Service |
1d8f1c |
g_object_ref_sink (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (emoji_dict == NULL)
|
|
Packit Service |
1d8f1c |
emoji_dict = priv->emoji_dict = load_emoji_dict (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (emoji_dict == NULL || emoji_dict->dict == NULL)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (n_compose > emoji_dict->max_seq_len)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
str = g_string_new (NULL);
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
i = 0;
|
|
Packit Service |
1d8f1c |
while (i < n_compose) {
|
|
Packit Service |
1d8f1c |
gunichar ch;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ch = ibus_keyval_to_unicode (priv->compose_buffer[i]);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (ch == 0)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (!g_unichar_isprint (ch))
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
buf[g_unichar_to_utf8 (ch, buf)] = '\0';
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_string_append (str, buf);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
++i;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (str->str) {
|
|
Packit Service |
1d8f1c |
words = g_hash_table_lookup (emoji_dict->dict, str->str);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
g_string_free (str, TRUE);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (words != NULL) {
|
|
Packit Service |
1d8f1c |
int i = 0;
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_clear (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = TRUE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
while (words) {
|
|
Packit Service |
1d8f1c |
if (i == index) {
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->tentative_emoji = g_strdup (words->data);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
IBusText *text = ibus_text_new_from_string (words->data);
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_append_candidate (priv->lookup_table, text);
|
|
Packit Service |
1d8f1c |
words = words->next;
|
|
Packit Service |
1d8f1c |
i++;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static int
|
|
Packit Service |
1d8f1c |
compare_seq_index (const void *key, const void *value)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
const guint16 *keysyms = key;
|
|
Packit Service |
1d8f1c |
const guint16 *seq = value;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (keysyms[0] < seq[0])
|
|
Packit Service |
1d8f1c |
return -1;
|
|
Packit Service |
1d8f1c |
else if (keysyms[0] > seq[0])
|
|
Packit Service |
1d8f1c |
return 1;
|
|
Packit Service |
1d8f1c |
return 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static int
|
|
Packit Service |
1d8f1c |
compare_seq (const void *key, const void *value)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
int i = 0;
|
|
Packit Service |
1d8f1c |
const guint16 *keysyms = key;
|
|
Packit Service |
1d8f1c |
const guint16 *seq = value;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
while (keysyms[i]) {
|
|
Packit Service |
1d8f1c |
if (keysyms[i] < seq[i])
|
|
Packit Service |
1d8f1c |
return -1;
|
|
Packit Service |
1d8f1c |
else if (keysyms[i] > seq[i])
|
|
Packit Service |
1d8f1c |
return 1;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
i++;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
check_table (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const IBusComposeTable *table,
|
|
Packit Service |
1d8f1c |
gint n_compose)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
// g_debug("check_table");
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
gint row_stride = table->max_seq_len + 2;
|
|
Packit Service |
1d8f1c |
guint16 *seq;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_assert (IBUS_IS_ENGINE_SIMPLE (simple));
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (n_compose > table->max_seq_len)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
seq = bsearch (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
table->data, table->n_seqs,
|
|
Packit Service |
1d8f1c |
sizeof (guint16) * row_stride,
|
|
Packit Service |
1d8f1c |
compare_seq);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (seq == NULL)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
guint16 *prev_seq;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Back up to the first sequence that matches to make sure
|
|
Packit Service |
1d8f1c |
* we find the exact match if their is one.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
while (seq > table->data) {
|
|
Packit Service |
1d8f1c |
prev_seq = seq - row_stride;
|
|
Packit Service |
1d8f1c |
if (compare_seq (priv->compose_buffer, prev_seq) != 0) {
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
seq = prev_seq;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* complete sequence */
|
|
Packit Service |
1d8f1c |
if (n_compose == table->max_seq_len || seq[n_compose] == 0) {
|
|
Packit Service |
1d8f1c |
guint16 *next_seq;
|
|
Packit Service |
1d8f1c |
gunichar value =
|
|
Packit Service |
1d8f1c |
0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* We found a tentative match. See if there are any longer
|
|
Packit Service |
1d8f1c |
* sequences containing this subsequence
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
next_seq = seq + row_stride;
|
|
Packit Service |
1d8f1c |
if (next_seq < table->data + row_stride * table->n_seqs) {
|
|
Packit Service |
1d8f1c |
if (compare_seq (priv->compose_buffer, next_seq) == 0) {
|
|
Packit Service |
1d8f1c |
priv->tentative_match = value;
|
|
Packit Service |
1d8f1c |
priv->tentative_match_len = n_compose;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, value);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
// g_debug ("U+%04X\n", value);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gboolean
|
|
Packit Service |
1d8f1c |
ibus_check_compact_table (const IBusComposeTableCompact *table,
|
|
Packit Service |
1d8f1c |
guint16 *compose_buffer,
|
|
Packit Service |
1d8f1c |
gint n_compose,
|
|
Packit Service |
1d8f1c |
gboolean *compose_finish,
|
|
Packit Service |
1d8f1c |
gunichar *output_char)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
gint row_stride;
|
|
Packit Service |
1d8f1c |
guint16 *seq_index;
|
|
Packit Service |
1d8f1c |
guint16 *seq;
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (compose_finish)
|
|
Packit Service |
1d8f1c |
*compose_finish = FALSE;
|
|
Packit Service |
1d8f1c |
if (output_char)
|
|
Packit Service |
1d8f1c |
*output_char = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Will never match, if the sequence in the compose buffer is longer
|
|
Packit Service |
1d8f1c |
* than the sequences in the table. Further, compare_seq (key, val)
|
|
Packit Service |
1d8f1c |
* will overrun val if key is longer than val. */
|
|
Packit Service |
1d8f1c |
if (n_compose > table->max_seq_len)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// g_debug ("check_compact_table(n_compose=%d) [%04x, %04x, %04x, %04x]",
|
|
Packit Service |
1d8f1c |
// n_compose,
|
|
Packit Service |
1d8f1c |
// compose_buffer[0],
|
|
Packit Service |
1d8f1c |
// compose_buffer[1],
|
|
Packit Service |
1d8f1c |
// compose_buffer[2],
|
|
Packit Service |
1d8f1c |
// compose_buffer[3]);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
seq_index = bsearch (compose_buffer,
|
|
Packit Service |
1d8f1c |
table->data,
|
|
Packit Service |
1d8f1c |
table->n_index_size,
|
|
Packit Service |
1d8f1c |
sizeof (guint16) * table->n_index_stride,
|
|
Packit Service |
1d8f1c |
compare_seq_index);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (seq_index == NULL) {
|
|
Packit Service |
1d8f1c |
// g_debug ("compact: no\n");
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (n_compose == 1) {
|
|
Packit Service |
1d8f1c |
// g_debug ("compact: yes\n");
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// g_debug ("compact: %04x ", *seq_index);
|
|
Packit Service |
1d8f1c |
seq = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (i = n_compose - 1; i < table->max_seq_len; i++) {
|
|
Packit Service |
1d8f1c |
row_stride = i + 1;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (seq_index[i + 1] - seq_index[i] > 0) {
|
|
Packit Service |
1d8f1c |
seq = bsearch (compose_buffer + 1,
|
|
Packit Service |
1d8f1c |
table->data + seq_index[i],
|
|
Packit Service |
1d8f1c |
(seq_index[i + 1] - seq_index[i]) / row_stride,
|
|
Packit Service |
1d8f1c |
sizeof (guint16) * row_stride,
|
|
Packit Service |
1d8f1c |
compare_seq);
|
|
Packit Service |
1d8f1c |
// g_debug ("seq = %p", seq);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (seq) {
|
|
Packit Service |
1d8f1c |
if (i == n_compose - 1)
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (!seq) {
|
|
Packit Service |
1d8f1c |
// g_debug ("no\n");
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else {
|
|
Packit Service |
1d8f1c |
if (compose_finish)
|
|
Packit Service |
1d8f1c |
*compose_finish = TRUE;
|
|
Packit Service |
1d8f1c |
if (output_char)
|
|
Packit Service |
1d8f1c |
*output_char = seq[row_stride - 1];
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// g_debug ("U+%04X\n", value);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Checks if a keysym is a dead key. Dead key keysym values are defined in
|
|
Packit Service |
1d8f1c |
* ../gdk/gdkkeysyms.h and the first is GDK_KEY_dead_grave. As X.Org is updated,
|
|
Packit Service |
1d8f1c |
* more dead keys are added and we need to update the upper limit.
|
|
Packit Service |
1d8f1c |
* Currently, the upper limit is GDK_KEY_dead_dasia+1. The +1 has to do with
|
|
Packit Service |
1d8f1c |
* a temporary issue in the X.Org header files.
|
|
Packit Service |
1d8f1c |
* In future versions it will be just the keysym (no +1).
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
#define IS_DEAD_KEY(k) \
|
|
Packit Service |
1d8f1c |
((k) >= IBUS_KEY_dead_grave && (k) <= (IBUS_KEY_dead_dasia + 1))
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* This function receives a sequence of Unicode characters and tries to
|
|
Packit Service |
1d8f1c |
* normalize it (NFC). We check for the case the the resulting string
|
|
Packit Service |
1d8f1c |
* has length 1 (single character).
|
|
Packit Service |
1d8f1c |
* NFC normalisation normally rearranges diacritic marks, unless these
|
|
Packit Service |
1d8f1c |
* belong to the same Canonical Combining Class.
|
|
Packit Service |
1d8f1c |
* If they belong to the same canonical combining class, we produce all
|
|
Packit Service |
1d8f1c |
* permutations of the diacritic marks, then attempt to normalize.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
check_normalize_nfc (gunichar* combination_buffer, gint n_compose)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
gunichar combination_buffer_temp[IBUS_MAX_COMPOSE_LEN];
|
|
Packit Service |
1d8f1c |
gchar *combination_utf8_temp = NULL;
|
|
Packit Service |
1d8f1c |
gchar *nfc_temp = NULL;
|
|
Packit Service |
1d8f1c |
gint n_combinations;
|
|
Packit Service |
1d8f1c |
gunichar temp_swap;
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
n_combinations = 1;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (i = 1; i < n_compose; i++ )
|
|
Packit Service |
1d8f1c |
n_combinations *= i;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Xorg reuses dead_tilde for the perispomeni diacritic mark.
|
|
Packit Service |
1d8f1c |
* We check if base character belongs to Greek Unicode block,
|
|
Packit Service |
1d8f1c |
* and if so, we replace tilde with perispomeni. */
|
|
Packit Service |
1d8f1c |
if (combination_buffer[0] >= 0x390 && combination_buffer[0] <= 0x3FF) {
|
|
Packit Service |
1d8f1c |
for (i = 1; i < n_compose; i++ )
|
|
Packit Service |
1d8f1c |
if (combination_buffer[i] == 0x303)
|
|
Packit Service |
1d8f1c |
combination_buffer[i] = 0x342;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
memcpy (combination_buffer_temp,
|
|
Packit Service |
1d8f1c |
combination_buffer,
|
|
Packit Service |
1d8f1c |
IBUS_MAX_COMPOSE_LEN * sizeof (gunichar) );
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (i = 0; i < n_combinations; i++ ) {
|
|
Packit Service |
1d8f1c |
g_unicode_canonical_ordering (combination_buffer_temp, n_compose);
|
|
Packit Service |
1d8f1c |
combination_utf8_temp = g_ucs4_to_utf8 (combination_buffer_temp, -1, NULL, NULL, NULL);
|
|
Packit Service |
1d8f1c |
nfc_temp = g_utf8_normalize (combination_utf8_temp, -1, G_NORMALIZE_NFC);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (g_utf8_strlen (nfc_temp, -1) == 1) {
|
|
Packit Service |
1d8f1c |
memcpy (combination_buffer,
|
|
Packit Service |
1d8f1c |
combination_buffer_temp,
|
|
Packit Service |
1d8f1c |
IBUS_MAX_COMPOSE_LEN * sizeof (gunichar) );
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_free (combination_utf8_temp);
|
|
Packit Service |
1d8f1c |
g_free (nfc_temp);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_free (combination_utf8_temp);
|
|
Packit Service |
1d8f1c |
g_free (nfc_temp);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (n_compose > 2) {
|
|
Packit Service |
1d8f1c |
gint j = i % (n_compose - 1) + 1;
|
|
Packit Service |
1d8f1c |
gint k = (i+1) % (n_compose - 1) + 1;
|
|
Packit Service |
1d8f1c |
if (j >= IBUS_MAX_COMPOSE_LEN) {
|
|
Packit Service |
1d8f1c |
g_warning ("j >= IBUS_MAX_COMPOSE_LEN for " \
|
|
Packit Service |
1d8f1c |
"combination_buffer_temp");
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (k >= IBUS_MAX_COMPOSE_LEN) {
|
|
Packit Service |
1d8f1c |
g_warning ("k >= IBUS_MAX_COMPOSE_LEN for " \
|
|
Packit Service |
1d8f1c |
"combination_buffer_temp");
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
temp_swap = combination_buffer_temp[j];
|
|
Packit Service |
1d8f1c |
combination_buffer_temp[j] = combination_buffer_temp[k];
|
|
Packit Service |
1d8f1c |
combination_buffer_temp[k] = temp_swap;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gboolean
|
|
Packit Service |
1d8f1c |
ibus_check_algorithmically (const guint16 *compose_buffer,
|
|
Packit Service |
1d8f1c |
gint n_compose,
|
|
Packit Service |
1d8f1c |
gunichar *output_char)
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
gunichar combination_buffer[IBUS_MAX_COMPOSE_LEN];
|
|
Packit Service |
1d8f1c |
gchar *combination_utf8, *nfc;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (output_char)
|
|
Packit Service |
1d8f1c |
*output_char = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (n_compose >= IBUS_MAX_COMPOSE_LEN)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (i = 0; i < n_compose && IS_DEAD_KEY (compose_buffer[i]); i++)
|
|
Packit Service |
1d8f1c |
;
|
|
Packit Service |
1d8f1c |
if (i == n_compose)
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (i > 0 && i == n_compose - 1) {
|
|
Packit Service |
1d8f1c |
combination_buffer[0] = ibus_keyval_to_unicode (compose_buffer[i]);
|
|
Packit Service |
1d8f1c |
combination_buffer[n_compose] = 0;
|
|
Packit Service |
1d8f1c |
i--;
|
|
Packit Service |
1d8f1c |
while (i >= 0) {
|
|
Packit Service |
1d8f1c |
combination_buffer[i+1] = ibus_keysym_to_unicode (compose_buffer[i],
|
|
Packit Service |
1d8f1c |
TRUE);
|
|
Packit Service |
1d8f1c |
if (!combination_buffer[i+1]) {
|
|
Packit Service |
1d8f1c |
combination_buffer[i+1] =
|
|
Packit Service |
1d8f1c |
ibus_keyval_to_unicode (compose_buffer[i]);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
i--;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* If the buffer normalizes to a single character,
|
|
Packit Service |
1d8f1c |
* then modify the order of combination_buffer accordingly, if necessary,
|
|
Packit Service |
1d8f1c |
* and return TRUE.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
if (check_normalize_nfc (combination_buffer, n_compose)) {
|
|
Packit Service |
1d8f1c |
combination_utf8 = g_ucs4_to_utf8 (combination_buffer, -1, NULL, NULL, NULL);
|
|
Packit Service |
1d8f1c |
nfc = g_utf8_normalize (combination_utf8, -1, G_NORMALIZE_NFC);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (output_char)
|
|
Packit Service |
1d8f1c |
*output_char = g_utf8_get_char (nfc);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_free (combination_utf8);
|
|
Packit Service |
1d8f1c |
g_free (nfc);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
no_sequence_matches (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
gint n_compose,
|
|
Packit Service |
1d8f1c |
guint keyval,
|
|
Packit Service |
1d8f1c |
guint keycode,
|
|
Packit Service |
1d8f1c |
guint modifiers)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gunichar ch;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* No compose sequences found, check first if we have a partial
|
|
Packit Service |
1d8f1c |
* match pending.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match) {
|
|
Packit Service |
1d8f1c |
gint len = priv->tentative_match_len;
|
|
Packit Service |
1d8f1c |
int i;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, priv->tentative_match);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (i=0; i < n_compose - len - 1; i++) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_process_key_event (
|
|
Packit Service |
1d8f1c |
(IBusEngine *)simple,
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[len + i],
|
|
Packit Service |
1d8f1c |
0, 0);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return ibus_engine_simple_process_key_event (
|
|
Packit Service |
1d8f1c |
(IBusEngine *)simple, keyval, keycode, modifiers);
|
|
Packit Service |
1d8f1c |
} else if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (simple, priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
if (n_compose > 1) {
|
|
Packit Service |
1d8f1c |
/* Invalid sequence */
|
|
Packit Service |
1d8f1c |
// FIXME beep_window (event->window);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
ch = ibus_keyval_to_unicode (keyval);
|
|
Packit Service |
1d8f1c |
/* IBUS_CHANGE: RH#769133
|
|
Packit Service |
1d8f1c |
* Since we use ibus xkb engines as the disable state,
|
|
Packit Service |
1d8f1c |
* do not commit the characters locally without in_hex_sequence. */
|
|
Packit Service |
1d8f1c |
if (ch != 0 && !g_unichar_iscntrl (ch) &&
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
is_hex_keyval (guint keyval)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
gunichar ch = ibus_keyval_to_unicode (keyval);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return g_unichar_isxdigit (ch);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
is_graph_keyval (guint keyval)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
gunichar ch = ibus_keyval_to_unicode (keyval);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return g_unichar_isgraph (ch);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (IBusEngineSimple *simple)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv;
|
|
Packit Service |
1d8f1c |
guint index, candidates;
|
|
Packit Service |
1d8f1c |
gchar *aux_label = NULL;
|
|
Packit Service |
1d8f1c |
IBusText *text = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_return_if_fail (IBUS_IS_ENGINE_SIMPLE (simple));
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
priv = simple->priv;
|
|
Packit Service |
1d8f1c |
index = ibus_lookup_table_get_cursor_pos (priv->lookup_table) + 1;
|
|
Packit Service |
1d8f1c |
candidates = ibus_lookup_table_get_number_of_candidates(priv->lookup_table);
|
|
Packit Service |
1d8f1c |
aux_label = g_strdup_printf ("(%u / %u)", index, candidates);
|
|
Packit Service |
1d8f1c |
text = ibus_text_new_from_string (aux_label);
|
|
Packit Service |
1d8f1c |
g_free (aux_label);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_update_auxiliary_text (IBUS_ENGINE (simple),
|
|
Packit Service |
1d8f1c |
text,
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible);
|
|
Packit Service |
1d8f1c |
ibus_engine_update_lookup_table (IBUS_ENGINE (simple),
|
|
Packit Service |
1d8f1c |
priv->lookup_table,
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_if_in_range_of_lookup_table (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
guint keyval)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv;
|
|
Packit Service |
1d8f1c |
int index, candidates, cursor_pos, cursor_in_page, page_size;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table == NULL || !priv->lookup_table_visible)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
if (keyval < IBUS_KEY_0 || keyval > IBUS_KEY_9)
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
if (keyval == IBUS_KEY_0)
|
|
Packit Service |
1d8f1c |
keyval = IBUS_KEY_9 + 1;
|
|
Packit Service |
1d8f1c |
index = keyval - IBUS_KEY_1;
|
|
Packit Service |
1d8f1c |
candidates =
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_get_number_of_candidates (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
cursor_pos = ibus_lookup_table_get_cursor_pos (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
cursor_in_page = ibus_lookup_table_get_cursor_in_page (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
page_size = ibus_lookup_table_get_page_size (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
if (index > ((candidates - (cursor_pos - cursor_in_page)) % page_size))
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_set_number_on_lookup_table (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
guint keyval,
|
|
Packit Service |
1d8f1c |
int n_compose)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv;
|
|
Packit Service |
1d8f1c |
int index, cursor_pos, cursor_in_page, real_index;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
priv = simple->priv;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (keyval == IBUS_KEY_0)
|
|
Packit Service |
1d8f1c |
keyval = IBUS_KEY_9 + 1;
|
|
Packit Service |
1d8f1c |
index = keyval - IBUS_KEY_1;
|
|
Packit Service |
1d8f1c |
cursor_pos = ibus_lookup_table_get_cursor_pos (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
cursor_in_page = ibus_lookup_table_get_cursor_in_page (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
real_index = cursor_pos - cursor_in_page + index;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_set_cursor_pos (priv->lookup_table, real_index);
|
|
Packit Service |
1d8f1c |
check_emoji_table (simple, n_compose, real_index);
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (simple, priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static gboolean
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_process_key_event (IBusEngine *engine,
|
|
Packit Service |
1d8f1c |
guint keyval,
|
|
Packit Service |
1d8f1c |
guint keycode,
|
|
Packit Service |
1d8f1c |
guint modifiers)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimple *simple = (IBusEngineSimple *)engine;
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
gint n_compose = 0;
|
|
Packit Service |
1d8f1c |
gboolean have_hex_mods;
|
|
Packit Service |
1d8f1c |
gboolean is_hex_start = FALSE;
|
|
Packit Service |
1d8f1c |
gboolean is_emoji_start = FALSE;
|
|
Packit Service |
1d8f1c |
gboolean is_hex_end;
|
|
Packit Service |
1d8f1c |
gboolean is_space;
|
|
Packit Service |
1d8f1c |
gboolean is_backspace;
|
|
Packit Service |
1d8f1c |
gboolean is_escape;
|
|
Packit Service |
1d8f1c |
guint hex_keyval;
|
|
Packit Service |
1d8f1c |
guint printable_keyval;
|
|
Packit Service |
1d8f1c |
gint i;
|
|
Packit Service |
1d8f1c |
gboolean compose_finish;
|
|
Packit Service |
1d8f1c |
gunichar output_char;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
while (n_compose < EMOJI_SOURCE_LEN && priv->compose_buffer[n_compose] != 0)
|
|
Packit Service |
1d8f1c |
n_compose++;
|
|
Packit Service |
1d8f1c |
if (n_compose >= EMOJI_SOURCE_LEN) {
|
|
Packit Service |
1d8f1c |
g_warning ("copmose table buffer is full.");
|
|
Packit Service |
1d8f1c |
n_compose = EMOJI_SOURCE_LEN - 1;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (modifiers & IBUS_RELEASE_MASK) {
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence &&
|
|
Packit Service |
1d8f1c |
(keyval == IBUS_KEY_Control_L || keyval == IBUS_KEY_Control_R ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_Shift_L || keyval == IBUS_KEY_Shift_R)) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match &&
|
|
Packit Service |
1d8f1c |
g_unichar_validate (priv->tentative_match)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, priv->tentative_match);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
} else if (n_compose == 0) {
|
|
Packit Service |
1d8f1c |
priv->modifiers_dropped = TRUE;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
/* invalid hex sequence */
|
|
Packit Service |
1d8f1c |
/* FIXME beep_window (event->window); */
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
/* Handle Shift + Space */
|
|
Packit Service |
1d8f1c |
else if (priv->in_emoji_sequence &&
|
|
Packit Service |
1d8f1c |
(keyval == IBUS_KEY_Control_L || keyval == IBUS_KEY_Control_R)) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (simple, priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
} else if (n_compose == 0) {
|
|
Packit Service |
1d8f1c |
priv->modifiers_dropped = TRUE;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
/* invalid hex sequence */
|
|
Packit Service |
1d8f1c |
/* FIXME beep_window (event->window); */
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Ignore modifier key presses */
|
|
Packit Service |
1d8f1c |
for (i = 0; i < G_N_ELEMENTS (IBUS_COMPOSE_IGNORE_KEYLIST); i++)
|
|
Packit Service |
1d8f1c |
if (keyval == IBUS_COMPOSE_IGNORE_KEYLIST[i])
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if ((priv->in_hex_sequence || priv->in_emoji_sequence)
|
|
Packit Service |
1d8f1c |
&& priv->modifiers_dropped) {
|
|
Packit Service |
1d8f1c |
have_hex_mods = TRUE;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
have_hex_mods = (modifiers & (HEX_MOD_MASK)) == HEX_MOD_MASK;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
is_hex_start = (keyval == IBUS_KEY_U) && priv->hex_mode_enabled;
|
|
Packit Service |
1d8f1c |
is_hex_end = (keyval == IBUS_KEY_space ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_KP_Space ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_Return ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_ISO_Enter ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_KP_Enter);
|
|
Packit Service |
1d8f1c |
is_space = (keyval == IBUS_KEY_space || keyval == IBUS_KEY_KP_Space);
|
|
Packit Service |
1d8f1c |
is_backspace = keyval == IBUS_KEY_BackSpace;
|
|
Packit Service |
1d8f1c |
is_escape = keyval == IBUS_KEY_Escape;
|
|
Packit Service |
1d8f1c |
hex_keyval = is_hex_keyval (keyval) ? keyval : 0;
|
|
Packit Service |
1d8f1c |
printable_keyval = is_graph_keyval (keyval) ? keyval : 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* gtkimcontextsimple causes a buffer overflow in priv->compose_buffer.
|
|
Packit Service |
1d8f1c |
* Add the check code here.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
if ((n_compose >= IBUS_MAX_COMPOSE_LEN && priv->in_hex_sequence) ||
|
|
Packit Service |
1d8f1c |
(n_compose >= EMOJI_SOURCE_LEN && priv->in_emoji_sequence)) {
|
|
Packit Service |
1d8f1c |
if (is_backspace) {
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[--n_compose] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (is_hex_end) {
|
|
Packit Service |
1d8f1c |
/* invalid hex sequence */
|
|
Packit Service |
1d8f1c |
// beep_window (event->window);
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (is_escape) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_reset (engine);
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table != NULL && priv->lookup_table_visible) {
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (have_hex_mods)
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* If we are already in a non-hex sequence, or
|
|
Packit Service |
1d8f1c |
* this keystroke is not hex modifiers + hex digit, don't filter
|
|
Packit Service |
1d8f1c |
* key events with accelerator modifiers held down. We only treat
|
|
Packit Service |
1d8f1c |
* Control and Alt as accel modifiers here, since Super, Hyper and
|
|
Packit Service |
1d8f1c |
* Meta are often co-located with Mode_Switch, Multi_Key or
|
|
Packit Service |
1d8f1c |
* ISO_Level3_Switch.
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
if (!have_hex_mods ||
|
|
Packit Service |
1d8f1c |
(n_compose > 0 && !priv->in_hex_sequence && !priv->in_emoji_sequence) ||
|
|
Packit Service |
1d8f1c |
(n_compose == 0 && !priv->in_hex_sequence && !is_hex_start &&
|
|
Packit Service |
1d8f1c |
!priv->in_emoji_sequence && !is_emoji_start) ||
|
|
Packit Service |
1d8f1c |
(priv->in_hex_sequence && !hex_keyval &&
|
|
Packit Service |
1d8f1c |
!is_hex_start && !is_hex_end && !is_escape && !is_backspace) ||
|
|
Packit Service |
1d8f1c |
(priv->in_emoji_sequence && !printable_keyval &&
|
|
Packit Service |
1d8f1c |
!is_emoji_start && !is_hex_end && !is_escape && !is_backspace)) {
|
|
Packit Service |
1d8f1c |
if (modifiers & (IBUS_MOD1_MASK | IBUS_CONTROL_MASK) ||
|
|
Packit Service |
1d8f1c |
((priv->in_hex_sequence || priv->in_emoji_sequence) &&
|
|
Packit Service |
1d8f1c |
priv->modifiers_dropped &&
|
|
Packit Service |
1d8f1c |
(keyval == IBUS_KEY_Return ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_ISO_Enter ||
|
|
Packit Service |
1d8f1c |
keyval == IBUS_KEY_KP_Enter))) {
|
|
Packit Service |
1d8f1c |
return FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Handle backspace */
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence && have_hex_mods && is_backspace) {
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
n_compose--;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[n_compose] = 0;
|
|
Packit Service |
1d8f1c |
check_hex (simple, n_compose);
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (priv->in_emoji_sequence && have_hex_mods && is_backspace) {
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
n_compose--;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[n_compose] = 0;
|
|
Packit Service |
1d8f1c |
check_emoji_table (simple, n_compose, -1);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (!priv->in_hex_sequence && !priv->in_emoji_sequence && is_backspace) {
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
n_compose--;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[n_compose] = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Check for hex sequence restart */
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence && have_hex_mods && is_hex_start) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match &&
|
|
Packit Service |
1d8f1c |
g_unichar_validate (priv->tentative_match)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, priv->tentative_match);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else {
|
|
Packit Service |
1d8f1c |
/* invalid hex sequence */
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
// FIXME beep_window (event->window);
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
if (priv->in_emoji_sequence && have_hex_mods && is_emoji_start) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (simple, priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else {
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Check for hex sequence start */
|
|
Packit Service |
1d8f1c |
if (!priv->in_hex_sequence && !priv->in_emoji_sequence &&
|
|
Packit Service |
1d8f1c |
have_hex_mods && is_hex_start) {
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = TRUE;
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->modifiers_dropped = FALSE;
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// g_debug ("Start HEX MODE");
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
} else if (!priv->in_hex_sequence && !priv->in_emoji_sequence &&
|
|
Packit Service |
1d8f1c |
have_hex_mods && is_emoji_start) {
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = TRUE;
|
|
Packit Service |
1d8f1c |
priv->modifiers_dropped = FALSE;
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
// g_debug ("Start HEX MODE");
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Then, check for compose sequences */
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
if (hex_keyval) {
|
|
Packit Service |
1d8f1c |
SET_COMPOSE_BUFFER_ELEMENT_NEXT (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
hex_keyval);
|
|
Packit Service |
1d8f1c |
} else if (is_escape) {
|
|
Packit Service |
1d8f1c |
// FIXME
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_reset (engine);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
} else if (!is_hex_end) {
|
|
Packit Service |
1d8f1c |
// FIXME
|
|
Packit Service |
1d8f1c |
/* non-hex character in hex sequence */
|
|
Packit Service |
1d8f1c |
// beep_window (event->window);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
} else if (priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
if (printable_keyval) {
|
|
Packit Service |
1d8f1c |
if (!ibus_engine_simple_if_in_range_of_lookup_table (simple,
|
|
Packit Service |
1d8f1c |
printable_keyval)) {
|
|
Packit Service |
1d8f1c |
/* digit keyval can be an index on the current lookup table
|
|
Packit Service |
1d8f1c |
* but it also can be a part of an emoji annotation.
|
|
Packit Service |
1d8f1c |
* E.g. "1" and "2" are indexes of emoji "1".
|
|
Packit Service |
1d8f1c |
* "100" is an annotation of the emoji "100".
|
|
Packit Service |
1d8f1c |
*/
|
|
Packit Service |
1d8f1c |
SET_COMPOSE_BUFFER_ELEMENT_NEXT (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
printable_keyval);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (is_space && (modifiers & IBUS_SHIFT_MASK)) {
|
|
Packit Service |
1d8f1c |
SET_COMPOSE_BUFFER_ELEMENT_NEXT (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
IBUS_KEY_space);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (is_escape) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_reset (engine);
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table != NULL && priv->lookup_table_visible) {
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
if (is_escape) {
|
|
Packit Service |
1d8f1c |
if (n_compose > 0) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_reset (engine);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
SET_COMPOSE_BUFFER_ELEMENT_NEXT (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
keyval);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
SET_COMPOSE_BUFFER_ELEMENT_END (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
0);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->in_hex_sequence) {
|
|
Packit Service |
1d8f1c |
/* If the modifiers are still held down, consider the sequence again */
|
|
Packit Service |
1d8f1c |
if (have_hex_mods) {
|
|
Packit Service |
1d8f1c |
/* space or return ends the sequence, and we eat the key */
|
|
Packit Service |
1d8f1c |
if (n_compose > 0 && is_hex_end) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_match &&
|
|
Packit Service |
1d8f1c |
g_unichar_validate (priv->tentative_match)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple,
|
|
Packit Service |
1d8f1c |
priv->tentative_match);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
// FIXME
|
|
Packit Service |
1d8f1c |
/* invalid hex sequence */
|
|
Packit Service |
1d8f1c |
// beep_window (event->window);
|
|
Packit Service |
1d8f1c |
priv->tentative_match = 0;
|
|
Packit Service |
1d8f1c |
priv->in_hex_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (!check_hex (simple, n_compose))
|
|
Packit Service |
1d8f1c |
// FIXME
|
|
Packit Service |
1d8f1c |
// beep_window (event->window);
|
|
Packit Service |
1d8f1c |
;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (priv->in_emoji_sequence) {
|
|
Packit Service |
1d8f1c |
if (have_hex_mods && n_compose > 0) {
|
|
Packit Service |
1d8f1c |
gboolean update_lookup_table = FALSE;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table_visible) {
|
|
Packit Service |
1d8f1c |
switch (keyval) {
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_space:
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_KP_Space:
|
|
Packit Service |
1d8f1c |
if ((modifiers & IBUS_SHIFT_MASK) == 0) {
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_cursor_down (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_Down:
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_cursor_down (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_Up:
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_cursor_up (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_Page_Down:
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_page_down (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
case IBUS_KEY_Page_Up:
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_page_up (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
default:;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (!update_lookup_table) {
|
|
Packit Service |
1d8f1c |
if (ibus_engine_simple_if_in_range_of_lookup_table (simple,
|
|
Packit Service |
1d8f1c |
keyval)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_set_number_on_lookup_table (
|
|
Packit Service |
1d8f1c |
simple,
|
|
Packit Service |
1d8f1c |
keyval,
|
|
Packit Service |
1d8f1c |
n_compose);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else if (is_hex_end && !is_space) {
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table) {
|
|
Packit Service |
1d8f1c |
int index = (int) ibus_lookup_table_get_cursor_pos (
|
|
Packit Service |
1d8f1c |
priv->lookup_table);
|
|
Packit Service |
1d8f1c |
check_emoji_table (simple, n_compose, index);
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
} else if (check_emoji_table (simple, n_compose, -1)) {
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
priv->lookup_table_visible = FALSE;
|
|
Packit Service |
1d8f1c |
update_lookup_table = TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (update_lookup_table)
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
if (is_hex_end && !is_space) {
|
|
Packit Service |
1d8f1c |
if (priv->tentative_emoji && *priv->tentative_emoji) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_str (simple,
|
|
Packit Service |
1d8f1c |
priv->tentative_emoji);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
g_clear_pointer (&priv->tentative_emoji, g_free);
|
|
Packit Service |
1d8f1c |
priv->in_emoji_sequence = FALSE;
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else {
|
|
Packit Service |
1d8f1c |
GSList *list = global_tables;
|
|
Packit Service |
1d8f1c |
while (list) {
|
|
Packit Service |
1d8f1c |
if (check_table (simple,
|
|
Packit Service |
1d8f1c |
(IBusComposeTable *)list->data,
|
|
Packit Service |
1d8f1c |
n_compose)) {
|
|
Packit Service |
1d8f1c |
// g_debug("check_table returns true");
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
list = list->next;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (ibus_check_compact_table (&ibus_compose_table_compact,
|
|
Packit Service |
1d8f1c |
priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
&compose_finish,
|
|
Packit Service |
1d8f1c |
&output_char)) {
|
|
Packit Service |
1d8f1c |
if (compose_finish) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, output_char);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (ibus_check_algorithmically (priv->compose_buffer,
|
|
Packit Service |
1d8f1c |
n_compose,
|
|
Packit Service |
1d8f1c |
&output_char)) {
|
|
Packit Service |
1d8f1c |
if (output_char) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_commit_char (simple, output_char);
|
|
Packit Service |
1d8f1c |
priv->compose_buffer[0] = 0;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_preedit_text (simple);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* The current compose_buffer doesn't match anything */
|
|
Packit Service |
1d8f1c |
return no_sequence_matches (simple, n_compose, keyval, keycode, modifiers);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_page_down (IBusEngine *engine)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimple *simple = (IBusEngineSimple *)engine;
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table == NULL)
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_page_down (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_page_up (IBusEngine *engine)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimple *simple = (IBusEngineSimple *)engine;
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table == NULL)
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
ibus_lookup_table_page_up (priv->lookup_table);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_update_lookup_and_aux_table (simple);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
static void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_candidate_clicked (IBusEngine *engine,
|
|
Packit Service |
1d8f1c |
guint index,
|
|
Packit Service |
1d8f1c |
guint button,
|
|
Packit Service |
1d8f1c |
guint state)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
IBusEngineSimple *simple = (IBusEngineSimple *)engine;
|
|
Packit Service |
1d8f1c |
IBusEngineSimplePrivate *priv = simple->priv;
|
|
Packit Service |
1d8f1c |
guint keyval;
|
|
Packit Service |
1d8f1c |
gint n_compose = 0;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (priv->lookup_table == NULL || !priv->lookup_table_visible)
|
|
Packit Service |
1d8f1c |
return;
|
|
Packit Service |
1d8f1c |
if (index == 9)
|
|
Packit Service |
1d8f1c |
keyval = IBUS_KEY_0;
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
keyval = IBUS_KEY_1 + index;
|
|
Packit Service |
1d8f1c |
while (priv->compose_buffer[n_compose] != 0)
|
|
Packit Service |
1d8f1c |
n_compose++;
|
|
Packit Service |
1d8f1c |
CHECK_COMPOSE_BUFFER_LENGTH (n_compose);
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_set_number_on_lookup_table (simple, keyval, n_compose);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
void
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_table (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const guint16 *data,
|
|
Packit Service |
1d8f1c |
gint max_seq_len,
|
|
Packit Service |
1d8f1c |
gint n_seqs)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
g_return_if_fail (IBUS_IS_ENGINE_SIMPLE (simple));
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
global_tables = ibus_compose_table_list_add_array (global_tables,
|
|
Packit Service |
1d8f1c |
data,
|
|
Packit Service |
1d8f1c |
max_seq_len,
|
|
Packit Service |
1d8f1c |
n_seqs);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gboolean
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_table_by_locale (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const gchar *locale)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
/* Now ibus_engine_simple_add_compose_file() always returns TRUE. */
|
|
Packit Service |
1d8f1c |
gboolean retval = TRUE;
|
|
Packit Service |
1d8f1c |
gchar *path = NULL;
|
|
Packit Service |
1d8f1c |
const gchar *home;
|
|
Packit Service |
1d8f1c |
const gchar *_locale;
|
|
Packit Service |
1d8f1c |
gchar **langs = NULL;
|
|
Packit Service |
1d8f1c |
gchar **lang = NULL;
|
|
Packit Service |
1d8f1c |
gchar * const sys_langs[] = { "el_gr", "fi_fi", "pt_br", NULL };
|
|
Packit Service |
1d8f1c |
gchar * const *sys_lang = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (locale == NULL) {
|
|
Packit Service |
1d8f1c |
path = g_build_filename (g_get_user_config_dir (),
|
|
Packit Service |
1d8f1c |
"ibus", "Compose", NULL);
|
|
Packit Service |
1d8f1c |
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (simple, path);
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
path = g_build_filename (g_get_user_config_dir (),
|
|
Packit Service |
1d8f1c |
"gtk-3.0", "Compose", NULL);
|
|
Packit Service |
1d8f1c |
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (simple, path);
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
home = g_get_home_dir ();
|
|
Packit Service |
1d8f1c |
if (home == NULL)
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
path = g_build_filename (home, ".XCompose", NULL);
|
|
Packit Service |
1d8f1c |
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (simple, path);
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
_locale = g_getenv ("LC_CTYPE");
|
|
Packit Service |
1d8f1c |
if (_locale == NULL)
|
|
Packit Service |
1d8f1c |
_locale = g_getenv ("LANG");
|
|
Packit Service |
1d8f1c |
if (_locale == NULL)
|
|
Packit Service |
1d8f1c |
_locale = "C";
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=751826 */
|
|
Packit Service |
1d8f1c |
langs = g_get_locale_variants (_locale);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
for (lang = langs; *lang; lang++) {
|
|
Packit Service |
1d8f1c |
if (g_str_has_prefix (*lang, "en_US"))
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
if (**lang == 'C')
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
/* Other languages just include en_us compose table. */
|
|
Packit Service |
1d8f1c |
for (sys_lang = sys_langs; *sys_lang; sys_lang++) {
|
|
Packit Service |
1d8f1c |
if (g_ascii_strncasecmp (*lang, *sys_lang,
|
|
Packit Service |
1d8f1c |
strlen (*sys_lang)) == 0) {
|
|
Packit Service |
1d8f1c |
path = g_build_filename (X11_DATADIR,
|
|
Packit Service |
1d8f1c |
*lang, "Compose", NULL);
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (path == NULL)
|
|
Packit Service |
1d8f1c |
continue;
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
g_strfreev (langs);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if (path != NULL)
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (simple, path);
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
} else {
|
|
Packit Service |
1d8f1c |
path = g_build_filename (X11_DATADIR, locale, "Compose", NULL);
|
|
Packit Service |
1d8f1c |
do {
|
|
Packit Service |
1d8f1c |
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
|
Packit Service |
1d8f1c |
break;
|
|
Packit Service |
1d8f1c |
g_free (path);
|
|
Packit Service |
1d8f1c |
path = NULL;
|
|
Packit Service |
1d8f1c |
} while (0);
|
|
Packit Service |
1d8f1c |
if (path == NULL)
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (simple, path);
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
return retval;
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
gboolean
|
|
Packit Service |
1d8f1c |
ibus_engine_simple_add_compose_file (IBusEngineSimple *simple,
|
|
Packit Service |
1d8f1c |
const gchar *compose_file)
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
g_return_val_if_fail (IBUS_IS_ENGINE_SIMPLE (simple), TRUE);
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
global_tables = ibus_compose_table_list_add_file (global_tables,
|
|
Packit Service |
1d8f1c |
compose_file);
|
|
Packit Service |
1d8f1c |
return TRUE;
|
|
Packit Service |
1d8f1c |
}
|