lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
433 stars 68 forks source link

Does lgi support Gtk4? #278

Open JeysonFlores opened 2 years ago

JeysonFlores commented 2 years ago

Hi, I was considering using Lgi with Fennel for one of my future projects. However I develop apps for the eOS platform, and in the next months they'll be releasing Gtk4 (only for developers) to start working on it. So I was wondering Lgi supports (at least decently) Gtk4. It seems one of the latest commits was about not getting errors on Gtk but I don't think that means a full support of the new version of Gtk. Also, if the answer is no, Do you plan to give support to Gtk4 in the near future? Thanks

Scupake commented 2 years ago

Currently, I don't think so. https://github.com/pavouk/lgi/issues/226

jdeut commented 2 years ago

the introspection of gtk4 works after #273 at least on my setup. Until now i have encountered no crashes which i would assign to lgi

image

JeysonFlores commented 2 years ago

@jdeut Oh, those are good news. I'll try it by myself to see if it works

ousia commented 2 years ago

@JeysonFlores, did it work for you?

I mean, maybe support is already there (and this issue could be closed).

aum7 commented 1 year ago

the introspection of gtk4 works after #273 at least on my setup. Until now i have encountered no crashes which i would assign to lgi

image

i tried this, no luck, does not work for me linux mint 21.1

tried with gtk3, works like a charm

aum7 commented 1 year ago

using linux mint 21.1 vera (latest, greatest of them all lol) testing with https://github.com/Miqueas/Lua-GTK-Examples/blob/master/GtkApplication.lua i changed local gtk = lgi.require('Gtk', '3.0') to ... lgi.require('Gtk','4.0') gtk4-dev etc is installed on my sistem running the example file with luajit, i get an error : luajit: /usr/local/share/lua/5.1/lgi/override/Gdk.lua:23: bad argument #1 to 'registerlock' (userdata expected, got nil) is it possible that someone helps me solve this issue, so i can use gtk4 with lgi ?

thank you, bow

aum7 commented 1 year ago

also, seems that something has been done in direction to make lgi be used with gtk4, but those commits were done in 2021, while lgi main page says ... history ... 0.9.2 (9-Oct-2017) therefore last update was in 2017 ? and there is a thread saying ... psychon deleted the gtk4 branch last year

i am so confused

i have installed lgi with luarocks please install lgi and luarocks show lgi gives version lgi 0.9.2-1 that is, ad 2017 version ?

if i git clone and build / compile on my system, should this update lgi to version with 'let's make lgi work with gtk4' commits included ?

godspeed

aum s love nia

Aire-One commented 1 year ago

Hello @aum7. Yeah, the release cycle of LGI is a mess. Currently, the latest release is the one version from 2017. It's the version distro packages should be, and also the one you'll install by default with Luarocks.

To use the latest developments from here, you have to either, manually build from sources, or use the rockspec file from https://github.com/lgi-devs/lgi/pull/305 as described in the PR message.

aum7 commented 1 year ago

@Aire-One thank you for the clear & useful answer

since i am low-level programmer (lol, meaning not an experienced one), i would like to clarify, before i (again) brake my os (though i recently got used to do dev in qemu vm) 1) $ luarocks uninstall lgi 2) $ luarocks install https://raw.githubusercontent.com/lgi-devs/... 3) use lgi as nothing has changed = use same directives / includes etc but now i will have latest dev version, which should allow me to use gtk4 lib ?

thank you for your help, really appreciate

ps : is there a particular reason that public version has not been updated, especially since gtk4 is already mature for few years now ? (i might be wrong here.) and this is really useful binding, afaik. just curious

pps: if i ask devs for public update, will it make any difference ?

have fun

aum s love nia

Aire-One commented 1 year ago
  1. $ luarocks uninstall lgi
  2. $ luarocks install https://raw.githubusercontent.com/lgi-devs/...
  3. use lgi as nothing has changed = use same directives / includes etc but now i will have latest dev version, which should allow me to use gtk4 lib ?

Looks good to me.

pps: if i ask devs for public update, will it make any difference ?

It wouldn't change much. We already have this request on other threads... The SCM rockspec is actually a community initiative to distribute an up-to-date version.

aum7 commented 1 year ago

he he he community rules !

while installing lgi, i got compiler warnings and send bug report to glib2.0 devs i just got reply from them that i should file bug report with lgi quote : "You should open an issue against the Lua bindings, as they are using deprecated API." and i replied to them that it would probably be a futile attempt since last public commit was in 2017

i might nevertheless try it, can not hurt, wright ? lol

thanks for your help

have fun godspeed

Aire-One commented 1 year ago

while installing lgi, i got compiler warnings and send bug report to glib2.0 devs i just got reply from them that i should file bug report with lgi quote : "You should open an issue against the Lua bindings, as they are using deprecated API."

This is indeed an issue on our side. You can silently ignore these warnings. They are just deprecation notices because LGI still uses ancient libraries. It shouldn't affect your work.

aum7 commented 1 year ago

all hail aireone ! removed old, & installed new luarocks lgi lib tested with few gtk3 examples, including one above, from jdeut works like a charm i can now use lgi with gtk4 i am soon to be 48 years old, and i feel like a little kid with new toy (lgi / gtk) with new batteries (lunar vim) lol thank you aire-one & thank you all developers bow

have fun aum s love nia

aum7 commented 1 year ago

just for the sake of completeness, here is a reply from glib devs : quote

The warnings come from lgi using deprecated GLib API. GLib has nothing to do with it. The appropriate fix is for lgi not to use deprecated API. If they wish to continue using deprecated API while avoiding the compiler warnings that come from that choice, then they have two options:

use a blanket #define GLIB_DISABLE_DEPRECATION_WARNINGS before including the GLib headers
define GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED, to define the minimum required version of GLib they depend on (and only get deprecation warnings if they try to use a symbol that was deprecated in earlier versions) and the maximum required version of GLib they allow (and get warnings if they try use API provided by a newer version of GLib).

quote end

have fun

aum7 commented 1 year ago

not sure, maybe this is not a good place for such questions, i trust you will let me know ;)

i would kindly ask if someone can offer some help : i have succeeded with compiling my gtk(4) app, using .ui (.glade, xml) builder file but would like to code the gui from scratch, using lgi & gtk4, and lua i have peeked into lgi/samples/gtk-demo, trying to convert those gtk3 examples into gtk4 i did manage to get a basic, empty application / window, in gtk4 but, (there is always but lol) proceeding with code, i got stucked, ie lgi/samples/gtk-demo/demo-application.lua file, line 10

-- Register icon. Gtk.stock_add { Gtk.StockItem { stock_id = 'demo-gtk-logo', label = "_GTK!", } }

gives me a runtime error because gtk4 switched to freedesktop icon theme specs for icon manipulation it seems i need to use gtk.image and there are more examples of code that does not work in gtk4 and i have a hard time converting it to gtk4

qs: 1) can somebody please share their lgi/gtk4 code, as an examples ?

2) best thing for a beginner like me would be to use gtk4 docs, and use that for coding. problem : original code is in c language, and i am not familiar with how to convert that to lgi / lua. yes, i did read lgi/docs/*.md files, but the text is way above my coding skills, beside, i learn best with images i would kindly ask for an example, how can an api doc (https://gtk.org/gtk4/) be used / converted into lgi / lua code

3) my ide (lunarvim) does not give me code completion / intellisense suggestions, which could help me with gtk.___ code; therefore i thought, if i dump whole lgi / gtk library, i might have some insight into gtk4 code, what and how can i access so i tried with the code, found in lgi/docs/guide.md file

dump(Gtk.Widget:_resolve(true), 3)

which again gives me an runtime error ( attempt to call global 'dump' (a nil value) ), this time i guess because i do not have cli-debugger lua package. neither luarocks nor uncle google knows anything about this package. dead end for me. therefore i am asking for a help with dumping the whole gtk4 lib, which might help me learn more about its guts

i am particularly interested in :

using lnx mint 21.1

thank you for your understanding

godspeed

aum7 commented 1 year ago

while browsing some more, i might have found partial answer to q2 : comparing code from demo-application.lua and gtk3 online docs, plus gtk4 docs, i tried a gtk4 code :

local icon = gtk_image_new_from_file('path/to/file.png')

then it occurred i might try :

local icon = gtk.Image.new_from_file(...)

running the code produced no error. good.

now i need to use this icon.

how ?

aum7 commented 1 year ago

olo i am still trying to use / convert lgi gtk3 samples, into gtk4 code i have posted my question on stackexchange : https://stackoverflow.com/questions/75534970/gtk4-lgi-luajit-how-to-draw-area-with-cairo

kindly asking for a help, i got stuck here thank you have fun

godspeed

Aire-One commented 1 year ago

Recent finding: Here is a repository with some GTK4 code examples in Lua with LGI https://github.com/Miqueas/GTK-Examples/tree/main/lua/gtk4 that can be used as references. (CC @Miqueas)

Miqueas commented 1 year ago

Recent finding: Here is a repository with some GTK4 code examples in Lua with LGI https://github.com/Miqueas/GTK-Examples/tree/main/lua/gtk4 that can be used as references. (CC @Miqueas)

Yes, the repo isn't so much very active, but in there you may found useful examples

aum7 commented 1 year ago

thanks for update

have fun

aum

ghost commented 1 year ago

Fellas, i poked around and found out. id-based widget referencing and nested-dictionary widget constructors don't work.

Here's some investigative work:

Not sure what's going on here. Do these features rely on the now nonexistant Container class? is this even supposed to work on anything other than version 3?

Paste and run this lua code for a blank window (It's supposed to have a button)

Snippet: lgi gtk4 window (from constructors)

```lua lgi = require 'lgi' gtk = lgi.require('Gtk','4.0') local app= gtk.Application{application_id = 'org.phicross.gtk4lua.intro'} local handles = {application = app} function app:on_startup() end function app:on_activate() handles.window = gtk.ApplicationWindow{ id = 'theWindow', application = self, title = "intro app.", default_width = 200, default_height = 200, gtk.Grid { id='atop', orientation = gtk.Orientation.VERTICAL, gtk.Button { id = "theButton", gtk.Label{ id = 'intro', label = 'whatsup.' } , on_clicked = function(self) print 'did you just slap me?' end } } } handles.window:show() end app:run(arg) ```

Now paste and run this new (ugly) version, and this time the button shows up.

Snippet: lgi gtk4 window (explicitly setting hierarchy)

```lua lgi = require 'lgi' gtk = lgi.require('Gtk','4.0') local app= gtk.Application{application_id = 'org.phicross.gtk4lua.intro'} local handles = {application = app} function app:on_startup() end function app:on_activate() handles.window = gtk.ApplicationWindow{ application = self, title = "intro app.", default_width = 200, default_height = 200 } handles.atop = gtk.Box{ orientation = gtk.Orientation.VERTICAL} handles.window:set_child(handles.atop) print('ready.') handles.theButton = gtk.Button { label = 'slap', on_clicked = function(self) print 'did you just slap me?' end } handles.atop:append(handles.theButton) function handles.theButton:on_clicked() print 'overriden click callback.' end handles.window:show() end app:run(arg) ```

Aire-One commented 1 year ago

@PhiCross5 that's probably a copy/past issue, but your first snippet can't work because the line function app:on_startup() is out of its place. It either shouldn't be there, or should have a proper body.

ghost commented 1 year ago

@PhiCross5 that's probably a copy/past issue, but your first snippet can't work because the line function app:on_startup() is out of its place. It either shouldn't be there, or should have a proper body.

Oops, sorry about that. Both the snippets had been improperly pasted, so i fixed them now.

ghost commented 1 year ago

Early work in GTK4 migration

As of #313 , nested constructors work again on GTK4, but only for Boxes.

Containers were the secret sauce.

Nested constructors were one of the custom niceties provided by lgi's internal GTK override. In GTK3, they relied on methods from the Container class. However, as of GTK4, Containers don't exist anymore, thus not only us, but also any other binding that wrapped that class, will now have to swtich from Container.add() to the specific methods of each subclass, as in: Box.append(), Grid.attach(), Paned.set_start_child() and others.

Help us migrate

Contributors are welcome to help reimplement these wrappings or propose a new way to describe a widget hierarchy neatly in lua code without somehow bringing back "the diddly gosh darned Generic Containers" GTK4 wants everyone to drop so much. I intend on discussing this more carefully when i come up with a pull request (re)covering more of those container classes.

What to do if "i want GTK4 now"

Just like any other C library with a G-Introspection package available for it, you can use the methods directly as if they were just renamed C functions under a namespace. Because lgi does support GTK4, it just doesn't have all the fancy object-oriented bindings for it like it did for GTK3. When in doubt, follow the C examples by GTK themselves and convert the functions to lgi's calling convention (it is described in the documentation)