/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Compile with gcc -D_REENTRANT -Wall -o xim1 xim1.c -L/usr/X11R6/lib -lX11 -lSM -lICE -lX11 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #include #include #include #include #include #include #include #define DEFAULT_FONT_NAME "-*-*-*-R-Normal--14-130-75-75-*-*" #define F_SIZE 14 #define COL 30 #define ROW 10 #define W_WIDTH (F_SIZE * COL) #define W_HEIGHT (F_SIZE * ROW) int main(int argc, char *argv[]) { Display *display; int screen; GC gc; Window window; XWMHints hints; Atom protocols; XFontSet fs; char **missing_list; int missing_count; char *def_string; XFontSetExtents *fs_ext; int dec; XIM im; XIC ic; XEvent event; unsigned long mask, fevent; int len = 128; char string[128], s_tab[ROW][128]; int i, row = 0, col = 0; KeySym keysym; int count = 0; Status status; #ifdef _REENTRANT fprintf(stderr, "Initializing threads\n"); XInitThreads(); #endif display = XOpenDisplay(""); screen = DefaultScreen(display); gc = DefaultGC(display,screen); if(setlocale(LC_CTYPE, "") == NULL){ fprintf(stderr, "Error : setlocale() !\n"); exit(0); } fs = XCreateFontSet(display, DEFAULT_FONT_NAME, &missing_list, &missing_count, &def_string); fs_ext = XExtentsOfFontSet(fs); dec = fs_ext->max_logical_extent.height-(-fs_ext->max_logical_extent.y); window = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, W_WIDTH, W_HEIGHT+dec, 2, BlackPixel(display,screen), WhitePixel(display,screen)); XStoreName(display, window, "XIM demo - Root window"); hints.flags = InputHint; hints.input = True; XSetWMHints(display, window, &hints); protocols = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &protocols, 1); if((im = XOpenIM(display, NULL, NULL, NULL)) == NULL){ printf("Error : XOpenIM() !\n"); exit(0); } ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, window, NULL); if(ic == NULL){ printf("Error : XCreateIC() !\n"); XCloseIM(im); exit(0); } XGetICValues(ic, XNFilterEvents, &fevent, NULL); mask = ExposureMask | KeyPressMask | FocusChangeMask; XSelectInput(display, window, mask|fevent); for(i=0; i