Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.skiko.hostOs

private var subscriberCount = 0
private var pollingJob: Job? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2026 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:OptIn(ExperimentalMediaQueryApi::class)

package androidx.compose.ui.platform

import androidx.compose.ui.ExperimentalMediaQueryApi
import androidx.compose.ui.UiMediaScope
import androidx.compose.ui.unit.Dp

internal class DesktopMediaScope(val windowInfo: WindowInfo) : UiMediaScope {

override val windowPosture: UiMediaScope.Posture
get() = UiMediaScope.Posture.Flat

override val windowWidth: Dp
get() = windowInfo.containerDpSize.width

override val windowHeight: Dp
get() = windowInfo.containerDpSize.height
Comment on lines +30 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not important, but windowInfo.containerDpSize refers to the container (excludes insets), and this refers to the window (includes insets).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


override val pointerPrecision: UiMediaScope.PointerPrecision
get() = UiMediaScope.PointerPrecision.Fine

override val keyboardKind: UiMediaScope.KeyboardKind
get() = UiMediaScope.KeyboardKind.Physical

override val hasMicrophone: Boolean
get() = true //inferred as always having at least 1 microphone

override val hasCamera: Boolean
get() = false //no reliable way to get it

override val viewingDistance: UiMediaScope.ViewingDistance
get() = UiMediaScope.ViewingDistance.Near

fun dispose() {
// No-op for now, but can be used to clean up resources if needed in the future.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.runtime.mutableStateSetOf
import androidx.compose.ui.ComposeFeatureFlags
import androidx.compose.ui.ComposeUiFlags
import androidx.compose.ui.ExperimentalMediaQueryApi
import androidx.compose.ui.ProvideSystemTheme
import androidx.compose.ui.UiMediaScope
import androidx.compose.ui.awt.AwtEventListener
import androidx.compose.ui.awt.AwtEventListeners
import androidx.compose.ui.awt.DebouncingEdtExecutor
Expand Down Expand Up @@ -51,6 +53,7 @@ import androidx.compose.ui.navigationevent.BackNavigationEventInput
import androidx.compose.ui.platform.AwtDragAndDropManager
import androidx.compose.ui.platform.DefaultInputModeManager
import androidx.compose.ui.platform.DelegateRootForTestListener
import androidx.compose.ui.platform.DesktopMediaScope
import androidx.compose.ui.platform.DesktopTextInputService
import androidx.compose.ui.platform.DesktopTextInputService2
import androidx.compose.ui.platform.FrameRecomposer
Expand Down Expand Up @@ -162,6 +165,8 @@ internal class ComposeSceneMediator(
DesktopTextInputService(platformComponent)
}

private val desktopMediaScope = DesktopMediaScope(windowInfo = windowContext.windowInfo)

private val textInputService2 by lazy(LazyThreadSafetyMode.NONE) {
DesktopTextInputService2(platformComponent)
}
Expand Down Expand Up @@ -630,6 +635,8 @@ internal class ComposeSceneMediator(
// Since rendering will not happen after, we need to execute all scheduled updates
interopContainer.dispose()

desktopMediaScope.dispose()

_onComponentAttached = null
}

Expand Down Expand Up @@ -835,6 +842,8 @@ internal class ComposeSceneMediator(

private inner class DesktopPlatformContext : PlatformContext {
override val windowInfo: WindowInfo get() = windowContext.windowInfo
@OptIn(ExperimentalMediaQueryApi::class)
override val mediaScope: UiMediaScope get() = desktopMediaScope

override val taskDispatchers: TaskDispatchers = object : TaskDispatchers {
override val Default = Dispatchers.Default
Expand Down
Loading