1 /* 2 * Copyright (C) 2020 The HIME team, Taiwan 3 * Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation version 2.1 8 * of the License. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 #ifndef HIME_IM_CLIENT_H 21 #define HIME_IM_CLIENT_H 22 23 #include <stdint.h> 24 #include <stdlib.h> 25 26 #include "hime-im-client-attr.h" 27 28 #ifndef _XSERVER64 29 #define _XSERVER64 30 #endif 31 32 struct HIME_PASSWD; 33 34 typedef struct HIME_client_handle_S { 35 int fd; 36 Window client_win; /* client window */ 37 uint32_t input_style; /* input style */ 38 XPoint spot_location; /* spot location */ 39 40 // below are private data, don't modify them. 41 uint32_t flag; 42 Display *display; /* X Display, not a GdkDisplay */ 43 struct HIME_PASSWD *passwd; 44 uint32_t seq; 45 } HIME_client_handle; 46 47 enum { 48 FLAG_HIME_client_handle_has_focus = 1, 49 FLAG_HIME_client_handle_use_preedit = 2, 50 FLAG_HIME_client_handle_raise_window = 0x1000 // for mozilla, dirty fix 51 }; 52 53 enum { 54 FLAG_HIME_srv_ret_status_use_pop_up = 1 // If this is used, we don't need the dirty fix 55 }; 56 57 #ifdef __cplusplus 58 extern "C" { 59 #endif 60 61 // APIs for Gtk+/Qt IM modules 62 HIME_client_handle *hime_im_client_open (Display *display); 63 void hime_im_client_close (HIME_client_handle *handle); 64 65 // set the client window 66 void hime_im_client_set_client_window (HIME_client_handle *handle, 67 const Window win); 68 69 // retrieve the current preedit string 70 // str: retrieved string, must be freed by caller 71 // attr: retrieved attribute list 72 // cursor: cursor location of the preedit string 73 // return: # of attr 74 int hime_im_client_get_preedit (HIME_client_handle *handle, 75 char **str, 76 HIME_PREEDIT_ATTR att[], 77 int *cursor, 78 int *sub_comp_len); 79 80 /* rstr returns UTF-8 encoded string, you should use 'free()' to free the 81 memory. 82 83 return boolean: 84 FALSE : the key is rejected, should use client's own result(ASCII key). 85 TRUE : the key is accepted, translated result is in rstr. 86 */ 87 int hime_im_client_forward_key_press (HIME_client_handle *handle, 88 const KeySym key, 89 const uint32_t state, 90 char **rstr); 91 int hime_im_client_forward_key_release (HIME_client_handle *handle, 92 const KeySym key, 93 const uint32_t state, 94 char **rstr); 95 96 void hime_im_client_focus_in (HIME_client_handle *handle); 97 void hime_im_client_focus_out (HIME_client_handle *handle); 98 void hime_im_client_focus_out2 (HIME_client_handle *handle, char **rstr); 99 void hime_im_client_reset (HIME_client_handle *handle); 100 101 // set client window cursor location 102 void hime_im_client_set_cursor_location (HIME_client_handle *handle, 103 const int x, 104 const int y); 105 106 void hime_im_client_set_flags (HIME_client_handle *handle, 107 const int flags, 108 int *ret_flags); 109 void hime_im_client_clear_flags (HIME_client_handle *handle, 110 const int flags, 111 int *ret_flags); 112 113 // other APIs 114 115 // write message to hime server 116 void hime_im_client_send_message (HIME_client_handle *handle, 117 const char *message); 118 119 // return the X Window of the display 120 Window find_hime_window (Display *display); 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* HIME_IM_CLIENT_H */ 127