@@ -68,10 +68,40 @@ bool ffPrintGamepad(FFGamepadOptions* options)
68
68
return false;
69
69
}
70
70
71
+ FF_LIST_AUTO_DESTROY filtered = ffListCreate (sizeof (FFGamepadDevice * ));
72
+ FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
73
+ {
74
+ bool ignored = false;
75
+ FF_LIST_FOR_EACH (FFstrbuf , ignore , options -> ignores )
76
+ {
77
+ if (ffStrbufStartsWithIgnCase (& device -> name , ignore ))
78
+ {
79
+ ignored = true;
80
+ break ;
81
+ }
82
+ }
83
+ if (!ignored )
84
+ {
85
+ FFGamepadDevice * * ptr = ffListAdd (& filtered );
86
+ * ptr = device ;
87
+ }
88
+ }
89
+
90
+ if (!filtered .length )
91
+ {
92
+ ffPrintError (FF_GAMEPAD_MODULE_NAME , 0 , & options -> moduleArgs , FF_PRINT_TYPE_DEFAULT , "All devices are ignored" );
93
+ return false;
94
+ }
95
+
71
96
uint8_t index = 0 ;
97
+ FF_LIST_FOR_EACH (FFGamepadDevice * , pdevice , filtered )
98
+ {
99
+ FFGamepadDevice * device = * pdevice ;
100
+ printDevice (options , device , filtered .length > 1 ? ++ index : 0 );
101
+ }
102
+
72
103
FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
73
104
{
74
- printDevice (options , device , result .length > 1 ? ++ index : 0 );
75
105
ffStrbufDestroy (& device -> serial );
76
106
ffStrbufDestroy (& device -> name );
77
107
}
@@ -88,6 +118,21 @@ void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)
88
118
if (ffJsonConfigParseModuleArgs (key , val , & options -> moduleArgs ))
89
119
continue ;
90
120
121
+ if (unsafe_yyjson_equals_str (key , "ignores" ))
122
+ {
123
+ yyjson_val * elem ;
124
+ size_t eidx , emax ;
125
+ yyjson_arr_foreach (val , eidx , emax , elem )
126
+ {
127
+ if (yyjson_is_str (elem ))
128
+ {
129
+ FFstrbuf * strbuf = ffListAdd (& options -> ignores );
130
+ ffStrbufInitJsonVal (strbuf , elem );
131
+ }
132
+ }
133
+ continue ;
134
+ }
135
+
91
136
if (ffPercentParseJsonObject (key , val , & options -> percent ))
92
137
continue ;
93
138
@@ -99,6 +144,12 @@ void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc,
99
144
{
100
145
ffJsonConfigGenerateModuleArgsConfig (doc , module , & options -> moduleArgs );
101
146
147
+ if (options -> ignores .length > 0 )
148
+ {
149
+ yyjson_mut_val * ignores = yyjson_mut_obj_add_arr (doc , module , "ignores" );
150
+ FF_LIST_FOR_EACH (FFstrbuf , strbuf , options -> ignores )
151
+ yyjson_mut_arr_append (ignores , yyjson_mut_strncpy (doc , strbuf -> chars , strbuf -> length ));
152
+ }
102
153
ffPercentGenerateJsonConfig (doc , module , options -> percent );
103
154
}
104
155
@@ -120,6 +171,17 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
120
171
yyjson_mut_val * obj = yyjson_mut_arr_add_obj (doc , arr );
121
172
yyjson_mut_obj_add_strbuf (doc , obj , "serial" , & device -> serial );
122
173
yyjson_mut_obj_add_strbuf (doc , obj , "name" , & device -> name );
174
+
175
+ bool ignored = false;
176
+ FF_LIST_FOR_EACH (FFstrbuf , ignore , options -> ignores )
177
+ {
178
+ if (ffStrbufStartsWithIgnCase (& device -> name , ignore ))
179
+ {
180
+ ignored = true;
181
+ break ;
182
+ }
183
+ }
184
+ yyjson_mut_obj_add_bool (doc , obj , "ignored" , ignored );
123
185
}
124
186
125
187
FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
@@ -134,12 +196,18 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
134
196
void ffInitGamepadOptions (FFGamepadOptions * options )
135
197
{
136
198
ffOptionInitModuleArg (& options -> moduleArgs , "" );
199
+
200
+ ffListInit (& options -> ignores , sizeof (FFstrbuf ));
137
201
options -> percent = (FFPercentageModuleConfig ) { 50 , 20 , 0 };
138
202
}
139
203
140
204
void ffDestroyGamepadOptions (FFGamepadOptions * options )
141
205
{
142
206
ffOptionDestroyModuleArg (& options -> moduleArgs );
207
+
208
+ FF_LIST_FOR_EACH (FFstrbuf , str , options -> ignores )
209
+ ffStrbufDestroy (str );
210
+ ffListDestroy (& options -> ignores );
143
211
}
144
212
145
213
FFModuleBaseInfo ffGamepadModuleInfo = {
0 commit comments