@@ -141,7 +141,7 @@ install_signal_handler(void)
141
141
SIGPWR
142
142
#endif
143
143
};
144
- int i ;
144
+ unsigned int i ;
145
145
struct sigaction act ;
146
146
sigset_t set ;
147
147
@@ -202,7 +202,7 @@ get_time(void)
202
202
return tv .tv_sec + tv .tv_usec / 1000000.0 ;
203
203
}
204
204
205
- static void ///////////////////////////////XXXXXXXXXXXXXXXXXXXXX//////////////////////////////////////////////////////
205
+ static void
206
206
main_loop (Display * display , double idle_time , int poll_delay )
207
207
{
208
208
double last_activity = 0.0 ;
@@ -253,188 +253,8 @@ setup_keyboard_mask(Display *display, int ignore_modifier_keys)
253
253
}
254
254
}
255
255
256
- /* ---- the following code is for using the xrecord extension ----- */
257
- //#ifdef HAVE_XRECORD
258
- //
259
- //#define MAX_MODIFIERS 16
260
- //
261
- ///* used for exchanging information with the callback function */
262
- //struct xrecord_callback_results {
263
- // XModifierKeymap *modifiers;
264
- // Bool key_event;
265
- // Bool non_modifier_event;
266
- // KeyCode pressed_modifiers[MAX_MODIFIERS];
267
- //};
268
- //
269
- ///* test if the xrecord extension is found */
270
- //Bool check_xrecord(Display *display) {
271
- //
272
- // Bool found;
273
- // Status status;
274
- // int major_opcode, minor_opcode, first_error;
275
- // int version[2];
276
- //
277
- // found = XQueryExtension(display,
278
- // "RECORD",
279
- // &major_opcode,
280
- // &minor_opcode,
281
- // &first_error);
282
- //
283
- // status = XRecordQueryVersion(display, version, version+1);
284
- // if (!background && status) {
285
- // printf("X RECORD extension version %d.%d\n", version[0], version[1]);
286
- // }
287
- // return found;
288
- //}
289
- //
290
- ///* called by XRecordProcessReplies() */
291
- //void xrecord_callback( XPointer closure, XRecordInterceptData* recorded_data) {
292
- //
293
- // struct xrecord_callback_results *cbres;
294
- // xEvent *xev;
295
- // int nxev;
296
- //
297
- // cbres = (struct xrecord_callback_results *)closure;
298
- //
299
- // if (recorded_data->category != XRecordFromServer) {
300
- // XRecordFreeData(recorded_data);
301
- // return;
302
- // }
303
- //
304
- // nxev = recorded_data->data_len / 8;
305
- // xev = (xEvent *)recorded_data->data;
306
- // while(nxev--) {
307
- //
308
- // if ( (xev->u.u.type == KeyPress) || (xev->u.u.type == KeyRelease)) {
309
- // int i;
310
- // int is_modifier = 0;
311
- //
312
- // cbres->key_event = 1; /* remember, a key was pressed or released. */
313
- //
314
- // /* test if it was a modifier */
315
- // for (i = 0; i < 8 * cbres->modifiers->max_keypermod; i++) {
316
- // KeyCode kc = cbres->modifiers->modifiermap[i];
317
- //
318
- // if (kc == xev->u.u.detail) {
319
- // is_modifier = 1; /* yes, it is a modifier. */
320
- // break;
321
- // }
322
- // }
323
- //
324
- // if (is_modifier) {
325
- // if (xev->u.u.type == KeyPress) {
326
- // for (i=0; i < MAX_MODIFIERS; ++i)
327
- // if (!cbres->pressed_modifiers[i]) {
328
- // cbres->pressed_modifiers[i] = xev->u.u.detail;
329
- // break;
330
- // }
331
- // } else { /* KeyRelease */
332
- // for (i=0; i < MAX_MODIFIERS; ++i)
333
- // if (cbres->pressed_modifiers[i] == xev->u.u.detail)
334
- // cbres->pressed_modifiers[i] = 0;
335
- // }
336
- //
337
- // } else {
338
- // /* remember, a non-modifier was pressed. */
339
- // cbres->non_modifier_event = 1;
340
- // }
341
- // }
342
- //
343
- // xev++;
344
- // }
345
- //
346
- // XRecordFreeData(recorded_data); /* cleanup */
347
- //}
348
- //
349
- //static int is_modifier_pressed(const struct xrecord_callback_results *cbres) {
350
- // int i;
351
- //
352
- // for (i = 0; i < MAX_MODIFIERS; ++i)
353
- // if (cbres->pressed_modifiers[i])
354
- // return 1;
355
- //
356
- // return 0;
357
- //}
358
- //
359
- //void record_main_loop(Display* display, double idle_time) {
360
- //
361
- // struct xrecord_callback_results cbres;
362
- // XRecordContext context;
363
- // XRecordClientSpec cspec = XRecordAllClients;
364
- // Display *dpy_data;
365
- // XRecordRange *range;
366
- // int i;
367
- //
368
- // dpy_data = XOpenDisplay(NULL); /* we need an additional data connection. */
369
- // range = XRecordAllocRange();
370
- //
371
- // range->device_events.first = KeyPress;
372
- // range->device_events.last = KeyRelease;
373
- //
374
- // context = XRecordCreateContext(dpy_data, 0,
375
- // &cspec,1,
376
- // &range, 1);
377
- //
378
- // XRecordEnableContextAsync(dpy_data, context, xrecord_callback, (XPointer)&cbres);
379
- //
380
- // cbres.modifiers = XGetModifierMapping(display);
381
- // /* clear list of modifiers */
382
- // for (i = 0; i < MAX_MODIFIERS; ++i)
383
- // cbres.pressed_modifiers[i] = 0;
384
- //
385
- // while (1) {
386
- //
387
- // int fd = ConnectionNumber(dpy_data);
388
- // fd_set read_fds;
389
- // int ret;
390
- // int disable_event = 0;
391
- // struct timeval timeout;
392
- //
393
- // FD_ZERO(&read_fds);
394
- // FD_SET(fd, &read_fds);
395
- //
396
- // ret = select(fd+1 /* =(max descriptor in read_fds) + 1 */,
397
- // &read_fds, NULL, NULL,
398
- // pad_disabled ? &timeout : NULL /* timeout only required for enabling */ );
399
- //
400
- // if (FD_ISSET(fd, &read_fds)) {
401
- //
402
- // cbres.key_event = 0;
403
- // cbres.non_modifier_event = 0;
404
- //
405
- // XRecordProcessReplies(dpy_data);
406
- //
407
- // if (!ignore_modifier_keys && cbres.key_event) {
408
- // disable_event = 1;
409
- // }
410
- //
411
- // if (cbres.non_modifier_event &&
412
- // !(ignore_modifier_combos && is_modifier_pressed(&cbres)) ) {
413
- // disable_event = 1;
414
- // }
415
- // }
416
- //
417
- // if (disable_event) {
418
- // /* adjust the enable_time */
419
- // timeout.tv_sec = (int)idle_time;
420
- // timeout.tv_usec = (idle_time-(double)timeout.tv_sec) * 1.e6;
421
- //
422
- // toggle_touchpad(False);
423
- // }
424
- //
425
- // if (ret == 0 && pad_disabled) { /* timeout => enable event */
426
- // toggle_touchpad(True);
427
- // if (!background) printf("enable touchpad\n");
428
- // }
429
- //
430
- // } /* end while(1) */
431
- //
432
- // XFreeModifiermap(cbres.modifiers);
433
- //}
434
- //#endif /* HAVE_XRECORD */
435
-
436
256
static XDevice *
437
- dp_get_device (Display * dpy , int dev_id )
257
+ dp_get_device (Display * dpy , unsigned int dev_id , int have_dev_id )
438
258
{
439
259
XDevice * dev = NULL ;
440
260
XDeviceInfo * info = NULL ;
@@ -464,7 +284,7 @@ dp_get_device(Display *dpy, int dev_id)
464
284
* device. If a device id was specified, we should only accept
465
285
* that device.
466
286
*/
467
- if ((dev_id == -1 && (info [ndevices ].type == touchpad_type
287
+ if ((! have_dev_id && (info [ndevices ].type == touchpad_type
468
288
|| info [ndevices ].type == mouse_type
469
289
|| info [ndevices ].type == trackball_type ))
470
290
|| dev_id == info [ndevices ].id ) {
@@ -474,15 +294,15 @@ dp_get_device(Display *dpy, int dev_id)
474
294
fprintf (stderr , "Failed to open device '%s'.\n" ,
475
295
info [ndevices ].name );
476
296
error = 1 ;
477
- goto unwind ;
297
+ break ;
478
298
}
479
299
480
300
properties = XListDeviceProperties (dpy , dev , & nprops );
481
301
if (!properties || !nprops )
482
302
{
483
303
fprintf (stderr , "No properties on device '%s'.\n" , info [ndevices ].name );
484
304
error = 1 ;
485
- goto unwind ;
305
+ break ;
486
306
}
487
307
488
308
while (nprops -- )
@@ -498,31 +318,32 @@ dp_get_device(Display *dpy, int dev_id)
498
318
{
499
319
fprintf (stderr , "Could not identify enable/disable property on device '%s'.\n" , info [ndevices ].name );
500
320
error = 1 ;
501
- goto unwind ;
321
+ break ;
502
322
}
503
323
504
324
break ; /* Yay, device is suitable */
505
325
}
506
326
}
507
327
508
- unwind :
509
328
XFree (properties );
510
329
XFreeDeviceList (info );
511
- if (! dev )
330
+ if (error )
512
331
{
513
- if (dev_id == -1 )
332
+ if (! have_dev_id )
514
333
{
515
334
fprintf (stderr , "Unable to find a device.\n" );
516
335
}
517
336
else
518
337
{
519
338
fprintf (stderr , "Unable to find the specified device (id=%d).\n" , dev_id );
520
339
}
521
- }
522
- else if (error && dev )
523
- {
524
- XCloseDevice (dpy , dev );
525
- dev = NULL ;
340
+
341
+ // Free allocated memory
342
+ if (dev )
343
+ {
344
+ XCloseDevice (dpy , dev );
345
+ dev = NULL ;
346
+ }
526
347
}
527
348
return dev ;
528
349
}
@@ -534,7 +355,6 @@ main(int argc, char *argv[])
534
355
int poll_delay = 200000 ; /* 200 ms */
535
356
int dev_id = -1 ;
536
357
int c ;
537
- int use_xrecord = 0 ;
538
358
539
359
/* Parse command line parameters */
540
360
while ((c = getopt (argc , argv , "i:m:dp:kKD:?" )) != EOF ) {
@@ -577,7 +397,7 @@ main(int argc, char *argv[])
577
397
exit (2 );
578
398
}
579
399
580
- if (!(dev = dp_get_device (display , dev_id )))
400
+ if (!(dev = dp_get_device (display , dev_id , ( dev_id != -1 ) )))
581
401
exit (2 );
582
402
583
403
/* Install a signal handler to restore synaptics parameters on exit */
@@ -609,23 +429,9 @@ main(int argc, char *argv[])
609
429
pad_disabled = False ;
610
430
store_current_touchpad_state ();
611
431
612
- /*#ifdef HAVE_XRECORD
613
- if (use_xrecord)
614
- {
615
- if(check_xrecord(display))
616
- record_main_loop(display, idle_time);
617
- else {
618
- fprintf(stderr, "Use of XRecord requested, but failed to "
619
- " initialize.\n");
620
- exit(2);
621
- }
622
- } else
623
- #endif /* HAVE_XRECORD */
624
- {
625
- setup_keyboard_mask (display , ignore_modifier_keys );
432
+ setup_keyboard_mask (display , ignore_modifier_keys );
626
433
627
- /* Run the main loop */
628
- main_loop (display , idle_time , poll_delay );
629
- }
434
+ /* Run the main loop */
435
+ main_loop (display , idle_time , poll_delay );
630
436
return 0 ;
631
437
}
0 commit comments