void get_hime_im_srv_sock_path(char *outstr, int outstrN) { char *disp = getenv("DISPLAY"); int my_uid = getuid(); if (!disp || !strcmp(disp, ":0")) disp = ":0.0"; char tdisp[64]; strcpy(tdisp, disp); if (!strchr(disp, ':')) strcat(tdisp, ":0"); if (!strchr(disp, '.')) strcat(tdisp, ".0"); char my_dir[128]; struct passwd *pw = getpwuid(my_uid); snprintf(my_dir, sizeof(my_dir), "%s/.hime-%s", g_get_tmp_dir(), pw->pw_name); struct stat st; if (stat(my_dir, &st) < 0) mkdir(my_dir, 0700); else { if (st.st_uid != my_uid) { fprintf(stderr, "please check the permision of dir %s\n", my_dir); return; } } snprintf(outstr,outstrN, "%s/socket-%s-%s", my_dir, tdisp, get_hime_xim_name()); }
void open_xim() { XIMTriggerKeys triggerKeys; im_styles.supported_styles = Styles; im_styles.count_styles = sizeof(Styles)/sizeof(Styles[0]); triggerKeys.count_keys = sizeof(trigger_keys)/sizeof(trigger_keys[0]); triggerKeys.keylist = trigger_keys; encodings.count_encodings = sizeof(chEncodings)/sizeof(XIMEncoding) - 1; encodings.supported_encodings = chEncodings; char *xim_name = get_hime_xim_name(); XIMS xims = IMOpenIM(dpy, IMServerWindow, xim_xwin, //input window IMModifiers, "Xi18n", //X11R6 protocol IMServerName, xim_name, //XIM server name IMLocale, lc, IMServerTransport, "X/", //Comm. protocol IMInputStyles, &im_styles, //faked styles IMEncodingList, &encodings, IMProtocolHandler, hime_ProtoHandler, IMFilterEventMask, KeyPressMask|KeyReleaseMask, IMOnKeysList, &triggerKeys, NULL); if (xims == NULL) { p_err("IMOpenIM '%s' failed. Maybe another XIM server is running.\n", xim_name); } }
Atom get_hime_atom(Display *dpy) { char *xim_name = get_hime_xim_name(); char tt[128]; snprintf(tt, sizeof(tt), "HIME_ATOM_%s", xim_name); Atom atom = XInternAtom(dpy, tt, False); return atom; }
Atom get_hime_sockpath_atom(Display *dpy) { if (!dpy) { dbg("dpy is null\n"); return 0; } char *xim_name = get_hime_xim_name(); char tt[128]; snprintf(tt, sizeof(tt), "HIME_SOCKPATH_ATOM_%s", xim_name); Atom atom = XInternAtom(dpy, tt, False); return atom; }
int main(int argc, char **argv) { #if WIN32 putenv("PANGO_WIN32_NO_UNISCRIBE=1"); #endif char *destroy = getenv("HIME_DESTROY_WINDOW"); if (destroy) destroy_window = atoi(destroy); // printf("HIME_DESTROY_WINDOW=%d\n",destroy_window); gtk_init (&argc, &argv); #if GTK_CHECK_VERSION(2,91,6) static char css[]= "GtkButton\n" "{\n" " border-width: 0;\n" " padding: 0;\n" " -GtkButton-inner-border: 0;\n" "}"; GtkCssProvider *provider = gtk_css_provider_new(); gtk_css_provider_load_from_data(provider, css, -1, NULL); gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref(provider); #else static char button_rc[]="style \"button\"\n" "{\n" " GtkButton::inner-border = {0,0,0,0}\n" "\n" "xthickness = 1\n" "ythickness = 0\n" "}\n" "class \"GtkButton\" style \"button\""; gtk_rc_parse_string(button_rc); #endif #if UNIX signal(SIGCHLD, SIG_IGN); signal(SIGPIPE, SIG_IGN); if (getenv("HIME_DAEMON")) { daemon(1,1); #if FREEBSD setpgid(0, getpid()); #else setpgrp(); #endif } #endif //putenv("GDK_NATIVE_WINDOWS=1"); #if WIN32 typedef BOOL (WINAPI* pImmDisableIME)(DWORD); pImmDisableIME pd; HMODULE imm32=LoadLibraryA("imm32"); if (imm32 && (pd=(pImmDisableIME)GetProcAddress(imm32, "ImmDisableIME"))) { (*pd)(0); } init_hime_program_files(); init_hime_im_serv(); #endif set_is_chs(); #if UNIX char *lc_ctype = getenv("LC_CTYPE"); char *lc_all = getenv("LC_ALL"); char *lang = getenv("LANG"); if (!lc_ctype && lang) lc_ctype = lang; if (lc_all) lc_ctype = lc_all; if (!lc_ctype) lc_ctype = "zh_TW.Big5"; dbg("hime get env LC_CTYPE=%s LC_ALL=%s LANG=%s\n", lc_ctype, lc_all, lang); #endif #if USE_XIM char *t = strchr(lc_ctype, '.'); if (t) { int len = t - lc_ctype; #if MAC_OS || FREEBSD lc = strdup(lc_ctype); lc[len] = 0; #else lc = g_strndup(lc_ctype, len); #endif } else lc = lc_ctype; char *xim_server_name = get_hime_xim_name(); strcpy(xim_arr[0].xim_server_name, xim_server_name); dbg("hime XIM will use %s as the default encoding\n", lc_ctype); #endif if (argc == 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version") || !strcmp(argv[1], "-h")) ) { setenv("NO_GTK_INIT", "", TRUE); p_err(" version %s\n", HIME_VERSION); } init_TableDir(); load_setttings(); load_gtab_list(TRUE); #if HIME_i18n_message bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif dbg("after gtk_init\n"); #if UNIX dpy = GDK_DISPLAY(); root=DefaultRootWindow(dpy); #endif get_dpy_xyl(); g_signal_connect(gdk_screen_get_default(),"size-changed", G_CALLBACK(screen_size_changed), NULL); dbg("display width:%d height:%d\n", dpy_xl, dpy_yl); #if UNIX start_inmd_window(); #endif #if USE_XIM open_xim(); #endif #if UNIX gdk_window_add_filter(NULL, my_gdk_filter, NULL); init_atom_property(); signal(SIGINT, sig_do_exit); signal(SIGHUP, sig_do_exit); // disable the io handler abort // void *olderr = XSetErrorHandler((XErrorHandler)xerror_handler); #endif #if UNIX init_hime_im_serv(xim_arr[0].xim_xwin); #endif exec_setup_scripts(); #if UNIX g_timeout_add(5000, delayed_start_cb, NULL); #else delayed_start_cb(NULL); #endif dbg("before gtk_main\n"); disp_win_kbm_capslock_init(); gtk_main(); return 0; }