summaryrefslogtreecommitdiff
path: root/libxklavier/xklavier_private.h
blob: 4298a9af06dc2dfff2f1f87685ffa6cfded1bbe8 (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
/*
 * 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 __XKLAVIER_PRIVATE_H__
#define __XKLAVIER_PRIVATE_H__

#include <stdio.h>

#include <libxml/xpath.h>

#include <libxklavier/xklavier.h>

enum { WM_NAME,
	WM_STATE,
	XKLAVIER_STATE,
	XKLAVIER_TRANSPARENT,
	XKLAVIER_ALLOW_SECONDARY,
	TOTAL_ATOMS
};

#define XKL_NUMBER_OF_REGISTRY_DOCS 2

struct _XklEnginePrivate {

	gboolean group_per_toplevel_window;

	gboolean handle_indicators;

	gboolean skip_one_restore;

	gint default_group;

	guint listener_type;

	guint secondary_groups_mask;

	Window root_window;

	Window prev_toplvl_win;

	Window curr_toplvl_win;

	XErrorHandler default_error_handler;

	Status last_error_code;

	XklState curr_state;

	gboolean criticalSection;

	Atom atoms[TOTAL_ATOMS];

	Display *display;

	/*
	 * Backend name
	 */
	const gchar *backend_id;

	/*
	 * Functions supported by the backend, combination of XKLF_* constants
	 */
	guint8 features;

	/*
	 * Activates the configuration.
	 * xkb: create proper the XkbDescRec and send it to the server
	 * xmodmap: save the property, init layout #1
	 */
	 gboolean(*activate_config_rec) (XklEngine * engine,
					 const XklConfigRec * data);

	/*
	 * Background-specific initialization.
	 * xkb: XkbInitAtoms - init internal xkb atoms table
	 * xmodmap: void.
	 */
	void (*init_config_registry) (XklConfigRegistry * config);

	/*
	 * Loads the registry tree into DOM (using whatever path(s))
	 * The XklVTConfigFreeRegistry is static - no virtualization necessary.
	 * xkb: loads xml from XKB_BASE+"/rules/"+ruleset+".xml"
	 * xmodmap: loads xml from XMODMAP_BASE+"/"+ruleset+".xml"
	 */
	 gboolean(*load_config_registry) (XklConfigRegistry * config,
					  gboolean if_extras_needed);

	/*
	 * Write the configuration into the file (binary/textual)
	 * xkb: write xkb or xkm file
	 * xmodmap: if text requested, just dump XklConfigRec to the 
	 * file - not really useful. If binary - fail (not supported)
	 */
	 gboolean(*write_config_rec_to_file) (XklEngine * engine,
					      const gchar * file_name,
					      const XklConfigRec * data,
					      const gboolean binary);

	/*
	 * Get the list of the group names
	 * xkb: return cached list of the group names
	 * xmodmap: return the list of layouts from the internal XklConfigRec
	 */
	const gchar **(*get_groups_names) (XklEngine * engine);

	/*
	 * Get the list of the indicators names
	 * xkb: return cached list of the indicators names
	 * xmodmap: return NULL
	 */
	const gchar **(*get_indicators_names) (XklEngine * engine);

	/*
	 * Get the maximum number of loaded groups
	 * xkb: returns 1 or XkbNumKbdGroups
	 * xmodmap: return 0
	 */
	 guint(*get_max_num_groups) (XklEngine * engine);

	/*
	 * Get the number of loaded groups
	 * xkb: return from the cached XkbDesc
	 * xmodmap: return number of layouts from internal XklConfigRec
	 */
	 guint(*get_num_groups) (XklEngine * engine);

	/*
	 * Switches the keyboard to the group N
	 * xkb: simple one-liner to call the XKB function
	 * xmodmap: changes the root window property 
	 * (listener invokes xmodmap with appropriate config file).
	 */
	void (*lock_group) (XklEngine * engine, gint group);

	/*
	 * Handles X events.
	 * xkb: XkbEvent handling
	 * xmodmap: keep track on the root window properties. What else can we do?
	 */
	 gint(*process_x_event) (XklEngine * engine, XEvent * xev);

	/*
	 * Flushes the cached server config info.
	 * xkb: frees XkbDesc
	 * xmodmap: frees internal XklConfigRec
	 */
	void (*free_all_info) (XklEngine * engine);

	/*
	 * Compares the cached info with the actual one, from the server
	 * xkb: Compares some parts of XkbDescPtr
	 * xmodmap: returns False
	 */
	 gboolean(*if_cached_info_equals_actual) (XklEngine * engine);

	/*
	 * Loads the configuration info from the server
	 * xkb: loads XkbDesc, names, indicators
	 * xmodmap: loads internal XklConfigRec from server
	 */
	 gboolean(*load_all_info) (XklEngine * engine);

	/*
	 * Gets the current state
	 * xkb: XkbGetState and XkbGetIndicatorState
	 * xmodmap: check the root window property (regarding the group)
	 */
	void (*get_server_state) (XklEngine * engine,
				  XklState * current_state_out);

	/*
	 * Stop tracking the keyboard-related events
	 * xkb: XkbSelectEvents(..., 0)
	 * xmodmap: Ungrab the switching shortcut.
	 */
	 gint(*pause_listen) (XklEngine * engine);

	/*
	 * Start tracking the keyboard-related events
	 * xkb: XkbSelectEvents + XkbSelectEventDetails
	 * xmodmap: Grab the switching shortcut.
	 */
	 gint(*resume_listen) (XklEngine * engine);

	/*
	 * Set the indicators state from the XklState
	 * xkb: XklSetIndicator for all indicators
	 * xmodmap: NULL. Not supported
	 */
	void (*set_indicators) (XklEngine * engine,
				const XklState * window_state);

	/*
	 * Perform the cleanup
	 */
	void (*finalize) (XklEngine * engine);

	/* all data is private - no direct access */
	/*
	 * The base configuration atom.
	 * xkb: _XKB_RF_NAMES_PROP_ATOM
	 * xmodmap:  "_XMM_NAMES"
	 */
	Atom base_config_atom;

	/*
	 * The configuration backup atom
	 * xkb: "_XKB_RULES_NAMES_BACKUP"
	 * xmodmap: "_XMM_NAMES_BACKUP"
	 */
	Atom backup_config_atom;

	/*
	 * Fallback for missing model
	 */
	const gchar *default_model;

	/*
	 * Fallback for missing layout
	 */
	const gchar *default_layout;

	/*
	 * Any stuff backend might need to put in here
	 */
	gpointer backend;
};

extern XklEngine *xkl_get_the_engine(void);

struct _XklConfigRegistryPrivate {
	XklEngine *engine;

	xmlDocPtr docs[XKL_NUMBER_OF_REGISTRY_DOCS];
	xmlXPathContextPtr xpath_contexts[XKL_NUMBER_OF_REGISTRY_DOCS];
};

extern void xkl_engine_ensure_vtable_inited(XklEngine * engine);

extern void xkl_engine_process_focus_in_evt(XklEngine * engine,
					    XFocusChangeEvent * fev);
extern void xkl_engine_process_focus_out_evt(XklEngine * engine,
					     XFocusChangeEvent * fev);
extern void xkl_engine_process_property_evt(XklEngine * engine,
					    XPropertyEvent * rev);
extern void xkl_engine_process_create_window_evt(XklEngine * engine,
						 XCreateWindowEvent * cev);

extern int xkl_process_error(Display * dpy, XErrorEvent * evt);

extern void xkl_engine_process_state_modification(XklEngine * engine,
						  XklEngineStateChange
						  change_type, gint group,
						  unsigned inds,
						  gboolean set_indicators);

extern Window xkl_engine_get_registered_parent(XklEngine * engine,
					       Window win);
extern void xkl_engine_reset_all_info(XklEngine * engine, gboolean force,
				      const gchar reason[]);
extern gboolean xkl_engine_load_window_tree(XklEngine * engine);
extern gboolean xkl_engine_load_subtree(XklEngine * engine, Window window,
					gint level, XklState * init_state);

extern gboolean xkl_engine_if_window_has_wm_state(XklEngine * engine,
						  Window win);


/**
 * Toplevel window stuff
 */
extern void xkl_engine_add_toplevel_window(XklEngine * engine, Window win,
					   Window parent, gboolean force,
					   XklState * init_state);

extern gboolean xkl_engine_find_toplevel_window_bottom_to_top(XklEngine *
							      engine,
							      Window win,
							      Window *
							      toplevel_win_out);

extern gboolean xkl_engine_find_toplevel_window(XklEngine * engine,
						Window win,
						Window * toplevel_win_out);

extern gboolean xkl_engine_is_toplevel_window_transparent(XklEngine *
							  engine,
							  Window
							  toplevel_win);

extern void xkl_engine_set_toplevel_window_transparent(XklEngine * engine,
						       Window toplevel_win,
						       gboolean
						       transparent);

extern gboolean xkl_engine_get_toplevel_window_state(XklEngine * engine,
						     Window toplevel_win,
						     XklState * state_out);

extern void xkl_engine_remove_toplevel_window_state(XklEngine * engine,
						    Window toplevel_win);
extern void xkl_engine_save_toplevel_window_state(XklEngine * engine,
						  Window toplevel_win,
						  XklState * state);
/***/

extern void xkl_engine_select_input_merging(XklEngine * engine, Window win,
					    gulong mask);

extern gchar *xkl_get_debug_window_title(XklEngine * engine, Window win);

extern Status xkl_engine_query_tree(XklEngine * engine,
				    Window w,
				    Window * root_out,
				    Window * parent_out,
				    Window ** children_out,
				    guint * nchildren_out);

extern void xkl_engine_try_call_state_func(XklEngine * engine,
					   XklEngineStateChange
					   change_type,
					   XklState * old_state);

extern gchar *xkl_engine_get_ruleset_name(XklEngine * engine,
					  const gchar default_ruleset[]);

extern gboolean xkl_config_rec_get_full_from_server(gchar **
						    rules_file_out,
						    XklConfigRec * data,
						    XklEngine * engine);

extern gchar *xkl_strings_concat_comma_separated(gchar ** array);

extern void xkl_strings_split_comma_separated(gchar *** array,
					      const gchar * merged);

/**
 * XConfigRec
 */
extern gchar *xkl_config_rec_merge_layouts(const XklConfigRec * data);

extern gchar *xkl_config_rec_merge_variants(const XklConfigRec * data);

extern gchar *xkl_config_rec_merge_options(const XklConfigRec * data);

extern void xkl_config_rec_split_layouts(XklConfigRec * data,
					 const gchar * merged);

extern void xkl_config_rec_split_variants(XklConfigRec * data,
					  const gchar * merged);

extern void xkl_config_rec_split_options(XklConfigRec * data,
					 const gchar * merged);
/***/

extern void xkl_config_rec_dump(FILE * file, XklConfigRec * data);

extern const gchar *xkl_event_get_name(gint type);

extern void xkl_engine_update_current_state(XklEngine * engine, gint group,
					    unsigned indicators,
					    const gchar reason[]);

extern gint xkl_xkb_init(XklEngine * engine);

extern gint xkl_xmm_init(XklEngine * engine);

extern gboolean
xkl_engine_is_one_switch_to_secondary_group_allowed(XklEngine * engine);

extern void xkl_engine_one_switch_to_secondary_group_performed(XklEngine *
							       engine);

extern gboolean xkl_config_registry_load_from_file(XklConfigRegistry *
						   config,
						   const gchar * file_name,
						   gint docidx);

extern void xkl_config_registry_free(XklConfigRegistry * config);

extern gchar *xkl_locale_from_utf8(XklConfigRegistry * config,
				   const gchar * utf8string);

extern gboolean xkl_config_registry_load_helper(XklConfigRegistry * config, const char
						default_ruleset[],
						const char base_dir[],
						gboolean if_extras_needed);

#define XKLAVIER_STATE_PROP_LENGTH 2

/* taken from XFree86 maprules.c */
#define XKB_RF_NAMES_PROP_MAXLEN 1024

#define WINID_FORMAT "%lx"

#define xkl_engine_priv(engine,member)  (engine)->priv->member
#define xkl_engine_backend(engine,type,member)  ((type*)((engine)->priv->backend))->member
#define xkl_engine_get_display(engine) (xkl_engine_priv(engine,display))
#define xkl_engine_vcall(engine,func)  (*(engine)->priv->func)

#define xkl_config_registry_is_initialized(config) \
  ( xkl_config_registry_priv(config,xpath_contexts[0]) != NULL )

#define xkl_config_registry_priv(config,member)  (config)->priv->member
#define xkl_config_registry_get_engine(config) ((config)->priv->engine)

#define XKBCR_MODEL_PATH "/xkbConfigRegistry/modelList/model"
#define XKBCR_LAYOUT_PATH "/xkbConfigRegistry/layoutList/layout"
#define XKBCR_VARIANT_PATH XKBCR_LAYOUT_PATH "/variantList/variant"
#define XKBCR_GROUP_PATH "/xkbConfigRegistry/optionList/group"
#define XKBCR_OPTION_PATH XKBCR_GROUP_PATH "/option"

#define XML_TAG_DESCR "description"
#define XML_TAG_SHORT_DESCR "shortDescription"
#define XML_TAG_VENDOR "vendor"
#define XML_TAG_COUNTRY_LIST "countryList"
#define XML_TAG_LANGUAGE_LIST "languageList"
#define XML_TAG_ISO3166ID "iso3166Id"
#define XML_TAG_ISO639ID "iso639Id"

extern void



xkl_config_registry_foreach_in_xpath_with_param(XklConfigRegistry * config,
						const gchar * format,
						const gchar * value,
						ConfigItemProcessFunc func,
						gpointer data);

extern void xkl_config_registry_foreach_in_xpath(XklConfigRegistry *
						 config,
						 xmlXPathCompExprPtr
						 xpath_comp_expr,
						 ConfigItemProcessFunc
						 func, gpointer data);

extern gboolean xkl_read_config_item(XklConfigRegistry * config,
				     gint doc_index, xmlNodePtr iptr,
				     XklConfigItem * item);

extern gint xkl_debug_level;

extern const gchar *xkl_last_error_message;

#endif