MBKeyboardRow* mb_kbd_row_new(MBKeyboard *kbd) { MBKeyboardRow *row = NULL; row = util_malloc0(sizeof(MBKeyboardRow)); row->kbd = kbd; return row; }
MBKeyboardLayout* mb_kbd_layout_new(MBKeyboard *kbd, const char *id) { MBKeyboardLayout *layout = NULL; layout = util_malloc0(sizeof(MBKeyboardLayout)); layout->kbd = kbd; layout->id = strdup(id); return layout; }
MBKeyboardKey* mb_kbd_key_new(MBKeyboard *kbd) { MBKeyboardKey *key = NULL; int i; key = util_malloc0(sizeof(MBKeyboardKey)); key->kbd = kbd; for (i=0; i<N_MBKeyboardKeyStateTypes; i++) key->states[i] = NULL; return key; }
int mb_kbd_config_load(MBKeyboard *kbd, char *variant) { char *data; XML_Parser p; MBKeyboardConfigState *state; if (!(data = load_config_file ("keyboard", variant, 1, &kbd->config_file))) util_fatal_error("Couldn't find a keyboard config file\n"); p = XML_ParserCreate(NULL); if (!p) util_fatal_error("Couldn't allocate memory for XML parser\n"); if (variant && !strstr(kbd->config_file, variant)) fprintf(stderr, "matchbox-keyboard: *Warning* Unable to locate variant: %s\n" " falling back to %s\n", variant, kbd->config_file); state = util_malloc0(sizeof(MBKeyboardConfigState)); state->keyboard = kbd; state->parser = p; XML_SetElementHandler(p, config_xml_start_cb, NULL); /* XML_SetCharacterDataHandler(p, chars); */ XML_SetUserData(p, (void *)state); if (! XML_Parse(p, data, strlen(data), 1)) { fprintf(stderr, "matchbox-keyboard:%s:%d: XML Parse error:%s\n", kbd->config_file, (int)XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p))); util_fatal_error("XML Parse failed.\n"); } XML_ParserFree (p); return 1; }
MBKeyboardImage* mb_kbd_image_new (MBKeyboard *kbd, const char *filename) { MBKeyboardUI *ui; MBKeyboardImage *img; unsigned char *data, *p; int width, height, x, y; XRenderPictFormat *ren_fmt; XRenderPictureAttributes ren_attr; GC gc; XImage *ximg; ui = kbd->ui; data = png_file_load (filename, &width, &height); if (data == NULL || width == 0 || height == 0) { if (data) free(data); return NULL; } img = util_malloc0(sizeof(MBKeyboardImage)); img->width = width; img->height = height; ren_fmt = XRenderFindStandardFormat(mb_kbd_ui_x_display(ui), PictStandardARGB32); img->xdraw = XCreatePixmap(mb_kbd_ui_x_display(ui), mb_kbd_ui_x_win_root(ui), width, height, ren_fmt->depth); XSync(mb_kbd_ui_x_display(ui), False); ren_attr.dither = True; ren_attr.component_alpha = True; ren_attr.repeat = False; img->xpic = XRenderCreatePicture(mb_kbd_ui_x_display(ui), img->xdraw, ren_fmt, CPRepeat|CPDither|CPComponentAlpha, &ren_attr); gc = XCreateGC(mb_kbd_ui_x_display(ui), img->xdraw, 0, NULL); ximg = XCreateImage(mb_kbd_ui_x_display(ui), DefaultVisual(mb_kbd_ui_x_display(ui), mb_kbd_ui_x_screen(ui)), ren_fmt->depth, ZPixmap, 0, NULL, width, height, 32, 0); ximg->data = malloc(ximg->bytes_per_line * ximg->height); p = data; for (y = 0; y < height; y++) for (x = 0; x < width; x++) { unsigned char a, r, g, b; r = *p++; g = *p++; b = *p++; a = *p++; r = (r * (a + 1)) / 256; /* premult */ g = (g * (a + 1)) / 256; b = (b * (a + 1)) / 256; XPutPixel(ximg, x, y, (a << 24) | (r << 16) | (g << 8) | b); } XPutImage(mb_kbd_ui_x_display(ui), img->xdraw, gc, ximg, 0, 0, 0, 0, width, height); free(ximg->data); ximg->data = NULL; XDestroyImage(ximg); XFreeGC (mb_kbd_ui_x_display(ui), gc); free(data); return img; }
static void _mb_kbd_key_init_state(MBKeyboardKey *key, MBKeyboardKeyStateType state) { key->states[state] = util_malloc0(sizeof(MBKeyboardKeyState)); }