/* ** ClanLib SDK ** Copyright (c) 1997-2005 The ClanLib Team ** ** This software is provided 'as-is', without any express or implied ** warranty. In no event will the authors be held liable for any damages ** arising from the use of this software. ** ** Permission is granted to anyone to use this software for any purpose, ** including commercial applications, and to alter it and redistribute it ** freely, subject to the following restrictions: ** ** 1. The origin of this software must not be misrepresented; you must not ** claim that you wrote the original software. If you use this software ** in a product, an acknowledgment in the product documentation would be ** appreciated but is not required. ** 2. Altered source versions must be plainly marked as such, and must not be ** misrepresented as being the original software. ** 3. This notice may not be removed or altered from any source distribution. ** ** Note: Some of the libraries ClanLib may link to may have additional ** requirements or restrictions. ** ** File Author(s): ** ** Magnus Norddahl ** (if your name is missing here, please add it) */ #if 0 #include #include #include #include #include #include #include #include "API/Core/System/error.h" #include "API/Core/System/clanstring.h" #include "API/Display/input_event.h" #include "input_device_linuxevent.h" // FIXME: These three should be in linux/input.h #define MSC_RAW 0x03 #define MSC_SCAN 0x04 #define MSC_MAX 0x07 #ifndef EV_SYN #define EV_SYN 0 #endif #define BITS_PER_LONG (sizeof(long) * 8) #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) #define OFF(x) ((x)%BITS_PER_LONG) #define BIT(x) (1UL<> OFF(bit)) & 1) static char *events[EV_MAX + 1] = { NULL }; static char **names[EV_MAX + 1] = { NULL }; CL_InputDevice_LinuxEvent::CL_InputDevice_LinuxEvent(CL_DisplayWindow_Generic* parent_, const std::string& device_) : parent(parent_), device(device_) { fd = open(device.c_str(), O_RDONLY | O_NONBLOCK); if (fd == -1) { throw CL_Error(strerror(errno)); } if (ioctl(fd, EVIOCGVERSION, &version)) { throw CL_Error("CL_InputDevice_LinuxEvent: can't get version"); } #if 0 if (0) { // FIXME: Some versions of linux don't have these structs, use arrays there struct input_id id; ioctl(fd, EVIOCGID, &id); printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id.bustype, id.vendor, id.product, id.vendor); } #endif { // Get the human readable name char c_name[256] = "Unknown"; ioctl(fd, EVIOCGNAME(sizeof(c_name)), c_name); name = c_name; } { unsigned long bit[EV_MAX][NBITS(KEY_MAX)]; memset(bit, 0, sizeof(bit)); ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]); for (int i = 0; i < EV_MAX; i++) { if (test_bit(i, bit[0])) { //printf(" Event type %d (%s)\n", i, events[i] ? events[i] : "?"); if (!i) continue; ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]); for (int j = 0; j < KEY_MAX; j++) { if (test_bit(j, bit[i])) { if (i == EV_KEY) { // Found something that might be a button buttons.push_back(Button(j)); } else if (i == EV_ABS) { // Found something that might be an axis #if 0 // FIXME: Some Linuxes don't have these struct struct input_absinfo absinfo; ioctl(fd, EVIOCGABS(j), &absinfo); // FIXME: we are ignoring absinfo.fuzz and absinfo.flat, not sure what they are good for axes.push_back(Axis(j, absinfo.minimum, absinfo.maximum, absinfo.value)); #else int absinfo[5]; ioctl(fd, EVIOCGABS(j), &absinfo); // FIXME: we are ignoring absinfo.fuzz and absinfo.flat, not sure what they are good for axes.push_back(Axis(j, absinfo[1], absinfo[2], absinfo[0])); #endif } else if (i == EV_REL) { // Found something mouse/ball like balls.push_back(Ball(j)); } } } } } } } int CL_InputDevice_LinuxEvent::get_ball_index_by_code(int code) { for(std::vector::size_type i = 0; i != balls.size(); ++i) { if (balls[i].code == code) { return i; } } return -1; } int CL_InputDevice_LinuxEvent::get_button_index_by_code(int code) { for(std::vector