diff options
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r-- | platform/x11/os_x11.cpp | 230 |
1 files changed, 33 insertions, 197 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 74ebad748a..f42e93b93f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,6 +32,7 @@ #include "key_mapping_x11.h" #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "print_string.h" #include "servers/physics/physics_server_sw.h" #include "errno.h" @@ -57,10 +58,6 @@ #include <fcntl.h> #include <unistd.h> -#ifdef __linux__ -#include <linux/joystick.h> -#endif - //stupid linux.h #ifdef KEY_TAB #undef KEY_TAB @@ -81,7 +78,7 @@ const char * OS_X11::get_video_driver_name(int p_driver) const { } OS::VideoMode OS_X11::get_default_video_mode() const { - return OS::VideoMode(800,600,false); + return OS::VideoMode(1024,600,false); } int OS_X11::get_audio_driver_count() const { @@ -98,8 +95,6 @@ const char *OS_X11::get_audio_driver_name(int p_driver) const { void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { last_button_state=0; - dpad_last[0]=0; - dpad_last[1]=0; xmbstring=NULL; event_id=0; @@ -431,9 +426,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi physics_2d_server->init(); input = memnew( InputDefault ); - - probe_joystick(); - +#ifdef JOYDEV_ENABLED + joystick = memnew( joystick_linux(input)); +#endif _ensure_data_dir(); } @@ -452,6 +447,11 @@ void OS_X11::finalize() { // memdelete(debugger_connection_console); //} +#ifdef JOYDEV_ENABLED + memdelete(joystick); +#endif + memdelete(input); + memdelete(sample_manager); audio_server->finish(); @@ -467,8 +467,6 @@ void OS_X11::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); - memdelete(input); - XUnmapWindow( x11_display, x11_window ); XDestroyWindow( x11_display, x11_window ); @@ -621,6 +619,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); + } int OS_X11::get_screen_count() const { @@ -889,7 +888,16 @@ void OS_X11::set_window_maximized(bool p_enabled) { XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa); current_videomode.width = xwa.width; current_videomode.height = xwa.height; -*/ +//*/ + +// current_videomode.width = wm_max_horz; +// current_videomode.height = wm_max_vert; + + //Size2 ss = get_screen_size(get_current_screen()); + //current_videomode.width=ss.width; + //current_videomode.height=ss.height; + + maximized = p_enabled; } @@ -1652,193 +1660,11 @@ String OS_X11::get_system_dir(SystemDir p_dir) const { return pipe.strip_edges(); } - -void OS_X11::close_joystick(int p_id) { - - if (p_id == -1) { - for (int i=0; i<JOYSTICKS_MAX; i++) { - - close_joystick(i); - }; - return; - }; - - - if (joysticks[p_id].fd != -1) { - 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++) { - - probe_joystick(i); - }; - return; - }; - - if (joysticks[p_id].fd != -1) - close_joystick(p_id); - - const char *joy_names[] = { - "/dev/input/js%d", - "/dev/js%d", - NULL - }; - - int i=0; - while(joy_names[i]) { - - char fname[64]; - sprintf(fname, joy_names[i], p_id); - int fd = open(fname, O_RDONLY|O_NONBLOCK); - if (fd != -1) { - - //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 - }; - - ++i; - }; - #endif -}; - void OS_X11::move_window_to_foreground() { XRaiseWindow(x11_display,x11_window); } -void OS_X11::process_joysticks() { - #ifndef __FreeBSD__ - int bytes; - js_event events[32]; - InputEvent ievent; - for (int i=0; i<JOYSTICKS_MAX; i++) { - - 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) { - - int ev_count = bytes / sizeof(js_event); - for (int j=0; j<ev_count; j++) { - - js_event& event = events[j]; - - //printf("got event on joystick %i, %i, %i, %i, %i\n", i, joysticks[i].fd, event.type, event.number, event.value); - if (event.type & JS_EVENT_INIT) - continue; - - switch (event.type & ~JS_EVENT_INIT) { - - case JS_EVENT_AXIS: - - //if (joysticks[i].last_axis[event.number] != event.value) { - - /* - if (event.number==5 || event.number==6) { - - int axis=event.number-5; - int val = event.value; - if (val<0) - val=-1; - if (val>0) - val=+1; - - InputEvent ev; - ev.type = InputEvent::JOYSTICK_BUTTON; - ev.ID = ++event_id; - - - if (val!=dpad_last[axis]) { - - int prev_val = dpad_last[axis]; - if (prev_val!=0) { - - ev.joy_button.pressed=false; - ev.joy_button.pressure=0.0; - if (event.number==5) - ev.joy_button.button_index=JOY_DPAD_LEFT+(prev_val+1)/2; - if (event.number==6) - ev.joy_button.button_index=JOY_DPAD_UP+(prev_val+1)/2; - - input->parse_input_event( ev ); - } - } - - if (val!=0) { - - ev.joy_button.pressed=true; - ev.joy_button.pressure=1.0; - if (event.number==5) - ev.joy_button.button_index=JOY_DPAD_LEFT+(val+1)/2; - if (event.number==6) - ev.joy_button.button_index=JOY_DPAD_UP+(val+1)/2; - - input->parse_input_event( ev ); - } - - - 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; - //ERR_FAIL_COND(event.number >= JOY_AXIS_MAX); - ievent.type = InputEvent::JOYSTICK_MOTION; - ievent.ID = ++event_id; - 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; - if (event.number < JOY_AXIS_MAX) - joysticks[i].last_axis[event.number] = event.value; - input->parse_input_event( ievent ); - //}; - break; - - case JS_EVENT_BUTTON: - - - ievent.type = InputEvent::JOYSTICK_BUTTON; - ievent.ID = ++event_id; - 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 -}; - - void OS_X11::set_cursor_shape(CursorShape p_shape) { ERR_FAIL_INDEX(p_shape,CURSOR_MAX); @@ -1938,7 +1764,9 @@ void OS_X11::run() { while (!force_quit) { process_xevents(); // get rid of pending events - process_joysticks(); +#ifdef JOYDEV_ENABLED + event_id = joystick->process_joysticks(event_id); +#endif if (Main::iteration()==true) break; }; @@ -1946,6 +1774,14 @@ void OS_X11::run() { main_loop->finish(); } +bool OS_X11::is_joy_known(int p_device) { + return input->is_joy_mapped(p_device); +} + +String OS_X11::get_joy_guid(int p_device) const { + return input->get_joy_guid_remapped(p_device); +} + OS_X11::OS_X11() { #ifdef RTAUDIO_ENABLED |