i3-input: Store and use xcb_char2b_t directly

This commit is contained in:
Quentin Glidic 2012-08-08 15:08:05 +02:00
parent d89cb04c98
commit 284294e9c2
1 changed files with 8 additions and 15 deletions

View File

@ -45,7 +45,7 @@ static bool modeswitch_active = false;
static xcb_window_t win; static xcb_window_t win;
static xcb_pixmap_t pixmap; static xcb_pixmap_t pixmap;
static xcb_gcontext_t pixmap_gc; static xcb_gcontext_t pixmap_gc;
static char *glyphs_ucs[512]; static xcb_char2b_t glyphs_ucs[512];
static char *glyphs_utf8[512]; static char *glyphs_utf8[512];
static int input_position; static int input_position;
static i3Font font; static i3Font font;
@ -102,11 +102,7 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t
} }
/* … and the text */ /* … and the text */
if (input_position > 0) if (input_position > 0)
{ draw_text((char *)glyphs_ucs, input_position, true, pixmap, pixmap_gc, 4, 4 + prompt_offset, 492 - prompt_offset);
char *full_text = (char *)concat_strings(glyphs_ucs, input_position);
draw_text(full_text, input_position, true, pixmap, pixmap_gc, 4, 4 + prompt_offset, 492 - prompt_offset);
free(full_text);
}
/* Copy the contents of the pixmap to the real window */ /* Copy the contents of the pixmap to the real window */
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8); xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8);
@ -212,7 +208,6 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
return 1; return 1;
input_position--; input_position--;
free(glyphs_ucs[input_position]);
free(glyphs_utf8[input_position]); free(glyphs_utf8[input_position]);
handle_expose(NULL, conn, NULL); handle_expose(NULL, conn, NULL);
@ -243,18 +238,16 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
return 1; return 1;
} }
/* store the UCS into a string */ xcb_char2b_t inp;
uint8_t inp[3] = {(ucs & 0xFF00) >> 8, (ucs & 0xFF), 0}; inp.byte1 = ( ucs & 0xff00 ) >> 2;
inp.byte2 = ( ucs & 0x00ff ) >> 0;
printf("inp[0] = %02x, inp[1] = %02x, inp[2] = %02x\n", inp[0], inp[1], inp[2]); printf("inp.byte1 = %02x, inp.byte2 = %02x\n", inp.byte1, inp.byte2);
/* convert it to UTF-8 */ /* convert it to UTF-8 */
char *out = convert_ucs2_to_utf8((xcb_char2b_t*)inp, 1); char *out = convert_ucs2_to_utf8(&inp, 1);
printf("converted to %s\n", out); printf("converted to %s\n", out);
glyphs_ucs[input_position] = malloc(3 * sizeof(uint8_t)); glyphs_ucs[input_position] = inp;
if (glyphs_ucs[input_position] == NULL)
err(EXIT_FAILURE, "malloc() failed\n");
memcpy(glyphs_ucs[input_position], inp, 3);
glyphs_utf8[input_position] = out; glyphs_utf8[input_position] = out;
input_position++; input_position++;