locale_x11encoding.c 793 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Prints the locale's encoding via libX11. */
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <assert.h>
  5. #include <locale.h>
  6. #include <X11/Xlib.h>
  7. #include <X11/Xutil.h>
  8. int main (int argc, char* argv[])
  9. {
  10. Display* display;
  11. XTextProperty textprop;
  12. char* input;
  13. if (argc != 1)
  14. exit(1);
  15. setlocale(LC_CTYPE,"");
  16. display = XOpenDisplay(NULL);
  17. if (display == NULL) {
  18. fprintf(stderr,"cannot open display\n");
  19. exit(1);
  20. }
  21. input = "";
  22. if (XmbTextListToTextProperty(display, &input, 1, XTextStyle, &textprop) != Success) {
  23. fprintf(stderr,"XmbTextListToTextProperty failed\n");
  24. exit(1);
  25. }
  26. assert(textprop.format == 8);
  27. assert(textprop.nitems == 0);
  28. printf("%s\n", XGetAtomName(display, textprop.encoding));
  29. XCloseDisplay(display);
  30. exit(0);
  31. }