lint: Check for missing braces

The `eek/layersurface.c` file should be excluded because it's an imported, "foreign" source, but clang-tidy doesn't seem to have an annotation for that.

An alternative would have been to exclude it in Meson and do the check there, but that requires clang-tidy, raising the barrier to contribute of Squeekboard even more (it already requires libfeedback, which isn't packaged widely).
This commit is contained in:
Dorota Czaplejewicz
2020-10-20 10:43:54 +00:00
parent c0b6ea51fa
commit 153f9c39e5
8 changed files with 67 additions and 37 deletions

View File

@ -136,7 +136,10 @@ test:
- build_meson - build_meson
script: script:
- apt-get -y build-dep . - apt-get -y build-dep .
- apt-get -y install clang-tidy
- ninja -C _build test - ninja -C _build test
- cd _build
- clang-tidy --checks=-clang-diagnostic-missing-braces,readability-braces-around-statements, --warnings-as-errors=readability-braces-around-statements -extra-arg=-Wno-unknown-warning-option ../src/*.c ../eek/*.c ../eekboard/*.c
check_release: check_release:
<<: *tags <<: *tags

View File

@ -113,7 +113,7 @@ User interface modules should:
Code submitted should roughly match the style of surrounding code. Things that will *not* be accepted are ones that often lead to errors: Code submitted should roughly match the style of surrounding code. Things that will *not* be accepted are ones that often lead to errors:
- skipping brackets `{}` after every `if()`, `else`, and similar - skipping brackets `{}` after every `if()`, `else`, and similar ([SCI CERT C: EXP19-C](https://wiki.sei.cmu.edu/confluence/display/c/EXP19-C.+Use+braces+for+the+body+of+an+if%2C+for%2C+or+while+statement))
Bad example: Bad example:

View File

@ -129,11 +129,12 @@ eek_gtk_keyboard_real_size_allocate (GtkWidget *self,
eekboard_context_service_use_layout(priv->eekboard_context, priv->layout, time); eekboard_context_service_use_layout(priv->eekboard_context, priv->layout, time);
} }
if (priv->renderer) if (priv->renderer) {
eek_renderer_set_allocation_size (priv->renderer, eek_renderer_set_allocation_size (priv->renderer,
priv->keyboard->layout, priv->keyboard->layout,
allocation->width, allocation->width,
allocation->height); allocation->height);
}
GTK_WIDGET_CLASS (eek_gtk_keyboard_parent_class)-> GTK_WIDGET_CLASS (eek_gtk_keyboard_parent_class)->
size_allocate (self, allocation); size_allocate (self, allocation);
@ -355,10 +356,11 @@ eek_gtk_keyboard_init (EekGtkKeyboard *self)
EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (EEK_GTK_KEYBOARD (self)); EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (EEK_GTK_KEYBOARD (self));
g_autoptr(GError) err = NULL; g_autoptr(GError) err = NULL;
if (lfb_init(SQUEEKBOARD_APP_ID, &err)) if (lfb_init(SQUEEKBOARD_APP_ID, &err)) {
priv->event = lfb_event_new ("button-pressed"); priv->event = lfb_event_new ("button-pressed");
else } else {
g_warning ("Failed to init libfeedback: %s", err->message); g_warning ("Failed to init libfeedback: %s", err->message);
}
GtkIconTheme *theme = gtk_icon_theme_get_default (); GtkIconTheme *theme = gtk_icon_theme_get_default ();

View File

@ -42,8 +42,9 @@ struct keymap squeek_key_map_from_str(const char *keymap_str) {
struct xkb_keymap *keymap = xkb_keymap_new_from_string(context, keymap_str, struct xkb_keymap *keymap = xkb_keymap_new_from_string(context, keymap_str,
XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!keymap) if (!keymap) {
g_error("Bad keymap:\n%s", keymap_str); g_error("Bad keymap:\n%s", keymap_str);
}
xkb_context_unref(context); xkb_context_unref(context);
@ -52,8 +53,9 @@ struct keymap squeek_key_map_from_str(const char *keymap_str) {
g_autofree char *path = strdup("/eek_keymap-XXXXXX"); g_autofree char *path = strdup("/eek_keymap-XXXXXX");
char *r = &path[strlen(path) - 6]; char *r = &path[strlen(path) - 6];
if (getrandom(r, 6, GRND_NONBLOCK) < 0) if (getrandom(r, 6, GRND_NONBLOCK) < 0) {
g_error("Failed to get random numbers: %s", strerror(errno)); g_error("Failed to get random numbers: %s", strerror(errno));
}
for (unsigned i = 0; i < 6; i++) { for (unsigned i = 0; i < 6; i++) {
r[i] = (r[i] & 0b1111111) | 0b1000000; // A-z r[i] = (r[i] & 0b1111111) | 0b1000000; // A-z
r[i] = r[i] > 'z' ? '?' : r[i]; // The randomizer doesn't need to be good... r[i] = r[i] > 'z' ? '?' : r[i]; // The randomizer doesn't need to be good...

View File

@ -590,27 +590,32 @@ phosh_layer_surface_set_size(PhoshLayerSurface *self, gint width, gint height)
g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self));
priv = phosh_layer_surface_get_instance_private (self); priv = phosh_layer_surface_get_instance_private (self);
if (priv->height == height && priv->width == width) if (priv->height == height && priv->width == width) {
return; return;
}
old_width = priv->width; old_width = priv->width;
old_height = priv->height; old_height = priv->height;
if (width != -1) if (width != -1) {
priv->width = width; priv->width = width;
}
if (height != -1) if (height != -1) {
priv->height = height; priv->height = height;
}
if (gtk_widget_get_mapped (GTK_WIDGET (self))) { if (gtk_widget_get_mapped (GTK_WIDGET (self))) {
zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height); zwlr_layer_surface_v1_set_size(priv->layer_surface, priv->width, priv->height);
} }
if (priv->height != old_height) if (priv->height != old_height) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_HEIGHT]);
}
if (priv->width != old_width) if (priv->width != old_width) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_LAYER_WIDTH]);
}
} }
/** /**
@ -632,25 +637,31 @@ phosh_layer_surface_set_margins(PhoshLayerSurface *self, gint top, gint right, g
old_right = priv->margin_right; old_right = priv->margin_right;
old_bottom = priv->margin_bottom; old_bottom = priv->margin_bottom;
if (old_top == top && old_left == left && old_right == right && old_bottom == bottom) if (old_top == top && old_left == left && old_right == right && old_bottom == bottom) {
return; return;
}
priv->margin_top = top; priv->margin_top = top;
priv->margin_left = left; priv->margin_left = left;
priv->margin_right = right; priv->margin_right = right;
priv->margin_bottom = bottom; priv->margin_bottom = bottom;
if (priv->layer_surface) if (priv->layer_surface) {
zwlr_layer_surface_v1_set_margin(priv->layer_surface, top, right, bottom, left); zwlr_layer_surface_v1_set_margin(priv->layer_surface, top, right, bottom, left);
}
if (old_top != top) if (old_top != top) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_TOP]);
if (old_bottom != bottom) }
if (old_bottom != bottom) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_BOTTOM]);
if (old_left != left) }
if (old_left != left) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_LEFT]);
if (old_right != right) }
if (old_right != right) {
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_MARGIN_RIGHT]);
}
} }
/** /**
@ -669,13 +680,15 @@ phosh_layer_surface_set_exclusive_zone(PhoshLayerSurface *self, gint zone)
old_zone = priv->exclusive_zone; old_zone = priv->exclusive_zone;
if (old_zone == zone) if (old_zone == zone) {
return; return;
}
priv->exclusive_zone = zone; priv->exclusive_zone = zone;
if (priv->layer_surface) if (priv->layer_surface) {
zwlr_layer_surface_v1_set_exclusive_zone(priv->layer_surface, zone); zwlr_layer_surface_v1_set_exclusive_zone(priv->layer_surface, zone);
}
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_EXCLUSIVE_ZONE]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_EXCLUSIVE_ZONE]);
} }
@ -693,13 +706,14 @@ phosh_layer_surface_set_kbd_interactivity (PhoshLayerSurface *self, gboolean int
g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self));
priv = phosh_layer_surface_get_instance_private (self); priv = phosh_layer_surface_get_instance_private (self);
if (priv->kbd_interactivity == interactivity) if (priv->kbd_interactivity == interactivity) {
return; return;
}
priv->kbd_interactivity = interactivity; priv->kbd_interactivity = interactivity;
if (priv->layer_surface) if (priv->layer_surface) {
zwlr_layer_surface_v1_set_keyboard_interactivity (priv->layer_surface, interactivity); zwlr_layer_surface_v1_set_keyboard_interactivity (priv->layer_surface, interactivity);
}
g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_KBD_INTERACTIVITY]); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LAYER_SURFACE_PROP_KBD_INTERACTIVITY]);
} }
@ -717,6 +731,7 @@ phosh_layer_surface_wl_surface_commit (PhoshLayerSurface *self)
g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self)); g_return_if_fail (PHOSH_IS_LAYER_SURFACE (self));
priv = phosh_layer_surface_get_instance_private (self); priv = phosh_layer_surface_get_instance_private (self);
if (priv->wl_surface) if (priv->wl_surface) {
wl_surface_commit (priv->wl_surface); wl_surface_commit (priv->wl_surface);
}
} }

View File

@ -20,6 +20,7 @@ add_project_arguments(
'-Werror=incompatible-pointer-types', '-Werror=incompatible-pointer-types',
'-Werror=int-conversion', '-Werror=int-conversion',
'-Werror=redundant-decls', '-Werror=redundant-decls',
'-Werror=parentheses',
'-Wformat-nonliteral', '-Wformat-nonliteral',
'-Wformat-security', '-Wformat-security',
'-Winit-self', '-Winit-self',

View File

@ -125,14 +125,17 @@ on_surface_configure(ServerContextService *self, PhoshLayerSurface *surface)
// we can use different algorithms for portrait and landscape mode. // we can use different algorithms for portrait and landscape mode.
// Note: this is a temporary fix until the size manager is complete. // Note: this is a temporary fix until the size manager is complete.
display = gdk_display_get_default (); display = gdk_display_get_default ();
if (display) if (display) {
window = gtk_widget_get_window (GTK_WIDGET (surface)); window = gtk_widget_get_window (GTK_WIDGET (surface));
if (window) }
if (window) {
monitor = gdk_display_get_monitor_at_window (display, window); monitor = gdk_display_get_monitor_at_window (display, window);
if (monitor) }
if (monitor) {
gdk_monitor_get_geometry (monitor, &geometry); gdk_monitor_get_geometry (monitor, &geometry);
else } else {
geometry.width = geometry.height = 0; geometry.width = geometry.height = 0;
}
// When the geometry event comes after surface.configure, // When the geometry event comes after surface.configure,
// this entire height calculation does nothing. // this entire height calculation does nothing.
@ -159,8 +162,9 @@ on_surface_configure(ServerContextService *self, PhoshLayerSurface *surface)
static void static void
make_window (ServerContextService *self) make_window (ServerContextService *self)
{ {
if (self->window) if (self->window) {
g_error("Window already present"); g_error("Window already present");
}
struct squeek_output_handle output = squeek_outputs_get_current(squeek_wayland->outputs); struct squeek_output_handle output = squeek_outputs_get_current(squeek_wayland->outputs);
squeek_uiman_set_output(self->manager, output); squeek_uiman_set_output(self->manager, output);
@ -234,19 +238,21 @@ on_hide (ServerContextService *self)
static void static void
server_context_service_real_show_keyboard (ServerContextService *self) server_context_service_real_show_keyboard (ServerContextService *self)
{ {
if (!self->enabled) if (!self->enabled) {
return; return;
}
if (self->hiding) { if (self->hiding) {
g_source_remove (self->hiding); g_source_remove (self->hiding);
self->hiding = 0; self->hiding = 0;
} }
if (!self->window) if (!self->window) {
make_window (self); make_window (self);
if (!self->widget) }
if (!self->widget) {
make_widget (self); make_widget (self);
}
self->visible = TRUE; self->visible = TRUE;
gtk_widget_show (GTK_WIDGET(self->window)); gtk_widget_show (GTK_WIDGET(self->window));
} }
@ -254,9 +260,9 @@ server_context_service_real_show_keyboard (ServerContextService *self)
static void static void
server_context_service_real_hide_keyboard (ServerContextService *self) server_context_service_real_hide_keyboard (ServerContextService *self)
{ {
if (!self->hiding) if (!self->hiding) {
self->hiding = g_timeout_add (200, (GSourceFunc) on_hide, self); self->hiding = g_timeout_add (200, (GSourceFunc) on_hide, self);
}
self->visible = FALSE; self->visible = FALSE;
} }

View File

@ -213,12 +213,13 @@ main (int argc, char **argv)
// dbus is not strictly necessary for the useful operation // dbus is not strictly necessary for the useful operation
// if text-input is used, as it can bring the keyboard in and out // if text-input is used, as it can bring the keyboard in and out
GBusType bus_type; GBusType bus_type;
if (opt_system) if (opt_system) {
bus_type = G_BUS_TYPE_SYSTEM; bus_type = G_BUS_TYPE_SYSTEM;
else if (opt_address) } else if (opt_address) {
bus_type = G_BUS_TYPE_NONE; bus_type = G_BUS_TYPE_NONE;
else } else {
bus_type = G_BUS_TYPE_SESSION; bus_type = G_BUS_TYPE_SESSION;
}
GDBusConnection *connection = NULL; GDBusConnection *connection = NULL;
GError *error = NULL; GError *error = NULL;