There's a potential for a bug here. In order for modifiers to be kept up to date, you really need to update the keymod state on every key  event where the modifier mask might have changed. I don't know enough about Xutf8LookupString, but if status isn't XLookupChars, XLookupBoth or XLookupKeySym then you'll end up with a situation with stuck modifiers.

I'd suggest checking for modifiers before doing IM stuff.