Browse Source

Dx/Sdl: Add KeyMapChanged event (#793)

Yuxiao Mao 2 months ago
parent
commit
f1604c465e

+ 2 - 0
libs/directx/dx/Driver.hx

@@ -749,10 +749,12 @@ class Driver {
 	static function dxDebugPrint( str : hl.Bytes ) {
 	static function dxDebugPrint( str : hl.Bytes ) {
 	}
 	}
 
 
+	@:deprecated("dx.Driver.detectKeyboardLayout is deprecated. Use dx.Window.detectKeyboardLayout instead.")
 	public static function detectKeyboardLayout() @:privateAccess {
 	public static function detectKeyboardLayout() @:privateAccess {
 		return String.fromUTF8( dxDetectKeyboardLayout() );
 		return String.fromUTF8( dxDetectKeyboardLayout() );
 	}
 	}
 
 
+	@:deprecated("dx.Driver.dxDetectKeyboardLayout is deprecated. Use dx.Window.dxDetectKeyboardLayout instead.")
 	@:hlNative("directx", "detect_keyboard_layout")
 	@:hlNative("directx", "detect_keyboard_layout")
 	static function dxDetectKeyboardLayout() : hl.Bytes {
 	static function dxDetectKeyboardLayout() : hl.Bytes {
 		return null;
 		return null;

+ 1 - 0
libs/directx/dx/Event.hx

@@ -34,6 +34,7 @@ enum abstract EventType(Int) {
 	var DropStart   = 10;
 	var DropStart   = 10;
 	var DropFile    = 11;
 	var DropFile    = 11;
 	var DropEnd     = 12;
 	var DropEnd     = 12;
+	var KeyMapChanged = 13;
 }
 }
 
 
 enum abstract WindowStateChange(Int) {
 enum abstract WindowStateChange(Int) {

+ 10 - 1
libs/directx/dx/Window.hx

@@ -368,4 +368,13 @@ class Window {
 	static function winSetDragAcceptFiles( win : WinPtr, enable: Bool ) : Void {
 	static function winSetDragAcceptFiles( win : WinPtr, enable: Bool ) : Void {
 	}
 	}
 
 
-}
+	public static function detectKeyboardLayout() @:privateAccess {
+		return String.fromUTF8( dxDetectKeyboardLayout() );
+	}
+
+	@:hlNative("directx", "detect_keyboard_layout")
+	static function dxDetectKeyboardLayout() : hl.Bytes {
+		return null;
+	}
+
+}

+ 4 - 0
libs/directx/window.c

@@ -17,6 +17,7 @@ typedef enum {
 	DropStart = 10,
 	DropStart = 10,
 	DropFile = 11,
 	DropFile = 11,
 	DropEnd = 12,
 	DropEnd = 12,
+	KeyMapChanged = 13,
 } EventType;
 } EventType;
 
 
 typedef enum {
 typedef enum {
@@ -513,6 +514,9 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 		DragFinish(drop);
 		DragFinish(drop);
 		break;
 		break;
 	}
 	}
+	case WM_INPUTLANGCHANGE:
+		e = addEvent(wnd,KeyMapChanged);
+		break;
 	case WM_CLOSE:
 	case WM_CLOSE:
 		addState(Close);
 		addState(Close);
 		return 0;
 		return 0;

+ 5 - 1
libs/sdl/sdl.c

@@ -61,6 +61,7 @@ typedef enum {
 	DropFile,
 	DropFile,
 	DropText,
 	DropText,
 	DropEnd,
 	DropEnd,
+	KeyMapChanged = 500,
 } event_type;
 } event_type;
 
 
 typedef enum {
 typedef enum {
@@ -373,6 +374,9 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) {
 			event->type = DropEnd;
 			event->type = DropEnd;
 			event->window = e.drop.windowID;
 			event->window = e.drop.windowID;
 			break;
 			break;
+		case SDL_KEYMAPCHANGED:
+			event->type = KeyMapChanged;
+			break;
 		default:
 		default:
 			//printf("Unknown event type 0x%X\\n", e.type);
 			//printf("Unknown event type 0x%X\\n", e.type);
 			continue;
 			continue;
@@ -523,7 +527,7 @@ HL_PRIM SDL_Window *HL_NAME(win_create_ex)(int x, int y, int width, int height,
 	// force window to match device resolution on mobile
 	// force window to match device resolution on mobile
 	if ((sdlFlags & (
 	if ((sdlFlags & (
 #ifdef HL_MAC
 #ifdef HL_MAC
-		SDL_WINDOW_METAL | 
+		SDL_WINDOW_METAL |
 #endif
 #endif
 		SDL_WINDOW_VULKAN )) == 0) {
 		SDL_WINDOW_VULKAN )) == 0) {
 		sdlFlags |= SDL_WINDOW_OPENGL;
 		sdlFlags |= SDL_WINDOW_OPENGL;

+ 2 - 1
libs/sdl/sdl/Event.hx

@@ -25,7 +25,7 @@ package sdl;
 	inline function get_controller() return reference;
 	inline function get_controller() return reference;
 	inline function get_joystick() return reference;
 	inline function get_joystick() return reference;
 	inline function get_fingerId() return reference;
 	inline function get_fingerId() return reference;
-	
+
 	public function new() {
 	public function new() {
 	}
 	}
 }
 }
@@ -60,6 +60,7 @@ enum abstract EventType(Int) {
 	var DropFile = 401;
 	var DropFile = 401;
 	var DropText = 402;
 	var DropText = 402;
 	var DropEnd = 403;
 	var DropEnd = 403;
+	var KeyMapChanged = 500;
 }
 }
 
 
 enum abstract WindowStateChange(Int) {
 enum abstract WindowStateChange(Int) {