has anyone tried to make a kotlin gtk app?
# gui
m
has anyone tried to make a kotlin gtk app?
m
I tried. At that moment the easiest way was to take the libui. There is also a repository with finished artifacts on bintray. You can see it on my project. The good way would be to have a nice DSL like with libui, or to be able to take the XML from the Gnome Designer (Glade).
m
Yeah the kotlin-native-gtk provides a DSL, it generates it from the GIR XML provided by gtk
👍 1
I was able to build and run the sample
message has been deleted
The sample code looks pretty decent, very similar to tornadofx or well any GUI with kotlin DSL I've seen so far:
Copy code
vbox {
            hbox {
                hbbox {
                    button {
                        label = "Quit"
                        onClicked {
                            println("Quit Kotlin GTK!")
                            this@createWindow.destroy()
                        }
                    }
                    button {
                        label = "File Manager"
                        onClicked {
                            fileManager().showAll()
                        }
                    }
                }
m
Cool, you're right, it looks pretty good. Btw do you know this project? https://github.com/kavanmevada/kotlin-native-gtk-linux
m
yeah I was looking at it earlier today
it uses the gtk c interface directly, the kotlin-native-gtk library gives you the easier to use kotlin DSL
m
I agree. A pretty DSL and/or UI file and binding only. This is the goals of mine. But still, one more problem: threads and async. Again in my example project, I don't know how to do async I/O operations without crashing (because of the freezed object) 😁
m
Most GUIs require you to update the GUI in the main thread so your other threads have to push any data to the GUI thread, but I'm sure how you do that is highly specific to each GUI framework
b
this is cool!
m
It's really promising
b
I didn't manage to build the kavanmevada project
Copy code
A problem occurred evaluating root project 'weather'.
> Could not create task ':cinteropLibgtk3Linux'.
   > Could not create task of type 'CInteropProcess'.
      > 'org.gradle.api.file.RegularFileProperty org.jetbrains.kotlin.gradle.tasks.CInteropProcess.newOutputFile()'
m
yeah I'm not sure about that project, what you want is this: https://github.com/kropp/kotlin-native-gtk
although you should clone the forked version that has a number of updates
it only builds on linux at the moment
b
will have to redo the work for GTK4 soon 😉
m
I may take a stab at updating it for other platforms just to see if/how well it works
only if you really really need GTK4
b
when is GTK3 going to be deprecated?
m
¯\_(ツ)_/¯
b
building
wow building times are pretty long
m
yep, it is faster if you update the kotlin version to 1.4.10
b
42s for the sample. That machine compile a linux kernel in <=2min
m
but if you already started it will take longer to restart 😛
b
yes I moved everything to 1.4.10
it refused to compile at all without that
had to upgrade gradle as well
m
right, need at least gradle 6
b
oh my ❤️ an application that starts in milliseconds
m
I would update and make a PR but dude never accepted the one from drieks
b
well that would require a new project …
m
only a couple MB executable as well and runs fast
b
oh that was my next step to look at
m
what linux system did you build it on? I had to edit the include path to get it to build on kubuntu 20.04
b
archlinux
I had to add harfbuzz include
m
yeah same here
b
do you know what those generated kotlin files are?
what is making them?
m
yeah
its the code in the kngtk-generator
it reads the GIR XML and generates the kotlin code from it
b
neat
m
yeah works pretty well as far as I can tell
b
below 2MB if you strip the binary
m
of course, that's what GIR was made for I think, to help other languages create bindings
b
that's a lot of moving pieces
m
it's just projects that have used GIR so other languages can use GTK
this project should be on the list
b
yes yes
I was talking about what is necessary to get gtk running on kotlin native
m
ah
it didn't look too bad to me
The CInterop allows using the GTK c interfaces
then the kotlin-native-gtk project made it easier to use
using straight GTK from CInterop is ugly