summaryrefslogtreecommitdiff
path: root/platform/x11/os_x11.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-08-01 22:10:38 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-08-01 22:10:38 -0300
commit678948068bbde7f12a9c5f28a467b6cf4d127851 (patch)
tree75572f3a5cc6089a6ca3046e9307d0a7c0b72c51 /platform/x11/os_x11.cpp
parent9ff6d55822647c87eef392147ea15641d0922d47 (diff)
Small Issues & Maintenance
-=-=-=-=-=-=-=-=-=-=-=-=-= -Begin work on Navigation Meshes (simple pathfinding for now, will improve soon) -More doc on theme overriding -Upgraded OpenSSL to version without bugs -Misc bugfixes
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r--platform/x11/os_x11.cpp46
1 files changed, 34 insertions, 12 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index e7d9a4d691..62af302791 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1046,10 +1046,12 @@ void OS_X11::close_joystick(int p_id) {
close(joysticks[p_id].fd);
joysticks[p_id].fd = -1;
};
+ input->joy_connection_changed(p_id, false, "");
};
void OS_X11::probe_joystick(int p_id) {
#ifndef __FreeBSD__
+
if (p_id == -1) {
for (int i=0; i<JOYSTICKS_MAX; i++) {
@@ -1059,7 +1061,8 @@ void OS_X11::probe_joystick(int p_id) {
return;
};
- close_joystick(p_id);
+ if (joysticks[p_id].fd != -1)
+ close_joystick(p_id);
const char *joy_names[] = {
"/dev/input/js%d",
@@ -1072,12 +1075,22 @@ void OS_X11::probe_joystick(int p_id) {
char fname[64];
sprintf(fname, joy_names[i], p_id);
- int fd = open(fname, O_RDONLY);
+ int fd = open(fname, O_RDONLY|O_NONBLOCK);
if (fd != -1) {
- fcntl( fd, F_SETFL, O_NONBLOCK );
+ //fcntl( fd, F_SETFL, O_NONBLOCK );
joysticks[p_id] = Joystick(); // this will reset the axis array
joysticks[p_id].fd = fd;
+
+ String name;
+ char namebuf[255] = {0};
+ if (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) >= 0) {
+ name = namebuf;
+ } else {
+ name = "error";
+ };
+
+ input->joy_connection_changed(p_id, true, name);
break; // don't try the next name
};
@@ -1098,8 +1111,11 @@ void OS_X11::process_joysticks() {
InputEvent ievent;
for (int i=0; i<JOYSTICKS_MAX; i++) {
- if (joysticks[i].fd == -1)
- continue;
+ if (joysticks[i].fd == -1) {
+ probe_joystick(i);
+ if (joysticks[i].fd == -1)
+ continue;
+ };
ievent.device = i;
while ( (bytes = read(joysticks[i].fd, &events, sizeof(events))) > 0) {
@@ -1117,8 +1133,9 @@ void OS_X11::process_joysticks() {
case JS_EVENT_AXIS:
- if (joysticks[i].last_axis[event.number] != event.value) {
+ //if (joysticks[i].last_axis[event.number] != event.value) {
+ /*
if (event.number==5 || event.number==6) {
int axis=event.number-5;
@@ -1165,17 +1182,19 @@ void OS_X11::process_joysticks() {
dpad_last[axis]=val;
}
+ */
//print_line("ev: "+itos(event.number)+" val: "+ rtos((float)event.value / (float)MAX_JOY_AXIS));
- if (event.number >= JOY_AXIS_MAX)
- break;
+ //if (event.number >= JOY_AXIS_MAX)
+ // break;
//ERR_FAIL_COND(event.number >= JOY_AXIS_MAX);
ievent.type = InputEvent::JOYSTICK_MOTION;
ievent.ID = ++event_id;
- ievent.joy_motion.axis = _pc_joystick_get_native_axis(event.number);
+ ievent.joy_motion.axis = event.number; //_pc_joystick_get_native_axis(event.number);
ievent.joy_motion.axis_value = (float)event.value / (float)MAX_JOY_AXIS;
- joysticks[i].last_axis[event.number] = event.value;
+ if (event.number < JOY_AXIS_MAX)
+ joysticks[i].last_axis[event.number] = event.value;
input->parse_input_event( ievent );
- };
+ //};
break;
case JS_EVENT_BUTTON:
@@ -1183,13 +1202,16 @@ void OS_X11::process_joysticks() {
ievent.type = InputEvent::JOYSTICK_BUTTON;
ievent.ID = ++event_id;
- ievent.joy_button.button_index = _pc_joystick_get_native_button(event.number);
+ ievent.joy_button.button_index = event.number; // _pc_joystick_get_native_button(event.number);
ievent.joy_button.pressed = event.value;
input->parse_input_event( ievent );
break;
};
};
};
+ if (bytes == 0 || (bytes < 0 && errno != EAGAIN)) {
+ close_joystick(i);
+ };
};
#endif
};