1. Wrap Callback Question
- Posted by Icy_Viking 3 months ago
- 360 views
Hi all,
After going through and looking at GTK, I think I'm gonna at least take a crack at trying to wrap GTK 4. However I'm a bit confused on how I'd wrap this callback function.
C Code [https://docs.gtk.org/gtk4/getting_started.html]
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv);
Possible Eu Code
public constant xg_signal_connect = define_c_func(gtk,"+g_signal_connect",{C_POINTER,C_STRING,C_POINTER,C_POINTER},C_POINTER) public constant xg_application_run = define_c_func(gtk,"+g_application_run",{C_POINTER,C_POINTER,C_STRING},C_POINTER) public function g_signal_connect(atom app,sequence cmd,atom cb,atom x) return c_func(xg_signal_connect,{app,cmd,cb,x}) end function public function g_application_run(atom app,atom argc,sequence argv) return c_func(xg_application_run,{app,argc,argv}) end function
The above eu code is basically pseudo code for now. I'm just trying to guess how I'd wrap that, callbacks still kinda throw me off.
NOTE: For those wondering where C_STRING comes from, I'm using Greg's FFI Euphoria library which has a nice C_STRING type to help with wrapping strings and structs. You can find it here [https://github.com/ghaberek/libffi-euphoria]
2. Re: Wrap Callback Question
- Posted by petelomax 3 months ago
- 316 views
GTK does not export g_signal_connect(), it is a C macro that invokes g_signal_connect_data() with the last two params as NULL, 0. [at least in GTK2/3, that is]
There are a whole bunch of examples for that in xpGUI, note that in Phix you can just say xpg_gtk_release_key where Euphoria needs routine_id("xpg_gtk_release_key")
Likewise in Phix you can just throw a string directly at c_func(), but in Euphoria you have to allocate_string() or similar - that cmd above is never gona work, ditto argv.
As for g_application_run, I'm afraid I can't help you with that. For GTK2/3 I use gtk_main() but it seems they've ripped that out
and the best information I can find, with the obligatory 404 doc link, is https://github.com/vmagnin/gtk-fortran/issues/163
As you will find, the GTK docs truly suck, and clearly the development team know that and constantly try to rearrange them into
something better, which means that all external links to the documentation that are more than ~17mins old will 404. Personally,
I always got far more useful information from searching the source code, where you'll find almost all the heredocs from which all
that gendoc generated garbage comes from anyway [not that I can be certain of that for GTK4].
(Actually, by comparison the GTK2 docs where pretty decent, but they've been on a steep downward trajectory ever since - prettier, sure, less useful, without a shadow.)
3. Re: Wrap Callback Question
- Posted by axtens_bruce 3 months ago
- 260 views
There are other cross-platform graphics libraries. E.g. nuklear on Github
-Bruce