@@ -177,3 +177,127 @@ void fossil_io_keyboard_poll_events(void) {
177
177
}
178
178
}
179
179
}
180
+
181
+ // MOUSE
182
+ static int fossil_io_mouse_event_match (const fossil_io_mouse_event_t * a , const fossil_io_mouse_event_t * b ) {
183
+ return (a -> button == b -> button &&
184
+ (a -> shift == b -> shift || a -> shift == -1 || b -> shift == -1 ) &&
185
+ (a -> ctrl == b -> ctrl || a -> ctrl == -1 || b -> ctrl == -1 ) &&
186
+ (a -> alt == b -> alt || a -> alt == -1 || b -> alt == -1 ));
187
+ }
188
+
189
+ // Dummy OS-agnostic implementation for now
190
+ static void fossil_io_mouse_get_event (fossil_io_mouse_event_t * event ) {
191
+ static int toggle = 0 ;
192
+ event -> x = 100 + (toggle ++ % 10 );
193
+ event -> y = 200 + (toggle % 5 );
194
+ event -> button = toggle % 2 ;
195
+ event -> shift = -1 ;
196
+ event -> ctrl = -1 ;
197
+ event -> alt = -1 ;
198
+ }
199
+
200
+ void fossil_io_mouse_register_binding (fossil_io_mouse_event_t event , fossil_io_mouse_callback_t callback ) {
201
+ if (mouse_manager .count >= MAX_MOUSEBINDS ) {
202
+ fprintf (stderr , "[mouse] Max bindings reached\n" );
203
+ return ;
204
+ }
205
+
206
+ mouse_manager .bindings [mouse_manager .count ++ ] = (fossil_io_mouse_binding_t ){ event , callback };
207
+ }
208
+
209
+ void fossil_io_mouse_unregister_binding (fossil_io_mouse_event_t event ) {
210
+ for (size_t i = 0 ; i < mouse_manager .count ; ++ i ) {
211
+ if (fossil_io_mouse_event_match (& mouse_manager .bindings [i ].event , & event )) {
212
+ memmove (& mouse_manager .bindings [i ], & mouse_manager .bindings [i + 1 ],
213
+ sizeof (fossil_io_mouse_binding_t ) * (mouse_manager .count - i - 1 ));
214
+ -- mouse_manager .count ;
215
+ return ;
216
+ }
217
+ }
218
+ fprintf (stderr , "[mouse] Binding not found\n" );
219
+ }
220
+
221
+ void fossil_io_mouse_poll_events (void ) {
222
+ fossil_io_mouse_event_t event = {0 };
223
+ fossil_io_mouse_get_event (& event );
224
+
225
+ for (size_t i = 0 ; i < mouse_manager .count ; ++ i ) {
226
+ if (fossil_io_mouse_event_match (& mouse_manager .bindings [i ].event , & event )) {
227
+ if (mouse_manager .bindings [i ].callback ) {
228
+ mouse_manager .bindings [i ].callback (event );
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ void fossil_io_mouse_init (void ) {
235
+ printf ("[mouse] Initialized\n" );
236
+ }
237
+
238
+ void fossil_io_mouse_shutdown (void ) {
239
+ printf ("[mouse] Shutdown\n" );
240
+ }
241
+
242
+ // TOUCH
243
+ static int fossil_io_touch_event_match (const fossil_io_touch_event_t * a , const fossil_io_touch_event_t * b ) {
244
+ return (a -> touch_id == b -> touch_id &&
245
+ a -> action == b -> action &&
246
+ (a -> shift == b -> shift || a -> shift == -1 || b -> shift == -1 ) &&
247
+ (a -> ctrl == b -> ctrl || a -> ctrl == -1 || b -> ctrl == -1 ) &&
248
+ (a -> alt == b -> alt || a -> alt == -1 || b -> alt == -1 ));
249
+ }
250
+
251
+ // Dummy implementation for simulation/testing
252
+ static void fossil_io_touch_get_event (fossil_io_touch_event_t * event ) {
253
+ static int state = 0 ;
254
+ event -> x = 320 + (state % 3 );
255
+ event -> y = 240 + (state % 2 );
256
+ event -> touch_id = 1 ;
257
+ event -> action = state ++ % 3 ; // 0=start, 1=move, 2=end
258
+ event -> shift = -1 ;
259
+ event -> ctrl = -1 ;
260
+ event -> alt = -1 ;
261
+ }
262
+
263
+ void fossil_io_touch_register_binding (fossil_io_touch_event_t event , fossil_io_touch_callback_t callback ) {
264
+ if (touch_manager .count >= MAX_TOUCHBINDS ) {
265
+ fprintf (stderr , "[touch] Max bindings reached\n" );
266
+ return ;
267
+ }
268
+
269
+ touch_manager .bindings [touch_manager .count ++ ] = (fossil_io_touch_binding_t ){ event , callback };
270
+ }
271
+
272
+ void fossil_io_touch_unregister_binding (fossil_io_touch_event_t event ) {
273
+ for (size_t i = 0 ; i < touch_manager .count ; ++ i ) {
274
+ if (fossil_io_touch_event_match (& touch_manager .bindings [i ].event , & event )) {
275
+ memmove (& touch_manager .bindings [i ], & touch_manager .bindings [i + 1 ],
276
+ sizeof (fossil_io_touch_binding_t ) * (touch_manager .count - i - 1 ));
277
+ -- touch_manager .count ;
278
+ return ;
279
+ }
280
+ }
281
+ fprintf (stderr , "[touch] Binding not found\n" );
282
+ }
283
+
284
+ void fossil_io_touch_poll_events (void ) {
285
+ fossil_io_touch_event_t event = {0 };
286
+ fossil_io_touch_get_event (& event );
287
+
288
+ for (size_t i = 0 ; i < touch_manager .count ; ++ i ) {
289
+ if (fossil_io_touch_event_match (& touch_manager .bindings [i ].event , & event )) {
290
+ if (touch_manager .bindings [i ].callback ) {
291
+ touch_manager .bindings [i ].callback (event );
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ void fossil_io_touch_init (void ) {
298
+ printf ("[touch] Initialized\n" );
299
+ }
300
+
301
+ void fossil_io_touch_shutdown (void ) {
302
+ printf ("[touch] Shutdown\n" );
303
+ }
0 commit comments