diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index dc81c38b68f..ae21c095435 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -435,6 +435,7 @@ String _OS::get_latin_keyboard_variant() const { case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY"; case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK"; case OS::LATIN_KEYBOARD_NEO: return "NEO"; + case OS::LATIN_KEYBOARD_COLEMAK: return "COLEMAK"; default: return "ERROR"; } } diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 17f3bd10ab3..0f4414d9661 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -507,6 +507,27 @@ static const _KeyCodeReplace _keycode_replace_neo[] = { { 0, 0 } }; +static const _KeyCodeReplace _keycode_replace_colemak[] = { + { KEY_E, KEY_F }, + { KEY_R, KEY_P }, + { KEY_T, KEY_G }, + { KEY_Y, KEY_J }, + { KEY_U, KEY_L }, + { KEY_I, KEY_U }, + { KEY_O, KEY_Y }, + { KEY_P, KEY_SEMICOLON }, + { KEY_S, KEY_R }, + { KEY_D, KEY_S }, + { KEY_F, KEY_T }, + { KEY_G, KEY_D }, + { KEY_J, KEY_N }, + { KEY_K, KEY_E }, + { KEY_L, KEY_I }, + { KEY_SEMICOLON, KEY_O }, + { KEY_N, KEY_K }, + { 0, 0 } +}; + int latin_keyboard_keycode_convert(int p_keycode) { const _KeyCodeReplace *kcr = NULL; diff --git a/core/os/os.h b/core/os/os.h index 07f9c2ef3f6..157ae125e70 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -314,8 +314,8 @@ public: virtual void hide_virtual_keyboard(); virtual void set_cursor_shape(CursorShape p_shape) = 0; - virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) = 0; - + virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) = 0; + virtual bool get_swap_ok_cancel() { return false; } virtual void dump_memory_to_file(const char *p_file); virtual void dump_resources_to_file(const char *p_file); @@ -405,6 +405,7 @@ public: LATIN_KEYBOARD_QZERTY, LATIN_KEYBOARD_DVORAK, LATIN_KEYBOARD_NEO, + LATIN_KEYBOARD_COLEMAK, }; virtual LatinKeyboardVariant get_latin_keyboard_variant() const; diff --git a/doc/base/classes.xml b/doc/base/classes.xml index e9290179d3b..cb6c75bd48a 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -23422,7 +23422,7 @@ Returns the current latin keyboard variant as a String. - Possible return values are: "QWERTY", "AZERTY", "QZERTY", "DVORAK", "NEO" or "ERROR" + Possible return values are: "QWERTY", "AZERTY", "QZERTY", "DVORAK", "NEO", "COLEMAK" or "ERROR" diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 3a21fe03799..4d01a63e9a6 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -34,11 +34,11 @@ #include "main/main.h" #include "os/keyboard.h" #include "print_string.h" +#include "scene/resources/texture.h" #include "sem_osx.h" #include "servers/physics/physics_server_sw.h" #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" -#include "scene/resources/texture.h" #include #import @@ -502,9 +502,10 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) { if (OS_OSX::singleton->main_loop && OS_OSX::singleton->mouse_mode != OS::MOUSE_MODE_CAPTURED) OS_OSX::singleton->main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER); - if (OS_OSX::singleton->input) + if (OS_OSX::singleton->input) { OS_OSX::singleton->cursor_shape = OS::CURSOR_MAX; OS_OSX::singleton->set_cursor_shape(OS::CURSOR_ARROW); + } } - (void)viewDidChangeBackingProperties { @@ -1193,7 +1194,7 @@ void OS_OSX::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot){ +void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { if (p_cursor.is_valid()) { Ref texture = p_cursor; Image image = texture->get_data(); @@ -1203,16 +1204,16 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c ERR_FAIL_COND(texture->get_width() != 32 || texture->get_height() != 32); NSBitmapImageRep *imgrep = [[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes:NULL - pixelsWide:image.get_width() - pixelsHigh:image.get_height() - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:image.get_width() * 4 - bitsPerPixel:32] autorelease]; + initWithBitmapDataPlanes:NULL + pixelsWide:image.get_width() + pixelsHigh:image.get_height() + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:image.get_width() * 4 + bitsPerPixel:32] autorelease]; ERR_FAIL_COND(imgrep == nil); uint8_t *pixels = [imgrep bitmapData]; @@ -1229,10 +1230,10 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c pixels[i * 4 + 3] = alpha; } - NSImage * nsimage = [[[NSImage alloc] initWithSize: NSMakeSize(image.get_width(), image.get_height())] autorelease]; - [nsimage addRepresentation: imgrep]; - - NSCursor *cursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(p_hotspot.x, p_hotspot.y)]; + NSImage *nsimage = [[[NSImage alloc] initWithSize:NSMakeSize(image.get_width(), image.get_height())] autorelease]; + [nsimage addRepresentation:imgrep]; + + NSCursor *cursor = [[NSCursor alloc] initWithImage:nsimage hotSpot:NSMakePoint(p_hotspot.x, p_hotspot.y)]; cursors[p_shape] = cursor; @@ -1816,6 +1817,8 @@ OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const { layout = LATIN_KEYBOARD_DVORAK; } else if ([test isEqualToString:@"xvlcwk"]) { layout = LATIN_KEYBOARD_NEO; + } else if ([test isEqualToString:@"qwfpgj"]) { + layout = LATIN_KEYBOARD_COLEMAK; } [test release]; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d68a9154c55..bc2e75c3a76 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -68,6 +68,8 @@ #undef CursorShape +#include + int OS_X11::get_video_driver_count() const { return 1; } @@ -2201,6 +2203,38 @@ void OS_X11::set_context(int p_context) { } } +OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const { + + XkbDescRec *xkbdesc = XkbAllocKeyboard(); + ERR_FAIL_COND_V(!xkbdesc, LATIN_KEYBOARD_QWERTY); + + XkbGetNames(x11_display, XkbSymbolsNameMask, xkbdesc); + ERR_FAIL_COND_V(!xkbdesc->names, LATIN_KEYBOARD_QWERTY); + ERR_FAIL_COND_V(!xkbdesc->names->symbols, LATIN_KEYBOARD_QWERTY); + + char *layout = XGetAtomName(x11_display, xkbdesc->names->symbols); + ERR_FAIL_COND_V(!layout, LATIN_KEYBOARD_QWERTY); + + Vector info = String(layout).split("+"); + ERR_FAIL_INDEX_V(1, info.size(), LATIN_KEYBOARD_QWERTY); + + if (info[1].find("colemak") != -1) { + return LATIN_KEYBOARD_COLEMAK; + } else if (info[1].find("qwertz") != -1) { + return LATIN_KEYBOARD_QWERTZ; + } else if (info[1].find("azerty") != -1) { + return LATIN_KEYBOARD_AZERTY; + } else if (info[1].find("qzerty") != -1) { + return LATIN_KEYBOARD_QZERTY; + } else if (info[1].find("dvorak") != -1) { + return LATIN_KEYBOARD_DVORAK; + } else if (info[1].find("neo") != -1) { + return LATIN_KEYBOARD_NEO; + } + + return LATIN_KEYBOARD_QWERTY; +} + OS_X11::OS_X11() { #ifdef RTAUDIO_ENABLED diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index e52a39e5960..26e9552870b 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -285,6 +285,8 @@ public: void disable_crash_handler(); bool is_disable_crash_handler() const; + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + OS_X11(); };