diff --git a/honoka/libhonoka/Makefile.am b/honoka/libhonoka/Makefile.am index f579a1e..d20b832 100644 --- a/honoka/libhonoka/Makefile.am +++ b/honoka/libhonoka/Makefile.am @@ -25,7 +25,7 @@ -DHONOKA_ICON_FILE=\"@SCIM_ICONDIR@/honoka.png\" \ -DHONOKA_PLUGINDIR=\"@SCIM_MODULEDIR@/honoka\" -noinst_HEADERS = +noinst_HEADERS = honokatimer.h moduledir = @SCIM_MODULEDIR@/IMEngine @@ -35,7 +35,8 @@ lib_LTLIBRARIES = libhonoka_plugin.la libhonoka_plugin_la_SOURCES = convertor.cpp honokapluginbase.cpp preeditor.cpp \ - honokakeyeventlist.cpp honokamultiplepluginbase.cpp predictor.cpp resultlist.cpp + honokakeyeventlist.cpp honokamultiplepluginbase.cpp predictor.cpp resultlist.cpp \ + honokatimer.cpp libhonoka_plugin_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ libhonoka_plugin_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ libhonoka_plugin_la_LDFLAGS = @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ diff --git a/honoka/libhonoka/honokatimer.cpp b/honoka/libhonoka/honokatimer.cpp new file mode 100644 index 0000000..214f57a --- /dev/null +++ b/honoka/libhonoka/honokatimer.cpp @@ -0,0 +1,153 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "honokatimer.h" +#include +#include + +using namespace Honoka; + +HonokaTimer::HonokaTimer() +{ + bef = 1; + eventCount = 0; + timer_pid = -1; + scim::HelperInfo info( + HONOKA_TIMER_UUID, + "Honoka Timer", + "", + "Honoka Timer", + SCIM_HELPER_STAND_ALONE); + String display = getenv("DISPLAY"); + id = agent.open_connection(info,display); +} + + +HonokaTimer::~HonokaTimer() +{ + if (id != -1) agent.close_connection(); + if (timer_pid > 0) { + kill(timer_pid,SIGKILL); + wait(NULL); + } +} + +HonokaTimer * HonokaTimer::_self = 0; + + + +/*! + \fn Honoka::HonokaTimer::self() + */ +HonokaTimer * Honoka::HonokaTimer::self() +{ + if (!_self) { + _self = new HonokaTimer(); + _self->exec(); + } + return _self; +} + + +/*! + \fn Honoka::HonokaTimer::destruct() + */ +void Honoka::HonokaTimer::destruct() +{ + if (_self == 0) return; + delete _self; + _self = 0; +} + + +/*! + \fn Honoka::HonokaTimer::timer() + */ +void Honoka::HonokaTimer::timer() +{ + Transaction trans; + uint32 counter = 1; + while(1) { + usleep(HONOKA_TIMER_INTERVAL); + trans.clear(); + trans.put_command(HONOKA_TRANS_TIMER); + trans.put_data(counter); + agent.send_imengine_event(-1,"8bb03c1c-db6c-41b1-91bd-b7fb7dd70343",trans); + if ((counter ++) == 0) counter ++; + } +} + + +/*! + \fn Honoka::HonokaTimer::exec() + */ +void Honoka::HonokaTimer::exec() +{ + timer_pid = fork(); + if (timer_pid == 0) timer(); +} + + +/*! + \fn Honoka::HonokaTimer::decode(const Transaction &trans) + */ +uint32 Honoka::HonokaTimer::decode(const Transaction &trans) +{ + TransactionReader reader(trans); + int cmd; + if (reader.get_command(cmd)) { + if (cmd == HONOKA_TRANS_TIMER) { + uint32 c; + reader.get_data(c); + return c; + } + } + return 0; +} + + +/*! + \fn Honoka::HonokaTimer::eventFilter(const Transaction &trans) + */ +vector Honoka::HonokaTimer::eventFilter(const Transaction &trans) +{ + vector res; + uint32 c = decode(trans); + if (c == 0) return res; + for(uint32 i = bef;i != c;i ++) { + map::iterator it = events.find(i); + if (it == events.end()) break; + res.push_back(it->second); + events.erase(it); + } + bef = c; + return res; +} + + +/*! + \fn Honoka::HonokaTimer::appendDelayEvent(uint32 delay) + */ +int Honoka::HonokaTimer::appendDelayEvent(uint32 delay) +{ + eventCount ++; + events.insert(pair(bef + delay,eventCount)); + return eventCount; +} diff --git a/honoka/libhonoka/honokatimer.h b/honoka/libhonoka/honokatimer.h new file mode 100644 index 0000000..f7808ba --- /dev/null +++ b/honoka/libhonoka/honokatimer.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef HONOKAHONOKATIMER_H +#define HONOKAHONOKATIMER_H + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define Uses_SCIM_UTILITY +#define Uses_SCIM_HELPER +#define Uses_SCIM_TRANS_COMMANDS + +#include +#include +#include + +#define HONOKA_TIMER_UUID "050ba7c6-0fe2-4b37-a913-7903bc2c6215" +#define HONOKA_TIMER_INTERVAL 100000 +#define HONOKA_TRANS_TIMER SCIM_TRANS_CMD_USER_DEFINED + 0 +using namespace scim; +using namespace std; + +namespace Honoka { + +/** +@author TAM (Teppei Tamra) +*/ +class HonokaTimer; +class HonokaTimer{ +protected: + HonokaTimer(); + + ~HonokaTimer(); + void timer(); + void exec(); +public: + static HonokaTimer * self(); + static void destruct(); + uint32 decode(const Transaction &trans); + vector eventFilter(const Transaction &trans); + int appendDelayEvent(uint32 delay); + +protected: + static HonokaTimer * _self; + HelperAgent agent; + int id; + pid_t timer_pid; + uint32 bef; + int eventCount; + map events; +}; + +} + + +#endif diff --git a/honoka/m4/Makefile b/honoka/m4/Makefile index 72a101b..60560a1 100644 --- a/honoka/m4/Makefile +++ b/honoka/m4/Makefile @@ -114,8 +114,8 @@ HAVE_WPRINTF = 0 HONOKA_MAJOR_VERSION = 0 HONOKA_MICRO_VERSION = 0 -HONOKA_MINOR_VERSION = 4 -HONOKA_VERSION = 0.4.0 +HONOKA_MINOR_VERSION = 8 +HONOKA_VERSION = 0.8.0 INSTALL_DATA = ${INSTALL} -m 644 INSTALL_LTDL_FALSE = INSTALL_LTDL_TRUE = # @@ -147,9 +147,9 @@ PACKAGE = honoka PACKAGE_BUGREPORT = tam-t@par.odn.ne.jp PACKAGE_NAME = honoka -PACKAGE_STRING = honoka 0.4.0 +PACKAGE_STRING = honoka 0.8.0 PACKAGE_TARNAME = honoka -PACKAGE_VERSION = 0.4.0 +PACKAGE_VERSION = 0.8.0 PATH_SEPARATOR = : PKG_CONFIG = /usr/bin/pkg-config POSUB = po @@ -171,7 +171,7 @@ STRIP = strip USE_INCLUDED_LIBINTL = no USE_NLS = yes -VERSION = 0.4.0 +VERSION = 0.8.0 WNNCONVERSION = WNNCONVERSION_FALSE = # WNNCONVERSION_TRUE = diff --git a/honoka/src/honoka_def.h b/honoka/src/honoka_def.h index 7cff608..72de5cb 100644 --- a/honoka/src/honoka_def.h +++ b/honoka/src/honoka_def.h @@ -117,6 +117,8 @@ #define HONOKA_CONFIG_REALTIME_PREDICTION "/IMEngine/Honoka/RealtimePrediction" #define HONOKA_DEFAULT_REALTIME_PREDICTION true +#define HONOKA_CONFIG_PREDICTION_DELAY "/IMEngine/Honoka/PredictionDelay" +#define HONOKA_DEFAULT_PREDICTION_DELAY 0 #define HONOKA_PROP_MODESTATUS "/IMEngine/Honoka/Property/ModeStatus" #define HONOKA_PROP_INPUTMODE "/IMEngine/Honoka/InputMode" diff --git a/honoka/src/honoka_imengine.cpp b/honoka/src/honoka_imengine.cpp index 37a1a7d..bdd7fe4 100644 --- a/honoka/src/honoka_imengine.cpp +++ b/honoka/src/honoka_imengine.cpp @@ -41,6 +41,7 @@ // scim�Τ��ޤ��ʤ��� #include "honoka_imengine.h" +#include "honokatimer.h" #include "honoka_def.h" #define scim_module_init honoka_LTX_scim_module_init @@ -164,6 +165,7 @@ HonokaInstance::~HonokaInstance() { + HonokaTimer::destruct(); for(unsigned int i = 0;i < plugins.size();i ++) { plugins[i].deleteInstance(plugins[i].instance); dlclose(plugins[i].dll); @@ -327,6 +329,7 @@ defaultConvertor = _scim_config->read(String(HONOKA_CONFIG_DEFAULT_CONVERTOR),String(HONOKA_DEFAULT_DEFAULT_CONVERTOR)); defaultPredictor = _scim_config->read(String(HONOKA_CONFIG_DEFAULT_PREDICTOR),String(HONOKA_DEFAULT_DEFAULT_PREDICTOR)); auto_conversion = _scim_config->read(String(HONOKA_CONFIG_AUTO_CONVERSION),HONOKA_DEFAULT_AUTO_CONVERSION);; + predictionDelay = _scim_config->read(String(HONOKA_CONFIG_PREDICTION_DELAY),HONOKA_DEFAULT_PREDICTION_DELAY); // �ǥե���ȥ������ꡣ scim_string_to_key_list(k_conversion_start, @@ -459,6 +462,7 @@ _scim_config->read(String(HONOKA_CONFIG_KEY_PREDICTOR_PREFIX) + String("/") + predictors[i]->getName(),String(""))); k_predictor.push_back(k); } + } @@ -671,16 +675,21 @@ } // Prediction if ((!m_conversion) && realtime_prediction && prediction && m_predictor->isConnected() && (!auto_conversion)) { - m_convList = m_predictor->getPredictionList(m_preeditor->getText()); - if (m_convList.count()) { - m_lookup_table.clear(); - for(unsigned int i = 0;i < m_convList.count();i ++) { - m_lookup_table.append_candidate(m_convList.kouho.at(i).kanji); - } - startLookup(); - } else { - //m_lookup_table.clear(); + if (predictionDelay > 0) { + preeditKeyDelay = HonokaTimer::self()->appendDelayEvent(predictionDelay); hide_lookup_table(); + } else { + m_convList = m_predictor->getPredictionList(m_preeditor->getText()); + if (m_convList.count()) { + m_lookup_table.clear(); + for(unsigned int i = 0;i < m_convList.count();i ++) { + m_lookup_table.append_candidate(m_convList.kouho.at(i).kanji); + } + startLookup(); + } else { + //m_lookup_table.clear(); + hide_lookup_table(); + } } } else hide_lookup_table(); } else { @@ -717,6 +726,16 @@ updateProperty(); } +void HonokaInstance::process_helper_event (const String &helper_uuid, const Transaction &trans) +{ + if (helper_uuid == HONOKA_TIMER_UUID) { + vector e = HonokaTimer::self()->eventFilter(trans); + for(unsigned int i = 0;i < e.size();i ++) { + timerEvent(e[i]); + } + } +} + bool HonokaInstance::process_key_event (const KeyEvent& key) { @@ -731,6 +750,14 @@ // �������٥�Ƚ����� //if (key.is_key_release()) return false; + /* + trans.clear(); + trans.put_command(SCIM_TRANS_CMD_REQUEST); + trans.put_command(SCIM_TRANS_CMD_PROCESS_KEY_EVENT); + trans.put_data(key); + send_helper_event("e135e0ee-5588-423e-a027-f07d769c12a3",trans); + */ + KeyEvent ke = key; if (ke.mask & SCIM_KEY_CapsLockMask) ke.mask -= SCIM_KEY_CapsLockMask; if (ke.mask & SCIM_KEY_NumLockMask) ke.mask -= SCIM_KEY_NumLockMask; @@ -1548,3 +1575,35 @@ + + +/*! + \fn HonokaInstance::timerEvent(int id) + */ +void HonokaInstance::timerEvent(int id) +{ + if ((id == preeditKeyDelay) && (!m_conversion) && (!m_prediction)) { + WideString w = m_preeditor->getText(); + if (!w.length()) { + hide_lookup_table(); + return; + } + m_convList = m_predictor->getPredictionList(w); + if (m_convList.count()) { + m_lookup_table.clear(); + for(unsigned int i = 0;i < m_convList.count();i ++) { + m_lookup_table.append_candidate(m_convList.kouho.at(i).kanji); + } + if (w == m_preeditor->getText()) startLookup(); + else hide_lookup_table(); + } else { + //m_lookup_table.clear(); + hide_lookup_table(); + } + } +} + + + + + diff --git a/honoka/src/honoka_imengine.h b/honoka/src/honoka_imengine.h index de9aac5..119eea3 100644 --- a/honoka/src/honoka_imengine.h +++ b/honoka/src/honoka_imengine.h @@ -31,7 +31,7 @@ #define Uses_SCIM_LOOKUP_TABLE #define Uses_SCIM_CONFIG_BASE #define Uses_SCIM_ICONV - +#define Uses_SCIM_TRANS_COMMANDS #include #include @@ -110,9 +110,11 @@ virtual void focus_in (); virtual void focus_out (); virtual void trigger_property (const String &property); + virtual void process_helper_event (const String &helper_uuid, const Transaction &trans); void startLookup(); protected: + Transaction trans; CommonLookupTable m_lookup_table; PreEditor *m_preeditor; Convertor *m_convertor; @@ -146,6 +148,8 @@ Convertor *m_multi; vector segments; ACPredictor *acpredictor; + int preeditKeyDelay; + uint32 predictionDelay; protected: bool process_preedit_key_event(const KeyEvent &key); bool process_conversion_key_event(const KeyEvent &key); @@ -167,6 +171,7 @@ const WideString getConvertedText(); const AttributeList getConvertedAttributeList(); void updateConvertedString(); + void timerEvent(int id); private: HonokaKeyEventList k_conversion_start, // �Ѵ�����