diff --git a/src/unix/fcitx5/BUILD b/src/unix/fcitx5/BUILD index 14295aa20..2094fe75e 100644 --- a/src/unix/fcitx5/BUILD +++ b/src/unix/fcitx5/BUILD @@ -31,6 +31,16 @@ mozc_cc_library( ] ) +mozc_cc_library( + name = "i18nwrapper", + hdrs = [ + "i18nwrapper.h" + ], + deps = [ + "@fcitx5//:fcitx5" + ] +) + mozc_cc_library( name = "mozc_engine", srcs = [ @@ -43,10 +53,8 @@ mozc_cc_library( "mozc_response_parser.h", "mozc_state.h" ], - local_defines = [ - 'FCITX_GETTEXT_DOMAIN=\\"fcitx5-mozc\\"', - ], deps = [ + ":i18nwrapper", ":mozc_connection", ":mozc_client_pool", ":fcitx_key_util", diff --git a/src/unix/fcitx5/fcitx_key_event_handler.cc b/src/unix/fcitx5/fcitx_key_event_handler.cc index 7777753bf..e55a04e49 100644 --- a/src/unix/fcitx5/fcitx_key_event_handler.cc +++ b/src/unix/fcitx5/fcitx_key_event_handler.cc @@ -30,11 +30,19 @@ #include "unix/fcitx5/fcitx_key_event_handler.h" +#include + +#include #include +#include +#include -#include "base/logging.h" +#include "absl/log/check.h" +#include "absl/log/log.h" #include "base/singleton.h" -#include "base/vlog.h" +#include "protocol/commands.pb.h" +#include "protocol/config.pb.h" +#include "unix/fcitx5/fcitx_key_translator.h" namespace fcitx { @@ -72,11 +80,9 @@ void AddAdditionalModifiers( mozc::Singleton::get()->data(); // Adds MODIFIER if there are (LEFT|RIGHT)_MODIFIER like LEFT_SHIFT. - for (std::set::const_iterator it = - modifier_keys_set->begin(); - it != modifier_keys_set->end(); ++it) { - std::map::const_iterator - item = data.find(*it); + for (auto it = modifier_keys_set->begin(); it != modifier_keys_set->end(); + ++it) { + auto item = data.find(*it); if (item != data.end()) { modifier_keys_set->insert(item->second); } @@ -97,7 +103,8 @@ bool IsModifierToBeSentOnKeyUp(const mozc::commands::KeyEvent &key_event) { } } // namespace -KeyEventHandler::KeyEventHandler() : key_translator_(new KeyTranslator) { +KeyEventHandler::KeyEventHandler() + : key_translator_(std::make_unique()) { Clear(); } @@ -225,7 +232,7 @@ bool KeyEventHandler::ProcessModifiers(bool is_key_up, uint32_t keyval, // implementation does NOT do it. if (currently_pressed_modifiers_.empty() || !modifiers_to_be_sent_.empty()) { - for (size_t i = 0; i < key_event->modifier_keys_size(); ++i) { + for (int i = 0; i < key_event->modifier_keys_size(); ++i) { modifiers_to_be_sent_.insert(key_event->modifier_keys(i)); } AddAdditionalModifiers(&modifiers_to_be_sent_); diff --git a/src/unix/fcitx5/fcitx_key_event_handler.h b/src/unix/fcitx5/fcitx_key_event_handler.h index 1ba2655a8..78942aa2f 100644 --- a/src/unix/fcitx5/fcitx_key_event_handler.h +++ b/src/unix/fcitx5/fcitx_key_event_handler.h @@ -33,10 +33,10 @@ #include +#include #include #include -#include "base/port.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" #include "unix/fcitx5/fcitx_key_translator.h" diff --git a/src/unix/fcitx5/fcitx_key_translator.cc b/src/unix/fcitx5/fcitx_key_translator.cc index fe5992ff6..6a95486ff 100644 --- a/src/unix/fcitx5/fcitx_key_translator.cc +++ b/src/unix/fcitx5/fcitx_key_translator.cc @@ -30,13 +30,23 @@ #include "unix/fcitx5/fcitx_key_translator.h" -#include "base/logging.h" +#include +#include + +#include +#include +#include +#include + +#include "absl/log/check.h" #include "base/vlog.h" +#include "protocol/commands.pb.h" +#include "protocol/config.pb.h" namespace fcitx { using namespace mozc; namespace { -static const auto kSpecialKeyMap = +const auto kSpecialKeyMap = new std::map({ {FcitxKey_space, commands::KeyEvent::SPACE}, {FcitxKey_Return, commands::KeyEvent::ENTER}, @@ -136,7 +146,7 @@ static const auto kSpecialKeyMap = // - FcitxKey_Kana_Lock? FcitxKey_KEY_Kana_Shift? }); -static const auto kIbusModifierMaskMap = new std::map({ +const auto kFcitxModifierMaskMap = new std::map({ {FcitxKey_Shift_L, KeyState::Shift}, {FcitxKey_Shift_R, KeyState::Shift}, {FcitxKey_Control_L, KeyState::Ctrl}, @@ -149,8 +159,8 @@ static const auto kIbusModifierMaskMap = new std::map({ // '4' is mapped to Japanese 'Hiragana Letter U' (without Shift modifier) and // 'Hiragana Letter Small U' (with Shift modifier). // TODO(team): Add kana_map_dv to support Dvoraklayout. -typedef std::map> KanaMap; -static const KanaMap *kKanaJpMap = new KanaMap({ +using KanaMap = std::map>; +const KanaMap *kKanaJpMap = new KanaMap({ {'1', {"ぬ", "ぬ"}}, {'!', {"ぬ", "ぬ"}}, {'2', {"ふ", "ふ"}}, @@ -251,7 +261,7 @@ static const KanaMap *kKanaJpMap = new KanaMap({ {U'¥', {"ー", "ー"}}, // U+00A5 }); -static const KanaMap *kKanaUsMap = new KanaMap({ +const KanaMap *kKanaUsMap = new KanaMap({ {'`', {"ろ", "ろ"}}, {'~', {"ろ", "ろ"}}, {'1', {"ぬ", "ぬ"}}, {'!', {"ぬ", "ぬ"}}, {'2', {"ふ", "ふ"}}, {'@', {"ふ", "ふ"}}, {'3', {"あ", "ぁ"}}, {'#', {"あ", "ぁ"}}, {'4', {"う", "ぅ"}}, @@ -307,7 +317,9 @@ bool KeyTranslator::Translate(KeySym keyval, uint32_t keycode, out_event->Clear(); /* this is key we cannot handle, don't process it */ - if (modifiers & KeyState::Super) return false; + if (modifiers & KeyState::Super) { + return false; + } // Due to historical reasons, many linux ditributions set Hiragana_Katakana // key as Hiragana key (which is Katkana key with shift modifier). So, we @@ -329,9 +341,9 @@ bool KeyTranslator::Translate(KeySym keyval, uint32_t keycode, out_event->add_modifier_keys(mozc::commands::KeyEvent::CAPS); } out_event->set_key_code(keyval); - } else if (auto it = kIbusModifierMaskMap->find(keyval); - it != kIbusModifierMaskMap->end()) { - // Convert Ibus modifier key to mask (e.g. FcitxKey_Shift_L to + } else if (auto it = kFcitxModifierMaskMap->find(keyval); + it != kFcitxModifierMaskMap->end()) { + // Convert Fcitx modifier key to mask (e.g. FcitxKey_Shift_L to // KeyState::Shift) modifiers |= it->second; } else if (auto it = kSpecialKeyMap->find(keyval); @@ -359,7 +371,7 @@ bool KeyTranslator::Translate(KeySym keyval, uint32_t keycode, } bool KeyTranslator::IsHiraganaKatakanaKeyWithShift(KeySym keyval, - uint32_t keycode, + uint32_t /*keycode*/, KeyStates modifiers) { return ((modifiers & KeyState::Shift) && (keyval == FcitxKey_Hiragana_Katakana)); @@ -407,8 +419,8 @@ bool KeyTranslator::IsPrintable(KeySym keyval, uint32_t keycode, return IsAscii(keyval, keycode, modifiers); } -bool KeyTranslator::IsAscii(KeySym keyval, uint32_t keycode, - KeyStates modifiers) { +bool KeyTranslator::IsAscii(KeySym keyval, uint32_t /*keycode*/, + KeyStates /*modifiers*/) { return (keyval > FcitxKey_space && // Note: Space key (0x20) is a special key in Mozc. keyval <= FcitxKey_asciitilde); // 0x7e. diff --git a/src/unix/fcitx5/fcitx_key_translator.h b/src/unix/fcitx5/fcitx_key_translator.h index 65c513dac..0991b386c 100644 --- a/src/unix/fcitx5/fcitx_key_translator.h +++ b/src/unix/fcitx5/fcitx_key_translator.h @@ -34,12 +34,10 @@ #include #include -#include -#include #include -#include "base/port.h" #include "protocol/commands.pb.h" +#include "protocol/config.pb.h" namespace fcitx { diff --git a/src/unix/fcitx5/i18nwrapper.h b/src/unix/fcitx5/i18nwrapper.h new file mode 100644 index 000000000..9680f1856 --- /dev/null +++ b/src/unix/fcitx5/i18nwrapper.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017~2017 by CSSlayer + * wengxt@gmail.com + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; see the file COPYING. If not, + * see . + */ + +#ifndef UNIX_FCITX5_I18NWRAPPER_H_ +#define UNIX_FCITX5_I18NWRAPPER_H_ + +#define FCITX_GETTEXT_DOMAIN "fcitx5-mozc" + +#include // IWYU pragma: export + +#endif diff --git a/src/unix/fcitx5/mozc_client_pool.cc b/src/unix/fcitx5/mozc_client_pool.cc index d3894a0de..d913c1f9a 100644 --- a/src/unix/fcitx5/mozc_client_pool.cc +++ b/src/unix/fcitx5/mozc_client_pool.cc @@ -30,13 +30,19 @@ #include "unix/fcitx5/mozc_client_pool.h" #include +#include +#include +#include +#include + +#include +#include +#include #include "unix/fcitx5/mozc_connection.h" namespace fcitx { -MozcClientHolder::MozcClientHolder() {} - MozcClientHolder::~MozcClientHolder() { if (pool_) { pool_->unregisterClient(key_); diff --git a/src/unix/fcitx5/mozc_client_pool.h b/src/unix/fcitx5/mozc_client_pool.h index 3b6eaa3bd..855e88234 100644 --- a/src/unix/fcitx5/mozc_client_pool.h +++ b/src/unix/fcitx5/mozc_client_pool.h @@ -30,8 +30,11 @@ #ifndef UNIX_FCITX5_MOZC_CLIENT_POOL_H_ #define UNIX_FCITX5_MOZC_CLIENT_POOL_H_ +#include #include +#include +#include #include #include "client/client_interface.h" @@ -45,7 +48,7 @@ class MozcClientHolder { friend class MozcClientPool; public: - MozcClientHolder(); + MozcClientHolder() = default; MozcClientHolder(MozcClientHolder &&) = delete; @@ -84,4 +87,4 @@ class MozcClientPool { } // namespace fcitx -#endif \ No newline at end of file +#endif diff --git a/src/unix/fcitx5/mozc_connection.cc b/src/unix/fcitx5/mozc_connection.cc index 3f281e44d..b88bf1254 100644 --- a/src/unix/fcitx5/mozc_connection.cc +++ b/src/unix/fcitx5/mozc_connection.cc @@ -30,10 +30,8 @@ #include "unix/fcitx5/mozc_connection.h" -#include +#include -#include "base/logging.h" -#include "base/util.h" #include "base/vlog.h" #include "client/client.h" #include "ipc/ipc.h" diff --git a/src/unix/fcitx5/mozc_connection.h b/src/unix/fcitx5/mozc_connection.h index 4d5e0eee4..1c9544a62 100644 --- a/src/unix/fcitx5/mozc_connection.h +++ b/src/unix/fcitx5/mozc_connection.h @@ -32,11 +32,6 @@ #define MOZC_UNIX_FCITX5_MOZC_CONNECTION_H_ #include -#include - -#include "base/port.h" -#include "protocol/commands.pb.h" -#include "unix/fcitx5/fcitx_key_event_handler.h" namespace mozc { diff --git a/src/unix/fcitx5/mozc_engine.cc b/src/unix/fcitx5/mozc_engine.cc index d00d31145..dfb7ecec7 100644 --- a/src/unix/fcitx5/mozc_engine.cc +++ b/src/unix/fcitx5/mozc_engine.cc @@ -20,23 +20,34 @@ #include "unix/fcitx5/mozc_engine.h" #include -#include +#include #include +#include +#include #include +#include +#include +#include +#include #include #include #include +#include +#include +#include #include -#include +#include +#include +#include -#include "base/clock.h" #include "base/init_mozc.h" #include "base/process.h" -#include "mozc_response_parser.h" +#include "protocol/commands.pb.h" +#include "unix/fcitx5/i18nwrapper.h" #include "unix/fcitx5/mozc_client_pool.h" -#include "unix/fcitx5/mozc_connection.h" #include "unix/fcitx5/mozc_response_parser.h" +#include "unix/fcitx5/mozc_state.h" namespace fcitx { @@ -104,12 +115,12 @@ MozcModeSubAction::MozcModeSubAction(MozcEngine *engine, } bool MozcModeSubAction::isChecked(InputContext *ic) const { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); return mozc_state->GetCompositionMode() == mode_; } void MozcModeSubAction::activate(InputContext *ic) { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); mozc_state->SendCompositionMode(mode_); } @@ -229,28 +240,28 @@ void MozcEngine::reloadConfig() { readAsIni(config_, "conf/mozc.conf"); ResetClientPool(); } -void MozcEngine::activate(const fcitx::InputMethodEntry &, +void MozcEngine::activate(const fcitx::InputMethodEntry & /*entry*/, fcitx::InputContextEvent &event) { if (client_) { client_->EnsureConnection(); } - auto ic = event.inputContext(); - auto mozc_state = mozcState(ic); + auto *ic = event.inputContext(); + auto *mozc_state = mozcState(ic); mozc_state->FocusIn(); ic->statusArea().addAction(StatusGroup::InputMethod, &toolAction_); } -void MozcEngine::deactivate(const fcitx::InputMethodEntry &, +void MozcEngine::deactivate(const fcitx::InputMethodEntry & /*entry*/, fcitx::InputContextEvent &event) { - auto ic = event.inputContext(); + auto *ic = event.inputContext(); deactivating_ = true; - auto mozc_state = mozcState(ic); + auto *mozc_state = mozcState(ic); mozc_state->FocusOut(event); deactivating_ = false; } void MozcEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) { - auto mozc_state = mozcState(event.inputContext()); + auto *mozc_state = mozcState(event.inputContext()); - auto &group = instance_->inputMethodManager().currentGroup(); + const auto &group = instance_->inputMethodManager().currentGroup(); std::string layout = group.layoutFor(entry.uniqueName()); if (layout.empty()) { layout = group.defaultLayout(); @@ -265,8 +276,9 @@ void MozcEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) { } } -void MozcEngine::reset(const InputMethodEntry &, InputContextEvent &event) { - auto mozc_state = mozcState(event.inputContext()); +void MozcEngine::reset(const InputMethodEntry & /*entry*/, + InputContextEvent &event) { + auto *mozc_state = mozcState(event.inputContext()); mozc_state->Reset(); } @@ -277,15 +289,15 @@ void MozcEngine::save() { client_->SyncData(); } -std::string MozcEngine::subMode(const fcitx::InputMethodEntry &, +std::string MozcEngine::subMode(const fcitx::InputMethodEntry & /*entry*/, fcitx::InputContext &ic) { - auto mozc_state = mozcState(&ic); + auto *mozc_state = mozcState(&ic); return _(kPropCompositionModes[mozc_state->GetCompositionMode()].description); } -std::string MozcEngine::subModeIconImpl(const fcitx::InputMethodEntry &, - fcitx::InputContext &ic) { - auto mozc_state = mozcState(&ic); +std::string MozcEngine::subModeIconImpl( + const fcitx::InputMethodEntry & /*unused*/, fcitx::InputContext &ic) { + auto *mozc_state = mozcState(&ic); return _(kPropCompositionModes[mozc_state->GetCompositionMode()].icon); } @@ -305,7 +317,7 @@ AddonInstance *MozcEngine::clipboardAddon() { return clipboard(); } void MozcEngine::ResetClientPool() { if (pool_->policy() != GetSharedStatePolicy()) { instance_->inputContextManager().foreach ([this](InputContext *ic) { - if (auto state = this->mozcState(ic)) { + if (auto *state = this->mozcState(ic)) { state->ReleaseClient(); } return true; diff --git a/src/unix/fcitx5/mozc_engine.h b/src/unix/fcitx5/mozc_engine.h index 21b41e0cc..1f3e0f8fb 100644 --- a/src/unix/fcitx5/mozc_engine.h +++ b/src/unix/fcitx5/mozc_engine.h @@ -21,18 +21,31 @@ #include #include -#include +#include +#include +#include #include #include #include #include +#include #include +#include +#include +#include #include #include #include +#include +#include +#include + #include "base/file_util.h" #include "base/system_util.h" +#include "client/client_interface.h" +#include "protocol/commands.pb.h" +#include "unix/fcitx5/i18nwrapper.h" #include "unix/fcitx5/mozc_client_pool.h" #include "unix/fcitx5/mozc_state.h" @@ -97,8 +110,8 @@ FCITX_CONFIGURATION( class MozcModeSubAction : public SimpleAction { public: MozcModeSubAction(MozcEngine *engine, mozc::commands::CompositionMode mode); - bool isChecked(fcitx::InputContext *) const override; - void activate(fcitx::InputContext *) override; + bool isChecked(fcitx::InputContext *ic) const override; + void activate(fcitx::InputContext *ic) override; private: MozcEngine *engine_; @@ -118,8 +131,8 @@ class MozcEngine final : public InputMethodEngineV2 { void reloadConfig() override; void reset(const InputMethodEntry &entry, InputContextEvent &event) override; void save() override; - std::string subMode(const fcitx::InputMethodEntry &, - fcitx::InputContext &) override; + std::string subMode(const fcitx::InputMethodEntry & /*entry*/, + fcitx::InputContext &ic) override; std::string subModeIconImpl(const InputMethodEntry &entry, InputContext &ic) override; diff --git a/src/unix/fcitx5/mozc_engine_factory.cc b/src/unix/fcitx5/mozc_engine_factory.cc index dc8316e4b..7ba6e799e 100644 --- a/src/unix/fcitx5/mozc_engine_factory.cc +++ b/src/unix/fcitx5/mozc_engine_factory.cc @@ -16,16 +16,17 @@ * License along with this library; see the file COPYING. If not, * see . */ -#include +#include #include #include #include -#include +#include #include #include "base/system_util.h" #include "mozc_engine.h" +#include "unix/fcitx5/i18nwrapper.h" namespace fcitx { class MozcEngineFactory : public AddonFactory { diff --git a/src/unix/fcitx5/mozc_response_parser.cc b/src/unix/fcitx5/mozc_response_parser.cc index ec0224c63..0fe9cc020 100644 --- a/src/unix/fcitx5/mozc_response_parser.cc +++ b/src/unix/fcitx5/mozc_response_parser.cc @@ -30,21 +30,32 @@ #include "unix/fcitx5/mozc_response_parser.h" -#include +#include +#include #include #include #include #include - +#include + +#include +#include +#include +#include +#include +#include #include +#include #include -#include "base/logging.h" -#include "base/process.h" -#include "base/util.h" +#include "absl/log/check.h" +#include "absl/log/log.h" #include "base/vlog.h" +#include "protocol/candidates.pb.h" #include "protocol/commands.pb.h" +#include "unix/fcitx5/i18nwrapper.h" #include "unix/fcitx5/mozc_engine.h" +#include "unix/fcitx5/mozc_state.h" #include "unix/fcitx5/surrounding_text_util.h" namespace fcitx { @@ -71,10 +82,10 @@ std::string CreateDescriptionString(const std::string &description) { class MozcCandidateWord final : public CandidateWord { public: MozcCandidateWord(int id, std::string text, MozcEngine *engine) - : CandidateWord(Text(text)), id_(id), engine_(engine) {} + : CandidateWord(Text(std::move(text))), id_(id), engine_(engine) {} void select(InputContext *inputContext) const override { - auto mozc_state = engine_->mozcState(inputContext); + MozcState *mozc_state = engine_->mozcState(inputContext); mozc_state->SelectCandidate(id_); } @@ -89,7 +100,7 @@ class MozcCandidateList final : public CandidateList, MozcCandidateList(const mozc::commands::Candidates &candidates, InputContext *ic, MozcEngine *engine, bool use_annotation) : ic_(ic), engine_(engine) { - auto state = engine_->mozcState(ic); + auto *state = engine_->mozcState(ic); setPageable(this); bool index_visible = false; if (candidates.has_footer()) { @@ -123,7 +134,9 @@ class MozcCandidateList final : public CandidateList, const mozc::commands::InformationList &usages = candidates.usages(); for (size_t i = 0; i < usages.information().size(); ++i) { const mozc::commands::Information &information = usages.information(i); - if (!information.has_id() || !information.has_description()) continue; + if (!information.has_id() || !information.has_description()) { + continue; + } usage_map[information.id()].first = information.title(); usage_map[information.id()].second = information.description(); } @@ -217,11 +230,11 @@ class MozcCandidateList final : public CandidateList, bool hasPrev() const override { return hasPrev_; } bool hasNext() const override { return hasNext_; } void prev() override { - auto mozc_state = engine_->mozcState(ic_); + auto *mozc_state = engine_->mozcState(ic_); mozc_state->Paging(true); } void next() override { - auto mozc_state = engine_->mozcState(ic_); + auto *mozc_state = engine_->mozcState(ic_); mozc_state->Paging(false); } @@ -264,7 +277,7 @@ void MozcResponseParser::UpdateDeletionRange( void MozcResponseParser::LaunchTool(const mozc::commands::Output &response, InputContext *ic) const { if (response.has_launch_tool_mode()) { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); mozc_state->GetClient()->LaunchToolWithProtoBuf(response); } } @@ -317,7 +330,7 @@ void MozcResponseParser::ExecuteCallback(const mozc::commands::Output &response, return; } - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); mozc::commands::Output new_output; if (!mozc_state->SendCommand(session_command, &new_output)) { LOG(ERROR) << "Callback Command Failed"; @@ -349,7 +362,7 @@ void MozcResponseParser::ExecuteCallback(const mozc::commands::Output &response, bool MozcResponseParser::ParseResponse(const mozc::commands::Output &response, InputContext *ic) const { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); mozc_state->SetUsage("", ""); UpdateDeletionRange(response, ic); @@ -396,7 +409,7 @@ bool MozcResponseParser::ParseResponse(const mozc::commands::Output &response, void MozcResponseParser::ParseResult(const mozc::commands::Result &result, InputContext *ic) const { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); switch (result.type()) { case mozc::commands::Result::NONE: { mozc_state->SetAuxString("No result"); // not a fatal error. @@ -411,7 +424,7 @@ void MozcResponseParser::ParseResult(const mozc::commands::Result &result, void MozcResponseParser::ParseCandidates( const mozc::commands::Candidates &candidates, InputContext *ic) const { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); const mozc::commands::Footer &footer = candidates.footer(); if (candidates.has_footer()) { std::string auxString; @@ -444,7 +457,7 @@ void MozcResponseParser::ParseCandidates( void MozcResponseParser::ParsePreedit(const mozc::commands::Preedit &preedit, uint32_t position, InputContext *ic) const { - auto mozc_state = engine_->mozcState(ic); + auto *mozc_state = engine_->mozcState(ic); Text preedit_text; std::string s; diff --git a/src/unix/fcitx5/mozc_state.cc b/src/unix/fcitx5/mozc_state.cc index e438d1d43..c5e3308a9 100644 --- a/src/unix/fcitx5/mozc_state.cc +++ b/src/unix/fcitx5/mozc_state.cc @@ -29,23 +29,31 @@ #include "unix/fcitx5/mozc_state.h" -#include +#include +#include +#include #include #include #include +#include #include +#include +#include +#include +#include #include +#include -#include "base/const.h" -#include "base/file_util.h" -#include "base/logging.h" +#include "absl/log/check.h" +#include "absl/log/log.h" #include "base/process.h" -#include "base/system_util.h" -#include "base/util.h" #include "base/vlog.h" #include "client/client_interface.h" +#include "protocol/commands.pb.h" +#include "protocol/config.pb.h" #include "unix/fcitx5/fcitx_key_event_handler.h" +#include "unix/fcitx5/i18nwrapper.h" #include "unix/fcitx5/mozc_connection.h" #include "unix/fcitx5/mozc_engine.h" #include "unix/fcitx5/mozc_response_parser.h" @@ -119,8 +127,9 @@ bool MozcState::TrySendKeyEvent( mozc::commands::KeyEvent event; if (!handler_->GetKeyEvent(sym, keycode, state, preedit_method_, layout_is_jp, - is_key_up, &event)) + is_key_up, &event)) { return false; + } if ((composition_mode == mozc::commands::DIRECT) && !client->IsDirectModeCommand(event)) { @@ -136,13 +145,13 @@ bool MozcState::TrySendKeyEvent( context.set_following_text(surrounding_text_info.following_text); } - MOZC_VLOG(1) << "TrySendKeyEvent: " << std::endl << event.DebugString(); + MOZC_VLOG(1) << "TrySendKeyEvent: " << event.DebugString(); if (!client->SendKeyWithContext(event, context, out)) { *out_error = "SendKey failed"; MOZC_VLOG(1) << "ERROR"; return false; } - MOZC_VLOG(1) << "OK: " << std::endl << out->DebugString(); + MOZC_VLOG(1) << "OK: " << out->DebugString(); return true; } @@ -188,13 +197,13 @@ bool MozcState::TrySendCommand(mozc::commands::SessionCommand::CommandType type, bool MozcState::TrySendRawCommand(const mozc::commands::SessionCommand& command, mozc::commands::Output* out, std::string* out_error) const { - MOZC_VLOG(1) << "TrySendRawCommand: " << std::endl << command.DebugString(); + MOZC_VLOG(1) << "TrySendRawCommand: " << command.DebugString(); if (!GetClient()->SendCommand(command, out)) { *out_error = "SendCommand failed"; MOZC_VLOG(1) << "ERROR"; return false; } - MOZC_VLOG(1) << "OK: " << std::endl << out->DebugString(); + MOZC_VLOG(1) << "OK: " << out->DebugString(); return true; } @@ -378,10 +387,10 @@ void MozcState::DrawAll() { } } else { Text preedit = preedit_; - if (preedit.size()) { + if (!preedit.empty()) { preedit.append(" "); preedit.append(aux); - ic_->inputPanel().setPreedit(std::move(preedit)); + ic_->inputPanel().setPreedit(preedit); } else if (!aux_.empty()) { ic_->inputPanel().setAuxUp(Text(aux)); } diff --git a/src/unix/fcitx5/mozc_state.h b/src/unix/fcitx5/mozc_state.h index 5df755193..da09dc604 100644 --- a/src/unix/fcitx5/mozc_state.h +++ b/src/unix/fcitx5/mozc_state.h @@ -35,16 +35,17 @@ #include #include +#include #include +#include -#include "base/port.h" -#include "base/run_level.h" #include "client/client_interface.h" #include "protocol/commands.pb.h" +#include "protocol/config.pb.h" #include "unix/fcitx5/mozc_client_pool.h" namespace fcitx { -const int32_t kBadCandidateId = -12345; +inline const int32_t kBadCandidateId = -12345; class MozcConnectionInterface; class MozcResponseParser; class KeyTranslator; @@ -89,7 +90,7 @@ class MozcState : public InputContextProperty { // Sets the url to be opened by the default browser. void SetUrl(const std::string &url); - const std::string &GetIconFile(const std::string key); + const std::string &GetIconFile(std::string key); mozc::commands::CompositionMode GetCompositionMode() { return composition_mode_; @@ -138,7 +139,7 @@ class MozcState : public InputContextProperty { // Parses the response from mozc_server. Returns whether the server consumes // the input or not (true means 'consumed'). - bool ParseResponse(const mozc::commands::Output &request); + bool ParseResponse(const mozc::commands::Output &raw_response); void ClearAll(); void DrawPreeditInfo(); diff --git a/src/unix/fcitx5/surrounding_text_util.cc b/src/unix/fcitx5/surrounding_text_util.cc index f4b881203..bed152e90 100644 --- a/src/unix/fcitx5/surrounding_text_util.cc +++ b/src/unix/fcitx5/surrounding_text_util.cc @@ -30,13 +30,18 @@ #include "unix/fcitx5/surrounding_text_util.h" #include +#include #include +#include +#include +#include +#include #include #include -#include "base/logging.h" -#include "base/port.h" +#include "absl/log/check.h" +#include "absl/log/log.h" #include "base/util.h" #include "base/vlog.h" diff --git a/src/unix/fcitx5/surrounding_text_util.h b/src/unix/fcitx5/surrounding_text_util.h index 77885ee51..8370b74e0 100644 --- a/src/unix/fcitx5/surrounding_text_util.h +++ b/src/unix/fcitx5/surrounding_text_util.h @@ -32,18 +32,15 @@ #include +#include #include -#include "base/port.h" - namespace fcitx { class AddonInstance; struct SurroundingTextInfo { - SurroundingTextInfo() : relative_selected_length(0) {} - - int32_t relative_selected_length; + int32_t relative_selected_length = 0; std::string preceding_text; std::string selection_text; std::string following_text;