做输入法的困难

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_32768743/article/details/89716951

没有足够的键,使用Shift键加倍
输入法管理器跑在单独的进程与X Server通信,与应用通信。当应用启动时,locale设置或者im设置决定应用与哪个输入法管理器建立连接。
在这里插入图片描述
这个图很不清晰
XIM协议定义3个区域

  • Status
  • Preedit
  • Auxiliary

XIM协议定义4种交互

  • root-window
  • off-the-spot
  • over-the-spot
  • on-the-spot 需要处理回调
XOpenIM()       // 拿到XIM
XOpenDisplay()  // 拿到Display*
XCreateIC()     // 拿到XIC,还有决定XFontSet
XSetICFouces()  // 拿到焦点

在这里插入图片描述

1. When the user strikes a key on the keyboard, the keyboard sends a hardware−specific keycode to the X server.
2. The X server sends an event to the client or clients that have expressed interest in keystroke events for the window that
had focus when the keystroke occurred.
3. The keystroke event will be received in the client’s event loop by a call to XNextEvent().
4. The event is immediately passed to XFilterEvent() to give the input method the opportunity to use it. Generally,
the input method will not filter a KeyPress event.
5. Back in the application, if XFilterEvent() returns True, then the application will discard the event and wait for
the next one.
6. Otherwise, the application will go ahead and process the event. For every KeyPress event, the application will call
XmbLookupString() or XwcLookupString().
7. The input method now processes the keystroke: it adds a new character to its pre−edit text and updates the display in
the Preedit and Status areas of the application. If the keystroke is a control character such as Delete, the input method
may modify the pre−edit text.
8. If the keystroke indicates that the user is done pre−editing and wishes to compose the pre−edited text, the input method
does any necessary translation and the result becomes the return value of Xmb/XwcLookupString(). In most
applications, this returned string will be immediately echoed in the window with a call to one of the internationalized
text drawing functions. If the keystroke merely adds to the pre−edit text, then the status value returned by
Xmb/wcLookupString() indicates that there is no composed text ready.
  • 用户敲键盘,发送一个码到X server
  • X server发送事件
  • XNextEvent()处理事件
  • XFilterEvent()输入法使用事件
  • 调用XmbLookupString()或者XwcLookupString()
  • 输入法处理键击
  • 如果用户选定一个词,这个词将作为Xmb/XwcLookupString()的返回值

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/89716951