diff options
Diffstat (limited to 'platform/x11')
| -rw-r--r-- | platform/x11/SCsub | 13 | ||||
| -rw-r--r-- | platform/x11/context_gl_x11.cpp | 197 | ||||
| -rw-r--r-- | platform/x11/context_gl_x11.h | 76 | ||||
| -rw-r--r-- | platform/x11/detect.py | 146 | ||||
| -rw-r--r-- | platform/x11/export/export.cpp | 24 | ||||
| -rw-r--r-- | platform/x11/export/export.h | 4 | ||||
| -rw-r--r-- | platform/x11/godot_x11.cpp | 45 | ||||
| -rw-r--r-- | platform/x11/key_mapping_x11.cpp | 1812 | ||||
| -rw-r--r-- | platform/x11/key_mapping_x11.h | 55 | ||||
| -rw-r--r-- | platform/x11/logo.png | bin | 0 -> 2055 bytes | |||
| -rw-r--r-- | platform/x11/os_x11.cpp | 1300 | ||||
| -rw-r--r-- | platform/x11/os_x11.h | 203 | ||||
| -rw-r--r-- | platform/x11/platform_config.h | 32 |
13 files changed, 3907 insertions, 0 deletions
diff --git a/platform/x11/SCsub b/platform/x11/SCsub new file mode 100644 index 000000000..0644ba52e --- /dev/null +++ b/platform/x11/SCsub @@ -0,0 +1,13 @@ +Import('env') + + +common_x11=[\ + "context_gl_x11.cpp",\ + "os_x11.cpp",\ + "key_mapping_x11.cpp",\ +] + +if env["target"]=="release": + env.Program('#bin/godot_rel',['godot_x11.cpp']+common_x11) +else: + env.Program('#bin/godot',['godot_x11.cpp']+common_x11) diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp new file mode 100644 index 000000000..12708f52e --- /dev/null +++ b/platform/x11/context_gl_x11.cpp @@ -0,0 +1,197 @@ +/*************************************************************************/ +/* context_gl_x11.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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 "context_gl_x11.h" + +#ifdef X11_ENABLED +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> + +#include <GL/glx.h> + +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 + +typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*); + +struct ContextGL_X11_Private { + + ::GLXContext glx_context; +}; + + +void ContextGL_X11::release_current() { + + glXMakeCurrent(x11_display, None, NULL); +} + +void ContextGL_X11::make_current() { + + glXMakeCurrent(x11_display, x11_window, p->glx_context); +} +void ContextGL_X11::swap_buffers() { + + glXSwapBuffers(x11_display,x11_window); +} +/* +static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) { + + //print_line(String()+"getting proc of: "+p_function); + GLWrapperFuncPtr func=(GLWrapperFuncPtr)glXGetProcAddress( (const GLubyte*) p_function); + if (!func) { + print_line("Couldn't find function: "+String(p_function)); + } + + return func; + +}*/ + +Error ContextGL_X11::initialize() { + + + GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = NULL; + +// const char *extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display)); + + glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); + + ERR_FAIL_COND_V( !glXCreateContextAttribsARB, ERR_UNCONFIGURED ); + + + static int visual_attribs[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_DOUBLEBUFFER, true, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DEPTH_SIZE,0, + None + }; + + int fbcount; + GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount); + ERR_FAIL_COND_V(!fbc,ERR_UNCONFIGURED); + + XVisualInfo *vi = glXGetVisualFromFBConfig(x11_display, fbc[0]); + + XSetWindowAttributes swa; + + swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone); + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + + /* + char* windowid = getenv("GODOT_WINDOWID"); + if (windowid) { + + //freopen("/home/punto/stdout", "w", stdout); + //reopen("/home/punto/stderr", "w", stderr); + x11_window = atol(windowid); + } else { + */ + x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa); + ERR_FAIL_COND_V(!x11_window,ERR_UNCONFIGURED); + XMapWindow(x11_display, x11_window); + while(true) { + // wait for mapnotify (window created) + XEvent e; + XNextEvent(x11_display, &e); + if (e.type == MapNotify) + break; + } + //}; + + if (!opengl_3_context) { + //oldstyle context: + p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE); + } else { + static int context_attribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + None + }; + + p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs); + ERR_FAIL_COND_V(!p->glx_context,ERR_UNCONFIGURED); + } + + glXMakeCurrent(x11_display, x11_window, p->glx_context); + + /* + glWrapperInit(wrapper_get_proc_address); + glFlush(); + + glXSwapBuffers(x11_display,x11_window); +*/ + //glXMakeCurrent(x11_display, None, NULL); + + return OK; +} + +int ContextGL_X11::get_window_width() { + + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + + return xwa.width; +} +int ContextGL_X11::get_window_height() { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + + return xwa.height; + +} + + +ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context) : x11_window(p_x11_window) { + + default_video_mode=p_default_video_mode; + x11_display=p_x11_display; + + opengl_3_context=p_opengl_3_context; + + double_buffer=false; + direct_render=false; + glx_minor=glx_major=0; + p = memnew( ContextGL_X11_Private ); + p->glx_context=0; +} + + +ContextGL_X11::~ContextGL_X11() { + + memdelete( p ); +} + + +#endif +#endif diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h new file mode 100644 index 000000000..20a858bcd --- /dev/null +++ b/platform/x11/context_gl_x11.h @@ -0,0 +1,76 @@ +/*************************************************************************/ +/* context_gl_x11.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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. */ +/*************************************************************************/ +#ifndef CONTEXT_GL_X11_H +#define CONTEXT_GL_X11_H + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +#ifdef X11_ENABLED + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + + + +#include "os/os.h" +#include "drivers/gl_context/context_gl.h" +#include <X11/Xlib.h> + +struct ContextGL_X11_Private; + +class ContextGL_X11 : public ContextGL { + + ContextGL_X11_Private *p; + OS::VideoMode default_video_mode; +// ::Colormap x11_colormap; + ::Display *x11_display; + ::Window& x11_window; + bool double_buffer; + bool direct_render; + int glx_minor,glx_major; + bool opengl_3_context; +public: + + virtual void release_current(); + virtual void make_current(); + virtual void swap_buffers(); + virtual int get_window_width(); + virtual int get_window_height(); + + virtual Error initialize(); + + ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context); + ~ContextGL_X11(); + +}; + +#endif + +#endif +#endif diff --git a/platform/x11/detect.py b/platform/x11/detect.py new file mode 100644 index 000000000..38f697ef1 --- /dev/null +++ b/platform/x11/detect.py @@ -0,0 +1,146 @@ + +import os +import sys + + +def is_active(): + return True + +def get_name(): + return "X11" + + +def can_build(): + + if (os.name!="posix"): + return False + + if sys.platform == "darwin": + return False # no x11 on mac for now + + errorval=os.system("pkg-config --version > /dev/null") + + if (errorval): + print("pkg-config not found.. x11 disabled.") + return False + + x11_error=os.system("pkg-config x11 --modversion > /dev/null ") + if (x11_error): + print("X11 not found.. x11 disabled.") + return False + + x11_error=os.system("pkg-config xcursor --modversion > /dev/null ") + if (x11_error): + print("xcursor not found.. x11 disabled.") + return False + + return True # X11 enabled + +def get_opts(): + + return [ + ('use_llvm','Use llvm compiler','no'), + ('use_sanitizer','Use llvm compiler sanitize address','no'), + ('force_32_bits','Force 32 bits binary','no') + ] + +def get_flags(): + + return [ + ('opengl', 'no'), + ('legacygl', 'yes'), + ('builtin_zlib', 'no'), + ] + + + +def configure(env): + + env.Append(CPPPATH=['#platform/x11']) + if (env["use_llvm"]=="yes"): + env["CC"]="clang" + env["CXX"]="clang++" + env["LD"]="clang++" + if (env["use_sanitizer"]=="yes"): + env.Append(CXXFLAGS=['-fsanitize=address','-fno-omit-frame-pointer']) + env.Append(LINKFLAGS=['-fsanitize=address']) + + + + if (env["tools"]=="no"): + #no tools suffix + env['OBJSUFFIX'] = ".nt"+env['OBJSUFFIX'] + env['LIBSUFFIX'] = ".nt"+env['LIBSUFFIX'] + + + if (env["target"]=="release"): + + env.Append(CCFLAGS=['-O2','-ffast-math','-fomit-frame-pointer']) + env['OBJSUFFIX'] = "_opt"+env['OBJSUFFIX'] + env['LIBSUFFIX'] = "_opt"+env['LIBSUFFIX'] + + elif (env["target"]=="release_debug"): + + env.Append(CCFLAGS=['-O2','-ffast-math','-DDEBUG_ENABLED']) + env['OBJSUFFIX'] = "_optd"+env['OBJSUFFIX'] + env['LIBSUFFIX'] = "_optd"+env['LIBSUFFIX'] + + +# env.Append(CCFLAGS=['-Os','-ffast-math','-fomit-frame-pointer']) +#does not seem to have much effect +# env.Append(CCFLAGS=['-fno-default-inline']) +#recommended by wxwidgets +# env.Append(CCFLAGS=['-ffunction-sections','-fdata-sections']) +# env.Append(LINKFLAGS=['-Wl','--gc-sections']) + + elif (env["target"]=="debug"): + + env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) +#does not seem to have much effect +# env.Append(CCFLAGS=['-fno-default-inline']) +#recommended by wxwidgets +# env.Append(CCFLAGS=['-ffunction-sections','-fdata-sections']) +# env.Append(LINKFLAGS=['-Wl','--gc-sections']) + + elif (env["target"]=="debug_light"): + + env.Append(CCFLAGS=['-g1', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + + + elif (env["target"]=="profile"): + + env.Append(CCFLAGS=['-g','-pg']) + env.Append(LINKFLAGS=['-pg']) + + env.ParseConfig('pkg-config x11 --cflags --libs') + env.ParseConfig('pkg-config xcursor --cflags --libs') + + + env.ParseConfig('pkg-config freetype2 --cflags --libs') + env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) + + + if env['opengl'] == 'yes': + env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED']) + #env.Append(CPPFLAGS=["-DRTAUDIO_ENABLED"]) + env.Append(CPPFLAGS=["-DALSA_ENABLED"]) + env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLES_OVER_GL']) +# env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES_OVER_GL']) + env.Append(LIBS=['GL', 'GLU', 'pthread','asound','z']) #TODO detect linux/BSD! + #env.Append(CPPFLAGS=['-DMPC_FIXED_POINT']) + if (env["force_32_bits"]=="yes"): + env.Append(CPPFLAGS=['-m32']) + env.Append(LINKFLAGS=['-m32','-L/usr/lib/i386-linux-gnu']) + + if (env["CXX"]=="clang++"): + env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND']) + env["CC"]="clang" + env["LD"]="clang++" + + import methods + + 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.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) + diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp new file mode 100644 index 000000000..b17b92bcc --- /dev/null +++ b/platform/x11/export/export.cpp @@ -0,0 +1,24 @@ +#include "export.h" +#include "platform/x11/logo.h" +#include "tools/editor/editor_import_export.h" +#include "scene/resources/texture.h" + +void register_x11_exporter() { + + Image img(_x11_logo); + Ref<ImageTexture> logo = memnew( ImageTexture ); + logo->create_from_image(img); + + { + Ref<EditorExportPlatformPC> exporter = Ref<EditorExportPlatformPC>( memnew(EditorExportPlatformPC) ); + exporter->set_binary_extension("bin"); + exporter->set_release_binary32("linux_x11_32_release"); + exporter->set_debug_binary32("linux_x11_32_debug"); + exporter->set_release_binary64("linux_x11_64_release"); + exporter->set_debug_binary64("linux_x11_64_debug"); + exporter->set_name("Linux X11"); + exporter->set_logo(logo); + EditorImportExport::get_singleton()->add_export_platform(exporter); + } + +} diff --git a/platform/x11/export/export.h b/platform/x11/export/export.h new file mode 100644 index 000000000..1077709ea --- /dev/null +++ b/platform/x11/export/export.h @@ -0,0 +1,4 @@ + + +void register_x11_exporter(); + diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp new file mode 100644 index 000000000..3b50e8e51 --- /dev/null +++ b/platform/x11/godot_x11.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* godot_x11.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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 "main/main.h" +#include "os_x11.h" + +int main(int argc, char* argv[]) { + + OS_X11 os; + + Error err = Main::setup(argv[0],argc-1,&argv[1]); + if (err!=OK) + return 255; + + if (Main::start()) + os.run(); // it is actually the OS that decides how to run + Main::cleanup(); + + return os.get_exit_code(); +} diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp new file mode 100644 index 000000000..2f109355b --- /dev/null +++ b/platform/x11/key_mapping_x11.cpp @@ -0,0 +1,1812 @@ +/*************************************************************************/ +/* key_mapping_x11.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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 "key_mapping_x11.h" + + +/***** SCAN CODE CONVERSION ******/ + +struct _XTranslatePair { + + KeySym keysym; + unsigned int keycode; +}; + +static _XTranslatePair _xkeysym_to_keycode[]={ + // misc keys + + { XK_Escape, KEY_ESCAPE }, + { XK_Tab, KEY_TAB }, + { XK_ISO_Left_Tab, KEY_BACKTAB }, + { XK_BackSpace, KEY_BACKSPACE }, + { XK_Return, KEY_RETURN }, + { XK_Insert, KEY_INSERT }, + { XK_Delete, KEY_DELETE }, + { XK_Clear, KEY_DELETE }, + { XK_Pause, KEY_PAUSE }, + { XK_Print, KEY_PRINT }, + { XK_Home, KEY_HOME }, + { XK_End, KEY_END }, + { XK_Left, KEY_LEFT }, + { XK_Up, KEY_UP }, + { XK_Right, KEY_RIGHT }, + { XK_Down, KEY_DOWN }, + { XK_Prior, KEY_PAGEUP }, + { XK_Next, KEY_PAGEDOWN }, + { XK_Shift_L, KEY_SHIFT }, + { XK_Shift_R, KEY_SHIFT }, + { XK_Shift_Lock, KEY_SHIFT }, + { XK_Control_L, KEY_CONTROL }, + { XK_Control_R, KEY_CONTROL }, + { XK_Meta_L, KEY_META }, + { XK_Meta_R, KEY_META }, + { XK_Alt_L, KEY_ALT }, + { XK_Alt_R, KEY_ALT }, + { XK_Caps_Lock, KEY_CAPSLOCK }, + { XK_Num_Lock, KEY_NUMLOCK }, + { XK_Scroll_Lock, KEY_SCROLLLOCK }, + { XK_Super_L, KEY_SUPER_L }, + { XK_Super_R, KEY_SUPER_R }, + { XK_Menu, KEY_MENU }, + { XK_Hyper_L, KEY_HYPER_L }, + { XK_Hyper_R, KEY_HYPER_R }, + { XK_Help, KEY_HELP }, + { XK_KP_Space, KEY_SPACE }, + { XK_KP_Tab, KEY_TAB }, + { XK_KP_Enter, KEY_ENTER }, + { XK_Home, KEY_HOME }, + { XK_Left, KEY_LEFT }, + { XK_Up, KEY_UP }, + { XK_Right, KEY_RIGHT }, + { XK_Down, KEY_DOWN }, + { XK_Prior, KEY_PAGEUP }, + { XK_Next, KEY_PAGEDOWN }, + { XK_End, KEY_END }, + { XK_Begin, KEY_CLEAR }, + { XK_Insert, KEY_INSERT }, + { XK_Delete, KEY_DELETE }, +// { XK_KP_Equal, KEY_EQUAL }, +// { XK_KP_Separator, KEY_COMMA }, + { XK_KP_Decimal, KEY_KP_PERIOD }, + { XK_KP_Delete, KEY_KP_PERIOD }, + { XK_KP_Enter, KEY_KP_ENTER }, + { XK_KP_Multiply, KEY_KP_MULTIPLY}, + { XK_KP_Divide, KEY_KP_DIVIDE}, + { XK_KP_Subtract, KEY_KP_SUBSTRACT}, + { XK_KP_Add, KEY_KP_ADD}, + { XK_KP_0, KEY_KP_0}, + { XK_KP_1, KEY_KP_1}, + { XK_KP_2, KEY_KP_2}, + { XK_KP_3, KEY_KP_3}, + { XK_KP_4, KEY_KP_4}, + { XK_KP_5, KEY_KP_5}, + { XK_KP_6, KEY_KP_6}, + { XK_KP_7, KEY_KP_7}, + { XK_KP_8, KEY_KP_8}, + { XK_KP_9, KEY_KP_9}, + // same but with numlock + { XK_KP_Insert, KEY_KP_0}, + { XK_KP_End, KEY_KP_1}, + { XK_KP_Down, KEY_KP_2}, + { XK_KP_Page_Down, KEY_KP_3}, + { XK_KP_Left, KEY_KP_4}, + { XK_KP_Begin, KEY_KP_5}, + { XK_KP_Right, KEY_KP_6}, + { XK_KP_Home, KEY_KP_7}, + { XK_KP_Up, KEY_KP_8}, + { XK_KP_Page_Up, KEY_KP_9}, + { XK_F1, KEY_F1}, + { XK_F2, KEY_F2}, + { XK_F3, KEY_F3}, + { XK_F4, KEY_F4}, + { XK_F5, KEY_F5}, + { XK_F6, KEY_F6}, + { XK_F7, KEY_F7}, + { XK_F8, KEY_F8}, + { XK_F9, KEY_F9}, + { XK_F10, KEY_F10}, + { XK_F11, KEY_F11}, + { XK_F12, KEY_F12}, + { XK_F13, KEY_F13}, + { XK_F14, KEY_F14}, + { XK_F15, KEY_F15}, + { XK_F16, KEY_F16}, + + // media keys + { XF86XK_Back, KEY_BACK }, + { XF86XK_Forward, KEY_FORWARD }, + { XF86XK_Stop, KEY_STOP }, + { XF86XK_Refresh, KEY_REFRESH }, + { XF86XK_Favorites, KEY_FAVORITES }, + { XF86XK_AudioMedia, KEY_LAUNCHMEDIA }, + { XF86XK_OpenURL, KEY_OPENURL }, + { XF86XK_HomePage, KEY_HOMEPAGE }, + { XF86XK_Search, KEY_SEARCH }, + { XF86XK_AudioLowerVolume, KEY_VOLUMEDOWN }, + { XF86XK_AudioMute, KEY_VOLUMEMUTE }, + { XF86XK_AudioRaiseVolume, KEY_VOLUMEUP }, + { XF86XK_AudioPlay, KEY_MEDIAPLAY }, + { XF86XK_AudioStop, KEY_MEDIASTOP }, + { XF86XK_AudioPrev, KEY_MEDIAPREVIOUS }, + { XF86XK_AudioNext, KEY_MEDIANEXT }, + { XF86XK_AudioRecord, KEY_MEDIARECORD }, + + // launch keys + { XF86XK_Mail, KEY_LAUNCHMAIL }, + { XF86XK_MyComputer, KEY_LAUNCH0 }, + { XF86XK_Calculator, KEY_LAUNCH1 }, + { XF86XK_Standby, KEY_STANDBY }, + + { XF86XK_Launch0, KEY_LAUNCH2 }, + { XF86XK_Launch1, KEY_LAUNCH3 }, + { XF86XK_Launch2, KEY_LAUNCH4 }, + { XF86XK_Launch3, KEY_LAUNCH5 }, + { XF86XK_Launch4, KEY_LAUNCH6 }, + { XF86XK_Launch5, KEY_LAUNCH7 }, + { XF86XK_Launch6, KEY_LAUNCH8 }, + { XF86XK_Launch7, KEY_LAUNCH9 }, + { XF86XK_Launch8, KEY_LAUNCHA }, + { XF86XK_Launch9, KEY_LAUNCHB }, + { XF86XK_LaunchA, KEY_LAUNCHC }, + { XF86XK_LaunchB, KEY_LAUNCHD }, + { XF86XK_LaunchC, KEY_LAUNCHE }, + { XF86XK_LaunchD, KEY_LAUNCHF }, + + {0, 0 } +}; + + +unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) { + + // kinda bruteforce.. could optimize. + + if (p_keysym<0x100) // Latin 1, maps 1-1 + return p_keysym; + + // look for special key + for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) { + + if (_xkeysym_to_keycode[idx].keysym==p_keysym) + return _xkeysym_to_keycode[idx].keycode; + } + + return 0; +} +KeySym KeyMappingX11::get_keysym(unsigned int p_code) { + + // kinda bruteforce.. could optimize. + + if (p_code<0x100) // Latin 1, maps 1-1 + return p_code; + + // look for special key + for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) { + + if (_xkeysym_to_keycode[idx].keycode==p_code) + return _xkeysym_to_keycode[idx].keysym; + } + + return 0; +} + + +/***** UNICODE CONVERSION ******/ + +// Tables taken from FOX toolkit + +struct _XTranslateUnicodePair { + + KeySym keysym; + unsigned int unicode; +}; + +enum { + + _KEYSYM_MAX=759 +}; + +static _XTranslateUnicodePair _xkeysym_to_unicode[_KEYSYM_MAX] = { + { 0x01A1, 0x0104 }, + { 0x01A2, 0x02D8 }, + { 0x01A3, 0x0141 }, + { 0x01A5, 0x013D }, + { 0x01A6, 0x015A }, + { 0x01A9, 0x0160 }, + { 0x01AA, 0x015E }, + { 0x01AB, 0x0164 }, + { 0x01AC, 0x0179 }, + { 0x01AE, 0x017D }, + { 0x01AF, 0x017B }, + { 0x01B1, 0x0105 }, + { 0x01B2, 0x02DB }, + { 0x01B3, 0x0142 }, + { 0x01B5, 0x013E }, + { 0x01B6, 0x015B }, + { 0x01B7, 0x02C7 }, + { 0x01B9, 0x0161 }, + { 0x01BA, 0x015F }, + { 0x01BB, 0x0165 }, + { 0x01BC, 0x017A }, + { 0x01BD, 0x02DD }, + { 0x01BE, 0x017E }, + { 0x01BF, 0x017C }, + { 0x01C0, 0x0154 }, + { 0x01C3, 0x0102 }, + { 0x01C5, 0x0139 }, + { 0x01C6, 0x0106 }, + { 0x01C8, 0x010C }, + { 0x01CA, 0x0118 }, + { 0x01CC, 0x011A }, + { 0x01CF, 0x010E }, + { 0x01D0, 0x0110 }, + { 0x01D1, 0x0143 }, + { 0x01D2, 0x0147 }, + { 0x01D5, 0x0150 }, + { 0x01D8, 0x0158 }, + { 0x01D9, 0x016E }, + { 0x01DB, 0x0170 }, + { 0x01DE, 0x0162 }, + { 0x01E0, 0x0155 }, + { 0x01E3, 0x0103 }, + { 0x01E5, 0x013A }, + { 0x01E6, 0x0107 }, + { 0x01E8, 0x010D }, + { 0x01EA, 0x0119 }, + { 0x01EC, 0x011B }, + { 0x01EF, 0x010F }, + { 0x01F0, 0x0111 }, + { 0x01F1, 0x0144 }, + { 0x01F2, 0x0148 }, + { 0x01F5, 0x0151 }, + { 0x01F8, 0x0159 }, + { 0x01F9, 0x016F }, + { 0x01FB, 0x0171 }, + { 0x01FE, 0x0163 }, + { 0x01FF, 0x02D9 }, + { 0x02A1, 0x0126 }, + { 0x02A6, 0x0124 }, + { 0x02A9, 0x0130 }, + { 0x02AB, 0x011E }, + { 0x02AC, 0x0134 }, + { 0x02B1, 0x0127 }, + { 0x02B6, 0x0125 }, + { 0x02B9, 0x0131 }, + { 0x02BB, 0x011F }, + { 0x02BC, 0x0135 }, + { 0x02C5, 0x010A }, + { 0x02C6, 0x0108 }, + { 0x02D5, 0x0120 }, + { 0x02D8, 0x011C }, + { 0x02DD, 0x016C }, + { 0x02DE, 0x015C }, + { 0x02E5, 0x010B }, + { 0x02E6, 0x0109 }, + { 0x02F5, 0x0121 }, + { 0x02F8, 0x011D }, + { 0x02FD, 0x016D }, + { 0x02FE, 0x015D }, + { 0x03A2, 0x0138 }, + { 0x03A3, 0x0156 }, + { 0x03A5, 0x0128 }, + { 0x03A6, 0x013B }, + { 0x03AA, 0x0112 }, + { 0x03AB, 0x0122 }, + { 0x03AC, 0x0166 }, + { 0x03B3, 0x0157 }, + { 0x03B5, 0x0129 }, + { 0x03B6, 0x013C }, + { 0x03BA, 0x0113 }, + { 0x03BB, 0x0123 }, + { 0x03BC, 0x0167 }, + { 0x03BD, 0x014A }, + { 0x03BF, 0x014B }, + { 0x03C0, 0x0100 }, + { 0x03C7, 0x012E }, + { 0x03CC, 0x0116 }, + { 0x03CF, 0x012A }, + { 0x03D1, 0x0145 }, + { 0x03D2, 0x014C }, + { 0x03D3, 0x0136 }, + { 0x03D9, 0x0172 }, + { 0x03DD, 0x0168 }, + { 0x03DE, 0x016A }, + { 0x03E0, 0x0101 }, + { 0x03E7, 0x012F }, + { 0x03EC, 0x0117 }, + { 0x03EF, 0x012B }, + { 0x03F1, 0x0146 }, + { 0x03F2, 0x014D }, + { 0x03F3, 0x0137 }, + { 0x03F9, 0x0173 }, + { 0x03FD, 0x0169 }, + { 0x03FE, 0x016B }, + { 0x047E, 0x203E }, + { 0x04A1, 0x3002 }, + { 0x04A2, 0x300C }, + { 0x04A3, 0x300D }, + { 0x04A4, 0x3001 }, + { 0x04A5, 0x30FB }, + { 0x04A6, 0x30F2 }, + { 0x04A7, 0x30A1 }, + { 0x04A8, 0x30A3 }, + { 0x04A9, 0x30A5 }, + { 0x04AA, 0x30A7 }, + { 0x04AB, 0x30A9 }, + { 0x04AC, 0x30E3 }, + { 0x04AD, 0x30E5 }, + { 0x04AE, 0x30E7 }, + { 0x04AF, 0x30C3 }, + { 0x04B0, 0x30FC }, + { 0x04B1, 0x30A2 }, + { 0x04B2, 0x30A4 }, + { 0x04B3, 0x30A6 }, + { 0x04B4, 0x30A8 }, + { 0x04B5, 0x30AA }, + { 0x04B6, 0x30AB }, + { 0x04B7, 0x30AD }, + { 0x04B8, 0x30AF }, + { 0x04B9, 0x30B1 }, + { 0x04BA, 0x30B3 }, + { 0x04BB, 0x30B5 }, + { 0x04BC, 0x30B7 }, + { 0x04BD, 0x30B9 }, + { 0x04BE, 0x30BB }, + { 0x04BF, 0x30BD }, + { 0x04C0, 0x30BF }, + { 0x04C1, 0x30C1 }, + { 0x04C2, 0x30C4 }, + { 0x04C3, 0x30C6 }, + { 0x04C4, 0x30C8 }, + { 0x04C5, 0x30CA }, + { 0x04C6, 0x30CB }, + { 0x04C7, 0x30CC }, + { 0x04C8, 0x30CD }, + { 0x04C9, 0x30CE }, + { 0x04CA, 0x30CF }, + { 0x04CB, 0x30D2 }, + { 0x04CC, 0x30D5 }, + { 0x04CD, 0x30D8 }, + { 0x04CE, 0x30DB }, + { 0x04CF, 0x30DE }, + { 0x04D0, 0x30DF }, + { 0x04D1, 0x30E0 }, + { 0x04D2, 0x30E1 }, + { 0x04D3, 0x30E2 }, + { 0x04D4, 0x30E4 }, + { 0x04D5, 0x30E6 }, + { 0x04D6, 0x30E8 }, + { 0x04D7, 0x30E9 }, + { 0x04D8, 0x30EA }, + { 0x04D9, 0x30EB }, + { 0x04DA, 0x30EC }, + { 0x04DB, 0x30ED }, + { 0x04DC, 0x30EF }, + { 0x04DD, 0x30F3 }, + { 0x04DE, 0x309B }, + { 0x04DF, 0x309C }, + { 0x05AC, 0x060C }, + { 0x05BB, 0x061B }, + { 0x05BF, 0x061F }, + { 0x05C1, 0x0621 }, + { 0x05C2, 0x0622 }, + { 0x05C3, 0x0623 }, + { 0x05C4, 0x0624 }, + { 0x05C5, 0x0625 }, + { 0x05C6, 0x0626 }, + { 0x05C7, 0x0627 }, + { 0x05C8, 0x0628 }, + { 0x05C9, 0x0629 }, + { 0x05CA, 0x062A }, + { 0x05CB, 0x062B }, + { 0x05CC, 0x062C }, + { 0x05CD, 0x062D }, + { 0x05CE, 0x062E }, + { 0x05CF, 0x062F }, + { 0x05D0, 0x0630 }, + { 0x05D1, 0x0631 }, + { 0x05D2, 0x0632 }, + { 0x05D3, 0x0633 }, + { 0x05D4, 0x0634 }, + { 0x05D5, 0x0635 }, + { 0x05D6, 0x0636 }, + { 0x05D7, 0x0637 }, + { 0x05D8, 0x0638 }, + { 0x05D9, 0x0639 }, + { 0x05DA, 0x063A }, + { 0x05E0, 0x0640 }, + { 0x05E1, 0x0641 }, + { 0x05E2, 0x0642 }, + { 0x05E3, 0x0643 }, + { 0x05E4, 0x0644 }, + { 0x05E5, 0x0645 }, + { 0x05E6, 0x0646 }, + { 0x05E7, 0x0647 }, + { 0x05E8, 0x0648 }, + { 0x05E9, 0x0649 }, + { 0x05EA, 0x064A }, + { 0x05EB, 0x064B }, + { 0x05EC, 0x064C }, + { 0x05ED, 0x064D }, + { 0x05EE, 0x064E }, + { 0x05EF, 0x064F }, + { 0x05F0, 0x0650 }, + { 0x05F1, 0x0651 }, + { 0x05F2, 0x0652 }, + { 0x06A1, 0x0452 }, + { 0x06A2, 0x0453 }, + { 0x06A3, 0x0451 }, + { 0x06A4, 0x0454 }, + { 0x06A5, 0x0455 }, + { 0x06A6, 0x0456 }, + { 0x06A7, 0x0457 }, + { 0x06A8, 0x0458 }, + { 0x06A9, 0x0459 }, + { 0x06AA, 0x045A }, + { 0x06AB, 0x045B }, + { 0x06AC, 0x045C }, + { 0x06AE, 0x045E }, + { 0x06AF, 0x045F }, + { 0x06B0, 0x2116 }, + { 0x06B1, 0x0402 }, + { 0x06B2, 0x0403 }, + { 0x06B3, 0x0401 }, + { 0x06B4, 0x0404 }, + { 0x06B5, 0x0405 }, + { 0x06B6, 0x0406 }, + { 0x06B7, 0x0407 }, + { 0x06B8, 0x0408 }, + { 0x06B9, 0x0409 }, + { 0x06BA, 0x040A }, + { 0x06BB, 0x040B }, + { 0x06BC, 0x040C }, + { 0x06BE, 0x040E }, + { 0x06BF, 0x040F }, + { 0x06C0, 0x044E }, + { 0x06C1, 0x0430 }, + { 0x06C2, 0x0431 }, + { 0x06C3, 0x0446 }, + { 0x06C4, 0x0434 }, + { 0x06C5, 0x0435 }, + { 0x06C6, 0x0444 }, + { 0x06C7, 0x0433 }, + { 0x06C8, 0x0445 }, + { 0x06C9, 0x0438 }, + { 0x06CA, 0x0439 }, + { 0x06CB, 0x043A }, + { 0x06CC, 0x043B }, + { 0x06CD, 0x043C }, + { 0x06CE, 0x043D }, + { 0x06CF, 0x043E }, + { 0x06D0, 0x043F }, + { 0x06D1, 0x044F }, + { 0x06D2, 0x0440 }, + { 0x06D3, 0x0441 }, + { 0x06D4, 0x0442 }, + { 0x06D5, 0x0443 }, + { 0x06D6, 0x0436 }, + { 0x06D7, 0x0432 }, + { 0x06D8, 0x044C }, + { 0x06D9, 0x044B }, + { 0x06DA, 0x0437 }, + { 0x06DB, 0x0448 }, + { 0x06DC, 0x044D }, + { 0x06DD, 0x0449 }, + { 0x06DE, 0x0447 }, + { 0x06DF, 0x044A }, + { 0x06E0, 0x042E }, + { 0x06E1, 0x0410 }, + { 0x06E2, 0x0411 }, + { 0x06E3, 0x0426 }, + { 0x06E4, 0x0414 }, + { 0x06E5, 0x0415 }, + { 0x06E6, 0x0424 }, + { 0x06E7, 0x0413 }, + { 0x06E8, 0x0425 }, + { 0x06E9, 0x0418 }, + { 0x06EA, 0x0419 }, + { 0x06EB, 0x041A }, + { 0x06EC, 0x041B }, + { 0x06ED, 0x041C }, + { 0x06EE, 0x041D }, + { 0x06EF, 0x041E }, + { 0x06F0, 0x041F }, + { 0x06F1, 0x042F }, + { 0x06F2, 0x0420 }, + { 0x06F3, 0x0421 }, + { 0x06F4, 0x0422 }, + { 0x06F5, 0x0423 }, + { 0x06F6, 0x0416 }, + { 0x06F7, 0x0412 }, + { 0x06F8, 0x042C }, + { 0x06F9, 0x042B }, + { 0x06FA, 0x0417 }, + { 0x06FB, 0x0428 }, + { 0x06FC, 0x042D }, + { 0x06FD, 0x0429 }, + { 0x06FE, 0x0427 }, + { 0x06FF, 0x042A }, + { 0x07A1, 0x0386 }, + { 0x07A2, 0x0388 }, + { 0x07A3, 0x0389 }, + { 0x07A4, 0x038A }, + { 0x07A5, 0x03AA }, + { 0x07A7, 0x038C }, + { 0x07A8, 0x038E }, + { 0x07A9, 0x03AB }, + { 0x07AB, 0x038F }, + { 0x07AE, 0x0385 }, + { 0x07AF, 0x2015 }, + { 0x07B1, 0x03AC }, + { 0x07B2, 0x03AD }, + { 0x07B3, 0x03AE }, + { 0x07B4, 0x03AF }, + { 0x07B5, 0x03CA }, + { 0x07B6, 0x0390 }, + { 0x07B7, 0x03CC }, + { 0x07B8, 0x03CD }, + { 0x07B9, 0x03CB }, + { 0x07BA, 0x03B0 }, + { 0x07BB, 0x03CE }, + { 0x07C1, 0x0391 }, + { 0x07C2, 0x0392 }, + { 0x07C3, 0x0393 }, + { 0x07C4, 0x0394 }, + { 0x07C5, 0x0395 }, + { 0x07C6, 0x0396 }, + { 0x07C7, 0x0397 }, + { 0x07C8, 0x0398 }, + { 0x07C9, 0x0399 }, + { 0x07CA, 0x039A }, + { 0x07CB, 0x039B }, + { 0x07CC, 0x039C }, + { 0x07CD, 0x039D }, + { 0x07CE, 0x039E }, + { 0x07CF, 0x039F }, + { 0x07D0, 0x03A0 }, + { 0x07D1, 0x03A1 }, + { 0x07D2, 0x03A3 }, + { 0x07D4, 0x03A4 }, + { 0x07D5, 0x03A5 }, + { 0x07D6, 0x03A6 }, + { 0x07D7, 0x03A7 }, + { 0x07D8, 0x03A8 }, + { 0x07D9, 0x03A9 }, + { 0x07E1, 0x03B1 }, + { 0x07E2, 0x03B2 }, + { 0x07E3, 0x03B3 }, + { 0x07E4, 0x03B4 }, + { 0x07E5, 0x03B5 }, + { 0x07E6, 0x03B6 }, + { 0x07E7, 0x03B7 }, + { 0x07E8, 0x03B8 }, + { 0x07E9, 0x03B9 }, + { 0x07EA, 0x03BA }, + { 0x07EB, 0x03BB }, + { 0x07EC, 0x03BC }, + { 0x07ED, 0x03BD }, + { 0x07EE, 0x03BE }, + { 0x07EF, 0x03BF }, + { 0x07F0, 0x03C0 }, + { 0x07F1, 0x03C1 }, + { 0x07F2, 0x03C3 }, + { 0x07F3, 0x03C2 }, + { 0x07F4, 0x03C4 }, + { 0x07F5, 0x03C5 }, + { 0x07F6, 0x03C6 }, + { 0x07F7, 0x03C7 }, + { 0x07F8, 0x03C8 }, + { 0x07F9, 0x03C9 }, + { 0x08A1, 0x23B7 }, + { 0x08A2, 0x250C }, + { 0x08A3, 0x2500 }, + { 0x08A4, 0x2320 }, + { 0x08A5, 0x2321 }, + { 0x08A6, 0x2502 }, + { 0x08A7, 0x23A1 }, + { 0x08A8, 0x23A3 }, + { 0x08A9, 0x23A4 }, + { 0x08AA, 0x23A6 }, + { 0x08AB, 0x239B }, + { 0x08AC, 0x239D }, + { 0x08AD, 0x239E }, + { 0x08AE, 0x23A0 }, + { 0x08AF, 0x23A8 }, + { 0x08B0, 0x23AC }, + { 0x08BC, 0x2264 }, + { 0x08BD, 0x2260 }, + { 0x08BE, 0x2265 }, + { 0x08BF, 0x222B }, + { 0x08C0, 0x2234 }, + { 0x08C1, 0x221D }, + { 0x08C2, 0x221E }, + { 0x08C5, 0x2207 }, + { 0x08C8, 0x223C }, + { 0x08C9, 0x2243 }, + { 0x08CD, 0x21D4 }, + { 0x08CE, 0x21D2 }, + { 0x08CF, 0x2261 }, + { 0x08D6, 0x221A }, + { 0x08DA, 0x2282 }, + { 0x08DB, 0x2283 }, + { 0x08DC, 0x2229 }, + { 0x08DD, 0x222A }, + { 0x08DE, 0x2227 }, + { 0x08DF, 0x2228 }, + { 0x08EF, 0x2202 }, + { 0x08F6, 0x0192 }, + { 0x08FB, 0x2190 }, + { 0x08FC, 0x2191 }, + { 0x08FD, 0x2192 }, + { 0x08FE, 0x2193 }, + { 0x09E0, 0x25C6 }, + { 0x09E1, 0x2592 }, + { 0x09E2, 0x2409 }, + { 0x09E3, 0x240C }, + { 0x09E4, 0x240D }, + { 0x09E5, 0x240A }, + { 0x09E8, 0x2424 }, + { 0x09E9, 0x240B }, + { 0x09EA, 0x2518 }, + { 0x09EB, 0x2510 }, + { 0x09EC, 0x250C }, + { 0x09ED, 0x2514 }, + { 0x09EE, 0x253C }, + { 0x09EF, 0x23BA }, + { 0x09F0, 0x23BB }, + { 0x09F1, 0x2500 }, + { 0x09F2, 0x23BC }, + { 0x09F3, 0x23BD }, + { 0x09F4, 0x251C }, + { 0x09F5, 0x2524 }, + { 0x09F6, 0x2534 }, + { 0x09F7, 0x252C }, + { 0x09F8, 0x2502 }, + { 0x0AA1, 0x2003 }, + { 0x0AA2, 0x2002 }, + { 0x0AA3, 0x2004 }, + { 0x0AA4, 0x2005 }, + { 0x0AA5, 0x2007 }, + { 0x0AA6, 0x2008 }, + { 0x0AA7, 0x2009 }, + { 0x0AA8, 0x200A }, + { 0x0AA9, 0x2014 }, + { 0x0AAA, 0x2013 }, + { 0x0AAE, 0x2026 }, + { 0x0AAF, 0x2025 }, + { 0x0AB0, 0x2153 }, + { 0x0AB1, 0x2154 }, + { 0x0AB2, 0x2155 }, + { 0x0AB3, 0x2156 }, + { 0x0AB4, 0x2157 }, + { 0x0AB5, 0x2158 }, + { 0x0AB6, 0x2159 }, + { 0x0AB7, 0x215A }, + { 0x0AB8, 0x2105 }, + { 0x0ABB, 0x2012 }, + { 0x0ABC, 0x2329 }, + { 0x0ABE, 0x232A }, + { 0x0AC3, 0x215B }, + { 0x0AC4, 0x215C }, + { 0x0AC5, 0x215D }, + { 0x0AC6, 0x215E }, + { 0x0AC9, 0x2122 }, + { 0x0ACA, 0x2613 }, + { 0x0ACC, 0x25C1 }, + { 0x0ACD, 0x25B7 }, + { 0x0ACE, 0x25CB }, + { 0x0ACF, 0x25AF }, + { 0x0AD0, 0x2018 }, + { 0x0AD1, 0x2019 }, + { 0x0AD2, 0x201C }, + { 0x0AD3, 0x201D }, + { 0x0AD4, 0x211E }, + { 0x0AD6, 0x2032 }, + { 0x0AD7, 0x2033 }, + { 0x0AD9, 0x271D }, + { 0x0ADB, 0x25AC }, + { 0x0ADC, 0x25C0 }, + { 0x0ADD, 0x25B6 }, + { 0x0ADE, 0x25CF }, + { 0x0ADF, 0x25AE }, + { 0x0AE0, 0x25E6 }, + { 0x0AE1, 0x25AB }, + { 0x0AE2, 0x25AD }, + { 0x0AE3, 0x25B3 }, + { 0x0AE4, 0x25BD }, + { 0x0AE5, 0x2606 }, + { 0x0AE6, 0x2022 }, + { 0x0AE7, 0x25AA }, + { 0x0AE8, 0x25B2 }, + { 0x0AE9, 0x25BC }, + { 0x0AEA, 0x261C }, + { 0x0AEB, 0x261E }, + { 0x0AEC, 0x2663 }, + { 0x0AED, 0x2666 }, + { 0x0AEE, 0x2665 }, + { 0x0AF0, 0x2720 }, + { 0x0AF1, 0x2020 }, + { 0x0AF2, 0x2021 }, + { 0x0AF3, 0x2713 }, + { 0x0AF4, 0x2717 }, + { 0x0AF5, 0x266F }, + { 0x0AF6, 0x266D }, + { 0x0AF7, 0x2642 }, + { 0x0AF8, 0x2640 }, + { 0x0AF9, 0x260E }, + { 0x0AFA, 0x2315 }, + { 0x0AFB, 0x2117 }, + { 0x0AFC, 0x2038 }, + { 0x0AFD, 0x201A }, + { 0x0AFE, 0x201E }, + { 0x0BA3, 0x003C }, + { 0x0BA6, 0x003E }, + { 0x0BA8, 0x2228 }, + { 0x0BA9, 0x2227 }, + { 0x0BC0, 0x00AF }, + { 0x0BC2, 0x22A5 }, + { 0x0BC3, 0x2229 }, + { 0x0BC4, 0x230A }, + { 0x0BC6, 0x005F }, + { 0x0BCA, 0x2218 }, + { 0x0BCC, 0x2395 }, + { 0x0BCE, 0x22A4 }, + { 0x0BCF, 0x25CB }, + { 0x0BD3, 0x2308 }, + { 0x0BD6, 0x222A }, + { 0x0BD8, 0x2283 }, + { 0x0BDA, 0x2282 }, + { 0x0BDC, 0x22A2 }, + { 0x0BFC, 0x22A3 }, + { 0x0CDF, 0x2017 }, + { 0x0CE0, 0x05D0 }, + { 0x0CE1, 0x05D1 }, + { 0x0CE2, 0x05D2 }, + { 0x0CE3, 0x05D3 }, + { 0x0CE4, 0x05D4 }, + { 0x0CE5, 0x05D5 }, + { 0x0CE6, 0x05D6 }, + { 0x0CE7, 0x05D7 }, + { 0x0CE8, 0x05D8 }, + { 0x0CE9, 0x05D9 }, + { 0x0CEA, 0x05DA }, + { 0x0CEB, 0x05DB }, + { 0x0CEC, 0x05DC }, + { 0x0CED, 0x05DD }, + { 0x0CEE, 0x05DE }, + { 0x0CEF, 0x05DF }, + { 0x0CF0, 0x05E0 }, + { 0x0CF1, 0x05E1 }, + { 0x0CF2, 0x05E2 }, + { 0x0CF3, 0x05E3 }, + { 0x0CF4, 0x05E4 }, + { 0x0CF5, 0x05E5 }, + { 0x0CF6, 0x05E6 }, + { 0x0CF7, 0x05E7 }, + { 0x0CF8, 0x05E8 }, + { 0x0CF9, 0x05E9 }, + { 0x0CFA, 0x05EA }, + { 0x0DA1, 0x0E01 }, + { 0x0DA2, 0x0E02 }, + { 0x0DA3, 0x0E03 }, + { 0x0DA4, 0x0E04 }, + { 0x0DA5, 0x0E05 }, + { 0x0DA6, 0x0E06 }, + { 0x0DA7, 0x0E07 }, + { 0x0DA8, 0x0E08 }, + { 0x0DA9, 0x0E09 }, + { 0x0DAA, 0x0E0A }, + { 0x0DAB, 0x0E0B }, + { 0x0DAC, 0x0E0C }, + { 0x0DAD, 0x0E0D }, + { 0x0DAE, 0x0E0E }, + { 0x0DAF, 0x0E0F }, + { 0x0DB0, 0x0E10 }, + { 0x0DB1, 0x0E11 }, + { 0x0DB2, 0x0E12 }, + { 0x0DB3, 0x0E13 }, + { 0x0DB4, 0x0E14 }, + { 0x0DB5, 0x0E15 }, + { 0x0DB6, 0x0E16 }, + { 0x0DB7, 0x0E17 }, + { 0x0DB8, 0x0E18 }, + { 0x0DB9, 0x0E19 }, + { 0x0DBA, 0x0E1A }, + { 0x0DBB, 0x0E1B }, + { 0x0DBC, 0x0E1C }, + { 0x0DBD, 0x0E1D }, + { 0x0DBE, 0x0E1E }, + { 0x0DBF, 0x0E1F }, + { 0x0DC0, 0x0E20 }, + { 0x0DC1, 0x0E21 }, + { 0x0DC2, 0x0E22 }, + { 0x0DC3, 0x0E23 }, + { 0x0DC4, 0x0E24 }, + { 0x0DC5, 0x0E25 }, + { 0x0DC6, 0x0E26 }, + { 0x0DC7, 0x0E27 }, + { 0x0DC8, 0x0E28 }, + { 0x0DC9, 0x0E29 }, + { 0x0DCA, 0x0E2A }, + { 0x0DCB, 0x0E2B }, + { 0x0DCC, 0x0E2C }, + { 0x0DCD, 0x0E2D }, + { 0x0DCE, 0x0E2E }, + { 0x0DCF, 0x0E2F }, + { 0x0DD0, 0x0E30 }, + { 0x0DD1, 0x0E31 }, + { 0x0DD2, 0x0E32 }, + { 0x0DD3, 0x0E33 }, + { 0x0DD4, 0x0E34 }, + { 0x0DD5, 0x0E35 }, + { 0x0DD6, 0x0E36 }, + { 0x0DD7, 0x0E37 }, + { 0x0DD8, 0x0E38 }, + { 0x0DD9, 0x0E39 }, + { 0x0DDA, 0x0E3A }, + { 0x0DDF, 0x0E3F }, + { 0x0DE0, 0x0E40 }, + { 0x0DE1, 0x0E41 }, + { 0x0DE2, 0x0E42 }, + { 0x0DE3, 0x0E43 }, + { 0x0DE4, 0x0E44 }, + { 0x0DE5, 0x0E45 }, + { 0x0DE6, 0x0E46 }, + { 0x0DE7, 0x0E47 }, + { 0x0DE8, 0x0E48 }, + { 0x0DE9, 0x0E49 }, + { 0x0DEA, 0x0E4A }, + { 0x0DEB, 0x0E4B }, + { 0x0DEC, 0x0E4C }, + { 0x0DED, 0x0E4D }, + { 0x0DF0, 0x0E50 }, + { 0x0DF1, 0x0E51 }, + { 0x0DF2, 0x0E52 }, + { 0x0DF3, 0x0E53 }, + { 0x0DF4, 0x0E54 }, + { 0x0DF5, 0x0E55 }, + { 0x0DF6, 0x0E56 }, + { 0x0DF7, 0x0E57 }, + { 0x0DF8, 0x0E58 }, + { 0x0DF9, 0x0E59 }, + { 0x0EA1, 0x3131 }, + { 0x0EA2, 0x3132 }, + { 0x0EA3, 0x3133 }, + { 0x0EA4, 0x3134 }, + { 0x0EA5, 0x3135 }, + { 0x0EA6, 0x3136 }, + { 0x0EA7, 0x3137 }, + { 0x0EA8, 0x3138 }, + { 0x0EA9, 0x3139 }, + { 0x0EAA, 0x313A }, + { 0x0EAB, 0x313B }, + { 0x0EAC, 0x313C }, + { 0x0EAD, 0x313D }, + { 0x0EAE, 0x313E }, + { 0x0EAF, 0x313F }, + { 0x0EB0, 0x3140 }, + { 0x0EB1, 0x3141 }, + { 0x0EB2, 0x3142 }, + { 0x0EB3, 0x3143 }, + { 0x0EB4, 0x3144 }, + { 0x0EB5, 0x3145 }, + { 0x0EB6, 0x3146 }, + { 0x0EB7, 0x3147 }, + { 0x0EB8, 0x3148 }, + { 0x0EB9, 0x3149 }, + { 0x0EBA, 0x314A }, + { 0x0EBB, 0x314B }, + { 0x0EBC, 0x314C }, + { 0x0EBD, 0x314D }, + { 0x0EBE, 0x314E }, + { 0x0EBF, 0x314F }, + { 0x0EC0, 0x3150 }, + { 0x0EC1, 0x3151 }, + { 0x0EC2, 0x3152 }, + { 0x0EC3, 0x3153 }, + { 0x0EC4, 0x3154 }, + { 0x0EC5, 0x3155 }, + { 0x0EC6, 0x3156 }, + { 0x0EC7, 0x3157 }, + { 0x0EC8, 0x3158 }, + { 0x0EC9, 0x3159 }, + { 0x0ECA, 0x315A }, + { 0x0ECB, 0x315B }, + { 0x0ECC, 0x315C }, + { 0x0ECD, 0x315D }, + { 0x0ECE, 0x315E }, + { 0x0ECF, 0x315F }, + { 0x0ED0, 0x3160 }, + { 0x0ED1, 0x3161 }, + { 0x0ED2, 0x3162 }, + { 0x0ED3, 0x3163 }, + { 0x0ED4, 0x11A8 }, + { 0x0ED5, 0x11A9 }, + { 0x0ED6, 0x11AA }, + { 0x0ED7, 0x11AB }, + { 0x0ED8, 0x11AC }, + { 0x0ED9, 0x11AD }, + { 0x0EDA, 0x11AE }, + { 0x0EDB, 0x11AF }, + { 0x0EDC, 0x11B0 }, + { 0x0EDD, 0x11B1 }, + { 0x0EDE, 0x11B2 }, + { 0x0EDF, 0x11B3 }, + { 0x0EE0, 0x11B4 }, + { 0x0EE1, 0x11B5 }, + { 0x0EE2, 0x11B6 }, + { 0x0EE3, 0x11B7 }, + { 0x0EE4, 0x11B8 }, + { 0x0EE5, 0x11B9 }, + { 0x0EE6, 0x11BA }, + { 0x0EE7, 0x11BB }, + { 0x0EE8, 0x11BC }, + { 0x0EE9, 0x11BD }, + { 0x0EEA, 0x11BE }, + { 0x0EEB, 0x11BF }, + { 0x0EEC, 0x11C0 }, + { 0x0EED, 0x11C1 }, + { 0x0EEE, 0x11C2 }, + { 0x0EEF, 0x316D }, + { 0x0EF0, 0x3171 }, + { 0x0EF1, 0x3178 }, + { 0x0EF2, 0x317F }, + { 0x0EF3, 0x3181 }, + { 0x0EF4, 0x3184 }, + { 0x0EF5, 0x3186 }, + { 0x0EF6, 0x318D }, + { 0x0EF7, 0x318E }, + { 0x0EF8, 0x11EB }, + { 0x0EF9, 0x11F0 }, + { 0x0EFA, 0x11F9 }, + { 0x0EFF, 0x20A9 }, + { 0x13A4, 0x20AC }, + { 0x13BC, 0x0152 }, + { 0x13BD, 0x0153 }, + { 0x13BE, 0x0178 }, + { 0x20AC, 0x20AC }, +}; + +unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) { + + /* Latin-1 */ + if (p_keysym>=0x20 && p_keysym<=0x7e) + return p_keysym; + if (p_keysym>=0xa0 && p_keysym<=0xff) + return p_keysym; + // keypad to latin1 is easy + if (p_keysym>=0xffaa && p_keysym<=0xffb9) + return p_keysym-0xff80; + + /* Unicode (may be present)*/ + + if((p_keysym&0xff000000)==0x01000000) + return p_keysym&0x00ffffff; + + int middle,low=0,high=_KEYSYM_MAX-1; + do { + middle=(high+low)/2; + if ( _xkeysym_to_unicode[middle].keysym==p_keysym) + return _xkeysym_to_unicode[middle].unicode; + if ( _xkeysym_to_unicode[middle].keysym<=p_keysym ) + low=middle+1; + else + high=middle-1; + } while (high>=low); + + return 0; + +} + +struct _XTranslateUnicodePairReverse { + + unsigned int unicode; + KeySym keysym; +}; + +enum { + + _UNICODE_MAX=750 +}; + +static _XTranslateUnicodePairReverse _unicode_to_xkeysym[_UNICODE_MAX] = { + { 0x0ABD, 0x002E }, + { 0x0BA3, 0x003C }, + { 0x0BA6, 0x003E }, + { 0x0BC6, 0x005F }, + { 0x0BC0, 0x00AF }, + { 0x03C0, 0x0100 }, + { 0x03E0, 0x0101 }, + { 0x01C3, 0x0102 }, + { 0x01E3, 0x0103 }, + { 0x01A1, 0x0104 }, + { 0x01B1, 0x0105 }, + { 0x01C6, 0x0106 }, + { 0x01E6, 0x0107 }, + { 0x02C6, 0x0108 }, + { 0x02E6, 0x0109 }, + { 0x02C5, 0x010A }, + { 0x02E5, 0x010B }, + { 0x01C8, 0x010C }, + { 0x01E8, 0x010D }, + { 0x01CF, 0x010E }, + { 0x01EF, 0x010F }, + { 0x01D0, 0x0110 }, + { 0x01F0, 0x0111 }, + { 0x03AA, 0x0112 }, + { 0x03BA, 0x0113 }, + { 0x03CC, 0x0116 }, + { 0x03EC, 0x0117 }, + { 0x01CA, 0x0118 }, + { 0x01EA, 0x0119 }, + { 0x01CC, 0x011A }, + { 0x01EC, 0x011B }, + { 0x02D8, 0x011C }, + { 0x02F8, 0x011D }, + { 0x02AB, 0x011E }, + { 0x02BB, 0x011F }, + { 0x02D5, 0x0120 }, + { 0x02F5, 0x0121 }, + { 0x03AB, 0x0122 }, + { 0x03BB, 0x0123 }, + { 0x02A6, 0x0124 }, + { 0x02B6, 0x0125 }, + { 0x02A1, 0x0126 }, + { 0x02B1, 0x0127 }, + { 0x03A5, 0x0128 }, + { 0x03B5, 0x0129 }, + { 0x03CF, 0x012A }, + { 0x03EF, 0x012B }, + { 0x03C7, 0x012E }, + { 0x03E7, 0x012F }, + { 0x02A9, 0x0130 }, + { 0x02B9, 0x0131 }, + { 0x02AC, 0x0134 }, + { 0x02BC, 0x0135 }, + { 0x03D3, 0x0136 }, + { 0x03F3, 0x0137 }, + { 0x03A2, 0x0138 }, + { 0x01C5, 0x0139 }, + { 0x01E5, 0x013A }, + { 0x03A6, 0x013B }, + { 0x03B6, 0x013C }, + { 0x01A5, 0x013D }, + { 0x01B5, 0x013E }, + { 0x01A3, 0x0141 }, + { 0x01B3, 0x0142 }, + { 0x01D1, 0x0143 }, + { 0x01F1, 0x0144 }, + { 0x03D1, 0x0145 }, + { 0x03F1, 0x0146 }, + { 0x01D2, 0x0147 }, + { 0x01F2, 0x0148 }, + { 0x03BD, 0x014A }, + { 0x03BF, 0x014B }, + { 0x03D2, 0x014C }, + { 0x03F2, 0x014D }, + { 0x01D5, 0x0150 }, + { 0x01F5, 0x0151 }, + { 0x13BC, 0x0152 }, + { 0x13BD, 0x0153 }, + { 0x01C0, 0x0154 }, + { 0x01E0, 0x0155 }, + { 0x03A3, 0x0156 }, + { 0x03B3, 0x0157 }, + { 0x01D8, 0x0158 }, + { 0x01F8, 0x0159 }, + { 0x01A6, 0x015A }, + { 0x01B6, 0x015B }, + { 0x02DE, 0x015C }, + { 0x02FE, 0x015D }, + { 0x01AA, 0x015E }, + { 0x01BA, 0x015F }, + { 0x01A9, 0x0160 }, + { 0x01B9, 0x0161 }, + { 0x01DE, 0x0162 }, + { 0x01FE, 0x0163 }, + { 0x01AB, 0x0164 }, + { 0x01BB, 0x0165 }, + { 0x03AC, 0x0166 }, + { 0x03BC, 0x0167 }, + { 0x03DD, 0x0168 }, + { 0x03FD, 0x0169 }, + { 0x03DE, 0x016A }, + { 0x03FE, 0x016B }, + { 0x02DD, 0x016C }, + { 0x02FD, 0x016D }, + { 0x01D9, 0x016E }, + { 0x01F9, 0x016F }, + { 0x01DB, 0x0170 }, + { 0x01FB, 0x0171 }, + { 0x03D9, 0x0172 }, + { 0x03F9, 0x0173 }, + { 0x13BE, 0x0178 }, + { 0x01AC, 0x0179 }, + { 0x01BC, 0x017A }, + { 0x01AF, 0x017B }, + { 0x01BF, 0x017C }, + { 0x01AE, 0x017D }, + { 0x01BE, 0x017E }, + { 0x08F6, 0x0192 }, + { 0x01B7, 0x02C7 }, + { 0x01A2, 0x02D8 }, + { 0x01FF, 0x02D9 }, + { 0x01B2, 0x02DB }, + { 0x01BD, 0x02DD }, + { 0x07AE, 0x0385 }, + { 0x07A1, 0x0386 }, + { 0x07A2, 0x0388 }, + { 0x07A3, 0x0389 }, + { 0x07A4, 0x038A }, + { 0x07A7, 0x038C }, + { 0x07A8, 0x038E }, + { 0x07AB, 0x038F }, + { 0x07B6, 0x0390 }, + { 0x07C1, 0x0391 }, + { 0x07C2, 0x0392 }, + { 0x07C3, 0x0393 }, + { 0x07C4, 0x0394 }, + { 0x07C5, 0x0395 }, + { 0x07C6, 0x0396 }, + { 0x07C7, 0x0397 }, + { 0x07C8, 0x0398 }, + { 0x07C9, 0x0399 }, + { 0x07CA, 0x039A }, + { 0x07CB, 0x039B }, + { 0x07CC, 0x039C }, + { 0x07CD, 0x039D }, + { 0x07CE, 0x039E }, + { 0x07CF, 0x039F }, + { 0x07D0, 0x03A0 }, + { 0x07D1, 0x03A1 }, + { 0x07D2, 0x03A3 }, + { 0x07D4, 0x03A4 }, + { 0x07D5, 0x03A5 }, + { 0x07D6, 0x03A6 }, + { 0x07D7, 0x03A7 }, + { 0x07D8, 0x03A8 }, + { 0x07D9, 0x03A9 }, + { 0x07A5, 0x03AA }, + { 0x07A9, 0x03AB }, + { 0x07B1, 0x03AC }, + { 0x07B2, 0x03AD }, + { 0x07B3, 0x03AE }, + { 0x07B4, 0x03AF }, + { 0x07BA, 0x03B0 }, + { 0x07E1, 0x03B1 }, + { 0x07E2, 0x03B2 }, + { 0x07E3, 0x03B3 }, + { 0x07E4, 0x03B4 }, + { 0x07E5, 0x03B5 }, + { 0x07E6, 0x03B6 }, + { 0x07E7, 0x03B7 }, + { 0x07E8, 0x03B8 }, + { 0x07E9, 0x03B9 }, + { 0x07EA, 0x03BA }, + { 0x07EB, 0x03BB }, + { 0x07EC, 0x03BC }, + { 0x07ED, 0x03BD }, + { 0x07EE, 0x03BE }, + { 0x07EF, 0x03BF }, + { 0x07F0, 0x03C0 }, + { 0x07F1, 0x03C1 }, + { 0x07F3, 0x03C2 }, + { 0x07F2, 0x03C3 }, + { 0x07F4, 0x03C4 }, + { 0x07F5, 0x03C5 }, + { 0x07F6, 0x03C6 }, + { 0x07F7, 0x03C7 }, + { 0x07F8, 0x03C8 }, + { 0x07F9, 0x03C9 }, + { 0x07B5, 0x03CA }, + { 0x07B9, 0x03CB }, + { 0x07B7, 0x03CC }, + { 0x07B8, 0x03CD }, + { 0x07BB, 0x03CE }, + { 0x06B3, 0x0401 }, + { 0x06B1, 0x0402 }, + { 0x06B2, 0x0403 }, + { 0x06B4, 0x0404 }, + { 0x06B5, 0x0405 }, + { 0x06B6, 0x0406 }, + { 0x06B7, 0x0407 }, + { 0x06B8, 0x0408 }, + { 0x06B9, 0x0409 }, + { 0x06BA, 0x040A }, + { 0x06BB, 0x040B }, + { 0x06BC, 0x040C }, + { 0x06BE, 0x040E }, + { 0x06BF, 0x040F }, + { 0x06E1, 0x0410 }, + { 0x06E2, 0x0411 }, + { 0x06F7, 0x0412 }, + { 0x06E7, 0x0413 }, + { 0x06E4, 0x0414 }, + { 0x06E5, 0x0415 }, + { 0x06F6, 0x0416 }, + { 0x06FA, 0x0417 }, + { 0x06E9, 0x0418 }, + { 0x06EA, 0x0419 }, + { 0x06EB, 0x041A }, + { 0x06EC, 0x041B }, + { 0x06ED, 0x041C }, + { 0x06EE, 0x041D }, + { 0x06EF, 0x041E }, + { 0x06F0, 0x041F }, + { 0x06F2, 0x0420 }, + { 0x06F3, 0x0421 }, + { 0x06F4, 0x0422 }, + { 0x06F5, 0x0423 }, + { 0x06E6, 0x0424 }, + { 0x06E8, 0x0425 }, + { 0x06E3, 0x0426 }, + { 0x06FE, 0x0427 }, + { 0x06FB, 0x0428 }, + { 0x06FD, 0x0429 }, + { 0x06FF, 0x042A }, + { 0x06F9, 0x042B }, + { 0x06F8, 0x042C }, + { 0x06FC, 0x042D }, + { 0x06E0, 0x042E }, + { 0x06F1, 0x042F }, + { 0x06C1, 0x0430 }, + { 0x06C2, 0x0431 }, + { 0x06D7, 0x0432 }, + { 0x06C7, 0x0433 }, + { 0x06C4, 0x0434 }, + { 0x06C5, 0x0435 }, + { 0x06D6, 0x0436 }, + { 0x06DA, 0x0437 }, + { 0x06C9, 0x0438 }, + { 0x06CA, 0x0439 }, + { 0x06CB, 0x043A }, + { 0x06CC, 0x043B }, + { 0x06CD, 0x043C }, + { 0x06CE, 0x043D }, + { 0x06CF, 0x043E }, + { 0x06D0, 0x043F }, + { 0x06D2, 0x0440 }, + { 0x06D3, 0x0441 }, + { 0x06D4, 0x0442 }, + { 0x06D5, 0x0443 }, + { 0x06C6, 0x0444 }, + { 0x06C8, 0x0445 }, + { 0x06C3, 0x0446 }, + { 0x06DE, 0x0447 }, + { 0x06DB, 0x0448 }, + { 0x06DD, 0x0449 }, + { 0x06DF, 0x044A }, + { 0x06D9, 0x044B }, + { 0x06D8, 0x044C }, + { 0x06DC, 0x044D }, + { 0x06C0, 0x044E }, + { 0x06D1, 0x044F }, + { 0x06A3, 0x0451 }, + { 0x06A1, 0x0452 }, + { 0x06A2, 0x0453 }, + { 0x06A4, 0x0454 }, + { 0x06A5, 0x0455 }, + { 0x06A6, 0x0456 }, + { 0x06A7, 0x0457 }, + { 0x06A8, 0x0458 }, + { 0x06A9, 0x0459 }, + { 0x06AA, 0x045A }, + { 0x06AB, 0x045B }, + { 0x06AC, 0x045C }, + { 0x06AE, 0x045E }, + { 0x06AF, 0x045F }, + { 0x0CE0, 0x05D0 }, + { 0x0CE1, 0x05D1 }, + { 0x0CE2, 0x05D2 }, + { 0x0CE3, 0x05D3 }, + { 0x0CE4, 0x05D4 }, + { 0x0CE5, 0x05D5 }, + { 0x0CE6, 0x05D6 }, + { 0x0CE7, 0x05D7 }, + { 0x0CE8, 0x05D8 }, + { 0x0CE9, 0x05D9 }, + { 0x0CEA, 0x05DA }, + { 0x0CEB, 0x05DB }, + { 0x0CEC, 0x05DC }, + { 0x0CED, 0x05DD }, + { 0x0CEE, 0x05DE }, + { 0x0CEF, 0x05DF }, + { 0x0CF0, 0x05E0 }, + { 0x0CF1, 0x05E1 }, + { 0x0CF2, 0x05E2 }, + { 0x0CF3, 0x05E3 }, + { 0x0CF4, 0x05E4 }, + { 0x0CF5, 0x05E5 }, + { 0x0CF6, 0x05E6 }, + { 0x0CF7, 0x05E7 }, + { 0x0CF8, 0x05E8 }, + { 0x0CF9, 0x05E9 }, + { 0x0CFA, 0x05EA }, + { 0x05AC, 0x060C }, + { 0x05BB, 0x061B }, + { 0x05BF, 0x061F }, + { 0x05C1, 0x0621 }, + { 0x05C2, 0x0622 }, + { 0x05C3, 0x0623 }, + { 0x05C4, 0x0624 }, + { 0x05C5, 0x0625 }, + { 0x05C6, 0x0626 }, + { 0x05C7, 0x0627 }, + { 0x05C8, 0x0628 }, + { 0x05C9, 0x0629 }, + { 0x05CA, 0x062A }, + { 0x05CB, 0x062B }, + { 0x05CC, 0x062C }, + { 0x05CD, 0x062D }, + { 0x05CE, 0x062E }, + { 0x05CF, 0x062F }, + { 0x05D0, 0x0630 }, + { 0x05D1, 0x0631 }, + { 0x05D2, 0x0632 }, + { 0x05D3, 0x0633 }, + { 0x05D4, 0x0634 }, + { 0x05D5, 0x0635 }, + { 0x05D6, 0x0636 }, + { 0x05D7, 0x0637 }, + { 0x05D8, 0x0638 }, + { 0x05D9, 0x0639 }, + { 0x05DA, 0x063A }, + { 0x05E0, 0x0640 }, + { 0x05E1, 0x0641 }, + { 0x05E2, 0x0642 }, + { 0x05E3, 0x0643 }, + { 0x05E4, 0x0644 }, + { 0x05E5, 0x0645 }, + { 0x05E6, 0x0646 }, + { 0x05E7, 0x0647 }, + { 0x05E8, 0x0648 }, + { 0x05E9, 0x0649 }, + { 0x05EA, 0x064A }, + { 0x05EB, 0x064B }, + { 0x05EC, 0x064C }, + { 0x05ED, 0x064D }, + { 0x05EE, 0x064E }, + { 0x05EF, 0x064F }, + { 0x05F0, 0x0650 }, + { 0x05F1, 0x0651 }, + { 0x05F2, 0x0652 }, + { 0x0DA1, 0x0E01 }, + { 0x0DA2, 0x0E02 }, + { 0x0DA3, 0x0E03 }, + { 0x0DA4, 0x0E04 }, + { 0x0DA5, 0x0E05 }, + { 0x0DA6, 0x0E06 }, + { 0x0DA7, 0x0E07 }, + { 0x0DA8, 0x0E08 }, + { 0x0DA9, 0x0E09 }, + { 0x0DAA, 0x0E0A }, + { 0x0DAB, 0x0E0B }, + { 0x0DAC, 0x0E0C }, + { 0x0DAD, 0x0E0D }, + { 0x0DAE, 0x0E0E }, + { 0x0DAF, 0x0E0F }, + { 0x0DB0, 0x0E10 }, + { 0x0DB1, 0x0E11 }, + { 0x0DB2, 0x0E12 }, + { 0x0DB3, 0x0E13 }, + { 0x0DB4, 0x0E14 }, + { 0x0DB5, 0x0E15 }, + { 0x0DB6, 0x0E16 }, + { 0x0DB7, 0x0E17 }, + { 0x0DB8, 0x0E18 }, + { 0x0DB9, 0x0E19 }, + { 0x0DBA, 0x0E1A }, + { 0x0DBB, 0x0E1B }, + { 0x0DBC, 0x0E1C }, + { 0x0DBD, 0x0E1D }, + { 0x0DBE, 0x0E1E }, + { 0x0DBF, 0x0E1F }, + { 0x0DC0, 0x0E20 }, + { 0x0DC1, 0x0E21 }, + { 0x0DC2, 0x0E22 }, + { 0x0DC3, 0x0E23 }, + { 0x0DC4, 0x0E24 }, + { 0x0DC5, 0x0E25 }, + { 0x0DC6, 0x0E26 }, + { 0x0DC7, 0x0E27 }, + { 0x0DC8, 0x0E28 }, + { 0x0DC9, 0x0E29 }, + { 0x0DCA, 0x0E2A }, + { 0x0DCB, 0x0E2B }, + { 0x0DCC, 0x0E2C }, + { 0x0DCD, 0x0E2D }, + { 0x0DCE, 0x0E2E }, + { 0x0DCF, 0x0E2F }, + { 0x0DD0, 0x0E30 }, + { 0x0DD1, 0x0E31 }, + { 0x0DD2, 0x0E32 }, + { 0x0DD3, 0x0E33 }, + { 0x0DD4, 0x0E34 }, + { 0x0DD5, 0x0E35 }, + { 0x0DD6, 0x0E36 }, + { 0x0DD7, 0x0E37 }, + { 0x0DD8, 0x0E38 }, + { 0x0DD9, 0x0E39 }, + { 0x0DDA, 0x0E3A }, + { 0x0DDF, 0x0E3F }, + { 0x0DE0, 0x0E40 }, + { 0x0DE1, 0x0E41 }, + { 0x0DE2, 0x0E42 }, + { 0x0DE3, 0x0E43 }, + { 0x0DE4, 0x0E44 }, + { 0x0DE5, 0x0E45 }, + { 0x0DE6, 0x0E46 }, + { 0x0DE7, 0x0E47 }, + { 0x0DE8, 0x0E48 }, + { 0x0DE9, 0x0E49 }, + { 0x0DEA, 0x0E4A }, + { 0x0DEB, 0x0E4B }, + { 0x0DEC, 0x0E4C }, + { 0x0DED, 0x0E4D }, + { 0x0DF0, 0x0E50 }, + { 0x0DF1, 0x0E51 }, + { 0x0DF2, 0x0E52 }, + { 0x0DF3, 0x0E53 }, + { 0x0DF4, 0x0E54 }, + { 0x0DF5, 0x0E55 }, + { 0x0DF6, 0x0E56 }, + { 0x0DF7, 0x0E57 }, + { 0x0DF8, 0x0E58 }, + { 0x0DF9, 0x0E59 }, + { 0x0ED4, 0x11A8 }, + { 0x0ED5, 0x11A9 }, + { 0x0ED6, 0x11AA }, + { 0x0ED7, 0x11AB }, + { 0x0ED8, 0x11AC }, + { 0x0ED9, 0x11AD }, + { 0x0EDA, 0x11AE }, + { 0x0EDB, 0x11AF }, + { 0x0EDC, 0x11B0 }, + { 0x0EDD, 0x11B1 }, + { 0x0EDE, 0x11B2 }, + { 0x0EDF, 0x11B3 }, + { 0x0EE0, 0x11B4 }, + { 0x0EE1, 0x11B5 }, + { 0x0EE2, 0x11B6 }, + { 0x0EE3, 0x11B7 }, + { 0x0EE4, 0x11B8 }, + { 0x0EE5, 0x11B9 }, + { 0x0EE6, 0x11BA }, + { 0x0EE7, 0x11BB }, + { 0x0EE8, 0x11BC }, + { 0x0EE9, 0x11BD }, + { 0x0EEA, 0x11BE }, + { 0x0EEB, 0x11BF }, + { 0x0EEC, 0x11C0 }, + { 0x0EED, 0x11C1 }, + { 0x0EEE, 0x11C2 }, + { 0x0EF8, 0x11EB }, + { 0x0EFA, 0x11F9 }, + { 0x0AA2, 0x2002 }, + { 0x0AA1, 0x2003 }, + { 0x0AA3, 0x2004 }, + { 0x0AA4, 0x2005 }, + { 0x0AA5, 0x2007 }, + { 0x0AA6, 0x2008 }, + { 0x0AA7, 0x2009 }, + { 0x0AA8, 0x200A }, + { 0x0ABB, 0x2012 }, + { 0x0AAA, 0x2013 }, + { 0x0AA9, 0x2014 }, + { 0x07AF, 0x2015 }, + { 0x0CDF, 0x2017 }, + { 0x0AD0, 0x2018 }, + { 0x0AD1, 0x2019 }, + { 0x0AFD, 0x201A }, + { 0x0AD2, 0x201C }, + { 0x0AD3, 0x201D }, + { 0x0AFE, 0x201E }, + { 0x0AF1, 0x2020 }, + { 0x0AF2, 0x2021 }, + { 0x0AE6, 0x2022 }, + { 0x0AAE, 0x2026 }, + { 0x0AD6, 0x2032 }, + { 0x0AD7, 0x2033 }, + { 0x0AFC, 0x2038 }, + { 0x047E, 0x203E }, + { 0x20A0, 0x20A0 }, + { 0x20A1, 0x20A1 }, + { 0x20A2, 0x20A2 }, + { 0x20A3, 0x20A3 }, + { 0x20A4, 0x20A4 }, + { 0x20A5, 0x20A5 }, + { 0x20A6, 0x20A6 }, + { 0x20A7, 0x20A7 }, + { 0x20A8, 0x20A8 }, + { 0x0EFF, 0x20A9 }, + { 0x20A9, 0x20A9 }, + { 0x20AA, 0x20AA }, + { 0x20AB, 0x20AB }, + { 0x20AC, 0x20AC }, + { 0x0AB8, 0x2105 }, + { 0x06B0, 0x2116 }, + { 0x0AFB, 0x2117 }, + { 0x0AD4, 0x211E }, + { 0x0AC9, 0x2122 }, + { 0x0AB0, 0x2153 }, + { 0x0AB1, 0x2154 }, + { 0x0AB2, 0x2155 }, + { 0x0AB3, 0x2156 }, + { 0x0AB4, 0x2157 }, + { 0x0AB5, 0x2158 }, + { 0x0AB6, 0x2159 }, + { 0x0AB7, 0x215A }, + { 0x0AC3, 0x215B }, + { 0x0AC4, 0x215C }, + { 0x0AC5, 0x215D }, + { 0x0AC6, 0x215E }, + { 0x08FB, 0x2190 }, + { 0x08FC, 0x2191 }, + { 0x08FD, 0x2192 }, + { 0x08FE, 0x2193 }, + { 0x08CE, 0x21D2 }, + { 0x08CD, 0x21D4 }, + { 0x08EF, 0x2202 }, + { 0x08C5, 0x2207 }, + { 0x0BCA, 0x2218 }, + { 0x08D6, 0x221A }, + { 0x08C1, 0x221D }, + { 0x08C2, 0x221E }, + { 0x08DE, 0x2227 }, + { 0x0BA9, 0x2227 }, + { 0x08DF, 0x2228 }, + { 0x0BA8, 0x2228 }, + { 0x08DC, 0x2229 }, + { 0x0BC3, 0x2229 }, + { 0x08DD, 0x222A }, + { 0x0BD6, 0x222A }, + { 0x08BF, 0x222B }, + { 0x08C0, 0x2234 }, + { 0x08C8, 0x2245 }, + { 0x08BD, 0x2260 }, + { 0x08CF, 0x2261 }, + { 0x08BC, 0x2264 }, + { 0x08BE, 0x2265 }, + { 0x08DA, 0x2282 }, + { 0x0BDA, 0x2282 }, + { 0x08DB, 0x2283 }, + { 0x0BD8, 0x2283 }, + { 0x0BFC, 0x22A2 }, + { 0x0BDC, 0x22A3 }, + { 0x0BC2, 0x22A4 }, + { 0x0BCE, 0x22A5 }, + { 0x0BD3, 0x2308 }, + { 0x0BC4, 0x230A }, + { 0x0AFA, 0x2315 }, + { 0x08A4, 0x2320 }, + { 0x08A5, 0x2321 }, + { 0x0ABC, 0x2329 }, + { 0x0ABE, 0x232A }, + { 0x0BCC, 0x2395 }, + { 0x09E2, 0x2409 }, + { 0x09E5, 0x240A }, + { 0x09E9, 0x240B }, + { 0x09E3, 0x240C }, + { 0x09E4, 0x240D }, + { 0x09DF, 0x2422 }, + { 0x09E8, 0x2424 }, + { 0x09F1, 0x2500 }, + { 0x08A6, 0x2502 }, + { 0x09F8, 0x2502 }, + { 0x09EC, 0x250C }, + { 0x09EB, 0x2510 }, + { 0x09ED, 0x2514 }, + { 0x09EA, 0x2518 }, + { 0x09F4, 0x251C }, + { 0x09F5, 0x2524 }, + { 0x09F7, 0x252C }, + { 0x09F6, 0x2534 }, + { 0x09EE, 0x253C }, + { 0x09E1, 0x2592 }, + { 0x0ADF, 0x25A0 }, + { 0x0ACF, 0x25A1 }, + { 0x0AE7, 0x25AA }, + { 0x0AE1, 0x25AB }, + { 0x0ADB, 0x25AC }, + { 0x0AE2, 0x25AD }, + { 0x0AE8, 0x25B2 }, + { 0x0AE3, 0x25B3 }, + { 0x0ADD, 0x25B6 }, + { 0x0ACD, 0x25B7 }, + { 0x0AE9, 0x25BC }, + { 0x0AE4, 0x25BD }, + { 0x0ADC, 0x25C0 }, + { 0x0ACC, 0x25C1 }, + { 0x09E0, 0x25C6 }, + { 0x0ACE, 0x25CB }, + { 0x0BCF, 0x25CB }, + { 0x0ADE, 0x25CF }, + { 0x0AE0, 0x25E6 }, + { 0x0AE5, 0x2606 }, + { 0x0AF9, 0x260E }, + { 0x0ACA, 0x2613 }, + { 0x0AEA, 0x261C }, + { 0x0AEB, 0x261E }, + { 0x0AF8, 0x2640 }, + { 0x0AF7, 0x2642 }, + { 0x0AEC, 0x2663 }, + { 0x0AEE, 0x2665 }, + { 0x0AED, 0x2666 }, + { 0x0AF6, 0x266D }, + { 0x0AF5, 0x266F }, + { 0x0AF3, 0x2713 }, + { 0x0AF4, 0x2717 }, + { 0x0AD9, 0x271D }, + { 0x0AF0, 0x2720 }, + { 0x04A4, 0x3001 }, + { 0x04A1, 0x3002 }, + { 0x04A2, 0x300C }, + { 0x04A3, 0x300D }, + { 0x04DE, 0x309B }, + { 0x04DF, 0x309C }, + { 0x04A7, 0x30A1 }, + { 0x04B1, 0x30A2 }, + { 0x04A8, 0x30A3 }, + { 0x04B2, 0x30A4 }, + { 0x04A9, 0x30A5 }, + { 0x04B3, 0x30A6 }, + { 0x04AA, 0x30A7 }, + { 0x04B4, 0x30A8 }, + { 0x04AB, 0x30A9 }, + { 0x04B5, 0x30AA }, + { 0x04B6, 0x30AB }, + { 0x04B7, 0x30AD }, + { 0x04B8, 0x30AF }, + { 0x04B9, 0x30B1 }, + { 0x04BA, 0x30B3 }, + { 0x04BB, 0x30B5 }, + { 0x04BC, 0x30B7 }, + { 0x04BD, 0x30B9 }, + { 0x04BE, 0x30BB }, + { 0x04BF, 0x30BD }, + { 0x04C0, 0x30BF }, + { 0x04C1, 0x30C1 }, + { 0x04AF, 0x30C3 }, + { 0x04C2, 0x30C4 }, + { 0x04C3, 0x30C6 }, + { 0x04C4, 0x30C8 }, + { 0x04C5, 0x30CA }, + { 0x04C6, 0x30CB }, + { 0x04C7, 0x30CC }, + { 0x04C8, 0x30CD }, + { 0x04C9, 0x30CE }, + { 0x04CA, 0x30CF }, + { 0x04CB, 0x30D2 }, + { 0x04CC, 0x30D5 }, + { 0x04CD, 0x30D8 }, + { 0x04CE, 0x30DB }, + { 0x04CF, 0x30DE }, + { 0x04D0, 0x30DF }, + { 0x04D1, 0x30E0 }, + { 0x04D2, 0x30E1 }, + { 0x04D3, 0x30E2 }, + { 0x04AC, 0x30E3 }, + { 0x04D4, 0x30E4 }, + { 0x04AD, 0x30E5 }, + { 0x04D5, 0x30E6 }, + { 0x04AE, 0x30E7 }, + { 0x04D6, 0x30E8 }, + { 0x04D7, 0x30E9 }, + { 0x04D8, 0x30EA }, + { 0x04D9, 0x30EB }, + { 0x04DA, 0x30EC }, + { 0x04DB, 0x30ED }, + { 0x04DC, 0x30EF }, + { 0x04A6, 0x30F2 }, + { 0x04DD, 0x30F3 }, + { 0x04A5, 0x30FB }, + { 0x04B0, 0x30FC }, + { 0x0EA1, 0x3131 }, + { 0x0EA2, 0x3132 }, + { 0x0EA3, 0x3133 }, + { 0x0EA4, 0x3134 }, + { 0x0EA5, 0x3135 }, + { 0x0EA6, 0x3136 }, + { 0x0EA7, 0x3137 }, + { 0x0EA8, 0x3138 }, + { 0x0EA9, 0x3139 }, + { 0x0EAA, 0x313A }, + { 0x0EAB, 0x313B }, + { 0x0EAC, 0x313C }, + { 0x0EAD, 0x313D }, + { 0x0EAE, 0x313E }, + { 0x0EAF, 0x313F }, + { 0x0EB0, 0x3140 }, + { 0x0EB1, 0x3141 }, + { 0x0EB2, 0x3142 }, + { 0x0EB3, 0x3143 }, + { 0x0EB4, 0x3144 }, + { 0x0EB5, 0x3145 }, + { 0x0EB6, 0x3146 }, + { 0x0EB7, 0x3147 }, + { 0x0EB8, 0x3148 }, + { 0x0EB9, 0x3149 }, + { 0x0EBA, 0x314A }, + { 0x0EBB, 0x314B }, + { 0x0EBC, 0x314C }, + { 0x0EBD, 0x314D }, + { 0x0EBE, 0x314E }, + { 0x0EBF, 0x314F }, + { 0x0EC0, 0x3150 }, + { 0x0EC1, 0x3151 }, + { 0x0EC2, 0x3152 }, + { 0x0EC3, 0x3153 }, + { 0x0EC4, 0x3154 }, + { 0x0EC5, 0x3155 }, + { 0x0EC6, 0x3156 }, + { 0x0EC7, 0x3157 }, + { 0x0EC8, 0x3158 }, + { 0x0EC9, 0x3159 }, + { 0x0ECA, 0x315A }, + { 0x0ECB, 0x315B }, + { 0x0ECC, 0x315C }, + { 0x0ECD, 0x315D }, + { 0x0ECE, 0x315E }, + { 0x0ECF, 0x315F }, + { 0x0ED0, 0x3160 }, + { 0x0ED1, 0x3161 }, + { 0x0ED2, 0x3162 }, + { 0x0ED3, 0x3163 }, + { 0x0EEF, 0x316D }, + { 0x0EF0, 0x3171 }, + { 0x0EF1, 0x3178 }, + { 0x0EF2, 0x317F }, + { 0x0EF4, 0x3184 }, + { 0x0EF5, 0x3186 }, + { 0x0EF6, 0x318D }, + { 0x0EF7, 0x318E } +}; + +KeySym KeyMappingX11::get_keysym_from_unicode(unsigned int p_unicode) { + + /* Latin 1 */ + + if (p_unicode>=0x20 && p_unicode<=0x7e) + return p_unicode; + + if (p_unicode>=0xa0 && p_unicode<=0xff) + return p_unicode; + + int middle,low=0,high=_UNICODE_MAX-1; + do { + middle=(high+low)/2; + if ( _unicode_to_xkeysym[middle].keysym==p_unicode) + return _unicode_to_xkeysym[middle].keysym; + if ( _unicode_to_xkeysym[middle].keysym<=p_unicode ) + low=middle+1; + else + high=middle-1; + } while (high>=low); + + // if not found, let's hope X understands it as unicode + return p_unicode|0x01000000; +} diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h new file mode 100644 index 000000000..97393d92f --- /dev/null +++ b/platform/x11/key_mapping_x11.h @@ -0,0 +1,55 @@ +/*************************************************************************/ +/* key_mapping_x11.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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. */ +/*************************************************************************/ +#ifndef KEY_MAPPING_X11_H +#define KEY_MAPPING_X11_H + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +#include <X11/Xlib.h> +#include <X11/XF86keysym.h> +#define XK_MISCELLANY +#define XK_LATIN1 +#define XK_XKB_KEYS +#include <X11/keysymdef.h> + +#include "os/keyboard.h" + +class KeyMappingX11 { + KeyMappingX11() {}; +public: + static unsigned int get_keycode(KeySym p_keysym); + static KeySym get_keysym(unsigned int p_code); + static unsigned int get_unicode_from_keysym(KeySym p_keysym); + static KeySym get_keysym_from_unicode(unsigned int p_unicode); + +}; + + +#endif diff --git a/platform/x11/logo.png b/platform/x11/logo.png Binary files differnew file mode 100644 index 000000000..c40214d6d --- /dev/null +++ b/platform/x11/logo.png diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp new file mode 100644 index 000000000..79dd6f123 --- /dev/null +++ b/platform/x11/os_x11.cpp @@ -0,0 +1,1300 @@ +/*************************************************************************/ +/* os_x11.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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 "servers/visual/visual_server_raster.h" +#include "drivers/gles2/rasterizer_gles2.h" +#include "drivers/gles1/rasterizer_gles1.h" +#include "os_x11.h" +#include "key_mapping_x11.h" +#include <stdio.h> +#include <stdlib.h> +#include "print_string.h" +#include "servers/physics/physics_server_sw.h" + +#include "X11/Xutil.h" +#include "main/main.h" + + + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <linux/joystick.h> + +//stupid linux.h +#ifdef KEY_TAB +#undef KEY_TAB +#endif + + +#include <X11/Xatom.h> +#include "os/pc_joystick_map.h" + +#undef CursorShape + +int OS_X11::get_video_driver_count() const { + + return 2; +} +const char * OS_X11::get_video_driver_name(int p_driver) const { + + return p_driver==0?"GLES2":"GLES1"; +} +OS::VideoMode OS_X11::get_default_video_mode() const { + + return OS::VideoMode(800,600,false); +} + +void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { + + last_button_state=0; + dpad_last[0]=0; + dpad_last[1]=0; + + xmbstring=NULL; + event_id=0; + x11_window=0; + last_click_ms=0; + args=OS::get_singleton()->get_cmdline_args(); + current_videomode=p_desired; + main_loop=NULL; + last_timestamp=0; + last_mouse_pos_valid=false; + last_keyrelease_time=0; + + if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { + XInitThreads(); + } + + /** XLIB INITIALIZATION **/ + x11_display = XOpenDisplay(NULL); + + char * modifiers = XSetLocaleModifiers ("@im=none"); + ERR_FAIL_COND( modifiers == NULL ); + + xim = XOpenIM (x11_display, NULL, NULL, NULL); + + + if (xim == NULL) { + WARN_PRINT("XOpenIM failed"); + xim_style=NULL; + } else { + ::XIMStyles *xim_styles=NULL; + xim_style=0; + char *imvalret=NULL; + imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); + if (imvalret != NULL || xim_styles == NULL) { + fprintf (stderr, "Input method doesn't support any styles\n"); + } + + if (xim_styles) { + xim_style = 0; + for (int i=0;i<xim_styles->count_styles;i++) { + + if (xim_styles->supported_styles[i] == + (XIMPreeditNothing | XIMStatusNothing)) { + + xim_style = xim_styles->supported_styles[i]; + break; + } + } + + XFree (xim_styles); + } + } + + /* + char* windowid = getenv("GODOT_WINDOWID"); + if (windowid) { + + //freopen("/home/punto/stdout", "w", stdout); + //reopen("/home/punto/stderr", "w", stderr); + x11_window = atol(windowid); + + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; + }; + */ + + // maybe contextgl wants to be in charge of creating the window + //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); + context_gl->initialize(); + + if (p_video_driver == 0) { + rasterizer = memnew( RasterizerGLES2 ); + } else { + rasterizer = memnew( RasterizerGLES1 ); + }; + +#endif + visual_server = memnew( VisualServerRaster(rasterizer) ); + + if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { + + visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); + } + + AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + + if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + + ERR_PRINT("Initializing audio failed."); + } + + sample_manager = memnew( SampleManagerMallocSW ); + audio_server = memnew( AudioServerSW(sample_manager) ); + audio_server->init(); + spatial_sound_server = memnew( SpatialSoundServerSW ); + spatial_sound_server->init(); + spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); + spatial_sound_2d_server->init(); + + + ERR_FAIL_COND(!visual_server); + ERR_FAIL_COND(x11_window==0); + + XSetWindowAttributes new_attr; + + new_attr.event_mask=KeyPressMask | KeyReleaseMask | ButtonPressMask | + ButtonReleaseMask | EnterWindowMask | + LeaveWindowMask | PointerMotionMask | + Button1MotionMask | + Button2MotionMask | Button3MotionMask | + Button4MotionMask | Button5MotionMask | + ButtonMotionMask | KeymapStateMask | + ExposureMask | VisibilityChangeMask | + StructureNotifyMask | + SubstructureNotifyMask | SubstructureRedirectMask | + FocusChangeMask | PropertyChangeMask | + ColormapChangeMask | OwnerGrabButtonMask; + + XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); + + wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); + XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); + + + if (xim && xim_style) { + + xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL); + } else { + + xic=NULL; + WARN_PRINT("XCreateIC couldn't create xic"); + + } + + XcursorSetTheme(x11_display,"default"); + cursor_size = XcursorGetDefaultSize(x11_display); + cursor_theme = XcursorGetTheme(x11_display); + + if (!cursor_theme) { + print_line("not found theme"); + cursor_theme="default"; + } + + for(int i=0;i<CURSOR_MAX;i++) { + + cursors[i]=None; + } + + current_cursor=CURSOR_ARROW; + + if (cursor_theme) { + //print_line("cursor theme: "+String(cursor_theme)); + for(int i=0;i<CURSOR_MAX;i++) { + + static const char *cursor_file[]={ + "left_ptr", + "xterm", + "hand2", + "cross", + "watch", + "left_ptr_watch", + "fleur", + "hand1", + "X_cursor", + "sb_v_double_arrow", + "sb_h_double_arrow", + "size_bdiag", + "size_fdiag", + "hand1", + "sb_v_double_arrow", + "sb_h_double_arrow", + "question_arrow" + }; + + XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); + if (img) { + cursors[i]=XcursorImageLoadCursor(x11_display,img); + //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i])); + } else { + if (OS::is_stdout_verbose()) + print_line("failed cursor: "+String(cursor_file[i])); + } + } + + } + + + { + Pixmap cursormask; + XGCValues xgc; + GC gc; + XColor col; + Cursor cursor; + + cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1); + xgc.function = GXclear; + gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc); + XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1); + col.pixel = 0; + col.red = 0; + col.flags = 4; + cursor = XCreatePixmapCursor(x11_display, + cursormask, cursormask, + &col, &col, 0, 0); + XFreePixmap(x11_display, cursormask); + XFreeGC(x11_display, gc); + + + + if (cursor == None) + { + ERR_PRINT("FAILED CREATING CURSOR"); + } + + null_cursor=cursor; + } + set_cursor_shape(CURSOR_BUSY); + + + visual_server->init(); + // + physics_server = memnew( PhysicsServerSW ); + physics_server->init(); + physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server->init(); + + input = memnew( InputDefault ); + + probe_joystick(); + + _ensure_data_dir(); + + net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); + + + //printf("got map notify\n"); + +} +void OS_X11::finalize() { + + if(main_loop) + memdelete(main_loop); + main_loop=NULL; + + spatial_sound_server->finish(); + memdelete(spatial_sound_server); + spatial_sound_2d_server->finish(); + memdelete(spatial_sound_2d_server); + + //if (debugger_connection_console) { +// memdelete(debugger_connection_console); +//} + + audio_server->finish(); + memdelete(audio_server); + memdelete(sample_manager); + + visual_server->finish(); + memdelete(visual_server); + memdelete(rasterizer); + + physics_server->finish(); + memdelete(physics_server); + + physics_2d_server->finish(); + memdelete(physics_2d_server); + + memdelete(input); + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + memdelete(context_gl); +#endif + + + XCloseDisplay(x11_display); + if (xmbstring) + memfree(xmbstring); + + args.clear(); +} + + +void OS_X11::set_mouse_mode(MouseMode p_mode) { + + print_line("WUTF "+itos(p_mode)+" old "+itos(mouse_mode)); + if (p_mode==mouse_mode) + return; + + if (mouse_mode==MOUSE_MODE_CAPTURED) + XUngrabPointer(x11_display, CurrentTime); + if (mouse_mode!=MOUSE_MODE_VISIBLE && p_mode==MOUSE_MODE_VISIBLE) + XUndefineCursor(x11_display,x11_window); + if (p_mode!=MOUSE_MODE_VISIBLE && mouse_mode==MOUSE_MODE_VISIBLE) { + XDefineCursor(x11_display,x11_window,null_cursor); + } + + mouse_mode=p_mode; + + if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (XGrabPointer(x11_display, x11_window, True, + ButtonPressMask | ButtonReleaseMask | + PointerMotionMask, GrabModeAsync, GrabModeAsync, + x11_window, None, CurrentTime) != + GrabSuccess) { + ERR_PRINT("NO GRAB"); + } + + center.x = current_videomode.width/2; + center.y = current_videomode.height/2; + XWarpPointer(x11_display, None, x11_window, + 0,0,0,0, (int)center.x, (int)center.y); + } + +} + +OS::MouseMode OS_X11::get_mouse_mode() const { + + return mouse_mode; +} + + + +int OS_X11::get_mouse_button_state() const { + + return last_button_state; +} + +Point2 OS_X11::get_mouse_pos() const { + + return last_mouse_pos; +} + +void OS_X11::set_window_title(const String& p_title) { + + XStoreName(x11_display,x11_window,p_title.utf8().get_data()); +} + +void OS_X11::set_video_mode(const VideoMode& p_video_mode,int p_screen) { + + +} +OS::VideoMode OS_X11::get_video_mode(int p_screen) const { + + return current_videomode; +} +void OS_X11::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { + + +} + + +InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { + + InputModifierState state; + + state.shift = (p_x11_state&ShiftMask); + state.control = (p_x11_state&ControlMask); + state.alt = (p_x11_state&Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt + state.meta = (p_x11_state&Mod4Mask); + + return state; +} + +unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) { + + unsigned int state=0; + + if (p_x11_state&Button1Mask) { + + state|=1<<0; + } + + if (p_x11_state&Button3Mask) { + + state|=1<<1; + } + + if (p_x11_state&Button2Mask) { + + state|=1<<2; + } + + if (p_x11_state&Button4Mask) { + + state|=1<<3; + } + + if (p_x11_state&Button5Mask) { + + state|=1<<4; + } + + last_button_state=state; + return state; +} + +void OS_X11::handle_key_event(XKeyEvent *p_event) { + + + // X11 functions don't know what const is + XKeyEvent *xkeyevent = p_event; + + // This code was pretty difficult to write. + // The docs stink and every toolkit seems to + // do it in a different way. + + /* Phase 1, obtain a proper keysym */ + + // This was also very difficult to figure out. + // You'd expect you could just use Keysym provided by + // XKeycodeToKeysym to obtain internationalized + // input.. WRONG!! + // you must use XLookupString (???) which not only wastes + // cycles generating an unnecesary string, but also + // still works in half the cases. (won't handle deadkeys) + // For more complex input methods (deadkeys and more advanced) + // you have to use XmbLookupString (??). + // So.. then you have to chosse which of both results + // you want to keep. + // This is a real bizarreness and cpu waster. + + KeySym keysym_keycode=0; // keysym used to find a keycode + KeySym keysym_unicode=0; // keysym used to find unicode + + int nbytes=0; // bytes the string takes + + // XLookupString returns keysyms usable as nice scancodes/ + char str[256+1]; + nbytes=XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); + + // Meanwhile, XLookupString returns keysyms useful for unicode. + + + if (!xmbstring) { + // keep a temporary buffer for the string + xmbstring=(char*)memalloc(sizeof(char)*8); + xmblen=8; + } + + if (xkeyevent->type == KeyPress && xic) { + + Status status; + do { + + int mnbytes = XmbLookupString (xic, xkeyevent, xmbstring, xmblen - 1, &keysym_unicode, &status); + xmbstring[mnbytes] = '\0'; + + if (status == XBufferOverflow) { + xmblen = mnbytes + 1; + xmbstring = (char*)memrealloc (xmbstring, xmblen); + } + } while (status == XBufferOverflow); + } + + + /* Phase 2, obtain a pigui keycode from the keysym */ + + // KeyMappingX11 just translated the X11 keysym to a PIGUI + // keysym, so it works in all platforms the same. + + unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode); + + /* Phase 3, obtain an unicode character from the keysym */ + + // KeyMappingX11 also translates keysym to unicode. + // It does a binary search on a table to translate + // most properly. + //print_line("keysym_unicode: "+rtos(keysym_unicode)); + unsigned int unicode = keysym_unicode>0? KeyMappingX11::get_unicode_from_keysym(keysym_unicode):0; + + + /* Phase 4, determine if event must be filtered */ + + // This seems to be a side-effect of using XIM. + // XEventFilter looks like a core X11 funciton, + // but it's actually just used to see if we must + // ignore a deadkey, or events XIM determines + // must not reach the actual gui. + // Guess it was a design problem of the extension + + bool keypress = xkeyevent->type == KeyPress; + + if (xkeyevent->type == KeyPress && xic) { + if (XFilterEvent((XEvent*)xkeyevent, x11_window)) + return; + } + + if (keycode==0 && unicode==0) + return; + + /* Phase 5, determine modifier mask */ + + // No problems here, except I had no way to + // know Mod1 was ALT and Mod4 was META (applekey/winkey) + // just tried Mods until i found them. + + //print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask)); + + InputModifierState state = get_key_modifier_state(xkeyevent->state); + + /* Phase 6, determine echo character */ + + // Echo characters in X11 are a keyrelease and a keypress + // one after the other with the (almot) same timestamp. + // To detect them, i use XPeekEvent and check that their + // difference in time is below a treshold. + + bool echo=false; + + if (xkeyevent->type == KeyPress) { + + // saved the time of the last keyrelease to see + // if it's the same as this keypress. + if (xkeyevent->time==last_keyrelease_time) + echo=true; + + } else { + + // make sure there are events pending, + // so this call won't block. + if (XPending(x11_display)>0) { + XEvent peek_event; + XPeekEvent(x11_display, &peek_event); + + // I'm using a treshold of 5 msecs, + // since sometimes there seems to be a little + // jitter. I'm still not convinced that all this approach + // is correct, but the xorg developers are + // not very helpful today. + + ::Time tresh=ABS(peek_event.xkey.time-xkeyevent->time); + if (peek_event.type == KeyPress && tresh<5 ) + echo=true; + + // use the time from peek_event so it always works + last_keyrelease_time=peek_event.xkey.time; + } else { + last_keyrelease_time=xkeyevent->time; + } + + // save the time to check for echo when keypress happens + + } + + + /* Phase 7, send event to Window */ + + InputEvent event; + event.ID=++event_id; + event.type = InputEvent::KEY; + event.device=0; + event.key.mod=state; + event.key.pressed=keypress; + + if (keycode>='a' && keycode<='z') + keycode-='a'-'A'; + + event.key.scancode=keycode; + event.key.unicode=unicode; + event.key.echo=echo; + + if (event.key.scancode==KEY_BACKTAB) { + //make it consistent accross platforms. + event.key.scancode=KEY_TAB; + event.key.mod.shift=true; + } + + //printf("key: %x\n",event.key.scancode); + input->parse_input_event( event); + + +} + +void OS_X11::process_xevents() { + + //printf("checking events %i\n", XPending(x11_display)); + + bool do_mouse_warp=false; + + while (XPending(x11_display) > 0) { + XEvent event; + XNextEvent(x11_display, &event); + + switch (event.type) { + case Expose: + Main::force_redraw(); + break; + + case NoExpose: + minimized = true; + break; + + case VisibilityNotify: { + + XVisibilityEvent * visibility = (XVisibilityEvent *)&event; + minimized = (visibility->state == VisibilityFullyObscured); + + } break; + + case FocusIn: + main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); + if (mouse_mode==MOUSE_MODE_CAPTURED) { + XGrabPointer(x11_display, x11_window, True, + ButtonPressMask | ButtonReleaseMask | + PointerMotionMask, GrabModeAsync, GrabModeAsync, + x11_window, None, CurrentTime); + } + break; + + case FocusOut: + main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); + if (mouse_mode==MOUSE_MODE_CAPTURED) { + //dear X11, I try, I really try, but you never work, you do whathever you want. + XUngrabPointer(x11_display, CurrentTime); + } + break; + + case ConfigureNotify: + /* call resizeGLScene only if our window-size changed */ + + if ((event.xconfigure.width == current_videomode.width) && + (event.xconfigure.height == current_videomode.height)) + break; + + current_videomode.width=event.xconfigure.width; + current_videomode.height=event.xconfigure.height; + break; + case ButtonPress: + case ButtonRelease: { + + /* exit in case of a mouse button press */ + last_timestamp=event.xbutton.time; + if (mouse_mode==MOUSE_MODE_CAPTURED) { + event.xbutton.x=last_mouse_pos.x; + event.xbutton.y=last_mouse_pos.y; + } + + InputEvent mouse_event; + mouse_event.ID=++event_id; + mouse_event.type = InputEvent::MOUSE_BUTTON; + mouse_event.device=0; + mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state); + mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state); + mouse_event.mouse_button.x=event.xbutton.x; + mouse_event.mouse_button.y=event.xbutton.y; + mouse_event.mouse_button.global_x=event.xbutton.x; + mouse_event.mouse_button.global_y=event.xbutton.y; + mouse_event.mouse_button.button_index=event.xbutton.button; + if (mouse_event.mouse_button.button_index==2) + mouse_event.mouse_button.button_index=3; + else if (mouse_event.mouse_button.button_index==3) + mouse_event.mouse_button.button_index=2; + + mouse_event.mouse_button.pressed=(event.type==ButtonPress); + + + if (event.type==ButtonPress && event.xbutton.button==1) { + + uint64_t diff = get_ticks_usec()/1000 - last_click_ms; + + if (diff<400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x,event.xbutton.y))<5) { + + last_click_ms=0; + last_click_pos = Point2(-100,-100); + mouse_event.mouse_button.doubleclick=true; + mouse_event.ID=++event_id; + + } else { + last_click_ms+=diff; + last_click_pos = Point2(event.xbutton.x,event.xbutton.y); + } + } + + input->parse_input_event( mouse_event); + + + } break; + case MotionNotify: { + + + last_timestamp=event.xmotion.time; + + // Motion is also simple. + // A little hack is in order + // to be able to send relative motion events. + + Point2i pos( event.xmotion.x, event.xmotion.y ); + + if (mouse_mode==MOUSE_MODE_CAPTURED) { +#if 1 + Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2); + if (pos==Point2i(current_videomode.width/2,current_videomode.height/2)) { + //this sucks, it's a hack, etc and is a little inaccurate, etc. + //but nothing I can do, X11 sucks. + + center=pos; + break; + } + + Point2i ncenter = pos; + pos = last_mouse_pos + ( pos-center ); + center=ncenter; + do_mouse_warp=true; +#else + //Dear X11, thanks for making my life miserable + + center.x = current_videomode.width/2; + center.y = current_videomode.height/2; + pos = last_mouse_pos + ( pos-center ); + if (pos==last_mouse_pos) + break; + XWarpPointer(x11_display, None, x11_window, + 0,0,0,0, (int)center.x, (int)center.y); +#endif + + } + + + if (!last_mouse_pos_valid) { + + last_mouse_pos=pos; + last_mouse_pos_valid=true; + } + + Point2i rel = pos - last_mouse_pos; + + InputEvent motion_event; + motion_event.ID=++event_id; + motion_event.type=InputEvent::MOUSE_MOTION; + motion_event.device=0; + + motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state); + motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state); + motion_event.mouse_motion.x=pos.x; + motion_event.mouse_motion.y=pos.y; + input->set_mouse_pos(pos); + motion_event.mouse_motion.global_x=pos.x; + motion_event.mouse_motion.global_y=pos.y; + motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; + motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; + + motion_event.mouse_motion.relative_x=rel.x; + motion_event.mouse_motion.relative_y=rel.y; + + last_mouse_pos=pos; + + input->parse_input_event( motion_event); + + } break; + case KeyPress: + case KeyRelease: { + + last_timestamp=event.xkey.time; + + // key event is a little complex, so + // it will be handled in it's own function. + handle_key_event( (XKeyEvent*)&event ); + } break; + case SelectionRequest: { + + XSelectionRequestEvent *req; + XEvent e, respond; + e = event; + + req=&(e.xselectionrequest); + if (req->target == XA_STRING || req->target == XInternAtom(x11_display, "COMPOUND_TEXT", 0) || + req->target == XInternAtom(x11_display, "UTF8_STRING", 0)) + { + CharString clip = OS::get_clipboard().utf8(); + XChangeProperty (x11_display, + req->requestor, + req->property, + req->target, + 8, + PropModeReplace, + (unsigned char*)clip.get_data(), + clip.length()); + respond.xselection.property=req->property; + } else if (req->target == XInternAtom(x11_display, "TARGETS", 0)) { + + Atom data[2]; + data[0] = XInternAtom(x11_display, "UTF8_STRING", 0); + data[1] = XA_STRING; + XChangeProperty (x11_display, req->requestor, req->property, req->target, + 8, PropModeReplace, (unsigned char *) &data, + sizeof (data)); + respond.xselection.property=req->property; + + } else { + printf ("No String %x\n", + (int)req->target); + respond.xselection.property= None; + } + respond.xselection.type= SelectionNotify; + respond.xselection.display= req->display; + respond.xselection.requestor= req->requestor; + respond.xselection.selection=req->selection; + respond.xselection.target= req->target; + respond.xselection.time = req->time; + XSendEvent (x11_display, req->requestor,0,0,&respond); + XFlush (x11_display); + } break; + + + case ClientMessage: + + if ((unsigned int)event.xclient.data.l[0]==(unsigned int)wm_delete) + main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); + break; + default: + break; + } + } + + XFlush(x11_display); + + if (do_mouse_warp) { + + XWarpPointer(x11_display, None, x11_window, + 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); + + } +} + +MainLoop *OS_X11::get_main_loop() const { + + return main_loop; +} + +void OS_X11::delete_main_loop() { + + if (main_loop) + memdelete(main_loop); + main_loop=NULL; +} + +void OS_X11::set_main_loop( MainLoop * p_main_loop ) { + + main_loop=p_main_loop; + input->set_main_loop(p_main_loop); +} + +bool OS_X11::can_draw() const { + + return !minimized; +}; + +void OS_X11::set_clipboard(const String& p_text) { + + OS::set_clipboard(p_text); + + XSetSelectionOwner(x11_display, XA_PRIMARY, x11_window, CurrentTime); + XSetSelectionOwner(x11_display, XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, CurrentTime); +}; + +static String _get_clipboard(Atom p_source, Window x11_window, ::Display* x11_display, String p_internal_clipboard) { + + String ret; + + Atom type; + Atom selection = XA_PRIMARY; + int format, result; + unsigned long len, bytes_left, dummy; + unsigned char *data; + Window Sown = XGetSelectionOwner (x11_display, p_source); + + if (Sown == x11_window) { + + printf("returning internal clipboard\n"); + return p_internal_clipboard; + }; + + if (Sown != None) { + XConvertSelection (x11_display, p_source, XA_STRING, selection, + x11_window, CurrentTime); + XFlush (x11_display); + while (true) { + XEvent event; + XNextEvent(x11_display, &event); + if (event.type == SelectionNotify && event.xselection.requestor == x11_window) { + break; + }; + }; + + // + // Do not get any data, see how much data is there + // + XGetWindowProperty (x11_display, x11_window, + selection, // Tricky.. + 0, 0, // offset - len + 0, // Delete 0==FALSE + AnyPropertyType, //flag + &type, // return type + &format, // return format + &len, &bytes_left, //that + &data); + // DATA is There + if (bytes_left > 0) + { + result = XGetWindowProperty (x11_display, x11_window, + selection, 0,bytes_left,0, + AnyPropertyType, &type,&format, + &len, &dummy, &data); + if (result == Success) { + ret.parse_utf8((const char*)data); + } else printf ("FAIL\n"); + XFree (data); + } + } + + return ret; + +}; + +String OS_X11::get_clipboard() const { + + String ret; + ret = _get_clipboard(XInternAtom(x11_display, "CLIPBOARD", 0), x11_window, x11_display, OS::get_clipboard()); + + if (ret == "") { + ret = _get_clipboard(XA_PRIMARY, x11_window, x11_display, OS::get_clipboard()); + }; + + return ret; +}; + +String OS_X11::get_name() { + + return "X11"; +} + + +void OS_X11::close_joystick(int p_id) { + + if (p_id == -1) { + for (int i=0; i<JOYSTICKS_MAX; i++) { + + close_joystick(i); + }; + return; + }; + + + if (joysticks[p_id].fd != -1) { + close(joysticks[p_id].fd); + joysticks[p_id].fd = -1; + }; +}; + +void OS_X11::probe_joystick(int p_id) { + + if (p_id == -1) { + + for (int i=0; i<JOYSTICKS_MAX; i++) { + + probe_joystick(i); + }; + return; + }; + + close_joystick(p_id); + + const char *joy_names[] = { + "/dev/input/js%d", + "/dev/js%d", + NULL + }; + + int i=0; + while(joy_names[i]) { + + char fname[64]; + sprintf(fname, joy_names[i], p_id); + int fd = open(fname, O_RDONLY); + if (fd != -1) { + + fcntl( fd, F_SETFL, O_NONBLOCK ); + joysticks[p_id] = Joystick(); // this will reset the axis array + joysticks[p_id].fd = fd; + break; // don't try the next name + }; + + ++i; + }; +}; + +void OS_X11::move_window_to_foreground() { + + XRaiseWindow(x11_display,x11_window); +} + +void OS_X11::process_joysticks() { + + int bytes; + js_event events[32]; + InputEvent ievent; + for (int i=0; i<JOYSTICKS_MAX; i++) { + + if (joysticks[i].fd == -1) + continue; + ievent.device = i; + + while ( (bytes = read(joysticks[i].fd, &events, sizeof(events))) > 0) { + + int ev_count = bytes / sizeof(js_event); + for (int j=0; j<ev_count; j++) { + + js_event& event = events[j]; + + //printf("got event on joystick %i, %i, %i, %i, %i\n", i, joysticks[i].fd, event.type, event.number, event.value); + if (event.type & JS_EVENT_INIT) + continue; + + switch (event.type & ~JS_EVENT_INIT) { + + case JS_EVENT_AXIS: + + if (joysticks[i].last_axis[event.number] != event.value) { + + if (event.number==5 || event.number==6) { + + int axis=event.number-5; + int val = event.value; + if (val<0) + val=-1; + if (val>0) + val=+1; + + InputEvent ev; + ev.type = InputEvent::JOYSTICK_BUTTON; + ev.ID = ++event_id; + + + if (val!=dpad_last[axis]) { + + int prev_val = dpad_last[axis]; + if (prev_val!=0) { + + ev.joy_button.pressed=false; + ev.joy_button.pressure=0.0; + if (event.number==5) + ev.joy_button.button_index=JOY_DPAD_LEFT+(prev_val+1)/2; + if (event.number==6) + ev.joy_button.button_index=JOY_DPAD_UP+(prev_val+1)/2; + + input->parse_input_event( ev ); + } + } + + if (val!=0) { + + ev.joy_button.pressed=true; + ev.joy_button.pressure=1.0; + if (event.number==5) + ev.joy_button.button_index=JOY_DPAD_LEFT+(val+1)/2; + if (event.number==6) + ev.joy_button.button_index=JOY_DPAD_UP+(val+1)/2; + + input->parse_input_event( ev ); + } + + + dpad_last[axis]=val; + + } + //print_line("ev: "+itos(event.number)+" val: "+ rtos((float)event.value / (float)MAX_JOY_AXIS)); + if (event.number >= JOY_AXIS_MAX) + break; + //ERR_FAIL_COND(event.number >= JOY_AXIS_MAX); + ievent.type = InputEvent::JOYSTICK_MOTION; + ievent.ID = ++event_id; + ievent.joy_motion.axis = _pc_joystick_get_native_axis(event.number); + ievent.joy_motion.axis_value = (float)event.value / (float)MAX_JOY_AXIS; + joysticks[i].last_axis[event.number] = event.value; + input->parse_input_event( ievent ); + }; + break; + + case JS_EVENT_BUTTON: + + + ievent.type = InputEvent::JOYSTICK_BUTTON; + ievent.ID = ++event_id; + ievent.joy_button.button_index = _pc_joystick_get_native_button(event.number); + ievent.joy_button.pressed = event.value; + input->parse_input_event( ievent ); + break; + }; + }; + }; + }; +}; + +void OS_X11::set_cursor_shape(CursorShape p_shape) { + + ERR_FAIL_INDEX(p_shape,CURSOR_MAX); + + if (p_shape==current_cursor) + return; + if (mouse_mode==MOUSE_MODE_VISIBLE) { + if (cursors[p_shape]!=None) + XDefineCursor(x11_display,x11_window,cursors[p_shape]); + else if (cursors[CURSOR_ARROW]!=None) + XDefineCursor(x11_display,x11_window,cursors[CURSOR_ARROW]); + } + + + current_cursor=p_shape; +} + + +void OS_X11::release_rendering_thread() { + + context_gl->release_current(); + +} + +void OS_X11::make_rendering_thread() { + + context_gl->make_current(); +} + +void OS_X11::swap_buffers() { + + context_gl->swap_buffers(); +} + + +void OS_X11::set_icon(const Image& p_icon) { + + //does not work, if anyone knows why, please fix + if (!p_icon.empty()) { + + Image img=p_icon; + img.convert(Image::FORMAT_RGBA); + + + int w = img.get_width(); + int h = img.get_height(); + + Vector<long> pd; + + pd.resize((2+w*h)*sizeof(long)); + + print_line("***** SET ICON ***** "+itos(w)+" "+itos(h)); + + pd[0]=w; + pd[1]=h; + + DVector<uint8_t>::Read r = img.get_data().read(); + + uint32_t *wr=(uint32_t*)&pd[2]; + + for(int i=0;i<w*h;i++) { + + uint32_t v=0; + v|=r[i*4+3]; + v<<=8; + v|=r[i*4+0]; + v<<=8; + v|=r[i*4+1]; + v<<=8; + v|=r[i*4+2]; + wr[i]=v; + } + + XChangeProperty(x11_display, x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) pd.ptr(), + (2+w*h)); + } else { + XDeleteProperty(x11_display, x11_window, net_wm_icon); + } + XFlush(x11_display); + +} + + +void OS_X11::run() { + + force_quit = false; + + if (!main_loop) + return; + + main_loop->init(); + +// uint64_t last_ticks=get_ticks_usec(); + +// int frames=0; +// uint64_t frame=0; + + while (!force_quit) { + + process_xevents(); // get rid of pending events + process_joysticks(); + if (Main::iteration()==true) + break; + }; + + main_loop->finish(); +} + +OS_X11::OS_X11() { + +#ifdef RTAUDIO_ENABLED + AudioDriverManagerSW::add_driver(&driver_rtaudio); +#endif + +#ifdef ALSA_ENABLED + AudioDriverManagerSW::add_driver(&driver_alsa); +#endif + + minimized = false; + xim_style=NULL; + mouse_mode=MOUSE_MODE_VISIBLE; + + +}; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h new file mode 100644 index 000000000..ee50bdea4 --- /dev/null +++ b/platform/x11/os_x11.h @@ -0,0 +1,203 @@ +/*************************************************************************/ +/* os_x11.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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. */ +/*************************************************************************/ +#ifndef OS_X11_H +#define OS_X11_H + + +#include "os/input.h" +#include "drivers/unix/os_unix.h" +#include "context_gl_x11.h" +#include "servers/visual_server.h" +#include "servers/visual/visual_server_wrap_mt.h" +#include "servers/visual/rasterizer.h" +#include "servers/physics_server.h" +#include "servers/audio/audio_server_sw.h" +#include "servers/audio/sample_manager_sw.h" +#include "servers/spatial_sound/spatial_sound_server_sw.h" +#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "drivers/rtaudio/audio_driver_rtaudio.h" +#include "drivers/alsa/audio_driver_alsa.h" +#include "servers/physics_2d/physics_2d_server_sw.h" + +#include <X11/keysym.h> +#include <X11/Xlib.h> +#include <X11/Xcursor/Xcursor.h> + +//bitch +#undef CursorShape +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ + +class OS_X11 : public OS_Unix { + + Atom wm_delete; +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + ContextGL_X11 *context_gl; +#endif + Rasterizer *rasterizer; + VisualServer *visual_server; + VideoMode current_videomode; + List<String> args; + Window x11_window; + MainLoop *main_loop; + ::Display* x11_display; + char *xmbstring; + int xmblen; + unsigned long last_timestamp; + ::Time last_keyrelease_time; + ::XIC xic; + ::XIM xim; + ::XIMStyle xim_style; + Point2i last_mouse_pos; + bool last_mouse_pos_valid; + Point2i last_click_pos; + uint64_t last_click_ms; + unsigned int event_id; + uint32_t last_button_state; + + PhysicsServer *physics_server; + unsigned int get_mouse_button_state(unsigned int p_x11_state); + InputModifierState get_key_modifier_state(unsigned int p_x11_state); + Physics2DServer *physics_2d_server; + + MouseMode mouse_mode; + Point2i center; + + void handle_key_event(XKeyEvent *p_event); + void process_xevents(); + virtual void delete_main_loop(); + IP_Unix *ip_unix; + + AudioServerSW *audio_server; + SampleManagerMallocSW *sample_manager; + SpatialSoundServerSW *spatial_sound_server; + SpatialSound2DServerSW *spatial_sound_2d_server; + + bool force_quit; + bool minimized; + int dpad_last[2]; + + + const char *cursor_theme; + int cursor_size; + Cursor cursors[CURSOR_MAX]; + Cursor null_cursor; + CursorShape current_cursor; + + InputDefault *input; + +#ifdef RTAUDIO_ENABLED + AudioDriverRtAudio driver_rtaudio; +#endif + +#ifdef ALSA_ENABLED + AudioDriverALSA driver_alsa; +#endif + + enum { + JOYSTICKS_MAX = 8, + MAX_JOY_AXIS = 32768, // I've no idea + }; + + struct Joystick { + + int fd; + int last_axis[JOY_AXIS_MAX]; + + Joystick() { + fd = -1; + for (int i=0; i<JOY_AXIS_MAX; i++) { + + last_axis[i] = 0; + }; + }; + }; + + Atom net_wm_icon; + + + int joystick_count; + Joystick joysticks[JOYSTICKS_MAX]; + + +protected: + + virtual int get_video_driver_count() const; + virtual const char * get_video_driver_name(int p_driver) const; + virtual VideoMode get_default_video_mode() const; + + virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + virtual void finalize(); + + virtual void set_main_loop( MainLoop * p_main_loop ); + + void probe_joystick(int p_id = -1); + void process_joysticks(); + void close_joystick(int p_id = -1); + +public: + + virtual String get_name(); + + virtual void set_cursor_shape(CursorShape p_shape); + + void set_mouse_mode(MouseMode p_mode); + MouseMode get_mouse_mode() const; + + virtual Point2 get_mouse_pos() const; + virtual int get_mouse_button_state() const; + virtual void set_window_title(const String& p_title); + + virtual void set_icon(const Image& p_icon); + + virtual MainLoop *get_main_loop() const; + + virtual bool can_draw() const; + + virtual void set_clipboard(const String& p_text); + virtual String get_clipboard() const; + + virtual void release_rendering_thread(); + virtual void make_rendering_thread(); + virtual void swap_buffers(); + + + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); + virtual VideoMode get_video_mode(int p_screen=0) const; + virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; + + virtual void move_window_to_foreground(); + + void run(); + + OS_X11(); +}; + +#endif diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h new file mode 100644 index 000000000..d14f3e3f9 --- /dev/null +++ b/platform/x11/platform_config.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* platform_config.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 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 <alloca.h> +#define GLES2_INCLUDE_H "gl_context/glew.h" +#define GLES1_INCLUDE_H "gl_context/glew.h" + |
