Skip to content

Commit aa6ca7c

Browse files
committed
Install root CompositionLocals for Tao application
Provide LocalDensity and LocalLayoutDirection at the Tao application root before any window scene is mounted. This allows Compose APIs that read these locals at root composition (e.g. compose-resources Font() via rememberEnvironment) to work correctly under the Tao backend. - Expose nativeSystemLayoutDirection() as public API in ControlButtonsDirection - Introduce LayoutConfiguration.tao with GlobalDensity (1f fallback) and GlobalLayoutDirection (via native bridge) - Wrap taoApplication root content in CompositionLocalProvider - Remove tmp/souvlaki submodule (no longer needed) - Update Compose to 1.11.0
1 parent 08bc6b8 commit aa6ca7c

5 files changed

Lines changed: 38 additions & 4 deletions

File tree

decorated-window-core/src/main/kotlin/dev/nucleusframework/window/ControlButtonsDirection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ enum class ControlButtonsDirection {
4141
* On Linux (or if the native library is unavailable), falls back to checking
4242
* `user.language` system property against known RTL languages.
4343
*/
44-
internal fun nativeSystemLayoutDirection(): LayoutDirection =
44+
fun nativeSystemLayoutDirection(): LayoutDirection =
4545
if (NativeLayoutDirectionBridge.nativeIsRTL()) LayoutDirection.Rtl else LayoutDirection.Ltr
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package dev.nucleusframework.window.tao
2+
3+
import androidx.compose.ui.unit.Density
4+
import androidx.compose.ui.unit.LayoutDirection
5+
import dev.nucleusframework.window.nativeSystemLayoutDirection
6+
7+
/**
8+
* Root-level defaults for [androidx.compose.ui.platform.LocalDensity] and
9+
* [androidx.compose.ui.platform.LocalLayoutDirection], installed before any Tao window scene is
10+
* mounted. Required so Compose APIs that consult these locals at root composition
11+
* (e.g. `Font(resource = …)` via compose-resources → `rememberEnvironment` →
12+
* `LocalDensity.current`) keep working.
13+
*
14+
* Per-window [androidx.compose.ui.scene.ComposeScene]s override these with their own
15+
* platform-correct values once mounted, sourced from Tao's `nativeScaleFactor` and the
16+
* `SCALE_FACTOR_CHANGED` event.
17+
*/
18+
internal val GlobalDensity: Density = Density(1f)
19+
20+
internal val GlobalLayoutDirection: LayoutDirection
21+
get() = nativeSystemLayoutDirection()

decorated-window-tao/src/main/kotlin/dev/nucleusframework/window/tao/TaoApplicationCompose.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import androidx.compose.foundation.ExperimentalFoundationApi
44
import androidx.compose.runtime.Applier
55
import androidx.compose.runtime.Composable
66
import androidx.compose.runtime.Composition
7+
import androidx.compose.runtime.CompositionLocalProvider
78
import androidx.compose.runtime.MonotonicFrameClock
89
import androidx.compose.runtime.Recomposer
910
import androidx.compose.runtime.snapshots.Snapshot
11+
import androidx.compose.ui.platform.LocalDensity
12+
import androidx.compose.ui.platform.LocalLayoutDirection
1013
import kotlinx.coroutines.CoroutineScope
1114
import kotlinx.coroutines.Job
1215
import kotlinx.coroutines.channels.Channel
@@ -57,7 +60,18 @@ fun taoApplication(content: @Composable ApplicationScope.() -> Unit) {
5760
coroutineScope.launch {
5861
try {
5962
composition.setContent {
60-
if (scope.isOpen) scope.content()
63+
// Install root-level defaults for locals that Compose APIs may consult
64+
// before any window scene is mounted (e.g. compose-resources `Font(…)`
65+
// reads `LocalDensity.current` via `rememberEnvironment`). Mirrors the
66+
// exact pattern Compose Desktop's AWT `application { }` uses — see
67+
// `androidx.compose.ui.window.LayoutConfiguration.desktop.kt`. Per-window
68+
// ComposeScenes override these with their own platform-correct values.
69+
CompositionLocalProvider(
70+
LocalDensity provides GlobalDensity,
71+
LocalLayoutDirection provides GlobalLayoutDirection,
72+
) {
73+
if (scope.isOpen) scope.content()
74+
}
6175
}
6276
while (scope.isOpen) yield()
6377
recomposer.close()

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ kotlin = "2.3.21"
66
ktlintGradle = "14.2.0"
77
pluginPublish = "2.1.1"
88
versionCheck = "0.54.0"
9-
compose = "1.11.0-rc01"
9+
compose = "1.11.0"
1010
agp = "8.12.3"
1111
downloadTask = "5.7.0"
1212
kotlinPoet = "2.3.0"

tmp/souvlaki

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)