little style fixes
This commit is contained in:
parent
344c04af12
commit
561cf3719f
|
@ -50,7 +50,7 @@ static char *glyphs_utf8[512];
|
|||
static int input_position;
|
||||
static i3Font font;
|
||||
static char *prompt;
|
||||
static int prompt_len;
|
||||
static size_t prompt_len;
|
||||
static int limit;
|
||||
xcb_window_t root;
|
||||
xcb_connection_t *conn;
|
||||
|
|
|
@ -119,7 +119,7 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne
|
|||
params->workspaces_walk->name[len] = '\0';
|
||||
|
||||
/* Convert the name to ucs2, save its length in glyphs and calculate its rendered width */
|
||||
int ucs2_len;
|
||||
size_t ucs2_len;
|
||||
xcb_char2b_t *ucs2_name = (xcb_char2b_t*) convert_utf8_to_ucs2(params->workspaces_walk->name, &ucs2_len);
|
||||
params->workspaces_walk->ucs2_name = ucs2_name;
|
||||
params->workspaces_walk->name_glyphs = ucs2_len;
|
||||
|
|
|
@ -104,13 +104,13 @@ int _xcb_request_failed(xcb_void_cookie_t cookie, char *err_msg, int line) {
|
|||
*
|
||||
*/
|
||||
void refresh_statusline() {
|
||||
int glyph_count;
|
||||
size_t glyph_count;
|
||||
|
||||
if (statusline == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_char2b_t *text = (xcb_char2b_t*) convert_utf8_to_ucs2(statusline, &glyph_count);
|
||||
xcb_char2b_t *text = (xcb_char2b_t*)convert_utf8_to_ucs2(statusline, &glyph_count);
|
||||
uint32_t old_statusline_width = statusline_width;
|
||||
statusline_width = predict_text_width((char*)text, glyph_count, true);
|
||||
/* If the statusline is bigger than our screen we need to make sure that
|
||||
|
|
|
@ -285,7 +285,7 @@ struct Window {
|
|||
char *name_json;
|
||||
|
||||
/** The length of the name in glyphs (not bytes) */
|
||||
int name_len;
|
||||
size_t name_len;
|
||||
|
||||
/** Whether the application used _NET_WM_NAME */
|
||||
bool uses_net_wm_name;
|
||||
|
|
|
@ -184,7 +184,7 @@ uint32_t get_mod_mask_for(uint32_t keysym,
|
|||
* the fonts 'fixed' or '-misc-*' will be loaded instead of exiting.
|
||||
*
|
||||
*/
|
||||
i3Font load_font(const char *pattern, bool fallback);
|
||||
i3Font load_font(const char *pattern, const bool fallback);
|
||||
|
||||
/**
|
||||
* Converts the given string to UTF-8 from UCS-2 big endian. The return value
|
||||
|
@ -200,7 +200,7 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs);
|
|||
* returned. It has to be freed when done.
|
||||
*
|
||||
*/
|
||||
xcb_char2b_t *convert_utf8_to_ucs2(char *input, int *real_strlen);
|
||||
xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen);
|
||||
|
||||
/**
|
||||
* Defines the font to be used for the forthcoming draw_text and
|
||||
|
|
44
libi3/font.c
44
libi3/font.c
|
@ -22,7 +22,7 @@ static const i3Font *savedFont = NULL;
|
|||
* the fonts 'fixed' or '-misc-*' will be loaded instead of exiting.
|
||||
*
|
||||
*/
|
||||
i3Font load_font(const char *pattern, bool fallback) {
|
||||
i3Font load_font(const char *pattern, const bool fallback) {
|
||||
i3Font font;
|
||||
|
||||
/* Send all our requests first */
|
||||
|
@ -113,15 +113,7 @@ void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawabl
|
|||
}
|
||||
|
||||
/* Convert the text into UCS-2 so we can do basic pointer math */
|
||||
char *input;
|
||||
if (is_ucs2) {
|
||||
input = text;
|
||||
}
|
||||
else {
|
||||
int real_strlen;
|
||||
input = (char*)convert_utf8_to_ucs2(text, &real_strlen);
|
||||
text_len = real_strlen;
|
||||
}
|
||||
char *input = (is_ucs2 ? text : (char*)convert_utf8_to_ucs2(text, &text_len));
|
||||
|
||||
/* The X11 protocol limits text drawing to 255 chars, so we may need
|
||||
* multiple calls */
|
||||
|
@ -129,7 +121,7 @@ void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawabl
|
|||
int offset = 0;
|
||||
for (;;) {
|
||||
/* Calculate the size of this chunk */
|
||||
int chunk_size = text_len > 255 ? 255 : text_len;
|
||||
int chunk_size = (text_len > 255 ? 255 : text_len);
|
||||
xcb_char2b_t *chunk = (xcb_char2b_t*)input + offset;
|
||||
|
||||
/* Draw it */
|
||||
|
@ -153,11 +145,11 @@ void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawabl
|
|||
}
|
||||
|
||||
static int xcb_query_text_width(xcb_char2b_t *text, size_t text_len) {
|
||||
/* Make the user know we're using the slow path */
|
||||
static bool first = true;
|
||||
if (first) {
|
||||
/* Make the user know we’re using the slow path, but only once. */
|
||||
static bool first_invocation = true;
|
||||
if (first_invocation) {
|
||||
fprintf(stderr, "Using slow code path for text extents\n");
|
||||
first = false;
|
||||
first_invocation = false;
|
||||
}
|
||||
|
||||
/* Query the text width */
|
||||
|
@ -187,21 +179,16 @@ static int xcb_query_text_width(xcb_char2b_t *text, size_t text_len) {
|
|||
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 {
|
||||
int real_strlen;
|
||||
input = convert_utf8_to_ucs2(text, &real_strlen);
|
||||
text_len = real_strlen;
|
||||
}
|
||||
if (is_ucs2)
|
||||
input = (xcb_char2b_t*)text;
|
||||
else
|
||||
input = convert_utf8_to_ucs2(text, &text_len);
|
||||
|
||||
int width;
|
||||
if (savedFont->table == NULL) {
|
||||
/* If we don't have a font table, fall back to querying the server */
|
||||
width = xcb_query_text_width(input, text_len);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Save some pointers for convenience */
|
||||
xcb_query_font_reply_t *font_info = savedFont->info;
|
||||
xcb_charinfo_t *font_table = savedFont->table;
|
||||
|
@ -213,10 +200,11 @@ int predict_text_width(char *text, size_t text_len, bool is_ucs2) {
|
|||
int row = input[i].byte1;
|
||||
int col = input[i].byte2;
|
||||
|
||||
if (row < font_info->min_byte1 || row > font_info->max_byte1 ||
|
||||
col < font_info->min_char_or_byte2 || col > font_info->max_char_or_byte2) {
|
||||
if (row < font_info->min_byte1 ||
|
||||
row > font_info->max_byte1 ||
|
||||
col < font_info->min_char_or_byte2 ||
|
||||
col > font_info->max_char_or_byte2)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Don't you ask me, how this one works… (Merovius) */
|
||||
info = &font_table[((row - font_info->min_byte1) *
|
||||
|
|
|
@ -60,7 +60,7 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
|
|||
* returned. It has to be freed when done.
|
||||
*
|
||||
*/
|
||||
xcb_char2b_t *convert_utf8_to_ucs2(char *input, int *real_strlen) {
|
||||
xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen) {
|
||||
/* Calculate the input buffer size (UTF-8 is strlen-safe) */
|
||||
size_t input_size = strlen(input);
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ void handle_signal(int sig, siginfo_t *info, void *data) {
|
|||
int height = 13 + (crash_text_num * config.font.height);
|
||||
|
||||
/* calculate width for longest text */
|
||||
int text_len = strlen(crash_text[crash_text_longest]);
|
||||
size_t text_len = strlen(crash_text[crash_text_longest]);
|
||||
xcb_char2b_t *longest_text = convert_utf8_to_ucs2(crash_text[crash_text_longest], &text_len);
|
||||
int font_width = predict_text_width((char *)longest_text, text_len, true);
|
||||
int width = font_width + 20;
|
||||
|
|
|
@ -68,7 +68,7 @@ void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool befo
|
|||
return;
|
||||
}
|
||||
/* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
|
||||
int len;
|
||||
size_t len;
|
||||
xcb_char2b_t *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
|
||||
if (ucs2_name == NULL) {
|
||||
LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
|
||||
|
|
Loading…
Reference in New Issue