[Helper] Add a rofi_fallthrough macro to tell compiler fallthrough is intentional

This commit is contained in:
Qball Cow
2025-02-20 09:56:29 +01:00
parent 47053f30d2
commit 5d77a9bb33
4 changed files with 25 additions and 11 deletions

View File

@@ -455,6 +455,19 @@ void helper_select_next_matching_mode(void);
* Switch to the previous matching method. * Switch to the previous matching method.
*/ */
void helper_select_previous_matching_mode(void); void helper_select_previous_matching_mode(void);
/**
* Method to indicate fallthrough. This will help
* gcc/llvm warning/static code analysis.
*/
#if __has_attribute(__fallthrough__)
#define rofi_fallthrough __attribute__((__fallthrough__))
#else
#define rofi_fallthrough \
do { \
} while (0) /* fallthrough */
#endif
G_END_DECLS G_END_DECLS
/**@} */ /**@} */

View File

@@ -396,30 +396,30 @@ static void rofi_view_calculate_window_position(RofiViewState *state) {
switch (location) { switch (location) {
case WL_NORTH_WEST: case WL_NORTH_WEST:
state->x = CacheState.mon.x; state->x = CacheState.mon.x;
/* FALLTHRU */ rofi_fallthrough;
case WL_NORTH: case WL_NORTH:
state->y = CacheState.mon.y; state->y = CacheState.mon.y;
break; break;
case WL_NORTH_EAST: case WL_NORTH_EAST:
state->y = CacheState.mon.y; state->y = CacheState.mon.y;
/* FALLTHRU */ rofi_fallthrough;
case WL_EAST: case WL_EAST:
state->x = CacheState.mon.x + CacheState.mon.w; state->x = CacheState.mon.x + CacheState.mon.w;
break; break;
case WL_SOUTH_EAST: case WL_SOUTH_EAST:
state->x = CacheState.mon.x + CacheState.mon.w; state->x = CacheState.mon.x + CacheState.mon.w;
/* FALLTHRU */ rofi_fallthrough;
case WL_SOUTH: case WL_SOUTH:
state->y = CacheState.mon.y + CacheState.mon.h; state->y = CacheState.mon.y + CacheState.mon.h;
break; break;
case WL_SOUTH_WEST: case WL_SOUTH_WEST:
state->y = CacheState.mon.y + CacheState.mon.h; state->y = CacheState.mon.y + CacheState.mon.h;
/* FALLTHRU */ rofi_fallthrough;
case WL_WEST: case WL_WEST:
state->x = CacheState.mon.x; state->x = CacheState.mon.x;
break; break;
case WL_CENTER:; case WL_CENTER:;
/* FALLTHRU */ rofi_fallthrough;
default: default:
break; break;
} }
@@ -2057,10 +2057,10 @@ void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
return; return;
case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END: case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END:
target = NULL; target = NULL;
/* FALLTHRU */ rofi_fallthrough;
case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN: case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN:
state->mouse.motion_target = target; state->mouse.motion_target = target;
/* FALLTHRU */ rofi_fallthrough;
case WIDGET_TRIGGER_ACTION_RESULT_HANDLED: case WIDGET_TRIGGER_ACTION_RESULT_HANDLED:
return; return;
} }

View File

@@ -34,6 +34,7 @@
#include <widgets/textbox.h> #include <widgets/textbox.h>
#include <widgets/widget.h> #include <widgets/widget.h>
#include "helper.h"
#include "settings.h" #include "settings.h"
#include "theme.h" #include "theme.h"
#include "view.h" #include "view.h"
@@ -757,7 +758,7 @@ static WidgetTriggerActionResult listview_element_trigger_action(
break; break;
case ACCEPT_HOVERED_CUSTOM: case ACCEPT_HOVERED_CUSTOM:
custom = TRUE; custom = TRUE;
/* FALLTHRU */ rofi_fallthrough;
case ACCEPT_HOVERED_ENTRY: case ACCEPT_HOVERED_ENTRY:
listview_set_selected(lv, lv->last_offset + i); listview_set_selected(lv, lv->last_offset + i);
lv->mouse_activated(lv, custom, lv->mouse_activated_data); lv->mouse_activated(lv, custom, lv->mouse_activated_data);

View File

@@ -1172,13 +1172,13 @@ static gboolean x11_button_to_nk_bindings_scroll(guint32 x11_button,
switch (x11_button) { switch (x11_button) {
case 4: case 4:
*steps = -1; *steps = -1;
/* fallthrough */ rofi_fallthrough;
case 5: case 5:
*axis = NK_BINDINGS_SCROLL_AXIS_VERTICAL; *axis = NK_BINDINGS_SCROLL_AXIS_VERTICAL;
break; break;
case 6: case 6:
*steps = -1; *steps = -1;
/* fallthrough */ rofi_fallthrough;
case 7: case 7:
*axis = NK_BINDINGS_SCROLL_AXIS_HORIZONTAL; *axis = NK_BINDINGS_SCROLL_AXIS_HORIZONTAL;
break; break;