diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/detect.py | 2 | ||||
-rw-r--r-- | platform/osx/audio_driver_osx.cpp | 3 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 17 | ||||
-rw-r--r-- | platform/windows/detect.py | 40 | ||||
-rw-r--r-- | platform/windows/export/export.cpp | 343 | ||||
-rw-r--r-- | platform/windows/export/export.h | 33 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 26 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 2 | ||||
-rw-r--r-- | platform/winrt/os_winrt.cpp | 1 | ||||
-rw-r--r-- | platform/x11/detect.py | 16 | ||||
-rw-r--r-- | platform/x11/joystick_linux.cpp | 241 | ||||
-rw-r--r-- | platform/x11/joystick_linux.h | 3 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 23 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 2 |
14 files changed, 220 insertions, 532 deletions
diff --git a/platform/android/detect.py b/platform/android/detect.py index ee3dc119c2..15ef478e19 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -247,3 +247,5 @@ def configure(env): env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) + + env.use_windows_spawn_fix() diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp index a74303e6c2..d9d91b22fb 100644 --- a/platform/osx/audio_driver_osx.cpp +++ b/platform/osx/audio_driver_osx.cpp @@ -172,6 +172,9 @@ void AudioDriverOSX::unlock() { void AudioDriverOSX::finish() { + if (active) + AudioOutputUnitStop(audio_unit); + memdelete_arr(samples_in); }; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 2690ee3ba9..d808fb67a2 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -809,6 +809,21 @@ static int translateKey(unsigned int key) OS_OSX::singleton->push_input(ev); } + if (fabs(deltaX)) { + + InputEvent ev; + ev.type=InputEvent::MOUSE_BUTTON; + ev.mouse_button.button_index=deltaX >0 ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT; + ev.mouse_button.pressed=true; + ev.mouse_button.x=mouse_x; + ev.mouse_button.y=mouse_y; + ev.mouse_button.global_x=mouse_x; + ev.mouse_button.global_y=mouse_y; + ev.mouse_button.button_mask=button_mask; + OS_OSX::singleton->push_input(ev); + ev.mouse_button.pressed=false; + OS_OSX::singleton->push_input(ev); + } } @end @@ -839,7 +854,7 @@ const char * OS_OSX::get_video_driver_name(int p_driver) const { OS::VideoMode OS_OSX::get_default_video_mode() const { VideoMode vm; - vm.width=800; + vm.width=1024; vm.height=600; vm.fullscreen=false; vm.resizable=true; diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 81247db388..1ad0f164d2 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -262,46 +262,12 @@ def configure(env): env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"]) env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"]) env['ENV'] = os.environ; - env["x86_opt_vc"]=env["bits"]!="64" + env["x86_opt_vc"]=True else: # Workaround for MinGW. See: # http://www.scons.org/wiki/LongCmdLinesOnWin32 - if (os.name=="nt"): - import subprocess - - def mySubProcess(cmdline,env): - #print "SPAWNED : " + cmdline - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) - data, err = proc.communicate() - rv = proc.wait() - if rv: - print "=====" - print err - print "=====" - return rv - - def mySpawn(sh, escape, cmd, args, env): - - newargs = ' '.join(args[1:]) - cmdline = cmd + " " + newargs - - rv=0 - if len(cmdline) > 32000 and cmd.endswith("ar") : - cmdline = cmd + " " + args[1] + " " + args[2] + " " - for i in range(3,len(args)) : - rv = mySubProcess( cmdline + args[i], env ) - if rv : - break - else: - rv = mySubProcess( cmdline, env ) - - return rv - - env['SPAWN'] = mySpawn + env.use_windows_spawn_fix() #build using mingw if (os.name=="nt"): @@ -339,7 +305,7 @@ def configure(env): if (env["target"]=="release"): - env.Append(CCFLAGS=['-ffast-math','-fomit-frame-pointer','-msse2']) + env.Append(CCFLAGS=['-msse2']) if (env["bits"]=="64"): env.Append(CCFLAGS=['-O3']) diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 899edde087..952f51fdd4 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -1,345 +1,6 @@ -/*************************************************************************/ -/* export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* 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 */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - #include "export.h" #include "platform/windows/logo.h" -#include "os/os.h" -#include "globals.h" -#include "tools/editor/editor_node.h" -#include "tools/pe_bliss/pe_bliss_godot.h" - -/** - @author Masoud BaniHashemian <masoudbh3@gmail.com> -*/ - - -void EditorExportPlatformWindows::store_16(DVector<uint8_t>& vector, uint16_t value) { - const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value); - int size = vector.size(); - vector.resize( size + 2 ); - DVector<uint8_t>::Write w = vector.write(); - w[size]=bytes[0]; - w[size+1]=bytes[1]; -} -void EditorExportPlatformWindows::store_32(DVector<uint8_t>& vector, uint32_t value) { - const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value); - int size = vector.size(); - vector.resize( size + 4 ); - DVector<uint8_t>::Write w = vector.write(); - w[size]=bytes[0]; - w[size+1]=bytes[1]; - w[size+2]=bytes[2]; - w[size+3]=bytes[3]; -} - -bool EditorExportPlatformWindows::_set(const StringName& p_name, const Variant& p_value) { - - String n = p_name; - - if (n=="icon/icon_ico") { - - icon_ico=p_value; - } else if (n=="icon/icon_png") { - - icon_png=p_value; - } else if (n=="icon/icon_png16x16") { - - icon16=p_value; - } else if (n=="icon/icon_png32x32") { - - icon32=p_value; - } else if (n=="icon/icon_png48x48") { - - icon48=p_value; - } else if (n=="icon/icon_png64x64") { - - icon64=p_value; - } else if (n=="icon/icon_png128x128") { - - icon128=p_value; - } else if (n=="icon/icon_png256x256") { - - icon256=p_value; - } else if (n=="version_info/version_major") { - - version_major=p_value; - } else if (n=="version_info/version_minor") { - - version_minor=p_value; - } else if (n=="version_info/version_text") { - - version_text=p_value; - } else if (n=="version_info/company_name") { - - company_name=p_value; - } else if (n=="version_info/file_description") { - - file_description=p_value; - } else if (n=="version_info/product_name") { - - product_name=p_value; - } else if (n=="version_info/legal_copyright") { - - legal_copyright=p_value; - } else if (n=="version_info/add_godot_version") { - - set_godot_version=p_value; - } else - return false; - - return true; - -} - -bool EditorExportPlatformWindows::_get(const StringName& p_name,Variant &r_ret) const { - - String n = p_name; - - if (n=="icon/icon_ico") { - - r_ret=icon_ico; - } else if (n=="icon/icon_png") { - - r_ret=icon_png; - } else if (n=="icon/icon_png16x16") { - - r_ret=icon16; - } else if (n=="icon/icon_png32x32") { - - r_ret=icon32; - } else if (n=="icon/icon_png48x48") { - - r_ret=icon48; - } else if (n=="icon/icon_png64x64") { - - r_ret=icon64; - } else if (n=="icon/icon_png128x128") { - - r_ret=icon128; - } else if (n=="icon/icon_png256x256") { - - r_ret=icon256; - } else if (n=="version_info/version_major") { - - r_ret=version_major; - } else if (n=="version_info/version_minor") { - - r_ret=version_minor; - } else if (n=="version_info/version_text") { - - r_ret=version_text; - } else if (n=="version_info/company_name") { - - r_ret=company_name; - } else if (n=="version_info/file_description") { - - r_ret=file_description; - } else if (n=="version_info/product_name") { - - r_ret=product_name; - } else if (n=="version_info/legal_copyright") { - - r_ret=legal_copyright; - } else if (n=="version_info/add_godot_version") { - - r_ret=set_godot_version; - } else - return false; - - return true; - -} - -void EditorExportPlatformWindows::_get_property_list( List<PropertyInfo> *p_list) const { - - p_list->push_back( PropertyInfo( Variant::STRING, "icon/icon_ico",PROPERTY_HINT_FILE,"ico") ); - p_list->push_back( PropertyInfo( Variant::STRING, "icon/icon_png",PROPERTY_HINT_FILE,"png") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png16x16") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png32x32") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png48x48") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png64x64") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png128x128") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "icon/icon_png256x256") ); - p_list->push_back( PropertyInfo( Variant::INT, "version_info/version_major", PROPERTY_HINT_RANGE,"0,65535,1")); - p_list->push_back( PropertyInfo( Variant::INT, "version_info/version_minor", PROPERTY_HINT_RANGE,"0,65535,0")); - p_list->push_back( PropertyInfo( Variant::STRING, "version_info/version_text") ); - p_list->push_back( PropertyInfo( Variant::STRING, "version_info/company_name") ); - p_list->push_back( PropertyInfo( Variant::STRING, "version_info/file_description") ); - p_list->push_back( PropertyInfo( Variant::STRING, "version_info/product_name") ); - p_list->push_back( PropertyInfo( Variant::STRING, "version_info/legal_copyright") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "version_info/add_godot_version") ); - -} - -Error EditorExportPlatformWindows::export_project(const String& p_path, bool p_debug, int p_flags) { - - Error err = EditorExportPlatformPC::export_project(p_path, p_debug, p_flags); - if(err != OK) - { - return err; - } - EditorProgress ep("editexe","Edit EXE File",102); - ep.step("Create ico file..",0); - - DVector<uint8_t> icon_content; - if (this->icon_ico!="" && this->icon_ico.ends_with(".ico")) { - FileAccess *f = FileAccess::open(this->icon_ico,FileAccess::READ); - if (f) { - icon_content.resize(f->get_len()); - DVector<uint8_t>::Write write = icon_content.write(); - f->get_buffer(write.ptr(),icon_content.size()); - f->close(); - memdelete(f); - } - } else if (this->icon_png!="" && this->icon_png.ends_with(".png") && (icon16 || icon32 || icon48 || icon64 || icon128 || icon256)) { - #ifdef PNG_ENABLED - Vector<Image> pngs; - Image png; - Error err_png = png.load(this->icon_png); - if (err_png==OK && !png.empty()) { - if(icon256) { - Image icon_256(png); - if(!(png.get_height()==256 && png.get_width()==256)) icon_256.resize(256,256); - pngs.push_back(icon_256); - } - if(icon128) { - Image icon_128(png); - if(!(png.get_height()==128 && png.get_width()==128)) icon_128.resize(128,128); - pngs.push_back(icon_128); - } - if(icon64) { - Image icon_64(png); - if(!(png.get_height()==64 && png.get_width()==64)) icon_64.resize(64,64); - pngs.push_back(icon_64); - } - if(icon48) { - Image icon_48(png); - if(!(png.get_height()==48 && png.get_width()==48)) icon_48.resize(48,48); - pngs.push_back(icon_48); - } - if(icon32) { - Image icon_32(png); - if(!(png.get_height()==32 && png.get_width()==32)) icon_32.resize(32,32); - pngs.push_back(icon_32); - } - if(icon16) { - Image icon_16(png); - if(!(png.get_height()==16 && png.get_width()==16)) icon_16.resize(16,16); - pngs.push_back(icon_16); - } - // create icon according to https://www.daubnet.com/en/file-format-ico - store_16(icon_content,0); //Reserved - store_16(icon_content,1); //Type - store_16(icon_content,pngs.size()); //Count - int offset = 6+pngs.size()*16; - //List of bitmaps - for(int i=0;i<pngs.size();i++) { - int w = pngs[i].get_width(); - int h = pngs[i].get_height(); - icon_content.push_back(w<256?w:0); //width - icon_content.push_back(h<256?h:0); //height - icon_content.push_back(0); //ColorCount = 0 - icon_content.push_back(0); //Reserved - store_16(icon_content,1); //Planes - store_16(icon_content,32); //BitCount (bit per pixel) - int size = 40 + (w * h * 4) + (w * h / 8); - store_32(icon_content,size); //Size of (InfoHeader + ANDbitmap + XORbitmap) - store_32(icon_content,offset); //FileOffset - offset += size; - } - //Write bmp files. - for(int i=0;i<pngs.size();i++) { - int w = pngs[i].get_width(); - int h = pngs[i].get_height(); - store_32(icon_content,40); //Size of InfoHeader structure = 40 - store_32(icon_content,w); //Width - store_32(icon_content,h*2); //Height - store_16(icon_content,1); //Planes - store_16(icon_content,32); //BitCount - store_32(icon_content,0); //Compression - store_32(icon_content,w*h*4); //ImageSize = Size of Image in Bytes - store_32(icon_content,0); //unused = 0 - store_32(icon_content,0); //unused = 0 - store_32(icon_content,0); //unused = 0 - store_32(icon_content,0); //unused = 0 - //XORBitmap - for(int y=h-1;y>=0;y--) { - for(int x=0;x<w;x++) { - store_32(icon_content,pngs[i].get_pixel(x,y).to_32()); - } - } - //ANDBitmap - for(int m=0;m<(w * h / 8);m+=4) store_32(icon_content,0x00000000); // Add empty ANDBitmap , TODO create full ANDBitmap Structure if need. - } - } - #endif - } - - ep.step("Add rsrc..",50); - - String basename = Globals::get_singleton()->get("application/name"); - product_name=product_name.replace("$genname",basename); - String godot_version; - if(set_godot_version) godot_version = String( VERSION_MKSTRING ); - String ret = pe_bliss_add_resrc(p_path.utf8(), version_major, version_minor, - company_name, file_description, legal_copyright, version_text, - product_name, godot_version, icon_content); - if (ret.empty()) { - return OK; - } else { - EditorNode::add_io_error(ret); - return ERR_FILE_CANT_WRITE; - } -} - -EditorExportPlatformWindows::EditorExportPlatformWindows() { - - icon16=true; - icon32=true; - icon48=true; - icon64=true; - icon128=true; - icon256=true; - product_name="$genname"; - company_name="Godot Engine"; - file_description="Created With Godot Engine"; - version_text="1.0"; - OS::Date date = OS::get_singleton()->get_date(); - legal_copyright="Copyright (c) 2007-"; - legal_copyright+=String::num(date.year); - legal_copyright+=" Juan Linietsky, Ariel Manzur"; - version_major=1; - version_minor=0; - set_godot_version=true; -} - - +#include "tools/editor/editor_import_export.h" void register_windows_exporter() { @@ -348,7 +9,7 @@ void register_windows_exporter() { logo->create_from_image(img); { - Ref<EditorExportPlatformWindows> exporter = Ref<EditorExportPlatformWindows>( memnew(EditorExportPlatformWindows) ); + Ref<EditorExportPlatformPC> exporter = Ref<EditorExportPlatformPC>( memnew(EditorExportPlatformPC) ); exporter->set_binary_extension("exe"); exporter->set_release_binary32("windows_32_release.exe"); exporter->set_debug_binary32("windows_32_debug.exe"); diff --git a/platform/windows/export/export.h b/platform/windows/export/export.h index 2424efc861..68ce500a20 100644 --- a/platform/windows/export/export.h +++ b/platform/windows/export/export.h @@ -1,37 +1,4 @@ -#include "tools/editor/editor_import_export.h" -class EditorExportPlatformWindows : public EditorExportPlatformPC { - OBJ_TYPE( EditorExportPlatformWindows,EditorExportPlatformPC ); - -private: - String icon_ico; - String icon_png; - bool icon16; - bool icon32; - bool icon48; - bool icon64; - bool icon128; - bool icon256; - String company_name; - String file_description; - String product_name; - String legal_copyright; - String version_text; - int version_major; - int version_minor; - bool set_godot_version; - void store_16(DVector<uint8_t>& vector, uint16_t value); ///< store 16 bits uint - void store_32(DVector<uint8_t>& vector, uint32_t value); ///< store 32 bits uint - -protected: - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List<PropertyInfo> *p_list) const; - -public: - Error export_project(const String& p_path, bool p_debug,int p_flags=0); - EditorExportPlatformWindows(); -}; void register_windows_exporter(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 6f19f8bdfe..95a6a6ac58 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -47,7 +47,6 @@ #include "tcp_server_winsock.h" #include "packet_peer_udp_winsock.h" #include "stream_peer_winsock.h" -#include "os/pc_joystick_map.h" #include "lang_table.h" #include "os/memory_pool_dynamic_prealloc.h" #include "globals.h" @@ -67,6 +66,10 @@ extern "C" { #endif } +#ifndef WM_MOUSEHWHEEL +#define WM_MOUSEHWHEEL 0x020e +#endif + //#define STDOUT_FILE extern HINSTANCE godot_hinstance; @@ -149,7 +152,7 @@ const char * OS_Windows::get_video_driver_name(int p_driver) const { OS::VideoMode OS_Windows::get_default_video_mode() const { - return VideoMode(1280,720,false); + return VideoMode(1024,600,false); } int OS_Windows::get_audio_driver_count() const { @@ -433,6 +436,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: /*case WM_XBUTTONDOWN: @@ -503,12 +507,24 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { if (motion>0) - mb.button_index=4; + mb.button_index= BUTTON_WHEEL_UP; else - mb.button_index=5; + mb.button_index= BUTTON_WHEEL_DOWN; } break; + case WM_MOUSEHWHEEL: { + + mb.pressed = true; + int motion = (short)HIWORD(wParam); + if (!motion) + return 0; + + if (motion<0) + mb.button_index = BUTTON_WHEEL_LEFT; + else + mb.button_index = BUTTON_WHEEL_RIGHT; + } break; /* case WM_XBUTTONDOWN: { mb.pressed=true; @@ -2059,7 +2075,7 @@ String OS_Windows::get_system_dir(SystemDir p_dir) const { id=CSIDL_MYPICTURES; } break; case SYSTEM_DIR_DOCUMENTS: { - id=0x000C; + id=CSIDL_PERSONAL; } break; case SYSTEM_DIR_DOWNLOADS: { id=0x000C ; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index e433d5cc11..ab4acf312c 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -29,7 +29,7 @@ #ifndef OS_WINDOWS_H #define OS_WINDOWS_H -#define WINVER 0x0500 +#define WINVER 0x0600 #include "os/input.h" #include "os/os.h" diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp index f507c1aae7..b6ce7f950d 100644 --- a/platform/winrt/os_winrt.cpp +++ b/platform/winrt/os_winrt.cpp @@ -43,7 +43,6 @@ #include "servers/audio/audio_server_sw.h" #include "servers/visual/visual_server_wrap_mt.h" -#include "os/pc_joystick_map.h" #include "os/memory_pool_dynamic_prealloc.h" #include "globals.h" #include "io/marshalls.h" diff --git a/platform/x11/detect.py b/platform/x11/detect.py index e035c72993..f49475a2d5 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -52,6 +52,7 @@ def get_opts(): return [ ('use_llvm','Use llvm compiler','no'), + ('use_static_cpp','link stdc++ statically','no'), ('use_sanitizer','Use llvm compiler sanitize address','no'), ('use_leak_sanitizer','Use llvm compiler sanitize memory leaks','no'), ('pulseaudio','Detect & Use pulseaudio','yes'), @@ -158,18 +159,14 @@ def configure(env): if (env["gamepad"]=="yes" and platform.system() == "Linux"): # pkg-config returns 0 when the lib exists... found_udev = not os.system("pkg-config --exists libudev") - found_evdev = not os.system("pkg-config --exists libevdev") - if (found_udev and found_evdev): - print("Enabling gamepad support with udev/evdev") + if (found_udev): + print("Enabling gamepad support with udev") env.Append(CPPFLAGS=["-DJOYDEV_ENABLED"]) env.ParseConfig('pkg-config libudev --cflags --libs') - env.ParseConfig('pkg-config libevdev --cflags --libs') else: - if (not found_udev): - print("libudev development libraries not found") - if (not found_evdev): - print("libevdev development libraries not found") + print("libudev development libraries not found") + print("Some libraries are missing for the required gamepad support, aborting!") print("Install the mentioned libraries or build with 'gamepad=no' to disable gamepad support.") sys.exit(255) @@ -207,5 +204,8 @@ def configure(env): env.Append(CPPFLAGS=['-DNEW_WM_API']) env.ParseConfig('pkg-config xinerama --cflags --libs') + if (env["use_static_cpp"]=="yes"): + env.Append(LINKFLAGS=['-static-libstdc++']) + env["x86_opt_gcc"]=True diff --git a/platform/x11/joystick_linux.cpp b/platform/x11/joystick_linux.cpp index 6eb3671bc0..ef866d5d3a 100644 --- a/platform/x11/joystick_linux.cpp +++ b/platform/x11/joystick_linux.cpp @@ -31,22 +31,35 @@ #ifdef JOYDEV_ENABLED #include "joystick_linux.h" -#include "print_string.h" -#include <libevdev/libevdev.h> +#include <linux/input.h> #include <libudev.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <cstring> + +#define LONG_BITS (sizeof(long) * 8) +#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0) +#define NBITS(x) ((((x)-1)/LONG_BITS)+1) static const char* ignore_str = "/dev/input/js"; joystick_linux::Joystick::Joystick() { fd = -1; dpad = 0; - dev = NULL; devpath = ""; + for (int i = 0; i < MAX_ABS; i++) { + abs_info[i] = NULL; + } +} + +joystick_linux::Joystick::~Joystick() { + + for (int i = 0; i < MAX_ABS; i++) { + if (abs_info[i]) { + memdelete(abs_info[i]); + } + } } void joystick_linux::Joystick::reset() { @@ -112,10 +125,14 @@ void joystick_linux::enumerate_joysticks(udev *p_udev) { dev = udev_device_new_from_syspath(p_udev, path); const char* devnode = udev_device_get_devnode(dev); - if (devnode != NULL && strstr(devnode, ignore_str) == NULL) { - joy_mutex->lock(); - open_joystick(devnode); - joy_mutex->unlock(); + if (devnode) { + + String devnode_str = devnode; + if (devnode_str.find(ignore_str) == -1) { + joy_mutex->lock(); + open_joystick(devnode); + joy_mutex->unlock(); + } } udev_device_unref(dev); } @@ -146,22 +163,24 @@ void joystick_linux::monitor_joysticks(udev *p_udev) { /* Check if our file descriptor has received data. */ if (ret > 0 && FD_ISSET(fd, &fds)) { /* Make the call to receive the device. - select() ensured that this will not block. */ + select() ensured that this will not block. */ dev = udev_monitor_receive_device(mon); if (dev && udev_device_get_devnode(dev) != 0) { joy_mutex->lock(); - const char* action = udev_device_get_action(dev); + String action = udev_device_get_action(dev); const char* devnode = udev_device_get_devnode(dev); + if (devnode) { - if (strstr(devnode, ignore_str) == NULL) { - - if (strcmp(action, "add") == 0) - open_joystick(devnode); + String devnode_str = devnode; + if (devnode_str.find(ignore_str) == -1) { - else if (strcmp(action, "remove") == 0) - close_joystick(get_joy_from_path(devnode)); + if (action == "add") + open_joystick(devnode); + else if (String(action) == "remove") + close_joystick(get_joy_from_path(devnode)); + } } udev_device_unref(dev); @@ -208,7 +227,6 @@ void joystick_linux::close_joystick(int p_id) { if (joy.fd != -1) { - libevdev_free(joy.dev); close(joy.fd); joy.fd = -1; input->joy_connection_changed(p_id, false, ""); @@ -230,21 +248,27 @@ static String _hex_str(uint8_t p_byte) { void joystick_linux::setup_joystick_properties(int p_id) { Joystick* joy = &joysticks[p_id]; - libevdev* dev = joy->dev; + + unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; + unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; int num_buttons = 0; int num_axes = 0; + if ((ioctl(joy->fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || + (ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) { + return; + } for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) { - if (libevdev_has_event_code(dev, EV_KEY, i)) { + if (test_bit(i, keybit)) { joy->key_map[i] = num_buttons++; } } for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) { - if (libevdev_has_event_code(dev, EV_KEY, i)) { + if (test_bit(i, keybit)) { joy->key_map[i] = num_buttons++; } @@ -255,68 +279,85 @@ void joystick_linux::setup_joystick_properties(int p_id) { i = ABS_HAT3Y; continue; } - if (libevdev_has_event_code(dev, EV_ABS, i)) { + if (test_bit(i, absbit)) { joy->abs_map[i] = num_axes++; + joy->abs_info[i] = memnew(input_absinfo); + if (ioctl(joy->fd, EVIOCGABS(i), joy->abs_info[i]) < 0) { + memdelete(joy->abs_info[i]); + joy->abs_info[i] = NULL; + } } } } + void joystick_linux::open_joystick(const char *p_path) { int joy_num = get_free_joy_slot(); int fd = open(p_path, O_RDONLY | O_NONBLOCK); if (fd != -1 && joy_num != -1) { - int rc = libevdev_new_from_fd(fd, &joysticks[joy_num].dev); - if (rc < 0) { + unsigned long evbit[NBITS(EV_MAX)] = { 0 }; + unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; + unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; - fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc)); + if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || + (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || + (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) { + close(fd); return; } - libevdev *dev = joysticks[joy_num].dev; - //check if the device supports basic gamepad events, prevents certain keyboards from //being detected as joysticks - if (libevdev_has_event_type(dev, EV_ABS) && libevdev_has_event_type(dev, EV_KEY) && - (libevdev_has_event_code(dev, EV_KEY, BTN_A) || libevdev_has_event_code(dev, EV_KEY, BTN_THUMBL) || libevdev_has_event_code(dev, EV_KEY, BTN_TOP))) { - - char uid[128]; - String name = libevdev_get_name(dev); - uint16_t bus = __bswap_16(libevdev_get_id_bustype(dev)); - uint16_t vendor = __bswap_16(libevdev_get_id_vendor(dev)); - uint16_t product = __bswap_16(libevdev_get_id_product(dev)); - uint16_t version = __bswap_16(libevdev_get_id_version(dev)); - - joysticks[joy_num].reset(); - - Joystick &joy = joysticks[joy_num]; - joy.fd = fd; - joy.devpath = String(p_path); - setup_joystick_properties(joy_num); - sprintf(uid, "%04x%04x", bus, 0); - if (vendor && product && version) { - - sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0); - input->joy_connection_changed(joy_num, true, name, uid); - } - else { - String uidname = uid; - int uidlen = MIN(name.length(), 11); - for (int i=0; i<uidlen; i++) { + if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && + (test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit) || + test_bit(ABS_GAS, absbit) || test_bit(ABS_RUDDER, absbit)) && + (test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) || + test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) { + close(fd); + return; + } - uidname = uidname + _hex_str(name[i]); - } - uidname += "00"; - input->joy_connection_changed(joy_num, true, name, uidname); + char uid[128]; + char namebuf[128]; + String name = ""; + input_id inpid; + if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) >= 0) { + name = namebuf; + } - } + if (ioctl(fd, EVIOCGID, &inpid) < 0) { + close(fd); + return; + } + + joysticks[joy_num].reset(); + + Joystick &joy = joysticks[joy_num]; + joy.fd = fd; + joy.devpath = String(p_path); + setup_joystick_properties(joy_num); + sprintf(uid, "%04x%04x", __bswap_16(inpid.bustype), 0); + if (inpid.vendor && inpid.product && inpid.version) { + + uint16_t vendor = __bswap_16(inpid.vendor); + uint16_t product = __bswap_16(inpid.product); + uint16_t version = __bswap_16(inpid.version); + + sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0); + input->joy_connection_changed(joy_num, true, name, uid); } else { - //device is not a gamepad, clean up - libevdev_free(dev); - close(fd); + String uidname = uid; + int uidlen = MIN(name.length(), 11); + for (int i=0; i<uidlen; i++) { + + uidname = uidname + _hex_str(name[i]); + } + uidname += "00"; + input->joy_connection_changed(joy_num, true, name, uidname); } } } @@ -350,58 +391,54 @@ uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) { if (joysticks[i].fd == -1) continue; - input_event ev; + input_event events[32]; Joystick* joy = &joysticks[i]; - libevdev* dev = joy->dev; - int rc = 1; - rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); + int len; - if (rc < 0 && rc != -EAGAIN) { - continue; - } - - while (rc == LIBEVDEV_READ_STATUS_SYNC || rc == LIBEVDEV_READ_STATUS_SUCCESS) { - - switch (ev.type) { - case EV_KEY: - p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value); - break; - - case EV_ABS: - - switch (ev.code) { - case ABS_HAT0X: - if (ev.value != 0) { - if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_LEFT; - else joy->dpad |= InputDefault::HAT_MASK_RIGHT; - - } - else joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT); - - p_event_id = input->joy_hat(p_event_id, i, joy->dpad); - break; - - case ABS_HAT0Y: - if (ev.value != 0) { - if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_UP; - else joy->dpad |= InputDefault::HAT_MASK_DOWN; - } - else joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN); + while ((len = read(joy->fd, events, (sizeof events))) > 0) { + len /= sizeof(events[0]); + for (int j = 0; j < len; j++) { - p_event_id = input->joy_hat(p_event_id, i, joy->dpad); + input_event &ev = events[j]; + switch (ev.type) { + case EV_KEY: + p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value); break; - default: - if (joy->abs_map[ev.code] != -1) { - InputDefault::JoyAxis value = axis_correct(libevdev_get_abs_info(dev, ev.code), ev.value); - joy->curr_axis[joy->abs_map[ev.code]] = value; + case EV_ABS: + + switch (ev.code) { + case ABS_HAT0X: + if (ev.value != 0) { + if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_LEFT; + else joy->dpad |= InputDefault::HAT_MASK_RIGHT; + } + else joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT); + + p_event_id = input->joy_hat(p_event_id, i, joy->dpad); + break; + + case ABS_HAT0Y: + if (ev.value != 0) { + if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_UP; + else joy->dpad |= InputDefault::HAT_MASK_DOWN; + } + else joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN); + + p_event_id = input->joy_hat(p_event_id, i, joy->dpad); + break; + + default: + if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) { + InputDefault::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value); + joy->curr_axis[joy->abs_map[ev.code]] = value; + } + break; } break; } - break; } - rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); } for (int j = 0; j < MAX_ABS; j++) { int index = joy->abs_map[j]; diff --git a/platform/x11/joystick_linux.h b/platform/x11/joystick_linux.h index ee9bd0352a..7f96e3451f 100644 --- a/platform/x11/joystick_linux.h +++ b/platform/x11/joystick_linux.h @@ -61,9 +61,10 @@ private: int fd; String devpath; - struct libevdev *dev; + input_absinfo *abs_info[MAX_ABS]; Joystick(); + ~Joystick(); void reset(); }; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 82df8dff60..e5591810e7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -65,7 +65,6 @@ #include <X11/Xatom.h> -//#include "os/pc_joystick_map.h" #undef CursorShape @@ -78,7 +77,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(1280,720,false); + return OS::VideoMode(1024,600,false); } int OS_X11::get_audio_driver_count() const { @@ -575,6 +574,10 @@ Point2 OS_X11::get_mouse_pos() const { void OS_X11::set_window_title(const String& p_title) { XStoreName(x11_display,x11_window,p_title.utf8().get_data()); + + Atom _net_wm_name = XInternAtom(x11_display, "_NET_WM_NAME", false); + Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false); + XChangeProperty( x11_display, x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char*) p_title.utf8().get_data(), p_title.utf8().length()); } void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) { @@ -1782,6 +1785,22 @@ String OS_X11::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } +void OS_X11::set_context(int p_context) { + + XClassHint* classHint = NULL; + classHint = XAllocClassHint(); + if (classHint) { + + if (p_context == CONTEXT_EDITOR) + classHint->res_name = (char *)"Godot_Editor"; + if (p_context == CONTEXT_PROJECTMAN) + classHint->res_name = (char *)"Godot_ProjectList"; + classHint->res_class = (char *)"Godot"; + XSetClassHint(x11_display, x11_window, classHint); + XFree(classHint); + } +} + OS_X11::OS_X11() { #ifdef RTAUDIO_ENABLED diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 91dbeac284..0891e4b8eb 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -226,6 +226,8 @@ public: virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; + virtual void set_context(int p_context); + void run(); OS_X11(); |