Register input panel surface in wayland
[platform/core/uifw/libscl-core.git] / src / input-method-client-protocol.h
1 /*
2  * Copyright © 2012, 2013 Intel Corporation
3  *
4  * Permission to use, copy, modify, distribute, and sell this
5  * software and its documentation for any purpose is hereby granted
6  * without fee, provided that the above copyright notice appear in
7  * all copies and that both that copyright notice and this permission
8  * notice appear in supporting documentation, and that the name of
9  * the copyright holders not be used in advertising or publicity
10  * pertaining to distribution of the software without specific,
11  * written prior permission.  The copyright holders make no
12  * representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied
14  * warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
23  * THIS SOFTWARE.
24  */
25
26 #ifndef INPUT_METHOD_CLIENT_PROTOCOL_H
27 #define INPUT_METHOD_CLIENT_PROTOCOL_H
28
29 #ifdef  __cplusplus
30 extern "C" {
31 #endif
32
33 #include <stdint.h>
34 #include <stddef.h>
35 #include "wayland-client.h"
36
37 struct wl_client;
38 struct wl_resource;
39
40 struct wl_input_method_context;
41 struct wl_input_method;
42 struct wl_input_panel;
43 struct wl_input_panel_surface;
44
45 extern const struct wl_interface wl_input_method_context_interface;
46 extern const struct wl_interface wl_input_method_interface;
47 extern const struct wl_interface wl_input_panel_interface;
48 extern const struct wl_interface wl_input_panel_surface_interface;
49
50 /**
51  * wl_input_method_context - input method context
52  * @surrounding_text: surrounding text event
53  * @reset: (none)
54  * @content_type: (none)
55  * @invoke_action: (none)
56  * @commit_state: (none)
57  * @preferred_language: (none)
58  *
59  * Corresponds to a text model on input method side. An input method
60  * context is created on text mode activation on the input method side. It
61  * allows to receive information about the text model from the application
62  * via events. Input method contexts do not keep state after deactivation
63  * and should be destroyed after deactivation is handled.
64  *
65  * Text is generally UTF-8 encoded, indices and lengths are in bytes.
66  *
67  * Serials are used to synchronize the state between the text input and an
68  * input method. New serials are sent by the text input in the commit_state
69  * request and are used by the input method to indicate the known text
70  * input state in events like preedit_string, commit_string, and keysym.
71  * The text input can then ignore events from the input method which are
72  * based on an outdated state (for example after a reset).
73  */
74 struct wl_input_method_context_listener {
75     /**
76      * surrounding_text - surrounding text event
77      * @text: (none)
78      * @cursor: (none)
79      * @anchor: (none)
80      *
81      * The plain surrounding text around the input position. Cursor
82      * is the position in bytes within the surrounding text relative to
83      * the beginning of the text. Anchor is the position in bytes of
84      * the selection anchor within the surrounding text relative to the
85      * beginning of the text. If there is no selected text anchor is
86      * the same as cursor.
87      */
88     void (*surrounding_text)(void *data,
89                  struct wl_input_method_context *wl_input_method_context,
90                  const char *text,
91                  uint32_t cursor,
92                  uint32_t anchor);
93     /**
94      * reset - (none)
95      */
96     void (*reset)(void *data,
97               struct wl_input_method_context *wl_input_method_context);
98     /**
99      * content_type - (none)
100      * @hint: (none)
101      * @purpose: (none)
102      */
103     void (*content_type)(void *data,
104                  struct wl_input_method_context *wl_input_method_context,
105                  uint32_t hint,
106                  uint32_t purpose);
107     /**
108      * invoke_action - (none)
109      * @button: (none)
110      * @index: (none)
111      */
112     void (*invoke_action)(void *data,
113                   struct wl_input_method_context *wl_input_method_context,
114                   uint32_t button,
115                   uint32_t index);
116     /**
117      * commit_state - (none)
118      * @serial: serial of text input state
119      */
120     void (*commit_state)(void *data,
121                  struct wl_input_method_context *wl_input_method_context,
122                  uint32_t serial);
123     /**
124      * preferred_language - (none)
125      * @language: (none)
126      */
127     void (*preferred_language)(void *data,
128                    struct wl_input_method_context *wl_input_method_context,
129                    const char *language);
130 };
131
132 static inline int
133 wl_input_method_context_add_listener(struct wl_input_method_context *wl_input_method_context,
134                      const struct wl_input_method_context_listener *listener, void *data)
135 {
136     return wl_proxy_add_listener((struct wl_proxy *) wl_input_method_context,
137                      (void (**)(void)) listener, data);
138 }
139
140 #define WL_INPUT_METHOD_CONTEXT_DESTROY 0
141 #define WL_INPUT_METHOD_CONTEXT_COMMIT_STRING   1
142 #define WL_INPUT_METHOD_CONTEXT_PREEDIT_STRING  2
143 #define WL_INPUT_METHOD_CONTEXT_PREEDIT_STYLING 3
144 #define WL_INPUT_METHOD_CONTEXT_PREEDIT_CURSOR  4
145 #define WL_INPUT_METHOD_CONTEXT_DELETE_SURROUNDING_TEXT 5
146 #define WL_INPUT_METHOD_CONTEXT_CURSOR_POSITION 6
147 #define WL_INPUT_METHOD_CONTEXT_MODIFIERS_MAP   7
148 #define WL_INPUT_METHOD_CONTEXT_KEYSYM  8
149 #define WL_INPUT_METHOD_CONTEXT_GRAB_KEYBOARD   9
150 #define WL_INPUT_METHOD_CONTEXT_KEY 10
151 #define WL_INPUT_METHOD_CONTEXT_MODIFIERS   11
152 #define WL_INPUT_METHOD_CONTEXT_LANGUAGE    12
153 #define WL_INPUT_METHOD_CONTEXT_TEXT_DIRECTION  13
154
155 static inline void
156 wl_input_method_context_set_user_data(struct wl_input_method_context *wl_input_method_context, void *user_data)
157 {
158     wl_proxy_set_user_data((struct wl_proxy *) wl_input_method_context, user_data);
159 }
160
161 static inline void *
162 wl_input_method_context_get_user_data(struct wl_input_method_context *wl_input_method_context)
163 {
164     return wl_proxy_get_user_data((struct wl_proxy *) wl_input_method_context);
165 }
166
167 static inline void
168 wl_input_method_context_destroy(struct wl_input_method_context *wl_input_method_context)
169 {
170     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
171              WL_INPUT_METHOD_CONTEXT_DESTROY);
172
173     wl_proxy_destroy((struct wl_proxy *) wl_input_method_context);
174 }
175
176 static inline void
177 wl_input_method_context_commit_string(struct wl_input_method_context *wl_input_method_context, uint32_t serial, const char *text)
178 {
179     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
180              WL_INPUT_METHOD_CONTEXT_COMMIT_STRING, serial, text);
181 }
182
183 static inline void
184 wl_input_method_context_preedit_string(struct wl_input_method_context *wl_input_method_context, uint32_t serial, const char *text, const char *commit)
185 {
186     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
187              WL_INPUT_METHOD_CONTEXT_PREEDIT_STRING, serial, text, commit);
188 }
189
190 static inline void
191 wl_input_method_context_preedit_styling(struct wl_input_method_context *wl_input_method_context, uint32_t index, uint32_t length, uint32_t style)
192 {
193     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
194              WL_INPUT_METHOD_CONTEXT_PREEDIT_STYLING, index, length, style);
195 }
196
197 static inline void
198 wl_input_method_context_preedit_cursor(struct wl_input_method_context *wl_input_method_context, int32_t index)
199 {
200     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
201              WL_INPUT_METHOD_CONTEXT_PREEDIT_CURSOR, index);
202 }
203
204 static inline void
205 wl_input_method_context_delete_surrounding_text(struct wl_input_method_context *wl_input_method_context, int32_t index, uint32_t length)
206 {
207     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
208              WL_INPUT_METHOD_CONTEXT_DELETE_SURROUNDING_TEXT, index, length);
209 }
210
211 static inline void
212 wl_input_method_context_cursor_position(struct wl_input_method_context *wl_input_method_context, int32_t index, int32_t anchor)
213 {
214     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
215              WL_INPUT_METHOD_CONTEXT_CURSOR_POSITION, index, anchor);
216 }
217
218 static inline void
219 wl_input_method_context_modifiers_map(struct wl_input_method_context *wl_input_method_context, struct wl_array *map)
220 {
221     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
222              WL_INPUT_METHOD_CONTEXT_MODIFIERS_MAP, map);
223 }
224
225 static inline void
226 wl_input_method_context_keysym(struct wl_input_method_context *wl_input_method_context, uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers)
227 {
228     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
229              WL_INPUT_METHOD_CONTEXT_KEYSYM, serial, time, sym, state, modifiers);
230 }
231
232 static inline struct wl_keyboard *
233 wl_input_method_context_grab_keyboard(struct wl_input_method_context *wl_input_method_context)
234 {
235     struct wl_proxy *keyboard;
236
237     keyboard = wl_proxy_create((struct wl_proxy *) wl_input_method_context,
238                  &wl_keyboard_interface);
239     if (!keyboard)
240         return NULL;
241
242     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
243              WL_INPUT_METHOD_CONTEXT_GRAB_KEYBOARD, keyboard);
244
245     return (struct wl_keyboard *) keyboard;
246 }
247
248 static inline void
249 wl_input_method_context_key(struct wl_input_method_context *wl_input_method_context, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
250 {
251     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
252              WL_INPUT_METHOD_CONTEXT_KEY, serial, time, key, state);
253 }
254
255 static inline void
256 wl_input_method_context_modifiers(struct wl_input_method_context *wl_input_method_context, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
257 {
258     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
259              WL_INPUT_METHOD_CONTEXT_MODIFIERS, serial, mods_depressed, mods_latched, mods_locked, group);
260 }
261
262 static inline void
263 wl_input_method_context_language(struct wl_input_method_context *wl_input_method_context, uint32_t serial, const char *language)
264 {
265     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
266              WL_INPUT_METHOD_CONTEXT_LANGUAGE, serial, language);
267 }
268
269 static inline void
270 wl_input_method_context_text_direction(struct wl_input_method_context *wl_input_method_context, uint32_t serial, uint32_t direction)
271 {
272     wl_proxy_marshal((struct wl_proxy *) wl_input_method_context,
273              WL_INPUT_METHOD_CONTEXT_TEXT_DIRECTION, serial, direction);
274 }
275
276 /**
277  * wl_input_method - input method
278  * @activate: activate event
279  * @deactivate: activate event
280  *
281  * An input method object is responsible to compose text in response to
282  * input from hardware or virtual keyboards. There is one input method
283  * object per seat. On activate there is a new input method context object
284  * created which allows the input method to communicate with the text
285  * model.
286  */
287 struct wl_input_method_listener {
288     /**
289      * activate - activate event
290      * @id: (none)
291      *
292      * A text model was activated. Creates an input method context
293      * object which allows communication with the text model.
294      */
295     void (*activate)(void *data,
296              struct wl_input_method *wl_input_method,
297              struct wl_input_method_context *id);
298     /**
299      * deactivate - activate event
300      * @context: (none)
301      *
302      * The text model corresponding to the context argument was
303      * deactivated. The input method context should be destroyed after
304      * deactivation is handled.
305      */
306     void (*deactivate)(void *data,
307                struct wl_input_method *wl_input_method,
308                struct wl_input_method_context *context);
309 };
310
311 static inline int
312 wl_input_method_add_listener(struct wl_input_method *wl_input_method,
313                  const struct wl_input_method_listener *listener, void *data)
314 {
315     return wl_proxy_add_listener((struct wl_proxy *) wl_input_method,
316                      (void (**)(void)) listener, data);
317 }
318
319 static inline void
320 wl_input_method_set_user_data(struct wl_input_method *wl_input_method, void *user_data)
321 {
322     wl_proxy_set_user_data((struct wl_proxy *) wl_input_method, user_data);
323 }
324
325 static inline void *
326 wl_input_method_get_user_data(struct wl_input_method *wl_input_method)
327 {
328     return wl_proxy_get_user_data((struct wl_proxy *) wl_input_method);
329 }
330
331 static inline void
332 wl_input_method_destroy(struct wl_input_method *wl_input_method)
333 {
334     wl_proxy_destroy((struct wl_proxy *) wl_input_method);
335 }
336
337 #define WL_INPUT_PANEL_GET_INPUT_PANEL_SURFACE  0
338
339 static inline void
340 wl_input_panel_set_user_data(struct wl_input_panel *wl_input_panel, void *user_data)
341 {
342     wl_proxy_set_user_data((struct wl_proxy *) wl_input_panel, user_data);
343 }
344
345 static inline void *
346 wl_input_panel_get_user_data(struct wl_input_panel *wl_input_panel)
347 {
348     return wl_proxy_get_user_data((struct wl_proxy *) wl_input_panel);
349 }
350
351 static inline void
352 wl_input_panel_destroy(struct wl_input_panel *wl_input_panel)
353 {
354     wl_proxy_destroy((struct wl_proxy *) wl_input_panel);
355 }
356
357 static inline struct wl_input_panel_surface *
358 wl_input_panel_get_input_panel_surface(struct wl_input_panel *wl_input_panel, struct wl_surface *surface)
359 {
360     struct wl_proxy *id;
361
362     id = wl_proxy_create((struct wl_proxy *) wl_input_panel,
363                  &wl_input_panel_surface_interface);
364     if (!id)
365         return NULL;
366
367     wl_proxy_marshal((struct wl_proxy *) wl_input_panel,
368              WL_INPUT_PANEL_GET_INPUT_PANEL_SURFACE, id, surface);
369
370     return (struct wl_input_panel_surface *) id;
371 }
372
373 #ifndef WL_INPUT_PANEL_SURFACE_POSITION_ENUM
374 #define WL_INPUT_PANEL_SURFACE_POSITION_ENUM
375 enum wl_input_panel_surface_position {
376     WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM = 0,
377 };
378 #endif /* WL_INPUT_PANEL_SURFACE_POSITION_ENUM */
379
380 struct wl_input_panel_surface_listener {
381     /**
382      * cursor_rectangle - cursor rectangle
383      * @x: (none)
384      * @y: (none)
385      * @width: (none)
386      * @height: (none)
387      *
388      * Notify when the cursor rectangle relative to the input panel
389      * surface change.
390      */
391     void (*cursor_rectangle)(void *data,
392                  struct wl_input_panel_surface *wl_input_panel_surface,
393                  int32_t x,
394                  int32_t y,
395                  int32_t width,
396                  int32_t height);
397 };
398
399 static inline int
400 wl_input_panel_surface_add_listener(struct wl_input_panel_surface *wl_input_panel_surface,
401                     const struct wl_input_panel_surface_listener *listener, void *data)
402 {
403     return wl_proxy_add_listener((struct wl_proxy *) wl_input_panel_surface,
404                      (void (**)(void)) listener, data);
405 }
406
407 #define WL_INPUT_PANEL_SURFACE_SET_TOPLEVEL 0
408 #define WL_INPUT_PANEL_SURFACE_SET_OVERLAY_PANEL    1
409
410 static inline void
411 wl_input_panel_surface_set_user_data(struct wl_input_panel_surface *wl_input_panel_surface, void *user_data)
412 {
413     wl_proxy_set_user_data((struct wl_proxy *) wl_input_panel_surface, user_data);
414 }
415
416 static inline void *
417 wl_input_panel_surface_get_user_data(struct wl_input_panel_surface *wl_input_panel_surface)
418 {
419     return wl_proxy_get_user_data((struct wl_proxy *) wl_input_panel_surface);
420 }
421
422 static inline void
423 wl_input_panel_surface_destroy(struct wl_input_panel_surface *wl_input_panel_surface)
424 {
425     wl_proxy_destroy((struct wl_proxy *) wl_input_panel_surface);
426 }
427
428 static inline void
429 wl_input_panel_surface_set_toplevel(struct wl_input_panel_surface *wl_input_panel_surface, struct wl_output *output, uint32_t position)
430 {
431     wl_proxy_marshal((struct wl_proxy *) wl_input_panel_surface,
432              WL_INPUT_PANEL_SURFACE_SET_TOPLEVEL, output, position);
433 }
434
435 static inline void
436 wl_input_panel_surface_set_overlay_panel(struct wl_input_panel_surface *wl_input_panel_surface)
437 {
438     wl_proxy_marshal((struct wl_proxy *) wl_input_panel_surface,
439              WL_INPUT_PANEL_SURFACE_SET_OVERLAY_PANEL);
440 }
441
442 #ifdef  __cplusplus
443 }
444 #endif
445
446 #endif