1 /* 2 * SPDX-FileCopyrightText: 2014 Weng Xuetian <wengxt@gmail.com> 3 * 4 * SPDX-License-Identifier: LGPL-2.1-only 5 * 6 */ 7 #ifndef COMMON_H 8 #define COMMON_H 9 10 #include "ximproto.h" 11 #include <stdbool.h> 12 #include <stdint.h> 13 #include <stdio.h> 14 #include <xcb/xcb.h> 15 #include <xcb/xproto.h> 16 17 // some atom name 18 #define XIM_SERVERS "XIM_SERVERS" 19 #define XIM_LOCALES "LOCALES" 20 #define XIM_TRANSPORT "TRANSPORT" 21 #define _XIM_PROTOCOL "_XIM_PROTOCOL" 22 #define _XIM_XCONNECT "_XIM_XCONNECT" 23 24 #define ARRAY_SIZE(X) (sizeof(X) / sizeof(X[0])) 25 26 #define XIM_MESSAGE_BYTES(hdr) ((hdr)->length * 4) 27 28 /* 29 * categories in XIM_SERVERS 30 */ 31 #define XIM_SERVER_CATEGORY "@server=" 32 #define XIM_LOCAL_CATEGORY "@locale=" 33 #define XIM_TRANSPORT_CATEGORY "@transport=" 34 35 #define DebugLog(S...) \ 36 do { \ 37 if (im->logger) { \ 38 im->logger(S); \ 39 } \ 40 } while (0) 41 42 /* 43 * values for the type of XIMATTR & XICATTR 44 */ 45 #define XimType_SeparatorOfNestedList 0 46 #define XimType_CARD8 1 47 #define XimType_CARD16 2 48 #define XimType_CARD32 3 49 #define XimType_STRING8 4 50 #define XimType_Window 5 51 #define XimType_XIMStyles 10 52 #define XimType_XRectangle 11 53 #define XimType_XPoint 12 54 #define XimType_XFontSet 13 55 #define XimType_XIMOptions 14 56 #define XimType_XIMHotKeyTriggers 15 57 #define XimType_XIMHotKeyState 16 58 #define XimType_XIMStringConversion 17 59 #define XimType_XIMValuesList 18 60 #define XimType_NEST 0x7FFF 61 62 enum { 63 XIM_ATOM_SERVER_NAME, 64 XIM_ATOM_XIM_SERVERS, 65 XIM_ATOM_LOCALES, 66 XIM_ATOM_TRANSPORT, 67 XIM_ATOM_XIM_PROTOCOL, 68 XIM_ATOM_XIM_CONNECT, 69 XIM_ATOM_LAST 70 }; 71 72 static const xcb_im_ext_list Default_Extension[] = { 73 // client -> server, by set ic in xlib 74 {"XIM_EXT_MOVE", XCB_XIM_EXTENSION, XCB_XIM_EXT_MOVE}, 75 #if 0 76 // not in any imdkit 77 // server -> client 78 {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK}, 79 // server <-> client 80 // not enabled by xlib 81 {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT}, 82 #endif 83 }; 84 85 typedef void (*xcb_xim_callback)(); 86 87 bool _xcb_im_init_atoms(xcb_connection_t *conn, size_t n, 88 const char **atom_names, xcb_atom_t *atoms); 89 90 uint32_t _xcb_get_event_mask(xcb_connection_t *conn, xcb_window_t window); 91 bool _xcb_change_event_mask(xcb_connection_t *conn, xcb_window_t window, 92 uint32_t mask, bool remove); 93 94 size_t _xcb_im_ic_attr_size(uint32_t type); 95 96 uint8_t *_xcb_im_get_ic_value(void *p, uint32_t type, uint8_t *data, bool swap); 97 98 #endif // COMMON_H 99