master
ブランチ master
ShaderPlayground / deps / xlibre / include / xcb-imdkit / imdkit.h
12.1 KB、360行 生 Blame 履歴
1/*
2 * SPDX-FileCopyrightText: 2014 Weng Xuetian <wengxt@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7#ifndef _XCB_IMDKIT_IMDKIT_H_
8#define _XCB_IMDKIT_IMDKIT_H_
9
10#include "xcbimdkit_export.h"
11#include "ximcommon.h"
12#include "ximproto.h"
13#include <stdbool.h>
14#include <stdint.h>
15#include <xcb/xcb.h>
16#include <xcb/xproto.h>
17
18XCBIMDKIT_DECL_BEGIN
19
20/*
21 * `C' and `no' are additional one which cannot be obtained from modern
22 * locale.gen. `no' is obsolete, but we keep it here for compatible reason.
23 */
24#define XCB_IM_ALL_LOCALES \
25 "aa,af,am,an,ar,as,ast,az,be,bem,ber,bg,bho,bn,bo,br,brx,bs,byn," \
26 "C,ca,crh,cs,csb,cv,cy,da,de,dv,dz,el,en,es,et,eu,fa,ff,fi,fil,fo," \
27 "fr,fur,fy,ga,gd,gez,gl,gu,gv,ha,he,hi,hne,hr,hsb,ht,hu,hy,id,ig," \
28 "ik,is,it,iu,iw,ja,ka,kk,kl,km,kn,ko,kok,ks,ku,kw,ky,lb,lg,li,lij," \
29 "lo,lt,lv,mag,mai,mg,mhr,mi,mk,ml,mn,mr,ms,mt,my,nan,nb,nds,ne,nl," \
30 "nn,no,nr,nso,oc,om,or,os,pa,pap,pl,ps,pt,ro,ru,rw,sa,sc,sd,se,shs," \
31 "si,sid,sk,sl,so,sq,sr,ss,st,sv,sw,ta,te,tg,th,ti,tig,tk,tl,tn,tr," \
32 "ts,tt,ug,uk,unm,ur,uz,ve,vi,wa,wae,wal,wo,xh,yi,yo,yue,zh,zu"
33
34typedef struct _xcb_im_styles_t {
35 uint32_t nStyles;
36 uint32_t *styles;
37} xcb_im_styles_t;
38
39typedef char *xcb_im_encoding_t;
40
41typedef struct _xcb_im_encodings_t {
42 unsigned short nEncodings;
43 xcb_im_encoding_t *encodings;
44} xcb_im_encodings_t;
45
46typedef struct _xcb_im_t xcb_im_t;
47typedef struct _xcb_im_input_context_t xcb_im_input_context_t;
48typedef struct _xcb_im_client_t xcb_im_client_t;
49
50// Mask to check if the attribute is set.
51typedef enum _xcb_im_attr_mask_t {
52 XCB_XIM_XNArea_MASK = (1 << 0),
53 XCB_XIM_XNAreaNeeded_MASK = (1 << 1),
54 XCB_XIM_XNSpotLocation_MASK = (1 << 2),
55 XCB_XIM_XNColormap_MASK = (1 << 3),
56 XCB_XIM_XNForeground_MASK = (1 << 4),
57 XCB_XIM_XNBackground_MASK = (1 << 5),
58 XCB_XIM_XNBackgroundPixmap_MASK = (1 << 7),
59 XCB_XIM_XNLineSpace_MASK = (1 << 8),
60} xcb_im_attr_mask_t;
61
62typedef struct _xcb_im_preedit_attr_t {
63 xcb_rectangle_t area;
64 xcb_rectangle_t area_needed;
65 xcb_point_t spot_location;
66 xcb_colormap_t colormap;
67 uint32_t foreground;
68 uint32_t background;
69 xcb_window_t bg_pixmap;
70 uint32_t line_space;
71} xcb_im_preedit_attr_t;
72
73typedef struct _xcb_im_status_attr_t {
74 xcb_rectangle_t area;
75 xcb_rectangle_t area_needed;
76 xcb_point_t spot_location;
77 xcb_colormap_t colormap;
78 uint32_t foreground;
79 uint32_t background;
80 xcb_window_t bg_pixmap;
81 uint32_t line_space;
82} xcb_im_status_attr_t;
83
84typedef void (*xcb_im_callback)(xcb_im_t *im, xcb_im_client_t *client,
85 xcb_im_input_context_t *ic,
86 const xcb_im_packet_header_fr_t *hdr,
87 void *frame, void *arg, void *user_data);
88
89typedef void (*xcb_im_free_function)(void *memory);
90
91/**
92 * Create a XIM server.
93 *
94 * @param conn xcb connection to be used.
95 * @param screen xcb screen to be used.
96 * @param serverWindow A server window.
97 * @param serverName server name, need to be consistent with XMODIFIERS
98 * @param locale locale supported. You may want to use XCB_IM_ALL_LOCALES.
99 * @param inputStyles XIM Styles supported by XIM server.
100 * @param onKeysList Trigger on key to send to client.
101 * @param offKeysList Trigger off key to send to cilent.
102 * @param encodingList XIM encoding list.
103 * @param event_mask if 0, XCB_EVENT_MASK_KEY_PRESS will be used.
104 * @param callback Callback function
105 * @param user_data user data to callback function.
106 * @return xcb_im_t*
107 */
108XCBIMDKIT_EXPORT xcb_im_t *
109xcb_im_create(xcb_connection_t *conn, int screen, xcb_window_t serverWindow,
110 const char *serverName, const char *locale,
111 const xcb_im_styles_t *inputStyles,
112 const xcb_im_trigger_keys_t *onKeysList,
113 const xcb_im_trigger_keys_t *offKeysList,
114 const xcb_im_encodings_t *encodingList, uint32_t event_mask,
115 xcb_im_callback callback, void *user_data);
116
117/**
118 * @brief Set a logger handler.
119 *
120 * @param im XIM server.
121 * @param logger logger function.
122 */
123XCBIMDKIT_EXPORT void xcb_im_set_log_handler(xcb_im_t *im,
124 void (*logger)(const char *, ...));
125
126/**
127 * Whether to use sync mode, it will affect certain behavior of XIM.
128 *
129 * Forward event and commit string behavior will be changed. If sync mode is
130 * true, every request need to be replied with sync_reply. The library is still
131 * working under async mode, just no more request will be send to client.
132 *
133 * @param im XIM server
134 * @param sync sync mode or not.
135 */
136XCBIMDKIT_EXPORT void xcb_im_set_use_sync_mode(xcb_im_t *im, bool sync);
137
138/**
139 * Set whether the event defined by event mask is handled in a synchronous way.
140 *
141 * @param im XIM server
142 * @param sync sync on event or not.
143 */
144XCBIMDKIT_EXPORT void xcb_im_set_use_sync_event(xcb_im_t *im, bool sync);
145
146/**
147 * Start a XIM server synchronously.
148 *
149 * It only does the minimum initialization and try to grab the server name. When
150 * it fails, it means there might be another server with the same name running.
151 *
152 * To finish the initialization, you will need to use xcb_im_filter_event on all
153 * the event recevied.
154 *
155 * You may also call this function again if it fails or after xcb_im_close_im.
156 *
157 * @param im XIM server.
158 * @return whether XIM server is started successfully.
159 */
160XCBIMDKIT_EXPORT bool xcb_im_open_im(xcb_im_t *im);
161
162/**
163 * Handle XIM related event, most relevant event will be client message.
164 *
165 * @param im XIM server
166 * @param event X event.
167 * @return Whether the event is handled by XIM.
168 */
169XCBIMDKIT_EXPORT bool xcb_im_filter_event(xcb_im_t *im,
170 xcb_generic_event_t *event);
171
172/**
173 * Shutdown the XIM server and free all the resources.
174 *
175 * @param im XIM server
176 *
177 * @see xcb_im_open_im
178 */
179XCBIMDKIT_EXPORT void xcb_im_close_im(xcb_im_t *im);
180/**
181 * Destroy the XIM server.
182 *
183 * xcb_im_close_im need to be called if it is opened successfully.
184 *
185 * @param im XIM server.
186 */
187XCBIMDKIT_EXPORT void xcb_im_destroy(xcb_im_t *im);
188
189/**
190 * Send a key event to the client.
191 *
192 * @param im XIM server
193 * @param ic Input context.
194 * @param event key event.
195 */
196XCBIMDKIT_EXPORT void xcb_im_forward_event(xcb_im_t *im,
197 xcb_im_input_context_t *ic,
198 xcb_key_press_event_t *event);
199
200/**
201 * Send a key event to the client.
202 *
203 * @param im XIM server
204 * @param ic Input context.
205 * @param sequence sequence number, when re-inject, should be the value from
206 * forward_event
207 * @param event key event.
208 * @see xcb_im_forward_event_fr_t.
209 */
210XCBIMDKIT_EXPORT void xcb_im_forward_event_full(xcb_im_t *im,
211 xcb_im_input_context_t *ic,
212 uint16_t sequence,
213 xcb_key_press_event_t *event);
214
215/**
216 * Commit a string to the client.
217 *
218 * @param im XIM server
219 * @param ic Input Context
220 * @param flag a bit flag of xcb_xim_lookup_flags_t, XCB_XIM_LOOKUP_CHARS is the
221 * most common value to be used.
222 * @param str string to be committed, encoding is usually COMPOUND_TEXT.
223 * @param length byte length of the string
224 * @param keysym key symbol.
225 *
226 * @see xcb_xim_lookup_flags_t
227 * @see xcb_utf8_to_compound_text
228 */
229XCBIMDKIT_EXPORT void xcb_im_commit_string(xcb_im_t *im,
230 xcb_im_input_context_t *ic,
231 uint32_t flag, const char *str,
232 uint32_t length, uint32_t keysym);
233
234/**
235 * Start geometry negotiation, if XIMStyle has XIMPreeditArea or XIMStatusArea
236 * set.
237 *
238 * This is rarely used nowadays. Xlib doesn't have relevant code for it.
239 *
240 * @param im XIM server
241 * @param ic Input context
242 */
243XCBIMDKIT_EXPORT void xcb_im_geometry_callback(xcb_im_t *im,
244 xcb_im_input_context_t *ic);
245
246/**
247 * Sends XIM_PREEDIT_START message to call the XIMPreeditStartCallback function.
248 *
249 * @param im XIM server
250 * @param ic Input context
251 */
252XCBIMDKIT_EXPORT void xcb_im_preedit_start_callback(xcb_im_t *im,
253 xcb_im_input_context_t *ic);
254
255/**
256 * Sends XIM_PREEDIT_DRAW message to call the XIMPreeditDrawCallback function.
257 *
258 * @param im XIM server
259 * @param ic Input context
260 * @param frame information about preedit string.
261 */
262XCBIMDKIT_EXPORT void
263xcb_im_preedit_draw_callback(xcb_im_t *im, xcb_im_input_context_t *ic,
264 xcb_im_preedit_draw_fr_t *frame);
265
266/**
267 * Sends XIM_PREEDIT_CARET message to call the PreeditCaretCallback function.
268 *
269 * @param im XIM server
270 * @param ic Input context
271 * @param frame information about preedit caret.
272 */
273XCBIMDKIT_EXPORT void
274xcb_im_preedit_caret_callback(xcb_im_t *im, xcb_im_input_context_t *ic,
275 xcb_im_preedit_caret_fr_t *frame);
276
277/**
278 * sends XIM_PREEDIT_DONE message to call the XIMPreeditDoneCallback function.
279 *
280 * This should only be called after calling xcb_im_preedit_start_callback.
281 *
282 * @param im XIM server
283 * @param ic Input context
284 */
285XCBIMDKIT_EXPORT void xcb_im_preedit_done_callback(xcb_im_t *im,
286 xcb_im_input_context_t *ic);
287
288/**
289 * Sends XIM_STATUS_START message to call the XIMStatusStartCallback function.
290 *
291 * @param im XIM server
292 * @param ic Input context
293 */
294XCBIMDKIT_EXPORT void xcb_im_status_start_callback(xcb_im_t *im,
295 xcb_im_input_context_t *ic);
296
297/**
298 * Sends XIM_STATUS_DRAW message to call the XIMStatusDrawCallback function with
299 * text.
300 *
301 * @param im XIM server
302 * @param ic Input context
303 * @param frame text to be drawn by client.
304 */
305XCBIMDKIT_EXPORT void
306xcb_im_status_draw_text_callback(xcb_im_t *im, xcb_im_input_context_t *ic,
307 xcb_im_status_draw_text_fr_t *frame);
308
309/**
310 * Sends XIM_STATUS_DRAW message to call the XIMStatusDrawCallback function with
311 * bitmap.
312 *
313 * @param im XIM server
314 * @param ic Input context
315 * @param frame bitmap to be drawn by client.
316 */
317XCBIMDKIT_EXPORT void
318xcb_im_status_draw_bitmap_callback(xcb_im_t *im, xcb_im_input_context_t *ic,
319 xcb_im_status_draw_bitmap_fr_t *frame);
320
321/**
322 * Sends XIM_STATUS_DONE message to call the XIMStatusDoneCallback function.
323 *
324 * @param im XIM server
325 * @param ic Input context
326 */
327XCBIMDKIT_EXPORT void xcb_im_status_done_callback(xcb_im_t *im,
328 xcb_im_input_context_t *ic);
329XCBIMDKIT_EXPORT void xcb_im_preedit_start(xcb_im_t *im,
330 xcb_im_input_context_t *ic);
331XCBIMDKIT_EXPORT void xcb_im_preedit_end(xcb_im_t *im,
332 xcb_im_input_context_t *ic);
333XCBIMDKIT_EXPORT void xcb_im_sync_xlib(xcb_im_t *im,
334 xcb_im_input_context_t *ic);
335XCBIMDKIT_EXPORT bool xcb_im_support_extension(xcb_im_t *im,
336 uint16_t major_code,
337 uint16_t minor_code);
338XCBIMDKIT_EXPORT void
339xcb_im_input_context_set_data(xcb_im_input_context_t *ic, void *data,
340 xcb_im_free_function free_data_function);
341XCBIMDKIT_EXPORT void *
342xcb_im_input_context_get_data(xcb_im_input_context_t *ic);
343XCBIMDKIT_EXPORT uint32_t
344xcb_im_input_context_get_input_style(xcb_im_input_context_t *ic);
345XCBIMDKIT_EXPORT xcb_window_t
346xcb_im_input_context_get_client_window(xcb_im_input_context_t *ic);
347XCBIMDKIT_EXPORT xcb_window_t
348xcb_im_input_context_get_focus_window(xcb_im_input_context_t *ic);
349XCBIMDKIT_EXPORT const xcb_im_preedit_attr_t *
350xcb_im_input_context_get_preedit_attr(xcb_im_input_context_t *ic);
351XCBIMDKIT_EXPORT const xcb_im_status_attr_t *
352xcb_im_input_context_get_status_attr(xcb_im_input_context_t *ic);
353XCBIMDKIT_EXPORT uint32_t
354xcb_im_input_context_get_preedit_attr_mask(xcb_im_input_context_t *ic);
355XCBIMDKIT_EXPORT uint32_t
356xcb_im_input_context_get_status_attr_mask(xcb_im_input_context_t *ic);
357
358XCBIMDKIT_DECL_END
359
360#endif // _XCB_IMDKIT_IMDKIT_H_