static GClassInitFunc orig_gtk_im_context_xim_class_init;
static GType (*orig_g_type_module_register_type)(GTypeModule *,
GType, const gchar *,
const GTypeInfo *, GTypeFlags);
static gboolean (*orig_gtk_im_context_xim_filter_keypress)(GtkIMContext *context,
GdkEventKey *event);
static gboolean
hook_gtk_im_context_xim_filter_keypress(GtkIMContext *context, GdkEventKey *event) {
GtkIMContextXIM *im_context_xim = GTK_IM_CONTEXT_XIM(context);
if (!im_context_xim->client_window) {
DEBUG(“im_context_xim == %pn”, im_context_xim);
DEBUG(“event->window == %pn”, event->window);
gtk_im_context_set_client_window(context, event->window);
}
return orig_gtk_im_context_xim_filter_keypress(context, event);
}
static void
hook_gtk_im_context_xim_class_init (GtkIMContextXIMClass *class) {
orig_gtk_im_context_xim_class_init(class, NULL); /* wat? */
GtkIMContextClass *im_context_class = GTK_IM_CONTEXT_CLASS (class);
assert(!orig_gtk_im_context_xim_filter_keypress);
orig_gtk_im_context_xim_filter_keypress = im_context_class->filter_keypress;
im_context_class->filter_keypress = hook_gtk_im_context_xim_filter_keypress;
DEBUG(“orig_gtk_im_context_xim_filter_keypress: %pn”,
orig_gtk_im_context_xim_filter_keypress);
}
GType
g_type_module_register_type (GTypeModule *module,
GType parent_type,
const gchar *type_name,
const GTypeInfo *type_info,
GTypeFlags flags) {
if (!orig_g_type_module_register_type) {
orig_g_type_module_register_type = dlsym(RTLD_NEXT, “g_type_module_register_type”);
assert(orig_g_type_module_register_type);
}
if (type_name && !strcmp(type_name, “GtkIMContextXIM”)) {
assert(!orig_gtk_im_context_xim_class_init);
orig_gtk_im_context_xim_class_init = type_info->class_init;
assert(sizeof(GtkIMContextXIM) == type_info->instance_size);
const GTypeInfo hook_im_context_xim_info =
{
type_info->class_size,
type_info->base_init,
type_info->base_finalize,
(GClassInitFunc) hook_gtk_im_context_xim_class_init,
type_info->class_finalize,
type_info->class_data,
type_info->instance_size,
type_info->n_preallocs,
type_info->instance_init,
};
DEBUG(“orig_gtk_im_context_xim_class_init: %pn”, orig_gtk_im_context_xim_class_init);
gtk_type_im_context_xim =
orig_g_type_module_register_type(module, parent_type, type_name,
&hook_im_context_xim_info, flags);
return gtk_type_im_context_xim;
}
return orig_g_type_module_register_type(module, parent_type, type_name, type_info, flags);
}