Blame bus/ibusimpl.c

Packit 3ff832
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
Packit 3ff832
/* vim:set et sts=4: */
Packit 3ff832
/* ibus - The Input Bus
Packit 3ff832
 * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
 * Copyright (C) 2011-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
Packit 3ff832
 * Copyright (C) 2008-2018 Red Hat, Inc.
Packit 3ff832
 *
Packit 3ff832
 * This library is free software; you can redistribute it and/or
Packit 3ff832
 * modify it under the terms of the GNU Lesser General Public
Packit 3ff832
 * License as published by the Free Software Foundation; either
Packit 3ff832
 * version 2.1 of the License, or (at your option) any later version.
Packit 3ff832
 *
Packit 3ff832
 * This library is distributed in the hope that it will be useful,
Packit 3ff832
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff832
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3ff832
 * Lesser General Public License for more details.
Packit 3ff832
 *
Packit 3ff832
 * You should have received a copy of the GNU Lesser General Public
Packit 3ff832
 * License along with this library; if not, write to the Free Software
Packit 3ff832
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit 3ff832
 * USA
Packit 3ff832
 */
Packit 3ff832
Packit 3ff832
#include "ibusimpl.h"
Packit 3ff832
Packit 3ff832
#include <locale.h>
Packit 3ff832
#include <signal.h>
Packit 3ff832
#include <strings.h>
Packit 3ff832
#include <sys/types.h>
Packit 3ff832
#include <sys/wait.h>
Packit 3ff832
#include <unistd.h>
Packit 3ff832
Packit 3ff832
#include "connection.h"
Packit 3ff832
#include "dbusimpl.h"
Packit 3ff832
#include "factoryproxy.h"
Packit 3ff832
#include "global.h"
Packit 3ff832
#include "inputcontext.h"
Packit 3ff832
#include "panelproxy.h"
Packit 3ff832
#include "server.h"
Packit 3ff832
#include "types.h"
Packit 3ff832
Packit 3ff832
struct _BusIBusImpl {
Packit 3ff832
    IBusService parent;
Packit 3ff832
    /* instance members */
Packit 3ff832
    GHashTable *factory_dict;
Packit 3ff832
Packit 3ff832
    /* registered components */
Packit 3ff832
    GList *registered_components;
Packit 3ff832
    GList *contexts;
Packit 3ff832
Packit 3ff832
    /* a fake input context for global engine support */
Packit 3ff832
    BusInputContext *fake_context;
Packit 3ff832
    
Packit 3ff832
    /* a list of engines that are started by a user (without the --ibus
Packit 3ff832
     * command line flag.) */
Packit 3ff832
    GList *register_engine_list;
Packit 3ff832
Packit 3ff832
    /* if TRUE, ibus-daemon uses a keysym translated by the system
Packit 3ff832
     * (i.e. XKB) as-is. otherwise, ibus-daemon itself converts keycode
Packit 3ff832
     * into keysym. */
Packit 3ff832
    gboolean use_sys_layout;
Packit 3ff832
Packit 3ff832
    gboolean embed_preedit_text;
Packit 3ff832
Packit 3ff832
    IBusRegistry    *registry;
Packit 3ff832
Packit 3ff832
    /* a list of BusComponent objects that are created from component XML
Packit 3ff832
     * files (or from the cache of them). */
Packit 3ff832
    GList *components;
Packit 3ff832
Packit 3ff832
    /* a mapping from an engine name (e.g. 'pinyin') to the corresponding
Packit 3ff832
     * IBusEngineDesc object. */
Packit 3ff832
    GHashTable *engine_table;
Packit 3ff832
Packit 3ff832
    BusInputContext *focused_context;
Packit 3ff832
    BusPanelProxy   *panel;
Packit 3ff832
    BusPanelProxy   *emoji_extension;
Packit 3ff832
    gboolean         enable_emoji_extension;
Packit 3ff832
Packit 3ff832
    /* a default keymap of ibus-daemon (usually "us") which is used only
Packit 3ff832
     * when use_sys_layout is FALSE. */
Packit 3ff832
    IBusKeymap      *keymap;
Packit 3ff832
Packit 3ff832
    gboolean use_global_engine;
Packit 3ff832
    gchar *global_engine_name;
Packit 3ff832
    gchar *global_previous_engine_name;
Packit 3ff832
    GVariant *extension_register_keys;
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
struct _BusIBusImplClass {
Packit 3ff832
    IBusServiceClass parent;
Packit 3ff832
Packit 3ff832
    /* class members */
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
enum {
Packit 3ff832
    LAST_SIGNAL,
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
enum {
Packit 3ff832
    PROP_0,
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
/*
Packit 3ff832
static guint            _signals[LAST_SIGNAL] = { 0 };
Packit 3ff832
*/
Packit 3ff832
Packit 3ff832
/* functions prototype */
Packit 3ff832
static void     bus_ibus_impl_destroy   (BusIBusImpl        *ibus);
Packit 3ff832
static void     bus_ibus_impl_service_method_call
Packit 3ff832
                                        (IBusService        *service,
Packit 3ff832
                                         GDBusConnection    *connection,
Packit 3ff832
                                         const gchar        *sender,
Packit 3ff832
                                         const gchar        *object_path,
Packit 3ff832
                                         const gchar        *interface_name,
Packit 3ff832
                                         const gchar        *method_name,
Packit 3ff832
                                         GVariant           *parameters,
Packit 3ff832
                                         GDBusMethodInvocation
Packit 3ff832
                                                            *invocation);
Packit 3ff832
static GVariant *
Packit 3ff832
                bus_ibus_impl_service_get_property
Packit 3ff832
                                        (IBusService        *service,
Packit 3ff832
                                         GDBusConnection    *connection,
Packit 3ff832
                                         const gchar        *sender,
Packit 3ff832
                                         const gchar        *object_path,
Packit 3ff832
                                         const gchar        *interface_name,
Packit 3ff832
                                         const gchar        *property_name,
Packit 3ff832
                                         GError            **error);
Packit 3ff832
static gboolean
Packit 3ff832
                bus_ibus_impl_service_set_property
Packit 3ff832
                                        (IBusService        *service,
Packit 3ff832
                                         GDBusConnection    *connection,
Packit 3ff832
                                         const gchar        *sender,
Packit 3ff832
                                         const gchar        *object_path,
Packit 3ff832
                                         const gchar        *interface_name,
Packit 3ff832
                                         const gchar        *property_name,
Packit 3ff832
                                         GVariant           *value,
Packit 3ff832
                                         GError            **error);
Packit 3ff832
static void     bus_ibus_impl_registry_init
Packit 3ff832
                                        (BusIBusImpl        *ibus);
Packit 3ff832
static void     bus_ibus_impl_registry_changed
Packit 3ff832
                                        (BusIBusImpl        *ibus);
Packit 3ff832
static void     bus_ibus_impl_registry_destroy
Packit 3ff832
                                        (BusIBusImpl        *ibus);
Packit 3ff832
static void     bus_ibus_impl_component_name_owner_changed
Packit 3ff832
                                        (BusIBusImpl        *ibus,
Packit 3ff832
                                         const gchar        *name,
Packit 3ff832
                                         const gchar        *old_name,
Packit 3ff832
                                         const gchar        *new_name);
Packit 3ff832
static void     bus_ibus_impl_global_engine_changed
Packit 3ff832
                                        (BusIBusImpl        *ibus);
Packit 3ff832
static void     bus_ibus_impl_set_context_engine_from_desc
Packit 3ff832
                                        (BusIBusImpl        *ibus,
Packit 3ff832
                                         BusInputContext    *context,
Packit 3ff832
                                         IBusEngineDesc     *desc);
Packit 3ff832
static BusInputContext
Packit 3ff832
               *bus_ibus_impl_create_input_context
Packit 3ff832
                                        (BusIBusImpl        *ibus,
Packit 3ff832
                                         BusConnection      *connection,
Packit 3ff832
                                         const gchar        *client);
Packit 3ff832
static IBusEngineDesc
Packit 3ff832
               *bus_ibus_impl_get_engine_desc
Packit 3ff832
                                        (BusIBusImpl        *ibus,
Packit 3ff832
                                         const gchar        *engine_name);
Packit 3ff832
static void     bus_ibus_impl_set_focused_context
Packit 3ff832
                                        (BusIBusImpl        *ibus,
Packit 3ff832
                                         BusInputContext    *context);
Packit 3ff832
static void     bus_ibus_impl_property_changed
Packit 3ff832
                                        (BusIBusImpl        *service,
Packit 3ff832
                                         const gchar        *property_name,
Packit 3ff832
                                         GVariant           *value);
Packit 3ff832
/* some callback functions */
Packit 3ff832
static void     _context_engine_changed_cb
Packit 3ff832
                                        (BusInputContext    *context,
Packit 3ff832
                                         BusIBusImpl        *ibus);
Packit 3ff832
Packit 3ff832
/* The interfaces available in this class, which consists of a list of
Packit 3ff832
 * methods this class implements and a list of signals this class may emit.
Packit 3ff832
 * Method calls to the interface that are not defined in this XML will
Packit 3ff832
 * be automatically rejected by the GDBus library (see src/ibusservice.c
Packit 3ff832
 * for details.)
Packit 3ff832
 * Implement org.freedesktop.DBus.Properties
Packit 3ff832
 * http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties */
Packit 3ff832
static const gchar introspection_xml[] =
Packit 3ff832
    "<node>\n"
Packit 3ff832
    "  <interface name='org.freedesktop.IBus'>\n"
Packit 3ff832
    "    <property name='Address' type='s' access='read' />\n"
Packit 3ff832
    "    <property name='CurrentInputContext' type='o' access='read' />\n"
Packit 3ff832
    "    <property name='Engines' type='av' access='read' />\n"
Packit 3ff832
    "    <property name='GlobalEngine' type='v' access='read' />\n"
Packit 3ff832
    "    <property name='PreloadEngines' type='as' access='write'>\n"
Packit 3ff832
    "      
Packit 3ff832
    "          name='org.freedesktop.DBus.Property.EmitsChangedSignal'\n"
Packit 3ff832
    "          value='true' />\n"
Packit 3ff832
    "    </property>\n"
Packit 3ff832
    "    <property name='EmbedPreeditText' type='b' access='readwrite'>\n"
Packit 3ff832
    "      
Packit 3ff832
    "          name='org.freedesktop.DBus.Property.EmitsChangedSignal'\n"
Packit 3ff832
    "          value='true' />\n"
Packit 3ff832
    "    </property>\n"
Packit 3ff832
    "    <method name='CreateInputContext'>\n"
Packit 3ff832
    "      <arg direction='in'  type='s' name='client_name' />\n"
Packit 3ff832
    "      <arg direction='out' type='o' name='object_path' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='RegisterComponent'>\n"
Packit 3ff832
    "      <arg direction='in'  type='v' name='component' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='GetEnginesByNames'>\n"
Packit 3ff832
    "      <arg direction='in'  type='as' name='names' />\n"
Packit 3ff832
    "      <arg direction='out' type='av' name='engines' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='Exit'>\n"
Packit 3ff832
    "      <arg direction='in'  type='b' name='restart' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='Ping'>\n"
Packit 3ff832
    "      <arg direction='in'  type='v' name='data' />\n"
Packit 3ff832
    "      <arg direction='out' type='v' name='data' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='SetGlobalEngine'>\n"
Packit 3ff832
    "      <arg direction='in'  type='s' name='engine_name' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <signal name='RegistryChanged'>\n"
Packit 3ff832
    "    </signal>\n"
Packit 3ff832
    "    <signal name='GlobalEngineChanged'>\n"
Packit 3ff832
    "      <arg type='s' name='engine_name' />\n"
Packit 3ff832
    "    </signal>\n"
Packit 3ff832
    "    <property name='ActiveEngines' type='av' access='read' />\n"
Packit 3ff832
    "    <method name='GetAddress'>\n"
Packit 3ff832
    "      <arg direction='out' type='s' name='address' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='CurrentInputContext'>\n"
Packit 3ff832
    "      <arg direction='out' type='o' name='object_path' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='ListEngines'>\n"
Packit 3ff832
    "      <arg direction='out' type='av' name='engines' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='ListActiveEngines'>\n"
Packit 3ff832
    "      <arg direction='out' type='av' name='engines' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='GetUseSysLayout'>\n"
Packit 3ff832
    "      <arg direction='out' type='b' name='enabled' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='GetUseGlobalEngine'>\n"
Packit 3ff832
    "      <arg direction='out' type='b' name='enabled' />\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='IsGlobalEngineEnabled'>\n"
Packit 3ff832
    "      <arg direction='out' type='b' name='enabled' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "    <method name='GetGlobalEngine'>\n"
Packit 3ff832
    "      <arg direction='out' type='v' name='desc' />\n"
Packit 3ff832
    "      <annotation name='org.freedesktop.DBus.Deprecated' value='true'/>\n"
Packit 3ff832
    "    </method>\n"
Packit 3ff832
    "  </interface>\n"
Packit 3ff832
    "</node>\n";
Packit 3ff832
Packit 3ff832
Packit 3ff832
G_DEFINE_TYPE (BusIBusImpl, bus_ibus_impl, IBUS_TYPE_SERVICE)
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_class_init (BusIBusImplClass *class)
Packit 3ff832
{
Packit 3ff832
    IBUS_OBJECT_CLASS (class)->destroy =
Packit 3ff832
            (IBusObjectDestroyFunc) bus_ibus_impl_destroy;
Packit 3ff832
Packit 3ff832
    /* override the parent class's implementation. */
Packit 3ff832
    IBUS_SERVICE_CLASS (class)->service_method_call =
Packit 3ff832
            bus_ibus_impl_service_method_call;
Packit 3ff832
    IBUS_SERVICE_CLASS (class)->service_get_property =
Packit 3ff832
            bus_ibus_impl_service_get_property;
Packit 3ff832
    IBUS_SERVICE_CLASS (class)->service_set_property =
Packit 3ff832
            bus_ibus_impl_service_set_property;
Packit 3ff832
    /* register the xml so that bus_ibus_impl_service_method_call will be
Packit 3ff832
     * called on a method call defined in the xml (e.g. 'GetAddress'.) */
Packit 3ff832
    ibus_service_class_add_interfaces (IBUS_SERVICE_CLASS (class),
Packit 3ff832
                                       introspection_xml);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _panel_destroy_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function which is called when (1) the connection to the panel process is terminated,
Packit 3ff832
 * or (2) ibus_proxy_destroy (ibus->panel); is called. See src/ibusproxy.c for details.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_panel_destroy_cb (BusPanelProxy *panel,
Packit 3ff832
                   BusIBusImpl   *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_PANEL_PROXY (panel));
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    if (ibus->panel == panel)
Packit 3ff832
        ibus->panel = NULL;
Packit 3ff832
    else if (ibus->emoji_extension == panel)
Packit 3ff832
        ibus->emoji_extension = NULL;
Packit 3ff832
    else
Packit 3ff832
        g_return_if_reached ();
Packit 3ff832
    g_object_unref (panel);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_panel_extension_mode (BusIBusImpl        *ibus,
Packit 3ff832
                                        IBusExtensionEvent *event)
Packit 3ff832
{
Packit 3ff832
    gboolean is_extension = FALSE;
Packit 3ff832
    g_return_if_fail (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_return_if_fail (IBUS_IS_EXTENSION_EVENT (event));
Packit 3ff832
Packit 3ff832
    if (!ibus->emoji_extension) {
Packit 3ff832
        g_warning ("Panel extension is not running.");
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_return_if_fail (BUS_IS_PANEL_PROXY (ibus->emoji_extension));
Packit 3ff832
Packit 3ff832
    ibus->enable_emoji_extension = ibus_extension_event_is_enabled (event);
Packit 3ff832
    is_extension = ibus_extension_event_is_extension (event);
Packit 3ff832
    if (ibus->focused_context != NULL) {
Packit 3ff832
        if (ibus->enable_emoji_extension) {
Packit 3ff832
            bus_input_context_set_emoji_extension (ibus->focused_context,
Packit 3ff832
                                                   ibus->emoji_extension);
Packit 3ff832
        } else {
Packit 3ff832
            bus_input_context_set_emoji_extension (ibus->focused_context, NULL);
Packit 3ff832
        }
Packit 3ff832
        if (is_extension)
Packit 3ff832
            bus_input_context_panel_extension_received (ibus->focused_context,
Packit 3ff832
                                                        event);
Packit 3ff832
    }
Packit 3ff832
    if (is_extension)
Packit 3ff832
        return;
Packit 3ff832
Packit 3ff832
    /* Use the DBus method because it seems any DBus signal,
Packit 3ff832
     * g_dbus_message_new_signal(), cannot be reached to the server. */
Packit 3ff832
    bus_panel_proxy_panel_extension_received (ibus->emoji_extension,
Packit 3ff832
                                              event);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_panel_extension_keys (BusIBusImpl *ibus,
Packit 3ff832
                                        GVariant    *parameters)
Packit 3ff832
{
Packit 3ff832
    BusEngineProxy *engine = NULL;
Packit 3ff832
Packit 3ff832
    g_return_if_fail (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_return_if_fail (parameters);
Packit 3ff832
Packit 3ff832
    if (!ibus->emoji_extension) {
Packit 3ff832
        g_warning ("Panel extension is not running.");
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (ibus->extension_register_keys)
Packit 3ff832
        g_variant_unref (ibus->extension_register_keys);
Packit 3ff832
    ibus->extension_register_keys = g_variant_ref_sink (parameters);
Packit 3ff832
    if (ibus->focused_context != NULL) {
Packit 3ff832
            engine = bus_input_context_get_engine (ibus->focused_context);
Packit 3ff832
    }
Packit 3ff832
    if (!engine)
Packit 3ff832
        return;
Packit 3ff832
    bus_engine_proxy_panel_extension_register_keys (engine, parameters);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_panel_panel_extension_cb (BusPanelProxy      *panel,
Packit 3ff832
                           IBusExtensionEvent *event,
Packit 3ff832
                           BusIBusImpl        *ibus)
Packit 3ff832
{
Packit 3ff832
    bus_ibus_impl_set_panel_extension_mode (ibus, event);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_panel_panel_extension_register_keys_cb (BusInputContext *context,
Packit 3ff832
                                         GVariant        *parameters,
Packit 3ff832
                                         BusIBusImpl     *ibus)
Packit 3ff832
{
Packit 3ff832
    bus_ibus_impl_set_panel_extension_keys (ibus, parameters);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_panel_update_preedit_text_received_cb (BusPanelProxy *panel,
Packit 3ff832
                                        IBusText      *text,
Packit 3ff832
                                        guint          cursor_pos,
Packit 3ff832
                                        gboolean       visible,
Packit 3ff832
                                        BusIBusImpl   *ibus)
Packit 3ff832
{
Packit 3ff832
    g_return_if_fail (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    if (!ibus->focused_context)
Packit 3ff832
        return;
Packit 3ff832
    bus_input_context_update_preedit_text (ibus->focused_context,
Packit 3ff832
        text, cursor_pos, visible, IBUS_ENGINE_PREEDIT_CLEAR, FALSE);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_panel_update_lookup_table_received_cb (BusPanelProxy   *panel,
Packit 3ff832
                                        IBusLookupTable *table,
Packit 3ff832
                                        gboolean         visible,
Packit 3ff832
                                        BusIBusImpl     *ibus)
Packit 3ff832
{
Packit 3ff832
    g_return_if_fail (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_return_if_fail (IBUS_IS_LOOKUP_TABLE (table));
Packit 3ff832
Packit 3ff832
    if (!ibus->focused_context)
Packit 3ff832
        return;
Packit 3ff832
    /* Call bus_input_context_update_lookup_table() instead of
Packit 3ff832
     * bus_panel_proxy_update_lookup_table() for panel extensions because
Packit 3ff832
     * bus_input_context_page_up() can call bus_panel_proxy_page_up_received().
Packit 3ff832
     */
Packit 3ff832
    bus_input_context_update_lookup_table (
Packit 3ff832
            ibus->focused_context, table, visible, TRUE);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_panel_update_auxiliary_text_received_cb (BusPanelProxy *panel,
Packit 3ff832
                                          IBusText      *text,
Packit 3ff832
                                          gboolean       visible,
Packit 3ff832
                                          BusIBusImpl   *ibus)
Packit 3ff832
{
Packit 3ff832
    g_return_if_fail (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_return_if_fail (IBUS_IS_TEXT (text));
Packit 3ff832
Packit 3ff832
    if (!ibus->panel)
Packit 3ff832
        return;
Packit 3ff832
    bus_panel_proxy_update_auxiliary_text (
Packit 3ff832
            ibus->panel, text, visible);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_registry_changed_cb (IBusRegistry *registry,
Packit 3ff832
                      BusIBusImpl  *ibus)
Packit 3ff832
{
Packit 3ff832
    bus_ibus_impl_registry_changed (ibus);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/*
Packit 3ff832
 * _dbus_name_owner_changed_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the name-owner-changed signal is sent to the dbus object.
Packit 3ff832
 * This usually means a client (e.g. a panel/config/engine process or an application) is connected/disconnected to/from the bus.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_dbus_name_owner_changed_cb (BusDBusImpl   *dbus,
Packit 3ff832
                             BusConnection *orig_connection,
Packit 3ff832
                             const gchar   *name,
Packit 3ff832
                             const gchar   *old_name,
Packit 3ff832
                             const gchar   *new_name,
Packit 3ff832
                             BusIBusImpl   *ibus)
Packit 3ff832
{
Packit 3ff832
    PanelType panel_type = PANEL_TYPE_NONE;
Packit 3ff832
Packit 3ff832
    g_assert (BUS_IS_DBUS_IMPL (dbus));
Packit 3ff832
    g_assert (name != NULL);
Packit 3ff832
    g_assert (old_name != NULL);
Packit 3ff832
    g_assert (new_name != NULL);
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    if (!g_strcmp0 (name, IBUS_SERVICE_PANEL))
Packit 3ff832
        panel_type = PANEL_TYPE_PANEL;
Packit 3ff832
    else if (!g_strcmp0 (name, IBUS_SERVICE_PANEL_EXTENSION_EMOJI))
Packit 3ff832
        panel_type = PANEL_TYPE_EXTENSION_EMOJI;
Packit 3ff832
Packit Service 57bd60
    if (panel_type != PANEL_TYPE_NONE) {
Packit 3ff832
        if (g_strcmp0 (new_name, "") != 0) {
Packit 3ff832
            /* a Panel process is started. */
Packit 3ff832
            BusConnection *connection;
Packit 3ff832
            BusInputContext *context = NULL;
Packit 3ff832
            BusPanelProxy   **panel = (panel_type == PANEL_TYPE_PANEL) ?
Packit 3ff832
                                      &ibus->panel : &ibus->emoji_extension;
Packit 3ff832
Packit 3ff832
            if (*panel != NULL) {
Packit 3ff832
                ibus_proxy_destroy ((IBusProxy *)(*panel));
Packit 3ff832
                /* panel should be NULL after destroy. See _panel_destroy_cb
Packit 3ff832
                 * for details. */
Packit 3ff832
                g_assert (*panel == NULL);
Packit 3ff832
            }
Packit 3ff832
Packit Service 57bd60
            connection = bus_dbus_impl_get_connection_by_name (BUS_DEFAULT_DBUS, new_name);
Packit 3ff832
            g_return_if_fail (connection != NULL);
Packit 3ff832
Packit 3ff832
            *panel = bus_panel_proxy_new (connection, panel_type);
Packit 3ff832
            if (panel_type == PANEL_TYPE_EXTENSION_EMOJI)
Packit 3ff832
                ibus->enable_emoji_extension = FALSE;
Packit 3ff832
Packit 3ff832
            g_signal_connect (*panel,
Packit 3ff832
                              "destroy",
Packit 3ff832
                              G_CALLBACK (_panel_destroy_cb),
Packit 3ff832
                              ibus);
Packit 3ff832
            g_signal_connect (*panel,
Packit 3ff832
                              "panel-extension",
Packit 3ff832
                              G_CALLBACK (_panel_panel_extension_cb),
Packit 3ff832
                              ibus);
Packit 3ff832
            g_signal_connect (*panel,
Packit 3ff832
                              "panel-extension-register-keys",
Packit 3ff832
                              G_CALLBACK (
Packit 3ff832
                                      _panel_panel_extension_register_keys_cb),
Packit 3ff832
                              ibus);
Packit 3ff832
            g_signal_connect (
Packit 3ff832
                    *panel,
Packit 3ff832
                    "update-preedit-text-received",
Packit 3ff832
                    G_CALLBACK (_panel_update_preedit_text_received_cb),
Packit 3ff832
                    ibus);
Packit 3ff832
            g_signal_connect (
Packit 3ff832
                    *panel,
Packit 3ff832
                    "update-lookup-table-received",
Packit 3ff832
                    G_CALLBACK (_panel_update_lookup_table_received_cb),
Packit 3ff832
                    ibus);
Packit 3ff832
            g_signal_connect (
Packit 3ff832
                    *panel,
Packit 3ff832
                    "update-auxiliary-text-received",
Packit 3ff832
                    G_CALLBACK (_panel_update_auxiliary_text_received_cb),
Packit 3ff832
                    ibus);
Packit 3ff832
Packit 3ff832
            if (ibus->focused_context != NULL) {
Packit 3ff832
                context = ibus->focused_context;
Packit 3ff832
            }
Packit 3ff832
            else if (ibus->use_global_engine) {
Packit 3ff832
                context = ibus->fake_context;
Packit 3ff832
            }
Packit 3ff832
Packit 3ff832
            if (context != NULL) {
Packit 3ff832
                BusEngineProxy *engine;
Packit 3ff832
Packit 3ff832
                bus_panel_proxy_focus_in (*panel, context);
Packit 3ff832
Packit 3ff832
                engine = bus_input_context_get_engine (context);
Packit 3ff832
                if (engine != NULL) {
Packit 3ff832
                    IBusPropList *prop_list =
Packit 3ff832
                        bus_engine_proxy_get_properties (engine);
Packit 3ff832
                    bus_panel_proxy_register_properties (*panel, prop_list);
Packit 3ff832
                }
Packit 3ff832
            }
Packit 3ff832
        }
Packit Service 57bd60
    }
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_component_name_owner_changed (ibus, name, old_name, new_name);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_init:
Packit 3ff832
 *
Packit 3ff832
 * The constructor of BusIBusImpl. Initialize all member variables of a BusIBusImpl object.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_init (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    ibus->factory_dict = g_hash_table_new_full (
Packit 3ff832
                            g_str_hash,
Packit 3ff832
                            g_str_equal,
Packit 3ff832
                            NULL,
Packit 3ff832
                            (GDestroyNotify) g_object_unref);
Packit 3ff832
Packit 3ff832
    ibus->fake_context = bus_input_context_new (NULL, "fake");
Packit 3ff832
    g_object_ref_sink (ibus->fake_context);
Packit 3ff832
    bus_dbus_impl_register_object (BUS_DEFAULT_DBUS,
Packit 3ff832
                                   (IBusService *) ibus->fake_context);
Packit 3ff832
    bus_input_context_set_capabilities (ibus->fake_context,
Packit 3ff832
                                        IBUS_CAP_PREEDIT_TEXT |
Packit 3ff832
                                        IBUS_CAP_FOCUS |
Packit 3ff832
                                        IBUS_CAP_SURROUNDING_TEXT);
Packit 3ff832
    g_signal_connect (ibus->fake_context,
Packit 3ff832
                      "engine-changed",
Packit 3ff832
                      G_CALLBACK (_context_engine_changed_cb),
Packit 3ff832
                      ibus);
Packit 3ff832
    bus_input_context_focus_in (ibus->fake_context);
Packit 3ff832
Packit 3ff832
    ibus->register_engine_list = NULL;
Packit 3ff832
    ibus->contexts = NULL;
Packit 3ff832
    ibus->focused_context = NULL;
Packit 3ff832
    ibus->panel = NULL;
Packit 3ff832
    ibus->emoji_extension = NULL;
Packit 3ff832
Packit 3ff832
    ibus->keymap = ibus_keymap_get ("us");
Packit 3ff832
Packit 3ff832
    ibus->use_sys_layout = TRUE;
Packit 3ff832
    ibus->embed_preedit_text = TRUE;
Packit 3ff832
    ibus->use_global_engine = TRUE;
Packit 3ff832
    ibus->global_engine_name = NULL;
Packit 3ff832
    ibus->global_previous_engine_name = NULL;
Packit 3ff832
Packit 3ff832
    /* focus the fake_context, if use_global_engine is enabled. */
Packit 3ff832
    if (ibus->use_global_engine)
Packit 3ff832
        bus_ibus_impl_set_focused_context (ibus, ibus->fake_context);
Packit 3ff832
Packit 3ff832
    g_signal_connect (BUS_DEFAULT_DBUS,
Packit 3ff832
                      "name-owner-changed",
Packit 3ff832
                      G_CALLBACK (_dbus_name_owner_changed_cb),
Packit 3ff832
                      ibus);
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_registry_init (ibus);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_destroy:
Packit 3ff832
 *
Packit 3ff832
 * The destructor of BusIBusImpl.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_destroy (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    pid_t pid;
Packit 3ff832
    glong timeout;
Packit 3ff832
    gint status;
Packit 3ff832
    gboolean flag;
Packit 3ff832
Packit 3ff832
    g_list_foreach (ibus->components, (GFunc) bus_component_stop, NULL);
Packit 3ff832
Packit 3ff832
    pid = 0;
Packit 3ff832
    timeout = 0;
Packit 3ff832
    flag = FALSE;
Packit 3ff832
    while (1) {
Packit 3ff832
        while ((pid = waitpid (0, &status, WNOHANG)) > 0);
Packit 3ff832
Packit 3ff832
        if (pid == -1) { /* all children finished */
Packit 3ff832
            break;
Packit 3ff832
        }
Packit 3ff832
        if (pid == 0) { /* no child status changed */
Packit 3ff832
            g_usleep (1000);
Packit 3ff832
            timeout += 1000;
Packit 3ff832
            if (timeout >= G_USEC_PER_SEC) {
Packit 3ff832
                if (flag == FALSE) {
Packit 3ff832
                    gpointer old;
Packit 3ff832
                    old = signal (SIGTERM, SIG_IGN);
Packit 3ff832
                    /* send TERM signal to the whole process group (i.e. engines, panel, and config daemon.) */
Packit 3ff832
                    kill (-getpid (), SIGTERM);
Packit 3ff832
                    signal (SIGTERM, old);
Packit 3ff832
                    flag = TRUE;
Packit 3ff832
                }
Packit 3ff832
                else {
Packit 3ff832
                    g_warning ("Not every child processes exited!");
Packit 3ff832
                    break;
Packit 3ff832
                }
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_list_free_full (ibus->register_engine_list, g_object_unref);
Packit 3ff832
    ibus->register_engine_list = NULL;
Packit 3ff832
Packit 3ff832
    if (ibus->factory_dict != NULL) {
Packit 3ff832
        g_hash_table_destroy (ibus->factory_dict);
Packit 3ff832
        ibus->factory_dict = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (ibus->keymap != NULL) {
Packit 3ff832
        g_object_unref (ibus->keymap);
Packit 3ff832
        ibus->keymap = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_free (ibus->global_engine_name);
Packit 3ff832
    ibus->global_engine_name = NULL;
Packit 3ff832
Packit 3ff832
    g_free (ibus->global_previous_engine_name);
Packit 3ff832
    ibus->global_previous_engine_name = NULL;
Packit 3ff832
Packit 3ff832
    if (ibus->fake_context) {
Packit 3ff832
        g_object_unref (ibus->fake_context);
Packit 3ff832
        ibus->fake_context = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_registry_destroy (ibus);
Packit 3ff832
Packit 3ff832
    IBUS_OBJECT_CLASS (bus_ibus_impl_parent_class)->destroy (IBUS_OBJECT (ibus));
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_address:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "Address" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_address (BusIBusImpl     *ibus,
Packit 3ff832
                   GDBusConnection *connection,
Packit 3ff832
                   GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return g_variant_new_string (bus_server_get_address ());
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_get_address_depre (BusIBusImpl           *ibus,
Packit 3ff832
                         GVariant              *parameters,
Packit 3ff832
                         GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.GetAddress() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_address (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
            g_variant_new ("(s)", g_variant_get_string (variant, NULL)));
Packit 3ff832
Packit 3ff832
    g_variant_unref (variant);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static IBusEngineDesc *
Packit 3ff832
_find_engine_desc_by_name (BusIBusImpl *ibus,
Packit 3ff832
                           const gchar *engine_name)
Packit 3ff832
{
Packit 3ff832
    IBusEngineDesc *desc = NULL;
Packit 3ff832
    GList *p;
Packit 3ff832
Packit 3ff832
    /* find engine in registered engine list */
Packit 3ff832
    for (p = ibus->register_engine_list; p != NULL; p = p->next) {
Packit 3ff832
        desc = (IBusEngineDesc *) p->data;
Packit 3ff832
        if (g_strcmp0 (ibus_engine_desc_get_name (desc), engine_name) == 0)
Packit 3ff832
            return desc;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return NULL;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _context_request_engine_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the "request-engine" signal is sent to the context.
Packit 3ff832
 */
Packit 3ff832
static IBusEngineDesc *
Packit 3ff832
_context_request_engine_cb (BusInputContext *context,
Packit 3ff832
                            const gchar     *engine_name,
Packit 3ff832
                            BusIBusImpl     *ibus)
Packit 3ff832
{
Packit 3ff832
    if (engine_name == NULL || engine_name[0] == '\0')
Packit 3ff832
        engine_name = DEFAULT_ENGINE;
Packit 3ff832
Packit 3ff832
    return bus_ibus_impl_get_engine_desc (ibus, engine_name);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_get_engine_desc:
Packit 3ff832
 *
Packit 3ff832
 * Get the IBusEngineDesc by engine_name. If the engine_name is NULL, return
Packit 3ff832
 * a default engine desc.
Packit 3ff832
 */
Packit 3ff832
static IBusEngineDesc *
Packit 3ff832
bus_ibus_impl_get_engine_desc (BusIBusImpl *ibus,
Packit 3ff832
                               const gchar *engine_name)
Packit 3ff832
{
Packit 3ff832
    g_return_val_if_fail (engine_name != NULL, NULL);
Packit 3ff832
    g_return_val_if_fail (engine_name[0] != '\0', NULL);
Packit 3ff832
Packit 3ff832
    IBusEngineDesc *desc = _find_engine_desc_by_name (ibus, engine_name);
Packit 3ff832
    if (desc == NULL) {
Packit 3ff832
        desc = (IBusEngineDesc *) g_hash_table_lookup (ibus->engine_table,
Packit 3ff832
                                                       engine_name);
Packit 3ff832
    }
Packit 3ff832
    return desc;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_context_engine_from_desc (BusIBusImpl     *ibus,
Packit 3ff832
                                            BusInputContext *context,
Packit 3ff832
                                            IBusEngineDesc  *desc)
Packit 3ff832
{
Packit 3ff832
    bus_input_context_set_engine_by_desc (context,
Packit 3ff832
                                          desc,
Packit 3ff832
                                          g_gdbus_timeout, /* timeout in msec. */
Packit 3ff832
                                          NULL, /* we do not cancel the call. */
Packit 3ff832
                                          NULL, /* use the default callback function. */
Packit 3ff832
                                          NULL);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_context_panel_extension_cb (BusInputContext    *context,
Packit 3ff832
                             IBusExtensionEvent *event,
Packit 3ff832
                             BusIBusImpl        *ibus)
Packit 3ff832
{
Packit 3ff832
    bus_ibus_impl_set_panel_extension_mode (ibus, event);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
const static struct {
Packit 3ff832
    const gchar *name;
Packit 3ff832
    GCallback    callback;
Packit 3ff832
} context_signals [] = {
Packit 3ff832
    { "panel-extension",             G_CALLBACK (_context_panel_extension_cb) }
Packit 3ff832
};
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_set_focused_context:
Packit 3ff832
 *
Packit 3ff832
 * Set the current focused context.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_focused_context (BusIBusImpl     *ibus,
Packit 3ff832
                                   BusInputContext *context)
Packit 3ff832
{
Packit 3ff832
    gint i;
Packit 3ff832
    BusEngineProxy *engine = NULL;
Packit 3ff832
    guint purpose = 0;
Packit 3ff832
    guint hints = 0;
Packit 3ff832
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (context == NULL || BUS_IS_INPUT_CONTEXT (context));
Packit 3ff832
    g_assert (context == NULL || bus_input_context_get_capabilities (context) & IBUS_CAP_FOCUS);
Packit 3ff832
Packit 3ff832
    /* Do noting if it is focused context. */
Packit 3ff832
    if (ibus->focused_context == context) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (ibus->focused_context) {
Packit 3ff832
        if (ibus->use_global_engine) {
Packit 3ff832
            /* dettach engine from the focused context */
Packit 3ff832
            engine = bus_input_context_get_engine (ibus->focused_context);
Packit 3ff832
            if (engine) {
Packit 3ff832
                g_object_ref (engine);
Packit 3ff832
                bus_input_context_set_engine (ibus->focused_context, NULL);
Packit 3ff832
                bus_input_context_set_emoji_extension (ibus->focused_context,
Packit 3ff832
                                                       NULL);
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
Packit 3ff832
        if (ibus->panel != NULL)
Packit 3ff832
            bus_panel_proxy_focus_out (ibus->panel, ibus->focused_context);
Packit 3ff832
        if (ibus->emoji_extension != NULL) {
Packit 3ff832
            bus_panel_proxy_focus_out (ibus->emoji_extension,
Packit 3ff832
                                       ibus->focused_context);
Packit 3ff832
        }
Packit 3ff832
        bus_input_context_set_emoji_extension (ibus->focused_context, NULL);
Packit 3ff832
Packit 3ff832
        bus_input_context_get_content_type (ibus->focused_context,
Packit 3ff832
                                            &purpose, &hints);
Packit 3ff832
        for (i = 0; i < G_N_ELEMENTS(context_signals); i++) {
Packit 3ff832
            g_signal_handlers_disconnect_by_func (ibus->focused_context,
Packit 3ff832
                    context_signals[i].callback, ibus);
Packit 3ff832
        }
Packit 3ff832
        g_object_unref (ibus->focused_context);
Packit 3ff832
        ibus->focused_context = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (context == NULL && ibus->use_global_engine) {
Packit 3ff832
        context = ibus->fake_context;
Packit 3ff832
        if (context)
Packit 3ff832
            bus_input_context_set_content_type (context, purpose, hints);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (context) {
Packit 3ff832
        ibus->focused_context = (BusInputContext *) g_object_ref (context);
Packit 3ff832
        /* attach engine to the focused context */
Packit 3ff832
        if (engine != NULL) {
Packit 3ff832
            bus_input_context_set_engine (context, engine);
Packit 3ff832
            bus_input_context_enable (context);
Packit 3ff832
            if (ibus->enable_emoji_extension) {
Packit 3ff832
                bus_input_context_set_emoji_extension (context,
Packit 3ff832
                                                       ibus->emoji_extension);
Packit 3ff832
            } else {
Packit 3ff832
                bus_input_context_set_emoji_extension (context, NULL);
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
        for (i = 0; i < G_N_ELEMENTS(context_signals); i++) {
Packit 3ff832
            g_signal_connect (ibus->focused_context,
Packit 3ff832
                              context_signals[i].name,
Packit 3ff832
                              context_signals[i].callback,
Packit 3ff832
                              ibus);
Packit 3ff832
        }
Packit 3ff832
Packit 3ff832
        if (ibus->panel != NULL)
Packit 3ff832
            bus_panel_proxy_focus_in (ibus->panel, context);
Packit 3ff832
        if (ibus->emoji_extension != NULL)
Packit 3ff832
            bus_panel_proxy_focus_in (ibus->emoji_extension, context);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (engine != NULL)
Packit 3ff832
        g_object_unref (engine);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_global_engine (BusIBusImpl    *ibus,
Packit 3ff832
                                 BusEngineProxy *engine)
Packit 3ff832
{
Packit 3ff832
    if (!ibus->use_global_engine)
Packit 3ff832
        return;
Packit 3ff832
Packit 3ff832
    if (ibus->focused_context) {
Packit 3ff832
        bus_input_context_set_engine (ibus->focused_context, engine);
Packit 3ff832
        if (ibus->enable_emoji_extension) {
Packit 3ff832
            bus_input_context_set_emoji_extension (ibus->focused_context,
Packit 3ff832
                                                   ibus->emoji_extension);
Packit 3ff832
        } else {
Packit 3ff832
            bus_input_context_set_emoji_extension (ibus->focused_context, NULL);
Packit 3ff832
        }
Packit 3ff832
    } else if (ibus->fake_context) {
Packit 3ff832
        bus_input_context_set_engine (ibus->fake_context, engine);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_set_global_engine_by_name (BusIBusImpl *ibus,
Packit 3ff832
                                         const gchar *name)
Packit 3ff832
{
Packit 3ff832
    if (!ibus->use_global_engine)
Packit 3ff832
        return;
Packit 3ff832
Packit 3ff832
    BusInputContext *context =
Packit 3ff832
            ibus->focused_context != NULL ? ibus->focused_context : ibus->fake_context;
Packit 3ff832
Packit 3ff832
    if (context == NULL) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (name, ibus->global_engine_name) == 0) {
Packit 3ff832
        /* If the user requested the same global engine, then we just enable the
Packit 3ff832
         * original one. */
Packit 3ff832
        bus_input_context_enable (context);
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* If there is a focused input context, then we just change the engine of
Packit 3ff832
     * the focused context, which will then change the global engine
Packit 3ff832
     * automatically. Otherwise, we need to change the global engine directly.
Packit 3ff832
     */
Packit 3ff832
    IBusEngineDesc *desc = NULL;
Packit 3ff832
    desc = bus_ibus_impl_get_engine_desc (ibus, name);
Packit 3ff832
    if (desc != NULL) {
Packit 3ff832
        bus_ibus_impl_set_context_engine_from_desc (ibus,
Packit 3ff832
                                                    context,
Packit 3ff832
                                                    desc);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/* When preload_engines and register_engiens are changed, this function
Packit 3ff832
 * will check the global engine. If necessay, it will change the global engine.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_check_global_engine (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    GList *engine_list = NULL;
Packit 3ff832
Packit 3ff832
    /* do nothing */
Packit 3ff832
    if (!ibus->use_global_engine)
Packit 3ff832
        return;
Packit 3ff832
Packit 3ff832
    /* The current global engine is not removed, so do nothing. */
Packit 3ff832
    if (ibus->global_engine_name != NULL &&
Packit 3ff832
        _find_engine_desc_by_name (ibus, ibus->global_engine_name)) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* If the previous engine is available, then just switch to it. */
Packit 3ff832
    if (ibus->global_previous_engine_name != NULL &&
Packit 3ff832
        _find_engine_desc_by_name (ibus, ibus->global_previous_engine_name)) {
Packit 3ff832
        bus_ibus_impl_set_global_engine_by_name (
Packit 3ff832
            ibus, ibus->global_previous_engine_name);
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* Just switch to the fist engine in the list. */
Packit 3ff832
    engine_list = ibus->register_engine_list;
Packit 3ff832
Packit 3ff832
    if (engine_list) {
Packit 3ff832
        IBusEngineDesc *engine_desc = (IBusEngineDesc *)engine_list->data;
Packit 3ff832
        bus_ibus_impl_set_global_engine_by_name (ibus,
Packit 3ff832
                        ibus_engine_desc_get_name (engine_desc));
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* No engine available? Just disable global engine. */
Packit 3ff832
    bus_ibus_impl_set_global_engine (ibus, NULL);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _context_engine_changed_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the "engine-changed" signal is sent to the context.
Packit 3ff832
 * Update global engine as well if necessary.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_context_engine_changed_cb (BusInputContext *context,
Packit 3ff832
                            BusIBusImpl     *ibus)
Packit 3ff832
{
Packit 3ff832
    if (!ibus->use_global_engine)
Packit 3ff832
        return;
Packit 3ff832
Packit 3ff832
    if ((context == ibus->focused_context) ||
Packit 3ff832
        (ibus->focused_context == NULL && context == ibus->fake_context)) {
Packit 3ff832
        BusEngineProxy *engine = bus_input_context_get_engine (context);
Packit 3ff832
        if (engine != NULL) {
Packit 3ff832
            /* only set global engine if engine is not NULL */
Packit 3ff832
            const gchar *name = ibus_engine_desc_get_name (bus_engine_proxy_get_desc (engine));
Packit 3ff832
            if (g_strcmp0 (name, ibus->global_engine_name) == 0)
Packit 3ff832
                return;
Packit 3ff832
            g_free (ibus->global_previous_engine_name);
Packit 3ff832
            ibus->global_previous_engine_name = ibus->global_engine_name;
Packit 3ff832
            ibus->global_engine_name = g_strdup (name);
Packit 3ff832
            bus_ibus_impl_global_engine_changed (ibus);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _context_focus_in_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the "focus-in" signal is sent to the context.
Packit 3ff832
 * If necessary, enables the global engine on the context and update ibus->focused_context.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_context_focus_in_cb (BusInputContext *context,
Packit 3ff832
                      BusIBusImpl     *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (BUS_IS_INPUT_CONTEXT (context));
Packit 3ff832
Packit 3ff832
    /* Do nothing if context does not support focus.
Packit 3ff832
     * The global engine shoule be detached from the focused context. */
Packit 3ff832
    if ((bus_input_context_get_capabilities (context) & IBUS_CAP_FOCUS) == 0) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_set_focused_context (ibus, context);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _context_focus_out_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the "focus-out" signal is sent to the context.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_context_focus_out_cb (BusInputContext    *context,
Packit 3ff832
                       BusIBusImpl        *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (BUS_IS_INPUT_CONTEXT (context));
Packit 3ff832
Packit 3ff832
    /* Do noting if context does not support focus.
Packit 3ff832
     * Actually, the context should emit focus signals, if it does not support focus */
Packit 3ff832
    if ((bus_input_context_get_capabilities (context) & IBUS_CAP_FOCUS) == 0) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* Do noting if it is not focused context. */
Packit 3ff832
    if (ibus->focused_context != context) {
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_set_focused_context (ibus, NULL);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _context_destroy_cb:
Packit 3ff832
 *
Packit 3ff832
 * A callback function to be called when the "destroy" signal is sent to the
Packit 3ff832
 * context.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_context_destroy_cb (BusInputContext    *context,
Packit 3ff832
                     BusIBusImpl        *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (BUS_IS_INPUT_CONTEXT (context));
Packit 3ff832
Packit 3ff832
    if (context == ibus->focused_context)
Packit 3ff832
        bus_ibus_impl_set_focused_context (ibus, NULL);
Packit 3ff832
Packit 3ff832
    if (ibus->panel &&
Packit 3ff832
        bus_input_context_get_capabilities (context) & IBUS_CAP_FOCUS) {
Packit 3ff832
        bus_panel_proxy_destroy_context (ibus->panel, context);
Packit 3ff832
    }
Packit 3ff832
    if (ibus->emoji_extension &&
Packit 3ff832
        bus_input_context_get_capabilities (context) & IBUS_CAP_FOCUS) {
Packit 3ff832
        bus_panel_proxy_destroy_context (ibus->emoji_extension, context);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    ibus->contexts = g_list_remove (ibus->contexts, context);
Packit 3ff832
    g_object_unref (context);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_create_input_context:
Packit 3ff832
 * @client: A name of a client. e.g. "gtk-im"
Packit 3ff832
 * @returns: A BusInputContext object.
Packit 3ff832
 *
Packit 3ff832
 * Create a new BusInputContext object for the client.
Packit 3ff832
 */
Packit 3ff832
static BusInputContext *
Packit 3ff832
bus_ibus_impl_create_input_context (BusIBusImpl   *ibus,
Packit 3ff832
                                    BusConnection *connection,
Packit 3ff832
                                    const gchar   *client)
Packit 3ff832
{
Packit 3ff832
    BusInputContext *context = bus_input_context_new (connection, client);
Packit 3ff832
    g_object_ref_sink (context);
Packit 3ff832
    ibus->contexts = g_list_append (ibus->contexts, context);
Packit 3ff832
Packit 3ff832
    /* Installs glib signal handlers so that the ibus object could be notified when e.g. an IBus.InputContext D-Bus method is called. */
Packit 3ff832
    static const struct {
Packit 3ff832
        gchar *name;
Packit 3ff832
        GCallback callback;
Packit 3ff832
    } signals [] = {
Packit 3ff832
        { "request-engine", G_CALLBACK (_context_request_engine_cb) },
Packit 3ff832
        { "engine-changed", G_CALLBACK (_context_engine_changed_cb) },
Packit 3ff832
        { "focus-in",       G_CALLBACK (_context_focus_in_cb) },
Packit 3ff832
        { "focus-out",      G_CALLBACK (_context_focus_out_cb) },
Packit 3ff832
        { "destroy",        G_CALLBACK (_context_destroy_cb) },
Packit 3ff832
    };
Packit 3ff832
Packit 3ff832
    gint i;
Packit 3ff832
    for (i = 0; i < G_N_ELEMENTS (signals); i++) {
Packit 3ff832
        g_signal_connect (context,
Packit 3ff832
                          signals[i].name,
Packit 3ff832
                          signals[i].callback,
Packit 3ff832
                          ibus);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    bus_input_context_enable (context);
Packit 3ff832
Packit 3ff832
    /* register the context object so that the object could handle IBus.InputContext method calls. */
Packit 3ff832
    bus_dbus_impl_register_object (BUS_DEFAULT_DBUS,
Packit 3ff832
                                   (IBusService *) context);
Packit 3ff832
    g_object_ref (context);
Packit 3ff832
    return context;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_create_input_context:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "CreateInputContext" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_create_input_context (BusIBusImpl           *ibus,
Packit 3ff832
                            GVariant              *parameters,
Packit 3ff832
                            GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    const gchar *client_name = NULL;  // e.g. "gtk-im"
Packit 3ff832
    g_variant_get (parameters, "(&s)", &client_name);
Packit 3ff832
Packit 3ff832
    BusConnection *connection =
Packit 3ff832
            bus_connection_lookup (g_dbus_method_invocation_get_connection (invocation));
Packit 3ff832
    BusInputContext *context =
Packit 3ff832
            bus_ibus_impl_create_input_context (ibus,
Packit 3ff832
                                                connection,
Packit 3ff832
                                                client_name);
Packit 3ff832
    if (context) {
Packit 3ff832
        const gchar *path = ibus_service_get_object_path ((IBusService *) context);
Packit 3ff832
        /* the format-string 'o' is for a D-Bus object path. */
Packit 3ff832
        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", path));
Packit 3ff832
        g_object_unref (context);
Packit 3ff832
    }
Packit 3ff832
    else {
Packit 3ff832
        g_dbus_method_invocation_return_error (invocation,
Packit 3ff832
                                               G_DBUS_ERROR,
Packit 3ff832
                                               G_DBUS_ERROR_FAILED,
Packit 3ff832
                                               "Create input context failed!");
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_current_input_context:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "CurrentInputContext" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_current_input_context (BusIBusImpl     *ibus,
Packit 3ff832
                                 GDBusConnection *connection,
Packit 3ff832
                                 GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (!ibus->focused_context)
Packit 3ff832
    {
Packit 3ff832
        g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                     "No focused input context");
Packit 3ff832
        return NULL;
Packit 3ff832
    }
Packit 3ff832
    else {
Packit 3ff832
        const gchar *path = ibus_service_get_object_path (
Packit 3ff832
                (IBusService *) ibus->focused_context);
Packit 3ff832
        /* the format-string 'o' is for a D-Bus object path. */
Packit 3ff832
        return g_variant_new_object_path (path);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_current_input_context_depre (BusIBusImpl           *ibus,
Packit 3ff832
                                   GVariant              *parameters,
Packit 3ff832
                                   GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.CurrentInputContext() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_current_input_context (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    if (variant == NULL) {
Packit 3ff832
        g_dbus_method_invocation_return_error (
Packit 3ff832
                invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                "%s", error->message);
Packit 3ff832
        g_error_free (error);
Packit 3ff832
    } else {
Packit 3ff832
        const gchar *path = g_variant_get_string (variant, NULL);
Packit 3ff832
        g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
                                               g_variant_new ("(o)", path));
Packit 3ff832
        g_variant_unref (variant);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_component_destroy_cb (BusComponent *component,
Packit 3ff832
                       BusIBusImpl  *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (BUS_IS_COMPONENT (component));
Packit 3ff832
Packit 3ff832
    ibus->registered_components = g_list_remove (ibus->registered_components, component);
Packit 3ff832
Packit 3ff832
    /* remove engines from engine_list */
Packit 3ff832
    GList *engines = bus_component_get_engines (component);
Packit 3ff832
    GList *p;
Packit 3ff832
    for (p = engines; p != NULL; p = p->next) {
Packit 3ff832
        if (g_list_find (ibus->register_engine_list, p->data)) {
Packit 3ff832
            ibus->register_engine_list = g_list_remove (ibus->register_engine_list, p->data);
Packit 3ff832
            g_object_unref (p->data);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
    g_list_free (engines);
Packit 3ff832
Packit 3ff832
    g_object_unref (component);
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_check_global_engine (ibus);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_register_component:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "RegisterComponent" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_register_component (BusIBusImpl           *ibus,
Packit 3ff832
                          GVariant              *parameters,
Packit 3ff832
                          GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GVariant *variant = g_variant_get_child_value (parameters, 0);
Packit 3ff832
    IBusComponent *component =
Packit 3ff832
            (IBusComponent *) ibus_serializable_deserialize (variant);
Packit 3ff832
Packit 3ff832
    if (!IBUS_IS_COMPONENT (component)) {
Packit 3ff832
        if (component)
Packit 3ff832
            g_object_unref (component);
Packit 3ff832
        g_dbus_method_invocation_return_error (
Packit 3ff832
                invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                "The first argument should be an IBusComponent.");
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    BusConnection *connection = bus_connection_lookup (
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation));
Packit 3ff832
    BusFactoryProxy *factory = bus_factory_proxy_new (connection);
Packit 3ff832
Packit 3ff832
    if (factory == NULL) {
Packit 3ff832
        g_object_unref (component);
Packit 3ff832
        g_dbus_method_invocation_return_error (
Packit 3ff832
                invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                "Create factory failed.");
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_object_ref_sink (component);
Packit 3ff832
Packit 3ff832
    BusComponent *buscomp = bus_component_new (component, factory);
Packit 3ff832
    bus_component_set_destroy_with_factory (buscomp, TRUE);
Packit 3ff832
    g_object_unref (component);
Packit 3ff832
    g_object_unref (factory);
Packit 3ff832
Packit 3ff832
    ibus->registered_components = g_list_append (ibus->registered_components,
Packit 3ff832
                                                g_object_ref_sink (buscomp));
Packit 3ff832
    GList *engines = bus_component_get_engines (buscomp);
Packit 3ff832
    g_list_foreach (engines, (GFunc) g_object_ref, NULL);
Packit 3ff832
    ibus->register_engine_list = g_list_concat (ibus->register_engine_list,
Packit 3ff832
                                               engines);
Packit 3ff832
Packit 3ff832
    g_signal_connect (buscomp,
Packit 3ff832
                      "destroy",
Packit 3ff832
                      G_CALLBACK (_component_destroy_cb),
Packit 3ff832
                      ibus);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation, NULL);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_engines:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "Engines" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_engines (BusIBusImpl     *ibus,
Packit 3ff832
                   GDBusConnection *connection,
Packit 3ff832
                   GError         **error)
Packit 3ff832
{
Packit 3ff832
    GVariantBuilder builder;
Packit 3ff832
    GList *engines = NULL;
Packit 3ff832
    GList *p;
Packit 3ff832
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
Packit 3ff832
Packit 3ff832
    engines = g_hash_table_get_values (ibus->engine_table);
Packit 3ff832
Packit 3ff832
    for (p = engines; p != NULL; p = p->next) {
Packit 3ff832
        g_variant_builder_add (
Packit 3ff832
                &builder, "v",
Packit 3ff832
                ibus_serializable_serialize ((IBusSerializable *) p->data));
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_list_free (engines);
Packit 3ff832
Packit 3ff832
    return g_variant_builder_end (&builder);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_list_engines_depre (BusIBusImpl           *ibus,
Packit 3ff832
                          GVariant              *parameters,
Packit 3ff832
                          GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.ListEngines() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_engines (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
                                           g_variant_new ("(@av)", variant));
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_engines_by_names:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "GetEnginesByNames" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_get_engines_by_names (BusIBusImpl           *ibus,
Packit 3ff832
                            GVariant              *parameters,
Packit 3ff832
                            GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    const gchar **names = NULL;
Packit 3ff832
    g_variant_get (parameters, "(^a&s)", &names);
Packit 3ff832
Packit 3ff832
    g_assert (names != NULL);
Packit 3ff832
Packit 3ff832
    gint i = 0;
Packit 3ff832
    GVariantBuilder builder;
Packit 3ff832
    g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
Packit 3ff832
    while (names[i] != NULL) {
Packit 3ff832
        IBusEngineDesc *desc = (IBusEngineDesc *) g_hash_table_lookup (
Packit 3ff832
                ibus->engine_table, names[i++]);
Packit 3ff832
        if (desc == NULL)
Packit 3ff832
            continue;
Packit 3ff832
        g_variant_builder_add (
Packit 3ff832
                &builder,
Packit 3ff832
                "v",
Packit 3ff832
                ibus_serializable_serialize ((IBusSerializable *)desc));
Packit 3ff832
    }
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation, g_variant_new ("(av)", &builder));
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_active_engines:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "ActiveEngines" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_active_engines (BusIBusImpl     *ibus,
Packit 3ff832
                          GDBusConnection *connection,
Packit 3ff832
                          GError         **error)
Packit 3ff832
{
Packit 3ff832
    GVariantBuilder builder;
Packit 3ff832
    GList *p;
Packit 3ff832
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
Packit 3ff832
Packit 3ff832
    for (p = ibus->register_engine_list; p != NULL; p = p->next) {
Packit 3ff832
        g_variant_builder_add (
Packit 3ff832
                &builder, "v",
Packit 3ff832
                ibus_serializable_serialize ((IBusSerializable *) p->data));
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return g_variant_builder_end (&builder);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_list_active_engines_depre (BusIBusImpl           *ibus,
Packit 3ff832
                                 GVariant              *parameters,
Packit 3ff832
                                 GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.ListActiveEngines() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_active_engines (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
                                           g_variant_new ("(@av)", variant));
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_exit:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "Exit" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_exit (BusIBusImpl           *ibus,
Packit 3ff832
            GVariant              *parameters,
Packit 3ff832
            GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    gboolean restart = FALSE;
Packit 3ff832
    g_variant_get (parameters, "(b)", &restart);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation, NULL);
Packit 3ff832
Packit 3ff832
    /* Make sure the reply has been sent out before exit */
Packit 3ff832
    g_dbus_connection_flush_sync (
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation),
Packit 3ff832
            NULL,
Packit 3ff832
            NULL);
Packit 3ff832
Packit 3ff832
    bus_server_quit (restart);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_ping:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "Ping" method call of the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_ping (BusIBusImpl           *ibus,
Packit 3ff832
            GVariant              *parameters,
Packit 3ff832
            GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation, parameters);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_use_sys_layout:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "UseSysLayout" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_use_sys_layout (BusIBusImpl     *ibus,
Packit 3ff832
                          GDBusConnection *connection,
Packit 3ff832
                          GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return g_variant_new_boolean (ibus->use_sys_layout);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_get_use_sys_layout_depre (BusIBusImpl           *ibus,
Packit 3ff832
                                GVariant              *parameters,
Packit 3ff832
                                GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.GetUseSysLayout() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_use_sys_layout (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
            g_variant_new ("(b)", g_variant_get_boolean (variant)));
Packit 3ff832
Packit 3ff832
    g_variant_unref (variant);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_use_global_engine:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "UseGlobalEngine" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_use_global_engine (BusIBusImpl     *ibus,
Packit 3ff832
                             GDBusConnection *connection,
Packit 3ff832
                             GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return g_variant_new_boolean (ibus->use_global_engine);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_get_use_global_engine_depre (BusIBusImpl           *ibus,
Packit 3ff832
                                   GVariant              *parameters,
Packit 3ff832
                                   GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.GetUseGlobalEngine() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_use_global_engine (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
            g_variant_new ("(b)", g_variant_get_boolean (variant)));
Packit 3ff832
Packit 3ff832
    g_variant_unref (variant);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_global_engine:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "GlobalEngine" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_global_engine (BusIBusImpl     *ibus,
Packit 3ff832
                         GDBusConnection *connection,
Packit 3ff832
                         GError         **error)
Packit 3ff832
{
Packit 3ff832
    IBusEngineDesc *desc = NULL;
Packit 3ff832
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    do {
Packit 3ff832
        if (!ibus->use_global_engine)
Packit 3ff832
            break;
Packit 3ff832
        BusInputContext *context = ibus->focused_context;
Packit 3ff832
        if (context == NULL)
Packit 3ff832
            context = ibus->fake_context;
Packit 3ff832
Packit 3ff832
        desc = bus_input_context_get_engine_desc (context);
Packit 3ff832
Packit 3ff832
        if (desc == NULL)
Packit 3ff832
            break;
Packit 3ff832
Packit 3ff832
        GVariant *variant = ibus_serializable_serialize (
Packit 3ff832
                (IBusSerializable *) desc);
Packit 3ff832
        // Set type "v" for introspection_xml.
Packit 3ff832
        return g_variant_new_variant (variant);
Packit 3ff832
    } while (0);
Packit 3ff832
Packit 3ff832
    g_set_error (error,
Packit 3ff832
                 G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                 "No global engine.");
Packit 3ff832
    return NULL;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_get_global_engine_depre (BusIBusImpl           *ibus,
Packit 3ff832
                               GVariant              *parameters,
Packit 3ff832
                               GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.GetGlobalEngine() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_global_engine (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    if (variant == NULL) {
Packit 3ff832
        g_dbus_method_invocation_return_error (
Packit 3ff832
                invocation,
Packit 3ff832
                G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                "%s", error->message);
Packit 3ff832
        g_error_free (error);
Packit 3ff832
    } else {
Packit 3ff832
        GVariant *retval = g_variant_get_variant (variant);
Packit 3ff832
        g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
                g_variant_new ("(v)", retval));
Packit 3ff832
        g_variant_unref (variant);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
struct _SetGlobalEngineData {
Packit 3ff832
    BusIBusImpl *ibus;
Packit 3ff832
    GDBusMethodInvocation *invocation;
Packit 3ff832
};
Packit 3ff832
typedef struct _SetGlobalEngineData SetGlobalEngineData;
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_set_global_engine_ready_cb (BusInputContext       *context,
Packit 3ff832
                                  GAsyncResult          *res,
Packit 3ff832
                                  SetGlobalEngineData   *data)
Packit 3ff832
{
Packit 3ff832
    BusIBusImpl *ibus = data->ibus;
Packit 3ff832
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    if (!bus_input_context_set_engine_by_desc_finish (context, res, &error)) {
Packit 3ff832
        g_dbus_method_invocation_return_error (data->invocation,
Packit 3ff832
                                               G_DBUS_ERROR,
Packit 3ff832
                                               G_DBUS_ERROR_FAILED,
Packit 3ff832
                                               "Set global engine failed: %s",
Packit 3ff832
                                               error->message);
Packit 3ff832
        g_error_free (error);
Packit 3ff832
    }
Packit 3ff832
    else {
Packit 3ff832
        g_dbus_method_invocation_return_value (data->invocation, NULL);
Packit 3ff832
Packit 3ff832
        BusEngineProxy *engine = bus_input_context_get_engine (context);
Packit 3ff832
        if (ibus->use_global_engine && (context != ibus->focused_context)) {
Packit 3ff832
            /* context and ibus->focused_context don't match. This means that
Packit 3ff832
             * the focus is moved before _ibus_set_global_engine() asynchronous
Packit 3ff832
             * call finishes. In this case, the engine for the context currently
Packit 3ff832
             * being focused hasn't been updated. Update the engine here so that
Packit 3ff832
             * subsequent _ibus_get_global_engine() call could return a
Packit 3ff832
             * consistent engine name. */
Packit 3ff832
            if (engine && ibus->focused_context != NULL) {
Packit 3ff832
                g_object_ref (engine);
Packit 3ff832
                bus_input_context_set_engine (context, NULL);
Packit 3ff832
                bus_input_context_set_emoji_extension (context, NULL);
Packit 3ff832
                bus_input_context_set_engine (ibus->focused_context, engine);
Packit 3ff832
                if (ibus->enable_emoji_extension) {
Packit 3ff832
                    bus_input_context_set_emoji_extension (
Packit 3ff832
                            ibus->focused_context,
Packit 3ff832
                            ibus->emoji_extension);
Packit 3ff832
                } else {
Packit 3ff832
                    bus_input_context_set_emoji_extension (
Packit 3ff832
                            ibus->focused_context,
Packit 3ff832
                            NULL);
Packit 3ff832
                }
Packit 3ff832
                g_object_unref (engine);
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
        if (engine && ibus->extension_register_keys) {
Packit 3ff832
            bus_engine_proxy_panel_extension_register_keys (
Packit 3ff832
                    engine,
Packit 3ff832
                    ibus->extension_register_keys);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_object_unref (ibus);
Packit 3ff832
    g_slice_free (SetGlobalEngineData, data);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_set_global_engine:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "SetGlobalEngine" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
_ibus_set_global_engine (BusIBusImpl           *ibus,
Packit 3ff832
                         GVariant              *parameters,
Packit 3ff832
                         GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    if (!ibus->use_global_engine) {
Packit 3ff832
        g_dbus_method_invocation_return_error (invocation,
Packit 3ff832
                        G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
Packit 3ff832
                        "Global engine feature is disabled.");
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    BusInputContext *context = ibus->focused_context;
Packit 3ff832
    if (context == NULL)
Packit 3ff832
        context = ibus->fake_context;
Packit 3ff832
Packit 3ff832
    const gchar *engine_name = NULL;
Packit 3ff832
    g_variant_get (parameters, "(&s)", &engine_name);
Packit 3ff832
Packit 3ff832
    IBusEngineDesc *desc = bus_ibus_impl_get_engine_desc(ibus, engine_name);
Packit 3ff832
    if (desc == NULL) {
Packit 3ff832
        g_dbus_method_invocation_return_error (invocation,
Packit 3ff832
                                               G_DBUS_ERROR,
Packit 3ff832
                                               G_DBUS_ERROR_FAILED,
Packit 3ff832
                                               "Cannot find engine %s.",
Packit 3ff832
                                               engine_name);
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    SetGlobalEngineData *data = g_slice_new0 (SetGlobalEngineData);
Packit 3ff832
    data->ibus = g_object_ref (ibus);
Packit 3ff832
    data->invocation = invocation;
Packit 3ff832
    bus_input_context_set_engine_by_desc (context,
Packit 3ff832
                                          desc,
Packit 3ff832
                                          g_gdbus_timeout, /* timeout in msec. */
Packit 3ff832
                                          NULL, /* we do not cancel the call. */
Packit 3ff832
                                          (GAsyncReadyCallback) _ibus_set_global_engine_ready_cb,
Packit 3ff832
                                          data);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_global_engine_enabled:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "GlobalEngineEnabled" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_global_engine_enabled (BusIBusImpl     *ibus,
Packit 3ff832
                                 GDBusConnection *connection,
Packit 3ff832
                                 GError         **error)
Packit 3ff832
{
Packit 3ff832
    gboolean enabled = FALSE;
Packit 3ff832
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    do {
Packit 3ff832
        if (!ibus->use_global_engine)
Packit 3ff832
            break;
Packit 3ff832
Packit 3ff832
        BusInputContext *context = ibus->focused_context;
Packit 3ff832
        if (context == NULL)
Packit 3ff832
            context = ibus->fake_context;
Packit 3ff832
        if (context == NULL)
Packit 3ff832
            break;
Packit 3ff832
Packit 3ff832
        enabled = TRUE;
Packit 3ff832
    } while (0);
Packit 3ff832
Packit 3ff832
    return g_variant_new_boolean (enabled);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
_ibus_is_global_engine_enabled_depre (BusIBusImpl           *ibus,
Packit 3ff832
                                      GVariant              *parameters,
Packit 3ff832
                                      GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    GDBusConnection *connection =
Packit 3ff832
            g_dbus_method_invocation_get_connection (invocation);
Packit 3ff832
    GError *error = NULL;
Packit 3ff832
    GVariant *variant = NULL;
Packit 3ff832
Packit 3ff832
    g_warning ("org.freedesktop.IBus.IsGlobalEngineEnabled() is deprecated!");
Packit 3ff832
Packit 3ff832
    variant = _ibus_get_global_engine_enabled (ibus, connection, &error);
Packit 3ff832
Packit 3ff832
    g_dbus_method_invocation_return_value (invocation,
Packit 3ff832
            g_variant_new ("(b)", g_variant_get_boolean (variant)));
Packit 3ff832
Packit 3ff832
    g_variant_unref (variant);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_set_preload_engines:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "PreloadEngines" method call of the
Packit 3ff832
 * org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static gboolean
Packit 3ff832
_ibus_set_preload_engines (BusIBusImpl     *ibus,
Packit 3ff832
                           GDBusConnection *connection,
Packit 3ff832
                           GVariant        *value,
Packit 3ff832
                           GError         **error)
Packit 3ff832
{
Packit 3ff832
    int i, j;
Packit 3ff832
    const gchar **names = NULL;
Packit 3ff832
    IBusEngineDesc *desc = NULL;
Packit 3ff832
    BusComponent *component = NULL;
Packit 3ff832
    BusFactoryProxy *factory = NULL;
Packit 3ff832
    GPtrArray *array = g_ptr_array_new ();
Packit 3ff832
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_variant_get (value, "^a&s", &names);
Packit 3ff832
Packit 3ff832
    for (i = 0; names[i] != NULL; i++) {
Packit 3ff832
        gboolean has_component = FALSE;
Packit 3ff832
Packit 3ff832
        desc = bus_ibus_impl_get_engine_desc(ibus, names[i]);
Packit 3ff832
Packit 3ff832
        if (desc == NULL) {
Packit 3ff832
            g_set_error (error,
Packit 3ff832
                         G_DBUS_ERROR,
Packit 3ff832
                         G_DBUS_ERROR_FAILED,
Packit 3ff832
                         "Cannot find engine %s.",
Packit 3ff832
                         names[i]);
Packit 3ff832
            g_ptr_array_free (array, FALSE);
Packit 3ff832
            return FALSE;
Packit 3ff832
        }
Packit 3ff832
Packit 3ff832
        component = bus_component_from_engine_desc (desc);
Packit 3ff832
        factory = bus_component_get_factory (component);
Packit 3ff832
Packit 3ff832
        if (factory != NULL) {
Packit 3ff832
            continue;
Packit 3ff832
        }
Packit 3ff832
Packit 3ff832
        for (j = 0; j < array->len; j++) {
Packit 3ff832
            if (component == (BusComponent *) g_ptr_array_index (array, j)) {
Packit 3ff832
                has_component = TRUE;
Packit 3ff832
                break;
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
Packit 3ff832
        if (!has_component) {
Packit 3ff832
            g_ptr_array_add (array, component);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    for (j = 0; j < array->len; j++) {
Packit 3ff832
        bus_component_start ((BusComponent *) g_ptr_array_index (array, j),
Packit 3ff832
                             g_verbose);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_ptr_array_free (array, FALSE);
Packit 3ff832
Packit 3ff832
    bus_ibus_impl_property_changed (ibus, "PreloadEngines", value);
Packit 3ff832
Packit 3ff832
    return TRUE;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_get_embed_preedit_text:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "EmbedPreeditText" method call of
Packit 3ff832
 * the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
_ibus_get_embed_preedit_text (BusIBusImpl     *ibus,
Packit 3ff832
                              GDBusConnection *connection,
Packit 3ff832
                              GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return g_variant_new_boolean (ibus->embed_preedit_text);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * _ibus_set_embed_preedit_text:
Packit 3ff832
 *
Packit 3ff832
 * Implement the "EmbedPreeditText" method call of
Packit 3ff832
 * the org.freedesktop.IBus interface.
Packit 3ff832
 */
Packit 3ff832
static gboolean
Packit 3ff832
_ibus_set_embed_preedit_text (BusIBusImpl     *ibus,
Packit 3ff832
                              GDBusConnection *connection,
Packit 3ff832
                              GVariant        *value,
Packit 3ff832
                              GError         **error)
Packit 3ff832
{
Packit 3ff832
    if (error) {
Packit 3ff832
        *error = NULL;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    gboolean embed_preedit_text = g_variant_get_boolean (value);
Packit 3ff832
    if (embed_preedit_text != ibus->embed_preedit_text) {
Packit 3ff832
        ibus->embed_preedit_text = embed_preedit_text;
Packit 3ff832
        bus_ibus_impl_property_changed (ibus, "EmbedPreeditText", value);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    return TRUE;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_service_method_call:
Packit 3ff832
 *
Packit 3ff832
 * Handle a D-Bus method call whose destination and interface name are
Packit 3ff832
 * both "org.freedesktop.IBus"
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_service_method_call (IBusService           *service,
Packit 3ff832
                                   GDBusConnection       *connection,
Packit 3ff832
                                   const gchar           *sender,
Packit 3ff832
                                   const gchar           *object_path,
Packit 3ff832
                                   const gchar           *interface_name,
Packit 3ff832
                                   const gchar           *method_name,
Packit 3ff832
                                   GVariant              *parameters,
Packit 3ff832
                                   GDBusMethodInvocation *invocation)
Packit 3ff832
{
Packit 3ff832
    if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
Packit 3ff832
        IBUS_SERVICE_CLASS (bus_ibus_impl_parent_class)->service_method_call (
Packit 3ff832
                        service, connection, sender, object_path,
Packit 3ff832
                        interface_name, method_name,
Packit 3ff832
                        parameters, invocation);
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    /* all methods in the xml definition above should be listed here. */
Packit 3ff832
    static const struct {
Packit 3ff832
        const gchar *method_name;
Packit 3ff832
        void (* method_callback) (BusIBusImpl *,
Packit 3ff832
                                  GVariant *,
Packit 3ff832
                                  GDBusMethodInvocation *);
Packit 3ff832
    } methods [] =  {
Packit 3ff832
        /* IBus interface */
Packit 3ff832
        { "CreateInputContext",    _ibus_create_input_context },
Packit 3ff832
        { "RegisterComponent",     _ibus_register_component },
Packit 3ff832
        { "GetEnginesByNames",     _ibus_get_engines_by_names },
Packit 3ff832
        { "Exit",                  _ibus_exit },
Packit 3ff832
        { "Ping",                  _ibus_ping },
Packit 3ff832
        { "SetGlobalEngine",       _ibus_set_global_engine },
Packit 3ff832
        /* Start of deprecated methods */
Packit 3ff832
        { "GetAddress",            _ibus_get_address_depre },
Packit 3ff832
        { "CurrentInputContext",   _ibus_current_input_context_depre },
Packit 3ff832
        { "ListEngines",           _ibus_list_engines_depre },
Packit 3ff832
        { "ListActiveEngines",     _ibus_list_active_engines_depre },
Packit 3ff832
        { "GetUseSysLayout",       _ibus_get_use_sys_layout_depre },
Packit 3ff832
        { "GetUseGlobalEngine",    _ibus_get_use_global_engine_depre },
Packit 3ff832
        { "GetGlobalEngine",       _ibus_get_global_engine_depre },
Packit 3ff832
        { "IsGlobalEngineEnabled", _ibus_is_global_engine_enabled_depre },
Packit 3ff832
        /* End of deprecated methods */
Packit 3ff832
    };
Packit 3ff832
Packit 3ff832
    gint i;
Packit 3ff832
    for (i = 0; i < G_N_ELEMENTS (methods); i++) {
Packit 3ff832
        if (g_strcmp0 (methods[i].method_name, method_name) == 0) {
Packit 3ff832
            methods[i].method_callback ((BusIBusImpl *) service,
Packit 3ff832
                                        parameters,
Packit 3ff832
                                        invocation);
Packit 3ff832
            return;
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_warning ("service_method_call received an unknown method: %s",
Packit 3ff832
               method_name ? method_name : "(null)");
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_service_get_property:
Packit 3ff832
 *
Packit 3ff832
 * Handle org.freedesktop.DBus.Properties.Get
Packit 3ff832
 */
Packit 3ff832
static GVariant *
Packit 3ff832
bus_ibus_impl_service_get_property (IBusService     *service,
Packit 3ff832
                                    GDBusConnection *connection,
Packit 3ff832
                                    const gchar     *sender,
Packit 3ff832
                                    const gchar     *object_path,
Packit 3ff832
                                    const gchar     *interface_name,
Packit 3ff832
                                    const gchar     *property_name,
Packit 3ff832
                                    GError         **error)
Packit 3ff832
{
Packit 3ff832
    gint i;
Packit 3ff832
Packit 3ff832
    static const struct {
Packit 3ff832
        const gchar *method_name;
Packit 3ff832
        GVariant * (* method_callback) (BusIBusImpl *,
Packit 3ff832
                                        GDBusConnection *,
Packit 3ff832
                                        GError **);
Packit 3ff832
    } methods [] =  {
Packit 3ff832
        { "Address",               _ibus_get_address },
Packit 3ff832
        { "CurrentInputContext",   _ibus_get_current_input_context },
Packit 3ff832
        { "Engines",               _ibus_get_engines },
Packit 3ff832
        { "ActiveEngines",         _ibus_get_active_engines },
Packit 3ff832
        { "GlobalEngine",          _ibus_get_global_engine },
Packit 3ff832
        { "EmbedPreeditText",      _ibus_get_embed_preedit_text },
Packit 3ff832
    };
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
Packit 3ff832
        return IBUS_SERVICE_CLASS (
Packit 3ff832
                bus_ibus_impl_parent_class)->service_get_property (
Packit 3ff832
                        service, connection, sender, object_path,
Packit 3ff832
                        interface_name, property_name,
Packit 3ff832
                        error);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    for (i = 0; i < G_N_ELEMENTS (methods); i++) {
Packit 3ff832
        if (g_strcmp0 (methods[i].method_name, property_name) == 0) {
Packit 3ff832
            return methods[i].method_callback ((BusIBusImpl *) service,
Packit 3ff832
                                               connection,
Packit 3ff832
                                               error);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_warning ("service_get_property received an unknown property: %s",
Packit 3ff832
               property_name ? property_name : "(null)");
Packit 3ff832
    return NULL;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_service_set_property:
Packit 3ff832
 *
Packit 3ff832
 * Handle org.freedesktop.DBus.Properties.Set
Packit 3ff832
 */
Packit 3ff832
static gboolean
Packit 3ff832
bus_ibus_impl_service_set_property (IBusService     *service,
Packit 3ff832
                                    GDBusConnection *connection,
Packit 3ff832
                                    const gchar     *sender,
Packit 3ff832
                                    const gchar     *object_path,
Packit 3ff832
                                    const gchar     *interface_name,
Packit 3ff832
                                    const gchar     *property_name,
Packit 3ff832
                                    GVariant        *value,
Packit 3ff832
                                    GError         **error)
Packit 3ff832
{
Packit 3ff832
    gint i;
Packit 3ff832
Packit 3ff832
    static const struct {
Packit 3ff832
        const gchar *method_name;
Packit 3ff832
        gboolean (* method_callback) (BusIBusImpl *,
Packit 3ff832
                                      GDBusConnection *,
Packit 3ff832
                                      GVariant *,
Packit 3ff832
                                      GError **);
Packit 3ff832
    } methods [] =  {
Packit 3ff832
        { "PreloadEngines",        _ibus_set_preload_engines },
Packit 3ff832
        { "EmbedPreeditText",      _ibus_set_embed_preedit_text },
Packit 3ff832
    };
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (interface_name, IBUS_INTERFACE_IBUS) != 0) {
Packit 3ff832
        return IBUS_SERVICE_CLASS (
Packit 3ff832
                bus_ibus_impl_parent_class)->service_set_property (
Packit 3ff832
                        service, connection, sender, object_path,
Packit 3ff832
                        interface_name, property_name,
Packit 3ff832
                        value, error);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    for (i = 0; i < G_N_ELEMENTS (methods); i++) {
Packit 3ff832
        if (g_strcmp0 (methods[i].method_name, property_name) == 0) {
Packit 3ff832
            return methods[i].method_callback ((BusIBusImpl *) service,
Packit 3ff832
                                               connection,
Packit 3ff832
                                               value,
Packit 3ff832
                                               error);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_warning ("service_set_property received an unknown property: %s",
Packit 3ff832
               property_name ? property_name : "(null)");
Packit 3ff832
    return FALSE;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
BusIBusImpl *
Packit 3ff832
bus_ibus_impl_get_default (void)
Packit 3ff832
{
Packit 3ff832
    static BusIBusImpl *ibus = NULL;
Packit 3ff832
Packit 3ff832
    if (ibus == NULL) {
Packit 3ff832
        ibus = (BusIBusImpl *) g_object_new (BUS_TYPE_IBUS_IMPL,
Packit 3ff832
                                             "object-path", IBUS_PATH_IBUS,
Packit 3ff832
                                             NULL);
Packit 3ff832
    }
Packit 3ff832
    return ibus;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
BusFactoryProxy *
Packit 3ff832
bus_ibus_impl_lookup_factory (BusIBusImpl *ibus,
Packit 3ff832
                              const gchar *path)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    BusFactoryProxy *factory;
Packit 3ff832
Packit 3ff832
    factory = (BusFactoryProxy *) g_hash_table_lookup (ibus->factory_dict, path);
Packit 3ff832
Packit 3ff832
    return factory;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
IBusKeymap *
Packit 3ff832
bus_ibus_impl_get_keymap (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    return ibus->keymap;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_registry_init:
Packit 3ff832
 *
Packit 3ff832
 * Initialize IBusRegistry.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_registry_init (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    GList *p;
Packit 3ff832
    GList *components;
Packit 3ff832
    IBusRegistry *registry = ibus_registry_new ();
Packit 3ff832
Packit 3ff832
    ibus->registry = NULL;
Packit 3ff832
    ibus->components = NULL;
Packit 3ff832
    ibus->engine_table = g_hash_table_new (g_str_hash, g_str_equal);
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (g_cache, "none") == 0) {
Packit 3ff832
        /* Only load registry, but not read and write cache. */
Packit 3ff832
        ibus_registry_load (registry);
Packit 3ff832
    }
Packit 3ff832
    else if (g_strcmp0 (g_cache, "refresh") == 0) {
Packit 3ff832
        /* Load registry and overwrite the cache. */
Packit 3ff832
        ibus_registry_load (registry);
Packit 3ff832
        ibus_registry_save_cache (registry, TRUE);
Packit 3ff832
    }
Packit 3ff832
    else if (g_strcmp0 (g_cache, "auto") == 0) {
Packit 3ff832
        /* Load registry from cache. If the cache does not exist or
Packit 3ff832
         * it is outdated, then generate it.
Packit 3ff832
         */
Packit 3ff832
        if (ibus_registry_load_cache (registry, FALSE) == FALSE ||
Packit 3ff832
            ibus_registry_check_modification (registry)) {
Packit 3ff832
Packit 3ff832
            ibus_object_destroy (IBUS_OBJECT (registry));
Packit 3ff832
            registry = ibus_registry_new ();
Packit 3ff832
Packit 3ff832
            if (ibus_registry_load_cache (registry, TRUE) == FALSE ||
Packit 3ff832
                ibus_registry_check_modification (registry)) {
Packit 3ff832
Packit 3ff832
                ibus_object_destroy (IBUS_OBJECT (registry));
Packit 3ff832
                registry = ibus_registry_new ();
Packit 3ff832
                ibus_registry_load (registry);
Packit 3ff832
                ibus_registry_save_cache (registry, TRUE);
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    ibus->registry = registry;
Packit 3ff832
    components = ibus_registry_get_components (registry);
Packit 3ff832
Packit 3ff832
    for (p = components; p != NULL; p = p->next) {
Packit 3ff832
        IBusComponent *component = (IBusComponent *) p->data;
Packit 3ff832
        BusComponent *buscomp = bus_component_new (component,
Packit 3ff832
                                                   NULL /* factory */);
Packit 3ff832
        GList *engines = NULL;
Packit 3ff832
        GList *p1;
Packit 3ff832
Packit 3ff832
        g_object_ref_sink (buscomp);
Packit 3ff832
        ibus->components = g_list_append (ibus->components, buscomp);
Packit 3ff832
Packit 3ff832
        engines = bus_component_get_engines (buscomp);
Packit 3ff832
        for (p1 = engines; p1 != NULL; p1 = p1->next) {
Packit 3ff832
            IBusEngineDesc *desc = (IBusEngineDesc *) p1->data;
Packit 3ff832
            const gchar *name = ibus_engine_desc_get_name (desc);
Packit 3ff832
            if (g_hash_table_lookup (ibus->engine_table, name) == NULL) {
Packit 3ff832
                g_hash_table_insert (ibus->engine_table,
Packit 3ff832
                                     (gpointer) name,
Packit 3ff832
                                     desc);
Packit 3ff832
            } else {
Packit 3ff832
                g_message ("Engine %s is already registered by other component",
Packit 3ff832
                           name);
Packit 3ff832
            }
Packit 3ff832
        }
Packit 3ff832
        g_list_free (engines);
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    g_list_free (components);
Packit 3ff832
Packit 3ff832
    g_signal_connect (ibus->registry,
Packit 3ff832
                      "changed",
Packit 3ff832
                      G_CALLBACK (_registry_changed_cb),
Packit 3ff832
                      ibus);
Packit 3ff832
    ibus_registry_start_monitor_changes (ibus->registry);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_registry_destroy (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    g_list_free_full (ibus->components, g_object_unref);
Packit 3ff832
    ibus->components = NULL;
Packit 3ff832
Packit 3ff832
    g_clear_pointer (&ibus->engine_table, g_hash_table_destroy);
Packit 3ff832
Packit 3ff832
    g_clear_pointer (&ibus->registry, ibus_object_destroy);
Packit 3ff832
Packit 3ff832
    if (ibus->extension_register_keys)
Packit 3ff832
        g_clear_pointer (&ibus->extension_register_keys, g_variant_unref);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static gint
Packit 3ff832
_component_is_name_cb (BusComponent *component,
Packit 3ff832
                       const gchar  *name)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_COMPONENT (component));
Packit 3ff832
    g_assert (name);
Packit 3ff832
Packit 3ff832
    return g_strcmp0 (bus_component_get_name (component), name);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_component_name_owner_changed (BusIBusImpl *ibus,
Packit 3ff832
                                            const gchar *name,
Packit 3ff832
                                            const gchar *old_name,
Packit 3ff832
                                            const gchar *new_name)
Packit 3ff832
{
Packit 3ff832
    BusComponent *component;
Packit 3ff832
    BusFactoryProxy *factory;
Packit 3ff832
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (name);
Packit 3ff832
    g_assert (old_name);
Packit 3ff832
    g_assert (new_name);
Packit 3ff832
Packit 3ff832
    component = bus_ibus_impl_lookup_component_by_name (ibus, name);
Packit 3ff832
Packit 3ff832
    if (component == NULL) {
Packit 3ff832
        /* name is a unique name, or a well-known name we don't know. */
Packit 3ff832
        return;
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (old_name, "") != 0) {
Packit 3ff832
        /* the component is stopped. */
Packit 3ff832
        factory = bus_component_get_factory (component);
Packit 3ff832
Packit 3ff832
        if (factory != NULL) {
Packit 3ff832
            ibus_proxy_destroy ((IBusProxy *) factory);
Packit 3ff832
        }
Packit 3ff832
    }
Packit 3ff832
Packit 3ff832
    if (g_strcmp0 (new_name, "") != 0) {
Packit 3ff832
        /* the component is started. */
Packit 3ff832
        BusConnection *connection =
Packit 3ff832
                bus_dbus_impl_get_connection_by_name (BUS_DEFAULT_DBUS,
Packit 3ff832
                                                      new_name);
Packit 3ff832
        if (connection == NULL)
Packit 3ff832
            return;
Packit 3ff832
Packit 3ff832
        factory = bus_factory_proxy_new (connection);
Packit 3ff832
        if (factory == NULL)
Packit 3ff832
            return;
Packit 3ff832
        bus_component_set_factory (component, factory);
Packit 3ff832
        g_object_unref (factory);
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
BusComponent *
Packit 3ff832
bus_ibus_impl_lookup_component_by_name (BusIBusImpl *ibus,
Packit 3ff832
                                        const gchar *name)
Packit 3ff832
{
Packit 3ff832
    GList *p;
Packit 3ff832
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
    g_assert (name);
Packit 3ff832
Packit 3ff832
    p = g_list_find_custom (ibus->components,
Packit 3ff832
                            name,
Packit 3ff832
                            (GCompareFunc) _component_is_name_cb);
Packit 3ff832
    if (p) {
Packit 3ff832
        return (BusComponent *) p->data;
Packit 3ff832
    }
Packit 3ff832
    else {
Packit 3ff832
        return NULL;
Packit 3ff832
    }
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_property_changed
Packit 3ff832
 *
Packit 3ff832
 * Send a "PropertiesChanged" D-Bus signal for a property to buses
Packit 3ff832
 * (connections) that are listening to the signal.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_property_changed (BusIBusImpl *service,
Packit 3ff832
                                const gchar *property_name,
Packit 3ff832
                                GVariant    *value)
Packit 3ff832
{
Packit 3ff832
    GDBusMessage *message =
Packit 3ff832
        g_dbus_message_new_signal ("/org/freedesktop/IBus",
Packit 3ff832
                                   "org.freedesktop.DBus.Properties",
Packit 3ff832
                                   "PropertiesChanged");
Packit 3ff832
Packit 3ff832
    /* set a non-zero serial to make libdbus happy */
Packit 3ff832
    g_dbus_message_set_serial (message, 1);
Packit 3ff832
    g_dbus_message_set_sender (message, "org.freedesktop.IBus");
Packit 3ff832
Packit 3ff832
    GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
Packit 3ff832
    g_variant_builder_add (builder, "{sv}", property_name, value);
Packit 3ff832
    g_dbus_message_set_body (message,
Packit 3ff832
                             g_variant_new ("(sa{sv}as)",
Packit 3ff832
                                            "org.freedesktop.IBus",
Packit 3ff832
                                            builder,
Packit 3ff832
                                            NULL));
Packit 3ff832
    g_variant_builder_unref (builder);
Packit 3ff832
Packit 3ff832
    bus_dbus_impl_dispatch_message_by_rule (BUS_DEFAULT_DBUS, message, NULL);
Packit 3ff832
    g_object_unref (message);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
/**
Packit 3ff832
 * bus_ibus_impl_emit_signal:
Packit 3ff832
 *
Packit 3ff832
 * Send a D-Bus signal to buses (connections) that are listening to the signal.
Packit 3ff832
 */
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_emit_signal (BusIBusImpl *ibus,
Packit 3ff832
                           const gchar *signal_name,
Packit 3ff832
                           GVariant    *parameters)
Packit 3ff832
{
Packit 3ff832
    GDBusMessage *message = g_dbus_message_new_signal ("/org/freedesktop/IBus",
Packit 3ff832
                                                       "org.freedesktop.IBus",
Packit 3ff832
                                                       signal_name);
Packit 3ff832
    /* set a non-zero serial to make libdbus happy */
Packit 3ff832
    g_dbus_message_set_serial (message, 1);
Packit 3ff832
    g_dbus_message_set_sender (message, "org.freedesktop.IBus");
Packit 3ff832
    if (parameters)
Packit 3ff832
        g_dbus_message_set_body (message, parameters);
Packit 3ff832
    bus_dbus_impl_dispatch_message_by_rule (BUS_DEFAULT_DBUS, message, NULL);
Packit 3ff832
    g_object_unref (message);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_registry_changed (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    bus_ibus_impl_emit_signal (ibus, "RegistryChanged", NULL);
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
static void
Packit 3ff832
bus_ibus_impl_global_engine_changed (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    const gchar *name = ibus->global_engine_name ? ibus->global_engine_name : "";
Packit 3ff832
    bus_ibus_impl_emit_signal (ibus, "GlobalEngineChanged",
Packit 3ff832
                               g_variant_new ("(s)", name));
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
gboolean
Packit 3ff832
bus_ibus_impl_is_use_sys_layout (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    return ibus->use_sys_layout;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
gboolean
Packit 3ff832
bus_ibus_impl_is_embed_preedit_text (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    return ibus->embed_preedit_text;
Packit 3ff832
}
Packit 3ff832
Packit 3ff832
BusInputContext *
Packit 3ff832
bus_ibus_impl_get_focused_input_context (BusIBusImpl *ibus)
Packit 3ff832
{
Packit 3ff832
    g_assert (BUS_IS_IBUS_IMPL (ibus));
Packit 3ff832
Packit 3ff832
    return ibus->focused_context;
Packit 3ff832
}