Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/keysym.h>
- XIMStyle ChooseBetterStyle(XIMStyle style1, XIMStyle style2)
- {
- XIMStyle s,t;
- XIMStyle preedit = XIMPreeditArea | XIMPreeditCallbacks |
- XIMPreeditPosition | XIMPreeditNothing | XIMPreeditNone;
- XIMStyle status = XIMStatusArea | XIMStatusCallbacks |
- XIMStatusNothing | XIMStatusNone;
- if (style1 == 0) return style2;
- if (style2 == 0) return style1;
- if ((style1 & (preedit | status)) == (style2 & (preedit | status)))
- return style1;
- s = style1 & preedit;
- t = style2 & preedit;
- if (s != t) {
- if (s | t | XIMPreeditCallbacks)
- return (s == XIMPreeditCallbacks)?style1:style2;
- else if (s | t | XIMPreeditPosition)
- return (s == XIMPreeditPosition)?style1:style2;
- else if (s | t | XIMPreeditArea)
- return (s == XIMPreeditArea)?style1:style2;
- else if (s | t | XIMPreeditNothing)
- return (s == XIMPreeditNothing)?style1:style2;
- }
- else { /* if preedit flags are the same, compare status flags */
- s = style1 & status;
- t = style2 & status;
- if (s | t | XIMStatusCallbacks)
- return (s == XIMStatusCallbacks)?style1:style2;
- else if (s | t | XIMStatusArea)
- return (s == XIMStatusArea)?style1:style2;
- else if (s | t | XIMStatusNothing)
- return (s == XIMStatusNothing)?style1:style2;
- }
- }
- int main(int argc, char **argv)
- {
- Display *dpy;
- Window root;
- XIM xim;
- XIC xic;
- unsigned long event_mask;
- XIMStyle app_supported_styles;
- XVaNestedList list;
- XIMStyle style;
- XFontSet fontset;
- XIMStyle best_style;
- XIMStyles *im_supported_styles;
- dpy = XOpenDisplay(NULL);
- root = XDefaultRootWindow(dpy);
- xim = XOpenIM(dpy, NULL, NULL, NULL);
- event_mask = FocusIn | FocusOut;
- if((dpy = XOpenDisplay(NULL)) == NULL) {
- perror(argv[0]);
- exit(1);
- }
- XGetIMValues(xim, XNQueryInputStyle, &im_supported_styles, NULL);
- app_supported_styles = XIMPreeditNone | XIMPreeditNothing | XIMPreeditArea;
- app_supported_styles |= XIMStatusNone | XIMStatusNothing | XIMStatusArea;
- for(int i=0; i < im_supported_styles->count_styles; i++) {
- style = im_supported_styles->supported_styles[i];
- if ((style & app_supported_styles) == style) /* if we can handle it */
- best_style = ChooseBetterStyle(style, best_style);
- }
- XFree(im_supported_styles);
- list = XVaCreateNestedList(0, XNFontSet, fontset, NULL);
- xic = XCreateIC(xim, XNInputStyle, best_style,
- XNClientWindow, root,
- XNPreeditAttributes, list,
- XNStatusAttributes, list,
- NULL);
- XFree(list);
- XGetICValues(xic, XNFilterEvents, &event_mask, NULL);
- XSelectInput(dpy, root, FocusChangeMask | event_mask);
- XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
- XSetICFocus(xic);
- for(;;) {
- XEvent e;
- XNextEvent(dpy, &e);
- if (XFilterEvent(&e, None)) continue;
- printf("Received");
- switch (e.type) {
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement