Closed gavr123456789 closed 3 years ago
Is this a request to add that bindings to the gintro package, or a statement that you are currently working on adding them?
For the later case: When you provide at least one working, high level example application then I think we can integrate it to gintro. High level means no use of cast and addr at least.
For the former case: I would have to ask Gnome/GTK core devs what LibAdwaita is and if it makes sense to add it. The reason is that I added a few libs by user request, including libhandy, libnice, webkitgtk and gstreamer. And it was not a really smart decision from my side: libnice is very low level and generated a lot of trouble, and for the other 3 libs the guys who requested it vanished very fast.
This is a request. I looked through other issues looking for an example of a request, but I didn't find them.
This is a request.
OK. When the GTK/Gnome devs think that adding makes sense then I will try to add it. With some luck it is only adding a line to gen.nim script. But of course I have to search for a C or Python example and convert that to Nim.
Will I be able to test an example on PC, or do I need a mobile device for testing? And does Adwaita lib work with GTK4 already?
I just remembered
https://github.com/StefanSalewski/gintro/issues/110
Never heard again from that guy also, and unfortunately that lib does not work on PC at all, so we have no example yet.
guys who requested it vanished
Yes, I found a request to add webkitgtk. I even contacted Adam Dingle in the mail to find out the details. Can you explain why it was a bad decision? I did not understand the mechanism of gintro, but if it takes information from the GIR, do you need any additional manipulations? I mean, the whole point of GIR's existence is to be able to create automatic bindings without manual intervention.
LibAdwaita is not a low-level library. This is a library that extends the set of GTK widgets. It was originally created by purism to adapt GTK for their smartphone. But many widgets turned out to be extremely useful in desktop applications, after which LibHandy was renamed LibAdwaita(which shows that it is now a more general library, and not only for devices with a small screen)
As an experiment, I wanted to rewrite some simple GTK application to Nim(I'm trying to switch from Vala now). My choice fell on https://github.com/lainsce/khronos/ but it, like many, uses LibAdwaita.
Here are some examples that I found by going through the list of https://circle.gnome.org/
https://gitlab.gnome.org/World/Authenticator/-/blob/master/meson.build#L11
https://gitlab.gnome.org/somas/apostrophe/-/blob/master/meson.build#L48
https://gitlab.gnome.org/Cogitri/Health/-/blob/master/Cargo.toml#L16
https://github.com/GustavoPeredo/Font-Downloader/blob/master/meson.build#L13
https://gitlab.gnome.org/World/Shortwave/-/blob/master/meson.build#L16
why it was a bad decision?
Webkit was not that bad, was not much work to add it. But it is a very large lib, so it increases install time by a few seconds, and large libs have always some minimal risk that they will break the install process.
gstreamer and libnice causes much trouble, libnice maybe 40 hours of work for me, and gstreamer maybe 20 hours. Because both contained a lot low level stuff, and I do know nothing about that packages, so it was hard for me to port libnice example from C to Nim. But at least libnice is still used by someone from japan, and adding these packages improved the gen.nim bindings generator. But it is unclear for what someone will use Nim with gstreamer or webkitgtk.
LibHandy was renamed LibAdwaita
Interesting, I was not aware of it.
trying to switch from Vala now
OK, then you know GTK at least. The largest burden are request for packages from people with no GTK knowledge. Learning GTK is much work, and chances that newcomers will learn GTK and Nim are very tiny. I started the GTK4 book to make that possible, but the book is only 20% complete currently, and I am not sure if I will continue with it.
Do you have any chat in discord or tg about gintro?
Will I be able to test an example on PC, or do I need a mobile device for testing?
Ofc you dont, just the reason why handy was renamed to Adwaita is to show that it is no longer a library for devices with small screens, but just a GTK extension. (The standard theme is also called Adwaita)
And ye, ur gnome-settings using libhandy rigth now when you squeeze it
https://gitlab.gnome.org/GNOME/gnome-control-center/-/blob/master/meson.build#L102
Do you have any chat in discord or tg about gintro?
No, would not make too much sense for currently 1 to 2 active gintro users beside me, and I am not a guy who has the time to sit the whole day in front of a discord or IRC window. (Note, the other requested lib called GtkLayerShell was mobile only, so I was not able to test it.)
I will try to provide you with the LibAdwaita lib soon, will do first try tomorrow. I am a bit busy currently, as always...
First problem: Gentoo linux does not have LibAdwaita at all. So I have to install from sources, which sometimes works well, sometimes not. We will see tomorrow. LibAdwaita seems to be really a new development, see
https://aplazas.pages.gitlab.gnome.org/blog/blog/2021/03/31/introducing-libadwaita.html
OK, I was able to install latest libadwaita from git sources and I have added it to the gen.nim generator:
diff ~/gintrotest/tests/gen.nim gen.nim
1c1
< # High level gobject-introspection based GTK4/GTK3 bindings for the Nim programming language
---
> # High level gobject-introspection based GTK3/GTK4 bindings for the Nim programming language
3,4c3,4
< # v 0.8.9 2021-APR-11
< # (c) S. Salewski 2018, 2019, 2020, 2021
---
> # v 0.8.9 2021-MAR-16
> # (c) S. Salewski 2018
98,120d97
< AdwInit = proc (argc: ptr cint; argv: ptr ptr cstring) {.cdecl.}
<
< proc tryInitAdw(): LibHandle =
< # echo "Try to init gst"
< when defined(windows):
< const AdwLibName = "adwaita-1-0.dll"
< elif defined(macosx):
< const AdwLibName = "libadwaita-1.dylib"
< else:
< const AdwLibName = "libadwaita-1.so(|.0)"
< let adwLib = loadLibPattern(AdwLibName) # dlopen
< if adwLib != nil:
< let adwInit = cast[AdwInit](adwLib.symAddr("adw_init"))
< if adwInit != nil:
< adwInit(nil, nil)
< else:
< echo "Can't init adw library!"
< else:
< echo "Can't load adw library!"
< return adwLib
< # unloadLib(adwLib)
<
< type
143,145d119
<
<
<
3317d3290
< adwLib: LibHandle
3355,3357d3327
< if namespace == "Adw" and adwLib == nil:
< adwLib = tryInitAdw()
<
4063d4032
< main("Adw") # replaces libhandy for GTK4
4107,4108d4075
< if adwLib != nil:
< unloadLib(adwLib)
4125c4092
< # 4125 lines
---
> # 4092 lines
Generally only adding the line "main("Adw") # replaces libhandy for GTK4" would have been necessary, but as libadwaita expects that init_adw() is called before that lib is used, the gtk core devs told me that in that case I should open the lib before using gobject-introspection on it. For some gst modules that is indeed necessary, for libadwaita it seems to work without too. The dopen() solution is not too nice, as we have to guess the actual lib names for linux, windows and mac.
The lib installs and compiles fine for me, but I was not yet able to provide an example. The old libhandy example does not work. The libadwaita provides an C example, but as that is not tiny I was not yet able to port it to Nim. I found no other examples, no Python one. The C example uses gtk builder. Unfortunately I do know nothing about libadwaita currently, so it may take me some time before I can provide a working Nim example.
You can install it with
nimble install gintro@#head
Maybe ask on Gnome forum or Nim forum for actual help with an example, I am really busy, I don't think I can do more today.
You may have to wait some time for a working example unfortunately, see
https://discourse.gnome.org/t/libadwaita-simple-nim-example/6109
All works. See #122 carousel example.
It seems that every new GTK application uses LibAdwaita now, and the old ones are also ported to it.