Example #1
0
adv_error mouseb_event_init(int mouseb_id)
{
	unsigned i;
	adv_bool eacces = 0;
	struct event_location map[EVENT_MOUSE_DEVICE_MAX];
	unsigned mac;

	log_std(("mouseb:event: mouseb_event_init(id:%d)\n", mouseb_id));

#if defined(USE_SVGALIB)
	/* close the SVGALIB mouse device. SVGALIB always call mouse_init(), also */
	/* if mouse input is not requested */
	if (os_internal_svgalib_get()) {
		mouse_close();
	}
#endif

	log_std(("mouseb:event: opening mouse from 0 to %d\n", EVENT_MOUSE_DEVICE_MAX));

	mac = event_locate(map, EVENT_MOUSE_DEVICE_MAX, &eacces);

	event_state.mac = 0;
	for(i=0;i<mac;++i) {
		int f;

		if (event_state.mac >= EVENT_MOUSE_MAX)
			continue;

		f = event_open(map[i].file, event_state.map[event_state.mac].evtype_bitmask, sizeof(event_state.map[event_state.mac].evtype_bitmask));
		if (f == -1) {
			if (errno == EACCES) {
				eacces = 1;
			}
			continue;
		}

		if (!event_is_mouse(f, event_state.map[event_state.mac].evtype_bitmask)) {
			log_std(("mouseb:event: not a mouse on device %s\n", map[i].file));
			event_close(f);
			continue;
		}

		if (mouseb_setup(&event_state.map[event_state.mac], f) != 0) {
			event_close(f);
			continue;
		}

		++event_state.mac;
	}

	if (!event_state.mac) {
		if (eacces)
			error_set("No mouse found. Check the /dev/input/event* permissions.\n");
		else
			error_set("No mouse found.\n");
		return -1;
	}

	return 0;
}
Example #2
0
adv_error mouseb_raw_init(int mouseb_id)
{
	unsigned i;
	adv_bool eacces = 0;

	log_std(("mouseb:raw: mouseb_raw_init(id:%d)\n", mouseb_id));

#if defined(USE_SVGALIB)
	/* close the SVGALIB mouse device. SVGALIB always call mouse_init(), also */
	/* if mouse input is not requested */
	if (os_internal_svgalib_get()) {
		mouse_close();
	}
#endif

	raw_state.mac = 0;
	for (i = 0; i < RAW_MOUSE_MAX; ++i) {
		if (raw_mouse_init(&raw_state.map[i].context) == 0) {
			log_std(("mouseb:raw: open device %s\n", raw_state.map[i].context.dev));

			mouseb_setup(&raw_state.map[i]);

			raw_state.map[i].active_flag = 1;
			raw_state.mac = i + 1;
		} else {
			if (errno != ENODEV) {
				log_std(("ERROR:mouseb:raw: error opening device %s, errno %d (%s)\n", raw_state.map[i].context.dev, errno, strerror(errno)));
			}
			if (errno == EACCES) {
				eacces = 1;
			}
			raw_state.map[i].active_flag = 0;
		}
	}

	if (raw_state.mac == 0) {
		if (eacces)
			error_set("No mouse found. Check the /dev/mouse and /dev/input/mouse* permissions.\n");
		else
			error_set("No mouse found.\n");
		return -1;
	}

	return 0;
}
Example #3
0
adv_error mouseb_rawinput_init(int mouseb_id)
{
#if defined(USE_SDL) && SDL_MAJOR_VERSION != 1
	error_set("Incompatible with SDL2.\n");
	return -1;
#else
	unsigned i;
	HMODULE h;
	UINT n;
	UINT size;
	RAWINPUTDEVICELIST* l;

	log_std(("mouseb:rawinput: mouseb_rawinput_init(id:%d)\n", mouseb_id));

	h = GetModuleHandle("user32.dll");
	if (!h) {
		error_set("Error loading the user32 library.\n");
		return -1;
	}

	RegisterRawInputDevices_ptr = (RegisterRawInputDevices_type)GetProcAddress(h, "RegisterRawInputDevices");
	GetRawInputDeviceList_ptr = (GetRawInputDeviceList_type)GetProcAddress(h, "GetRawInputDeviceList");
	GetRawInputDeviceInfoA_ptr = (GetRawInputDeviceInfoA_type)GetProcAddress(h, "GetRawInputDeviceInfoA");
	GetRawInputData_ptr = (GetRawInputData_type)GetProcAddress(h, "GetRawInputData");

	if (!RegisterRawInputDevices_ptr || !GetRawInputDeviceList_ptr || !GetRawInputDeviceInfoA_ptr || !GetRawInputData_ptr) {
		error_set("Raw input devices not supported on your system.\n");
		return -1;
	}

	if (GetRawInputDeviceList_ptr(NULL, &n, sizeof(RAWINPUTDEVICELIST)) != 0) {
		error_set("Error getting the number of raw devices.\n");
		return -1;
	}

	if (n == 0) {
		error_set("No input device found.\n");
		return -1;
	}

	size = n * sizeof(RAWINPUTDEVICELIST);
	l = malloc(size);

	n = GetRawInputDeviceList_ptr(l, &size, sizeof(RAWINPUTDEVICELIST));
	if (n == -1) {
		free(l);
		error_set("Error getting the list of raw devices.\n");
		return -1;
	}

	log_std(("mouseb:rawinput: GetRawInputDeviceList() -> %d\n", (unsigned)n));

	raw_state.mac = 0;
	for (i = 0; i < n; ++i) {
		if (raw_state.mac < RAW_MOUSE_MAX) {
			UINT size;
			unsigned vid, pid, rev;
			struct raw_context* context = &raw_state.map[raw_state.mac].context;

			size = sizeof(RID_DEVICE_INFO);
			context->info.cbSize = sizeof(RID_DEVICE_INFO);
			if (GetRawInputDeviceInfoA_ptr(l[i].hDevice, RIDI_DEVICEINFO, &context->info, &size) == -1) {
				continue;
			}

			size = sizeof(context->name);
			if (GetRawInputDeviceInfoA_ptr(l[i].hDevice, RIDI_DEVICENAME, context->name, &size) < 0) {
				continue;
			}

			/* Get the VID/PID */
			if (GetRawInputDeviceHIDInfo(context->name, &vid, &pid, &rev) < 0) {
				/* on error use fake value, for not HID devices it's ok to fail */
				vid = 0;
				pid = 0;
				rev = 0;
			}

			log_std(("mouseb:rawinput: GetRawInputDeviceInfo(%d) -> type:%d,vid:%04x,pid:%04x,rev:%04x,%s\n", i, (unsigned)context->info.dwType, vid, pid, rev, context->name));

			/* HACK skip the global mouse which is the combination of all the others */
			if (strstr(context->name, "#RDP_MOU#") != 0) {
				continue;
			}

			if (context->info.dwType != RIM_TYPEMOUSE) {
				continue;
			}

			if (
				/* SMOG Lightgun (http://lightgun.splinder.com/) */
				(vid == 0x0b9a && pid == 0x016a)
				/* Acts Labs Lightgun (http://www.act-labs.com/) */
				|| (vid == 0x061c && pid == 0xa800)
				|| (vid == 0x061c && pid == 0xa700)
			) {
				/* ignore known lightguns */
				continue;
			}

			raw_state.map[raw_state.mac].context.h = l[i].hDevice;

			log_std(("mouseb:rawinput: mouse id:%d,vid:%04x,pid:%04x,rev:%04x,buttons:%d,samplerate:%d\n", (unsigned)context->info.mouse.dwId, vid, pid, rev, (unsigned)context->info.mouse.dwNumberOfButtons, (unsigned)context->info.mouse.dwSampleRate));

			mouseb_setup(&raw_state.map[raw_state.mac], context->info.mouse.dwNumberOfButtons);

			++raw_state.mac;
		}
	}

	free(l);

	if (raw_state.mac == 0) {
		error_set("No mouse found.\n");
		return -1;
	}

	qsort(raw_state.map, raw_state.mac, sizeof(raw_state.map[0]), mouseb_compare);

	return 0;
#endif
}