Enable to modify the iBus keyboard layout without the root permission.

Update from the upstream. (BUILD=4220)
* Enabled to dynamically generate the entries of iBus engines.
* Enabled to modify the iBus keyboard layout without the root permission.

-----

After this change, the contents of /usr/share/ibus/component/mozc.xml is changed as follows.

Before
```
<component>
  <name>com.google.IBus.Mozc</name>
  <description>Mozc Component</description>
  <exec>/usr/lib/ibus-mozc/ibus-engine-mozc --ibus</exec>
  <version>0.0.0.0</version>
  <author>Google Inc.</author>
  <license>New BSD</license>
  <homepage>https://github.com/google/mozc</homepage>
  <textdomain>ibus-mozc</textdomain>
<engines>
<engine>
  <description>Mozc (Japanese Input Method)</description>
  <language>ja</language>
  <icon>/usr/share/ibus-mozc/product_icon.png</icon>
  <rank>80</rank>
  <icon_prop_key>InputMode</icon_prop_key>
  <symbol>&#x3042;</symbol>
  <setup>/usr/lib/mozc/mozc_tool --mode=config_dialog</setup>
  <name>mozc-jp</name>
  <longname>Mozc</longname>
  <layout>default</layout>
</engine>
</engines>
</component>
```

After
```
<component>
  <name>com.google.IBus.Mozc</name>
  <description>Mozc Component</description>
  <exec>/usr/lib/ibus-mozc/ibus-engine-mozc --ibus</exec>
  <version>0.0.0.0</version>
  <author>Google Inc.</author>
  <license>New BSD</license>
  <homepage>https://github.com/google/mozc</homepage>
  <textdomain>ibus-mozc</textdomain>
  <engines exec="/usr/lib/ibus-mozc/ibus-engine-mozc --xml" />
</component>

<!-- Settings of <engines> and <layout> are stored in ibus_config.textproto -->
<!-- under the user configuration directory, which is either of: -->
<!-- * $XDG_CONFIG_HOME/mozc/ibus_config.textproto -->
<!-- * $HOME/.config/mozc/ibus_config.textproto -->
<!-- * $HOME/.mozc/ibus_config.textproto -->
```

Then, `/usr/lib/ibus-mozc/ibus-engine-mozc --xml` returns the values of the <engine> tags.

If `ibus_config.textproto` exists under the user config directory.
(i.e. `~/.mozc/ibus_config.textproto` or `~/.config/mozc/ibus_config.textproto`)
Mozc uses the settings in the file. If `ibus_config.textproto` does not exist,
it is created with the default values.

So, the users do not need to modify `/usr/share/ibus/component/mozc.xml` directly.
This is the same mechanism with ibus-anthy.

This change will fix two issues.

* There was no way to use Kana layout for US keyboard. With this change,
  if the layout is us, Kana layout for US keyboard is used instead of JP keyboard.
* If multilingual layouts were selected, the keyboard layout for Mozc was not stable.
  For example, when US and FR keyboards were selected in addition to Mozc,
  Mozc's layout was not stable. This change enables to specify the static layout for Mozc.
This commit is contained in:
Hiroyuki Komatsu
2020-12-12 19:12:52 +09:00
parent ba7cbecb7f
commit 9ba59b64d5
11 changed files with 462 additions and 71 deletions

View File

@@ -33,7 +33,7 @@ MAJOR = 2
MINOR = 26
# Number to be increased. This value may be replaced by other tools.
BUILD = 4219
BUILD = 4220
# Represent the platform and release channel.
REVISION = 100

View File

@@ -36,6 +36,7 @@ load(
"py_binary_mozc",
"select_mozc",
)
load("//tools/build_defs:stubs.bzl", "portable_proto_library")
package(default_visibility = ["//:__subpackages__"])
@@ -50,33 +51,25 @@ py_binary_mozc(
srcs = ["gen_mozc_xml.py"],
)
# This genrule uses pkg-config in gen_mozc_xml_main.
genrule(
name = "gen_mozc_xml",
outs = ["mozc.xml"],
cmd = select_mozc(
default = "touch $@", # This is stub.
linux = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
cmd = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
" --server_dir=" + MOZC_SERVER_DIRECTORY +
" --ibus_mozc_path=" + IBUS_MOZC_PATH +
" --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
" > $@"),
),
exec_tools = [":gen_mozc_xml_main"],
)
# This genrule uses pkg-config in gen_mozc_xml_main.
genrule(
name = "gen_main_h",
outs = ["main.h"],
cmd = select_mozc(
default = "touch $@", # This is stub.
linux = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
cmd = ("$(location :gen_mozc_xml_main) --branding=Mozc" +
" --output_cpp" +
" --ibus_mozc_path=" + IBUS_MOZC_PATH +
" --ibus_mozc_icon_path=" + IBUS_MOZC_ICON_PATH +
" > $@"),
),
exec_tools = [":gen_mozc_xml_main"],
)
@@ -169,8 +162,13 @@ cc_library_mozc(
"surrounding_text_util.h",
],
),
defines = [
"ENABLE_GTK_RENDERER",
"MOZC_ENABLE_X11_SELECTION_MONITOR",
],
deps = [
":gtk_candidate_window_handler",
":ibus_config",
":ibus_property_handler",
":ibus_utils",
":x11_selection_monitor",
@@ -180,6 +178,41 @@ cc_library_mozc(
],
)
proto_library(
name = "ibus_config_proto_full",
srcs = [
"ibus_config.proto",
],
)
portable_proto_library(
name = "ibus_config_proto",
config_string = "allow_all: true",
header_outs = [
"ibus_config.pb.h",
],
proto_deps = ["ibus_config_proto_full"],
)
cc_library_mozc(
name = "ibus_config",
srcs = ["ibus_config.cc"],
hdrs = [
"ibus_config.h",
":gen_main_h",
],
copts = ["-Wno-unused-variable"],
deps = [
":ibus_config_proto",
"//base:file_stream",
"//base:file_util",
"//base:logging",
"//base:system_util",
"//base/protobuf:text_format",
"@com_google_absl//absl/strings",
],
)
cc_binary_mozc(
name = "ibus_mozc",
srcs = select_mozc(
@@ -191,9 +224,11 @@ cc_binary_mozc(
),
data = [":gen_mozc_xml"],
deps = [
":ibus_config",
":ibus_mozc_lib",
":ibus_mozc_metadata",
"//base",
"//base:flags",
"//base:init_mozc",
],
)

View File

@@ -40,7 +40,6 @@ __author__ = "yusukes"
import optparse
import os
import subprocess
import sys
# Information to generate <component> part of mozc.xml. %s will be replaced with
@@ -68,14 +67,69 @@ CPP_HEADER = """// Copyright 2010 Google Inc. All Rights Reserved.
#ifndef %s
#define %s
#include <cstddef>
namespace {"""
CPP_FOOTER = """} // namespace
#endif // %s"""
def OutputXmlElement(param_dict, element_name, value):
print(' <%s>%s</%s>' % (element_name, (value % param_dict), element_name))
def GetXmlElement(param_dict, element_name, value):
return ' <%s>%s</%s>' % (element_name, (value % param_dict), element_name)
def GetTextProtoElement(param_dict, element_name, value):
return ' %s : "%s"' % (element_name, (value % param_dict))
def GetEnginesXml(param_dict, engine_common, engines, setup_arg):
"""Outputs a XML data for ibus-daemon.
Args:
param_dict: A dictionary to embed options into output string.
For example, {'product_name': 'Mozc'}.
engine_common: A dictionary from a property name to a property value that
are commonly used in all engines. For example, {'language': 'ja'}.
engines: A dictionary from a property name to a list of property values of
engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
setup_arg: A command line to execute Mozc's configuration tool.
Returns:
output string in XML.
"""
output = ['<engines>']
for i in range(len(engines['name'])):
output.append('<engine>')
for key in engine_common:
output.append(GetXmlElement(param_dict, key, engine_common[key]))
if setup_arg:
output.append(GetXmlElement(param_dict, 'setup', ' '.join(setup_arg)))
for key in engines:
output.append(GetXmlElement(param_dict, key, engines[key][i]))
output.append('</engine>')
output.append('</engines>')
return '\n'.join(output)
def GetIbusConfigTextProto(param_dict, engines):
"""Outputs a TextProto data for iBus config.
Args:
param_dict: A dictionary to embed options into output string.
For example, {'product_name': 'Mozc'}.
engines: A dictionary from a property name to a list of property values of
engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
Returns:
output string in TextProto.
"""
output = []
for i in range(len(engines['name'])):
output.append('engines {')
for key in engines:
output.append(GetTextProtoElement(param_dict, key, engines[key][i]))
output.append('}')
return '\n'.join(output)
def OutputXml(param_dict, component, engine_common, engines, setup_arg):
@@ -90,30 +144,30 @@ def OutputXml(param_dict, component, engine_common, engines, setup_arg):
are commonly used in all engines. For example, {'language': 'ja'}.
engines: A dictionary from a property name to a list of property values of
engines. For example, {'name': ['mozc-jp', 'mozc', 'mozc-dv']}.
setup_arg: A command line to execute Mozc's configuration tool.
"""
del engine_common, engines, setup_arg
print('<component>')
for key in component:
OutputXmlElement(param_dict, key, component[key])
print('<engines>')
for i in range(len(engines['name'])):
print('<engine>')
for key in engine_common:
OutputXmlElement(param_dict, key, engine_common[key])
if setup_arg:
OutputXmlElement(param_dict, 'setup', ' '.join(setup_arg))
for key in engines:
OutputXmlElement(param_dict, key, engines[key][i])
print('</engine>')
print('</engines>')
print(GetXmlElement(param_dict, key, component[key]))
print(' <engines exec="%s --xml" />' % param_dict['ibus_mozc_path'])
print('</component>')
print('''
<!-- Settings of <engines> and <layout> are stored in ibus_config.textproto -->
<!-- under the user configuration directory, which is either of: -->
<!-- * $XDG_CONFIG_HOME/mozc/ibus_config.textproto -->
<!-- * $HOME/.config/mozc/ibus_config.textproto -->
<!-- * $HOME/.mozc/ibus_config.textproto -->
''')
def OutputCppVariable(param_dict, prefix, variable_name, value):
print('const char k%s%s[] = "%s";' % (prefix, variable_name.capitalize(),
(value % param_dict)))
def OutputCpp(param_dict, component, engine_common, engines):
def OutputCpp(param_dict, component, engine_common, engines, setup_arg):
"""Outputs a C++ header file for mozc/unix/ibus/main.cc.
Args:
@@ -121,6 +175,7 @@ def OutputCpp(param_dict, component, engine_common, engines):
component: ditto.
engine_common: ditto.
engines: ditto.
setup_arg: ditto.
"""
guard_name = 'MOZC_UNIX_IBUS_MAIN_H_'
print(CPP_HEADER % (guard_name, guard_name))
@@ -128,25 +183,22 @@ def OutputCpp(param_dict, component, engine_common, engines):
OutputCppVariable(param_dict, 'Component', key, component[key])
for key in engine_common:
OutputCppVariable(param_dict, 'Engine', key, engine_common[key])
OutputCppVariable(param_dict, 'Engine', 'Setup', ' '.join(setup_arg))
for key in engines:
print('const char* kEngine%sArray[] = {' % key.capitalize())
for i in range(len(engines[key])):
print('"%s",' % (engines[key][i] % param_dict))
print('};')
print('const size_t kEngineArrayLen = %s;' % len(engines['name']))
print('const char kEnginesXml[] = R"#(', end='')
print(GetEnginesXml(param_dict, engine_common, engines, setup_arg))
print(')#";')
print('const char kIbusConfigTextProto[] = R"#(', end='')
print(GetIbusConfigTextProto(param_dict, engines))
print(')#";')
print(CPP_FOOTER % guard_name)
def CheckIBusVersion(options, minimum_version):
"""Tests if ibus version is equal to or greater than the given value."""
command_line = ['pkg-config', '--exists', 'ibus-1.0 >= %s' % minimum_version]
return_code = subprocess.call(command_line)
if return_code == 0:
return True
else:
return False
def main():
"""The main function."""
parser = optparse.OptionParser(usage='Usage: %prog [options]')
@@ -181,6 +233,10 @@ def main():
'language': 'ja',
'icon': '%(ibus_mozc_icon_path)s',
'rank': '80',
# Make sure that the property key 'InputMode' matches to the property name
# specified to |ibus_property_new| in unix/ibus/property_handler.cc
'icon_prop_key': 'InputMode',
'symbol': '&#x3042;',
}
# DO NOT change the engine name 'mozc-jp'. The names is referenced by
@@ -188,24 +244,12 @@ def main():
engines_props = {
'name': ['mozc-jp'],
'longname': ['%(product_name)s'],
'layout': ['default'],
}
# IBus 1.5.11 and greater supports 'icon_prop_key'.
# See ibus/ibus@23c45b970b195008a54884a1a9d810e7f8b22c5c
if CheckIBusVersion(options, '1.5.11'):
# Make sure that the property key 'InputMode' matches to the property name
# specified to |ibus_property_new| in unix/ibus/property_handler.cc
engine_common_props['icon_prop_key'] = 'InputMode'
if CheckIBusVersion(options, '1.5.0'):
engine_common_props['symbol'] = '&#x3042;'
engines_props['layout'] = ['default']
else:
engines_props['layout'] = ['jp']
if options.output_cpp:
OutputCpp(param_dict, IBUS_COMPONENT_PROPS, engine_common_props,
engines_props)
engines_props, setup_arg)
else:
OutputXml(param_dict, IBUS_COMPONENT_PROPS, engine_common_props,
engines_props, setup_arg)

View File

@@ -134,12 +134,39 @@
'../../base/base.gyp:base',
],
},
{
'target_name': 'genproto_ibus_config_proto',
'type': 'none',
'toolsets': ['host'],
'sources': [
'ibus_config.proto',
],
'includes': [
'../../protobuf/genproto.gypi',
],
},
{
'target_name': 'ibus_config_proto',
'type': 'static_library',
'hard_dependency': 1,
'sources': [
'<(proto_out_dir)/unix/ibus/ibus_config.pb.cc',
],
'dependencies': [
'../../protobuf/protobuf.gyp:protobuf',
'genproto_ibus_config_proto#host',
],
'export_dependent_settings': [
'genproto_ibus_config_proto#host',
],
},
{
'target_name': 'ibus_mozc_lib',
'type': 'static_library',
'sources': [
'engine_registrar.cc',
'ibus_candidate_window_handler.cc',
'ibus_config.cc',
'key_event_handler.cc',
'key_translator.cc',
'mozc_engine.cc',
@@ -147,9 +174,12 @@
'surrounding_text_util.cc',
],
'dependencies': [
'../../base/absl.gyp:absl_strings',
'../../client/client.gyp:client',
'../../protocol/protocol.gyp:commands_proto',
'../../session/session_base.gyp:ime_switch_util',
'gen_ibus_mozc_files',
'ibus_config_proto',
'ibus_property_handler',
'message_translator',
'path_util',
@@ -168,12 +198,8 @@
],
},
{
'target_name': 'ibus_mozc',
'type': 'executable',
'sources': [
'main.cc',
'<(gen_out_dir)/main.h',
],
'target_name': 'gen_ibus_mozc_files',
'type': 'none',
'actions': [
{
'action_name': 'gen_main_h',
@@ -194,8 +220,20 @@
],
},
],
'dependencies': [
'gen_mozc_xml',
],
},
{
'target_name': 'ibus_mozc',
'type': 'executable',
'sources': [
'main.cc',
'<(gen_out_dir)/main.h',
],
'dependencies': [
'../../base/base.gyp:base',
'gen_ibus_mozc_files',
'gen_mozc_xml',
'ibus_mozc_lib',
'ibus_mozc_metadata',

View File

@@ -0,0 +1,129 @@
// Copyright 2010-2020, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "unix/ibus/ibus_config.h"
#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/protobuf/text_format.h"
#include "base/system_util.h"
#include "unix/ibus/main.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
namespace mozc {
constexpr char kIbusConfigFile[] = "ibus_config.textproto";
namespace {
std::string UpdateConfigFile() {
const std::string engines_file = FileUtil::JoinPath(
SystemUtil::GetUserProfileDirectory(), kIbusConfigFile);
if (FileUtil::FileExists(engines_file)) {
InputFileStream ifs(engines_file.c_str());
return ifs.Read();
} else {
OutputFileStream ofs(engines_file.c_str());
ofs << kIbusConfigTextProto;
ofs.close();
if (ofs.fail()) {
LOG(ERROR) << "Failed to write " << engines_file;
}
return kIbusConfigTextProto;
}
}
bool ParseConfig(const std::string &data, ibus::Config &config) {
if (mozc::protobuf::TextFormat::ParseFromString(data, &config)) {
return true;
}
// Failed to parse the data, fallback to the default setting.
mozc::protobuf::TextFormat::ParseFromString(kIbusConfigTextProto, &config);
return false;
}
std::string EscapeXmlValue(const std::string &value) {
return absl::StrReplaceAll(value, {{"&", "&amp;"},
{"<", "&lt;"},
{">", "&gt;"},
{"\"", "&quot;"},
{"'", "&apos;"}});
}
std::string CreateEnginesXml(const ibus::Config &config) {
std::string output = "<engines>\n";
for (const ibus::Engine &engine : config.engines()) {
absl::StrAppend(
&output,
"<engine>\n",
" <description>", kEngineDescription, "</description>\n",
" <language>", kEngineLanguage, "</language>\n",
" <icon>", kEngineIcon, "</icon>\n",
" <rank>", kEngineRank, "</rank>\n",
" <icon_prop_key>", kEngineIcon_prop_key, "</icon_prop_key>\n",
" <symbol>", kEngineSymbol, "</symbol>\n",
" <setup>", kEngineSetup, "</setup>\n",
" <name>", EscapeXmlValue(engine.name()), "</name>\n",
" <longname>", EscapeXmlValue(engine.longname()), "</longname>\n",
" <layout>", EscapeXmlValue(engine.layout()), "</layout>\n",
"</engine>\n");
}
absl::StrAppend(&output, "</engines>\n");
return output;
}
} // namespace
const std::string &IbusConfig::InitEnginesXml() {
const std::string config_data = UpdateConfigFile();
const bool valid_user_config = ParseConfig(config_data, config_);
engine_xml_ = CreateEnginesXml(config_);
if (!valid_user_config) {
engine_xml_ += ("<!-- Failed to parse the user config. -->\n"
"<!-- Used the default setting instead. -->\n");
}
return engine_xml_;
}
const ibus::Config &IbusConfig::GetConfig() const {
return config_;
}
const std::string &IbusConfig::GetLayout(const std::string& name) const {
for (const ibus::Engine &engine : config_.engines()) {
if (engine.name() == name) {
return engine.layout();
}
}
return default_layout_;
}
} // namespace mozc

View File

@@ -0,0 +1,61 @@
// Copyright 2010-2020, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef MOZC_UNIX_IBUS_IBUS_CONFIG_H_
#define MOZC_UNIX_IBUS_IBUS_CONFIG_H_
#include <map>
#include <string>
#include "unix/ibus/ibus_config.pb.h"
namespace mozc {
class IbusConfig {
public:
IbusConfig() : default_layout_("default") {}
virtual ~IbusConfig() = default;
// Disallow implicit constructors.
IbusConfig(const IbusConfig&) = delete;
IbusConfig& operator=(const IbusConfig&) = delete;
const std::string &InitEnginesXml();
const std::string &GetLayout(const std::string &name) const;
const ibus::Config &GetConfig() const;
private:
std::string default_layout_;
std::string engine_xml_;
ibus::Config config_;
};
} // namespace mozc
#endif // MOZC_UNIX_IBUS_IBUS_CONFIG_H_

View File

@@ -0,0 +1,42 @@
// Copyright 2010-2020, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
package mozc.ibus;
message Config {
repeated Engine engines = 1;
}
message Engine {
optional string name = 1;
optional string longname = 2;
optional string layout = 3;
}

View File

@@ -34,11 +34,13 @@
#include "base/init_mozc.h"
#include "base/logging.h"
#include "base/version.h"
#include "unix/ibus/ibus_config.h"
#include "unix/ibus/main.h"
#include "unix/ibus/mozc_engine.h"
#include "unix/ibus/path_util.h"
DEFINE_bool(ibus, false, "The engine is started by ibus-daemon");
DEFINE_bool(xml, false, "Output xml data for the engine.");
namespace {
@@ -70,13 +72,16 @@ IBusComponent *GetIBusComponent() {
mozc::Version::GetMozcVersion().c_str(), kComponentLicense,
kComponentAuthor, kComponentHomepage, "", kComponentTextdomain);
const std::string icon_path = mozc::ibus::GetIconPath(kEngineIcon);
for (size_t i = 0; i < kEngineArrayLen; ++i) {
mozc::IbusConfig ibus_config;
ibus_config.InitEnginesXml();
for (const mozc::ibus::Engine &engine : ibus_config.GetConfig().engines()) {
ibus_component_add_engine(
component,
ibus_engine_desc_new(kEngineNameArray[i], kEngineLongnameArray[i],
ibus_engine_desc_new(engine.name().c_str(), engine.longname().c_str(),
kEngineDescription, kEngineLanguage,
kComponentLicense, kComponentAuthor,
icon_path.c_str(), kEngineLayoutArray[i]));
icon_path.c_str(), engine.layout().c_str()));
}
return component;
}
@@ -105,12 +110,22 @@ void InitIBusComponent(bool executed_by_ibus_daemon) {
g_object_unref(component);
}
void OutputXml() {
mozc::IbusConfig ibus_config;
std::cout << ibus_config.InitEnginesXml() << std::endl;
}
} // namespace
int main(gint argc, gchar **argv) {
mozc::InitMozc(argv[0], &argc, &argv);
if (mozc::GetFlag(FLAGS_xml)) {
OutputXml();
return 0;
}
ibus_init();
InitIBusComponent(FLAGS_ibus);
InitIBusComponent(mozc::GetFlag(FLAGS_ibus));
#ifndef MOZC_NO_LOGGING
EnableVerboseLog();
#endif // MOZC_NO_LOGGING

View File

@@ -27,7 +27,28 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include "base/flags.h"
#include "base/init_mozc.h"
#include "unix/ibus/ibus_config.h"
DEFINE_bool(xml, false, "Output xml data for the engine.");
namespace {
void OutputXml() {
mozc::IbusConfig ibus_config;
std::cout << ibus_config.InitEnginesXml() << std::endl;
}
} // namespace
int main(int argc, char **argv) {
mozc::InitMozc(argv[0], &argc, &argv);
if (mozc::GetFlag(FLAGS_xml)) {
OutputXml();
return 0;
}
// This is a stub used by platforms which do not support iBus
// (i.e. non Linux environments).
return 1;

View File

@@ -258,6 +258,8 @@ MozcEngine::MozcEngine()
}
#endif // MOZC_ENABLE_X11_SELECTION_MONITOR
ibus_config_.InitEnginesXml();
// TODO(yusukes): write a unit test to check if the capability is set
// as expected.
}
@@ -349,8 +351,10 @@ gboolean MozcEngine::ProcessKeyEvent(IBusEngine *engine, guint keyval,
return FALSE;
}
// TODO(yusukes): use |layout| in IBusEngineDesc if possible.
const bool layout_is_jp = !g_strcmp0(ibus_engine_get_name(engine), "mozc-jp");
// layout_is_jp is only used determine Kana input with US layout.
const std::string &layout =
ibus_config_.GetLayout(ibus_engine_get_name(engine));
const bool layout_is_jp = (layout != "us");
commands::KeyEvent key;
if (!key_event_handler_->GetKeyEvent(keyval, keycode, modifiers,

View File

@@ -38,6 +38,7 @@
#include "protocol/commands.pb.h"
#include "testing/base/public/gunit_prod.h"
#include "unix/ibus/engine_interface.h"
#include "unix/ibus/ibus_config.h"
namespace mozc {
@@ -148,6 +149,7 @@ class MozcEngine : public EngineInterface {
// Unique IDs of candidates that are currently shown.
std::vector<int32> unique_candidate_ids_;
IbusConfig ibus_config_;
friend class LaunchToolTest;
FRIEND_TEST(LaunchToolTest, LaunchToolTest);