From 3d2d62ca47485d13cefad3063bbddd671fd1906c Mon Sep 17 00:00:00 2001 From: xiaoshen Date: Sun, 23 Jan 2022 03:18:04 -0600 Subject: [PATCH 1/4] Add more info about lwjgl intergration --- experimental/lwjgl-integration/README.md | 36 +++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/experimental/lwjgl-integration/README.md b/experimental/lwjgl-integration/README.md index 3e9ea3ebeb6..c54ae3cac88 100644 --- a/experimental/lwjgl-integration/README.md +++ b/experimental/lwjgl-integration/README.md @@ -5,4 +5,38 @@ Note that: - not all features are implemented - not all features are currently supported (Accessibility, Input Methods) - to pass some event information it is needed to pass it via AWT events (java.awt.KeyEvent and java.awt.MouseEvent). In the future versions of Compose we plan to get rid of the need of AWT events. -- it has bugs (it doesn't show cursor in TextField) \ No newline at end of file + + + +## Problems + +### Cursor In TextField +This is easy, you need to provide `androidx.compose.ui.platform.WindowInfo` in CompositionLocal + +For example: +```kotlin +CompositionLocalProvider( + LocalWindowInfo provides object : WindowInfo { override val isWindowFocused: Boolean = true } +) { + // Your App +} +``` + + +### Popup +Since Compose still use some awt events (https://github.com/JetBrains/compose-jb/issues/1736), you can provide a fake contaniner. + +```kotlin +val awtContainer = object : Container() {} + +// call it when your custom compose app changes winodw position +fun onWindowUpdate(x: Int, y: Int, width: Int, height: Int) { + awtContainer.setBounds(x, y, width, height); +} + +CompositionLocalProvider( + LocalLayerContainer provides awtContainer +) { + // Your App +} +``` From 706bab1011d079f150d8912afd6c55691d4fc617 Mon Sep 17 00:00:00 2001 From: xiaoshen Date: Sun, 23 Jan 2022 03:27:15 -0600 Subject: [PATCH 2/4] remove ';' --- experimental/lwjgl-integration/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/lwjgl-integration/README.md b/experimental/lwjgl-integration/README.md index c54ae3cac88..e1af3389964 100644 --- a/experimental/lwjgl-integration/README.md +++ b/experimental/lwjgl-integration/README.md @@ -31,7 +31,7 @@ val awtContainer = object : Container() {} // call it when your custom compose app changes winodw position fun onWindowUpdate(x: Int, y: Int, width: Int, height: Int) { - awtContainer.setBounds(x, y, width, height); + awtContainer.setBounds(x, y, width, height) } CompositionLocalProvider( From 749d2770c6806eb2bf1f2020b7a4585b6c497498 Mon Sep 17 00:00:00 2001 From: xiaoshen Date: Mon, 24 Jan 2022 11:38:56 -0600 Subject: [PATCH 3/4] Grammer --- experimental/lwjgl-integration/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/lwjgl-integration/README.md b/experimental/lwjgl-integration/README.md index e1af3389964..30dffd75eb0 100644 --- a/experimental/lwjgl-integration/README.md +++ b/experimental/lwjgl-integration/README.md @@ -24,12 +24,12 @@ CompositionLocalProvider( ### Popup -Since Compose still use some awt events (https://github.com/JetBrains/compose-jb/issues/1736), you can provide a fake contaniner. +Since Compose still use some AWT events (https://github.com/JetBrains/compose-jb/issues/1736), you can provide a fake contaniner. ```kotlin val awtContainer = object : Container() {} -// call it when your custom compose app changes winodw position +// call it when your custom compose app changes window position fun onWindowUpdate(x: Int, y: Int, width: Int, height: Int) { awtContainer.setBounds(x, y, width, height) } From 5a690e892b8c939cd5383bb84de769432b33f9c8 Mon Sep 17 00:00:00 2001 From: xiaoshen Date: Thu, 27 Jan 2022 13:37:17 -0600 Subject: [PATCH 4/4] Update README.md --- experimental/lwjgl-integration/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/experimental/lwjgl-integration/README.md b/experimental/lwjgl-integration/README.md index 30dffd75eb0..3f854af892e 100644 --- a/experimental/lwjgl-integration/README.md +++ b/experimental/lwjgl-integration/README.md @@ -40,3 +40,18 @@ CompositionLocalProvider( // Your App } ``` + +`LocalLayerContainer` is internal, so you need to use a trick. + +Create a package `androidx.compose.ui.awt` and create a file `LocalLayerContainer.desktop.kt` + +Put following code inside +```kotlin +import androidx.compose.runtime.staticCompositionLocalOf +import your.package.yourFakeAwtContainer + +val LocalLayerContainer: androidx.compose.runtime.ProvidableCompositionLocal = + staticCompositionLocalOf { yourFakeAwtContainer } +``` + +Then you would be able to access the internal `LocalLayerContainer`