summaryrefslogtreecommitdiff
path: root/libxklavier/xkl_engine.h
blob: 9ca35a4cc71de6d08f7f82ab0c534204da6a4931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/*
 * Copyright (C) 2002-2006 Sergey V. Udaltsov <svu@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __XKL_ENGINE_H__
#define __XKL_ENGINE_H__

#include <X11/Xlib.h>

#include <glib-object.h>

#ifdef __cplusplus
extern "C" {
#endif

	typedef struct _XklEngine XklEngine;
	typedef struct _XklEnginePrivate XklEnginePrivate;
	typedef struct _XklEngineClass XklEngineClass;

#define XKL_TYPE_ENGINE             (xkl_engine_get_type ())
#define XKL_ENGINE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), XKL_TYPE_ENGINE, XklEngine))
#define XKL_ENGINE_CLASS(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), XKL_TYPE_ENGINE,  XklEngineClass))
#define XKL_IS_ENGINE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XKL_TYPE_ENGINE))
#define XKL_IS_ENGINE_CLASS(obj)    (G_TYPE_CHECK_CLASS_TYPE ((obj), XKL_TYPE_ENGINE))
#define XKL_ENGINE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), XKL_TYPE_ENGINE, XklEngineClass))

/**
 * The type of the keyboard state change
 *   @GROUP_CHANGED: Group was changed
 *   @INDICATORS_CHANGED: Indicators were changed
 */
	typedef enum {
		GROUP_CHANGED,
		INDICATORS_CHANGED
	} XklEngineStateChange;

/**
 * A set of flags used to indicate the capabilities of the active backend
 *   @XKLF_CAN_TOGGLE_INDICATORS: Backend allows to toggls indicators on/off
 *   @XKLF_CAN_OUTPUT_CONFIG_AS_ASCII: Backend allows writing ASCII representation of the configuration
 *   @XKLF_CAN_OUTPUT_CONFIG_AS_BINARY: Backend allows writing binary representation of the configuration
 *   @XKLF_MULTIPLE_LAYOUTS_SUPPORTED: Backend supports multiple layouts
 *   @XKLF_REQUIRES_MANUAL_LAYOUT_MANAGEMENT: Backend requires manual configuration, some daemon should do 
 *                                   xkl_start_listen(engine,XKLL_MANAGE_LAYOUTS);
 *   @XKLF_DEVICE_DISCOVERY: Backend supports device discovery, can notify
 */
	typedef enum { /*< flags >*/
		XKLF_CAN_TOGGLE_INDICATORS = 1 << 0,
		XKLF_CAN_OUTPUT_CONFIG_AS_ASCII = 1 << 1,
		XKLF_CAN_OUTPUT_CONFIG_AS_BINARY = 1 << 2,
		XKLF_MULTIPLE_LAYOUTS_SUPPORTED = 1 << 3,
		XKLF_REQUIRES_MANUAL_LAYOUT_MANAGEMENT = 1 << 4,
		XKLF_DEVICE_DISCOVERY = 1 << 5
	} XklEngineFeatures;

/**
 * XKB state. Can be global or per-window
 */
	typedef struct {
/** 
 * selected group 
 */
		gint32 group;
/**
 * set of active indicators
 */
		guint32 indicators;
	} XklState;

#define XKL_TYPE_STATE (xkl_state_get_type())

        GType xkl_state_get_type (void) G_GNUC_CONST;

/**
 *	The main Xklavier engine class
 */
	struct _XklEngine {
/**
 * The superclass object
 */
		GObject parent;
/**
 * Private data
 */
		XklEnginePrivate *priv;
	};

/**
 * The XklEngine class, derived from GObject
 */
	struct _XklEngineClass {
/**
 * The superclass
 */
		GObjectClass parent_class;

/**
 * XklEngine::config-notify:
 * @engine: the object on which the signal is emitted
 *
 * Used for notifying application of the XKB configuration change.
 */
		void (*config_notify) (XklEngine * engine);

/**
 * XklEngine::new_window_notify:
 * @engine: the object on which the signal is emitted
 * @win: new window
 * @parent: new window's parent
 *
 * Used for notifying application of new window creation (actually, 
 * registration).
 *
 * Returns: the initial group id for the window (-1 to use the default value)
 */
		 gint(*new_window_notify) (XklEngine * engine, Window win,
					   Window parent);
/**
 * XklEngine::state_notify
 * @engine: the object on which the signal is emitted
 * @change_type: mask of changes
 * @group: new group
 * @restore: whether this state is restored from
 * saved state of set as new.
 *
 * Used for notifying application of the window state change.
 */
		void (*state_notify) (XklEngine * engine,
				      XklEngineStateChange change_type,
				      gint group, gboolean restore);

/**
 * XklEngine::new_device_notify
 * @engine: the object on which the signal is emitted
 *
 * Used for notifying application of the new keyboard attached
 */
		void (*new_device_notify) (XklEngine * engine);

	};


/**
 * xkl_engine_get_type:
 *
 * Get type info for XklEngine
 *
 * Returns: GType for XklEngine
 */
	extern GType xkl_engine_get_type(void);


/**
 * xkl_engine_get_instance:
 * @display: the X display used by the application
 *
 * Get the instance of the XklEngine. Within a process, there is always once instance.
 *
 * Returns: (transfer none): the singleton instance
 */
	extern XklEngine *xkl_engine_get_instance(Display * display);


/**
 * xkl_engine_get_backend_name:
 * @engine: the engine
 * 
 * What kind of backend is used
 *
 * Returns: some string id of the backend
 */
	extern const gchar *xkl_engine_get_backend_name(XklEngine *
							engine);

/**
 * xkl_engine_get_features:
 * @engine: the engine
 *
 * Provides information regarding available backend features
 * (combination of XKLF_* constants)
 *
 * Returns: ORed XKLF_* constants
 */
	extern guint xkl_engine_get_features(XklEngine * engine);

/**
 * xkl_engine_get_max_num_groups:
 * @engine: the engine
 *
 * Provides the information on maximum number of simultaneously supported 
 * groups (layouts)
 *
 * Returns: maximum number of the groups in configuration, 
 *         0 if no restrictions.
 */
	extern guint xkl_engine_get_max_num_groups(XklEngine * engine);

/**
 * The listener action modes:
 *   @XKLL_MANAGE_WINDOW_STATES: The listener process should handle the per-window states 
 *                       and all the related activity
 *   @XKLL_TRACK_KEYBOARD_STATE: Just track the state and pass it to the application above.
 *   @XKLL_MANAGE_LAYOUTS: The listener process should help backend to maintain the configuration
 *                  (manually switch layouts etc).
 */
	typedef enum {
		XKLL_MANAGE_WINDOW_STATES = 0x01,
		XKLL_TRACK_KEYBOARD_STATE = 0x02,
		XKLL_MANAGE_LAYOUTS = 0x04,
	} XklEngineListenModes;

/**
 * xkl_engine_start_listen:
 * @engine: the engine
 * @flags: any combination of XKLL_* constants
 *
 * Starts listening for XKB-related events
 *
 * Returns: 0
 */
	extern gint xkl_engine_start_listen(XklEngine * engine,
					    guint flags);

/**
 * xkl_engine_stop_listen:
 * @engine: the engine
 * @flags: any combination of XKLL_* constants
 *
 * Stops listening for XKB-related events
 * Returns: 0
 */
	extern gint xkl_engine_stop_listen(XklEngine * engine,
					   guint flags);

/**
 * xkl_engine_pause_listen:
 * @engine: the engine
 *
 * Temporary pauses listening for XKB-related events
 *
 * Returns: 0
 */
	extern gint xkl_engine_pause_listen(XklEngine * engine);

/**
 * xkl_engine_resume_listen:
 * @engine: the engine
 *
 * Resumes listening for XKB-related events
 *
 * Returns: 0
 */
	extern gint xkl_engine_resume_listen(XklEngine * engine);

/**
 * xkl_engine_grab_key:
 * @engine: the engine
 * @keycode: keycode
 * @modifiers: bitmask of modifiers
 *
 * Grabs some key
 *
 * Returns: TRUE on success
 */
	extern gboolean xkl_engine_grab_key(XklEngine * engine,
					    gint keycode, guint modifiers);

/**
 * xkl_engine_ungrab_key:
 * @engine: the engine
 * @keycode: keycode
 * @modifiers: bitmask of modifiers
 *
 * Ungrabs some key
 *
 * Returns: TRUE on success
 */
	extern gboolean xkl_engine_ungrab_key(XklEngine * engine,
					      gint keycode,
					      guint modifiers);

/**
 * xkl_engine_filter_events:
 * @engine: the engine
 * @evt: (skip): delivered X event
 *
 * Processes X events. Should be included into the main event cycle of an
 * application. One of the most important functions. 
 *
 * Returns: 0 if the event it processed - 1 otherwise
 */
	extern gint xkl_engine_filter_events(XklEngine * engine,
					     XEvent * evt);

/**
 * xkl_engine_allow_one_switch_to_secondary_group:
 * @engine: the engine
 *
 * Allows to switch (once) to the secondary group
 *
 */
	extern void
	 xkl_engine_allow_one_switch_to_secondary_group(XklEngine *
							engine);

/**
 * xkl_engine_get_current_window:
 * @engine: the engine
 *
 * Returns: currently focused window
 */
	extern Window xkl_engine_get_current_window(XklEngine * engine);

/**
 * xkl_engine_get_current_state:
 * @engine: the engine
 *
 * Returns: (transfer none): current state of the keyboard.
 * Returned value is a statically allocated buffer, should not be freed.
 */
	extern XklState *xkl_engine_get_current_state(XklEngine * engine);

/**
 * xkl_engine_get_window_title:
 * @engine: the engine
 * @win: X window
 *
 * Returns: the window title of some window or NULL. 
 * If not NULL, it should be freed with XFree
 */
	extern gchar *xkl_engine_get_window_title(XklEngine * engine,
						  Window win);

/** 
 * xkl_engine_get_state:
 * @engine: the engine
 * @win: window to query
 * @state_out: structure to store the state
 * 
 * Finds the state for a given window (for its "App window").
 *
 * Returns: TRUE on success, otherwise FALSE 
 * (the error message can be obtained using xkl_GetLastError).
 */
	extern gboolean xkl_engine_get_state(XklEngine * engine,
					     Window win,
					     XklState * state_out);

/**
 * xkl_engine_delete_state:
 * @engine: the engine
 * @win: target window
 *
 * Drops the state of a given window (of its "App window").
 */
	extern void xkl_engine_delete_state(XklEngine * engine,
					    Window win);

/** 
 * xkl_engine_save_state:
 * @engine: the engine
 * @win: target window
 * @state: new state of the window
 *
 * Stores ths state for a given window
 */
	extern void xkl_engine_save_state(XklEngine * engine, Window win,
					  XklState * state);

/**
 * xkl_engine_set_window_transparent:
 * @engine: the engine
 * @win: window do set the flag for.
 * @transparent: if true, the windows is transparent.
 *
 * Sets the "transparent" flag. It means focus switching onto 
 * this window will never change the state.
 */
	extern void xkl_engine_set_window_transparent(XklEngine *
						      engine,
						      Window win,
						      gboolean
						      transparent);

/**
 * xkl_engine_is_window_transparent:
 * @engine: the engine
 * @win: window to get the transparent flag from.
 *
 * Returns: TRUE if the window is "transparent"
 */
	extern gboolean xkl_engine_is_window_transparent(XklEngine
							 * engine,
							 Window win);

/**
 * xkl_engine_is_window_from_same_toplevel_window:
 * @engine: the engine
 * @win1: first window
 * @win2: second window
 *
 * Checks whether 2 windows have the same topmost window
 *
 * Returns: TRUE is windows are in the same application
 */
	extern gboolean
	    xkl_engine_is_window_from_same_toplevel_window(XklEngine *
							   engine,
							   Window win1,
							   Window win2);

/**
 * xkl_engine_get_num_groups:
 * @engine: the engine
 *
 * Returns: the total number of groups in the current configuration 
 * (keyboard)
 */
	extern guint xkl_engine_get_num_groups(XklEngine * engine);

/**
 * xkl_engine_get_groups_names:
 * @engine: the engine
 *
 * Returns: (transfer none): the array of group names for the current XKB
 * configuration (keyboard).
 * This array is static, should not be freed
 */
	extern const gchar **xkl_engine_get_groups_names(XklEngine *
							 engine);

/**
 * xkl_engine_get_indicators_names:
 * @engine: the engine
 *
 * Returns: (transfer none): the array of indicator names for the current XKB
 * configuration (keyboard).
 * This array is static, should not be freed
 */
	extern const gchar **xkl_engine_get_indicators_names(XklEngine *
							     engine);

/**
 * xkl_engine_get_next_group:
 * @engine: the engine
 *
 * Calculates next group id. Does not change the state of anything.
 *
 * Returns: next group id
 */
	extern gint xkl_engine_get_next_group(XklEngine * engine);

/**
 * xkl_engine_get_prev_group:
 * @engine: the engine
 *
 * Calculates prev group id. Does not change the state of anything.
 *
 * Returns: prev group id
 */
	extern gint xkl_engine_get_prev_group(XklEngine * engine);

/**
 * xkl_engine_get_current_window_group:
 * @engine: the engine
 *
 * Returns: saved group id of the current window. 
 */
	extern gint xkl_engine_get_current_window_group(XklEngine *
							engine);

/**
 * xkl_engine_lock_group:
 * @engine: the engine
 * @group: group number for locking
 *
 * Locks the group. Can be used after xkl_GetXXXGroup functions
 */
	extern void xkl_engine_lock_group(XklEngine * engine, gint group);

/**
 * xkl_engine_set_group_per_toplevel_window:
 * @engine: the engine
 * @is_global: new parameter value
 *
 * Sets the configuration parameter: group per application
 */
	extern void xkl_engine_set_group_per_toplevel_window(XklEngine *
							     engine,
							     gboolean
							     is_global);

/**
 * xkl_engine_is_group_per_toplevel_window:
 * @engine: the engine
 * 
 * Returns: the value of the parameter: group per application
 */
	extern gboolean xkl_engine_is_group_per_toplevel_window(XklEngine *
								engine);

/**
 * xkl_engine_set_indicators_handling:
 * @engine: the engine
 * @whether_handle: new parameter value
 *
 * Sets the configuration parameter: perform indicators handling
 */
	extern void xkl_engine_set_indicators_handling(XklEngine * engine,
						       gboolean
						       whether_handle);

/**
 * xkl_engine_get_indicators_handling:
 * @engine: the engine
 *
 * Returns: the value of the parameter: perform indicator handling
 */
	extern gboolean xkl_engine_get_indicators_handling(XklEngine *
							   engine);

/**
 * xkl_engine_set_secondary_groups_mask:
 * @engine: the engine
 * @mask: new group mask
 *
 * Sets the secondary groups (one bit per group). 
 * Secondary groups require explicit "allowance" for switching
 */
	extern void xkl_engine_set_secondary_groups_mask(XklEngine *
							 engine,
							 guint mask);

/**
 * xkl_engine_get_secondary_groups_mask:
 * @engine: the engine
 *
 * Returns: the secondary group mask
 */
	extern guint xkl_engine_get_secondary_groups_mask(XklEngine *
							  engine);

/**
 * xkl_engine_set_default_group:
 * @engine: the engine
 * @group: default group
 *
 * Configures the default group set on window creation.
 * If -1, no default group is used
 */
	extern void xkl_engine_set_default_group(XklEngine * engine,
						 gint group);

/**
 * xkl_engine_get_default_group:
 * @engine: the engine
 *
 * Returns the default group set on window creation
 * If -1, no default group is used
 *
 * Returns: the default group
 */
	extern gint xkl_engine_get_default_group(XklEngine * engine);

#ifdef __cplusplus
}
#endif				/* __cplusplus */
#endif