https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compose-desktop
  • k

    Kebbin

    03/06/2022, 11:24 AM
    @olonho @Igor Demin In this context menu Tutorial, is the code linked below a simple copy of the code above it by mistake? I was looking for info about adding a context menu to an arbitrary window area. https://github.com/JetBrains/compose-jb/blob/master/tutorials/Context_Menu/README.md#context-menu-for-an-arbitrary-area Thanks!
    o
    i
    • 3
    • 4
  • m

    Martin Nonnenmacher

    03/06/2022, 12:28 PM
    Hi, I'm using
    collectAsState()
    with a flow that emits new values very frequently, about 10 times a second. The problem is that the
    SnapshotStateObserver.applyMaps
    property keeps growing and consumes more and more memory over time. This can be reproduced with the code below. A heap dump shows that after 50,000 iterations there is a single instance of
    androidx.compose.runtime.snapshots.SnapshotStateObserver$ApplyMap[]
    that consumes about 100 MB. As it seems to be by design that
    applyMaps
    can only grow, is there a fundamental issue with my code, or is there another approach I could use for frequent updates without eventually running out of memory?
    class TestState {
        private val scope = CoroutineScope(Dispatchers.Default)
        val value = MutableStateFlow(0)
    
        init {
            scope.launch {
                while (true) {
                    value.value = value.value + 1
                    delay(100)
                }
            }
        }
    }
    
    @Composable
    fun App() {
        val state = remember { TestState() }
        val value = state.value.collectAsState()
        Text("value = ${value.value}")
    }
    o
    • 2
    • 4
  • d

    David W

    03/07/2022, 12:03 AM
    At the end of my wits debugging a bizarre issue. My CfD application launches another third-party Java application. That application fails to load some crucial .dll files and crashes, but only when my application is started using
    runDistributable
    . It runs fine when launched from my application if it's launched via
    run
    ; it only fails to load the dlls and crashes when built for dist. Code here: <https://github.com/davidwhitman/SMOL/blob/dev/App/main/kotlin/smol_app/toolbar/Toolbar.kt#L148> and here <https://github.com/davidwhitman/SMOL/blob/dev/Utilities/main/kotlin/utilities/Utils.kt#L43> Screenshots and stacktrace: <https://github.com/davidwhitman/SMOL/issues/73> Things I've tried: • ProcessBuilder and Runtime exec, same results. • Copied the dll file to System32, which fixed the problem, I don't know why. • Many various usages of ProcessBuilder and Runtime exe, same results. •
    includeAllModules = true
    same results • Viewed in VisualVM, noted that the java program I'm launching doesn't show up, presumably because it's a subprocess, but that's true even when it works correctly so not sure if relevant. The other, crashing java program is given the dll path in env variable, but it successfully loads other dlls in the same path (and fails to load them if I rename them). This is probably too complex/unique for anyone to want to dive deep into, but I'll take any suggestions. One thing I'd like to try is launching the other java program as a standalone process, not a subprocess, but I haven't found a way to do this at all.
    cmd /C
    doesn't do it. I should maybe mention that the reason I consider this Compose-related is the difference between it working using
    run
    and not working using
    runDistributable
    . There's something about the Compose build that's changing things. update: Setting
    -Djava.library.path
    to an absolute path instead of relative seems to fix it. Doesn't make much sense to me, since it loads other .dlls from that folder without issue. Now I just need to figure out how to get java path variables to allow spaces... update: Just had to remove the
    cmd /C
    , probably the
    /C
    switch can't handle spaces in paths since it hands it all as a string. My problem is solved, although I couldn't say why this solution works. It's probably a unique case, but I'll leave this post anyway because you never know.
    o
    • 2
    • 3
  • r

    Remo

    03/07/2022, 7:45 AM
    Good morning everybody 🙂 Seeking for a little help here! I am supposed to upgrade a framework (&some demo applications) based on Compose v0.4 to v1.1. While upgrading, I’ve stumbled upon some classes which are not existing anymore, e.g.
    LocalAppWindow
    or
    AppManager
    Concret, I’m talking about this function, which should add some default key behaviour when pressing
    ctrl
    + `q`:
    @OptIn(ExperimentalComposeUiApi::class)
    @Composable
    private fun add addDefaultKeyBehaviour(){
        val key: Key = if(System.getProperty("os.name") == "Mac OS X") Key.MetaLeft else Key.CtrlLeft
        LocalAppWindow.current.keyboard.setShortcut(KeysSet(setOf(key, Key.Q))){
            AppManager.focusedWindow?.close()
        }
    }
    As I could not find any migration tutorial, I would appreciate some advice on this 🙂 Thanks in advance!
    o
    • 2
    • 6
  • f

    fitken

    03/07/2022, 10:52 AM
    Hi everybody, I'm new to Compose for desktop. Currently working on the Kiosk app on Windows OS I would like to know if there are any libraries for the virtual keyboard? or can I create a virtual keyboard inside the Compose for Desktop app? Here is my question on StackOverflow https://stackoverflow.com/q/71379870/3024962 🙇 🙏
    m
    • 2
    • 2
  • z

    zt

    03/07/2022, 11:28 PM
    Two questions: 1. Can I set a minimum size for a window? 2. How can I make draggable change the cursor to the resize icon whenever it's on the border of something?
    h
    n
    t
    • 4
    • 7
  • d

    Dieter Holz

    03/08/2022, 10:30 AM
    Is it possible to keep the "scroll-state" of two LazyColumns in sync? I would like to have a "table" consisting of LazyColumns. See current code in thread.
    • 1
    • 1
  • k

    Kebbin

    03/08/2022, 11:01 AM
    Hello, How do I open a new Window in the middle of a @Composable function, and pause the execution while keeping the Window open until it is manually closed?? See thread for code. Thanks!
    s
    • 2
    • 18
  • j

    Jasin Colegrove

    03/08/2022, 11:41 AM
    I have a project that uses ktorm for database access. I am looking to start using compose desktop as the UI, but I am a little confused on how to handle the ViewModel portion that I previously had used in tornadofx. What is the best paradigm to use with compose and is there any solid implementations that I could use as a reference? Google leaves me with more questions than answers atm
    b
    • 2
    • 3
  • z

    zt

    03/08/2022, 11:13 PM
    For whatever reason, I have to move the launched window around directly after building to be able to get things like the context menu to work and DropTarget to work. Is there a fix for this?
    o
    • 2
    • 1
  • d

    Dragos Rachieru

    03/10/2022, 9:38 AM
    Hello, Is there a way to add options to the windows installer to add desktop and start menu shortcuts? I have to manually find the app in program files to run it because it can't be found easily in the windows searchbar
    k
    r
    • 3
    • 2
  • e

    eygraber

    03/10/2022, 6:58 PM
    Maybe someone here will have more info on https://kotlinlang.slack.com/archives/CJLTWPH7S/p1646626860089129 (didn't get any traction in #compose)
    g
    l
    • 3
    • 6
  • s

    Stefan Oltmann

    03/11/2022, 2:29 PM
    I don't see how I can react to the pinch-to-zoom gesture on an Notebook touchpad. On Mac going up and down with two fingers is scrolling like mouse wheel. But how can I detect pinch-to-zoom? I looked at the imageviewer sample which uses
    detectTransformGestures
    . That works on my Android tablet, but does nothing on my MacBooks touchpad.
    👀 4
    k
    • 2
    • 13
  • a

    Alex Styl

    03/13/2022, 5:39 PM
    is there a way to ask for an image file using compose desktop? my use case is letting users select a file from their computer as their profile photo in my app. for anyone doing android, this would be done using the OpenDocument contract (or ACTION_OPEN_DOCUMENT intent)
    ➕ 2
    h
    d
    k
    • 4
    • 9
  • s

    Stefan Oltmann

    03/14/2022, 3:30 PM
    Why are
    androidx.compose.ui.util.fastAny
    and
    androidx.compose.ui.util.fastForEach
    not available?
    ✅ 1
    r
    m
    • 3
    • 4
  • m

    Mario Javier Medina Cocom

    03/14/2022, 6:22 PM
    Hello there, does anyone know if compose desktop has support for emojis?
    x
    • 2
    • 2
  • j

    Jasin Colegrove

    03/15/2022, 9:57 PM
    I've read a lot about state managment and libraries that help like redux, flowredux, decompose, kotlin-bloc etc. But I can't seem to wrap my head around how composables are meant to relate to state and the one that seems to have the proper example, decompose, just seems overly complicated. Searching google is a crap shoot since jetpack is so popular. I'm primarily developing a desktop app, but the state is rather complicated so I'm concerned about state mgmt using just compose. What's the secret recipe that I am missing for someone relativly green?
    c
    b
    +5
    • 8
    • 17
  • j

    Jeanne De ArcRuler

    03/16/2022, 6:06 AM
    what is a good navigation library for the compose desktop?
    b
    m
    a
    • 4
    • 3
  • l

    Long Tran

    03/16/2022, 8:31 AM
    Hi everyone, does anyone know if any 3rd-party library out there supports Compose Desktop to run lotties?
    👀 2
    ❤️ 3
    ❓ 1
    f
    g
    +2
    • 5
    • 7
  • a

    Alex

    03/16/2022, 1:42 PM
    Hi Guys, just started playing around with Compose, and was wonder what's the latest compose version right now
    s
    a
    • 3
    • 3
  • t

    Tim Almdal

    03/17/2022, 10:21 PM
    Hi all. I have been looking for an example of how to change the background of an
    IconButton/Icon
    when the mouse hovers over it. Much like what happens in Winddows, when you move the mouse over the window close button. I stumble on the
    MutableInteractSource
    but haven't found anything that allows me to et the background. Does anyone have any example I could leverage. Thanks
    a
    l
    +2
    • 5
    • 13
  • j

    Jasin Colegrove

    03/18/2022, 12:18 PM
    https://ibb.co/86f9dDq using the platform default, this shows how different the fonts look compare the compose text and the windows title text
    s
    • 2
    • 2
  • t

    theapache64

    03/19/2022, 8:24 AM
    [✅ SOLVED] Is it possible to hide the title bar entirely, but leave the traffic lights and the draggable zone? 🤔
    i
    s
    • 3
    • 9
  • j

    james

    03/19/2022, 11:59 AM
    has anyone had issues trying to get a Compose for Desktop application to get network access on Windows? is there some trick to enabling network connectivity? I'm building an app using a Windows machine for development, and there's nothing I can do with networking that doesn't result in an exception "Connection refused: no further information":
    👀 1
    k
    k
    s
    • 4
    • 9
  • j

    John Aoussou

    03/19/2022, 2:09 PM
    Hello, I'm trying to update a composable using mutableState inside a loop, but it only updates to the last value, after the loop finishes In Main.kt
    @Composable
    fun App() {
        var myClass = remember { MyClass() }
        MaterialTheme {
            Column() {
                Text(text="${myClass.myInt.value}")
                Button(onClick = myClass::run){ Text(text = "RUN") }
            }
        }
    }
    where
    class MyClass {
        val myInt = mutableStateOf(0)
        fun run(){
            for (i in 0..10){
                myInt.value = i
                Thread.sleep(500)
            }
        }
    }
    what am I missing?
    a
    z
    • 3
    • 6
  • d

    David W

    03/19/2022, 7:20 PM
    I have some code that behaves differently when run from a fresh template CfD project's
    runDistributable
    than when run from
    run
    , from a Java CLI jar, or from a Kotlin CLI jar. Here's the full code of the application (the rest is as generated from the CfD template)
    fun main() = application {
        Window(onCloseRequest = ::exitApplication) {
            Button(onClick = {
                ProcessBuilder(
                    "C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6\\starsector.exe"
                )
                    .directory(File("C:\\Program Files (x86)\\Fractal Softworks\\Starsector1.95.1-RC6"))
                    .start()
    
            }) {
                Text("Hello Madness")
            }
        }
    }
    The actual issue is hard to describe;
    starsector.exe
    launches a java-based game that runs on its own jre 7/8. The game crashes only when launched from CfD dist because it's unable to resolve some relative file paths that are passed to it from `starsector.exe`as jvm params. Mimicking the functionality of the
    exe
    with a custom
    java -jar
    thing fixes the issue if I use absolute paths for the game files, but this has other side effects (like any windows compat settings applied to the
    exe
    aren't used since I'm working around it. I don't want to work around the problem; the code works everywhere except as a CfD dist. I can take that
    ProcessBuilder
    code, put it into a pure java or kotlin CLI program, compile a jar, run it, and it'll run the game just fine. Literally it's only when run from
    runDistributable
    (or from the
    .exe
    built from
    createDistributable
    ). Any ideas? What's being done differently by CfD's dist exe?
    a
    a
    • 3
    • 85
  • d

    Dragos Rachieru

    03/21/2022, 10:27 AM
    Hello, I am trying to recreate the viewmodel from android and I don't know how. I want to have a
    viewModelScope
    inside it and use that, so maybe using
    rememberCoroutineScope()
    with it, but I don't know how to do it properly.
    h
    c
    • 3
    • 21
  • r

    Remo

    03/21/2022, 3:22 PM
    Hi there Trying to open a dialog when pressing a button (e.g.
    onClick
    ). Although, getting the compiler error
    @Composable invocations can only happen from the context of a @Composable function
    since
    onClick
    does not seem to accept a
    Composable
    function as argument. What would I need to change in my code to get this work? Code:
    @Composable
    private fun showDialogButton(){
        Button(onClick = {openDialog()}){
            Text("Hello Button")
        }
    }
    
    @Composable
    private fun openDialog(){
        Dialog(onCloseRequest = {}, title = "Dialog"){
            Button(onClick = {}) {
                Text("Close Dialog")
            }
        }
    }
    m
    z
    k
    • 4
    • 9
  • b

    Balaviknesh Sekar

    03/21/2022, 8:30 PM
    Hi guys, I'm not sure how to play sound files in compose desktop. I tried Javax library but it has very limited features. I believe currently there is no support for playing sounds but any idea when we will get that feature ?!
    g
    s
    b
    • 4
    • 5
  • m

    mcpiroman

    03/22/2022, 1:24 PM
    I have finally managed to get ProGuard working with CfD, with native distribution and packaging 🚀 - check out a sample setup . (Bad news is that, at first sight, optimization step does not boost performance in any way. I guess it's just more relevant to Android rather than modern JVM).
    🎉 4
    j
    s
    • 3
    • 4
Powered by Linen
Title
m

mcpiroman

03/22/2022, 1:24 PM
I have finally managed to get ProGuard working with CfD, with native distribution and packaging 🚀 - check out a sample setup . (Bad news is that, at first sight, optimization step does not boost performance in any way. I guess it's just more relevant to Android rather than modern JVM).
🎉 4
j

jw

03/22/2022, 1:30 PM
Have you considered trying R8 instead?
m

mcpiroman

03/22/2022, 1:43 PM
Yeah, I will try that later. Maybe also try to tune PG.
s

spierce7

03/22/2022, 2:27 PM
Does this mean you only have 1 jar shipped with your app?
m

mcpiroman

03/22/2022, 2:45 PM
No, but it's very easy to do that (but, unlike uberjar task, it won't pack non-jar files inside)
View count: 5