sockfd = ipc_connect(socket_path);
if (prompt != NULL)
- prompt_offset = predict_text_width((char *)i3string_as_ucs2(prompt), i3string_get_num_glyphs(prompt), true);
+ prompt_offset = predict_text_width(prompt);
int screens;
conn = xcb_connect(NULL, &screens);
/* Save the name */
params->workspaces_walk->name = i3string_from_utf8_with_length((const char *)val, len);
- /* Convert the name to ucs2, save its length in glyphs and calculate its rendered width */
+ /* Save its rendered width */
params->workspaces_walk->name_width =
- predict_text_width((char *)i3string_as_ucs2(params->workspaces_walk->name),
- i3string_get_num_glyphs(params->workspaces_walk->name), true);
+ predict_text_width(params->workspaces_walk->name);
DLOG("Got Workspace %s, name_width: %d, glyphs: %zu\n",
i3string_as_utf8(params->workspaces_walk->name),
if (i3string_get_num_bytes(block->full_text) == 0)
continue;
- block->width = predict_text_width((char *)i3string_as_ucs2(block->full_text), i3string_get_num_glyphs(block->full_text), true);
+ block->width = predict_text_width(block->full_text);
/* If this is not the last block, add some pixels for a separator. */
if (TAILQ_NEXT(block, blocks) != NULL)
block->width += 9;
xcb_gcontext_t gc, int x, int y, int max_width);
/**
- * Predict the text width in pixels for the given text. Text can be specified
- * as UCS-2 or UTF-8.
+ * Predict the text width in pixels for the given text. Text must be
+ * specified as an i3String.
*
*/
-int predict_text_width(char *text, size_t text_len, bool is_ucs2);
+int predict_text_width(i3String *text);
/**
* Returns true if this version of i3 is a debug build (anything which is not a
xcb_change_gc(conn, gc, mask, values);
}
+static int predict_text_width_xcb(const xcb_char2b_t *text, size_t text_len);
+
static void draw_text_xcb(const xcb_char2b_t *text, size_t text_len, xcb_drawable_t drawable,
xcb_gcontext_t gc, int x, int y, int max_width) {
/* X11 coordinates for fonts start at the baseline */
break;
/* Advance pos_x based on the predicted text width */
- x += predict_text_width((char*)chunk, chunk_size, true);
+ x += predict_text_width_xcb(chunk, chunk_size);
}
}
}
}
-static int xcb_query_text_width(xcb_char2b_t *text, size_t text_len) {
+static int xcb_query_text_width(const xcb_char2b_t *text, size_t text_len) {
/* Make the user know we’re using the slow path, but only once. */
static bool first_invocation = true;
if (first_invocation) {
return width;
}
-/*
- * Predict the text width in pixels for the given text. Text can be specified
- * as UCS-2 or UTF-8.
- *
- */
-int predict_text_width(char *text, size_t text_len, bool is_ucs2) {
- /* Convert the text into UTF-16 so we can do basic pointer math */
- xcb_char2b_t *input;
- if (is_ucs2)
- input = (xcb_char2b_t*)text;
- else
- input = convert_utf8_to_ucs2(text, &text_len);
+static int predict_text_width_xcb(const xcb_char2b_t *input, size_t text_len) {
+ if (text_len == 0)
+ return 0;
int width;
if (savedFont->table == NULL) {
}
}
- /* If we had to convert, free the converted string */
- if (!is_ucs2)
- free(input);
-
return width;
}
+
+/*
+ * Predict the text width in pixels for the given text. Text must be
+ * specified as an i3String.
+ *
+ */
+int predict_text_width(i3String *text) {
+ return predict_text_width_xcb(i3string_as_ucs2(text), i3string_get_num_glyphs(text));
+}
}
crash_text_i3strings[crash_text_length] = NULL;
/* calculate width for longest text */
- int font_width = predict_text_width((char *)i3string_as_ucs2(crash_text_i3strings[crash_text_longest]), i3string_get_num_glyphs(crash_text_i3strings[crash_text_longest]), true);
+ int font_width = predict_text_width(crash_text_i3strings[crash_text_longest]);
int width = font_width + 20;
/* Open a popup window on each virtual screen */