├── logo.png ├── SCsub ├── LICENSE.txt ├── README.md ├── haiku_application.cpp ├── platform_config.h ├── haiku_application.h ├── key_mapping_haiku.h ├── haiku_gl_view.h ├── godot_haiku.cpp ├── haiku_gl_view.cpp ├── context_gl_haiku.h ├── audio_driver_media_kit.h ├── context_gl_haiku.cpp ├── godot.rdef ├── haiku_direct_window.h ├── audio_driver_media_kit.cpp ├── os_haiku.h ├── detect.py ├── key_mapping_haiku.cpp ├── os_haiku.cpp └── haiku_direct_window.cpp /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godotengine/godot-platform-haiku/HEAD/logo.png -------------------------------------------------------------------------------- /SCsub: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | Import("env") 4 | 5 | common_haiku = [ 6 | "os_haiku.cpp", 7 | "context_gl_haiku.cpp", 8 | "haiku_application.cpp", 9 | "haiku_direct_window.cpp", 10 | "haiku_gl_view.cpp", 11 | "key_mapping_haiku.cpp", 12 | "audio_driver_media_kit.cpp", 13 | ] 14 | 15 | target = env.add_program("#bin/godot", ["godot_haiku.cpp"] + common_haiku) 16 | 17 | command = env.Command("#bin/godot.rsrc", "#platform/haiku/godot.rdef", ["rc -o $TARGET $SOURCE"]) 18 | 19 | 20 | def addResourcesAction(target=None, source=None, env=None): 21 | return env.Execute("xres -o " + File(target)[0].path + " bin/godot.rsrc") 22 | 23 | 24 | env.AddPostAction(target, addResourcesAction) 25 | env.Depends(target, command) 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. 2 | Copyright (c) 2014-2020 Godot Engine contributors. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Godot Engine platform port for Haiku 2 | 3 | This is the platform port of [Godot Engine](https://godotengine.org) for the 4 | [Haiku](https://www.haiku-os.org) operating system. 5 | 6 | Haiku is not an officially supported platform in the main tree of Godot, so 7 | this port is kept separate so that it can be contributed to independently of 8 | Godot's main release cycle. 9 | 10 | It may imply that this port might not be functional for the latest versions of 11 | Godot. For the time being, neither the `3.2` branch nor the `master` branch are 12 | functional out-of-the-box on Haiku. 13 | 14 | We welcome all contributions from Haiku developers to ensure that each branch 15 | and Git tag of this repository work as expected with the matching branches and 16 | tags of the [Godot repository](https://github.com/godotengine/godot/). 17 | 18 | ## Usage 19 | 20 | This code is meant to be copied as `platform/haiku` in the Godot Engine 21 | [source repository](https://github.com/godotengine/godot/) to make builds of 22 | Godot for Haiku. 23 | 24 | It can also be cloned as a Git submodule: 25 | 26 | ``` 27 | git clone https://github.com/godotengine/godot 28 | cd godot 29 | git submodule add https://github.com/godotengine/godot-haiku-platform platform/haiku 30 | ``` 31 | 32 | Be sure to use compatible branches for the Godot repository and the Haiku port. 33 | 34 | You can then compile Godot for Haiku with: 35 | 36 | ``` 37 | # Editor build, optimized. 38 | scons p=haiku tools=yes target=release_debug 39 | 40 | # Export template, debug. 41 | scons p=haiku tools=no target=release_debug 42 | # Export template, release. 43 | scons p=haiku tools=no target=release 44 | ``` 45 | 46 | ## License 47 | 48 | This port is distributed under the MIT license, with the same copyright as the 49 | main Godot source repository. 50 | 51 | See [LICENSE.txt](/LICENSE.txt) for details, and 52 | [AUTHORS.md](https://github.com/godotengine/godot/blob/master/AUTHORS.md) in 53 | the Godot repository for a list of contributors. 54 | -------------------------------------------------------------------------------- /haiku_application.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_application.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "haiku_application.h" 32 | 33 | HaikuApplication::HaikuApplication() : 34 | BApplication("application/x-vnd.godot") { 35 | } 36 | -------------------------------------------------------------------------------- /platform_config.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* platform_config.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include 32 | 33 | // for ifaddrs.h needed in drivers/unix/ip_unix.cpp 34 | #define _BSD_SOURCE 1 35 | 36 | #define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h" 37 | -------------------------------------------------------------------------------- /haiku_application.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_application.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef HAIKU_APPLICATION_H 32 | #define HAIKU_APPLICATION_H 33 | 34 | #include // needed for image_id 35 | 36 | #include 37 | 38 | class HaikuApplication : public BApplication { 39 | public: 40 | HaikuApplication(); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /key_mapping_haiku.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* key_mapping_haiku.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef KEY_MAPPING_HAIKU_H 32 | #define KEY_MAPPING_HAIKU_H 33 | 34 | class KeyMappingHaiku { 35 | KeyMappingHaiku() {} 36 | 37 | public: 38 | static unsigned int get_keysym(int32 raw_char, int32 key); 39 | static unsigned int get_modifier_keysym(int32 key); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /haiku_gl_view.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_gl_view.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef HAIKU_GL_VIEW_H 32 | #define HAIKU_GL_VIEW_H 33 | 34 | #include // needed for image_id 35 | 36 | #include 37 | 38 | class HaikuGLView : public BGLView { 39 | public: 40 | HaikuGLView(BRect frame, uint32 type); 41 | virtual void AttachedToWindow(void); 42 | virtual void Draw(BRect updateRect); 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /godot_haiku.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* godot_haiku.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "main/main.h" 32 | #include "os_haiku.h" 33 | 34 | int main(int argc, char *argv[]) { 35 | OS_Haiku os; 36 | 37 | Error error = Main::setup(argv[0], argc - 1, &argv[1]); 38 | if (error != OK) { 39 | return 255; 40 | } 41 | 42 | if (Main::start()) { 43 | os.run(); 44 | } 45 | 46 | Main::cleanup(); 47 | 48 | return os.get_exit_code(); 49 | } 50 | -------------------------------------------------------------------------------- /haiku_gl_view.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_gl_view.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "haiku_gl_view.h" 32 | #include "main/main.h" 33 | 34 | HaikuGLView::HaikuGLView(BRect frame, uint32 type) : 35 | BGLView(frame, "GodotGLView", B_FOLLOW_ALL_SIDES, 0, type) { 36 | } 37 | 38 | void HaikuGLView::AttachedToWindow(void) { 39 | LockGL(); 40 | BGLView::AttachedToWindow(); 41 | UnlockGL(); 42 | MakeFocus(); 43 | } 44 | 45 | void HaikuGLView::Draw(BRect updateRect) { 46 | Main::force_redraw(); 47 | } 48 | -------------------------------------------------------------------------------- /context_gl_haiku.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* context_gl_haiku.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef CONTEXT_GL_HAIKU_H 32 | #define CONTEXT_GL_HAIKU_H 33 | 34 | #if defined(OPENGL_ENABLED) 35 | 36 | #include "haiku_direct_window.h" 37 | #include "haiku_gl_view.h" 38 | 39 | class ContextGL_Haiku { 40 | private: 41 | HaikuGLView *view; 42 | HaikuDirectWindow *window; 43 | 44 | bool use_vsync; 45 | 46 | public: 47 | Error initialize(); 48 | void release_current(); 49 | void make_current(); 50 | void swap_buffers(); 51 | int get_window_width(); 52 | int get_window_height(); 53 | 54 | void set_use_vsync(bool p_use); 55 | bool is_using_vsync() const; 56 | 57 | ContextGL_Haiku(HaikuDirectWindow *p_window); 58 | ~ContextGL_Haiku(); 59 | }; 60 | 61 | #endif 62 | #endif 63 | -------------------------------------------------------------------------------- /audio_driver_media_kit.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* audio_driver_media_kit.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "servers/audio_server.h" 32 | 33 | #ifdef MEDIA_KIT_ENABLED 34 | 35 | #include "core/os/mutex.h" 36 | #include "core/os/thread.h" 37 | 38 | #include // needed for image_id 39 | 40 | #include 41 | 42 | class AudioDriverMediaKit : public AudioDriver { 43 | Mutex mutex; 44 | 45 | BSoundPlayer *player; 46 | static int32_t *samples_in; 47 | 48 | static void PlayBuffer(void *cookie, void *buffer, size_t size, const media_raw_audio_format &format); 49 | 50 | unsigned int mix_rate; 51 | SpeakerMode speaker_mode; 52 | unsigned int buffer_size; 53 | int channels; 54 | 55 | bool active; 56 | 57 | public: 58 | const char *get_name() const { 59 | return "MediaKit"; 60 | }; 61 | 62 | virtual Error init(); 63 | virtual void start(); 64 | virtual int get_mix_rate() const; 65 | virtual SpeakerMode get_speaker_mode() const; 66 | virtual void lock(); 67 | virtual void unlock(); 68 | virtual void finish(); 69 | 70 | AudioDriverMediaKit(); 71 | ~AudioDriverMediaKit(); 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /context_gl_haiku.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* context_gl_haiku.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "context_gl_haiku.h" 32 | 33 | #if defined(OPENGL_ENABLED) 34 | 35 | ContextGL_Haiku::ContextGL_Haiku(HaikuDirectWindow *p_window) { 36 | window = p_window; 37 | 38 | uint32 type = BGL_RGB | BGL_DOUBLE | BGL_DEPTH; 39 | view = new HaikuGLView(window->Bounds(), type); 40 | 41 | use_vsync = false; 42 | } 43 | 44 | ContextGL_Haiku::~ContextGL_Haiku() { 45 | delete view; 46 | } 47 | 48 | Error ContextGL_Haiku::initialize() { 49 | window->AddChild(view); 50 | window->SetHaikuGLView(view); 51 | 52 | return OK; 53 | } 54 | 55 | void ContextGL_Haiku::release_current() { 56 | view->UnlockGL(); 57 | } 58 | 59 | void ContextGL_Haiku::make_current() { 60 | view->LockGL(); 61 | } 62 | 63 | void ContextGL_Haiku::swap_buffers() { 64 | view->SwapBuffers(use_vsync); 65 | } 66 | 67 | int ContextGL_Haiku::get_window_width() { 68 | return window->Bounds().IntegerWidth(); 69 | } 70 | 71 | int ContextGL_Haiku::get_window_height() { 72 | return window->Bounds().IntegerHeight(); 73 | } 74 | 75 | void ContextGL_Haiku::set_use_vsync(bool p_use) { 76 | use_vsync = p_use; 77 | } 78 | 79 | bool ContextGL_Haiku::is_using_vsync() const { 80 | return use_vsync; 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /godot.rdef: -------------------------------------------------------------------------------- 1 | resource app_version { 2 | major = 2, 3 | middle = 0, 4 | minor = 0, 5 | 6 | variety = B_APPV_FINAL, 7 | internal = 0, 8 | 9 | short_info = "Godot Game Engine", 10 | long_info = "An advanced, feature packed, multi-platform 2D and 3D game engine." 11 | }; 12 | 13 | resource app_signature "application/x-vnd.godot"; 14 | 15 | resource vector_icon { 16 | $"6E6369660403A39F9F05FF03478CBF03414042090A04B37FB379CC26B379CC26" 17 | $"CC20B37FCC200A09B5E9C41B2AC240B8E1BDFBBFA1BDA4C6A7BDFFCA1AC45CC9" 18 | $"7AC607C01CC75BB6F4C65A062AFE9FFF9F69FE7FFEDFCF0FC95FC3D7C95FC51E" 19 | $"C95FC51EC95FC53EC92BC565C94AC55BC92BC565C728C60BC728C60BC712C612" 20 | $"C6E6C600C6F9C60EC6D3C5F2C6C7C5C4C6C7C5DCC6C7C5C4C460C4E5C4BCC4E5" 21 | $"C626C4E5C626C4E5C64BC4A5C670C4CAC66BC4A5C670C1EDC6CFC1EDC6CFC1E9" 22 | $"C6CFC1E2C6D0C1E6C6D0C1D1C6D0C1B2C6BEC1BFC6C9C1A2C6AFC19851C198C6" 23 | $"9BC19851C505C031C507C507C016C507BFFCC507C507BE94C505BE9451BE9451" 24 | $"BE94C69BBE7BC6BEBE8BC6AFBE6DC6C9BE4AC6D0BE5CC6D0BE47C6D0BE40C6CF" 25 | $"BE44C6CFBE40C6CFBB87C670BB87C670BB63C66BBB47C626BB47C64BBB47C626" 26 | $"C4BCB965C460B965C5C4B965C5C4B965C5DCB947C600B95AC5F2B934C60EB904" 27 | $"C60BB91BC612B904C60BB701C565B701C565B6E3C55BB6CEC51EB6CEC53EB6CE" 28 | $"C51EC3D7B590C36CB590C36CB581C3B0B578C43AB578C3F5B578C78FBFF8CA27" 29 | $"BA2ACA22BFF8CA27BFFABFFCCA27BFFCCA27C5CACA22CA7CC43ACA7CC78FCA7C" 30 | $"C3FBCA67C37ECA754ACA67C37E0639F6F97FFEF8E7FFF9F6FFFFFFFFFF03B67D" 31 | $"BDEEC31FB730C35CB730C35CB74EC3662BC3A22BC3822BC3A2C4E8B8D1C55EB8" 32 | $"D1C406B8D1C406B8D1C3F0B8ECC3CDB8DBC3DBB8FDC3BFB929C3BDB913C3B9B9" 33 | $"29C3BDBB9FC436BB9FC436BBC2C43CBBDCC47EBBDCC45BBBDCC47EC5E6BE00C6" 34 | $"31BE00C4BBBE00C4BBBE00C4A7BE16C486BE08C494BE24C479BE4AC471BE37C4" 35 | $"71BE4AC471BE4BC016C473C1E2C471C1E2C471C1F6C471C217C486C209C479C2" 36 | $"25C494C22DC4BBC22DC4A7C22DC4BBC631C451C5E6C451C47EC451C47EC451C4" 37 | $"5BC48DC436C46AC43CC48DC436C704C3BDC704C3BDC719C3B9C741C3CDC730C3" 38 | $"BF53C3DBC75CC406C75CC3F0C75CC406C55EC8CAC4E8C8CAC3A2C8CAC3A2C8CA" 39 | $"C382C8FDC35CC8DFC366C8FDC35CC977C333BDEEC97ABDEEC97ABDEEC9F1BD56" 40 | $"CAC9BC0BCA60BCB6CA3DBB1CC8D9B981C991BA47C82FB9D7C6EDBAA0C789BA38" 41 | $"C69FBA52C5F0B9D0C647BA12C59BB98BC4E0B91FC53BB959C4FBB855C50EB6C0" 42 | $"C509B78FC424B64AC22DB5C4C32AB5FCC1C8B66DC11BB7D9C16BB725C0BCB7C9" 43 | $"BFFCB7C2C05CB7C3BFFCB7C2BFFCB7C2BFFCB7C2BFFBB7C2BFFAB7C2BFFAB7C2" 44 | $"BFF9B7C2BFF8B7C2BFF9B7C2BFF8B7C2BFF8B7C2BFF8B7C2BF98B7C3BED9B7D9" 45 | $"BF38B7C9BE88B725BDC7B5C4BE2CB66DBCCAB5FCBAE6B6C0BBD0B64ABAEBB78F" 46 | $"BB13B91F34B855BAB8B959BA04B9D0BA59B98BB9ADBA12B907BAA0B955BA52B8" 47 | $"6ABA38B71AB981B7C5B9D7B663BA47B52BBC0BB5B7BB1CB594BCB6B679BDEEB6" 48 | $"02BD56B679BDEE0005BD3EC06CBD3EC06CBD3EC197BB2147BC4C47B9F647B904" 49 | $"C06CB904C197B904BF41BB21BE4FB9F6BE4FBC4CBE4FBD3EC06CBD3EBF41BD3E" 50 | $"C06C0005BCBC42BCBC42BCBCC153BB55C1F3BC1BC1F3BA8EC1F3B9ED42B9EDC1" 51 | $"53B9EDBFC6BB55BF25BA8EBF25BC1BBF25BCBC42BCBCBFC6BCBC420007C01BC2" 52 | $"BBC01BC2BBBFBAC2BBBF6CC21CBF6CC274BF6CC21CBF6CC02ABF6CC02ABF6CBF" 53 | $"D3C01BBF8CBFBABF8CC07BBF8CC0C9C02AC0C9BFD3C0C9C02AC0C9C21CC0C9C2" 54 | $"1CC0C9C274C01BC2BBC07BC2BBC01BC2BB0005C2F7C06CC2F7C06CC2F7C197C5" 55 | $"1547C3E947C64047C732C06CC732C197C732BF41C515BE4FC640BE4FC3E9BE4F" 56 | $"C2F7C06CC2F7BF41C2F7C06C0005C37942C37942C379C153C4E1C1F3C41AC1F3" 57 | $"C5A7C1F3C64842C648C153C648BFC6C4E1BF25C5A7BF25C41ABF25C37942C379" 58 | $"BFC6C37942090A0000000A010101000A020102000A020103000A010104000A03" 59 | $"0105000A010106000A010107000A03010800" 60 | }; 61 | -------------------------------------------------------------------------------- /haiku_direct_window.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_direct_window.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef HAIKU_DIRECT_WINDOW_H 32 | #define HAIKU_DIRECT_WINDOW_H 33 | 34 | #include // needed for image_id 35 | 36 | #include 37 | 38 | #include "core/input/input.h" 39 | #include "core/os/os.h" 40 | 41 | #include "haiku_gl_view.h" 42 | 43 | #define REDRAW_MSG 'rdrw' 44 | #define LOCKGL_MSG 'glck' 45 | #define UNLOCKGL_MSG 'ulck' 46 | 47 | class HaikuDirectWindow : public BDirectWindow { 48 | private: 49 | Point2i last_mouse_position; 50 | bool last_mouse_pos_valid; 51 | uint32 last_buttons_state; 52 | uint32 last_key_modifier_state; 53 | int last_button_mask; 54 | OS::VideoMode *current_video_mode; 55 | 56 | MainLoop *main_loop; 57 | InputDefault *input; 58 | HaikuGLView *view; 59 | BMessageRunner *update_runner; 60 | 61 | void HandleMouseButton(BMessage *message); 62 | void HandleMouseMoved(BMessage *message); 63 | void HandleMouseWheelChanged(BMessage *message); 64 | void HandleWindowResized(BMessage *message); 65 | void HandleKeyboardEvent(BMessage *message); 66 | void HandleKeyboardModifierEvent(BMessage *message); 67 | inline void GetKeyModifierState(Ref event, uint32 p_state); 68 | inline int GetMouseButtonState(uint32 p_state); 69 | 70 | public: 71 | HaikuDirectWindow(BRect p_frame); 72 | ~HaikuDirectWindow(); 73 | 74 | void SetHaikuGLView(HaikuGLView *p_view); 75 | void StartMessageRunner(); 76 | void StopMessageRunner(); 77 | void SetInput(InputDefault *p_input); 78 | void SetMainLoop(MainLoop *p_main_loop); 79 | inline void SetVideoMode(OS::VideoMode *video_mode) { current_video_mode = video_mode; }; 80 | virtual bool QuitRequested(); 81 | virtual void DirectConnected(direct_buffer_info *info); 82 | virtual void MessageReceived(BMessage *message); 83 | virtual void DispatchMessage(BMessage *message, BHandler *handler); 84 | 85 | inline Point2i GetLastMousePosition() { return last_mouse_position; }; 86 | inline int GetLastButtonMask() { return last_button_mask; }; 87 | }; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /audio_driver_media_kit.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* audio_driver_media_kit.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "audio_driver_media_kit.h" 32 | 33 | #ifdef MEDIA_KIT_ENABLED 34 | 35 | #include "core/project_settings.h" 36 | 37 | int32_t *AudioDriverMediaKit::samples_in = nullptr; 38 | 39 | Error AudioDriverMediaKit::init() { 40 | active = false; 41 | 42 | mix_rate = GLOBAL_GET("audio/mix_rate"); 43 | speaker_mode = SPEAKER_MODE_STEREO; 44 | channels = 2; 45 | 46 | int latency = GLOBAL_GET("audio/output_latency"); 47 | buffer_size = next_power_of_2(latency * mix_rate / 1000); 48 | samples_in = memnew_arr(int32_t, buffer_size * channels); 49 | 50 | media_raw_audio_format format; 51 | format = media_raw_audio_format::wildcard; 52 | format.frame_rate = mix_rate; 53 | format.channel_count = channels; 54 | format.format = media_raw_audio_format::B_AUDIO_INT; 55 | format.byte_order = B_MEDIA_LITTLE_ENDIAN; 56 | format.buffer_size = buffer_size * sizeof(int32_t) * channels; 57 | 58 | player = new BSoundPlayer( 59 | &format, 60 | "godot_sound_server", 61 | AudioDriverMediaKit::PlayBuffer, 62 | nullptr, 63 | this); 64 | 65 | if (player->InitCheck() != B_OK) { 66 | fprintf(stderr, "MediaKit ERR: can not create a BSoundPlayer instance\n"); 67 | ERR_FAIL_COND_V(player == nullptr, ERR_CANT_OPEN); 68 | } 69 | 70 | player->Start(); 71 | 72 | return OK; 73 | } 74 | 75 | void AudioDriverMediaKit::PlayBuffer(void *cookie, void *buffer, size_t size, const media_raw_audio_format &format) { 76 | AudioDriverMediaKit *ad = (AudioDriverMediaKit *)cookie; 77 | int32_t *buf = (int32_t *)buffer; 78 | 79 | if (!ad->active) { 80 | for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { 81 | AudioDriverMediaKit::samples_in[i] = 0; 82 | } 83 | } else { 84 | ad->lock(); 85 | ad->audio_server_process(ad->buffer_size, AudioDriverMediaKit::samples_in); 86 | ad->unlock(); 87 | } 88 | 89 | for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { 90 | buf[i] = AudioDriverMediaKit::samples_in[i]; 91 | } 92 | } 93 | 94 | void AudioDriverMediaKit::start() { 95 | active = true; 96 | } 97 | 98 | int AudioDriverMediaKit::get_mix_rate() const { 99 | return mix_rate; 100 | } 101 | 102 | AudioDriverMediaKit::SpeakerMode AudioDriverMediaKit::get_speaker_mode() const { 103 | return speaker_mode; 104 | } 105 | 106 | void AudioDriverMediaKit::lock() { 107 | if (!mutex) 108 | return; 109 | 110 | mutex.lock(); 111 | } 112 | 113 | void AudioDriverMediaKit::unlock() { 114 | if (!mutex) 115 | return; 116 | 117 | mutex.unlock(); 118 | } 119 | 120 | void AudioDriverMediaKit::finish() { 121 | delete player; 122 | 123 | if (samples_in) { 124 | memdelete_arr(samples_in); 125 | }; 126 | } 127 | 128 | AudioDriverMediaKit::AudioDriverMediaKit() { 129 | player = nullptr; 130 | } 131 | 132 | AudioDriverMediaKit::~AudioDriverMediaKit() { 133 | } 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /os_haiku.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* os_haiku.h */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #ifndef OS_HAIKU_H 32 | #define OS_HAIKU_H 33 | 34 | #include "audio_driver_media_kit.h" 35 | #include "context_gl_haiku.h" 36 | #include "core/input/input.h" 37 | #include "drivers/unix/os_unix.h" 38 | #include "haiku_application.h" 39 | #include "haiku_direct_window.h" 40 | #include "servers/audio_server.h" 41 | #include "servers/rendering_server.h" 42 | 43 | class OS_Haiku : public OS_Unix { 44 | private: 45 | HaikuApplication *app; 46 | HaikuDirectWindow *window; 47 | MainLoop *main_loop; 48 | InputDefault *input; 49 | RenderingServer *rendering_server; 50 | VideoMode current_video_mode; 51 | int video_driver_index; 52 | 53 | #ifdef MEDIA_KIT_ENABLED 54 | AudioDriverMediaKit driver_media_kit; 55 | #endif 56 | 57 | #if defined(OPENGL_ENABLED) 58 | ContextGL_Haiku *context_gl; 59 | #endif 60 | 61 | virtual void delete_main_loop(); 62 | 63 | protected: 64 | virtual int get_video_driver_count() const; 65 | virtual const char *get_video_driver_name(int p_driver) const; 66 | virtual int get_current_video_driver() const; 67 | 68 | virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); 69 | virtual void finalize(); 70 | 71 | virtual void set_main_loop(MainLoop *p_main_loop); 72 | 73 | public: 74 | OS_Haiku(); 75 | void run(); 76 | 77 | virtual String get_name() const; 78 | 79 | virtual MainLoop *get_main_loop() const; 80 | 81 | virtual bool can_draw() const; 82 | virtual void release_rendering_thread(); 83 | virtual void make_rendering_thread(); 84 | virtual void swap_buffers(); 85 | 86 | virtual Point2 get_mouse_position() const; 87 | virtual int get_mouse_button_state() const; 88 | virtual void set_cursor_shape(CursorShape p_shape); 89 | virtual CursorShape get_cursor_shape() const; 90 | virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot); 91 | 92 | virtual int get_screen_count() const; 93 | virtual int get_current_screen() const; 94 | virtual void set_current_screen(int p_screen); 95 | virtual Point2 get_screen_position(int p_screen = -1) const; 96 | virtual Size2 get_screen_size(int p_screen = -1) const; 97 | virtual void set_window_title(const String &p_title); 98 | virtual Size2 get_window_size() const; 99 | virtual void set_window_size(const Size2 p_size); 100 | virtual Point2 get_window_position() const; 101 | virtual void set_window_position(const Point2 &p_position); 102 | virtual void set_window_fullscreen(bool p_enabled); 103 | virtual bool is_window_fullscreen() const; 104 | virtual void set_window_resizable(bool p_enabled); 105 | virtual bool is_window_resizable() const; 106 | virtual void set_window_minimized(bool p_enabled); 107 | virtual bool is_window_minimized() const; 108 | virtual void set_window_maximized(bool p_enabled); 109 | virtual bool is_window_maximized() const; 110 | 111 | virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0); 112 | virtual VideoMode get_video_mode(int p_screen = 0) const; 113 | virtual void get_fullscreen_mode_list(List *p_list, int p_screen = 0) const; 114 | virtual String get_executable_path() const; 115 | 116 | virtual bool _check_internal_feature_support(const String &p_feature); 117 | 118 | virtual String get_config_path() const; 119 | virtual String get_data_path() const; 120 | virtual String get_cache_path() const; 121 | }; 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /detect.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | def is_active(): 6 | return True 7 | 8 | 9 | def get_name(): 10 | return "Haiku" 11 | 12 | 13 | def can_build(): 14 | 15 | if os.name != "posix" or sys.platform == "darwin": 16 | return False 17 | 18 | return True 19 | 20 | 21 | def get_opts(): 22 | from SCons.Variables import EnumVariable 23 | 24 | return [ 25 | EnumVariable("debug_symbols", "Add debugging symbols to release builds", "yes", ("yes", "no", "full")), 26 | ] 27 | 28 | 29 | def get_flags(): 30 | 31 | return [] 32 | 33 | 34 | def configure(env): 35 | 36 | ## Build type 37 | 38 | if env["target"] == "release": 39 | env.Prepend(CCFLAGS=["-O3"]) 40 | if env["debug_symbols"] == "yes": 41 | env.Prepend(CCFLAGS=["-g1"]) 42 | if env["debug_symbols"] == "full": 43 | env.Prepend(CCFLAGS=["-g2"]) 44 | 45 | elif env["target"] == "release_debug": 46 | env.Prepend(CCFLAGS=["-O2", "-DDEBUG_ENABLED"]) 47 | if env["debug_symbols"] == "yes": 48 | env.Prepend(CCFLAGS=["-g1"]) 49 | if env["debug_symbols"] == "full": 50 | env.Prepend(CCFLAGS=["-g2"]) 51 | 52 | elif env["target"] == "debug": 53 | env.Prepend(CCFLAGS=["-g3", "-DDEBUG_ENABLED"]) 54 | 55 | ## Architecture 56 | 57 | is64 = sys.maxsize > 2 ** 32 58 | if env["bits"] == "default": 59 | env["bits"] = "64" if is64 else "32" 60 | 61 | ## Compiler configuration 62 | 63 | env["CC"] = "gcc-x86" 64 | env["CXX"] = "g++-x86" 65 | 66 | ## Dependencies 67 | 68 | if not env["builtin_libwebp"]: 69 | env.ParseConfig("pkg-config libwebp --cflags --libs") 70 | 71 | # freetype depends on libpng and zlib, so bundling one of them while keeping others 72 | # as shared libraries leads to weird issues 73 | if env["builtin_freetype"] or env["builtin_libpng"] or env["builtin_zlib"]: 74 | env["builtin_freetype"] = True 75 | env["builtin_libpng"] = True 76 | env["builtin_zlib"] = True 77 | 78 | if not env["builtin_freetype"]: 79 | env.ParseConfig("pkg-config freetype2 --cflags --libs") 80 | 81 | if not env["builtin_libpng"]: 82 | env.ParseConfig("pkg-config libpng16 --cflags --libs") 83 | 84 | if not env["builtin_bullet"]: 85 | # We need at least version 2.88 86 | import subprocess 87 | 88 | bullet_version = subprocess.check_output(["pkg-config", "bullet", "--modversion"]).strip() 89 | if bullet_version < "2.88": 90 | # Abort as system bullet was requested but too old 91 | print( 92 | "Bullet: System version {0} does not match minimal requirements ({1}). Aborting.".format( 93 | bullet_version, "2.88" 94 | ) 95 | ) 96 | sys.exit(255) 97 | env.ParseConfig("pkg-config bullet --cflags --libs") 98 | 99 | if not env["builtin_enet"]: 100 | env.ParseConfig("pkg-config libenet --cflags --libs") 101 | 102 | if not env["builtin_squish"]: 103 | env.ParseConfig("pkg-config libsquish --cflags --libs") 104 | 105 | if not env["builtin_zstd"]: 106 | env.ParseConfig("pkg-config libzstd --cflags --libs") 107 | 108 | # Sound and video libraries 109 | # Keep the order as it triggers chained dependencies (ogg needed by others, etc.) 110 | 111 | if not env["builtin_libtheora"]: 112 | env["builtin_libogg"] = False # Needed to link against system libtheora 113 | env["builtin_libvorbis"] = False # Needed to link against system libtheora 114 | env.ParseConfig("pkg-config theora theoradec --cflags --libs") 115 | 116 | if not env["builtin_libvpx"]: 117 | env.ParseConfig("pkg-config vpx --cflags --libs") 118 | 119 | if not env["builtin_libvorbis"]: 120 | env["builtin_libogg"] = False # Needed to link against system libvorbis 121 | env.ParseConfig("pkg-config vorbis vorbisfile --cflags --libs") 122 | 123 | if not env["builtin_opus"]: 124 | env["builtin_libogg"] = False # Needed to link against system opus 125 | env.ParseConfig("pkg-config opus opusfile --cflags --libs") 126 | 127 | if not env["builtin_libogg"]: 128 | env.ParseConfig("pkg-config ogg --cflags --libs") 129 | 130 | if env["builtin_libtheora"]: 131 | list_of_x86 = ["x86_64", "x86", "i386", "i586"] 132 | if any(platform.machine() in s for s in list_of_x86): 133 | env["x86_libtheora_opt_gcc"] = True 134 | 135 | if not env["builtin_wslay"]: 136 | env.ParseConfig("pkg-config libwslay --cflags --libs") 137 | 138 | if not env["builtin_mbedtls"]: 139 | # mbedTLS does not provide a pkgconfig config yet. See https://github.com/ARMmbed/mbedtls/issues/228 140 | env.Append(LIBS=["mbedtls", "mbedcrypto", "mbedx509"]) 141 | 142 | if not env["builtin_miniupnpc"]: 143 | # No pkgconfig file so far, hardcode default paths. 144 | env.Prepend(CPPPATH=["/system/develop/headers/x86/miniupnpc"]) 145 | env.Append(LIBS=["miniupnpc"]) 146 | 147 | # On Linux wchar_t should be 32-bits 148 | # 16-bit library shouldn't be required due to compiler optimisations 149 | if not env["builtin_pcre2"]: 150 | env.ParseConfig("pkg-config libpcre2-32 --cflags --libs") 151 | 152 | ## Flags 153 | 154 | env.Prepend(CPPPATH=["#platform/haiku"]) 155 | env.Append(CPPDEFINES=["UNIX_ENABLED", "OPENGL_ENABLED", "GLES_ENABLED"]) 156 | env.Append(CPPDEFINES=["MEDIA_KIT_ENABLED"]) 157 | env.Append(CPPDEFINES=["PTHREAD_NO_RENAME"]) # TODO: enable when we have pthread_setname_np 158 | env.Append(LIBS=["be", "game", "media", "network", "bnetapi", "z", "GL"]) 159 | -------------------------------------------------------------------------------- /key_mapping_haiku.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* key_mapping_haiku.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include 32 | 33 | #include "core/os/keyboard.h" 34 | #include "key_mapping_haiku.h" 35 | 36 | struct _HaikuTranslatePair { 37 | unsigned int keysym; 38 | int32 keycode; 39 | }; 40 | 41 | static _HaikuTranslatePair _mod_to_keycode[] = { 42 | { KEY_SHIFT, B_SHIFT_KEY }, 43 | { KEY_ALT, B_COMMAND_KEY }, 44 | { KEY_CONTROL, B_CONTROL_KEY }, 45 | { KEY_CAPSLOCK, B_CAPS_LOCK }, 46 | { KEY_SCROLLLOCK, B_SCROLL_LOCK }, 47 | { KEY_NUMLOCK, B_NUM_LOCK }, 48 | { KEY_SUPER_L, B_OPTION_KEY }, 49 | { KEY_MENU, B_MENU_KEY }, 50 | { KEY_SHIFT, B_LEFT_SHIFT_KEY }, 51 | { KEY_SHIFT, B_RIGHT_SHIFT_KEY }, 52 | { KEY_ALT, B_LEFT_COMMAND_KEY }, 53 | { KEY_ALT, B_RIGHT_COMMAND_KEY }, 54 | { KEY_CONTROL, B_LEFT_CONTROL_KEY }, 55 | { KEY_CONTROL, B_RIGHT_CONTROL_KEY }, 56 | { KEY_SUPER_L, B_LEFT_OPTION_KEY }, 57 | { KEY_SUPER_R, B_RIGHT_OPTION_KEY }, 58 | { KEY_UNKNOWN, 0 } 59 | }; 60 | 61 | static _HaikuTranslatePair _fn_to_keycode[] = { 62 | { KEY_F1, B_F1_KEY }, 63 | { KEY_F2, B_F2_KEY }, 64 | { KEY_F3, B_F3_KEY }, 65 | { KEY_F4, B_F4_KEY }, 66 | { KEY_F5, B_F5_KEY }, 67 | { KEY_F6, B_F6_KEY }, 68 | { KEY_F7, B_F7_KEY }, 69 | { KEY_F8, B_F8_KEY }, 70 | { KEY_F9, B_F9_KEY }, 71 | { KEY_F10, B_F10_KEY }, 72 | { KEY_F11, B_F11_KEY }, 73 | { KEY_F12, B_F12_KEY }, 74 | //{ KEY_F13, ? }, 75 | //{ KEY_F14, ? }, 76 | //{ KEY_F15, ? }, 77 | //{ KEY_F16, ? }, 78 | { KEY_PRINT, B_PRINT_KEY }, 79 | { KEY_SCROLLLOCK, B_SCROLL_KEY }, 80 | { KEY_PAUSE, B_PAUSE_KEY }, 81 | { KEY_UNKNOWN, 0 } 82 | }; 83 | 84 | static _HaikuTranslatePair _hb_to_keycode[] = { 85 | { KEY_BACKSPACE, B_BACKSPACE }, 86 | { KEY_TAB, B_TAB }, 87 | { KEY_ENTER, B_RETURN }, 88 | { KEY_CAPSLOCK, B_CAPS_LOCK }, 89 | { KEY_ESCAPE, B_ESCAPE }, 90 | { KEY_SPACE, B_SPACE }, 91 | { KEY_PAGEUP, B_PAGE_UP }, 92 | { KEY_PAGEDOWN, B_PAGE_DOWN }, 93 | { KEY_END, B_END }, 94 | { KEY_HOME, B_HOME }, 95 | { KEY_LEFT, B_LEFT_ARROW }, 96 | { KEY_UP, B_UP_ARROW }, 97 | { KEY_RIGHT, B_RIGHT_ARROW }, 98 | { KEY_DOWN, B_DOWN_ARROW }, 99 | { KEY_PRINT, B_PRINT_KEY }, 100 | { KEY_INSERT, B_INSERT }, 101 | { KEY_DELETE, B_DELETE }, 102 | // { KEY_HELP, ??? }, 103 | 104 | { KEY_0, (0x30) }, 105 | { KEY_1, (0x31) }, 106 | { KEY_2, (0x32) }, 107 | { KEY_3, (0x33) }, 108 | { KEY_4, (0x34) }, 109 | { KEY_5, (0x35) }, 110 | { KEY_6, (0x36) }, 111 | { KEY_7, (0x37) }, 112 | { KEY_8, (0x38) }, 113 | { KEY_9, (0x39) }, 114 | { KEY_A, (0x61) }, 115 | { KEY_B, (0x62) }, 116 | { KEY_C, (0x63) }, 117 | { KEY_D, (0x64) }, 118 | { KEY_E, (0x65) }, 119 | { KEY_F, (0x66) }, 120 | { KEY_G, (0x67) }, 121 | { KEY_H, (0x68) }, 122 | { KEY_I, (0x69) }, 123 | { KEY_J, (0x6A) }, 124 | { KEY_K, (0x6B) }, 125 | { KEY_L, (0x6C) }, 126 | { KEY_M, (0x6D) }, 127 | { KEY_N, (0x6E) }, 128 | { KEY_O, (0x6F) }, 129 | { KEY_P, (0x70) }, 130 | { KEY_Q, (0x71) }, 131 | { KEY_R, (0x72) }, 132 | { KEY_S, (0x73) }, 133 | { KEY_T, (0x74) }, 134 | { KEY_U, (0x75) }, 135 | { KEY_V, (0x76) }, 136 | { KEY_W, (0x77) }, 137 | { KEY_X, (0x78) }, 138 | { KEY_Y, (0x79) }, 139 | { KEY_Z, (0x7A) }, 140 | 141 | /* 142 | { KEY_PLAY, VK_PLAY},// (0xFA) 143 | { KEY_STANDBY,VK_SLEEP },//(0x5F) 144 | { KEY_BACK,VK_BROWSER_BACK},// (0xA6) 145 | { KEY_FORWARD,VK_BROWSER_FORWARD},// (0xA7) 146 | { KEY_REFRESH,VK_BROWSER_REFRESH},// (0xA8) 147 | { KEY_STOP,VK_BROWSER_STOP},// (0xA9) 148 | { KEY_SEARCH,VK_BROWSER_SEARCH},// (0xAA) 149 | { KEY_FAVORITES, VK_BROWSER_FAVORITES},// (0xAB) 150 | { KEY_HOMEPAGE,VK_BROWSER_HOME},// (0xAC) 151 | { KEY_VOLUMEMUTE,VK_VOLUME_MUTE},// (0xAD) 152 | { KEY_VOLUMEDOWN,VK_VOLUME_DOWN},// (0xAE) 153 | { KEY_VOLUMEUP,VK_VOLUME_UP},// (0xAF) 154 | { KEY_MEDIANEXT,VK_MEDIA_NEXT_TRACK},// (0xB0) 155 | { KEY_MEDIAPREVIOUS,VK_MEDIA_PREV_TRACK},// (0xB1) 156 | { KEY_MEDIASTOP,VK_MEDIA_STOP},// (0xB2) 157 | { KEY_LAUNCHMAIL, VK_LAUNCH_MAIL},// (0xB4) 158 | { KEY_LAUNCHMEDIA,VK_LAUNCH_MEDIA_SELECT},// (0xB5) 159 | { KEY_LAUNCH0,VK_LAUNCH_APP1},// (0xB6) 160 | { KEY_LAUNCH1,VK_LAUNCH_APP2},// (0xB7) 161 | */ 162 | 163 | { KEY_SEMICOLON, 0x3B }, 164 | { KEY_EQUAL, 0x3D }, 165 | { KEY_COLON, 0x2C }, 166 | { KEY_MINUS, 0x2D }, 167 | { KEY_PERIOD, 0x2E }, 168 | { KEY_SLASH, 0x2F }, 169 | { KEY_KP_MULTIPLY, 0x2A }, 170 | { KEY_KP_ADD, 0x2B }, 171 | 172 | { KEY_QUOTELEFT, 0x60 }, 173 | { KEY_BRACKETLEFT, 0x5B }, 174 | { KEY_BACKSLASH, 0x5C }, 175 | { KEY_BRACKETRIGHT, 0x5D }, 176 | { KEY_APOSTROPHE, 0x27 }, 177 | 178 | { KEY_UNKNOWN, 0 } 179 | }; 180 | 181 | unsigned int KeyMappingHaiku::get_keysym(int32 raw_char, int32 key) { 182 | if (raw_char == B_INSERT && key == 0x64) { 183 | return KEY_KP_0; 184 | } 185 | if (raw_char == B_END && key == 0x58) { 186 | return KEY_KP_1; 187 | } 188 | if (raw_char == B_DOWN_ARROW && key == 0x59) { 189 | return KEY_KP_2; 190 | } 191 | if (raw_char == B_PAGE_DOWN && key == 0x5A) { 192 | return KEY_KP_3; 193 | } 194 | if (raw_char == B_LEFT_ARROW && key == 0x48) { 195 | return KEY_KP_4; 196 | } 197 | if (raw_char == 0x35 && key == 0x49) { 198 | return KEY_KP_5; 199 | } 200 | if (raw_char == B_RIGHT_ARROW && key == 0x4A) { 201 | return KEY_KP_6; 202 | } 203 | if (raw_char == B_HOME && key == 0x37) { 204 | return KEY_KP_7; 205 | } 206 | if (raw_char == B_UP_ARROW && key == 0x38) { 207 | return KEY_KP_8; 208 | } 209 | if (raw_char == B_PAGE_UP && key == 0x39) { 210 | return KEY_KP_9; 211 | } 212 | if (raw_char == 0x2F && key == 0x23) { 213 | return KEY_KP_DIVIDE; 214 | } 215 | if (raw_char == 0x2D && key == 0x25) { 216 | return KEY_KP_SUBTRACT; 217 | } 218 | if (raw_char == B_DELETE && key == 0x65) { 219 | return KEY_KP_PERIOD; 220 | } 221 | 222 | if (raw_char == 0x10) { 223 | for (int i = 0; _fn_to_keycode[i].keysym != KEY_UNKNOWN; i++) { 224 | if (_fn_to_keycode[i].keycode == key) { 225 | return _fn_to_keycode[i].keysym; 226 | } 227 | } 228 | 229 | return KEY_UNKNOWN; 230 | } 231 | 232 | for (int i = 0; _hb_to_keycode[i].keysym != KEY_UNKNOWN; i++) { 233 | if (_hb_to_keycode[i].keycode == raw_char) { 234 | return _hb_to_keycode[i].keysym; 235 | } 236 | } 237 | 238 | return KEY_UNKNOWN; 239 | } 240 | 241 | unsigned int KeyMappingHaiku::get_modifier_keysym(int32 key) { 242 | for (int i = 0; _mod_to_keycode[i].keysym != KEY_UNKNOWN; i++) { 243 | if ((_mod_to_keycode[i].keycode & key) != 0) { 244 | return _mod_to_keycode[i].keysym; 245 | } 246 | } 247 | 248 | return KEY_UNKNOWN; 249 | } 250 | -------------------------------------------------------------------------------- /os_haiku.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* os_haiku.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include "os_haiku.h" 32 | 33 | #include "drivers/gles2/rasterizer_gles2.h" 34 | #include "main/main.h" 35 | #include "servers/physics_3d/physics_server_3d_sw.h" 36 | #include "servers/rendering/rendering_server_raster.h" 37 | #include "servers/rendering/rendering_server_wrap_mt.h" 38 | 39 | #include 40 | 41 | OS_Haiku::OS_Haiku() { 42 | #ifdef MEDIA_KIT_ENABLED 43 | AudioDriverManager::add_driver(&driver_media_kit); 44 | #endif 45 | }; 46 | 47 | void OS_Haiku::run() { 48 | if (!main_loop) { 49 | return; 50 | } 51 | 52 | main_loop->init(); 53 | context_gl->release_current(); 54 | 55 | // TODO: clean up 56 | BMessenger *bms = new BMessenger(window); 57 | BMessage *msg = new BMessage(); 58 | bms->SendMessage(LOCKGL_MSG, msg); 59 | 60 | window->StartMessageRunner(); 61 | app->Run(); 62 | window->StopMessageRunner(); 63 | 64 | delete app; 65 | 66 | delete bms; 67 | delete msg; 68 | main_loop->finish(); 69 | } 70 | 71 | String OS_Haiku::get_name() const { 72 | return "Haiku"; 73 | } 74 | 75 | int OS_Haiku::get_video_driver_count() const { 76 | return 1; 77 | } 78 | 79 | const char *OS_Haiku::get_video_driver_name(int p_driver) const { 80 | return "GLES2"; 81 | } 82 | 83 | int OS_Haiku::get_current_video_driver() const { 84 | return video_driver_index; 85 | } 86 | 87 | Error OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { 88 | main_loop = nullptr; 89 | current_video_mode = p_desired; 90 | 91 | app = new HaikuApplication(); 92 | 93 | BRect frame; 94 | frame.Set(50, 50, 50 + current_video_mode.width - 1, 50 + current_video_mode.height - 1); 95 | 96 | window = new HaikuDirectWindow(frame); 97 | window->SetVideoMode(¤t_video_mode); 98 | 99 | if (current_video_mode.fullscreen) { 100 | window->SetFullScreen(true); 101 | } 102 | 103 | if (!current_video_mode.resizable) { 104 | uint32 flags = window->Flags(); 105 | flags |= B_NOT_RESIZABLE; 106 | window->SetFlags(flags); 107 | } 108 | 109 | #if defined(OPENGL_ENABLED) 110 | context_gl = memnew(ContextGL_Haiku(window)); 111 | context_gl->initialize(); 112 | context_gl->make_current(); 113 | context_gl->set_use_vsync(current_video_mode.use_vsync); 114 | // FIXME: That's not how the rasterizer setup should happen. 115 | RasterizerGLES2::register_config(); 116 | RasterizerGLES2::make_current(); 117 | #endif 118 | 119 | rendering_server = memnew(RenderingServerRaster); 120 | // FIXME: Reimplement threaded rendering 121 | if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { 122 | rendering_server = memnew(RenderingServerWrapMT(rendering_server, false)); 123 | } 124 | 125 | ERR_FAIL_COND_V(!rendering_server, ERR_UNAVAILABLE); 126 | 127 | video_driver_index = p_video_driver; 128 | 129 | input = memnew(InputDefault); 130 | window->SetInput(input); 131 | 132 | window->Show(); 133 | rendering_server->init(); 134 | 135 | AudioDriverManager::initialize(p_audio_driver); 136 | 137 | return OK; 138 | } 139 | 140 | void OS_Haiku::finalize() { 141 | if (main_loop) { 142 | memdelete(main_loop); 143 | } 144 | 145 | main_loop = nullptr; 146 | 147 | rendering_server->finish(); 148 | memdelete(rendering_server); 149 | 150 | memdelete(input); 151 | 152 | #if defined(OPENGL_ENABLED) 153 | memdelete(context_gl); 154 | #endif 155 | } 156 | 157 | void OS_Haiku::set_main_loop(MainLoop *p_main_loop) { 158 | main_loop = p_main_loop; 159 | input->set_main_loop(p_main_loop); 160 | window->SetMainLoop(p_main_loop); 161 | } 162 | 163 | MainLoop *OS_Haiku::get_main_loop() const { 164 | return main_loop; 165 | } 166 | 167 | void OS_Haiku::delete_main_loop() { 168 | if (main_loop) { 169 | memdelete(main_loop); 170 | } 171 | 172 | main_loop = nullptr; 173 | window->SetMainLoop(nullptr); 174 | } 175 | 176 | void OS_Haiku::release_rendering_thread() { 177 | context_gl->release_current(); 178 | } 179 | 180 | void OS_Haiku::make_rendering_thread() { 181 | context_gl->make_current(); 182 | } 183 | 184 | bool OS_Haiku::can_draw() const { 185 | // TODO: implement 186 | return true; 187 | } 188 | 189 | void OS_Haiku::swap_buffers() { 190 | context_gl->swap_buffers(); 191 | } 192 | 193 | Point2 OS_Haiku::get_mouse_position() const { 194 | return window->GetLastMousePosition(); 195 | } 196 | 197 | int OS_Haiku::get_mouse_button_state() const { 198 | return window->GetLastButtonMask(); 199 | } 200 | 201 | void OS_Haiku::set_cursor_shape(CursorShape p_shape) { 202 | //ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); 203 | } 204 | 205 | OS::CursorShape OS_Haiku::get_cursor_shape() const { 206 | // TODO: implement get_cursor_shape 207 | } 208 | 209 | void OS_Haiku::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { 210 | // TODO 211 | } 212 | 213 | int OS_Haiku::get_screen_count() const { 214 | // TODO: implement get_screen_count() 215 | return 1; 216 | } 217 | 218 | int OS_Haiku::get_current_screen() const { 219 | // TODO: implement get_current_screen() 220 | return 0; 221 | } 222 | 223 | void OS_Haiku::set_current_screen(int p_screen) { 224 | // TODO: implement set_current_screen() 225 | } 226 | 227 | Point2 OS_Haiku::get_screen_position(int p_screen) const { 228 | // TODO: make this work with the p_screen parameter 229 | BScreen *screen = new BScreen(window); 230 | BRect frame = screen->Frame(); 231 | delete screen; 232 | return Point2i(frame.left, frame.top); 233 | } 234 | 235 | Size2 OS_Haiku::get_screen_size(int p_screen) const { 236 | // TODO: make this work with the p_screen parameter 237 | BScreen *screen = new BScreen(window); 238 | BRect frame = screen->Frame(); 239 | delete screen; 240 | return Size2i(frame.IntegerWidth() + 1, frame.IntegerHeight() + 1); 241 | } 242 | 243 | void OS_Haiku::set_window_title(const String &p_title) { 244 | window->SetTitle(p_title.utf8().get_data()); 245 | } 246 | 247 | Size2 OS_Haiku::get_window_size() const { 248 | BSize size = window->Size(); 249 | return Size2i(size.IntegerWidth() + 1, size.IntegerHeight() + 1); 250 | } 251 | 252 | void OS_Haiku::set_window_size(const Size2 p_size) { 253 | // TODO: why does it stop redrawing after this is called? 254 | window->ResizeTo(p_size.x, p_size.y); 255 | } 256 | 257 | Point2 OS_Haiku::get_window_position() const { 258 | BPoint point(0, 0); 259 | window->ConvertToScreen(&point); 260 | return Point2i(point.x, point.y); 261 | } 262 | 263 | void OS_Haiku::set_window_position(const Point2 &p_position) { 264 | window->MoveTo(p_position.x, p_position.y); 265 | } 266 | 267 | void OS_Haiku::set_window_fullscreen(bool p_enabled) { 268 | window->SetFullScreen(p_enabled); 269 | current_video_mode.fullscreen = p_enabled; 270 | rendering_server->init(); 271 | } 272 | 273 | bool OS_Haiku::is_window_fullscreen() const { 274 | return current_video_mode.fullscreen; 275 | } 276 | 277 | void OS_Haiku::set_window_resizable(bool p_enabled) { 278 | uint32 flags = window->Flags(); 279 | 280 | if (p_enabled) { 281 | flags &= ~(B_NOT_RESIZABLE); 282 | } else { 283 | flags |= B_NOT_RESIZABLE; 284 | } 285 | 286 | window->SetFlags(flags); 287 | current_video_mode.resizable = p_enabled; 288 | } 289 | 290 | bool OS_Haiku::is_window_resizable() const { 291 | return current_video_mode.resizable; 292 | } 293 | 294 | void OS_Haiku::set_window_minimized(bool p_enabled) { 295 | window->Minimize(p_enabled); 296 | } 297 | 298 | bool OS_Haiku::is_window_minimized() const { 299 | return window->IsMinimized(); 300 | } 301 | 302 | void OS_Haiku::set_window_maximized(bool p_enabled) { 303 | window->Minimize(!p_enabled); 304 | } 305 | 306 | bool OS_Haiku::is_window_maximized() const { 307 | return !window->IsMinimized(); 308 | } 309 | 310 | void OS_Haiku::set_video_mode(const VideoMode &p_video_mode, int p_screen) { 311 | ERR_PRINT("set_video_mode() NOT IMPLEMENTED"); 312 | } 313 | 314 | OS::VideoMode OS_Haiku::get_video_mode(int p_screen) const { 315 | return current_video_mode; 316 | } 317 | 318 | void OS_Haiku::get_fullscreen_mode_list(List *p_list, int p_screen) const { 319 | ERR_PRINT("get_fullscreen_mode_list() NOT IMPLEMENTED"); 320 | } 321 | 322 | String OS_Haiku::get_executable_path() const { 323 | return OS::get_executable_path(); 324 | } 325 | 326 | bool OS_Haiku::_check_internal_feature_support(const String &p_feature) { 327 | return p_feature == "pc"; 328 | } 329 | 330 | String OS_Haiku::get_config_path() const { 331 | if (has_environment("XDG_CONFIG_HOME")) { 332 | return get_environment("XDG_CONFIG_HOME"); 333 | } else if (has_environment("HOME")) { 334 | return get_environment("HOME").plus_file("config/settings"); 335 | } else { 336 | return "."; 337 | } 338 | } 339 | 340 | String OS_Haiku::get_data_path() const { 341 | if (has_environment("XDG_DATA_HOME")) { 342 | return get_environment("XDG_DATA_HOME"); 343 | } else if (has_environment("HOME")) { 344 | return get_environment("HOME").plus_file("config/data"); 345 | } else { 346 | return get_config_path(); 347 | } 348 | } 349 | 350 | String OS_Haiku::get_cache_path() const { 351 | if (has_environment("XDG_CACHE_HOME")) { 352 | return get_environment("XDG_CACHE_HOME"); 353 | } else if (has_environment("HOME")) { 354 | return get_environment("HOME").plus_file("config/cache"); 355 | } else { 356 | return get_config_path(); 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /haiku_direct_window.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************/ 2 | /* haiku_direct_window.cpp */ 3 | /*************************************************************************/ 4 | /* This file is part of: */ 5 | /* GODOT ENGINE */ 6 | /* https://godotengine.org */ 7 | /*************************************************************************/ 8 | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 | /* */ 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ 12 | /* a copy of this software and associated documentation files (the */ 13 | /* "Software"), to deal in the Software without restriction, including */ 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 | /* permit persons to whom the Software is furnished to do so, subject to */ 17 | /* the following conditions: */ 18 | /* */ 19 | /* The above copyright notice and this permission notice shall be */ 20 | /* included in all copies or substantial portions of the Software. */ 21 | /* */ 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 | /*************************************************************************/ 30 | 31 | #include 32 | 33 | #include "core/os/keyboard.h" 34 | #include "haiku_direct_window.h" 35 | #include "key_mapping_haiku.h" 36 | #include "main/main.h" 37 | 38 | HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) : 39 | BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) { 40 | last_mouse_pos_valid = false; 41 | last_buttons_state = 0; 42 | last_button_mask = 0; 43 | last_key_modifier_state = 0; 44 | 45 | view = nullptr; 46 | update_runner = nullptr; 47 | input = nullptr; 48 | main_loop = nullptr; 49 | } 50 | 51 | HaikuDirectWindow::~HaikuDirectWindow() { 52 | } 53 | 54 | void HaikuDirectWindow::SetHaikuGLView(HaikuGLView *p_view) { 55 | view = p_view; 56 | } 57 | 58 | void HaikuDirectWindow::StartMessageRunner() { 59 | update_runner = new BMessageRunner(BMessenger(this), 60 | new BMessage(REDRAW_MSG), 1000000 / 60 /* 60 fps */); 61 | } 62 | 63 | void HaikuDirectWindow::StopMessageRunner() { 64 | delete update_runner; 65 | } 66 | 67 | void HaikuDirectWindow::SetInput(InputDefault *p_input) { 68 | input = p_input; 69 | } 70 | 71 | void HaikuDirectWindow::SetMainLoop(MainLoop *p_main_loop) { 72 | main_loop = p_main_loop; 73 | } 74 | 75 | bool HaikuDirectWindow::QuitRequested() { 76 | StopMessageRunner(); 77 | main_loop->notification(NOTIFICATION_WM_CLOSE_REQUEST); 78 | return false; 79 | } 80 | 81 | void HaikuDirectWindow::DirectConnected(direct_buffer_info *info) { 82 | view->DirectConnected(info); 83 | view->EnableDirectMode(true); 84 | } 85 | 86 | void HaikuDirectWindow::MessageReceived(BMessage *message) { 87 | switch (message->what) { 88 | case REDRAW_MSG: 89 | if (Main::iteration()) { 90 | view->EnableDirectMode(false); 91 | Quit(); 92 | } 93 | break; 94 | 95 | default: 96 | BDirectWindow::MessageReceived(message); 97 | } 98 | } 99 | 100 | void HaikuDirectWindow::DispatchMessage(BMessage *message, BHandler *handler) { 101 | switch (message->what) { 102 | case B_MOUSE_DOWN: 103 | case B_MOUSE_UP: 104 | HandleMouseButton(message); 105 | break; 106 | 107 | case B_MOUSE_MOVED: 108 | HandleMouseMoved(message); 109 | break; 110 | 111 | case B_MOUSE_WHEEL_CHANGED: 112 | HandleMouseWheelChanged(message); 113 | break; 114 | 115 | case B_KEY_DOWN: 116 | case B_KEY_UP: 117 | HandleKeyboardEvent(message); 118 | break; 119 | 120 | case B_MODIFIERS_CHANGED: 121 | HandleKeyboardModifierEvent(message); 122 | break; 123 | 124 | case B_WINDOW_RESIZED: 125 | HandleWindowResized(message); 126 | break; 127 | 128 | case LOCKGL_MSG: 129 | view->LockGL(); 130 | break; 131 | 132 | case UNLOCKGL_MSG: 133 | view->UnlockGL(); 134 | break; 135 | 136 | default: 137 | BDirectWindow::DispatchMessage(message, handler); 138 | } 139 | } 140 | 141 | void HaikuDirectWindow::HandleMouseButton(BMessage *message) { 142 | BPoint where; 143 | if (message->FindPoint("where", &where) != B_OK) { 144 | return; 145 | } 146 | 147 | uint32 modifiers = message->FindInt32("modifiers"); 148 | uint32 buttons = message->FindInt32("buttons"); 149 | uint32 button = buttons ^ last_buttons_state; 150 | last_buttons_state = buttons; 151 | 152 | // TODO: implement the mouse_mode checks 153 | /* 154 | if (mouse_mode == MOUSE_MODE_CAPTURED) { 155 | event.xbutton.x=last_mouse_pos.x; 156 | event.xbutton.y=last_mouse_pos.y; 157 | } 158 | */ 159 | 160 | Ref mouse_event; 161 | mouse_event.instance(); 162 | 163 | mouse_event->set_button_mask(GetMouseButtonState(buttons)); 164 | mouse_event->set_position({ where.x, where.y }); 165 | mouse_event->set_global_position({ where.x, where.y }); 166 | GetKeyModifierState(mouse_event, modifiers); 167 | 168 | switch (button) { 169 | default: 170 | case B_PRIMARY_MOUSE_BUTTON: 171 | mouse_event->set_button_index(1); 172 | break; 173 | 174 | case B_SECONDARY_MOUSE_BUTTON: 175 | mouse_event->set_button_index(2); 176 | break; 177 | 178 | case B_TERTIARY_MOUSE_BUTTON: 179 | mouse_event->set_button_index(3); 180 | break; 181 | } 182 | 183 | mouse_event->set_pressed(message->what == B_MOUSE_DOWN); 184 | 185 | if (message->what == B_MOUSE_DOWN && mouse_event->get_button_index() == 1) { 186 | int32 clicks = message->FindInt32("clicks"); 187 | 188 | if (clicks > 1) { 189 | mouse_event->set_doubleclick(true); 190 | } 191 | } 192 | 193 | input->parse_input_event(mouse_event); 194 | } 195 | 196 | void HaikuDirectWindow::HandleMouseMoved(BMessage *message) { 197 | BPoint where; 198 | if (message->FindPoint("where", &where) != B_OK) { 199 | return; 200 | } 201 | 202 | Point2i pos(where.x, where.y); 203 | uint32 modifiers = message->FindInt32("modifiers"); 204 | uint32 buttons = message->FindInt32("buttons"); 205 | 206 | if (!last_mouse_pos_valid) { 207 | last_mouse_position = pos; 208 | last_mouse_pos_valid = true; 209 | } 210 | 211 | Point2i rel = pos - last_mouse_position; 212 | 213 | Ref motion_event; 214 | motion_event.instance(); 215 | GetKeyModifierState(motion_event, modifiers); 216 | 217 | motion_event->set_button_mask(GetMouseButtonState(buttons)); 218 | motion_event->set_position({ pos.x, pos.y }); 219 | input->set_mouse_position(pos); 220 | motion_event->set_global_position({ pos.x, pos.y }); 221 | motion_event->set_speed({ input->get_last_mouse_speed().x, 222 | input->get_last_mouse_speed().y }); 223 | 224 | motion_event->set_relative({ rel.x, rel.y }); 225 | 226 | last_mouse_position = pos; 227 | 228 | input->parse_input_event(motion_event); 229 | } 230 | 231 | void HaikuDirectWindow::HandleMouseWheelChanged(BMessage *message) { 232 | float wheel_delta_y = 0; 233 | if (message->FindFloat("be:wheel_delta_y", &wheel_delta_y) != B_OK) { 234 | return; 235 | } 236 | 237 | Ref mouse_event; 238 | mouse_event.instance(); 239 | //GetKeyModifierState(mouse_event, modifiers); 240 | 241 | mouse_event->set_button_index(wheel_delta_y < 0 ? 4 : 5); 242 | mouse_event->set_button_mask(last_button_mask); 243 | mouse_event->set_position({ last_mouse_position.x, 244 | last_mouse_position.y }); 245 | mouse_event->set_global_position({ last_mouse_position.x, 246 | last_mouse_position.y }); 247 | 248 | mouse_event->set_pressed(true); 249 | input->parse_input_event(mouse_event); 250 | 251 | mouse_event->set_pressed(false); 252 | input->parse_input_event(mouse_event); 253 | } 254 | 255 | void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) { 256 | int32 raw_char = 0; 257 | int32 key = 0; 258 | int32 modifiers = 0; 259 | 260 | if (message->FindInt32("raw_char", &raw_char) != B_OK) { 261 | return; 262 | } 263 | 264 | if (message->FindInt32("key", &key) != B_OK) { 265 | return; 266 | } 267 | 268 | if (message->FindInt32("modifiers", &modifiers) != B_OK) { 269 | return; 270 | } 271 | 272 | Ref event; 273 | event.instance(); 274 | GetKeyModifierState(event, modifiers); 275 | event->set_pressed(message->what == B_KEY_DOWN); 276 | event->set_keycode(KeyMappingHaiku::get_keysym(raw_char, key)); 277 | event->set_physical_keycode(KeyMappingHaiku::get_keysym(raw_char, key)); 278 | event->set_echo(message->HasInt32("be:key_repeat")); 279 | event->set_unicode(0); 280 | 281 | const char *bytes = nullptr; 282 | if (message->FindString("bytes", &bytes) == B_OK) { 283 | event->set_unicode(BUnicodeChar::FromUTF8(&bytes)); 284 | } 285 | 286 | //make it consistent across platforms. 287 | if (event->get_keycode() == KEY_BACKTAB) { 288 | event->set_keycode(KEY_TAB); 289 | event->set_physical_keycode(KEY_TAB); 290 | event->set_shift(true); 291 | } 292 | 293 | input->parse_input_event(event); 294 | } 295 | 296 | void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage *message) { 297 | int32 old_modifiers = 0; 298 | int32 modifiers = 0; 299 | 300 | if (message->FindInt32("be:old_modifiers", &old_modifiers) != B_OK) { 301 | return; 302 | } 303 | 304 | if (message->FindInt32("modifiers", &modifiers) != B_OK) { 305 | return; 306 | } 307 | 308 | int32 key = old_modifiers ^ modifiers; 309 | 310 | Ref event; 311 | event.instance(); 312 | GetKeyModifierState(event, modifiers); 313 | 314 | event->set_shift(key & B_SHIFT_KEY); 315 | event->set_alt(key & B_OPTION_KEY); 316 | event->set_control(key & B_CONTROL_KEY); 317 | event->set_command(key & B_COMMAND_KEY); 318 | 319 | input->parse_input_event(event); 320 | } 321 | 322 | void HaikuDirectWindow::HandleWindowResized(BMessage *message) { 323 | int32 width = 0; 324 | int32 height = 0; 325 | 326 | if ((message->FindInt32("width", &width) != B_OK) || (message->FindInt32("height", &height) != B_OK)) { 327 | return; 328 | } 329 | 330 | current_video_mode->width = width; 331 | current_video_mode->height = height; 332 | } 333 | 334 | inline void HaikuDirectWindow::GetKeyModifierState(Ref event, uint32 p_state) { 335 | last_key_modifier_state = p_state; 336 | 337 | event->set_shift(p_state & B_SHIFT_KEY); 338 | event->set_control(p_state & B_CONTROL_KEY); 339 | event->set_alt(p_state & B_OPTION_KEY); 340 | event->set_metakey(p_state & B_COMMAND_KEY); 341 | 342 | return state; 343 | } 344 | 345 | inline int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { 346 | int state = 0; 347 | 348 | if (p_state & B_PRIMARY_MOUSE_BUTTON) { 349 | state |= 1 << 0; 350 | } 351 | 352 | if (p_state & B_SECONDARY_MOUSE_BUTTON) { 353 | state |= 1 << 1; 354 | } 355 | 356 | if (p_state & B_TERTIARY_MOUSE_BUTTON) { 357 | state |= 1 << 2; 358 | } 359 | 360 | last_button_mask = state; 361 | 362 | return state; 363 | } 364 | --------------------------------------------------------------------------------