forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 84
Compose UI for native Linux #2027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Thomas-Vos
wants to merge
4
commits into
JetBrains:jb-main
Choose a base branch
from
Thomas-Vos:compose-ui-linux
base: jb-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,7 @@ androidXComposeMultiplatform { | |
js() | ||
wasm() | ||
darwin() | ||
|
||
linuxX64() | ||
linuxArm64() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,7 @@ androidXComposeMultiplatform { | |
js() | ||
wasm() | ||
darwin() | ||
|
||
linuxX64() | ||
linuxArm64() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,7 @@ androidXComposeMultiplatform { | |
js() | ||
wasm() | ||
darwin() | ||
|
||
linuxX64() | ||
linuxArm64() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,7 @@ androidXComposeMultiplatform { | |
js() | ||
wasm() | ||
darwin() | ||
|
||
linuxX64() | ||
linuxArm64() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) { | |
darwin() | ||
js() | ||
wasm() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) { | |
darwin() | ||
js() | ||
wasm() | ||
linux() | ||
} | ||
|
||
kotlin { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...foundation/foundation/src/linuxMain/kotlin/androidx/compose/foundation/Clickable.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
package androidx.compose.foundation | ||
|
||
// TODO: b/168524931 - should this depend on the input device? | ||
internal actual val TapIndicationDelay: Long = 0L |
27 changes: 27 additions & 0 deletions
27
...oundation/foundation/src/linuxMain/kotlin/androidx/compose/foundation/Overscroll.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
|
||
package androidx.compose.foundation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalAccessorScope | ||
|
||
@Composable | ||
internal actual fun rememberPlatformOverscrollEffect(): OverscrollEffect? = | ||
null | ||
|
||
internal actual fun CompositionLocalAccessorScope.defaultOverscrollFactory(): OverscrollFactory? = | ||
null |
19 changes: 19 additions & 0 deletions
19
.../foundation/src/linuxMain/kotlin/androidx/compose/foundation/RequestFocusOnClick.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2023 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. | ||
*/ | ||
|
||
package androidx.compose.foundation | ||
|
||
internal actual fun isRequestFocusOnClickEnabled(): Boolean = true |
44 changes: 44 additions & 0 deletions
44
...dation/src/linuxMain/kotlin/androidx/compose/foundation/gestures/LinuxScrollable.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2022 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. | ||
*/ | ||
|
||
package androidx.compose.foundation.gestures | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.input.pointer.PointerEvent | ||
import androidx.compose.ui.node.CompositionLocalConsumerModifierNode | ||
import androidx.compose.ui.unit.Density | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.util.fastFold | ||
import kotlin.math.sqrt | ||
|
||
internal actual fun CompositionLocalConsumerModifierNode.platformScrollConfig(): ScrollConfig = | ||
LinuxScrollConfig | ||
|
||
private object LinuxScrollConfig : ScrollConfig { | ||
// See https://developer.apple.com/documentation/appkit/nsevent/1535387-scrollingdeltay | ||
override fun Density.calculateMouseWheelScroll(event: PointerEvent, bounds: IntSize): Offset { | ||
// 64 dp value is taken from ViewConfiguration.java, replace with better solution | ||
|
||
val verticalScrollFactor = -64.dp.toPx() | ||
|
||
val horizontalScrollFactor = -64.dp.toPx() | ||
|
||
return event.changes | ||
.fastFold(Offset.Zero) { acc, c -> acc + c.scrollDelta } | ||
.let { Offset(it.x * horizontalScrollFactor, it.y * verticalScrollFactor) } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../foundation/src/linuxMain/kotlin/androidx/compose/foundation/gestures/Scrollable.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
package androidx.compose.foundation.gestures | ||
|
||
import androidx.compose.animation.SplineBasedFloatDecayAnimationSpec | ||
import androidx.compose.animation.core.generateDecayAnimationSpec | ||
import androidx.compose.animation.rememberSplineBasedDecay | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
|
||
internal actual fun platformDefaultFlingBehavior(): ScrollableDefaultFlingBehavior = | ||
DefaultFlingBehavior( | ||
SplineBasedFloatDecayAnimationSpec(UnityDensity).generateDecayAnimationSpec() | ||
) | ||
|
||
@Composable | ||
internal actual fun rememberPlatformDefaultFlingBehavior(): FlingBehavior { | ||
val flingSpec = rememberSplineBasedDecay<Float>() | ||
return remember(flingSpec) { | ||
DefaultFlingBehavior(flingSpec) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ndation/src/linuxMain/kotlin/androidx/compose/foundation/internal/ClipboardUtils.linux.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2025 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(ExperimentalComposeUiApi::class) | ||
|
||
package androidx.compose.foundation.internal | ||
|
||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.platform.ClipEntry | ||
import androidx.compose.ui.text.AnnotatedString | ||
|
||
|
||
internal actual suspend fun ClipEntry.readText(): String? { | ||
return null | ||
} | ||
|
||
internal actual suspend fun ClipEntry.readAnnotatedString(): AnnotatedString? { | ||
return null | ||
} | ||
|
||
internal actual fun AnnotatedString?.toClipEntry(): ClipEntry? { | ||
return null | ||
} | ||
|
||
internal actual fun ClipEntry?.hasText(): Boolean = false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many features in this PR are not implemented (this is just one random example). I am afraid that using wayland code here could break it for non-wayland apps.
My use case is using Compose on an embedded system which is not using wayland but manufacturer specific APIs for most (windowing) features. I need to implement some of these functions with manufacturer-specific code, which of course can never be merged into compose.
As this is an expect/actual (like almost everywhere), I do not know of an easy way to pull out the wayland code into a separate module. Ideally a user like me can provide their own implementation for the windowing features. Or maybe multiple separate modules (one for wayland, etc). Any ideas what would work best?