int
main(int argc, char *argv[])
{
    int c;
    int delay = -1;
    int do_monitor = 0;
    int dump_settings = 0;
    int first_cmd;

    Display *dpy;
    XDevice *dev;

    if (argc == 1)
        dump_settings = 1;

    /* Parse command line parameters */
    while ((c = getopt(argc, argv, "sm:hlV")) != -1) {
	switch (c) {
	case 'm':
	    do_monitor = 1;
	    if ((delay = atoi(optarg)) < 0)
		usage();
	    break;
	case 'l':
	    dump_settings = 1;
	    break;
	case 'V':
	    printf("%s\n", VERSION);
	    exit(0);
	default:
	    usage();
	}
    }

    first_cmd = optind;
    if (!do_monitor && !dump_settings && first_cmd == argc)
	usage();

    /* Connect to the shared memory area */
    if (do_monitor)
        shm_process_commands(do_monitor, delay);

    dpy = dp_init();
    if (!dpy || !(dev = dp_get_device(dpy)))
        return 1;

    dp_set_variables(dpy, dev, argc, argv, first_cmd);
    if (dump_settings)
        dp_show_settings(dpy, dev);

    XCloseDevice(dpy, dev);
    XCloseDisplay(dpy);

    return 0;
}
int
main(int argc, char *argv[])
{
    int c;
    int dump_settings = 0;
    int first_cmd;

    Display *dpy;
    XDevice *dev;

    if (argc == 1)
        dump_settings = 1;

    /* Parse command line parameters */
    while ((c = getopt(argc, argv, "lV?")) != -1) {
        switch (c) {
        case 'l':
            dump_settings = 1;
            break;
        case 'V':
            printf("%s\n", VERSION);
            exit(0);
        case '?':
        default:
            usage();
        }
    }

    first_cmd = optind;
    if (!dump_settings && first_cmd == argc)
        usage();

    dpy = dp_init();
    if (!dpy || !(dev = dp_get_device(dpy)))
        return 1;

    dp_set_variables(dpy, dev, argc, argv, first_cmd);
    if (dump_settings)
        dp_show_settings(dpy, dev);

    XCloseDevice(dpy, dev);
    XCloseDisplay(dpy);

    return 0;
}
Exemple #3
0
int
main(int argc, char *argv[])
{
    int c;
    int delay = -1;
    int do_monitor = 0;
    int dump_hw = 0;
    int dump_settings = 0;
    int use_shm = 1;
    int first_cmd;

#ifdef HAVE_PROPERTIES
    use_shm = 0;
#endif

    /* Parse command line parameters */
    while ((c = getopt(argc, argv, "sm:hlV")) != -1) {
	switch (c) {
	case 's':
	    use_shm = 1;
	    break;
	case 'm':
	    use_shm = 1;
	    do_monitor = 1;
	    if ((delay = atoi(optarg)) < 0)
		usage();
	    break;
	case 'h':
	    use_shm = 1;
	    dump_hw = 1;
	    break;
	case 'l':
	    dump_settings = 1;
	    break;
	case 'V':
//	    printf("%s\n", VERSION);
	    exit(0);
	default:
	    usage();
	}
    }

    first_cmd = optind;
    if (!do_monitor && !dump_hw && !dump_settings && first_cmd == argc)
	usage();

    /* Connect to the shared memory area */
    if (use_shm)
    {
	SynapticsSHM *synshm = NULL;

	synshm = shm_init();
	if (!synshm)
	    return 1;

	/* Perform requested actions */
	if (dump_hw)
	    shm_show_hw_info(synshm);

	shm_set_variables(synshm, argc, argv, first_cmd);

	if (dump_settings)
	    shm_show_settings(synshm);
	if (do_monitor)
	    shm_monitor(synshm, delay);
    }
#ifdef HAVE_PROPERTIES
    else /* Device properties */
    {
	Display *dpy;
	XDevice *dev;

	dpy = dp_init();
	if (!dpy || !(dev = dp_get_device(dpy)))
	    return 1;

	dp_set_variables(dpy, dev, argc, argv, first_cmd);
	if (dump_settings)
	    dp_show_settings(dpy, dev);

	XCloseDevice(dpy, dev);
	XCloseDisplay(dpy);
    }
#endif

    return 0;
}
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;
}
void grabber_synaptics_loop(Grabber * self, Configuration * conf) {

	XDevice* dev = NULL;
	dev = dp_get_device(self->dpy);

	if (!dev) {
		printf("No synaptics touchpad detected.\n");
		return;
	}

	synaptics_disable_3fingers_tap(self, dev);

	SynapticsSHM *synshm = NULL;
	synshm = grabber_synaptics_shm_init(0);

	printf("\nSynaptics Driver (with Shared Memory enabled):\n");
	printf("   [x] 'synaptics'\n");

	if (!synshm) {
		printf(
				"Your Synaptics driver does not have shared memory access, so multitouch gestures will not work on your touchpad.\n"
						"Take a look at https://github.com/Chosko/xserver-xorg-input-synaptics if you want to enable SynapticsSHM.\n");
		return;
	}

	int delay = 10;

	SynapticsSHM old;

	memset(&old, 0, sizeof(SynapticsSHM));
	old.x = -1; /* Force first equality test to fail */

	int max_fingers = 0;

	while (!self->shut_down) {

		SynapticsSHM cur = *synshm;

		if (!synaptics_shm_is_equal(&old, &cur)) {

			int delay = 10;

			// release
			if (cur.numFingers >= 3 && max_fingers >= 3) {

				grabbing_update_movement(self, cur.x, cur.y);

				//// got > 3 fingers
			} else if (cur.numFingers == 0 && max_fingers >= 3) {

				if (self->verbose) {
					syn_print(&cur);
					printf("stopped	\n");
				}

				// reset max fingers
				max_fingers = 0;

				grabbing_end_movement(self, old.x, old.y, "Synaptics", conf);

				/// energy economy
				int delay = 50;

			} else if (cur.numFingers >= 3 && max_fingers < 3) {

				if (self->verbose) {

					syn_print(&cur);

				}

				max_fingers = max_fingers + 1;

				if (max_fingers >= 3) {

					if (self->verbose) {
						printf("started\n");
					}

					grabbing_start_movement(self, cur.x, cur.y);

				}

			}

			//// movement

		}

		usleep(delay * 1000);

		old = cur;

	}

}