int main(int argc, char *argv[]) { double idle_time = 2.0; int poll_delay = 200000; /* 200 ms */ int c; int use_xrecord = 0; /* Parse command line parameters */ while ((c = getopt(argc, argv, "i:m:dtp:kKR?v")) != EOF) { switch (c) { case 'i': idle_time = atof(optarg); break; case 'm': poll_delay = atoi(optarg) * 1000; break; case 'd': background = 1; break; case 't': disable_state = TappingOff; break; case 'p': pid_file = optarg; break; case 'k': ignore_modifier_keys = 1; break; case 'K': ignore_modifier_combos = 1; ignore_modifier_keys = 1; break; case 'R': use_xrecord = 1; break; case 'v': verbose = 1; break; case '?': default: usage(); break; } } if (idle_time <= 0.0) usage(); /* Open a connection to the X server */ display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Can't open display.\n"); exit(2); } if (!(dev = dp_get_device(display))) exit(2); /* Install a signal handler to restore synaptics parameters on exit */ install_signal_handler(); if (background) { pid_t pid; if ((pid = fork()) < 0) { perror("fork"); exit(3); } else if (pid != 0) exit(0); /* Child (daemon) is running here */ setsid(); /* Become session leader */ chdir("/"); /* In case the file system gets unmounted */ umask(0); /* We don't want any surprises */ if (pid_file) { FILE *fd = fopen(pid_file, "w"); if (!fd) { perror("Can't create pid file"); exit(3); } fprintf(fd, "%d\n", getpid()); fclose(fd); } } pad_disabled = False; store_current_touchpad_state(); #ifdef HAVE_X11_EXTENSIONS_RECORD_H if (use_xrecord) { if (check_xrecord(display)) record_main_loop(display, idle_time); else { fprintf(stderr, "Use of XRecord requested, but failed to " " initialize.\n"); exit(4); } } else #endif /* HAVE_X11_EXTENSIONS_RECORD_H */ { setup_keyboard_mask(display, ignore_modifier_keys); /* Run the main loop */ main_loop(display, idle_time, poll_delay); } return 0; }
int main(int argc, char *argv[]) { double idle_time = 2.0; int poll_delay = 200000; /* 200 ms */ Display *display; int c; int shmid; int ignore_modifier_keys = 0; /* Parse command line parameters */ while ((c = getopt(argc, argv, "i:m:dtp:kK?")) != EOF) { switch(c) { case 'i': idle_time = atof(optarg); break; case 'm': poll_delay = atoi(optarg) * 1000; break; case 'd': background = 1; break; case 't': disable_taps_only = 1; break; case 'p': pid_file = optarg; break; case 'k': ignore_modifier_keys = 1; break; case 'K': ignore_modifier_combos = 1; ignore_modifier_keys = 1; break; default: usage(); break; } } if (idle_time <= 0.0) usage(); /* Open a connection to the X server */ display = XOpenDisplay(NULL); if (!display) { fprintf(stderr, "Can't open display.\n"); exit(2); } /* Connect to the shared memory area */ if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) { if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) { fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n"); exit(2); } else { fprintf(stderr, "Incorrect size of shared memory area. Incompatible driver version?\n"); exit(2); } } if ((synshm = (SynapticsSHM*) shmat(shmid, NULL, 0)) == NULL) { perror("shmat"); exit(2); } /* Install a signal handler to restore synaptics parameters on exit */ install_signal_handler(); if (background) { pid_t pid; if ((pid = fork()) < 0) { perror("fork"); exit(3); } else if (pid != 0) exit(0); /* Child (daemon) is running here */ setsid(); /* Become session leader */ chdir("/"); /* In case the file system gets unmounted */ umask(0); /* We don't want any surprises */ if (pid_file) { FILE *fd = fopen(pid_file, "w"); if (!fd) { perror("Can't create pid file"); exit(2); } fprintf(fd, "%d\n", getpid()); fclose(fd); } } setup_keyboard_mask(display, ignore_modifier_keys); /* Run the main loop */ main_loop(display, idle_time, poll_delay); return 0; }