Advertisement
Guest User

Untitled

a guest
Jul 5th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5. #include <X11/keysym.h>
  6.  
  7. XIMStyle ChooseBetterStyle(XIMStyle style1, XIMStyle style2)
  8. {
  9.     XIMStyle s,t;
  10.     XIMStyle preedit = XIMPreeditArea | XIMPreeditCallbacks |
  11.                        XIMPreeditPosition | XIMPreeditNothing | XIMPreeditNone;
  12.     XIMStyle status = XIMStatusArea | XIMStatusCallbacks |
  13.                       XIMStatusNothing | XIMStatusNone;
  14.     if (style1 == 0) return style2;
  15.     if (style2 == 0) return style1;
  16.     if ((style1 & (preedit | status)) == (style2 & (preedit | status)))
  17.         return style1;
  18.     s = style1 & preedit;
  19.     t = style2 & preedit;
  20.     if (s != t) {
  21.         if (s | t | XIMPreeditCallbacks)
  22.             return (s == XIMPreeditCallbacks)?style1:style2;
  23.         else if (s | t | XIMPreeditPosition)
  24.             return (s == XIMPreeditPosition)?style1:style2;
  25.         else if (s | t | XIMPreeditArea)
  26.             return (s == XIMPreeditArea)?style1:style2;
  27.         else if (s | t | XIMPreeditNothing)
  28.             return (s == XIMPreeditNothing)?style1:style2;
  29.     }
  30.     else { /* if preedit flags are the same, compare status flags */
  31.         s = style1 & status;
  32.         t = style2 & status;
  33.         if (s | t | XIMStatusCallbacks)
  34.             return (s == XIMStatusCallbacks)?style1:style2;
  35.         else if (s | t | XIMStatusArea)
  36.             return (s == XIMStatusArea)?style1:style2;
  37.         else if (s | t | XIMStatusNothing)
  38.             return (s == XIMStatusNothing)?style1:style2;
  39.     }
  40. }
  41.  
  42. int main(int argc, char **argv)
  43. {
  44.     Display *dpy;
  45.     Window root;
  46.     XIM xim;
  47.     XIC xic;
  48.     unsigned long event_mask;
  49.     XIMStyle app_supported_styles;
  50.     XVaNestedList list;
  51.     XIMStyle style;
  52.     XFontSet fontset;
  53.     XIMStyle best_style;
  54.     XIMStyles *im_supported_styles;
  55.  
  56.  
  57.     dpy = XOpenDisplay(NULL);
  58.     root = XDefaultRootWindow(dpy);
  59.  
  60.     xim = XOpenIM(dpy, NULL, NULL, NULL);
  61.  
  62.     event_mask = FocusIn | FocusOut;
  63.     if((dpy = XOpenDisplay(NULL)) == NULL) {
  64.         perror(argv[0]);
  65.         exit(1);
  66.     }
  67.  
  68.     XGetIMValues(xim, XNQueryInputStyle, &im_supported_styles, NULL);
  69.     app_supported_styles = XIMPreeditNone | XIMPreeditNothing | XIMPreeditArea;
  70.     app_supported_styles |= XIMStatusNone | XIMStatusNothing | XIMStatusArea;
  71.  
  72.     for(int i=0; i < im_supported_styles->count_styles; i++) {
  73.         style = im_supported_styles->supported_styles[i];
  74.         if ((style & app_supported_styles) == style) /* if we can handle it */
  75.             best_style = ChooseBetterStyle(style, best_style);
  76.     }
  77.     XFree(im_supported_styles);
  78.  
  79.  
  80.     list = XVaCreateNestedList(0, XNFontSet, fontset, NULL);
  81.     xic = XCreateIC(xim, XNInputStyle, best_style,
  82.                     XNClientWindow, root,
  83.                     XNPreeditAttributes, list,
  84.                     XNStatusAttributes, list,
  85.                     NULL);
  86.     XFree(list);
  87.  
  88.     XGetICValues(xic, XNFilterEvents, &event_mask, NULL);
  89.     XSelectInput(dpy, root, FocusChangeMask | event_mask);
  90.     XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  91.     XSetICFocus(xic);
  92.     for(;;) {
  93.         XEvent e;
  94.         XNextEvent(dpy, &e);
  95.         if (XFilterEvent(&e, None)) continue;
  96.     printf("Received");
  97.         switch (e.type) {
  98.  
  99.         }
  100.     }
  101.     return 0;
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement