format **/*.c with clang-format-3.5
This has multiple effects: 1) The i3 codebase is now consistently formatted. clang-format uncovered plenty of places where inconsistent code made it into our code base. 2) When writing code, you don’t need to think or worry about our coding style. Write it in yours, then run clang-format-3.5 3) When submitting patches, we don’t need to argue about coding style. The basic idea is that we don’t want to care about _how_ we write the code, but _what_ it does :). The coding style that we use is defined in the .clang-format config file and is based on the google style, but adapted in such a way that the number of modifications to the i3 code base is minimal.
This commit is contained in:
@ -12,5 +12,5 @@ extern xcb_screen_t *root_screen;
|
||||
int logical_px(const int logical) {
|
||||
const int dpi = (double)root_screen->height_in_pixels * 25.4 /
|
||||
(double)root_screen->height_in_millimeters;
|
||||
return ceil((dpi / 96.0) * logical);
|
||||
return ceil((dpi / 96.0) * logical);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window
|
||||
generated_event->above_sibling = XCB_NONE;
|
||||
generated_event->override_redirect = false;
|
||||
|
||||
xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)generated_event);
|
||||
xcb_send_event(conn, false, window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *)generated_event);
|
||||
xcb_flush(conn);
|
||||
|
||||
free(event);
|
||||
|
43
libi3/font.c
43
libi3/font.c
@ -69,8 +69,7 @@ static bool load_pango_font(i3Font *font, const char *desc) {
|
||||
|
||||
LOG("Using Pango font %s, size %d\n",
|
||||
pango_font_description_get_family(font->specific.pango_desc),
|
||||
pango_font_description_get_size(font->specific.pango_desc) / PANGO_SCALE
|
||||
);
|
||||
pango_font_description_get_size(font->specific.pango_desc) / PANGO_SCALE);
|
||||
|
||||
/* We cache root_visual_type here, since you must call
|
||||
* load_pango_font before any other pango function
|
||||
@ -103,11 +102,11 @@ static bool load_pango_font(i3Font *font, const char *desc) {
|
||||
*
|
||||
*/
|
||||
static void draw_text_pango(const char *text, size_t text_len,
|
||||
xcb_drawable_t drawable, int x, int y, int max_width) {
|
||||
xcb_drawable_t drawable, int x, int y, int max_width) {
|
||||
/* Create the Pango layout */
|
||||
/* root_visual_type is cached in load_pango_font */
|
||||
cairo_surface_t *surface = cairo_xcb_surface_create(conn, drawable,
|
||||
root_visual_type, x + max_width, y + savedFont->height);
|
||||
root_visual_type, x + max_width, y + savedFont->height);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
PangoLayout *layout = create_layout_with_dpi(cr);
|
||||
gint height;
|
||||
@ -188,7 +187,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
|
||||
/* Send all our requests first */
|
||||
font.specific.xcb.id = xcb_generate_id(conn);
|
||||
xcb_void_cookie_t font_cookie = xcb_open_font_checked(conn, font.specific.xcb.id,
|
||||
strlen(pattern), pattern);
|
||||
strlen(pattern), pattern);
|
||||
xcb_query_font_cookie_t info_cookie = xcb_query_font(conn, font.specific.xcb.id);
|
||||
|
||||
/* Check for errors. If errors, fall back to default font. */
|
||||
@ -201,7 +200,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
|
||||
pattern, error->error_code);
|
||||
pattern = "fixed";
|
||||
font_cookie = xcb_open_font_checked(conn, font.specific.xcb.id,
|
||||
strlen(pattern), pattern);
|
||||
strlen(pattern), pattern);
|
||||
info_cookie = xcb_query_font(conn, font.specific.xcb.id);
|
||||
|
||||
/* Check if we managed to open 'fixed' */
|
||||
@ -212,12 +211,13 @@ i3Font load_font(const char *pattern, const bool fallback) {
|
||||
ELOG("Could not open fallback font 'fixed', trying with '-misc-*'.\n");
|
||||
pattern = "-misc-*";
|
||||
font_cookie = xcb_open_font_checked(conn, font.specific.xcb.id,
|
||||
strlen(pattern), pattern);
|
||||
strlen(pattern), pattern);
|
||||
info_cookie = xcb_query_font(conn, font.specific.xcb.id);
|
||||
|
||||
if ((error = xcb_request_check(conn, font_cookie)) != NULL)
|
||||
errx(EXIT_FAILURE, "Could open neither requested font nor fallbacks "
|
||||
"(fixed or -misc-*): X11 error %d", error->error_code);
|
||||
"(fixed or -misc-*): X11 error %d",
|
||||
error->error_code);
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background
|
||||
case FONT_TYPE_XCB: {
|
||||
/* Change the font and colors in the GC */
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||
uint32_t values[] = { foreground, background, savedFont->specific.xcb.id };
|
||||
uint32_t values[] = {foreground, background, savedFont->specific.xcb.id};
|
||||
xcb_change_gc(conn, gc, mask, values);
|
||||
break;
|
||||
}
|
||||
@ -314,7 +314,7 @@ void set_font_colors(xcb_gcontext_t gc, uint32_t foreground, uint32_t background
|
||||
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) {
|
||||
xcb_gcontext_t gc, int x, int y, int max_width) {
|
||||
/* X11 coordinates for fonts start at the baseline */
|
||||
int pos_y = y + savedFont->specific.xcb.info->font_ascent;
|
||||
|
||||
@ -360,7 +360,7 @@ void draw_text(i3String *text, xcb_drawable_t drawable,
|
||||
return;
|
||||
case FONT_TYPE_XCB:
|
||||
draw_text_xcb(i3string_as_ucs2(text), i3string_get_num_glyphs(text),
|
||||
drawable, gc, x, y, max_width);
|
||||
drawable, gc, x, y, max_width);
|
||||
break;
|
||||
#if PANGO_SUPPORT
|
||||
case FONT_TYPE_PANGO:
|
||||
@ -379,15 +379,14 @@ void draw_text(i3String *text, xcb_drawable_t drawable,
|
||||
*
|
||||
*/
|
||||
void draw_text_ascii(const char *text, 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);
|
||||
|
||||
switch (savedFont->type) {
|
||||
case FONT_TYPE_NONE:
|
||||
/* Nothing to do */
|
||||
return;
|
||||
case FONT_TYPE_XCB:
|
||||
{
|
||||
case FONT_TYPE_XCB: {
|
||||
size_t text_len = strlen(text);
|
||||
if (text_len > 255) {
|
||||
/* The text is too long to draw it directly to X */
|
||||
@ -425,9 +424,9 @@ static int xcb_query_text_width(const xcb_char2b_t *text, size_t text_len) {
|
||||
/* Query the text width */
|
||||
xcb_generic_error_t *error;
|
||||
xcb_query_text_extents_cookie_t cookie = xcb_query_text_extents(conn,
|
||||
savedFont->specific.xcb.id, text_len, (xcb_char2b_t*)text);
|
||||
savedFont->specific.xcb.id, text_len, (xcb_char2b_t *)text);
|
||||
xcb_query_text_extents_reply_t *reply = xcb_query_text_extents_reply(conn,
|
||||
cookie, &error);
|
||||
cookie, &error);
|
||||
if (reply == NULL) {
|
||||
/* We return a safe estimate because a rendering error is better than
|
||||
* a crash. Plus, the user will see the error in his log. */
|
||||
@ -469,14 +468,14 @@ static int predict_text_width_xcb(const xcb_char2b_t *input, size_t text_len) {
|
||||
|
||||
/* Don't you ask me, how this one works… (Merovius) */
|
||||
info = &font_table[((row - font_info->min_byte1) *
|
||||
(font_info->max_char_or_byte2 - font_info->min_char_or_byte2 + 1)) +
|
||||
(col - font_info->min_char_or_byte2)];
|
||||
(font_info->max_char_or_byte2 - font_info->min_char_or_byte2 + 1)) +
|
||||
(col - font_info->min_char_or_byte2)];
|
||||
|
||||
if (info->character_width != 0 ||
|
||||
(info->right_side_bearing |
|
||||
info->left_side_bearing |
|
||||
info->ascent |
|
||||
info->descent) != 0) {
|
||||
(info->right_side_bearing |
|
||||
info->left_side_bearing |
|
||||
info->ascent |
|
||||
info->descent) != 0) {
|
||||
width += info->character_width;
|
||||
}
|
||||
}
|
||||
|
@ -15,87 +15,86 @@
|
||||
* Returned value must be freed by the caller.
|
||||
*/
|
||||
char *get_exe_path(const char *argv0) {
|
||||
size_t destpath_size = 1024;
|
||||
size_t tmp_size = 1024;
|
||||
char *destpath = smalloc(destpath_size);
|
||||
char *tmp = smalloc(tmp_size);
|
||||
|
||||
size_t destpath_size = 1024;
|
||||
size_t tmp_size = 1024;
|
||||
char *destpath = smalloc(destpath_size);
|
||||
char *tmp = smalloc(tmp_size);
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
/* Linux and Debian/kFreeBSD provide /proc/self/exe */
|
||||
/* Linux and Debian/kFreeBSD provide /proc/self/exe */
|
||||
#if defined(__linux__) || defined(__FreeBSD_kernel__)
|
||||
const char *exepath = "/proc/self/exe";
|
||||
const char *exepath = "/proc/self/exe";
|
||||
#elif defined(__FreeBSD__)
|
||||
const char *exepath = "/proc/curproc/file";
|
||||
const char *exepath = "/proc/curproc/file";
|
||||
#endif
|
||||
ssize_t linksize;
|
||||
ssize_t linksize;
|
||||
|
||||
while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
|
||||
destpath_size = destpath_size * 2;
|
||||
destpath = srealloc(destpath, destpath_size);
|
||||
}
|
||||
if (linksize != -1) {
|
||||
/* readlink() does not NULL-terminate strings, so we have to. */
|
||||
destpath[linksize] = '\0';
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
while ((linksize = readlink(exepath, destpath, destpath_size)) == (ssize_t)destpath_size) {
|
||||
destpath_size = destpath_size * 2;
|
||||
destpath = srealloc(destpath, destpath_size);
|
||||
}
|
||||
if (linksize != -1) {
|
||||
/* readlink() does not NULL-terminate strings, so we have to. */
|
||||
destpath[linksize] = '\0';
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* argv[0] is most likely a full path if it starts with a slash. */
|
||||
if (argv0[0] == '/') {
|
||||
free(tmp);
|
||||
free(destpath);
|
||||
return sstrdup(argv0);
|
||||
}
|
||||
/* argv[0] is most likely a full path if it starts with a slash. */
|
||||
if (argv0[0] == '/') {
|
||||
free(tmp);
|
||||
free(destpath);
|
||||
return sstrdup(argv0);
|
||||
}
|
||||
|
||||
/* if argv[0] contains a /, prepend the working directory */
|
||||
if (strchr(argv0, '/') != NULL) {
|
||||
char *retgcwd;
|
||||
while ((retgcwd = getcwd(tmp, tmp_size)) == NULL && errno == ERANGE) {
|
||||
tmp_size = tmp_size * 2;
|
||||
tmp = srealloc(tmp, tmp_size);
|
||||
}
|
||||
if (retgcwd != NULL) {
|
||||
free(destpath);
|
||||
sasprintf(&destpath, "%s/%s", tmp, argv0);
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
}
|
||||
/* if argv[0] contains a /, prepend the working directory */
|
||||
if (strchr(argv0, '/') != NULL) {
|
||||
char *retgcwd;
|
||||
while ((retgcwd = getcwd(tmp, tmp_size)) == NULL && errno == ERANGE) {
|
||||
tmp_size = tmp_size * 2;
|
||||
tmp = srealloc(tmp, tmp_size);
|
||||
}
|
||||
if (retgcwd != NULL) {
|
||||
free(destpath);
|
||||
sasprintf(&destpath, "%s/%s", tmp, argv0);
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fall back to searching $PATH (or _CS_PATH in absence of $PATH). */
|
||||
char *path = getenv("PATH");
|
||||
if (path == NULL) {
|
||||
/* _CS_PATH is typically something like "/bin:/usr/bin" */
|
||||
while (confstr(_CS_PATH, tmp, tmp_size) > tmp_size) {
|
||||
tmp_size = tmp_size * 2;
|
||||
tmp = srealloc(tmp, tmp_size);
|
||||
}
|
||||
sasprintf(&path, ":%s", tmp);
|
||||
} else {
|
||||
path = strdup(path);
|
||||
}
|
||||
const char *component;
|
||||
char *str = path;
|
||||
while (1) {
|
||||
if ((component = strtok(str, ":")) == NULL)
|
||||
break;
|
||||
str = NULL;
|
||||
free(destpath);
|
||||
sasprintf(&destpath, "%s/%s", component, argv0);
|
||||
/* Of course this is not 100% equivalent to actually exec()ing the
|
||||
/* Fall back to searching $PATH (or _CS_PATH in absence of $PATH). */
|
||||
char *path = getenv("PATH");
|
||||
if (path == NULL) {
|
||||
/* _CS_PATH is typically something like "/bin:/usr/bin" */
|
||||
while (confstr(_CS_PATH, tmp, tmp_size) > tmp_size) {
|
||||
tmp_size = tmp_size * 2;
|
||||
tmp = srealloc(tmp, tmp_size);
|
||||
}
|
||||
sasprintf(&path, ":%s", tmp);
|
||||
} else {
|
||||
path = strdup(path);
|
||||
}
|
||||
const char *component;
|
||||
char *str = path;
|
||||
while (1) {
|
||||
if ((component = strtok(str, ":")) == NULL)
|
||||
break;
|
||||
str = NULL;
|
||||
free(destpath);
|
||||
sasprintf(&destpath, "%s/%s", component, argv0);
|
||||
/* Of course this is not 100% equivalent to actually exec()ing the
|
||||
* binary, but meh. */
|
||||
if (access(destpath, X_OK) == 0) {
|
||||
free(path);
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
}
|
||||
free(destpath);
|
||||
free(path);
|
||||
free(tmp);
|
||||
if (access(destpath, X_OK) == 0) {
|
||||
free(path);
|
||||
free(tmp);
|
||||
return destpath;
|
||||
}
|
||||
}
|
||||
free(destpath);
|
||||
free(path);
|
||||
free(tmp);
|
||||
|
||||
/* Last resort: maybe it’s in /usr/bin? */
|
||||
return sstrdup("/usr/bin/i3-nagbar");
|
||||
/* Last resort: maybe it’s in /usr/bin? */
|
||||
return sstrdup("/usr/bin/i3-nagbar");
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols) {
|
||||
*
|
||||
*/
|
||||
uint32_t get_mod_mask_for(uint32_t keysym,
|
||||
xcb_key_symbols_t *symbols,
|
||||
xcb_get_modifier_mapping_reply_t *modmap_reply) {
|
||||
xcb_key_symbols_t *symbols,
|
||||
xcb_get_modifier_mapping_reply_t *modmap_reply) {
|
||||
xcb_keycode_t *codes, *modmap;
|
||||
xcb_keycode_t mod_code;
|
||||
|
||||
|
@ -32,7 +32,7 @@ int ipc_connect(const char *socket_path) {
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
||||
if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
|
||||
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
|
||||
err(EXIT_FAILURE, "Could not connect to i3");
|
||||
|
||||
return sockfd;
|
||||
|
@ -28,10 +28,9 @@ int ipc_send_message(int sockfd, const uint32_t message_size,
|
||||
const uint32_t message_type, const uint8_t *payload) {
|
||||
const i3_ipc_header_t header = {
|
||||
/* We don’t use I3_IPC_MAGIC because it’s a 0-terminated C string. */
|
||||
.magic = { 'i', '3', '-', 'i', 'p', 'c' },
|
||||
.magic = {'i', '3', '-', 'i', 'p', 'c'},
|
||||
.size = message_size,
|
||||
.type = message_type
|
||||
};
|
||||
.type = message_type};
|
||||
|
||||
size_t sent_bytes = 0;
|
||||
int n = 0;
|
||||
@ -40,7 +39,7 @@ int ipc_send_message(int sockfd, const uint32_t message_size,
|
||||
* buffers which cannot fit 14 bytes into them, so the write() will only be
|
||||
* called once. */
|
||||
while (sent_bytes < sizeof(i3_ipc_header_t)) {
|
||||
if ((n = write(sockfd, ((void*)&header) + sent_bytes, sizeof(i3_ipc_header_t) - sent_bytes)) == -1) {
|
||||
if ((n = write(sockfd, ((void *)&header) + sent_bytes, sizeof(i3_ipc_header_t) - sent_bytes)) == -1) {
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
return -1;
|
||||
|
@ -80,14 +80,14 @@ char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn,
|
||||
if (prop_reply->type == XCB_ATOM_CARDINAL) {
|
||||
/* We treat a CARDINAL as a >= 32-bit unsigned int. The only CARDINAL
|
||||
* we query is I3_PID, which is 32-bit. */
|
||||
if (asprintf(&content, "%u", *((unsigned int*)xcb_get_property_value(prop_reply))) == -1) {
|
||||
if (asprintf(&content, "%u", *((unsigned int *)xcb_get_property_value(prop_reply))) == -1) {
|
||||
free(atom_reply);
|
||||
free(prop_reply);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (asprintf(&content, "%.*s", xcb_get_property_value_length(prop_reply),
|
||||
(char*)xcb_get_property_value(prop_reply)) == -1) {
|
||||
(char *)xcb_get_property_value(prop_reply)) == -1) {
|
||||
free(atom_reply);
|
||||
free(prop_reply);
|
||||
return NULL;
|
||||
@ -99,4 +99,3 @@ char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn,
|
||||
free(prop_reply);
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
|
||||
|
||||
/* Do the conversion */
|
||||
size_t input_len = num_glyphs * sizeof(xcb_char2b_t);
|
||||
size_t rc = iconv(utf8_conversion_descriptor, (char**)&text,
|
||||
&input_len, &output, &output_size);
|
||||
size_t rc = iconv(utf8_conversion_descriptor, (char **)&text,
|
||||
&input_len, &output, &output_size);
|
||||
if (rc == (size_t)-1) {
|
||||
perror("Converting to UTF-8 failed");
|
||||
free(buffer);
|
||||
@ -83,8 +83,8 @@ xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen) {
|
||||
}
|
||||
|
||||
/* Do the conversion */
|
||||
size_t rc = iconv(ucs2_conversion_descriptor, (char**)&input,
|
||||
&input_size, (char**)&output, &output_size);
|
||||
size_t rc = iconv(ucs2_conversion_descriptor, (char **)&input,
|
||||
&input_size, (char **)&output, &output_size);
|
||||
if (rc == (size_t)-1) {
|
||||
perror("Converting to UCS-2 failed");
|
||||
free(buffer);
|
||||
|
Reference in New Issue
Block a user