Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
92352b1c
Unverified
Commit
92352b1c
authored
Jun 11, 2020
by
bruvzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add keyboard layout enumeration / set / get functions (macOS, Windows,…
Add keyboard layout enumeration / set / get functions (macOS, Windows, Linux/X11), remove latin variant function.
parent
84abf5a9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
363 additions
and
179 deletions
+363
-179
DisplayServer.xml
doc/classes/DisplayServer.xml
+46
-20
display_server_x11.cpp
platform/linuxbsd/display_server_x11.cpp
+94
-25
display_server_x11.h
platform/linuxbsd/display_server_x11.h
+5
-1
display_server_osx.h
platform/osx/display_server_osx.h
+5
-1
display_server_osx.mm
platform/osx/display_server_osx.mm
+98
-54
display_server_windows.cpp
platform/windows/display_server_windows.cpp
+83
-54
display_server_windows.h
platform/windows/display_server_windows.h
+5
-1
display_server.cpp
servers/display_server.cpp
+22
-11
display_server.h
servers/display_server.h
+5
-12
No files found.
doc/classes/DisplayServer.xml
View file @
92352b1c
...
@@ -127,12 +127,6 @@
...
@@ -127,12 +127,6 @@
<description>
<description>
</description>
</description>
</method>
</method>
<method
name=
"get_latin_keyboard_variant"
qualifiers=
"const"
>
<return
type=
"int"
enum=
"DisplayServer.LatinKeyboardVariant"
>
</return>
<description>
</description>
</method>
<method
name=
"get_name"
qualifiers=
"const"
>
<method
name=
"get_name"
qualifiers=
"const"
>
<return
type=
"String"
>
<return
type=
"String"
>
</return>
</return>
...
@@ -389,6 +383,52 @@
...
@@ -389,6 +383,52 @@
<description>
<description>
</description>
</description>
</method>
</method>
<method
name=
"keyboard_get_current_layout"
qualifiers=
"const"
>
<return
type=
"int"
>
</return>
<description>
Returns active keyboard layout index.
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method
name=
"keyboard_get_layout_count"
qualifiers=
"const"
>
<return
type=
"int"
>
</return>
<description>
Returns the number of keyboard layouts.
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method
name=
"keyboard_get_layout_language"
qualifiers=
"const"
>
<return
type=
"String"
>
</return>
<argument
index=
"0"
name=
"index"
type=
"int"
>
</argument>
<description>
Returns the ISO-639/BCP-47 language code of the keyboard layout at position [code]index[/code].
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method
name=
"keyboard_get_layout_name"
qualifiers=
"const"
>
<return
type=
"String"
>
</return>
<argument
index=
"0"
name=
"index"
type=
"int"
>
</argument>
<description>
Returns the localized name of the keyboard layout at position [code]index[/code].
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method
name=
"keyboard_set_current_layout"
>
<return
type=
"void"
>
</return>
<argument
index=
"0"
name=
"index"
type=
"int"
>
</argument>
<description>
Sets active keyboard layout.
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method
name=
"mouse_get_absolute_position"
qualifiers=
"const"
>
<method
name=
"mouse_get_absolute_position"
qualifiers=
"const"
>
<return
type=
"Vector2i"
>
<return
type=
"Vector2i"
>
</return>
</return>
...
@@ -1021,20 +1061,6 @@
...
@@ -1021,20 +1061,6 @@
</constant>
</constant>
<constant
name=
"WINDOW_FLAG_MAX"
value=
"5"
enum=
"WindowFlags"
>
<constant
name=
"WINDOW_FLAG_MAX"
value=
"5"
enum=
"WindowFlags"
>
</constant>
</constant>
<constant
name=
"LATIN_KEYBOARD_QWERTY"
value=
"0"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_QWERTZ"
value=
"1"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_AZERTY"
value=
"2"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_QZERTY"
value=
"3"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_DVORAK"
value=
"4"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_NEO"
value=
"5"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"LATIN_KEYBOARD_COLEMAK"
value=
"6"
enum=
"LatinKeyboardVariant"
>
</constant>
<constant
name=
"WINDOW_EVENT_MOUSE_ENTER"
value=
"0"
enum=
"WindowEvent"
>
<constant
name=
"WINDOW_EVENT_MOUSE_ENTER"
value=
"0"
enum=
"WindowEvent"
>
</constant>
</constant>
<constant
name=
"WINDOW_EVENT_MOUSE_EXIT"
value=
"1"
enum=
"WindowEvent"
>
<constant
name=
"WINDOW_EVENT_MOUSE_EXIT"
value=
"1"
enum=
"WindowEvent"
>
...
...
platform/linuxbsd/display_server_x11.cpp
View file @
92352b1c
...
@@ -1846,37 +1846,106 @@ void DisplayServerX11::cursor_set_custom_image(const RES &p_cursor, CursorShape
...
@@ -1846,37 +1846,106 @@ void DisplayServerX11::cursor_set_custom_image(const RES &p_cursor, CursorShape
}
}
}
}
DisplayServerX11
::
LatinKeyboardVariant
DisplayServerX11
::
get_latin_keyboard_variant
()
const
{
int
DisplayServerX11
::
keyboard_get_layout_count
()
const
{
_THREAD_SAFE_METHOD_
int
_group_count
=
0
;
XkbDescRec
*
kbd
=
XkbAllocKeyboard
();
XkbDescRec
*
xkbdesc
=
XkbAllocKeyboard
();
if
(
kbd
)
{
ERR_FAIL_COND_V
(
!
xkbdesc
,
LATIN_KEYBOARD_QWERTY
);
kbd
->
dpy
=
x11_display
;
XkbGetControls
(
x11_display
,
XkbAllControlsMask
,
kbd
);
XkbGetNames
(
x11_display
,
XkbSymbolsNameMask
,
kbd
);
const
Atom
*
groups
=
kbd
->
names
->
groups
;
if
(
kbd
->
ctrls
!=
NULL
)
{
_group_count
=
kbd
->
ctrls
->
num_groups
;
}
else
{
while
(
_group_count
<
XkbNumKbdGroups
&&
groups
[
_group_count
]
!=
None
)
{
_group_count
++
;
}
}
XkbFreeKeyboard
(
kbd
,
0
,
true
);
}
return
_group_count
;
}
XkbGetNames
(
x11_display
,
XkbSymbolsNameMask
,
xkbdesc
);
int
DisplayServerX11
::
keyboard_get_current_layout
()
const
{
ERR_FAIL_COND_V
(
!
xkbdesc
->
names
,
LATIN_KEYBOARD_QWERTY
);
XkbStateRec
state
;
ERR_FAIL_COND_V
(
!
xkbdesc
->
names
->
symbols
,
LATIN_KEYBOARD_QWERTY
);
XkbGetState
(
x11_display
,
XkbUseCoreKbd
,
&
state
);
return
state
.
group
;
}
char
*
layout
=
XGetAtomName
(
x11_display
,
xkbdesc
->
names
->
symbols
);
void
DisplayServerX11
::
keyboard_set_current_layout
(
int
p_index
)
{
ERR_FAIL_COND_V
(
!
layout
,
LATIN_KEYBOARD_QWERTY
);
ERR_FAIL_INDEX
(
p_index
,
keyboard_get_layout_count
());
XkbLockGroup
(
x11_display
,
XkbUseCoreKbd
,
p_index
);
}
Vector
<
String
>
info
=
String
(
layout
).
split
(
"+"
);
String
DisplayServerX11
::
keyboard_get_layout_language
(
int
p_index
)
const
{
ERR_FAIL_INDEX_V
(
1
,
info
.
size
(),
LATIN_KEYBOARD_QWERTY
);
String
ret
;
XkbDescRec
*
kbd
=
XkbAllocKeyboard
();
if
(
kbd
)
{
kbd
->
dpy
=
x11_display
;
XkbGetControls
(
x11_display
,
XkbAllControlsMask
,
kbd
);
XkbGetNames
(
x11_display
,
XkbSymbolsNameMask
,
kbd
);
XkbGetNames
(
x11_display
,
XkbGroupNamesMask
,
kbd
);
int
_group_count
=
0
;
const
Atom
*
groups
=
kbd
->
names
->
groups
;
if
(
kbd
->
ctrls
!=
NULL
)
{
_group_count
=
kbd
->
ctrls
->
num_groups
;
}
else
{
while
(
_group_count
<
XkbNumKbdGroups
&&
groups
[
_group_count
]
!=
None
)
{
_group_count
++
;
}
}
if
(
info
[
1
].
find
(
"colemak"
)
!=
-
1
)
{
Atom
names
=
kbd
->
names
->
symbols
;
return
LATIN_KEYBOARD_COLEMAK
;
if
(
names
!=
None
)
{
}
else
if
(
info
[
1
].
find
(
"qwertz"
)
!=
-
1
)
{
char
*
name
=
XGetAtomName
(
x11_display
,
names
);
return
LATIN_KEYBOARD_QWERTZ
;
Vector
<
String
>
info
=
String
(
name
).
split
(
"+"
);
}
else
if
(
info
[
1
].
find
(
"azerty"
)
!=
-
1
)
{
if
(
p_index
>=
0
&&
p_index
<
_group_count
)
{
return
LATIN_KEYBOARD_AZERTY
;
if
(
p_index
+
1
<
info
.
size
())
{
}
else
if
(
info
[
1
].
find
(
"qzerty"
)
!=
-
1
)
{
ret
=
info
[
p_index
+
1
];
// Skip "pc" at the start and "inet"/"group" at the end of symbols.
return
LATIN_KEYBOARD_QZERTY
;
}
else
{
}
else
if
(
info
[
1
].
find
(
"dvorak"
)
!=
-
1
)
{
ret
=
"en"
;
// No symbol for layout fallback to "en".
return
LATIN_KEYBOARD_DVORAK
;
}
}
else
if
(
info
[
1
].
find
(
"neo"
)
!=
-
1
)
{
}
else
{
return
LATIN_KEYBOARD_NEO
;
ERR_PRINT
(
"Index "
+
itos
(
p_index
)
+
"is out of bounds ("
+
itos
(
_group_count
)
+
")."
);
}
XFree
(
name
);
}
XkbFreeKeyboard
(
kbd
,
0
,
true
);
}
}
return
ret
.
substr
(
0
,
2
);
}
String
DisplayServerX11
::
keyboard_get_layout_name
(
int
p_index
)
const
{
String
ret
;
XkbDescRec
*
kbd
=
XkbAllocKeyboard
();
if
(
kbd
)
{
kbd
->
dpy
=
x11_display
;
XkbGetControls
(
x11_display
,
XkbAllControlsMask
,
kbd
);
XkbGetNames
(
x11_display
,
XkbSymbolsNameMask
,
kbd
);
XkbGetNames
(
x11_display
,
XkbGroupNamesMask
,
kbd
);
int
_group_count
=
0
;
const
Atom
*
groups
=
kbd
->
names
->
groups
;
if
(
kbd
->
ctrls
!=
NULL
)
{
_group_count
=
kbd
->
ctrls
->
num_groups
;
}
else
{
while
(
_group_count
<
XkbNumKbdGroups
&&
groups
[
_group_count
]
!=
None
)
{
_group_count
++
;
}
}
return
LATIN_KEYBOARD_QWERTY
;
if
(
p_index
>=
0
&&
p_index
<
_group_count
)
{
char
*
full_name
=
XGetAtomName
(
x11_display
,
groups
[
p_index
]);
ret
.
parse_utf8
(
full_name
);
XFree
(
full_name
);
}
else
{
ERR_PRINT
(
"Index "
+
itos
(
p_index
)
+
"is out of bounds ("
+
itos
(
_group_count
)
+
")."
);
}
XkbFreeKeyboard
(
kbd
,
0
,
true
);
}
return
ret
;
}
}
DisplayServerX11
::
Property
DisplayServerX11
::
_read_property
(
Display
*
p_display
,
Window
p_window
,
Atom
p_property
)
{
DisplayServerX11
::
Property
DisplayServerX11
::
_read_property
(
Display
*
p_display
,
Window
p_window
,
Atom
p_property
)
{
...
...
platform/linuxbsd/display_server_x11.h
View file @
92352b1c
...
@@ -327,7 +327,11 @@ public:
...
@@ -327,7 +327,11 @@ public:
virtual
CursorShape
cursor_get_shape
()
const
;
virtual
CursorShape
cursor_get_shape
()
const
;
virtual
void
cursor_set_custom_image
(
const
RES
&
p_cursor
,
CursorShape
p_shape
,
const
Vector2
&
p_hotspot
);
virtual
void
cursor_set_custom_image
(
const
RES
&
p_cursor
,
CursorShape
p_shape
,
const
Vector2
&
p_hotspot
);
virtual
LatinKeyboardVariant
get_latin_keyboard_variant
()
const
;
virtual
int
keyboard_get_layout_count
()
const
;
virtual
int
keyboard_get_current_layout
()
const
;
virtual
void
keyboard_set_current_layout
(
int
p_index
);
virtual
String
keyboard_get_layout_language
(
int
p_index
)
const
;
virtual
String
keyboard_get_layout_name
(
int
p_index
)
const
;
virtual
void
process_events
();
virtual
void
process_events
();
...
...
platform/osx/display_server_osx.h
View file @
92352b1c
...
@@ -281,7 +281,11 @@ public:
...
@@ -281,7 +281,11 @@ public:
virtual
bool
get_swap_ok_cancel
();
virtual
bool
get_swap_ok_cancel
();
virtual
LatinKeyboardVariant
get_latin_keyboard_variant
()
const
;
virtual
int
keyboard_get_layout_count
()
const
;
virtual
int
keyboard_get_current_layout
()
const
;
virtual
void
keyboard_set_current_layout
(
int
p_index
);
virtual
String
keyboard_get_layout_language
(
int
p_index
)
const
;
virtual
String
keyboard_get_layout_name
(
int
p_index
)
const
;
virtual
void
process_events
();
virtual
void
process_events
();
virtual
void
force_process_and_drop_events
();
virtual
void
force_process_and_drop_events
();
...
...
platform/osx/display_server_osx.mm
View file @
92352b1c
...
@@ -2987,85 +2987,129 @@ void DisplayServerOSX::cursor_set_custom_image(const RES &p_cursor, CursorShape
...
@@ -2987,85 +2987,129 @@ void DisplayServerOSX::cursor_set_custom_image(const RES &p_cursor, CursorShape
}
}
}
}
struct LayoutInfo {
String name;
String code;
};
static Vector<LayoutInfo> kbd_layouts;
static int current_layout = 0;
static bool keyboard_layout_dirty = true;
static bool keyboard_layout_dirty = true;
static void keyboard_layout_changed(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef user_info) {
static void keyboard_layout_changed(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef user_info) {
kbd_layouts.clear();
current_layout = 0;
keyboard_layout_dirty = true;
keyboard_layout_dirty = true;
}
}
// Returns string representation of keys, if they are printable.
void _update_keyboard_layouts() {
static NSString *createStringForKeys(const CGKeyCode *keyCode, int length)
{
@autoreleasepool
{
TISInputSourceRef currentKeyboard
= TISCopyCurrentKeyboardInputSource();
TISInputSourceRef cur_source
= TISCopyCurrentKeyboardInputSource();
if (!currentKeyboard)
NSString *cur_name = (NSString *)TISGetInputSourceProperty(cur_source, kTISPropertyLocalizedName);
return nil
;
CFRelease(cur_source)
;
CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
// Enum IME layouts
if (!layoutData)
NSDictionary *filter_ime = @{ (NSString *)kTISPropertyInputSourceType : (NSString *)kTISTypeKeyboardInputMode };
return nil;
NSArray *list_ime = (NSArray *)TISCreateInputSourceList((CFDictionaryRef)filter_ime, false);
for (NSUInteger i = 0; i < [list_ime count]; i++) {
LayoutInfo ly;
NSString *name = (NSString *)TISGetInputSourceProperty((TISInputSourceRef)[list_ime objectAtIndex:i], kTISPropertyLocalizedName);
ly.name.parse_utf8([name UTF8String]);
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
NSArray *langs = (NSArray *)TISGetInputSourceProperty((TISInputSourceRef)[list_ime objectAtIndex:i], kTISPropertyInputSourceLanguages);
ly.code.parse_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
kbd_layouts.push_back(ly);
OSStatus err;
if ([name isEqualToString:cur_name]) {
CFMutableStringRef output = CFStringCreateMutable(NULL, 0);
current_layout = kbd_layouts.size() - 1;
}
}
[list_ime release];
for (int i = 0; i < length; ++i) {
// Enum plain keyboard layouts
UInt32 keysDown = 0;
NSDictionary *filter_kbd = @{ (NSString *)kTISPropertyInputSourceType : (NSString *)kTISTypeKeyboardLayout };
UniChar chars[4];
NSArray *list_kbd = (NSArray *)TISCreateInputSourceList((CFDictionaryRef)filter_kbd, false);
UniCharCount realLength;
for (NSUInteger i = 0; i < [list_kbd count]; i++) {
LayoutInfo ly;
NSString *name = (NSString *)TISGetInputSourceProperty((TISInputSourceRef)[list_kbd objectAtIndex:i], kTISPropertyLocalizedName);
ly.name.parse_utf8([name UTF8String]);
err = UCKeyTranslate(keyboardLayout,
NSArray *langs = (NSArray *)TISGetInputSourceProperty((TISInputSourceRef)[list_kbd objectAtIndex:i], kTISPropertyInputSourceLanguages);
keyCode[i],
ly.code.parse_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
kUCKeyActionDisplay,
kbd_layouts.push_back(ly);
0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit,
&keysDown,
sizeof(chars) / sizeof(chars[0]),
&realLength,
chars);
if (err != noErr
) {
if ([name isEqualToString:cur_name]
) {
CFRelease(output)
;
current_layout = kbd_layouts.size() - 1
;
return nil;
}
}
}
[list_kbd release];
CFStringAppendCharacters(output, chars, 1);
}
}
return (NSString *)output
;
keyboard_layout_dirty = false
;
}
}
DisplayServerOSX::LatinKeyboardVariant DisplayServerOSX::get_latin_keyboard_variant() const {
int DisplayServerOSX::keyboard_get_layout_count() const {
_THREAD_SAFE_METHOD_
if (keyboard_layout_dirty) {
_update_keyboard_layouts();
static LatinKeyboardVariant layout = LATIN_KEYBOARD_QWERTY;
}
return kbd_layouts.size();
}
void DisplayServerOSX::keyboard_set_current_layout(int p_index) {
if (keyboard_layout_dirty) {
if (keyboard_layout_dirty) {
layout = LATIN_KEYBOARD_QWERTY;
_update_keyboard_layouts();
}
ERR_FAIL_INDEX(p_index, kbd_layouts.size());
CGKeyCode keys[] = { kVK_ANSI_Q, kVK_ANSI_W, kVK_ANSI_E, kVK_ANSI_R, kVK_ANSI_T, kVK_ANSI_Y };
NSString *cur_name = [NSString stringWithUTF8String:kbd_layouts[p_index].name.utf8().get_data()];
NSString *test = createStringForKeys(keys, 6);
if ([test isEqualToString:@"qwertz"]) {
NSDictionary *filter_kbd = @{ (NSString *)kTISPropertyInputSourceType : (NSString *)kTISTypeKeyboardLayout };
layout = LATIN_KEYBOARD_QWERTZ;
NSArray *list_kbd = (NSArray *)TISCreateInputSourceList((CFDictionaryRef)filter_kbd, false);
} else if ([test isEqualToString:@"azerty"]) {
for (NSUInteger i = 0; i < [list_kbd count]; i++) {
layout = LATIN_KEYBOARD_AZERTY;
NSString *name = (NSString *)TISGetInputSourceProperty((TISInputSourceRef)[list_kbd objectAtIndex:i], kTISPropertyLocalizedName);
} else if ([test isEqualToString:@"qzerty"]) {
if ([name isEqualToString:cur_name]) {
layout = LATIN_KEYBOARD_QZERTY;
TISSelectInputSource((TISInputSourceRef)[list_kbd objectAtIndex:i]);
} else if ([test isEqualToString:@"',.pyf"]) {
break;
layout = LATIN_KEYBOARD_DVORAK;
} else if ([test isEqualToString:@"xvlcwk"]) {
layout = LATIN_KEYBOARD_NEO;
} else if ([test isEqualToString:@"qwfpgj"]) {
layout = LATIN_KEYBOARD_COLEMAK;
}
}
}
[list_kbd release];
[test release];
NSDictionary *filter_ime = @{ (NSString *)kTISPropertyInputSourceType : (NSString *)kTISTypeKeyboardInputMode };
NSArray *list_ime = (NSArray *)TISCreateInputSourceList((CFDictionaryRef)filter_ime, false);
for (NSUInteger i = 0; i < [list_ime count]; i++) {
NSString *name = (NSString *)TISGetInputSourceProperty((TISInputSourceRef)[list_ime objectAtIndex:i], kTISPropertyLocalizedName);
if ([name isEqualToString:cur_name]) {
TISSelectInputSource((TISInputSourceRef)[list_ime objectAtIndex:i]);
break;
}
}
[list_ime release];
}
int DisplayServerOSX::keyboard_get_current_layout() const {
if (keyboard_layout_dirty) {
_update_keyboard_layouts();
}
keyboard_layout_dirty = false;
return current_layout;
return layout;
}
String DisplayServerOSX::keyboard_get_layout_language(int p_index) const {
if (keyboard_layout_dirty) {
_update_keyboard_layouts();
}
ERR_FAIL_INDEX_V(p_index, kbd_layouts.size(), "");
return kbd_layouts[p_index].code;
}
String DisplayServerOSX::keyboard_get_layout_name(int p_index) const {
if (keyboard_layout_dirty) {
_update_keyboard_layouts();
}
}
return layout;
ERR_FAIL_INDEX_V(p_index, kbd_layouts.size(), "");
return kbd_layouts[p_index].name;
}
}
void DisplayServerOSX::_push_input(const Ref<InputEvent> &p_event) {
void DisplayServerOSX::_push_input(const Ref<InputEvent> &p_event) {
...
...
platform/windows/display_server_windows.cpp
View file @
92352b1c
...
@@ -1372,70 +1372,99 @@ void DisplayServerWindows::enable_for_stealing_focus(OS::ProcessID pid) {
...
@@ -1372,70 +1372,99 @@ void DisplayServerWindows::enable_for_stealing_focus(OS::ProcessID pid) {
AllowSetForegroundWindow
(
pid
);
AllowSetForegroundWindow
(
pid
);
}
}
DisplayServer
::
LatinKeyboardVariant
DisplayServerWindows
::
get_latin_keyboard_variant
()
const
{
int
DisplayServerWindows
::
keyboard_get_layout_count
()
const
{
_THREAD_SAFE_METHOD_
return
GetKeyboardLayoutList
(
0
,
NULL
);
}
unsigned
long
azerty
[]
=
{
int
DisplayServerWindows
::
keyboard_get_current_layout
()
const
{
0x00020401
,
// Arabic (102) AZERTY
HKL
cur_layout
=
GetKeyboardLayout
(
0
);
0x0001080c
,
// Belgian (Comma)
0x0000080c
,
// Belgian French
int
layout_count
=
GetKeyboardLayoutList
(
0
,
NULL
);
0x0000040c
,
// French
HKL
*
layouts
=
(
HKL
*
)
memalloc
(
layout_count
*
sizeof
(
HKL
));
0
// <--- STOP MARK
GetKeyboardLayoutList
(
layout_count
,
layouts
);
};
unsigned
long
qwertz
[]
=
{
for
(
int
i
=
0
;
i
<
layout_count
;
i
++
)
{
0x0000041a
,
// Croation
if
(
cur_layout
==
layouts
[
i
])
{
0x00000405
,
// Czech
memfree
(
layouts
);
0x00000407
,
// German
return
i
;
0x00010407
,
// German (IBM)
}
0x0000040e
,
// Hungarian
}
0x0000046e
,
// Luxembourgish
memfree
(
layouts
);
0x00010415
,
// Polish (214)
return
-
1
;
0x00000418
,
// Romanian (Legacy)
}
0x0000081a
,
// Serbian (Latin)
0x0000041b
,
// Slovak
void
DisplayServerWindows
::
keyboard_set_current_layout
(
int
p_index
)
{
0x00000424
,
// Slovenian
int
layout_count
=
GetKeyboardLayoutList
(
0
,
NULL
);
0x0001042e
,
// Sorbian Extended
0x0002042e
,
// Sorbian Standard
ERR_FAIL_INDEX
(
p_index
,
layout_count
);
0x0000042e
,
// Sorbian Standard (Legacy)
0x0000100c
,
// Swiss French
HKL
*
layouts
=
(
HKL
*
)
memalloc
(
layout_count
*
sizeof
(
HKL
));
0x00000807
,
// Swiss German
GetKeyboardLayoutList
(
layout_count
,
layouts
);
0
// <--- STOP MARK
ActivateKeyboardLayout
(
layouts
[
p_index
],
KLF_SETFORPROCESS
);
};
memfree
(
layouts
);
unsigned
long
dvorak
[]
=
{
}
0x00010409
,
// US-Dvorak
0x00030409
,
// US-Dvorak for left hand
String
DisplayServerWindows
::
keyboard_get_layout_language
(
int
p_index
)
const
{
0x00040409
,
// US-Dvorak for right hand
int
layout_count
=
GetKeyboardLayoutList
(
0
,
NULL
);
0
// <--- STOP MARK
};
char
name
[
KL_NAMELENGTH
+
1
];
ERR_FAIL_INDEX_V
(
p_index
,
layout_count
,
""
);
name
[
0
]
=
0
;
GetKeyboardLayoutNameA
(
name
);
unsigned
long
hex
=
strtoul
(
name
,
nullptr
,
16
);
HKL
*
layouts
=
(
HKL
*
)
memalloc
(
layout_count
*
sizeof
(
HKL
));
GetKeyboardLayoutList
(
layout_count
,
layouts
);
int
i
=
0
;
wchar_t
buf
[
LOCALE_NAME_MAX_LENGTH
];
while
(
azerty
[
i
]
!=
0
)
{
memset
(
buf
,
0
,
LOCALE_NAME_MAX_LENGTH
*
sizeof
(
wchar_t
));
if
(
azerty
[
i
]
==
hex
)
LCIDToLocaleName
(
MAKELCID
(
LOWORD
(
layouts
[
p_index
]),
SORT_DEFAULT
),
buf
,
LOCALE_NAME_MAX_LENGTH
,
0
);
return
LATIN_KEYBOARD_AZERTY
;
i
++
;
memfree
(
layouts
);
return
String
(
buf
).
substr
(
0
,
2
);
}
String
_get_full_layout_name_from_registry
(
HKL
p_layout
)
{
String
id
=
"SYSTEM
\\
CurrentControlSet
\\
Control
\\
Keyboard Layouts
\\
"
+
String
::
num_int64
((
int64_t
)
p_layout
,
16
,
false
).
lpad
(
8
,
"0"
);
String
ret
;
HKEY
hkey
;
wchar_t
layout_text
[
1024
];
memset
(
layout_text
,
0
,
1024
*
sizeof
(
wchar_t
));
if
(
RegOpenKeyExW
(
HKEY_LOCAL_MACHINE
,
(
LPCWSTR
)
id
.
c_str
(),
0
,
KEY_QUERY_VALUE
,
&
hkey
)
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
i
=
0
;
DWORD
buffer
=
1024
;
while
(
qwertz
[
i
]
!=
0
)
{
DWORD
vtype
=
REG_SZ
;
if
(
qwertz
[
i
]
==
hex
)
if
(
RegQueryValueExW
(
hkey
,
L"Layout Text"
,
NULL
,
&
vtype
,
(
LPBYTE
)
layout_text
,
&
buffer
)
==
ERROR_SUCCESS
)
{
return
LATIN_KEYBOARD_QWERTZ
;
ret
=
String
(
layout_text
);
i
++
;
}
}
RegCloseKey
(
hkey
);
return
ret
;
}
String
DisplayServerWindows
::
keyboard_get_layout_name
(
int
p_index
)
const
{
int
layout_count
=
GetKeyboardLayoutList
(
0
,
NULL
);
ERR_FAIL_INDEX_V
(
p_index
,
layout_count
,
""
);
HKL
*
layouts
=
(
HKL
*
)
memalloc
(
layout_count
*
sizeof
(
HKL
));
GetKeyboardLayoutList
(
layout_count
,
layouts
);
i
=
0
;
String
ret
=
_get_full_layout_name_from_registry
(
layouts
[
p_index
]);
// Try reading full name from Windows registry, fallback to locale name if failed (e.g. on Wine).
while
(
dvorak
[
i
]
!=
0
)
{
if
(
ret
==
String
())
{
if
(
dvorak
[
i
]
==
hex
)
wchar_t
buf
[
LOCALE_NAME_MAX_LENGTH
];
return
LATIN_KEYBOARD_DVORAK
;
memset
(
buf
,
0
,
LOCALE_NAME_MAX_LENGTH
*
sizeof
(
wchar_t
));
i
++
;
LCIDToLocaleName
(
MAKELCID
(
LOWORD
(
layouts
[
p_index
]),
SORT_DEFAULT
),
buf
,
LOCALE_NAME_MAX_LENGTH
,
0
);
wchar_t
name
[
1024
];
memset
(
name
,
0
,
1024
*
sizeof
(
wchar_t
));
GetLocaleInfoEx
(
buf
,
LOCALE_SLOCALIZEDDISPLAYNAME
,
(
LPWSTR
)
&
name
,
1024
);
ret
=
String
(
name
);
}
}
memfree
(
layouts
);
return
LATIN_KEYBOARD_QWERTY
;
return
ret
;
}
}
void
DisplayServerWindows
::
process_events
()
{
void
DisplayServerWindows
::
process_events
()
{
...
...
platform/windows/display_server_windows.h
View file @
92352b1c
...
@@ -523,7 +523,11 @@ public:
...
@@ -523,7 +523,11 @@ public:
virtual
void
enable_for_stealing_focus
(
OS
::
ProcessID
pid
);
virtual
void
enable_for_stealing_focus
(
OS
::
ProcessID
pid
);
virtual
LatinKeyboardVariant
get_latin_keyboard_variant
()
const
;
virtual
int
keyboard_get_layout_count
()
const
;
virtual
int
keyboard_get_current_layout
()
const
;
virtual
void
keyboard_set_current_layout
(
int
p_index
);
virtual
String
keyboard_get_layout_language
(
int
p_index
)
const
;
virtual
String
keyboard_get_layout_name
(
int
p_index
)
const
;
virtual
void
process_events
();
virtual
void
process_events
();
...
...
servers/display_server.cpp
View file @
92352b1c
...
@@ -276,8 +276,23 @@ Error DisplayServer::dialog_input_text(String p_title, String p_description, Str
...
@@ -276,8 +276,23 @@ Error DisplayServer::dialog_input_text(String p_title, String p_description, Str
return
OK
;
return
OK
;
}
}
DisplayServer
::
LatinKeyboardVariant
DisplayServer
::
get_latin_keyboard_variant
()
const
{
int
DisplayServer
::
keyboard_get_layout_count
()
const
{
return
LATIN_KEYBOARD_QWERTY
;
return
0
;
}
int
DisplayServer
::
keyboard_get_current_layout
()
const
{
return
-
1
;
}
void
DisplayServer
::
keyboard_set_current_layout
(
int
p_index
)
{
}
String
DisplayServer
::
keyboard_get_layout_language
(
int
p_index
)
const
{
return
""
;
}
String
DisplayServer
::
keyboard_get_layout_name
(
int
p_index
)
const
{
return
"Not supported"
;
}
}
void
DisplayServer
::
force_process_and_drop_events
()
{
void
DisplayServer
::
force_process_and_drop_events
()
{
...
@@ -461,7 +476,11 @@ void DisplayServer::_bind_methods() {
...
@@ -461,7 +476,11 @@ void DisplayServer::_bind_methods() {
ClassDB
::
bind_method
(
D_METHOD
(
"dialog_show"
,
"title"
,
"description"
,
"buttons"
,
"callback"
),
&
DisplayServer
::
dialog_show
);
ClassDB
::
bind_method
(
D_METHOD
(
"dialog_show"
,
"title"
,
"description"
,
"buttons"
,
"callback"
),
&
DisplayServer
::
dialog_show
);
ClassDB
::
bind_method
(
D_METHOD
(
"dialog_input_text"
,
"title"
,
"description"
,
"existing_text"
,
"callback"
),
&
DisplayServer
::
dialog_input_text
);
ClassDB
::
bind_method
(
D_METHOD
(
"dialog_input_text"
,
"title"
,
"description"
,
"existing_text"
,
"callback"
),
&
DisplayServer
::
dialog_input_text
);
ClassDB
::
bind_method
(
D_METHOD
(
"get_latin_keyboard_variant"
),
&
DisplayServer
::
get_latin_keyboard_variant
);
ClassDB
::
bind_method
(
D_METHOD
(
"keyboard_get_layout_count"
),
&
DisplayServer
::
keyboard_get_layout_count
);
ClassDB
::
bind_method
(
D_METHOD
(
"keyboard_get_current_layout"
),
&
DisplayServer
::
keyboard_get_current_layout
);
ClassDB
::
bind_method
(
D_METHOD
(
"keyboard_set_current_layout"
,
"index"
),
&
DisplayServer
::
keyboard_set_current_layout
);
ClassDB
::
bind_method
(
D_METHOD
(
"keyboard_get_layout_language"
,
"index"
),
&
DisplayServer
::
keyboard_get_layout_language
);
ClassDB
::
bind_method
(
D_METHOD
(
"keyboard_get_layout_name"
,
"index"
),
&
DisplayServer
::
keyboard_get_layout_name
);
ClassDB
::
bind_method
(
D_METHOD
(
"process_events"
),
&
DisplayServer
::
process_events
);
ClassDB
::
bind_method
(
D_METHOD
(
"process_events"
),
&
DisplayServer
::
process_events
);
ClassDB
::
bind_method
(
D_METHOD
(
"force_process_and_drop_events"
),
&
DisplayServer
::
force_process_and_drop_events
);
ClassDB
::
bind_method
(
D_METHOD
(
"force_process_and_drop_events"
),
&
DisplayServer
::
force_process_and_drop_events
);
...
@@ -543,14 +562,6 @@ void DisplayServer::_bind_methods() {
...
@@ -543,14 +562,6 @@ void DisplayServer::_bind_methods() {
BIND_ENUM_CONSTANT
(
WINDOW_FLAG_NO_FOCUS
);
BIND_ENUM_CONSTANT
(
WINDOW_FLAG_NO_FOCUS
);
BIND_ENUM_CONSTANT
(
WINDOW_FLAG_MAX
);
BIND_ENUM_CONSTANT
(
WINDOW_FLAG_MAX
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_QWERTY
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_QWERTZ
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_AZERTY
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_QZERTY
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_DVORAK
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_NEO
);
BIND_ENUM_CONSTANT
(
LATIN_KEYBOARD_COLEMAK
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_MOUSE_ENTER
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_MOUSE_ENTER
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_MOUSE_EXIT
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_MOUSE_EXIT
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_FOCUS_IN
);
BIND_ENUM_CONSTANT
(
WINDOW_EVENT_FOCUS_IN
);
...
...
servers/display_server.h
View file @
92352b1c
...
@@ -324,17 +324,11 @@ public:
...
@@ -324,17 +324,11 @@ public:
virtual
Error
dialog_show
(
String
p_title
,
String
p_description
,
Vector
<
String
>
p_buttons
,
const
Callable
&
p_callback
);
virtual
Error
dialog_show
(
String
p_title
,
String
p_description
,
Vector
<
String
>
p_buttons
,
const
Callable
&
p_callback
);
virtual
Error
dialog_input_text
(
String
p_title
,
String
p_description
,
String
p_partial
,
const
Callable
&
p_callback
);
virtual
Error
dialog_input_text
(
String
p_title
,
String
p_description
,
String
p_partial
,
const
Callable
&
p_callback
);
enum
LatinKeyboardVariant
{
virtual
int
keyboard_get_layout_count
()
const
;
LATIN_KEYBOARD_QWERTY
,
virtual
int
keyboard_get_current_layout
()
const
;
LATIN_KEYBOARD_QWERTZ
,
virtual
void
keyboard_set_current_layout
(
int
p_index
);
LATIN_KEYBOARD_AZERTY
,
virtual
String
keyboard_get_layout_language
(
int
p_index
)
const
;
LATIN_KEYBOARD_QZERTY
,
virtual
String
keyboard_get_layout_name
(
int
p_index
)
const
;
LATIN_KEYBOARD_DVORAK
,
LATIN_KEYBOARD_NEO
,
LATIN_KEYBOARD_COLEMAK
,
};
virtual
LatinKeyboardVariant
get_latin_keyboard_variant
()
const
;
virtual
void
process_events
()
=
0
;
virtual
void
process_events
()
=
0
;
...
@@ -384,6 +378,5 @@ VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation)
...
@@ -384,6 +378,5 @@ VARIANT_ENUM_CAST(DisplayServer::ScreenOrientation)
VARIANT_ENUM_CAST
(
DisplayServer
::
WindowMode
)
VARIANT_ENUM_CAST
(
DisplayServer
::
WindowMode
)
VARIANT_ENUM_CAST
(
DisplayServer
::
WindowFlags
)
VARIANT_ENUM_CAST
(
DisplayServer
::
WindowFlags
)
VARIANT_ENUM_CAST
(
DisplayServer
::
CursorShape
)
VARIANT_ENUM_CAST
(
DisplayServer
::
CursorShape
)
VARIANT_ENUM_CAST
(
DisplayServer
::
LatinKeyboardVariant
)
#endif // DISPLAY_SERVER_H
#endif // DISPLAY_SERVER_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment