[uim-commit] r901 - trunk/xim
ekato at freedesktop.org
ekato at freedesktop.org
Tue Jun 21 00:36:32 PDT 2005
Author: ekato
Date: 2005-06-21 00:36:26 -0700 (Tue, 21 Jun 2005)
New Revision: 901
Modified:
trunk/xim/connection.cpp
trunk/xim/connection.h
trunk/xim/convdisp.cpp
trunk/xim/main.cpp
trunk/xim/xim.h
trunk/xim/ximtrans.cpp
Log:
* uim-xim : Improve packet handling with async
(on-demand-synchronous) event flow.
* xim/xim.h (class Connection) : Remove unused OnPushPacket()
member. Add setter and getter for new mPreeditCaretSyncFlag
member. Remove mPendingRxQ member. Add xim_preedit_start_reply()
and xim_preedit_caret_reply() member. Rename clear_pending_rx()
as clear_pending_queue().
* xim/connection.h (class XConnection) : Add new member function
writePendingPacket(), writePassivePacket(), and
writeNormalPacket().
* xim/connection.cpp (XConnection::writePendingPacket) : New
function divided from writeProc().
(XConnection::writePassivePacket) : Ditto.
(XConnection::writeNormalPacket) : Ditto.
(XConnection::writeProc) : Simplify.
* xim/ximtrans.cpp (Connection::OnRecv) : Handle
XIM_PREEDIT_CARET_REPLY.
(Connection::setPreeditCaretSyncFlag) : New.
(Connection::unsetPreeditCaretSyncFlag) : Ditto.
(Connection::hasPreeditCaretSyncFlag) : Ditto.
(Connection::xim_forward_event) : Don't use mPendingRxQ.
(Connection::xim_sync_reply) : Ditto.
(Connection::xim_preedit_start_reply) : Remove unused parameter.
(Connection::xim_preedit_caret_reply) : New function.
(Connection::clear_pending_queue) : Renamed from
clear_pending_rx().
* xim/convdisp.cpp (ConvdispOs::update_preedit) : Send
XIM_PREEDIT_CARET packet.
Modified: trunk/xim/connection.cpp
===================================================================
--- trunk/xim/connection.cpp 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/connection.cpp 2005-06-21 07:36:26 UTC (rev 901)
@@ -245,28 +245,100 @@
return true;
}
-void XConnection::writeProc()
+void XConnection::writePendingPacket()
{
std::list<TxPacket *>::iterator i, j;
- std::list<TxPacket *> tmp;
+ bool sent_preedit_done = false;
int major;
- if (!mTxQ.size() && !mPTxQ.size())
- return;
+ while (mPendingTxQ.size()) {
+ if (hasSyncFlag() || hasPreeditStartSyncFlag() ||
+ hasPreeditCaretSyncFlag())
+ break;
- OnSend(); // add XIM_COMMIT packet to passive queue
+ i = mPendingTxQ.begin();
+ major = (*i)->get_major();
- // handle passive (i.e. precedent) packets
+ switch (major) {
+ case XIM_COMMIT:
+ case XIM_FORWARD_EVENT:
+ setSyncFlag();
+ break;
+ case XIM_PREEDIT_START:
+ setPreeditStartSyncFlag();
+ break;
+ case XIM_PREEDIT_CARET:
+ setPreeditCaretSyncFlag();
+ break;
+ case XIM_PREEDIT_DONE:
+ sent_preedit_done = true;
+ default:
+ break;
+ }
+
+ doSend(*i, true);
+ delete *i;
+ mPendingTxQ.pop_front();
+
+ // XIM_PREEDIT_START/DRAW just after XIM_PREEDIT_DONE maybe
+ // need to wait XIM_COMMIT and its XIM_SYNC_REPLY
+ if (sent_preedit_done == true) {
+ // push first XIM_COMMIT into the head of the queue
+ std::list<TxPacket *> tmp;
+ bool first = true;
+ while (mPendingTxQ.size()) {
+ j = mPendingTxQ.begin();
+ major = (*j)->get_major();
+ if (major == XIM_COMMIT && first == true) {
+ tmp.push_front(*j);
+ first = false;
+ } else
+ tmp.push_back(*j);
+
+ mPendingTxQ.pop_front();
+ }
+ mPendingTxQ = tmp;
+ sent_preedit_done = false;
+ }
+ }
+}
+
+void XConnection::writePassivePacket()
+{
+ std::list<TxPacket *>::iterator i, j;
bool sent_preedit_done = false;
+ int major;
+
while (mPTxQ.size()) {
+ if (mPendingTxQ.size())
+ break;
+
i = mPTxQ.begin();
+
+ if (hasSyncFlag() || hasPreeditStartSyncFlag() ||
+ hasPreeditCaretSyncFlag()) {
+ mPendingTxQ.push_back(*i);
+ mPTxQ.pop_front();
+ break;
+ }
+
major = (*i)->get_major();
-
- if (major == XIM_COMMIT)
+ switch (major) {
+ case XIM_COMMIT:
setSyncFlag();
-
- if (major == XIM_PREEDIT_DONE)
+ break;
+ case XIM_PREEDIT_START:
+ setPreeditStartSyncFlag();
+ break;
+ case XIM_PREEDIT_CARET:
+ setPreeditCaretSyncFlag();
+ break;
+ case XIM_PREEDIT_DONE:
sent_preedit_done = true;
+ break;
+ default:
+ break;
+ }
doSend(*i, true);
delete *i;
@@ -276,6 +348,7 @@
// need to wait XIM_COMMIT and its XIM_SYNC_REPLY
if (sent_preedit_done == true) {
// push first XIM_COMMIT into the head of passive queue
+ std::list<TxPacket *> tmp;
bool first = true;
while (mPTxQ.size()) {
j = mPTxQ.begin();
@@ -292,8 +365,13 @@
sent_preedit_done = false;
}
}
+}
- // handle normal packets
+void XConnection::writeNormalPacket()
+{
+ std::list<TxPacket *>::iterator i;
+ int major;
+
while (mTxQ.size()) {
i = mTxQ.begin();
major = (*i)->get_major();
@@ -310,7 +388,16 @@
delete *i;
mTxQ.pop_front();
}
+}
+void XConnection::writeProc()
+{
+ OnSend(); // add XIM_COMMIT packet to passive queue
+
+ writePendingPacket();
+ writePassivePacket();
+ writeNormalPacket();
+
XFlush(XimServer::gDpy);
if (mIsCloseWait) {
remove_window_watch(mClientWin);
Modified: trunk/xim/connection.h
===================================================================
--- trunk/xim/connection.h 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/connection.h 2005-06-21 07:36:26 UTC (rev 901)
@@ -47,6 +47,9 @@
void readProc(XClientMessageEvent *);
void writeProc();
+ void writePendingPacket();
+ void writePassivePacket();
+ void writeNormalPacket();
bool isValid() {return mIsValid;};
private:
bool readToBuf(XClientMessageEvent *);
Modified: trunk/xim/convdisp.cpp
===================================================================
--- trunk/xim/convdisp.cpp 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/convdisp.cpp 2005-06-21 07:36:26 UTC (rev 901)
@@ -1410,15 +1410,16 @@
mConn->push_passive_packet(t);
}
mPrevLen = len;
- /*
- t = createTxPacket(XIM_PREEDIT_CARET,0);
- t->pushC16(mImid);
- t->pushC16(mIcid);
- t->pushC32(pos);
- t->pushC32(dir);
- t->pushC32(style);
- mConn->push_packet(t);
- */
+
+ if (len) {
+ t = createTxPacket(XIM_PREEDIT_CARET, 0);
+ t->pushC16(mImid);
+ t->pushC16(mIcid);
+ t->pushC32(caret_pos);
+ t->pushC32(XIMAbsolutePosition);
+ t->pushC32(XIMIsPrimary);
+ mConn->push_passive_packet(t);
+ }
}
void ConvdispOs::move_candwin()
Modified: trunk/xim/main.cpp
===================================================================
--- trunk/xim/main.cpp 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/main.cpp 2005-06-21 07:36:26 UTC (rev 901)
@@ -181,7 +181,7 @@
std::pair<unsigned int, WindowIf *> p(id, w);
window_watch_stat.insert(p);
- // Event mash has same value defined in X,
+ // Event mask is the same value defined in X,
// but do not depend on.
int emask = 0;
if (mask & EXPOSE_MASK)
Modified: trunk/xim/xim.h
===================================================================
--- trunk/xim/xim.h 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/xim.h 2005-06-21 07:36:26 UTC (rev 901)
@@ -108,7 +108,6 @@
void OnRecv();
void OnSend();
void OnClose();
- virtual void OnPushPacket() {}; // Called when packet is pushed into sending queue. But doesn't do anything for now.
void push_packet(TxPacket *); // for normal packet for reply
void push_passive_packet(TxPacket *); // for preceding packet for reply
int byte_order() {return mByteorder;};
@@ -125,12 +124,14 @@
virtual void setPreeditStartSyncFlag();
virtual void unsetPreeditStartSyncFlag();
virtual bool hasPreeditStartSyncFlag();
+ virtual void setPreeditCaretSyncFlag();
+ virtual void unsetPreeditCaretSyncFlag();
+ virtual bool hasPreeditCaretSyncFlag();
std::list<RxPacket *> mRxQ;
- std::list<RxPacket *> mPendingRxQ; // pending queue for XIM_FORWARD Rx event
std::list<TxPacket *> mTxQ;
std::list<TxPacket *> mPTxQ;
- std::list<TxPacket *> mPendingTxQ; // pending queue for mTxQ
+ std::list<TxPacket *> mPendingTxQ; // pending queue for mTxQ and mPTxQ
int mByteorder;
bool mIsCloseWait; // true when the last packet has handled
private:
@@ -153,17 +154,19 @@
void xim_forward_event(RxPacket *);
void xim_sync_reply();
- void xim_preedit_start_reply(RxPacket *);
+ void xim_preedit_start_reply();
+ void xim_preedit_caret_reply();
void xim_error(RxPacket *);
bool is_xim_sync_reply_timeout();
- void clear_pending_rx();
+ void clear_pending_queue();
private:
XimIC *get_ic(RxPacket *);
std::list<int> mCreatedIm;
XimServer *mServer;
bool mSyncFlag;
bool mPreeditStartSyncFlag;
+ bool mPreeditCaretSyncFlag;
struct timeval mSyncStartTime;
};
Modified: trunk/xim/ximtrans.cpp
===================================================================
--- trunk/xim/ximtrans.cpp 2005-06-21 05:40:53 UTC (rev 900)
+++ trunk/xim/ximtrans.cpp 2005-06-21 07:36:26 UTC (rev 901)
@@ -203,6 +203,7 @@
mServer = svr;
mSyncFlag = false;
mPreeditStartSyncFlag = false;
+ mPreeditCaretSyncFlag = false;
}
Connection::~Connection()
@@ -217,9 +218,6 @@
for (ir = mRxQ.begin(); ir != mRxQ.end(); ir++) {
delete *ir;
}
- for (ir = mPendingRxQ.begin(); ir != mPendingRxQ.end(); ir++) {
- delete *ir;
- }
std::list<TxPacket *>::iterator it;
for (it = mTxQ.begin(); it != mTxQ.end(); it++) {
delete *it;
@@ -303,10 +301,10 @@
xim_reset_ic(p);
break;
case XIM_PREEDIT_START_REPLY:
- xim_preedit_start_reply(p);
+ xim_preedit_start_reply();
break;
case XIM_PREEDIT_CARET_REPLY:
- // do nothing
+ xim_preedit_caret_reply();
break;
case XIM_ERROR:
xim_error(p);
@@ -439,6 +437,21 @@
return mPreeditStartSyncFlag;
}
+void Connection::setPreeditCaretSyncFlag()
+{
+ mPreeditCaretSyncFlag = true;
+}
+
+void Connection::unsetPreeditCaretSyncFlag()
+{
+ mPreeditCaretSyncFlag = false;
+}
+
+bool Connection::hasPreeditCaretSyncFlag()
+{
+ return mPreeditCaretSyncFlag;
+}
+
//
// Packet handlers
//
@@ -701,49 +714,16 @@
if (is_xim_sync_reply_timeout()) {
// XIM protocol error?
push_error_packet(imid, icid, ERR_BadProtocol, "Bad Protocol");
- clear_pending_rx();
+ clear_pending_queue();
unsetSyncFlag();
- im->forward_event(p);
- } else {
- // Copy this packet since it will soon be deleted, then
- // add to pending queue.
- RxPacket *packet = copyRxPacket(p);
- mPendingRxQ.push_back(packet);
}
}
- else
- im->forward_event(p);
+ im->forward_event(p);
}
void Connection::xim_sync_reply()
{
- if (hasSyncFlag()) {
- unsetSyncFlag();
-
- // send consecutive XIM_FORWARD event just after XIM_COMMIT
- std::list<TxPacket *>::iterator i;
- while (mPendingTxQ.size()) {
- i = mPendingTxQ.begin();
- mTxQ.push_back(*i);
- mPendingTxQ.pop_front();
- }
-
- // process pending Rx queue
- int imid, icid;
- XimIM *im;
- std::list<RxPacket *>::iterator j;
- while (mPendingRxQ.size()) {
- j = mPendingRxQ.begin();
- imid = (*j)->getC16();
- icid = (*j)->getC16();
- (*j)->rewind();
- im = get_im_by_id(imid);
- im->forward_event(*j);
- delete *j;
- mPendingRxQ.pop_front();
- break; // handle only one pending event is safe...
- }
- }
+ unsetSyncFlag();
}
void Connection::xim_reset_ic(RxPacket *p)
@@ -753,21 +733,16 @@
ic->reset_ic();
}
-void Connection::xim_preedit_start_reply(RxPacket *p)
+void Connection::xim_preedit_start_reply()
{
- std::list<TxPacket *>::iterator i;
-
unsetPreeditStartSyncFlag();
-#if 0
- // not used for now
- while (mPPendingTxQ.size()) {
- i = mPPendingTxQ.begin();
- mPTxQ.push_back(*i);
- mPPendingTxQ.pop_front();
- }
-#endif
}
+void Connection::xim_preedit_caret_reply()
+{
+ unsetPreeditCaretSyncFlag();
+}
+
void Connection::xim_error(RxPacket *p)
{
int imid, icid, mask, ecode, len;
@@ -822,11 +797,11 @@
return false;
}
-void Connection::clear_pending_rx() {
- std::list<RxPacket *>::iterator i;
- while (mPendingRxQ.size()) {
- i = mPendingRxQ.begin();
- mPendingRxQ.pop_front();
+void Connection::clear_pending_queue() {
+ std::list<TxPacket *>::iterator i;
+ while (mPendingTxQ.size()) {
+ i = mPendingTxQ.begin();
+ mPendingTxQ.pop_front();
delete *i;
}
}
More information about the uim-commit
mailing list