#include "dat.h" #include "fn.h" #include #include #include static struct xkb_compose_state *cstate; /* Dead keys and Compose: no frontend's client does them for us. */ void composeinit(void) { struct xkb_context *ctx; struct xkb_compose_table *table; char *locale; locale = setlocale(LC_CTYPE, ""); ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if(ctx == nil) return; table = xkb_compose_table_new_from_locale(ctx, locale != nil ? locale : "C", XKB_COMPOSE_COMPILE_NO_FLAGS); if(table != nil) cstate = xkb_compose_state_new(table, XKB_COMPOSE_STATE_NO_FLAGS); xkb_compose_table_unref(table); xkb_context_unref(ctx); } /* * Feeds sym to the Compose table. Returns 1 while a sequence is * unfinished: the key belongs to the sequence, not to the engine. A * finished sequence leaves its text in buf, which the caller commits * after whatever the engine had pending. */ int composekey(u32int sym, char *buf, int n) { buf[0] = '\0'; if(cstate == nil || xkb_compose_state_feed(cstate, sym) != XKB_COMPOSE_FEED_ACCEPTED) return 0; switch(xkb_compose_state_get_status(cstate)){ case XKB_COMPOSE_COMPOSING: case XKB_COMPOSE_CANCELLED: return 1; case XKB_COMPOSE_COMPOSED: xkb_compose_state_get_utf8(cstate, buf, n); break; default: break; } return 0; }