MessageWindow* CreateMessageWindow (FcitxLightUI * lightui) { MessageWindow* messageWindow = fcitx_malloc0(sizeof(MessageWindow)); Display *dpy = lightui->dpy; int iScreen= lightui->iScreen; messageWindow->owner = lightui; messageWindow->color.r = messageWindow->color.g = messageWindow->color.b = 220.0 / 256; messageWindow->fontColor.r = messageWindow->fontColor.g = messageWindow->fontColor.b = 0; messageWindow->fontSize = 15; messageWindow->width = 1; messageWindow->height = 1; messageWindow->window = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy), 0, 0, 1, 1, 0, WhitePixel (dpy, DefaultScreen (dpy)), WhitePixel (dpy, DefaultScreen (dpy))); if (messageWindow->window == None) return False; InitMessageWindowProperty (messageWindow); XSelectInput (dpy, messageWindow->window, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask ); FcitxModuleFunctionArg arg; arg.args[0] = MessageWindowEventHandler; arg.args[1] = messageWindow; InvokeFunction(lightui->owner, FCITX_X11, ADDXEVENTHANDLER, arg); return messageWindow; }
XlibMenu* CreateXlibMenu(FcitxLightUI *lightui) { XlibMenu *menu = fcitx_malloc0(sizeof(XlibMenu)); menu->owner = lightui; InitXlibMenu(menu); FcitxModuleFunctionArg arg; arg.args[0] = MenuWindowEventHandler; arg.args[1] = menu; InvokeFunction(lightui->owner, FCITX_X11, ADDXEVENTHANDLER, arg); arg.args[0] = ReloadXlibMenu; arg.args[1] = menu; InvokeFunction(lightui->owner, FCITX_X11, ADDCOMPOSITEHANDLER, arg); return menu; }
LightUIImage* LoadImage(struct _FcitxLightUI* lightui, const char* name) { XImage* xpm = NULL, *mask = NULL; LightUIImage *image = NULL; HASH_FIND_STR(lightui->imageTable, name, image); if (image != NULL) return image; if ( strlen(name) > 0 ) { int i = 0; while (builtInImage[i].name != NULL) { if (strcmp(builtInImage[i].name, name) == 0) { XpmAttributes attrib; attrib.valuemask = 0; XpmCreateImageFromData (lightui->dpy, builtInImage[i].data , &xpm, &mask, &attrib); break; } i ++; } } if (xpm != NULL) { image = fcitx_malloc0(sizeof(LightUIImage)); image->name = strdup(name); image->image = xpm; image->mask = mask; image->pixmask = XCreatePixmap(lightui->dpy, DefaultRootWindow(lightui->dpy), mask->width, mask->height, mask->depth); GC gc = XCreateGC (lightui->dpy, image->pixmask, 0, NULL); XPutImage(lightui->dpy, image->pixmask, gc, image->mask, 0, 0, 0, 0, mask->width, mask->height); XFreeGC(lightui->dpy, gc); HASH_ADD_KEYPTR(hh, lightui->imageTable, image->name, strlen(image->name), image); return image; } return NULL; }
FcitxIMClient* FcitxIMClientOpen(FcitxIMClientConnectCallback connectcb, FcitxIMClientDestroyCallback destroycb, GObject* data) { FcitxIMClient* client = fcitx_malloc0(sizeof(FcitxIMClient)); GError *error = NULL; client->connectcb = connectcb; client->destroycb = destroycb; client->data = data; client->conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error); client->id = -1; /* You must have dbus to make it works */ if (client->conn == NULL) { g_warning("%s", error->message); free(client); return NULL; } client->dbusproxy = dbus_g_proxy_new_for_name(client->conn, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!client->dbusproxy) { g_object_unref(client->conn); free(client); return NULL; } sprintf(client->servicename, "%s-%d", FCITX_DBUS_SERVICE, FcitxGetDisplayNumber()); dbus_g_object_register_marshaller(fcitx_marshall_VOID__STRING_STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal(client->dbusproxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal(client->dbusproxy, "NameOwnerChanged", G_CALLBACK(_changed_cb), client, NULL); client->triggerkey[0].sym = client->triggerkey[0].state = client->triggerkey[1].sym = client->triggerkey[1].state = 0; FcitxIMClientCreateIC(client); return client; }
static unsigned int text_width(char* str) { if (iconvW == NULL) iconvW = iconv_open("ucs-4be", "utf-8"); if (iconvW == (iconv_t) -1) { return utf8_strlen(str); } else { size_t len = strlen(str); size_t charlen = utf8_strlen(str); unsigned *wmessage; size_t wlen = (len + 1) * sizeof (unsigned); wmessage = (unsigned *) fcitx_malloc0 ((len + 1) * sizeof (unsigned)); char *inp = str; char *outp = (char*) wmessage; iconv(iconvW, &inp, &len, &outp, &wlen); int i = 0; int width = 0; for (i = 0; i < charlen; i ++) { if (is_double_width(wmessage[i])) width += 2; else width += 1; } free(wmessage); return width; } }