From d07230e55e6c1b001cd09e03816710e66a34e7f4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 19 Aug 2014 13:33:06 -0400 Subject: [PATCH] Implemented the modal queue on the GTK+ backend to ensure proper queue ordering. --- redo/dialog_unix.go | 5 +++-- redo/uitask_unix.go | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/redo/dialog_unix.go b/redo/dialog_unix.go index 6a16ac6..a4020aa 100644 --- a/redo/dialog_unix.go +++ b/redo/dialog_unix.go @@ -9,6 +9,7 @@ import ( ) // #include "gtk_unix.h" +// #include "modalqueue.h" // /* because cgo doesn't like ... */ // GtkWidget *newOpenFileDialog(void) // { @@ -29,9 +30,9 @@ func openFile() string { C.gtk_file_chooser_set_local_only(fc, C.FALSE) C.gtk_file_chooser_set_select_multiple(fc, C.FALSE) C.gtk_file_chooser_set_show_hidden(fc, C.TRUE) - inmodal = true + C.beginModal() response := C.gtk_dialog_run(dialog) - inmodal = false + C.endModal() if response != C.GTK_RESPONSE_ACCEPT { return "" } diff --git a/redo/uitask_unix.go b/redo/uitask_unix.go index d330e4b..86628dd 100644 --- a/redo/uitask_unix.go +++ b/redo/uitask_unix.go @@ -12,7 +12,8 @@ import ( // #cgo pkg-config: gtk+-3.0 // #cgo CFLAGS: --std=c99 // #include "gtk_unix.h" -// extern gboolean doissue(gpointer data); +// #include "modalqueue.h" +// extern gboolean xdoissue(gpointer data); import "C" func uiinit() error { @@ -36,17 +37,19 @@ func uistop() { } func issue(f *func()) { - C.gdk_threads_add_idle(C.GSourceFunc(C.doissue), C.gpointer(unsafe.Pointer(f))) + if C.queueIfModal(unsafe.Pointer(f)) == 0 { + C.gdk_threads_add_idle(C.GSourceFunc(C.xdoissue), C.gpointer(unsafe.Pointer(f))) + } } -// TODO this is not order-safe! -var inmodal = false - -//export doissue -func doissue(data C.gpointer) C.gboolean { - if inmodal { - return C.TRUE // wait for modal dialog to finish - } +//export xdoissue +func xdoissue(data C.gpointer) C.gboolean { perform(unsafe.Pointer(data)) return C.FALSE // don't repeat } + +//export doissue +func doissue(data unsafe.Pointer) { + // for the modal queue functions + perform(data) +}