koreader/koreader-base

GTK3 filechooser broken in newer GTK3

Frenzie opened this issue · 2 comments

You get this crash:

12/18/18-13:12:37 DEBUG Opening FileChooser: gtk-3
./luajit: ./ffi/filechooser_gtk-3.lua:32: bad argument #1 to 'gtk_dialog_run' (cannot convert 'struct _GtkWidget *' to 'struct _GtkDialog *')
stack traceback:
	[C]: in function 'gtk_dialog_run'
	./ffi/filechooser_gtk-3.lua:32: in function 'open'
	frontend/device/input.lua:316: in function 'waitEvent'
	frontend/ui/uimanager.lua:931: in function 'handleInput'
	frontend/ui/uimanager.lua:979: in function 'run'
	./reader.lua:210: in main chunk
	[C]: at 0x5638956bf170
~/src/kobo/koreader

Crash avoided with some casting, but it gets stuck in the gtk_events_pending() loop.

diff --git a/ffi/filechooser_gtk-3.lua b/ffi/filechooser_gtk-3.lua
index f8dbb9f..37f858c 100644
--- a/ffi/filechooser_gtk-3.lua
+++ b/ffi/filechooser_gtk-3.lua
@@ -21,7 +21,7 @@ Proof of concept, https://github.com/Alloyed/nativefiledialog might be better.
 function FileChooser:show(action, button, title)
     gtk.gtk_init(nil, nil)
 
-    local d = gtk.gtk_file_chooser_dialog_new(
+    local dialog = gtk.gtk_file_chooser_dialog_new(
         title,
         nil,
         action,
@@ -29,10 +29,10 @@ function FileChooser:show(action, button, title)
         button, ffi.cast("const gchar *", gtk.GTK_RESPONSE_OK),
         nil)
 
-    local response = gtk.gtk_dialog_run(d)
-    local filename = gtk.gtk_file_chooser_get_filename(d)
+    local response = gtk.gtk_dialog_run( ffi.cast("GtkDialog *", dialog) )
+    local filename = gtk.gtk_file_chooser_get_filename( ffi.cast("GtkFileChooser *", dialog) )
 
-    gtk.gtk_widget_destroy(d)
+    gtk.gtk_widget_destroy(dialog)
 
     while gtk.gtk_events_pending() do
         gtk.gtk_main_iteration()
pazos commented

If we can skip crosscompilation I think we can use DearImgui to build a quick & fast file chooser with awesome retrofuturistic look.

There's also a cross-platform library that can integrate with native dialogs. This FFI GTK3 one was kind of a passing thought/experiment/proof of concept. I thought it worked out very well after using it for a couple of weeks. (But mainly I just drag & drop.)