From: Michael Stapelberg Date: Mon, 21 Nov 2011 21:48:24 +0000 (+0000) Subject: little style fixes X-Git-Tag: 4.2~231^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=561cf3719fd293f3dd4e7b22fc92d8e0a22ae1d6;p=i3%2Fi3 little style fixes --- diff --git a/i3-input/main.c b/i3-input/main.c index 7602e32b..25ccceaa 100644 --- a/i3-input/main.c +++ b/i3-input/main.c @@ -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; diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index a6312e38..5df1899f 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -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; diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index d907d083..4a5ff69a 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -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 diff --git a/include/data.h b/include/data.h index 740278ae..3bc425d9 100644 --- a/include/data.h +++ b/include/data.h @@ -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; diff --git a/include/libi3.h b/include/libi3.h index 4fb72717..17f8a5eb 100644 --- a/include/libi3.h +++ b/include/libi3.h @@ -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 diff --git a/libi3/font.c b/libi3/font.c index c6bdc093..045972d9 100644 --- a/libi3/font.c +++ b/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 */ @@ -99,7 +99,7 @@ void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background * */ void draw_text(char *text, size_t text_len, bool is_ucs2, xcb_drawable_t drawable, - xcb_gcontext_t gc, int x, int y, int max_width) { + xcb_gcontext_t gc, int x, int y, int max_width) { assert(savedFont != NULL); assert(text_len != 0); @@ -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) * diff --git a/libi3/ucs2_conversion.c b/libi3/ucs2_conversion.c index b170ac8d..6f7cf287 100644 --- a/libi3/ucs2_conversion.c +++ b/libi3/ucs2_conversion.c @@ -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); diff --git a/src/sighandler.c b/src/sighandler.c index e2cd15a1..ca74813d 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -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; diff --git a/src/window.c b/src/window.c index 17f2d4a2..270314ea 100644 --- a/src/window.c +++ b/src/window.c @@ -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");