1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
2 /*
3  * nimf-types.h
4  * This file is part of Nimf.
5  *
6  * Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
7  *
8  * Nimf is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Nimf is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program;  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef __NIMF_TYPES_H__
23 #define __NIMF_TYPES_H__
24 
25 #include <glib-object.h>
26 
27 G_BEGIN_DECLS
28 
29 /* copied from GdkModifierType in gdktypes.h for compatibility */
30 /**
31  * NimfModifierType:
32  * @NIMF_SHIFT_MASK: the Shift key.
33  * @NIMF_LOCK_MASK: a Lock key (depending on the modifier mapping of the
34  *  X server this may either be CapsLock or ShiftLock).
35  * @NIMF_CONTROL_MASK: the Control key.
36  * @NIMF_MOD1_MASK: the fourth modifier key (it depends on the modifier
37  *  mapping of the X server which key is interpreted as this modifier, but
38  *  normally it is the Alt key).
39  * @NIMF_MOD2_MASK: the fifth modifier key (it depends on the modifier
40  *  mapping of the X server which key is interpreted as this modifier).
41  * @NIMF_MOD3_MASK: the sixth modifier key (it depends on the modifier
42  *  mapping of the X server which key is interpreted as this modifier).
43  * @NIMF_MOD4_MASK: the seventh modifier key (it depends on the modifier
44  *  mapping of the X server which key is interpreted as this modifier).
45  * @NIMF_MOD5_MASK: the eighth modifier key (it depends on the modifier
46  *  mapping of the X server which key is interpreted as this modifier).
47  * @NIMF_BUTTON1_MASK: the first mouse button.
48  * @NIMF_BUTTON2_MASK: the second mouse button.
49  * @NIMF_BUTTON3_MASK: the third mouse button.
50  * @NIMF_BUTTON4_MASK: the fourth mouse button.
51  * @NIMF_BUTTON5_MASK: the fifth mouse button.
52  * @NIMF_MODIFIER_RESERVED_13_MASK: A reserved bit flag; do not use in your own code
53  * @NIMF_MODIFIER_RESERVED_14_MASK: A reserved bit flag; do not use in your own code
54  * @NIMF_MODIFIER_RESERVED_15_MASK: A reserved bit flag; do not use in your own code
55  * @NIMF_MODIFIER_RESERVED_16_MASK: A reserved bit flag; do not use in your own code
56  * @NIMF_MODIFIER_RESERVED_17_MASK: A reserved bit flag; do not use in your own code
57  * @NIMF_MODIFIER_RESERVED_18_MASK: A reserved bit flag; do not use in your own code
58  * @NIMF_MODIFIER_RESERVED_19_MASK: A reserved bit flag; do not use in your own code
59  * @NIMF_MODIFIER_RESERVED_20_MASK: A reserved bit flag; do not use in your own code
60  * @NIMF_MODIFIER_RESERVED_21_MASK: A reserved bit flag; do not use in your own code
61  * @NIMF_MODIFIER_RESERVED_22_MASK: A reserved bit flag; do not use in your own code
62  * @NIMF_MODIFIER_RESERVED_23_MASK: A reserved bit flag; do not use in your own code
63  * @NIMF_MODIFIER_RESERVED_24_MASK: A reserved bit flag; do not use in your own code
64  * @NIMF_MODIFIER_RESERVED_25_MASK: A reserved bit flag; do not use in your own code
65  * @NIMF_SUPER_MASK: the Super modifier.
66  * @NIMF_HYPER_MASK: the Hyper modifier.
67  * @NIMF_META_MASK: the Meta modifier.
68  * @NIMF_MODIFIER_RESERVED_29_MASK: A reserved bit flag; do not use in your own code
69  * @NIMF_RELEASE_MASK: exists because of compatibility.
70  * @NIMF_MODIFIER_MASK: a mask covering all modifier types.
71  *
72  * A set of bit-flags to indicate the state of modifier keys and mouse buttons
73  * in various event types. Typical modifier keys are Shift, Control, Meta,
74  * Super, Hyper, Alt, Compose, Apple, CapsLock or ShiftLock.
75  */
76 typedef enum
77 {
78   NIMF_SHIFT_MASK    = 1 << 0, /*< nick=<Shift> >*/
79   NIMF_LOCK_MASK     = 1 << 1, /*< nick=<Lock> >*/
80   NIMF_CONTROL_MASK  = 1 << 2, /*< nick=<Control> >*/
81   NIMF_MOD1_MASK     = 1 << 3, /*< nick=<Mod1> >*/
82   NIMF_MOD2_MASK     = 1 << 4, /*< nick=<Mod2> >*/
83   NIMF_MOD3_MASK     = 1 << 5, /*< nick=<Mod3> >*/
84   NIMF_MOD4_MASK     = 1 << 6, /*< nick=<Mod4> >*/
85   NIMF_MOD5_MASK     = 1 << 7, /*< nick=<Mod5> >*/
86   NIMF_BUTTON1_MASK  = 1 << 8, /*< nick=<Button1> >*/
87   NIMF_BUTTON2_MASK  = 1 << 9, /*< nick=<Button2> >*/
88   NIMF_BUTTON3_MASK  = 1 << 10, /*< nick=<Button3> >*/
89   NIMF_BUTTON4_MASK  = 1 << 11, /*< nick=<Button4> >*/
90   NIMF_BUTTON5_MASK  = 1 << 12, /*< nick=<Button5> >*/
91 
92   NIMF_MODIFIER_RESERVED_13_MASK  = 1 << 13,
93   NIMF_MODIFIER_RESERVED_14_MASK  = 1 << 14,
94   NIMF_MODIFIER_RESERVED_15_MASK  = 1 << 15,
95   NIMF_MODIFIER_RESERVED_16_MASK  = 1 << 16,
96   NIMF_MODIFIER_RESERVED_17_MASK  = 1 << 17,
97   NIMF_MODIFIER_RESERVED_18_MASK  = 1 << 18,
98   NIMF_MODIFIER_RESERVED_19_MASK  = 1 << 19,
99   NIMF_MODIFIER_RESERVED_20_MASK  = 1 << 20,
100   NIMF_MODIFIER_RESERVED_21_MASK  = 1 << 21,
101   NIMF_MODIFIER_RESERVED_22_MASK  = 1 << 22,
102   NIMF_MODIFIER_RESERVED_23_MASK  = 1 << 23,
103   NIMF_MODIFIER_RESERVED_24_MASK  = 1 << 24,
104   NIMF_MODIFIER_RESERVED_25_MASK  = 1 << 25,
105 
106   NIMF_SUPER_MASK    = 1 << 26, /*< nick=<Super> >*/
107   NIMF_HYPER_MASK    = 1 << 27, /*< nick=<Hyper> >*/
108   NIMF_META_MASK     = 1 << 28, /*< nick=<Meta> >*/
109 
110   NIMF_MODIFIER_RESERVED_29_MASK  = 1 << 29,
111 
112   NIMF_RELEASE_MASK  = 1 << 30, /*< nick=<Release> >*/
113 
114   /* Combination of NIMF_SHIFT_MASK..NIMF_BUTTON5_MASK + NIMF_SUPER_MASK
115      + NIMF_HYPER_MASK + NIMF_META_MASK + NIMF_RELEASE_MASK */
116   NIMF_MODIFIER_MASK = 0x5c001fff
117 } NimfModifierType;
118 
119 /**
120  * NimfRectangle:
121  * @x: x
122  * @y: y
123  * @width: width
124  * @height: height
125  *
126  * Defines the position and size of a rectangle.
127  */
128 typedef struct {
129   int x, y;
130   int width, height;
131 } NimfRectangle;
132 
133 /**
134  * NimfKey:
135  * @state: a bit-mask representing the state of the modifier keys
136  * @keyval: the key that was pressed or released.
137  */
138 typedef struct {
139   guint32 state;
140   guint32 keyval;
141 } NimfKey;
142 
143 /**
144  * NimfPreeditState:
145  * @NIMF_PREEDIT_STATE_START: presents preedit-start state.
146  * @NIMF_PREEDIT_STATE_END: presents preedit-end state.
147  */
148 typedef enum
149 {
150   NIMF_PREEDIT_STATE_START = 1,
151   NIMF_PREEDIT_STATE_END   = 0
152 } NimfPreeditState;
153 
154 /**
155  * NimfPreeditAttrType:
156  * @NIMF_PREEDIT_ATTR_UNDERLINE: whether the text has an underline
157  * @NIMF_PREEDIT_ATTR_HIGHLIGHT: whether the text has a highlight
158  */
159 typedef enum
160 {
161   NIMF_PREEDIT_ATTR_UNDERLINE,
162   NIMF_PREEDIT_ATTR_HIGHLIGHT
163 } NimfPreeditAttrType;
164 
165 /**
166  * NimfPreeditAttr:
167  * @type: a #NimfPreeditAttrType
168  * @start_index: the start index of the range (in characters).
169  * @end_index: end index of the range (in characters). The character at this
170  *   index is not included in the range.
171  */
172 typedef struct {
173   NimfPreeditAttrType type;
174   guint start_index; /* in characters */
175   guint end_index; /* in characters. The character at this index is not included */
176 } NimfPreeditAttr;
177 
178 /**
179  * NimfMethodInfo:
180  * @method_id: method id of the engine
181  * @label: human readable label
182  * @group: human readable group name
183  */
184 typedef struct
185 {
186   gchar *method_id; /* method id */
187   gchar *label;     /* Human readable label */
188   gchar *group;     /* Human readable group name */
189 } NimfMethodInfo;
190 
191 NimfKey  *nimf_key_new            (void);
192 NimfKey  *nimf_key_new_from_nicks (const gchar **nicks);
193 void      nimf_key_free           (NimfKey      *key);
194 NimfKey **nimf_key_newv           (const gchar **keys);
195 void      nimf_key_freev          (NimfKey     **keys);
196 
197 NimfPreeditAttr  *nimf_preedit_attr_new   (NimfPreeditAttrType type,
198                                            guint               start_index,
199                                            guint               end_index);
200 NimfPreeditAttr **nimf_preedit_attrs_copy (NimfPreeditAttr   **attrs);
201 void              nimf_preedit_attr_free  (NimfPreeditAttr    *attr);
202 void              nimf_preedit_attr_freev (NimfPreeditAttr   **attrs);
203 
204 NimfMethodInfo *nimf_method_info_new      (void);
205 void            nimf_method_info_free     (NimfMethodInfo  *info);
206 void            nimf_method_info_freev    (NimfMethodInfo **infos);
207 
208 G_END_DECLS
209 
210 #endif /* __NIMF_TYPES_H__ */
211