📄 i18nmethod.c
字号:
return IMServerName; /*endif*/ strcpy (p->value, address->im_name); } else { return IMServerName; } /*endif*/ } else if (strcmp (p->name, IMServerWindow) == 0) { if (address->imvalue_mask & I18N_IMSERVER_WIN) *((Window *) (p->value)) = address->im_window; else return IMServerWindow; /*endif*/ } else if (strcmp (p->name, IMInputStyles) == 0) { if (GetInputStyles (i18n_core, (XIMStyles **) p->value) == False) { return IMInputStyles; } /*endif*/ } else if (strcmp (p->name, IMProtocolHandler) == 0) { if (address->imvalue_mask & I18N_IM_HANDLER) *((IMProtoHandler *) (p->value)) = address->improto; else return IMProtocolHandler; /*endif*/ } else if (strcmp (p->name, IMOnKeysList) == 0) { if (address->imvalue_mask & I18N_ON_KEYS) { if (GetOnOffKeys (i18n_core, I18N_ON_KEYS, (XIMTriggerKeys **) p->value) == False) { return IMOnKeysList; } /*endif*/ } else { return IMOnKeysList; } /*endif*/ } else if (strcmp (p->name, IMOffKeysList) == 0) { if (address->imvalue_mask & I18N_OFF_KEYS) { if (GetOnOffKeys (i18n_core, I18N_OFF_KEYS, (XIMTriggerKeys **) p->value) == False) { return IMOffKeysList; } /*endif*/ } else { return IMOffKeysList; } /*endif*/ } else if (strcmp (p->name, IMEncodingList) == 0) { if (address->imvalue_mask & I18N_ENCODINGS) { if (GetEncodings (i18n_core, (XIMEncodings **) p->value) == False) { return IMEncodingList; } /*endif*/ } else { return IMEncodingList; } /*endif*/ } else if (strcmp (p->name, IMFilterEventMask) == 0) { if (address->imvalue_mask & I18N_FILTERMASK) *((long *) (p->value)) = address->filterevent_mask; else return IMFilterEventMask; /*endif*/ } /*endif*/ } /*endfor*/ } /*endif*/ return NULL;}static int CheckIMName (Xi18n i18n_core){ char *address = i18n_core->address.im_addr; int i; for (i = 0; _TransR[i].transportname; i++) { while (*address == ' ' || *address == '\t') address++; /*endwhile*/ if (strncmp (address, _TransR[i].transportname, _TransR[i].namelen) == 0 && address[_TransR[i].namelen] == '/') { if (_TransR[i].checkAddr (i18n_core, &_TransR[i], address + _TransR[i].namelen + 1) == True) { return True; } /*endif*/ return False; } /*endif*/ } /*endfor*/ return False;}static int SetXi18nSelectionOwner(Xi18n i18n_core){ Display *dpy = i18n_core->address.dpy; Window ims_win = i18n_core->address.im_window; Window root = RootWindow (dpy, DefaultScreen (dpy)); Atom realtype; int realformat; unsigned long bytesafter; long *data=NULL; unsigned long length; Atom atom; int i; int found; int forse = False; char buf[256]; (void)sprintf(buf, "@server=%s", i18n_core->address.im_name); if ((atom = XInternAtom(dpy, buf, False)) == 0) return False; i18n_core->address.selection = atom; if (XIM_Servers == None) XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False); /*endif*/ XGetWindowProperty (dpy, root, XIM_Servers, 0L, 1000000L, False, XA_ATOM, &realtype, &realformat, &length, &bytesafter, (unsigned char **) (&data)); if (realtype != None && (realtype != XA_ATOM || realformat != 32)) { if (data != NULL) XFree ((char *) data); return False; } found = False; for (i = 0; i < length; i++) { if (data[i] == atom) { Window owner; found = True; if ((owner = XGetSelectionOwner (dpy, atom)) != ims_win) { if (owner == None || forse == True) XSetSelectionOwner (dpy, atom, ims_win, CurrentTime); else return False; } break; } } if (found == False) { XSetSelectionOwner (dpy, atom, ims_win, CurrentTime); XChangeProperty (dpy, root, XIM_Servers, XA_ATOM, 32, PropModePrepend, (unsigned char *) &atom, 1); } else { /* * We always need to generate the PropertyNotify to the Root Window */ XChangeProperty (dpy, root, XIM_Servers, XA_ATOM, 32, PropModePrepend, (unsigned char *) data, 0); } if (data != NULL) XFree ((char *) data); /* Intern "LOCALES" and "TRANSOPORT" Target Atoms */ i18n_core->address.Localename = XInternAtom (dpy, LOCALES, False); i18n_core->address.Transportname = XInternAtom (dpy, TRANSPORT, False); return (XGetSelectionOwner (dpy, atom) == ims_win);}/* XIM protocol methods */static void *xi18n_setup (Display *dpy, XIMArg *args){ Xi18n i18n_core; CARD16 endian = 1; if ((i18n_core = (Xi18n) malloc (sizeof (Xi18nCore))) == (Xi18n) NULL) return NULL; /*endif*/ memset (i18n_core, 0, sizeof (Xi18nCore)); i18n_core->address.dpy = dpy; if (ParseArgs (i18n_core, I18N_OPEN, args) != NULL) { XFree (i18n_core); return NULL; } /*endif*/ if (*(char *) &endian) i18n_core->address.im_byteOrder = 'l'; else i18n_core->address.im_byteOrder = 'B'; /*endif*/ /* install IMAttr and ICAttr list in i18n_core */ _Xi18nInitAttrList (i18n_core); /* install IMExtension list in i18n_core */ _Xi18nInitExtension (i18n_core); return i18n_core;}static void ReturnSelectionNotify (Xi18n i18n_core, XSelectionRequestEvent *ev){ XEvent event; Display *dpy = i18n_core->address.dpy; char buf[256]; event.type = SelectionNotify; event.xselection.requestor = ev->requestor; event.xselection.selection = ev->selection; event.xselection.target = ev->target; event.xselection.time = ev->time; event.xselection.property = ev->property; if (ev->target == i18n_core->address.Localename) { sprintf (buf, "@locale=%s", i18n_core->address.im_locale); } else if (ev->target == i18n_core->address.Transportname) { sprintf (buf, "@transport=%s", i18n_core->address.im_addr); } /*endif*/ XChangeProperty (dpy, event.xselection.requestor, ev->target, ev->target, 8, PropModeReplace, (unsigned char *) buf, strlen (buf)); XSendEvent (dpy, event.xselection.requestor, False, NoEventMask, &event); XFlush (i18n_core->address.dpy);}static Bool WaitXSelectionRequest (Display *dpy, Window win, XEvent *ev, XPointer client_data){ XIMS ims = (XIMS) client_data; Xi18n i18n_core = ims->protocol; if (((XSelectionRequestEvent *) ev)->selection == i18n_core->address.selection) { ReturnSelectionNotify (i18n_core, (XSelectionRequestEvent *) ev); return True; } /*endif*/ return False;}static Status xi18n_openIM(XIMS ims){ Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; if (!CheckIMName (i18n_core) || !SetXi18nSelectionOwner (i18n_core) || !i18n_core->methods.begin (ims)) { XFree (i18n_core->address.im_name); XFree (i18n_core->address.im_locale); XFree (i18n_core->address.im_addr); XFree (i18n_core); return False; } /*endif*/ _XRegisterFilterByType (dpy, i18n_core->address.im_window, SelectionRequest, SelectionRequest, WaitXSelectionRequest, ims); XFlush(dpy); return True;}static Status xi18n_closeIM(XIMS ims){ Xi18n i18n_core = ims->protocol; Window ims_win = i18n_core->address.im_window; Display *dpy = i18n_core->address.dpy; Atom atom = i18n_core->address.selection; Window root = RootWindow (dpy, DefaultScreen (dpy)); Atom realtype; int realformat; unsigned long length; unsigned long bytesafter; long *data, *new_data; int i, j; if (!i18n_core->methods.end (ims))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -