Skip to content

Commit c0984f8

Browse files
m-sashaApoloApps
authored andcommitted
Introduce ComposeDesktopEntryPoint interface (JetBrains#3140)
1 parent d599b7d commit c0984f8

8 files changed

Lines changed: 88 additions & 16 deletions

File tree

compose/ui/ui/api/desktop/ui.api

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public final class androidx/compose/ui/ComposableSingletons$ImageComposeScene_sk
135135
public final fun getLambda$1296475654$ui ()Lkotlin/jvm/functions/Function2;
136136
}
137137

138+
public abstract interface class androidx/compose/ui/ComposeDesktopEntryPoint {
139+
public abstract fun getSemanticsOwners ()Ljava/util/Collection;
140+
}
141+
138142
public final class androidx/compose/ui/ComposedModifierKt {
139143
public static final fun composed (Landroidx/compose/ui/Modifier;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Landroidx/compose/ui/Modifier;
140144
public static final fun composed (Landroidx/compose/ui/Modifier;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Landroidx/compose/ui/Modifier;
@@ -181,6 +185,7 @@ public final class androidx/compose/ui/ImageComposeScene {
181185
public final fun close ()V
182186
public final fun getConstraints-msEJaDk ()J
183187
public final fun getContentSize-YbymL2g ()J
188+
public final fun getSemanticsOwners ()Ljava/util/Collection;
184189
public final fun hasInvalidations ()Z
185190
public final fun render (J)Lorg/jetbrains/skia/Image;
186191
public static synthetic fun render$default (Landroidx/compose/ui/ImageComposeScene;JILjava/lang/Object;)Lorg/jetbrains/skia/Image;
@@ -548,7 +553,7 @@ public final class androidx/compose/ui/awt/AwtWindow_desktopKt {
548553
public static final fun AwtWindow (ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
549554
}
550555

551-
public final class androidx/compose/ui/awt/ComposeDialog : javax/swing/JDialog {
556+
public final class androidx/compose/ui/awt/ComposeDialog : javax/swing/JDialog, androidx/compose/ui/ComposeDesktopEntryPoint {
552557
public static final field $stable I
553558
public fun <init> ()V
554559
public fun <init> (Ljava/awt/GraphicsConfiguration;)V
@@ -563,6 +568,7 @@ public final class androidx/compose/ui/awt/ComposeDialog : javax/swing/JDialog {
563568
public final fun getCompositionLocalContext ()Landroidx/compose/runtime/CompositionLocalContext;
564569
public fun getPreferredSize ()Ljava/awt/Dimension;
565570
public final fun getRenderApi ()Lorg/jetbrains/skiko/GraphicsApi;
571+
public fun getSemanticsOwners ()Ljava/util/Collection;
566572
public final fun getUndecoratedResizerThickness-D9Ej5fM ()F
567573
public final fun getWindowHandle ()J
568574
public final fun isTransparent ()Z
@@ -582,7 +588,7 @@ public final class androidx/compose/ui/awt/ComposeDialog : javax/swing/JDialog {
582588
public final fun setUndecoratedResizerThickness-0680j_4 (F)V
583589
}
584590

585-
public final class androidx/compose/ui/awt/ComposePanel : javax/swing/JLayeredPane {
591+
public final class androidx/compose/ui/awt/ComposePanel : javax/swing/JLayeredPane, androidx/compose/ui/ComposeDesktopEntryPoint {
586592
public static final field $stable I
587593
public static final field Companion Landroidx/compose/ui/awt/ComposePanel$Companion;
588594
public fun <init> ()V
@@ -594,6 +600,7 @@ public final class androidx/compose/ui/awt/ComposePanel : javax/swing/JLayeredPa
594600
public fun getMinimumSize ()Ljava/awt/Dimension;
595601
public fun getPreferredSize ()Ljava/awt/Dimension;
596602
public final fun getRenderApi ()Lorg/jetbrains/skiko/GraphicsApi;
603+
public fun getSemanticsOwners ()Ljava/util/Collection;
597604
public fun hasFocus ()Z
598605
public fun isFocusOwner ()Z
599606
public fun remove (Ljava/awt/Component;)V
@@ -620,7 +627,7 @@ public final class androidx/compose/ui/awt/ComposePanel : javax/swing/JLayeredPa
620627
public final class androidx/compose/ui/awt/ComposePanel$Companion {
621628
}
622629

623-
public final class androidx/compose/ui/awt/ComposeWindow : javax/swing/JFrame {
630+
public final class androidx/compose/ui/awt/ComposeWindow : javax/swing/JFrame, androidx/compose/ui/ComposeDesktopEntryPoint {
624631
public static final field $stable I
625632
public fun <init> (Ljava/awt/GraphicsConfiguration;)V
626633
public synthetic fun <init> (Ljava/awt/GraphicsConfiguration;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -633,6 +640,7 @@ public final class androidx/compose/ui/awt/ComposeWindow : javax/swing/JFrame {
633640
public final fun getPlacement ()Landroidx/compose/ui/window/WindowPlacement;
634641
public fun getPreferredSize ()Ljava/awt/Dimension;
635642
public final fun getRenderApi ()Lorg/jetbrains/skiko/GraphicsApi;
643+
public fun getSemanticsOwners ()Ljava/util/Collection;
636644
public final fun getUndecoratedResizerThickness-D9Ej5fM ()F
637645
public final fun getWindowHandle ()J
638646
public final fun isMinimized ()Z

compose/ui/ui/api/ui.klib.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,8 @@ final class androidx.compose.ui/ImageComposeScene { // androidx.compose.ui/Image
25602560

25612561
final val contentSize // androidx.compose.ui/ImageComposeScene.contentSize|{}contentSize[0]
25622562
final fun <get-contentSize>(): androidx.compose.ui.unit/IntSize // androidx.compose.ui/ImageComposeScene.contentSize.<get-contentSize>|<get-contentSize>(){}[0]
2563+
final val semanticsOwners // androidx.compose.ui/ImageComposeScene.semanticsOwners|{}semanticsOwners[0]
2564+
final fun <get-semanticsOwners>(): kotlin.collections/Collection<androidx.compose.ui.semantics/SemanticsOwner> // androidx.compose.ui/ImageComposeScene.semanticsOwners.<get-semanticsOwners>|<get-semanticsOwners>(){}[0]
25632565

25642566
final var constraints // androidx.compose.ui/ImageComposeScene.constraints|{}constraints[0]
25652567
final fun <get-constraints>(): androidx.compose.ui.unit/Constraints // androidx.compose.ui/ImageComposeScene.constraints.<get-constraints>|<get-constraints>(){}[0]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.compose.ui
18+
19+
import androidx.compose.runtime.tooling.ComposeToolingApi
20+
import androidx.compose.ui.semantics.SemanticsOwner
21+
22+
/**
23+
* The interface for classes that are an entry point for using Compose on the desktop.
24+
*/
25+
@ComposeToolingApi
26+
interface ComposeDesktopEntryPoint {
27+
/**
28+
* Returns the [SemanticsOwner]s corresponding to the roots of the semantics trees in this
29+
* [ComposeDesktopEntryPoint].
30+
*
31+
* This is backed by Snapshot state, so reading this property in a restartable function (e.g., a
32+
* composable function) will cause the function to restart when the set of semantics owners
33+
* changes.
34+
*/
35+
val semanticsOwners: Collection<SemanticsOwner>
36+
}

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeDialog.desktop.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ package androidx.compose.ui.awt
1717

1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.CompositionLocalContext
20+
import androidx.compose.runtime.tooling.ComposeToolingApi
21+
import androidx.compose.ui.ComposeDesktopEntryPoint
2022
import androidx.compose.ui.ExperimentalComposeUiApi
2123
import androidx.compose.ui.InternalComposeUiApi
2224
import androidx.compose.ui.Modifier
2325
import androidx.compose.ui.input.key.KeyEvent
2426
import androidx.compose.ui.layout.layoutId
27+
import androidx.compose.ui.semantics.SemanticsOwner
2528
import androidx.compose.ui.semantics.dialog
2629
import androidx.compose.ui.semantics.semantics
2730
import androidx.compose.ui.unit.Constraints
@@ -51,7 +54,8 @@ import org.jetbrains.skiko.SkiaLayerAnalytics
5154
/**
5255
* System dialog for displaying Compose UI, inheriting [javax.swing.JDialog].
5356
*/
54-
class ComposeDialog : JDialog {
57+
@OptIn(ComposeToolingApi::class)
58+
class ComposeDialog : JDialog, ComposeDesktopEntryPoint {
5559
private val composePanel: ComposeWindowPanel
5660

5761
private fun createComposePanel(
@@ -212,6 +216,18 @@ class ComposeDialog : JDialog {
212216

213217
private val undecoratedWindowResizer = UndecoratedWindowResizer(this)
214218

219+
/**
220+
* Returns the [SemanticsOwner]s corresponding to the roots of the semantics trees in this
221+
* [ComposeDialog].
222+
*
223+
* This is backed by Snapshot state, so reading this property in a restartable function (e.g., a
224+
* composable function) will cause the function to restart when the set of semantics owners
225+
* changes.
226+
*/
227+
@ComposeToolingApi
228+
override val semanticsOwners: Collection<SemanticsOwner>
229+
get() = composePanel.semanticsOwners
230+
215231
override fun add(component: Component) = composePanel.add(component)
216232

217233
override fun remove(component: Component) = composePanel.remove(component)

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import androidx.compose.runtime.CompositionLocalProvider
2121
import androidx.compose.runtime.getValue
2222
import androidx.compose.runtime.mutableStateOf
2323
import androidx.compose.runtime.setValue
24+
import androidx.compose.runtime.tooling.ComposeToolingApi
25+
import androidx.compose.ui.ComposeDesktopEntryPoint
2426
import androidx.compose.ui.ComposeFeatureFlags
2527
import androidx.compose.ui.ComposeUiFlags
2628
import androidx.compose.ui.ExperimentalComposeUiApi
@@ -64,12 +66,13 @@ import org.jetbrains.skiko.SkiaLayerAnalytics
6466
* @param renderSettings Configuration class for rendering settings.
6567
* @param coroutineContext The coroutine context for Compose content rendering and effects.
6668
*/
69+
@OptIn(ComposeToolingApi::class)
6770
class ComposePanel @ExperimentalComposeUiApi constructor(
6871
private val skiaLayerAnalytics: SkiaLayerAnalytics = SkiaLayerAnalytics.Empty,
6972
private var savedState: SavedState? = null,
7073
private val renderSettings: RenderSettings = DefaultRenderSettings,
7174
private val coroutineContext: CoroutineContext = EmptyCoroutineContext
72-
) : JLayeredPane() {
75+
) : JLayeredPane(), ComposeDesktopEntryPoint {
7376
constructor() : this(
7477
savedState = null,
7578
skiaLayerAnalytics = SkiaLayerAnalytics.Empty,
@@ -334,12 +337,12 @@ class ComposePanel @ExperimentalComposeUiApi constructor(
334337
* Returns the [SemanticsOwner]s corresponding to the roots of the semantics trees in this
335338
* [ComposePanel].
336339
*
337-
* This is backed by snapshot state, so reading this property in a restartable function (e.g., a
340+
* This is backed by Snapshot state, so reading this property in a restartable function (e.g., a
338341
* composable function) will cause the function to restart when the set of semantics owners
339342
* changes.
340343
*/
341-
@ExperimentalComposeUiApi
342-
val semanticsOwners: Collection<SemanticsOwner>
344+
@ComposeToolingApi
345+
override val semanticsOwners: Collection<SemanticsOwner>
343346
get() = _composeContainer?.semanticsOwners ?: emptyList()
344347

345348
// Needed to preserve binary compatibility

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeWindow.desktop.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package androidx.compose.ui.awt
1717

1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.CompositionLocalContext
20+
import androidx.compose.runtime.tooling.ComposeToolingApi
21+
import androidx.compose.ui.ComposeDesktopEntryPoint
2022
import androidx.compose.ui.ExperimentalComposeUiApi
2123
import androidx.compose.ui.InternalComposeUiApi
2224
import androidx.compose.ui.Modifier
@@ -55,12 +57,13 @@ import org.jetbrains.skiko.SkiaLayerAnalytics
5557
* @param savedState The saved state to restore the UI state from a previous instance.
5658
* @param coroutineContext The coroutine context for Compose content rendering and effects.
5759
*/
60+
@OptIn(ComposeToolingApi::class)
5861
class ComposeWindow @ExperimentalComposeUiApi constructor(
5962
graphicsConfiguration: GraphicsConfiguration? = null,
6063
skiaLayerAnalytics: SkiaLayerAnalytics = SkiaLayerAnalytics.Empty,
6164
savedState: SavedState? = null,
6265
coroutineContext: CoroutineContext = EmptyCoroutineContext
63-
) : JFrame(graphicsConfiguration) {
66+
) : JFrame(graphicsConfiguration), ComposeDesktopEntryPoint {
6467
/**
6568
* System window for displaying Compose UI, inheriting [javax.swing.JFrame].
6669
*
@@ -87,11 +90,12 @@ class ComposeWindow @ExperimentalComposeUiApi constructor(
8790
* Returns the [SemanticsOwner]s corresponding to the roots of the semantics trees in this
8891
* [ComposeWindow].
8992
*
90-
* This is backed by snapshot state, so reading this property in a restartable function (e.g., a
91-
* composable function) will cause the function to restart when set of semantics owners changes.
93+
* This is backed by Snapshot state, so reading this property in a restartable function (e.g., a
94+
* composable function) will cause the function to restart when the set of semantics owners
95+
* changes.
9296
*/
93-
@ExperimentalComposeUiApi
94-
val semanticsOwners: Collection<SemanticsOwner>
97+
@ComposeToolingApi
98+
override val semanticsOwners: Collection<SemanticsOwner>
9599
get() = composePanel.semanticsOwners
96100

97101
/**

compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/SemanticsOwnersProviderTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.runtime.mutableStateOf
2929
import androidx.compose.runtime.setValue
3030
import androidx.compose.runtime.snapshotFlow
3131
import androidx.compose.runtime.snapshots.Snapshot
32+
import androidx.compose.runtime.tooling.ComposeToolingApi
3233
import androidx.compose.ui.awt.ComposePanel
3334
import androidx.compose.ui.semantics.SemanticsNode
3435
import androidx.compose.ui.semantics.SemanticsOwner
@@ -160,6 +161,7 @@ private class ImageComposeSceneSemanticOwnersTestContext : SemanticsOwnersTestCo
160161
private class ComposeWindowSemanticOwnersTestContext : SemanticsOwnersTestContext {
161162
private lateinit var testScope: WindowTestScope
162163

164+
@OptIn(ComposeToolingApi::class)
163165
override val semanticsOwners: Collection<SemanticsOwner>
164166
get() = testScope.window.semanticsOwners
165167

@@ -184,6 +186,7 @@ private class ComposePanelSemanticOwnersTestContext(
184186
private lateinit var testScope: WindowTestScope
185187
private lateinit var composePanel: ComposePanel
186188

189+
@OptIn(ComposeToolingApi::class)
187190
override val semanticsOwners: Collection<SemanticsOwner>
188191
get() = composePanel.semanticsOwners
189192

compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/ImageComposeScene.skiko.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ class ImageComposeScene @ExperimentalComposeUiApi constructor(
206206
* Returns the [SemanticsOwner]s corresponding to the roots of the semantics trees in this
207207
* [ImageComposeScene].
208208
*
209-
* This is backed by snapshot state, so reading this property in a restartable function (e.g., a
210-
* composable function) will cause the function to restart when set of semantics owners changes.
209+
* This is backed by Snapshot state, so reading this property in a restartable function (e.g., a
210+
* composable function) will cause the function to restart when the set of semantics owners
211+
* changes.
211212
*/
212-
@ExperimentalComposeUiApi
213213
val semanticsOwners: Collection<SemanticsOwner>
214214
get() = _platformContext.semanticsOwners
215215

0 commit comments

Comments
 (0)