Beispiel #1
0
	/**
	\brief a rule to cluster points within a shell
	\ingroup cluster
	*/
	bool clstrruleshell(int i, int j, arg_t ptr)
	{
		assert(ptr != 0x0 && ptr != NULL);
		clstrruleshell_info* args = (clstrruleshell_info*)ptr;

		if (args->box.periodic.size() == 0) {
			args->box.periodic.push_back(true);
			args->box.periodic.push_back(true);
			args->box.periodic.push_back(true);
		}
		if (args->box.period.size() == 0) {
			args->box.period.push_back(0.0);
			args->box.period.push_back(0.0);
			args->box.period.push_back(0.0);
		}

		double rsq = distancesq(
			args->x[i], args->x[j], args->box.period, args->box.periodic);

		if (rsq < args->rcutsqouter) {
			if (rsq >= args->rcutsqinner) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}
Beispiel #2
0
	/**
	\brief a rule to cluster points within a set range with per type cutuff
	\ingroup cluster
	*/
	bool clstrrulerangetype(int i, int j, arg_t ptr)
	{
		assert(ptr != 0x0 && ptr != NULL);
		clstrrulerangetype_info* args = (clstrrulerangetype_info*)ptr;

		if (args->box.periodic.size() == 0) {
			args->box.periodic.push_back(true);
			args->box.periodic.push_back(true);
			args->box.periodic.push_back(true);
		}
		if (args->box.period.size() == 0) {
			args->box.period.push_back(0.0);
			args->box.period.push_back(0.0);
			args->box.period.push_back(0.0);
		}
        if (args->rcutsq.size() == 0) {
            std::cerr << "***ERROR: clstrrulerangetype: per type cutoff";
            std::cerr << " (rcutsq) not defined." << std::endl;
            exit(1);
        }

		double rsq = distancesq(
			args->x[i], args->x[j], args->box.period, args->box.periodic);

		if (rsq < args->rcutsq[args->type[i]][args->type[j]]) {
			return true;
		}
		else {
			return false;
		}
	}
Beispiel #3
0
void TrackpadRawInput(PDEVICE_CONTEXT pDevice, struct cyapa_softc *sc, struct cyapa_regs *regs, int tickinc){
	int nfingers;
	int afingers;	/* actual fingers after culling */
	int i;

	nfingers = CYAPA_FNGR_NUMFINGERS(regs->fngr);
	afingers = nfingers;

	//	system("cls");
#ifdef DEBUG
	CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "stat %02x\tTracking ID: %d\tbuttons %c%c%c\tnfngrs=%d\n",
		regs->stat,
		regs->touch->id,
		((regs->fngr & CYAPA_FNGR_LEFT) ? 'L' : '-'),
		((regs->fngr & CYAPA_FNGR_MIDDLE) ? 'M' : '-'),
		((regs->fngr & CYAPA_FNGR_RIGHT) ? 'R' : '-'),
		nfingers
		);
#endif

	for (i = 0; i < nfingers; ++i) {
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, " [x=%04d y=%04d p=%d]\n",
			CYAPA_TOUCH_X(regs, i),
			CYAPA_TOUCH_Y(regs, i),
			CYAPA_TOUCH_P(regs, i));
		if (CYAPA_TOUCH_Y(regs, i) > 400){
			if (CYAPA_TOUCH_X(regs, i) < 400){
				CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Simulate left hardware button! %d\n", CYAPA_TOUCH_Y(regs, i));
			}
			else {
				CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Simulate right hardware button! %d\n", CYAPA_TOUCH_Y(regs, i));
			}
		}
#endif
		if (CYAPA_TOUCH_P(regs, i) < cyapa_minpressure)
			--afingers;
	}

	if (regs->touch->id != sc->lastid){
		sc->x = 0;
		sc->y = 0;
		sc->lastid = regs->touch->id;
	}

	int x = sc->x;
	int y = sc->y;

	bool overrideDeltas = false;

	if (afingers > 0){
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Tick inc.\n");
#endif
		sc->tick += tickinc;
		x = CYAPA_TOUCH_X(regs, 0);
		y = CYAPA_TOUCH_Y(regs, 0);
		if (afingers > 1){
			int x1 = CYAPA_TOUCH_X(regs, 0);
			int y1 = CYAPA_TOUCH_Y(regs, 0);
			int x2 = CYAPA_TOUCH_X(regs, 1);
			int y2 = CYAPA_TOUCH_Y(regs, 1);

			int d1 = distancesq(x1 - sc->x, y1 - sc->y);
			int d2 = distancesq(x1 - sc->x, y1 - sc->y);
			if (d2 < d1 || (y > 400 && y2 < 400)){
				x = x2;
				y = y2;
			}
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "%d %d\t%d %d\t%d %d\n", x, y, x1, y1, x2, y2);
#endif
		}
		else {
			if (sc->mousedown && y > 400){
				overrideDeltas = true;
				sc->x = 0;
				sc->y = 0;
			}
		}
		if ((overrideDeltas != true) && (sc->x == 0 && sc->y == 0)){
			sc->x = x;
			sc->y = y;
		}
	}
	else {
		if (sc->tick < 10 && sc->tick != 0){
			INPUT input;
			if (sc->lastnfingers == 1){
				sc->mousebutton = 0;
			}
			else if (sc->lastnfingers == 2){
				sc->mousebutton = 1;
			}
			else if (sc->lastnfingers == 3){
				sc->mousebutton = 2;
			}
			else if (sc->lastnfingers == 4){
				sc->mousebutton = 3;
			}
			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			sc->mousedown = true;
			MySendInput(pDevice, &input, sc);
			sc->tickssincelastclick = 0;
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Tap to Click!\n");
#endif
		}
		sc->tick = 0;
		sc->hasmoved = false;
		sc->mousedownfromtap = false;
		sc->tickssincelastclick+=tickinc;
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Move Reset!\n");
#endif
	}

	int delta_x = x - sc->x, delta_y = y - sc->y;
	if (abs(delta_x) + abs(delta_y) > 10 && !sc->hasmoved){
		sc->hasmoved = true;
		if (sc->tickssincelastclick < 10 && sc->tickssincelastclick >= 0){
			INPUT input;
			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			MySendInput(pDevice, &input, sc);
			sc->mousebutton = 0;
			sc->mousedown = true;
			sc->mousedownfromtap = true;
			sc->tickssincelastclick = 0;
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Move from tap!\n");
#endif
		}
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Has moved!\n");
#endif
	}
	if (overrideDeltas){
		delta_x = 0;
		delta_y = 0;
	}

	sc->lastnfingers = nfingers;

	if (CYAPA_TOUCH_P(regs, 0) < 20)
		sc->tick -= tickinc;
	if (CYAPA_TOUCH_P(regs, 0) < 10)
		sc->tick = 0;
	else if (sc->hasmoved)
		sc->tick = 0;
	if (sc->tick < 0)
		sc->tick = 0;

	INPUT input;
	if (afingers < 2 || sc->mousedown){
		input.mi.dx = (BYTE)delta_x;
		input.mi.dy = (BYTE)delta_y;
		input.mi.dwFlags = MOUSEEVENTF_MOVE;
		if (delta_x != 0 && delta_y != 0)
			MySendInput(pDevice, &input, sc);
	}
	else if (afingers == 2){
		if (abs(delta_x) > abs(delta_y)){
			input.mi.dwFlags = MOUSEEVENTF_HWHEEL;
			input.mi.mouseData = (BYTE)-delta_x;
			MySendInput(pDevice, &input, sc);
		}
		else if (abs(delta_y) > abs(delta_x)){
			input.mi.dwFlags = MOUSEEVENTF_WHEEL;
			input.mi.mouseData = (BYTE)delta_y;
			MySendInput(pDevice, &input, sc);
		}
	}
	else if (afingers == 3){
		if (sc->hasmoved){
			sc->multitaskingx += delta_x;
			sc->multitaskingy += delta_y;
			if (sc->multitaskinggesturetick > 5 && !sc->multitaskingdone){
				if (abs(sc->multitaskingx) > abs(sc->multitaskingy)){
					BYTE shiftKeys = KBD_LGUI_BIT | KBD_LCONTROL_BIT;
					BYTE keyCodes[KBD_KEY_CODES] = { 0, 0, 0, 0, 0, 0 };
					if (sc->multitaskingx > 0)
						keyCodes[0] = 0x50;
					else
						keyCodes[0] = 0x4F;
					update_keyboard(pDevice, shiftKeys, keyCodes);
					shiftKeys = 0;
					keyCodes[0] = 0x0;
					update_keyboard(pDevice, shiftKeys, keyCodes);
				}
				else if (abs(sc->multitaskingy) > abs(sc->multitaskingx)){
					BYTE shiftKeys = KBD_LGUI_BIT;
					BYTE keyCodes[KBD_KEY_CODES] = { 0, 0, 0, 0, 0, 0 };
					if (sc->multitaskingy < 0)
						keyCodes[0] = 0x2B;
					else
						keyCodes[0] = 0x07;
					update_keyboard(pDevice, shiftKeys, keyCodes);
					shiftKeys = 0;
					keyCodes[0] = 0x0;
					update_keyboard(pDevice, shiftKeys, keyCodes);
				}
				sc->multitaskingdone = true;
				sc->multitaskinggesturetick = -1;
			}
			else if (sc->multitaskingdone){
				if (sc->multitaskinggesturetick > 25){
					sc->multitaskinggesturetick = -1;
					sc->multitaskingx = 0;
					sc->multitaskingy = 0;
					sc->multitaskingdone = false;
				}
			}
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO,DBG_IOCTL,"Multitasking Gestures!\n");
#endif
			sc->multitaskinggesturetick++;
		}
	}

	if (afingers != 3){
		sc->multitaskinggesturetick = 0;
		sc->multitaskingx = 0;
		sc->multitaskingy = 0;
		sc->multitaskingdone = false;
	}


	if (afingers > 0){
		if ((regs->fngr & CYAPA_FNGR_LEFT) != 0 && sc->mousedown == false){
			sc->mousedown = true;

			if (afingers == 1){
				if (sc->y < 400 || sc->x < 400){
					sc->mousebutton = 0;
				}
				else {
					sc->mousebutton = 1;
				}
			}
			else if (afingers == 2){
				sc->mousebutton = 1;
			}
			else if (afingers == 3){
				sc->mousebutton = 2;
			}
			else if (afingers == 4){
				sc->mousebutton = 3;
			}

			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			MySendInput(pDevice, &input, sc);
		}
		if (!overrideDeltas){
			sc->x = x;
			sc->y = y;
		}
	}
	else {
		if (!overrideDeltas){
			sc->x = 0;
			sc->y = 0;
		}
	}

	if ((regs->fngr & CYAPA_FNGR_LEFT) == 0 && sc->mousedown == true && sc->mousedownfromtap != true){
		sc->mousedown = false;

		if (sc->mousebutton == 3){
			BYTE shiftKeys = KBD_LGUI_BIT;
			BYTE keyCodes[KBD_KEY_CODES] = { 0x04, 0, 0, 0, 0, 0 };
			update_keyboard(pDevice, shiftKeys, keyCodes);
			shiftKeys = 0;
			keyCodes[0] = 0x0;
			update_keyboard(pDevice, shiftKeys, keyCodes);

		}
		sc->mousebutton = 0;
		input.mi.dx = 0;
		input.mi.dy = 0;
		input.mi.mouseData = 0;
		MySendInput(pDevice, &input, sc);
	}
}