summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2006-02-26 13:55:42 +0000
committerSergey Udaltsov <svu@gnome.org>2006-02-26 13:55:42 +0000
commit8ffc8fbcf0d5a657d71a55c8eb66671d83aec180 (patch)
tree49559060c49f7cba44a6720765e8e0a765eb6cec
parent883773a40a132b68d73d0a563b211c12994bc6b1 (diff)
downloadlibxklavier-8ffc8fbcf0d5a657d71a55c8eb66671d83aec180.tar.gz
further gobjectification
-rw-r--r--libxklavier/xklavier.c491
-rw-r--r--libxklavier/xklavier.h263
-rw-r--r--libxklavier/xklavier_config.c39
-rw-r--r--libxklavier/xklavier_config.h6
-rw-r--r--libxklavier/xklavier_evt.c322
-rw-r--r--libxklavier/xklavier_private.h263
-rw-r--r--libxklavier/xklavier_props.c4
7 files changed, 726 insertions, 662 deletions
diff --git a/libxklavier/xklavier.c b/libxklavier/xklavier.c
index 372bf7c..5088c90 100644
--- a/libxklavier/xklavier.c
+++ b/libxklavier/xklavier.c
@@ -7,60 +7,24 @@
#include "xklavier_private.h"
-Display *xkl_display;
-
-XklState xkl_current_state;
-
-Window xkl_current_client;
-
-Status xkl_last_error_code;
-
-const gchar *xkl_last_error_message;
-
-XErrorHandler xkl_default_error_handler;
-
-Atom xkl_atoms[TOTAL_ATOMS];
-
-Window xkl_root_window;
-
-gint xkl_default_group;
-
-gboolean xkl_skip_one_restore;
-
-guint xkl_secondary_groups_mask;
+static XklEngine *the_engine = NULL;
gint xkl_debug_level = 0;
-guint xkl_listener_type = 0;
-
-XklVTable *xkl_vtable = NULL;
-
-XklConfigNotifyFunc xkl_config_callback = NULL;
-gpointer xkl_config_callback_data;
-
-XklNewWindowNotifyFunc xkl_new_window_callback = NULL;
-gpointer xkl_new_window_callback_data;
-
-static XklStateNotifyFunc xkl_state_callback = NULL;
-static gpointer xkl_state_callback_data;
-
static XklLogAppender log_appender = xkl_default_log_appender;
-static gboolean group_per_toplevel_window = TRUE;
-
-static gboolean handle_indicators = FALSE;
-
void
-xkl_set_indicators_handling(gboolean whether_handle)
+xkl_engine_set_indicators_handling(XklEngine * engine,
+ gboolean whether_handle)
{
- handle_indicators = whether_handle;
+ engine->priv->handle_indicators = whether_handle;
}
gboolean
-xkl_get_indicators_handling(void)
+xkl_engine_get_indicators_handling(XklEngine * engine)
{
- return handle_indicators;
+ return engine->priv->handle_indicators;
}
void
@@ -70,39 +34,41 @@ xkl_set_debug_level(int level)
}
void
-xkl_set_group_per_toplevel_window(gboolean is_set)
+xkl_engine_set_group_per_toplevel_window(XklEngine * engine,
+ gboolean is_set)
{
- group_per_toplevel_window = is_set;
+ engine->priv->group_per_toplevel_window = is_set;
}
gboolean
-xkl_is_group_per_toplevel_window(void)
+xkl_engine_is_group_per_toplevel_window(XklEngine * engine)
{
- return group_per_toplevel_window;
+ return engine->priv->group_per_toplevel_window;
}
static void
-xkl_set_switch_to_secondary_group(gboolean val)
+xkl_engine_set_switch_to_secondary_group(XklEngine * engine, gboolean val)
{
CARD32 propval = (CARD32) val;
- XChangeProperty(xkl_display,
- xkl_root_window,
- xkl_atoms[XKLAVIER_ALLOW_SECONDARY],
+ Display *dpy = xkl_engine_get_display(engine);
+ XChangeProperty(dpy,
+ engine->priv->root_window,
+ engine->priv->atoms[XKLAVIER_ALLOW_SECONDARY],
XA_INTEGER, 32, PropModeReplace,
(unsigned char *) &propval, 1);
- XSync(xkl_display, False);
+ XSync(dpy, False);
}
void
-xkl_group_allow_one_switch_to_secondary(void)
+xkl_engine_group_allow_one_switch_to_secondary(XklEngine * engine)
{
xkl_debug(150,
"Setting allow_one_switch_to_secondary_group flag\n");
- xkl_set_switch_to_secondary_group(TRUE);
+ xkl_engine_set_switch_to_secondary_group(engine, TRUE);
}
gboolean
-xkl_is_one_switch_to_secondary_group_allowed(void)
+xkl_engine_is_one_switch_to_secondary_group_allowed(XklEngine * engine)
{
gboolean rv = FALSE;
unsigned char *propval = NULL;
@@ -112,12 +78,14 @@ xkl_is_one_switch_to_secondary_group_allowed(void)
unsigned long actual_items;
int result;
- result = XGetWindowProperty(xkl_display, xkl_root_window,
- xkl_atoms[XKLAVIER_ALLOW_SECONDARY],
- 0L, 1L, False, XA_INTEGER,
- &actual_type, &actual_format,
- &actual_items, &bytes_remaining,
- &propval);
+ result =
+ XGetWindowProperty(xkl_engine_get_display(engine),
+ engine->priv->root_window,
+ engine->priv->
+ atoms[XKLAVIER_ALLOW_SECONDARY], 0L, 1L,
+ False, XA_INTEGER, &actual_type,
+ &actual_format, &actual_items,
+ &bytes_remaining, &propval);
if (Success == result) {
if (actual_format == 32 && actual_items == 1) {
@@ -130,60 +98,35 @@ xkl_is_one_switch_to_secondary_group_allowed(void)
}
void
-xkl_one_switch_to_secondary_group_performed(void)
+xkl_engine_one_switch_to_secondary_group_performed(XklEngine * engine)
{
xkl_debug(150,
"Resetting allow_one_switch_to_secondary_group flag\n");
- xkl_set_switch_to_secondary_group(FALSE);
+ xkl_engine_set_switch_to_secondary_group(engine, FALSE);
}
void
-xkl_set_default_group(int group)
+xkl_engine_set_default_group(XklEngine * engine, gint group)
{
- xkl_default_group = group;
+ engine->priv->default_group = group;
}
gint
-_xkl_get_default_group(void)
+xkl_engine_get_default_group(XklEngine * engine)
{
- return xkl_default_group;
+ return engine->priv->default_group;
}
void
-xkl_set_secondary_groups_mask(guint mask)
+xkl_engine_set_secondary_groups_mask(XklEngine * engine, guint mask)
{
- xkl_secondary_groups_mask = mask;
+ engine->priv->secondary_groups_mask = mask;
}
guint
-xkl_get_secondary_groups_mask(void)
-{
- return xkl_secondary_groups_mask;
-}
-
-gint
-xkl_register_config_callback(XklConfigNotifyFunc func, gpointer data)
-{
- xkl_config_callback = func;
- xkl_config_callback_data = data;
- return 0;
-}
-
-gint
-xkl_register_state_callback(XklStateNotifyFunc func, gpointer data)
-{
- xkl_state_callback = func;
- xkl_state_callback_data = data;
- return 0;
-}
-
-gint
-xkl_register_new_window_callback(XklNewWindowNotifyFunc func,
- gpointer data)
+xkl_engine_get_secondary_groups_mask(XklEngine * engine)
{
- xkl_new_window_callback = func;
- xkl_new_window_callback_data = data;
- return 0;
+ return engine->priv->secondary_groups_mask;
}
void
@@ -193,118 +136,134 @@ xkl_set_log_appender(XklLogAppender func)
}
gint
-xkl_listen_start(guint what)
+xkl_engine_start_listen(XklEngine * engine, guint what)
{
- xkl_listener_type = what;
+ engine->priv->listener_type = what;
if (!
- (xkl_vtable->features & XKLF_REQUIRES_MANUAL_LAYOUT_MANAGEMENT)
- && (what & XKLL_MANAGE_LAYOUTS))
+ (engine->priv->
+ features & XKLF_REQUIRES_MANUAL_LAYOUT_MANAGEMENT)
+&& (what & XKLL_MANAGE_LAYOUTS))
xkl_debug(0,
"The backend does not require manual layout management - "
"but it is provided by the application");
- xkl_listen_resume();
- xkl_load_window_tree();
- XFlush(xkl_display);
+ xkl_engine_resume_listen(engine);
+ xkl_engine_load_window_tree(engine);
+ XFlush(xkl_engine_get_display(engine));
return 0;
}
gint
-xkl_listen_stop(void)
+xkl_engine_stop_listen(XklEngine * engine)
{
- xkl_listen_pause();
+ xkl_engine_pause_listen(engine);
return 0;
}
-gint
-xkl_init(Display * a_dpy)
+XklEngine *
+xkl_engine_get_instance(Display * display)
{
- int scr;
- const gchar *sdl;
- int rv;
-
- sdl = g_getenv("XKL_DEBUG");
- if (sdl != NULL) {
- xkl_set_debug_level(atoi(sdl));
+ if (the_engine != NULL) {
+ g_object_ref(G_OBJECT(the_engine));
+ return the_engine;
}
- if (!a_dpy) {
+ if (!display) {
xkl_debug(10, "xkl_init : display is NULL ?\n");
- return -1;
+ return NULL;
}
- xkl_default_error_handler =
- XSetErrorHandler((XErrorHandler) xkl_process_error);
+ the_engine = XKL_ENGINE(g_object_new(xkl_engine_get_type(), NULL));
- xkl_display = a_dpy;
- scr = DefaultScreen(xkl_display);
- xkl_root_window = RootWindow(xkl_display, scr);
- xkl_skip_one_restore = FALSE;
- xkl_default_group = -1;
- xkl_secondary_groups_mask = 0L;
- xkl_toplevel_window_prev = 0;
+ the_engine->priv->display = display;
- xkl_atoms[WM_NAME] = XInternAtom(xkl_display, "WM_NAME", False);
- xkl_atoms[WM_STATE] = XInternAtom(xkl_display, "WM_STATE", False);
- xkl_atoms[XKLAVIER_STATE] =
- XInternAtom(xkl_display, "XKLAVIER_STATE", False);
- xkl_atoms[XKLAVIER_TRANSPARENT] =
- XInternAtom(xkl_display, "XKLAVIER_TRANSPARENT", False);
- xkl_atoms[XKLAVIER_ALLOW_SECONDARY] =
- XInternAtom(xkl_display, "XKLAVIER_ALLOW_SECONDARY", False);
+ const gchar *sdl = g_getenv("XKL_DEBUG");
- xkl_one_switch_to_secondary_group_performed();
+ if (sdl != NULL) {
+ xkl_set_debug_level(atoi(sdl));
+ }
- rv = -1;
+ gint rv = -1;
xkl_debug(150, "Trying all backends:\n");
#ifdef ENABLE_XKB_SUPPORT
xkl_debug(150, "Trying XKB backend\n");
- rv = xkl_xkb_init();
+ rv = xkl_xkb_init(the_engine);
#endif
#ifdef ENABLE_XMM_SUPPORT
if (rv != 0) {
xkl_debug(150, "Trying XMM backend\n");
- rv = xkl_xmm_init();
+ rv = xkl_xmm_init(the_engine);
}
#endif
if (rv == 0) {
xkl_debug(150, "Actual backend: %s\n",
- xkl_backend_get_name());
+ xkl_engine_get_backend_name(the_engine));
} else {
xkl_debug(0, "All backends failed, last result: %d\n", rv);
- xkl_display = NULL;
+ the_engine->priv->display = NULL;
+ g_object_unref(G_OBJECT(the_engine));
+ the_engine = NULL;
+ return NULL;
}
- return (rv == 0) ?
- (xkl_load_all_info()? 0 : xkl_last_error_code) : -1;
+ int scr;
+
+ the_engine->priv->default_error_handler =
+ XSetErrorHandler((XErrorHandler) xkl_process_error);
+
+ Display *dpy = xkl_engine_get_display(the_engine);
+ scr = DefaultScreen(dpy);
+ the_engine->priv->root_window = RootWindow(dpy, scr);
+
+ the_engine->priv->skip_one_restore = FALSE;
+ the_engine->priv->default_group = -1;
+ the_engine->priv->secondary_groups_mask = 0L;
+ the_engine->priv->prev_toplvl_win = 0;
+
+ the_engine->priv->atoms[WM_NAME] =
+ XInternAtom(dpy, "WM_NAME", False);
+ the_engine->priv->atoms[WM_STATE] =
+ XInternAtom(dpy, "WM_STATE", False);
+ the_engine->priv->atoms[XKLAVIER_STATE] =
+ XInternAtom(dpy, "XKLAVIER_STATE", False);
+ the_engine->priv->atoms[XKLAVIER_TRANSPARENT] =
+ XInternAtom(dpy, "XKLAVIER_TRANSPARENT", False);
+ the_engine->priv->atoms[XKLAVIER_ALLOW_SECONDARY] =
+ XInternAtom(dpy, "XKLAVIER_ALLOW_SECONDARY", False);
+
+ xkl_engine_one_switch_to_secondary_group_performed(the_engine);
+
+ if (!xkl_engine_load_all_info(the_engine)) {
+ g_object_unref(G_OBJECT(the_engine));
+ the_engine = NULL;
+ }
+
+ return the_engine;
}
gint
-xkl_term(void)
+xkl_term(XklEngine * engine)
{
- XSetErrorHandler((XErrorHandler) xkl_default_error_handler);
- xkl_config_callback = NULL;
- xkl_state_callback = NULL;
- xkl_new_window_callback = NULL;
+ XSetErrorHandler((XErrorHandler) engine->priv->
+ default_error_handler);
- log_appender = xkl_default_log_appender;
- xkl_free_all_info();
+ xkl_engine_free_all_info(engine);
return 0;
}
gboolean
-xkl_key_grab(gint keycode, guint modifiers)
+xkl_engine_key_grab(XklEngine * engine, gint keycode, guint modifiers)
{
gboolean ret_code;
gchar *keyname;
+ Display *dpy = xkl_engine_get_display(engine);
if (xkl_debug_level >= 100) {
keyname =
- XKeysymToString(XKeycodeToKeysym
- (xkl_display, keycode, 0));
+ XKeysymToString(XKeycodeToKeysym(dpy, keycode, 0));
xkl_debug(100, "Listen to the key %d/(%s)/%d\n", keycode,
keyname, modifiers);
}
@@ -312,124 +271,143 @@ xkl_key_grab(gint keycode, guint modifiers)
if (0 == keycode)
return FALSE;
- xkl_last_error_code = Success;
+ engine->priv->last_error_code = Success;
ret_code =
- XGrabKey(xkl_display, keycode, modifiers, xkl_root_window,
+ XGrabKey(dpy, keycode, modifiers, engine->priv->root_window,
TRUE, GrabModeAsync, GrabModeAsync);
- XSync(xkl_display, False);
+ XSync(dpy, False);
xkl_debug(100, "XGrabKey recode %d/error %d\n",
- ret_code, xkl_last_error_code);
+ ret_code, engine->priv->last_error_code);
- ret_code = (xkl_last_error_code == Success);
+ ret_code = (engine->priv->last_error_code == Success);
if (!ret_code)
- xkl_last_error_message = "Could not grab the key";
+ engine->priv->last_error_message =
+ "Could not grab the key";
return ret_code;
}
gboolean
-xkl_key_ungrab(gint keycode, guint modifiers)
+xkl_engine_key_ungrab(XklEngine * engine, gint keycode, guint modifiers)
{
if (0 == keycode)
return FALSE;
- return Success == XUngrabKey(xkl_display, keycode, 0,
- xkl_root_window);
+ return Success == XUngrabKey(xkl_engine_get_display(engine),
+ keycode, 0,
+ engine->priv->root_window);
}
gint
-xkl_group_get_next(void)
+xkl_engine_get_next_group(XklEngine * engine)
{
- return (xkl_current_state.group + 1) % xkl_groups_get_num();
+ gint n = xkl_engine_get_num_groups(engine);
+ return (engine->priv->curr_state.group + 1) % n;
}
gint
-xkl_get_prev_group(void)
+xkl_engine_get_prev_group(XklEngine * engine)
{
- gint n = xkl_groups_get_num();
- return (xkl_current_state.group + n - 1) % n;
+ gint n = xkl_engine_get_num_groups(engine);
+ return (engine->priv->curr_state.group + n - 1) % n;
}
gint
-xkl_get_restore_group(void)
+xkl_engine_get_current_window_group(XklEngine * engine)
{
XklState state;
- if (xkl_current_client == (Window) NULL) {
+ if (engine->priv->curr_toplvl_win == (Window) NULL) {
xkl_debug(150, "cannot restore without current client\n");
- } else if (xkl_state_get(xkl_current_client, &state)) {
+ } else
+ if (xkl_engine_get_toplevel_window_state
+ (engine, engine->priv->curr_toplvl_win, &state)) {
return state.group;
} else
xkl_debug(150,
"Unbelievable: current client " WINID_FORMAT
- ", '%s' has no group\n", xkl_current_client,
- xkl_window_get_debug_title(xkl_current_client));
+ ", '%s' has no group\n",
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win));
return 0;
}
void
-xkl_set_transparent(Window win, gboolean transparent)
+xkl_engine_set_transparent(XklEngine * engine, Window win,
+ gboolean transparent)
{
Window toplevel_win;
xkl_debug(150,
"setting transparent flag %d for " WINID_FORMAT "\n",
transparent, win);
- if (!xkl_toplevel_window_find(win, &toplevel_win)) {
+ if (!xkl_engine_find_toplevel_window(engine, win, &toplevel_win)) {
xkl_debug(150, "No toplevel window!\n");
toplevel_win = win;
/* return; */
}
- xkl_toplevel_window_set_transparent(toplevel_win, transparent);
+ xkl_engine_set_toplevel_window_transparent(engine, toplevel_win,
+ transparent);
}
gboolean
-xkl_window_is_transparent(Window win)
+xkl_engine_is_window_transparent(XklEngine * engine, Window win)
{
Window toplevel_win;
- if (!xkl_toplevel_window_find(win, &toplevel_win))
+ if (!xkl_engine_find_toplevel_window(engine, win, &toplevel_win))
return FALSE;
- return xkl_toplevel_window_is_transparent(toplevel_win);
+ return xkl_engine_is_toplevel_window_transparent(engine,
+ toplevel_win);
}
/**
* Loads the tree recursively.
*/
gboolean
-xkl_load_window_tree(void)
+xkl_engine_load_window_tree(XklEngine * engine)
{
Window focused;
int revert;
gboolean retval = TRUE, have_toplevel_win;
- if (xkl_listener_type & XKLL_MANAGE_WINDOW_STATES)
+ if (engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES)
retval =
- xkl_load_subtree(xkl_root_window, 0,
- &xkl_current_state);
+ xkl_engine_load_subtree(engine,
+ engine->priv->root_window, 0,
+ &engine->priv->curr_state);
- XGetInputFocus(xkl_display, &focused, &revert);
+ XGetInputFocus(xkl_engine_get_display(engine), &focused, &revert);
xkl_debug(160, "initially focused: " WINID_FORMAT ", '%s'\n",
- focused, xkl_window_get_debug_title(focused));
+ focused, xkl_get_debug_window_title(focused));
have_toplevel_win =
- xkl_toplevel_window_find(focused, &xkl_current_client);
+ xkl_engine_find_toplevel_window(engine, focused,
+ &engine->priv->
+ curr_toplvl_win);
if (have_toplevel_win) {
gboolean have_state =
- xkl_toplevel_window_get_state(xkl_current_client,
- &xkl_current_state);
+ xkl_engine_get_toplevel_window_state(engine,
+ engine->priv->
+ curr_toplvl_win,
+ &engine->priv->
+ curr_state);
xkl_debug(160,
- "initial xkl_cur_client: " WINID_FORMAT
- ", '%s' %s state %d/%X\n", xkl_current_client,
- xkl_window_get_debug_title(xkl_current_client),
+ "initial toplevel: " WINID_FORMAT
+ ", '%s' %s state %d/%X\n",
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win),
(have_state ? "with" : "without"),
- (have_state ? xkl_current_state.group : -1),
- (have_state ? xkl_current_state.
+ (have_state ? engine->priv->curr_state.
+ group : -1),
+ (have_state ? engine->priv->curr_state.
indicators : -1));
} else {
xkl_debug(160,
@@ -470,68 +448,77 @@ xkl_default_log_appender(const gchar file[], const gchar function[],
* Just selects some events from the window.
*/
void
-xkl_select_input(Window win, gulong mask)
+xkl_engine_select_input(XklEngine * engine, Window win, gulong mask)
{
- if (xkl_root_window == win)
+ if (engine->priv->root_window == win)
xkl_debug(160,
"Someone is looking for %lx on root window ***\n",
mask);
- XSelectInput(xkl_display, win, mask);
+ XSelectInput(xkl_engine_get_display(engine), win, mask);
}
void
-xkl_select_input_merging(Window win, gulong mask)
+xkl_engine_select_input_merging(XklEngine * engine, Window win,
+ gulong mask)
{
XWindowAttributes attrs;
gulong oldmask = 0L, newmask;
memset(&attrs, 0, sizeof(attrs));
- if (XGetWindowAttributes(xkl_display, win, &attrs))
+ if (XGetWindowAttributes
+ (xkl_engine_get_display(engine), win, &attrs))
oldmask = attrs.your_event_mask;
newmask = oldmask | mask;
if (newmask != oldmask)
- xkl_select_input(win, newmask);
+ xkl_engine_select_input(engine, win, newmask);
}
void
-xkl_try_call_state_func(XklStateChange change_type, XklState * old_state)
+xkl_engine_try_call_state_func(XklEngine * engine,
+ XklStateChange change_type,
+ XklState * old_state)
{
- gint group = xkl_current_state.group;
+ gint group = engine->priv->curr_state.group;
gboolean restore = old_state->group == group;
xkl_debug(150,
"change_type: %d, group: %d, secondary_group_mask: %X, allowsecondary: %d\n",
- change_type, group, xkl_secondary_groups_mask,
- xkl_is_one_switch_to_secondary_group_allowed());
+ change_type, group, engine->priv->secondary_groups_mask,
+ xkl_engine_is_one_switch_to_secondary_group_allowed
+ (engine));
if (change_type == GROUP_CHANGED) {
if (!restore) {
- if ((xkl_secondary_groups_mask & (1 << group)) != 0
+ if ((engine->priv->
+ secondary_groups_mask & (1 << group)) != 0
&&
- !xkl_is_one_switch_to_secondary_group_allowed
- ()) {
+ !xkl_engine_is_one_switch_to_secondary_group_allowed
+ (engine)) {
xkl_debug(150, "secondary -> go next\n");
- group = xkl_group_get_next();
- xkl_group_lock(group);
+ group = xkl_engine_get_next_group(engine);
+ xkl_engine_lock_group(engine, group);
return; /* we do not need to revalidate */
}
}
- xkl_one_switch_to_secondary_group_performed();
+ xkl_engine_one_switch_to_secondary_group_performed(engine);
}
+// TODO
+#if 0
if (xkl_state_callback != NULL) {
(*xkl_state_callback) (change_type,
- xkl_current_state.group, restore,
+ xkl_curr_state.group, restore,
xkl_state_callback_data);
}
+#endif
}
void
-xkl_ensure_vtable_inited(void)
+xkl_engine_ensure_vtable_inited(XklEngine * engine)
{
char *p;
- if (xkl_vtable == NULL) {
+ if (engine->priv->backend_id == NULL) {
xkl_debug(0, "ERROR: XKL VTable is NOT initialized.\n");
/* force the crash! */
p = NULL;
@@ -540,26 +527,27 @@ xkl_ensure_vtable_inited(void)
}
const gchar *
-xkl_backend_get_name(void)
+xkl_engine_get_backend_name(XklEngine * engine)
{
- return xkl_vtable->id;
+ return engine->priv->backend_id;
}
guint
-xkl_backend_get_features(void)
+xkl_engine_get_features(XklEngine * engine)
{
- return xkl_vtable->features;
+ return engine->priv->features;
}
void
-xkl_reset_all_info(const gchar reason[])
+xkl_engine_reset_all_info(XklEngine * engine, const gchar reason[])
{
xkl_debug(150, "Resetting all the cached info, reason: [%s]\n",
reason);
- xkl_ensure_vtable_inited();
- if (!(*xkl_vtable->if_cached_info_equals_actual_func) ()) {
- (*xkl_vtable->free_all_info_func) ();
- (*xkl_vtable->load_all_info_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ if (!xkl_engine_vcall(engine, if_cached_info_equals_actual)
+ ()) {
+ xkl_engine_vcall(engine, free_all_info) ();
+ xkl_engine_vcall(engine, load_all_info) ();
} else
xkl_debug(100,
"NOT Resetting the cache: same configuration\n");
@@ -569,66 +557,75 @@ xkl_reset_all_info(const gchar reason[])
* Calling through vtable
*/
const gchar **
-xkl_groups_get_names(void)
+xkl_engine_groups_get_names(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->groups_get_names_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ return (*engine->priv->get_groups_names) ();
}
guint
-xkl_groups_get_num(void)
+xkl_engine_get_num_groups(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->groups_get_num_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ return (*engine->priv->get_num_groups) ();
}
void
-xkl_group_lock(int group)
+xkl_engine_group_lock(XklEngine * engine, int group)
{
- xkl_ensure_vtable_inited();
- (*xkl_vtable->group_lock_func) (group);
+ xkl_engine_ensure_vtable_inited(engine);
+ xkl_engine_vcall(engine, lock_group) (group);
}
gint
-xkl_listen_pause(void)
+xkl_engine_pause_listen(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->listen_pause_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ return xkl_engine_vcall(engine, pause_listen) ();
}
gint
-xkl_listen_resume(void)
+xkl_engine_resume_listen(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- xkl_debug(150, "listenerType: %x\n", xkl_listener_type);
- if ((*xkl_vtable->listen_resume_func) ())
+ xkl_engine_ensure_vtable_inited(engine);
+ xkl_debug(150, "listenerType: %x\n", engine->priv->listener_type);
+ if (xkl_engine_vcall(engine, resume_listen) ())
return 1;
- xkl_select_input_merging(xkl_root_window,
- SubstructureNotifyMask |
- PropertyChangeMask);
- xkl_ensure_vtable_inited();
- (*xkl_vtable->get_server_state_func) (&xkl_current_state);
+ xkl_engine_select_input_merging(engine, engine->priv->root_window,
+ SubstructureNotifyMask |
+ PropertyChangeMask);
+
+// TODO
+#if 0
+ (*xkl_vtable->get_server_state_func) (&xkl_curr_state);
+#endif
return 0;
}
gboolean
-xkl_load_all_info(void)
+xkl_engine_load_all_info(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->load_all_info_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ return xkl_engine_vcall(engine, load_all_info) ();
}
void
-xkl_free_all_info(void)
+xkl_engine_free_all_info(XklEngine * engine)
{
- xkl_ensure_vtable_inited();
- (*xkl_vtable->free_all_info_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ xkl_engine_vcall(engine, free_all_info) ();
}
guint
-xkl_groups_get_max_num(void)
+xkl_engine_get_max_num_groups(XklEngine * engine)
+{
+ xkl_engine_ensure_vtable_inited(engine);
+ return (*engine->priv->get_max_num_groups) ();
+}
+
+XklEngine *
+xkl_get_the_engine()
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->groups_get_max_num_func) ();
+ return the_engine;
}
diff --git a/libxklavier/xklavier.h b/libxklavier/xklavier.h
index a9f0459..90af274 100644
--- a/libxklavier/xklavier.h
+++ b/libxklavier/xklavier.h
@@ -9,12 +9,28 @@
#include <X11/Xlib.h>
-#include <glib.h>
+#include <glib-object.h>
#ifdef __cplusplus
extern "C" {
#endif
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+ 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_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 (G_TYPE_INSTANCE_GET_CLASS ((obj), XKL_TYPE_ENGINE, XklEngineClass))
+
+#endif // DOXYGEN_SHOULD_SKIP_THIS
+
+
typedef enum {
/**
* Group was changed
@@ -64,37 +80,83 @@ extern "C" {
} XklState;
/**
- * @defgroup xklinitterm Library initialization and termination
- * @{
+ * The main Xklavier engine class
+ */
+ struct _XklEngine {
+/**
+ * The superclass object
+ */
+ GObject parent;
+/**
+ * Private data
*/
+ XklEnginePrivate *priv;
+ };
/**
- * Initializes internal structures. Does not start actual listening though.
- * Some apps can use xkl_avier for information retrieval but not for actual
- * processing.
- * @param dpy is an open display, will be tested for XKB extension
- * @return 0 if OK, otherwise last X error
- * (special case: -1 if XKB extension is not present)
+ * The XklEngine class, derived from GObject
*/
- extern gint xkl_init(Display * dpy);
+ struct _XklEngineClass {
+/**
+ * The superclass
+ */
+ GObjectClass parent_class;
+
+/**
+ * Used for notifying application of the XKB configuration change.
+ */
+ void (*config_notify) (XklEngine * engine);
+
+/**
+ * Used for notifying application of new window creation (actually,
+ * registration).
+ * @param win is a new window
+ * @param parent is a new window's parent
+ * @return the initial group id for the window (-1 to use the default value)
+ */
+ gint(*new_window_notify) (XklEngine * engine, Window win,
+ Window parent);
+/**
+ * Used for notifying application of the window state change.
+ * @param changeType is a mask of changes
+ * @param group is a new group
+ * @param restore is indicator of whether this state is restored from
+ * saved state of set as new.
+ */
+ void (*state_notify) (XklEngine * engine,
+ XklStateChange changeType,
+ gint group, gboolean restore);
+
+ };
+
+
+/**
+ * Get type info for XklEngine
+ * @return GType for XklEngine
+ */
+ extern GType xkl_engine_get_type(void);
+
/**
- * Terminates everything...
+ * Get the instance of the XklEngine. Within a process, there is always once instance
+ * @return the singleton instance
*/
- extern gint xkl_term(void);
+ extern XklEngine *xkl_engine_get_instance(Display * display);
+
/**
* What kind of backend if used
* @return some string id of the backend
*/
- extern const gchar *xkl_backend_get_name(void);
+ extern const gchar *xkl_engine_get_backend_name(XklEngine *
+ engine);
/**
* Provides information regarding available backend features
* (combination of XKLF_* constants)
* @return ORed XKLF_* constants
*/
- extern guint xkl_backend_get_features(void);
+ extern guint xkl_engine_get_features(XklEngine * engine);
/**
* Provides the information on maximum number of simultaneously supported
@@ -102,8 +164,7 @@ extern "C" {
* @return maximum number of the groups in configuration,
* 0 if no restrictions.
*/
- extern unsigned xkl_groups_get_max_num(void);
-/** @} */
+ extern unsigned xkl_engine_get_max_num_groups(XklEngine * engine);
/**
* @defgroup xkbevents XKB event handling and management
@@ -132,25 +193,26 @@ extern "C" {
* @param what any combination of XKLL_* constants
* @return 0
*/
- extern gint xkl_listen_start(guint what);
+ extern gint xkl_engine_start_listen(XklEngine * engine,
+ guint what);
/**
* Stops listening for XKB-related events
* @return 0
*/
- extern gint xkl_listen_stop(void);
+ extern gint xkl_engine_stop_listen(XklEngine * engine);
/**
* Temporary pauses listening for XKB-related events
* @return 0
*/
- extern gint xkl_listen_pause(void);
+ extern gint xkl_engine_pause_listen(XklEngine * engine);
/**
* Resumes listening for XKB-related events
* @return 0
*/
- extern gint xkl_listen_resume(void);
+ extern gint xkl_engine_resume_listen(XklEngine * engine);
/**
* Grabs some key
@@ -158,7 +220,9 @@ extern "C" {
* @param modifiers is a bitmask of modifiers
* @return True on success
*/
- extern gboolean xkl_key_grab(gint keycode, unsigned modifiers);
+ extern gboolean xkl_engine_grab_key(XklEngine * engine,
+ gint keycode,
+ unsigned modifiers);
/**
* Ungrabs some key
@@ -166,7 +230,9 @@ extern "C" {
* @param modifiers is a bitmask of modifiers
* @return True on success
*/
- extern gboolean xkl_key_ungrab(gint keycode, unsigned modifiers);
+ extern gboolean xkl_engine_key_ungrab(XklEngine * engine,
+ gint keycode,
+ unsigned modifiers);
/**
* Processes X events. Should be included into the main event cycle of an
@@ -175,12 +241,15 @@ extern "C" {
* @return 0 if the event it processed - 1 otherwise
* @see xkl_StartListen
*/
- extern gint xkl_events_filter(XEvent * evt);
+ extern gint xkl_engine_events_filter(XklEngine * engine,
+ XEvent * evt);
/**
* Allows to switch (once) to the secondary group
*/
- extern void xkl_group_allow_one_switch_to_secondary(void);
+ extern void
+ xkl_engine_allow_one_switch_to_secondary_group(XklEngine *
+ engine);
/** @} */
@@ -192,13 +261,13 @@ extern "C" {
/**
* @return currently focused window
*/
- extern Window xkl_window_get_current(void);
+ extern Window xkl_engine_get_current_window(XklEngine * engine);
/**
* @return current state of the keyboard (in XKB terms).
* Returned value is a statically allocated buffer, should not be freed.
*/
- extern XklState *xkl_state_get_current(void);
+ extern XklState *xkl_engine_get_current_state(XklEngine * engine);
/** @} */
@@ -211,7 +280,7 @@ extern "C" {
* @return the window title of some window or NULL.
* If not NULL, it should be freed with XFree
*/
- extern gchar *xkl_window_get_title(Window w);
+ extern gchar *xkl_get_window_title(Window w);
/**
* Finds the state for a given window (for its "App window").
@@ -220,20 +289,24 @@ extern "C" {
* @return True on success, otherwise False
* (the error message can be obtained using xkl_GetLastError).
*/
- extern gboolean xkl_state_get(Window win, XklState * state_out);
+ extern gboolean xkl_engine_get_state(XklEngine * engine,
+ Window win,
+ XklState * state_out);
/**
* Drops the state of a given window (of its "App window").
* @param win is a target window
*/
- extern void xkl_state_delete(Window win);
+ extern void xkl_engine_delete_state(XklEngine * engine,
+ Window win);
/**
* Stores ths state for a given window
* @param win is a target window
* @param state is a new state of the window
*/
- extern void xkl_state_save(Window win, XklState * state);
+ extern void xkl_engine_save_state(XklEngine * engine, Window win,
+ XklState * state);
/**
* Sets the "transparent" flag. It means focus switching onto
@@ -242,15 +315,19 @@ extern "C" {
* @param transparent - if true, the windows is transparent.
* @see xkl_IsTranspatent
*/
- extern void xkl_window_set_transparent(Window win,
- gboolean transparent);
+ extern void xkl_engine_set_window_transparent(XklEngine * engine,
+ Window win,
+ gboolean
+ transparent);
/**
* Returns "transparent" flag.
* @param win is the window to get the transparent flag from.
* @see xkl_SetTranspatent
*/
- extern gboolean xkl_window_is_transparent(Window win);
+ extern gboolean xkl_engine_is_window_transparent(XklEngine *
+ engine,
+ Window win);
/**
* Checks whether 2 windows have the same topmost window
@@ -258,8 +335,8 @@ extern "C" {
* @param win2 is second window
* @return True is windows are in the same application
*/
- extern gboolean xkl_windows_is_same_appication(Window win1,
- Window win2);
+ extern gboolean xkl_windows_from_same_toplevel_window(Window win1,
+ Window win2);
/** @} */
@@ -272,21 +349,23 @@ extern "C" {
* @return the total number of groups in the current XKB configuration
* (keyboard)
*/
- extern unsigned xkl_groups_get_num(void);
+ extern unsigned xkl_engine_get_num_groups(XklEngine * engine);
/**
* @return the array of group names for the current XKB configuration
* (keyboard).
* This array is static, should not be freed
*/
- extern const gchar **xkl_groups_get_names(void);
+ extern const gchar **xkl_engine_get_groups_names(XklEngine *
+ engine);
/**
* @return the array of indicator names for the current XKB configuration
* (keyboard).
* This array is static, should not be freed
*/
- extern const gchar **xkl_indicators_get_names(void);
+ extern const gchar **xkl_engine_get_indicators_names(XklEngine *
+ engine);
/** @} */
@@ -299,19 +378,20 @@ extern "C" {
* Calculates next group id. Does not change the state of anything.
* @return next group id
*/
- extern gint xkl_group_get_next(void);
+ extern gint xkl_engine_get_next_group(XklEngine * engine);
/**
* Calculates prev group id. Does not change the state of anything.
* @return prev group id
*/
- extern gint xkl_group_get_prev(void);
+ extern gint xkl_engine_get_prev_group(XklEngine * engine);
/**
- * @return saved group id of the current client.
+ * @return saved group id of the current window.
* Does not change the state of anything.
*/
- extern gint xkl_group_get_restore(void);
+ extern gint xkl_engine_get_current_window_group(XklEngine *
+ engine);
/**
* Locks the group. Can be used after xkl_GetXXXGroup functions
@@ -320,75 +400,7 @@ extern "C" {
* @see xkl_GetPrevGroup
* @see xkl_GetRestoreGroup
*/
- extern void xkl_group_lock(gint group);
-
-/** @} */
-
-/**
- * @defgroup callbacks Application callbacks support
- * @{
- */
-
-/**
- * Used for notifying application of the XKB configuration change.
- * @param data is anything which can be stored into the pointer
- * @see xkl_RegisterConfigCallback
- */
- typedef void (*XklConfigNotifyFunc) (gpointer data);
-
-/**
- * Registers user callback. Only one callback can be registered at a time
- * @param func is the function to call
- * @param data is the data to pass
- * @see xkl_ConfigCallback
- */
- extern gint xkl_register_config_callback(XklConfigNotifyFunc func,
- gpointer data);
-
-/**
- * Used for notifying application of new window creation (actually,
- * registration).
- * @param win is a new window
- * @param parent is a new window's parent
- * @param data is anything which can be stored into the pointer
- * @return the initial group id for the window (-1 to use the default value)
- * @see xkl_register_config_callback
- * @see xkl_set_default_group
- * @see xkl_get_default_group
- */
- typedef gint(*XklNewWindowNotifyFunc) (Window win, Window parent,
- gpointer data);
-
-/**
- * Registers user callback. Only one callback can be registered at a time
- * @param func is the function to call
- * @param data is the data to pass
- * @see XklWindowCallback
- */
- extern gint xkl_register_new_window_callback(XklNewWindowNotifyFunc
- func, gpointer data);
-
-/**
- * Used for notifying application of the window state change.
- * @param changeType is a mask of changes
- * @param group is a new group
- * @param restore is indicator of whether this state is restored from
- * saved state of set as new.
- * @param data is anything which can be stored into the pointer
- * @see xkl_register_config_callback
- */
- typedef void (*XklStateNotifyFunc) (XklStateChange changeType,
- gint group, gboolean restore,
- gpointer data);
-
-/**
- * Registers user callback. Only one callback can be registered at a time
- * @param func is the function to call
- * @param data is the data to pass
- * @see XklStateNotifyFunc
- */
- extern gint xkl_register_state_callback(XklStateNotifyFunc func,
- gpointer data);
+ extern void xkl_engine_lock_group(XklEngine * engine, gint group);
/** @} */
@@ -401,23 +413,30 @@ extern "C" {
* Sets the configuration parameter: group per application
* @param isGlobal is a new parameter value
*/
- extern void xkl_set_group_per_toplevel_window(gboolean isGlobal);
+ extern void xkl_engine_set_group_per_toplevel_window(XklEngine *
+ engine,
+ gboolean
+ isGlobal);
/**
* @return the value of the parameter: group per application
*/
- extern gboolean xkl_is_group_per_toplevel_window(void);
+ extern gboolean xkl_engine_is_group_per_toplevel_window(XklEngine *
+ engine);
/**
* Sets the configuration parameter: perform indicators handling
* @param whetherHandle is a new parameter value
*/
- extern void xkl_set_indicators_handling(gboolean whetherHandle);
+ extern void xkl_engine_set_indicators_handling(XklEngine * engine,
+ gboolean
+ whetherHandle);
/**
* @return the value of the parameter: perform indicator handling
*/
- extern gboolean xkl_get_indicators_handling(void);
+ extern gboolean xkl_engine_get_indicators_handling(XklEngine *
+ engine);
/**
* Sets the secondary groups (one bit per group).
@@ -425,26 +444,30 @@ extern "C" {
* @param mask is a new group mask
* @see xkl_allow_one_switch_to_secondary_group
*/
- extern void xkl_set_secondary_groups_mask(guint mask);
+ extern void xkl_engine_set_secondary_groups_mask(XklEngine *
+ engine,
+ guint mask);
/**
* @return the secondary group mask
*/
- extern guint xkl_get_secondary_groups_mask(void);
+ extern guint xkl_engine_get_secondary_groups_mask(XklEngine *
+ engine);
/**
* Configures the default group set on window creation.
* If -1, no default group is used
* @param group the default group
*/
- extern void xkl_group_set_default(gint group);
+ extern void xkl_engine_group_set_default(XklEngine * engine,
+ gint group);
/**
* Returns the default group set on window creation
* If -1, no default group is used
* @return the default group
*/
- extern gint xkl_group_get_default(void);
+ extern gint xkl_engine_group_get_default(XklEngine * engine);
/** @} */
@@ -456,7 +479,7 @@ extern "C" {
/**
* @return the text message (statically allocated) of the last error
*/
- extern const gchar *xkl_get_last_error(void);
+ extern const gchar *xkl_engine_get_last_error(XklEngine * engine);
/**
* Output (optionally) some debug info
diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c
index 49691c2..30ffcee 100644
--- a/libxklavier/xklavier_config.c
+++ b/libxklavier/xklavier_config.c
@@ -24,6 +24,8 @@ static xmlXPathCompExprPtr option_groups_xpath;
#define xkl_config_registry_is_initialized() \
( the_registry.xpath_context != NULL )
+static XklEngine *engine = NULL;
+
static xmlChar *
xkl_node_get_xml_lang_attr(xmlNodePtr nptr)
{
@@ -290,14 +292,15 @@ xkl_strings_split_comma_separated(gchar *** array, const gchar * merged)
}
gchar *
-xkl_rules_set_get_name(const gchar default_ruleset[])
+xkl_engine_get_ruleset_name(XklEngine * engine,
+ const gchar default_ruleset[])
{
static gchar rules_set_name[1024] = "";
if (!rules_set_name[0]) {
/* first call */
gchar *rf = NULL;
if (!xkl_get_names_prop
- (xkl_vtable->base_config_atom, &rf, NULL)
+ (engine->priv->base_config_atom, &rf, NULL)
|| (rf == NULL)) {
g_strlcpy(rules_set_name, default_ruleset,
sizeof rules_set_name);
@@ -313,7 +316,7 @@ xkl_rules_set_get_name(const gchar default_ruleset[])
}
void
-xkl_config_init(void)
+xkl_config_init(XklEngine * engine)
{
xmlXPathInit();
models_xpath = xmlXPathCompile((unsigned char *)
@@ -324,8 +327,8 @@ xkl_config_init(void)
"/xkbConfigRegistry/optionList/group");
xkl_i18n_init();
- xkl_ensure_vtable_inited();
- (*xkl_vtable->config_init_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ xkl_engine_vcall(engine, init_config) ();
}
void
@@ -351,7 +354,7 @@ xkl_config_registry_load_from_file(const gchar * file_name)
the_registry.doc = xmlParseFile(file_name);
if (the_registry.doc == NULL) {
the_registry.xpath_context = NULL;
- xkl_last_error_message =
+ engine->priv->last_error_message =
"Could not parse XKB configuration registry";
} else
the_registry.xpath_context =
@@ -512,15 +515,15 @@ xkl_config_find_option(const char *option_group_name,
gboolean
xkl_config_activate(const XklConfigRec * data)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->config_activate_func) (data);
+ xkl_engine_ensure_vtable_inited(engine);
+ return xkl_engine_vcall(engine, activate_config) (data);
}
gboolean
xkl_config_registry_load(void)
{
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->config_registry_load_func) ();
+ xkl_engine_ensure_vtable_inited(engine);
+ return xkl_engine_vcall(engine, load_config_registry) ();
}
gboolean
@@ -528,16 +531,18 @@ xkl_config_write_file(const gchar * file_name,
const XklConfigRec * data, const gboolean binary)
{
if ((!binary &&
- !(xkl_vtable->features & XKLF_CAN_OUTPUT_CONFIG_AS_ASCII)) ||
- (binary &&
- !(xkl_vtable->features & XKLF_CAN_OUTPUT_CONFIG_AS_BINARY))) {
- xkl_last_error_message =
+ !(engine->priv->features & XKLF_CAN_OUTPUT_CONFIG_AS_ASCII))
+ || (binary
+ && !(engine->priv->
+ features & XKLF_CAN_OUTPUT_CONFIG_AS_BINARY))) {
+ engine->priv->last_error_message =
"Function not supported at backend";
return FALSE;
}
- xkl_ensure_vtable_inited();
- return (*xkl_vtable->config_write_file_func) (file_name, data,
- binary);
+ xkl_engine_ensure_vtable_inited(engine);
+ return xkl_engine_vcall(engine, write_config_to_file) (file_name,
+ data,
+ binary);
}
void
diff --git a/libxklavier/xklavier_config.h b/libxklavier/xklavier_config.h
index 6b4d5e5..645f86e 100644
--- a/libxklavier/xklavier_config.h
+++ b/libxklavier/xklavier_config.h
@@ -88,8 +88,8 @@ extern "C" {
GObjectClass parent_class;
};
/**
- * Get type info for XConfigItem
- * @return GType for XConfigItem
+ * Get type info for XklConfigItem
+ * @return GType for XklConfigItem
*/
extern GType xkl_config_item_get_type(void);
@@ -155,7 +155,7 @@ extern "C" {
/**
* Initializes XML configuration-related structures
*/
- extern void xkl_config_init(void);
+ extern void xkl_config_init(XklEngine * engine);
/**
* Cleans XML configuration-related structures
diff --git a/libxklavier/xklavier_evt.c b/libxklavier/xklavier_evt.c
index 8e5540e..a6238fa 100644
--- a/libxklavier/xklavier_evt.c
+++ b/libxklavier/xklavier_evt.c
@@ -8,26 +8,31 @@
#include "xklavier_private.h"
gint
-xkl_events_filter(XEvent * xev)
+xkl_engine_events_filter(XklEngine * engine, XEvent * xev)
{
XAnyEvent *pe = (XAnyEvent *) xev;
xkl_debug(400,
"**> Filtering event %d of type %d from window %d\n",
pe->serial, pe->type, pe->window);
- xkl_ensure_vtable_inited();
- if (!xkl_vtable->process_x_event_func(xev))
+ xkl_engine_ensure_vtable_inited(engine);
+ if (!xkl_engine_vcall(engine, process_x_event) (xev))
switch (xev->type) { /* core events */
case FocusIn:
- xkl_process_focus_in_evt(&xev->xfocus);
+ xkl_engine_process_focus_in_evt(engine,
+ &xev->xfocus);
break;
case FocusOut:
- xkl_process_focus_out_evt(&xev->xfocus);
+ xkl_engine_process_focus_out_evt(engine,
+ &xev->xfocus);
break;
case PropertyNotify:
- xkl_process_property_evt(&xev->xproperty);
+ xkl_engine_process_property_evt(engine,
+ &xev->xproperty);
break;
case CreateNotify:
- xkl_process_create_window_evt(&xev->xcreatewindow);
+ xkl_engine_process_create_window_evt(engine,
+ &xev->
+ xcreatewindow);
break;
case DestroyNotify:
xkl_debug(150,
@@ -44,7 +49,8 @@ xkl_events_filter(XEvent * xev)
case MappingNotify:
xkl_debug(200, "%s\n",
xkl_event_get_name(xev->type));
- xkl_reset_all_info("X event: MappingNotify");
+ xkl_engine_reset_all_info(engine,
+ "X event: MappingNotify");
break;
default:
{
@@ -63,13 +69,14 @@ xkl_events_filter(XEvent * xev)
* FocusIn handler
*/
void
-xkl_process_focus_in_evt(XFocusChangeEvent * fev)
+xkl_engine_process_focus_in_evt(XklEngine * engine,
+ XFocusChangeEvent * fev)
{
Window win;
Window toplevel_win;
XklState selected_window_state;
- if (!(xkl_listener_type & XKLL_MANAGE_WINDOW_STATES))
+ if (!(engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES))
return;
win = fev->window;
@@ -87,23 +94,24 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
}
xkl_debug(150, "Window " WINID_FORMAT ", '%s' has got focus\n",
- win, xkl_window_get_debug_title(win));
+ win, xkl_get_debug_window_title(win));
- if (!xkl_toplevel_window_find(win, &toplevel_win)) {
+ if (!xkl_engine_find_toplevel_window(engine, win, &toplevel_win)) {
return;
}
xkl_debug(150, "Appwin " WINID_FORMAT ", '%s' has got focus\n",
- toplevel_win, xkl_window_get_debug_title(toplevel_win));
+ toplevel_win, xkl_get_debug_window_title(toplevel_win));
- if (xkl_state_get(toplevel_win, &selected_window_state)) {
- if (xkl_current_client != toplevel_win) {
+ if (xkl_engine_get_toplevel_window_state
+ (engine, toplevel_win, &selected_window_state)) {
+ if (engine->priv->curr_toplvl_win != toplevel_win) {
gboolean old_win_transparent, new_win_transparent;
XklState tmp_state;
old_win_transparent =
- xkl_toplevel_window_is_transparent
- (xkl_current_client);
+ xkl_engine_is_toplevel_window_transparent
+ (engine, engine->priv->curr_toplvl_win);
if (old_win_transparent)
xkl_debug(150,
"Leaving transparent window\n");
@@ -114,36 +122,44 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
* the _previous_ window.
*/
if (!old_win_transparent &&
- xkl_state_get(xkl_current_client, &tmp_state))
+ xkl_engine_get_toplevel_window_state(engine,
+ engine->
+ priv->
+ curr_toplvl_win,
+ &tmp_state))
{
- xkl_current_state_update(tmp_state.group,
- tmp_state.
- indicators,
- "Loading current (previous) state from the current (previous) window");
+ xkl_engine_update_current_state(engine,
+ tmp_state.
+ group,
+ tmp_state.
+ indicators,
+ "Loading current (previous) state from the current (previous) window");
}
- xkl_current_client = toplevel_win;
+ engine->priv->curr_toplvl_win = toplevel_win;
xkl_debug(150,
"CurClient:changed to " WINID_FORMAT
- ", '%s'\n", xkl_current_client,
- xkl_window_get_debug_title
- (xkl_current_client));
+ ", '%s'\n",
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win));
new_win_transparent =
- xkl_toplevel_window_is_transparent
- (toplevel_win);
+ xkl_engine_is_toplevel_window_transparent
+ (engine, toplevel_win);
if (new_win_transparent)
xkl_debug(150,
"Entering transparent window\n");
- if (xkl_is_group_per_toplevel_window() ==
- !new_win_transparent) {
+ if (xkl_engine_is_group_per_toplevel_window(engine)
+ == !new_win_transparent) {
/* We skip restoration only if we return to the same app window */
gboolean do_skip = FALSE;
- if (xkl_skip_one_restore) {
- xkl_skip_one_restore = FALSE;
+ if (engine->priv->skip_one_restore) {
+ engine->priv->skip_one_restore =
+ FALSE;
if (toplevel_win ==
- xkl_toplevel_window_prev)
+ engine->priv->prev_toplvl_win)
do_skip = TRUE;
}
@@ -151,16 +167,17 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
xkl_debug(150,
"Skipping one restore as requested - instead, "
"saving the current group into the window state\n");
- xkl_toplevel_window_save_state
- (toplevel_win,
- &xkl_current_state);
+ xkl_engine_save_toplevel_window_state
+ (engine, toplevel_win,
+ &engine->priv->curr_state);
} else {
- if (xkl_current_state.group !=
+ if (engine->priv->curr_state.
+ group !=
selected_window_state.group) {
xkl_debug(150,
"Restoring the group from %d to %d after gaining focus\n",
- xkl_current_state.
- group,
+ engine->priv->
+ curr_state.group,
selected_window_state.
group);
/**
@@ -168,14 +185,16 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
* (because of the group change notification being late).
* so we'll enforce the update. But this should only happen in GPA mode
*/
- xkl_current_state_update
- (selected_window_state.
+ xkl_engine_update_current_state
+ (engine,
+ selected_window_state.
group,
selected_window_state.
indicators,
"Enforcing fast update of the current state");
- xkl_group_lock
- (selected_window_state.
+ xkl_engine_lock_group
+ (engine,
+ selected_window_state.
group);
} else {
xkl_debug(150,
@@ -183,33 +202,36 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
"have group %d so no point restoring it\n",
selected_window_state.
group);
- xkl_one_switch_to_secondary_group_performed
- ();
+ xkl_engine_one_switch_to_secondary_group_performed
+ (engine);
}
}
- if ((xkl_vtable->
+ if ((engine->priv->
features & XKLF_CAN_TOGGLE_INDICATORS)
- && xkl_get_indicators_handling()) {
+ &&
+ xkl_engine_get_indicators_handling
+ (engine)) {
xkl_debug(150,
"Restoring the indicators from %X to %X after gaining focus\n",
- xkl_current_state.
+ engine->priv->curr_state.
indicators,
selected_window_state.
indicators);
- xkl_ensure_vtable_inited();
- (*xkl_vtable->
- indicators_set_func)
- (&selected_window_state);
+ xkl_engine_ensure_vtable_inited
+ (engine);
+ xkl_engine_vcall(engine,
+ set_indicators)
+ (&selected_window_state);
} else
xkl_debug(150,
"Not restoring the indicators %X after gaining focus: indicator handling is not enabled\n",
- xkl_current_state.
+ engine->priv->curr_state.
indicators);
} else
xkl_debug(150,
"Not restoring the group %d after gaining focus: global layout (xor transparent window)\n",
- xkl_current_state.group);
+ engine->priv->curr_state.group);
} else
xkl_debug(150,
"Same app window - just do nothing\n");
@@ -218,15 +240,20 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
if (xkl_window_has_wm_state(win)) {
xkl_debug(150,
"But it does have wm_state so we'll add it\n");
- xkl_current_client = toplevel_win;
+ engine->priv->curr_toplvl_win = toplevel_win;
xkl_debug(150,
"CurClient:changed to " WINID_FORMAT
- ", '%s'\n", xkl_current_client,
- xkl_window_get_debug_title
- (xkl_current_client));
- xkl_toplevel_window_add(xkl_current_client,
- (Window) NULL, FALSE,
- &xkl_current_state);
+ ", '%s'\n",
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win));
+ xkl_engine_add_toplevel_window(engine,
+ engine->priv->
+ curr_toplvl_win,
+ (Window) NULL,
+ FALSE,
+ &engine->priv->
+ curr_state);
} else
xkl_debug(150,
"And it does have wm_state either\n");
@@ -237,9 +264,10 @@ xkl_process_focus_in_evt(XFocusChangeEvent * fev)
* FocusOut handler
*/
void
-xkl_process_focus_out_evt(XFocusChangeEvent * fev)
+xkl_engine_process_focus_out_evt(XklEngine * engine,
+ XFocusChangeEvent * fev)
{
- if (!(xkl_listener_type & XKLL_MANAGE_WINDOW_STATES))
+ if (!(engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES))
return;
if (fev->mode != NotifyNormal) {
@@ -251,20 +279,21 @@ xkl_process_focus_out_evt(XFocusChangeEvent * fev)
}
xkl_debug(160, "Window " WINID_FORMAT ", '%s' has lost focus\n",
- fev->window, xkl_window_get_debug_title(fev->window));
+ fev->window, xkl_get_debug_window_title(fev->window));
- if (xkl_window_is_transparent(fev->window)) {
+ if (xkl_engine_is_window_transparent(engine, fev->window)) {
xkl_debug(150, "Leaving transparent window!\n");
/**
* If we are leaving the transparent window - we skip the restore operation.
* This is useful for secondary groups switching from the transparent control
* window.
*/
- xkl_skip_one_restore = TRUE;
+ engine->priv->skip_one_restore = TRUE;
} else {
Window p;
- if (xkl_toplevel_window_find(fev->window, &p))
- xkl_toplevel_window_prev = p;
+ if (xkl_engine_find_toplevel_window
+ (engine, fev->window, &p))
+ engine->priv->prev_toplvl_win = p;
}
}
@@ -276,10 +305,12 @@ xkl_process_focus_out_evt(XFocusChangeEvent * fev)
* - Configuration property of the root window
*/
void
-xkl_process_property_evt(XPropertyEvent * pev)
+xkl_engine_process_property_evt(XklEngine * engine, XPropertyEvent * pev)
{
if (400 <= xkl_debug_level) {
- char *atom_name = XGetAtomName(xkl_display, pev->atom);
+ char *atom_name =
+ XGetAtomName(xkl_engine_get_display(engine),
+ pev->atom);
if (atom_name != NULL) {
xkl_debug(400,
"The property '%s' changed for "
@@ -293,41 +324,45 @@ xkl_process_property_evt(XPropertyEvent * pev)
}
}
- if (xkl_listener_type & XKLL_MANAGE_WINDOW_STATES) {
- if (pev->atom == xkl_atoms[WM_STATE]) {
+ if (engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES) {
+ if (pev->atom == engine->priv->atoms[WM_STATE]) {
gboolean has_xkl_state =
- xkl_state_get(pev->window, NULL);
+ xkl_engine_get_state(engine, pev->window,
+ NULL);
if (pev->state == PropertyNewValue) {
xkl_debug(160,
"New value of WM_STATE on window "
WINID_FORMAT "\n", pev->window);
if (!has_xkl_state) { /* Is this event the first or not? */
- xkl_toplevel_window_add(pev->
- window,
- (Window)
- NULL,
- FALSE,
- &xkl_current_state);
+ xkl_engine_add_toplevel_window
+ (engine, pev->window, (Window)
+ NULL, FALSE,
+ &engine->priv->curr_state);
}
} else { /* ev->xproperty.state == PropertyDelete, either client or WM can remove it, ICCCM 4.1.3.1 */
xkl_debug(160,
"Something (%d) happened to WM_STATE of window 0x%x\n",
pev->state, pev->window);
- xkl_select_input_merging(pev->window,
- PropertyChangeMask);
+ xkl_engine_select_input_merging(engine,
+ pev->
+ window,
+ PropertyChangeMask);
if (has_xkl_state) {
- xkl_state_delete(pev->window);
+ xkl_engine_delete_state(engine,
+ pev->
+ window);
}
}
} else
- if (pev->atom == xkl_vtable->base_config_atom
- && pev->window == xkl_root_window) {
+ if (pev->atom == engine->priv->base_config_atom
+ && pev->window == engine->priv->root_window) {
if (pev->state == PropertyNewValue) {
/* If root window got new *_NAMES_PROP_ATOM -
it most probably means new keyboard config is loaded by somebody */
- xkl_reset_all_info
- ("New value of *_NAMES_PROP_ATOM on root window");
+ xkl_engine_reset_all_info
+ (engine,
+ "New value of *_NAMES_PROP_ATOM on root window");
}
}
} /* XKLL_MANAGE_WINDOW_STATES */
@@ -337,15 +372,16 @@ xkl_process_property_evt(XPropertyEvent * pev)
* CreateNotify handler. Just interested in properties and focus events...
*/
void
-xkl_process_create_window_evt(XCreateWindowEvent * cev)
+xkl_engine_process_create_window_evt(XklEngine * engine,
+ XCreateWindowEvent * cev)
{
- if (!(xkl_listener_type & XKLL_MANAGE_WINDOW_STATES))
+ if (!(engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES))
return;
xkl_debug(200,
"Under-root window " WINID_FORMAT
"/%s (%d,%d,%d x %d) is created\n", cev->window,
- xkl_window_get_debug_title(cev->window), cev->x, cev->y,
+ xkl_get_debug_window_title(cev->window), cev->x, cev->y,
cev->width, cev->height);
if (!cev->override_redirect) {
@@ -356,15 +392,18 @@ xkl_process_create_window_evt(XCreateWindowEvent * cev)
* event + SelectInput request is not zero) and we definitely will (my system DO)
* lose FocusIn/Out events after the following call of PropertyNotifyHandler.
* So I just decided to purify this extra FocusChangeMask in the FocusIn/OutHandler. */
- xkl_select_input_merging(cev->window,
- PropertyChangeMask |
- FocusChangeMask);
+ xkl_engine_select_input_merging(engine, cev->window,
+ PropertyChangeMask |
+ FocusChangeMask);
if (xkl_window_has_wm_state(cev->window)) {
xkl_debug(200,
"Just created window already has WM_STATE - so I'll add it");
- xkl_toplevel_window_add(cev->window, (Window) NULL,
- FALSE, &xkl_current_state);
+ xkl_engine_add_toplevel_window(engine, cev->window,
+ (Window) NULL,
+ FALSE,
+ &engine->priv->
+ curr_state);
}
}
}
@@ -376,8 +415,10 @@ xkl_process_create_window_evt(XCreateWindowEvent * cev)
void
xkl_process_error(Display * dpy, XErrorEvent * evt)
{
- xkl_last_error_code = evt->error_code;
- switch (xkl_last_error_code) {
+ XklEngine *engine = xkl_get_the_engine();
+
+ engine->priv->last_error_code = evt->error_code;
+ switch (engine->priv->last_error_code) {
case BadWindow:
case BadAccess:
{
@@ -392,7 +433,7 @@ xkl_process_error(Display * dpy, XErrorEvent * evt)
break;
}
default:
- (*xkl_default_error_handler) (dpy, evt);
+ (*engine->priv->default_error_handler) (dpy, evt);
}
}
@@ -400,8 +441,9 @@ xkl_process_error(Display * dpy, XErrorEvent * evt)
* Some common functionality for Xkb handler
*/
void
-xkl_process_state_modification(XklStateChange change_type,
- gint grp, guint inds, gboolean set_inds)
+xkl_engine_process_state_modification(XklEngine * engine,
+ XklStateChange change_type, gint grp,
+ guint inds, gboolean set_inds)
{
Window focused, focused_toplevel;
XklState old_state;
@@ -409,7 +451,7 @@ xkl_process_state_modification(XklStateChange change_type,
gboolean have_old_state = TRUE;
gboolean set_group = change_type == GROUP_CHANGED;
- XGetInputFocus(xkl_display, &focused, &revert);
+ XGetInputFocus(xkl_engine_get_display(engine), &focused, &revert);
if ((focused == None) || (focused == PointerRoot)) {
xkl_debug(160, "Something with focus: " WINID_FORMAT "\n",
@@ -418,34 +460,38 @@ xkl_process_state_modification(XklStateChange change_type,
}
/**
- * Only if we manage states - otherwise xkl_current_client does not make sense
+ * Only if we manage states - otherwise engine->priv->curr_toplvl_win does not make sense
*/
- if (!xkl_toplevel_window_find(focused, &focused_toplevel) &&
- xkl_listener_type & XKLL_MANAGE_WINDOW_STATES)
- focused_toplevel = xkl_current_client; /* what else can I do */
+ if (!xkl_engine_find_toplevel_window
+ (engine, focused, &focused_toplevel)
+ && engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES)
+ focused_toplevel = engine->priv->curr_toplvl_win; /* what else can I do */
xkl_debug(150, "Focused window: " WINID_FORMAT ", '%s'\n",
focused_toplevel,
- xkl_window_get_debug_title(focused_toplevel));
- if (xkl_listener_type & XKLL_MANAGE_WINDOW_STATES) {
+ xkl_get_debug_window_title(focused_toplevel));
+ if (engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES) {
xkl_debug(150, "CurClient: " WINID_FORMAT ", '%s'\n",
- xkl_current_client,
- xkl_window_get_debug_title(xkl_current_client));
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win));
- if (focused_toplevel != xkl_current_client) {
+ if (focused_toplevel != engine->priv->curr_toplvl_win) {
/**
* If not state - we got the new window
*/
- if (!xkl_toplevel_window_get_state
- (focused_toplevel, &old_state)) {
- xkl_current_state_update(grp, inds,
- "Updating the state from new focused window");
- if (xkl_listener_type &
+ if (!xkl_engine_get_toplevel_window_state
+ (engine, focused_toplevel, &old_state)) {
+ xkl_engine_update_current_state(engine,
+ grp, inds,
+ "Updating the state from new focused window");
+ if (engine->priv->
+ listener_type &
XKLL_MANAGE_WINDOW_STATES)
- xkl_toplevel_window_add
- (focused_toplevel,
+ xkl_engine_add_toplevel_window
+ (engine, focused_toplevel,
(Window) NULL, FALSE,
- &xkl_current_state);
+ &engine->priv->curr_state);
}
/**
* There is state - just get the state from the window
@@ -454,36 +500,46 @@ xkl_process_state_modification(XklStateChange change_type,
grp = old_state.group;
inds = old_state.indicators;
}
- xkl_current_client = focused_toplevel;
+ engine->priv->curr_toplvl_win = focused_toplevel;
xkl_debug(160,
"CurClient:changed to " WINID_FORMAT
- ", '%s'\n", xkl_current_client,
- xkl_window_get_debug_title
- (xkl_current_client));
+ ", '%s'\n",
+ engine->priv->curr_toplvl_win,
+ xkl_get_debug_window_title(engine->priv->
+ curr_toplvl_win));
}
/* If the window already has this this state - we are just restoring it!
(see the second parameter of stateCallback */
have_old_state =
- xkl_toplevel_window_get_state(xkl_current_client,
- &old_state);
+ xkl_engine_get_toplevel_window_state(engine,
+ engine->priv->
+ curr_toplvl_win,
+ &old_state);
} else { /* just tracking the stuff, no smart things */
xkl_debug(160,
"Just updating the current state in the tracking mode\n");
- memcpy(&old_state, &xkl_current_state, sizeof(XklState));
+ memcpy(&old_state, &engine->priv->curr_state,
+ sizeof(XklState));
}
if (set_group || have_old_state) {
- xkl_current_state_update(set_group ? grp : old_state.group,
- set_inds ? inds : old_state.
- indicators,
- "Restoring the state from the window");
+ xkl_engine_update_current_state(engine,
+ set_group ? grp :
+ old_state.group,
+ set_inds ? inds :
+ old_state.indicators,
+ "Restoring the state from the window");
}
if (have_old_state)
- xkl_try_call_state_func(change_type, &old_state);
-
- if (xkl_listener_type & XKLL_MANAGE_WINDOW_STATES)
- xkl_toplevel_window_save_state(xkl_current_client,
- &xkl_current_state);
+ xkl_engine_try_call_state_func(engine, change_type,
+ &old_state);
+
+ if (engine->priv->listener_type & XKLL_MANAGE_WINDOW_STATES)
+ xkl_engine_save_toplevel_window_state(engine,
+ engine->priv->
+ curr_toplvl_win,
+ &engine->priv->
+ curr_state);
}
diff --git a/libxklavier/xklavier_private.h b/libxklavier/xklavier_private.h
index d3a560c..64e4cd2 100644
--- a/libxklavier/xklavier_private.h
+++ b/libxklavier/xklavier_private.h
@@ -5,46 +5,50 @@
#include <libxklavier/xklavier_config.h>
-/* XklConfigRec */
-typedef gboolean(*XklVTConfigActivateFunc) (const XklConfigRec * data);
+enum { WM_NAME,
+ WM_STATE,
+ XKLAVIER_STATE,
+ XKLAVIER_TRANSPARENT,
+ XKLAVIER_ALLOW_SECONDARY,
+ TOTAL_ATOMS
+};
+
+struct _XklEnginePrivate {
-typedef void (*XklVTConfigInitFunc) (void);
+ gboolean group_per_toplevel_window;
-typedef gboolean(*XklVTConfigRegistryLoadFunc) (void);
+ gboolean handle_indicators;
-typedef gboolean(*XklVTConfigWriteFileFunc) (const gchar * file_name,
- const XklConfigRec * data,
- const gboolean binary);
+ gboolean skip_one_restore;
-/* Groups */
-typedef const gchar **(*XklVTGroupsGetNamesFunc) (void);
+ gint default_group;
-typedef guint(*XklVTGroupsGetMaxNumFunc) (void);
+ guint listener_type;
-typedef guint(*XklVTGroupsGetNumFunc) (void);
+ guint secondary_groups_mask;
-typedef void (*XklVTGroupLockFunc) (gint group);
+ Window root_window;
+ Window prev_toplvl_win;
-typedef gint(*XklVTProcessXEventFunc) (XEvent * xev);
+ Window curr_toplvl_win;
-typedef void (*XklVTFreeAllInfoFunc) (void);
+ XErrorHandler default_error_handler;
-typedef gboolean(*XklVTIfCachedInfoEqualsActualFunc) (void);
+ Status last_error_code;
-typedef gboolean(*XklVTLoadAllInfoFunc) (void);
+ const gchar *last_error_message;
-typedef void (*XklVTGetServerStateFunc) (XklState * current_state_out);
+ XklState curr_state;
-typedef gint(*XklVTPauseResumeListenFunc) (void);
+ Atom atoms[TOTAL_ATOMS];
-typedef void (*XklVTIndicatorsSetFunc) (const XklState * window_state);
+ Display *display;
-typedef struct {
/**
* Backend name
*/
- const gchar *id;
+ const gchar *backend_id;
/**
* Functions supported by the backend, combination of XKLF_* constants
@@ -56,14 +60,14 @@ typedef struct {
* xkb: create proper the XkbDescRec and send it to the server
* xmodmap: save the property, init layout #1
*/
- XklVTConfigActivateFunc config_activate_func;
+ gboolean(*activate_config) (const XklConfigRec * data);
/**
* Background-specific initialization.
* xkb: XkbInitAtoms - init internal xkb atoms table
* xmodmap: void.
*/
- XklVTConfigInitFunc config_init_func; /* private */
+ void (*init_config) (void);
/**
* Loads the registry tree into DOM (using whatever path(s))
@@ -71,7 +75,7 @@ typedef struct {
* xkb: loads xml from XKB_BASE+"/rules/"+ruleset+".xml"
* xmodmap: loads xml from XMODMAP_BASE+"/"+ruleset+".xml"
*/
- XklVTConfigRegistryLoadFunc config_registry_load_func;
+ gboolean(*load_config_registry) (void);
/**
* Write the configuration into the file (binary/textual)
@@ -79,29 +83,30 @@ typedef struct {
* xmodmap: if text requested, just dump XklConfigRec to the
* file - not really useful. If binary - fail (not supported)
*/
- XklVTConfigWriteFileFunc config_write_file_func;
-
+ gboolean(*write_config_to_file) (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
*/
- XklVTGroupsGetNamesFunc groups_get_names_func;
+ const gchar **(*get_groups_names) (void);
/**
* Get the maximum number of loaded groups
* xkb: returns 1 or XkbNumKbdGroups
* xmodmap: return 0
*/
- XklVTGroupsGetMaxNumFunc groups_get_max_num_func;
+ guint(*get_max_num_groups) (void);
/**
* Get the number of loaded groups
* xkb: return from the cached XkbDesc
* xmodmap: return number of layouts from internal XklConfigRec
*/
- XklVTGroupsGetNumFunc groups_get_num_func;
+ guint(*get_num_groups) (void);
/**
* Switches the keyboard to the group N
@@ -109,65 +114,63 @@ typedef struct {
* xmodmap: changes the root window property
* (listener invokes xmodmap with appropriate config file).
*/
- XklVTGroupLockFunc group_lock_func;
-
+ void (*lock_group) (gint group);
/**
* Handles X events.
* xkb: XkbEvent handling
* xmodmap: keep track on the root window properties. What else can we do?
*/
- XklVTProcessXEventFunc process_x_event_func;
+ gint(*process_x_event) (XEvent * xev);
/**
* Flushes the cached server config info.
* xkb: frees XkbDesc
* xmodmap: frees internal XklConfigRec
*/
- XklVTFreeAllInfoFunc free_all_info_func; /* private */
+ void (*free_all_info) (void);
/**
* Compares the cached info with the actual one, from the server
* xkb: Compares some parts of XkbDescPtr
* xmodmap: returns False
*/
- XklVTIfCachedInfoEqualsActualFunc
- if_cached_info_equals_actual_func;
+ gboolean(*if_cached_info_equals_actual) (void);
/**
* Loads the configuration info from the server
* xkb: loads XkbDesc, names, indicators
* xmodmap: loads internal XklConfigRec from server
*/
- XklVTLoadAllInfoFunc load_all_info_func; /* private */
+ gboolean(*load_all_info) (void);
/**
- * Gets the current stateCallback
+ * Gets the current state
* xkb: XkbGetState and XkbGetIndicatorState
* xmodmap: check the root window property (regarding the group)
*/
- XklVTGetServerStateFunc get_server_state_func;
+ void (*get_server_state) (XklState * current_state_out);
/**
* Stop tracking the keyboard-related events
* xkb: XkbSelectEvents(..., 0)
* xmodmap: Ungrab the switching shortcut.
*/
- XklVTPauseResumeListenFunc listen_pause_func;
+ gint(*pause_listen) (void);
/**
* Start tracking the keyboard-related events
* xkb: XkbSelectEvents + XkbSelectEventDetails
* xmodmap: Grab the switching shortcut.
*/
- XklVTPauseResumeListenFunc listen_resume_func;
+ gint(*resume_listen) (void);
/**
* Set the indicators state from the XklState
* xkb: XklSetIndicator for all indicators
* xmodmap: NULL. Not supported
*/
- XklVTIndicatorsSetFunc indicators_set_func; /* private */
+ void (*set_indicators) (const XklState * window_state);
/* all data is private - no direct access */
/**
@@ -194,29 +197,38 @@ typedef struct {
*/
const gchar *default_layout;
-} XklVTable;
+};
+
+extern XklEngine *xkl_get_the_engine(void);
-extern void xkl_ensure_vtable_inited(void);
-extern void xkl_process_focus_in_evt(XFocusChangeEvent * fev);
-extern void xkl_process_focus_out_evt(XFocusChangeEvent * fev);
-extern void xkl_process_property_evt(XPropertyEvent * rev);
-extern void xkl_process_create_window_evt(XCreateWindowEvent * cev);
+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 void xkl_process_error(Display * dpy, XErrorEvent * evt);
-extern void xkl_process_state_modification(XklStateChange change_type,
- gint group,
- unsigned inds,
- gboolean set_indicators);
+extern void xkl_engine_process_state_modification(XklEngine * engine,
+ XklStateChange
+ change_type, gint group,
+ unsigned inds,
+ gboolean set_indicators);
extern Window xkl_get_registered_parent(Window win);
-extern gboolean xkl_load_all_info(void);
-extern void xkl_free_all_info(void);
-extern void xkl_reset_all_info(const gchar reason[]);
-extern gboolean xkl_load_window_tree(void);
-extern gboolean xkl_load_subtree(Window window,
- gint level, XklState * init_state);
+extern gboolean xkl_engine_load_all_info(XklEngine * engine);
+extern void xkl_engine_free_all_info(XklEngine * engine);
+extern void xkl_engine_reset_all_info(XklEngine * engine,
+ 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_window_has_wm_state(Window win);
@@ -224,33 +236,45 @@ extern gboolean xkl_window_has_wm_state(Window win);
/**
* Toplevel window stuff
*/
-extern void xkl_toplevel_window_add(Window win,
- Window parent, gboolean force,
- XklState * init_state);
-
-extern gboolean xkl_toplevel_window_find_bottom_to_top(Window win,
- Window *
- toplevel_win_out);
-
-extern gboolean xkl_toplevel_window_find(Window win,
- Window * toplevel_win_out);
-
-extern gboolean xkl_toplevel_window_is_transparent(Window toplevel_win);
-
-extern void xkl_toplevel_window_set_transparent(Window toplevel_win,
- gboolean transparent);
-
-extern gboolean xkl_toplevel_window_get_state(Window toplevel_win,
- XklState * state_out);
-
-extern void xkl_toplevel_window_remove_state(Window toplevel_win);
-extern void xkl_toplevel_window_save_state(Window toplevel_win,
- XklState * state);
+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_select_input_merging(Window win, gulong mask);
+extern void xkl_engine_select_input_merging(XklEngine * engine, Window win,
+ gulong mask);
-extern gchar *xkl_window_get_debug_title(Window win);
+extern gchar *xkl_get_debug_window_title(Window win);
extern Status xkl_status_query_tree(Window w,
Window * root_out,
@@ -258,10 +282,12 @@ extern Status xkl_status_query_tree(Window w,
Window ** children_out,
guint * nchildren_out);
-extern gboolean xkl_indicator_set(gint indicator_num, gboolean set);
+extern gboolean xkl_engine_indicator_set(XklEngine * engine,
+ gint indicator_num, gboolean set);
-extern void xkl_try_call_state_func(XklStateChange change_type,
- XklState * old_state);
+extern void xkl_engine_try_call_state_func(XklEngine * engine,
+ XklStateChange change_type,
+ XklState * old_state);
extern void xkl_i18n_init(void);
@@ -269,7 +295,7 @@ extern gchar *xkl_locale_from_utf8(const gchar * utf8string);
extern gint xkl_get_language_priority(const gchar * language);
-extern gchar *xkl_rules_set_get_name(const gchar default_ruleset[]);
+extern gchar *xkl_engine_get_ruleset_name(XklEngine * engine, const gchar default_ruleset[]);
extern gboolean xkl_config_get_full_from_server(gchar ** rules_file_out,
XklConfigRec * data);
@@ -302,73 +328,30 @@ extern void xkl_config_dump(FILE * file, XklConfigRec * data);
extern const gchar *xkl_event_get_name(gint type);
-extern void xkl_current_state_update(gint group,
- unsigned indicators,
- const gchar reason[]);
-
-extern gint xkl_xkb_init(void);
-
-extern gint xkl_xmm_init(void);
-
-extern gboolean xkl_is_one_switch_to_secondary_group_allowed(void);
-
-extern void xkl_one_switch_to_secondary_group_performed(void);
-
-extern Display *xkl_display;
+extern void xkl_engine_update_current_state(XklEngine * engine, gint group,
+ unsigned indicators,
+ const gchar reason[]);
-extern Window xkl_root_window;
+extern gint xkl_xkb_init(XklEngine * engine);
-extern XklState xkl_current_state;
+extern gint xkl_xmm_init(XklEngine * engine);
-extern Window xkl_current_client;
+extern gboolean
+xkl_engine_is_one_switch_to_secondary_group_allowed(XklEngine * engine);
-extern Status xkl_last_error_code;
-
-extern const gchar *xkl_last_error_message;
-
-extern XErrorHandler xkl_default_error_handler;
-
-extern gchar *xkl_indicator_names[];
-
-enum { WM_NAME,
- WM_STATE,
- XKLAVIER_STATE,
- XKLAVIER_TRANSPARENT,
- XKLAVIER_ALLOW_SECONDARY,
- TOTAL_ATOMS
-};
+extern void xkl_engine_one_switch_to_secondary_group_performed(XklEngine *
+ engine);
#define XKLAVIER_STATE_PROP_LENGTH 2
/* taken from XFree86 maprules.c */
#define XKB_RF_NAMES_PROP_MAXLEN 1024
-extern Atom xkl_atoms[];
-
-extern gboolean xkl_allow_secondary_group_once;
-
-extern gint xkl_default_group;
-
-extern gboolean xkl_skip_one_restore;
-
-extern guint xkl_secondary_groups_mask;
-
-extern gint xkl_debug_level;
-
-extern guint xkl_listener_type;
-
-extern Window xkl_toplevel_window_prev;
-
#define WINID_FORMAT "%lx"
-extern XklConfigNotifyFunc xkl_config_callback;
-
-extern gpointer xkl_config_callback_data;
+#define xkl_engine_get_display(engine) ((engine)->priv->display)
+#define xkl_engine_vcall(engine,func) (*(engine)->priv->func)
-extern XklNewWindowNotifyFunc xkl_new_window_callback;
-
-extern gpointer xkl_new_window_callback_data;
-
-extern XklVTable *xkl_vtable;
+extern gint xkl_debug_level;
#endif
diff --git a/libxklavier/xklavier_props.c b/libxklavier/xklavier_props.c
index 75719fb..2a56868 100644
--- a/libxklavier/xklavier_props.c
+++ b/libxklavier/xklavier_props.c
@@ -53,7 +53,7 @@ xkl_config_rec_class_init(XklConfigRecClass * klass)
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
- g_object_class = g_type_class_peek_parent(klass);
+ g_object_class = g_type_class_peek_parent(object_class);
object_class->finalize = xkl_config_rec_finalize;
}
@@ -95,7 +95,7 @@ static gboolean
xkl_get_default_names_prop(char **rules_file_out, XklConfigRec * data)
{
if (rules_file_out != NULL)
- *rules_file_out = strdup(XKB_DEFAULT_RULESET);
+ *rules_file_out = g_strdup(XKB_DEFAULT_RULESET);
data->model = g_strdup(xkl_vtable->default_model);
/* keeping Nvariants = Nlayouts */
data->layouts = g_new0(char *, 2);