Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 88264ab

Browse files
author
Nicole Borrelli
committed
General code clean-up
1 parent 0cbd896 commit 88264ab

File tree

2 files changed

+21
-215
lines changed

2 files changed

+21
-215
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
touchdaemon : src/touchdaemon.c
3-
g++ -lX11 -lXi src/touchdaemon.c -o touchdaemon
3+
g++ -Wall -lX11 -lXi src/touchdaemon.c -o touchdaemon
44

55
clean:
66
rm touchdaemon

src/touchdaemon.c

+20-214
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ install_signal_handler(void)
141141
SIGPWR
142142
#endif
143143
};
144-
int i;
144+
unsigned int i;
145145
struct sigaction act;
146146
sigset_t set;
147147

@@ -202,7 +202,7 @@ get_time(void)
202202
return tv.tv_sec + tv.tv_usec / 1000000.0;
203203
}
204204

205-
static void ///////////////////////////////XXXXXXXXXXXXXXXXXXXXX//////////////////////////////////////////////////////
205+
static void
206206
main_loop(Display *display, double idle_time, int poll_delay)
207207
{
208208
double last_activity = 0.0;
@@ -253,188 +253,8 @@ setup_keyboard_mask(Display *display, int ignore_modifier_keys)
253253
}
254254
}
255255

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-
436256
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)
438258
{
439259
XDevice* dev = NULL;
440260
XDeviceInfo *info = NULL;
@@ -464,7 +284,7 @@ dp_get_device(Display *dpy, int dev_id)
464284
* device. If a device id was specified, we should only accept
465285
* that device.
466286
*/
467-
if ((dev_id == -1 && (info[ndevices].type == touchpad_type
287+
if ((!have_dev_id && (info[ndevices].type == touchpad_type
468288
|| info[ndevices].type == mouse_type
469289
|| info[ndevices].type == trackball_type))
470290
|| dev_id == info[ndevices].id) {
@@ -474,15 +294,15 @@ dp_get_device(Display *dpy, int dev_id)
474294
fprintf(stderr, "Failed to open device '%s'.\n",
475295
info[ndevices].name);
476296
error = 1;
477-
goto unwind;
297+
break;
478298
}
479299

480300
properties = XListDeviceProperties(dpy, dev, &nprops);
481301
if (!properties || !nprops)
482302
{
483303
fprintf(stderr, "No properties on device '%s'.\n", info[ndevices].name);
484304
error = 1;
485-
goto unwind;
305+
break;
486306
}
487307

488308
while(nprops--)
@@ -498,31 +318,32 @@ dp_get_device(Display *dpy, int dev_id)
498318
{
499319
fprintf(stderr, "Could not identify enable/disable property on device '%s'.\n", info[ndevices].name);
500320
error = 1;
501-
goto unwind;
321+
break;
502322
}
503323

504324
break; /* Yay, device is suitable */
505325
}
506326
}
507327

508-
unwind:
509328
XFree(properties);
510329
XFreeDeviceList(info);
511-
if (!dev)
330+
if (error)
512331
{
513-
if (dev_id == -1)
332+
if (!have_dev_id)
514333
{
515334
fprintf(stderr, "Unable to find a device.\n");
516335
}
517336
else
518337
{
519338
fprintf(stderr, "Unable to find the specified device (id=%d).\n", dev_id);
520339
}
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+
}
526347
}
527348
return dev;
528349
}
@@ -534,7 +355,6 @@ main(int argc, char *argv[])
534355
int poll_delay = 200000; /* 200 ms */
535356
int dev_id = -1;
536357
int c;
537-
int use_xrecord = 0;
538358

539359
/* Parse command line parameters */
540360
while ((c = getopt(argc, argv, "i:m:dp:kKD:?")) != EOF) {
@@ -577,7 +397,7 @@ main(int argc, char *argv[])
577397
exit(2);
578398
}
579399

580-
if (!(dev = dp_get_device(display, dev_id)))
400+
if (!(dev = dp_get_device(display, dev_id, (dev_id != -1))))
581401
exit(2);
582402

583403
/* Install a signal handler to restore synaptics parameters on exit */
@@ -609,23 +429,9 @@ main(int argc, char *argv[])
609429
pad_disabled = False;
610430
store_current_touchpad_state();
611431

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);
626433

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);
630436
return 0;
631437
}

0 commit comments

Comments
 (0)