Implemented the modal queue on the GTK+ backend to ensure proper queue ordering.

This commit is contained in:
Pietro Gagliardi 2014-08-19 13:33:06 -04:00
parent a3ff63490b
commit d07230e55e
2 changed files with 16 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import (
) )
// #include "gtk_unix.h" // #include "gtk_unix.h"
// #include "modalqueue.h"
// /* because cgo doesn't like ... */ // /* because cgo doesn't like ... */
// GtkWidget *newOpenFileDialog(void) // 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_local_only(fc, C.FALSE)
C.gtk_file_chooser_set_select_multiple(fc, C.FALSE) C.gtk_file_chooser_set_select_multiple(fc, C.FALSE)
C.gtk_file_chooser_set_show_hidden(fc, C.TRUE) C.gtk_file_chooser_set_show_hidden(fc, C.TRUE)
inmodal = true C.beginModal()
response := C.gtk_dialog_run(dialog) response := C.gtk_dialog_run(dialog)
inmodal = false C.endModal()
if response != C.GTK_RESPONSE_ACCEPT { if response != C.GTK_RESPONSE_ACCEPT {
return "" return ""
} }

View File

@ -12,7 +12,8 @@ import (
// #cgo pkg-config: gtk+-3.0 // #cgo pkg-config: gtk+-3.0
// #cgo CFLAGS: --std=c99 // #cgo CFLAGS: --std=c99
// #include "gtk_unix.h" // #include "gtk_unix.h"
// extern gboolean doissue(gpointer data); // #include "modalqueue.h"
// extern gboolean xdoissue(gpointer data);
import "C" import "C"
func uiinit() error { func uiinit() error {
@ -36,17 +37,19 @@ func uistop() {
} }
func issue(f *func()) { 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! //export xdoissue
var inmodal = false func xdoissue(data C.gpointer) C.gboolean {
//export doissue
func doissue(data C.gpointer) C.gboolean {
if inmodal {
return C.TRUE // wait for modal dialog to finish
}
perform(unsafe.Pointer(data)) perform(unsafe.Pointer(data))
return C.FALSE // don't repeat return C.FALSE // don't repeat
} }
//export doissue
func doissue(data unsafe.Pointer) {
// for the modal queue functions
perform(data)
}