summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2019-10-27 12:34:02 +0100
committerCamil Staps2019-10-27 12:34:02 +0100
commit8b94854da995a34790d194dcc01b654409e77593 (patch)
tree68f2cb72a2531992cf6c766b9eb7d99d0e708d60
parentAdd getCellText for GtkSheet (diff)
Add runWhileEventsPending to be able to show something before starting a long task on the main thread
-rw-r--r--src/Gtk/Internal.dcl2
-rw-r--r--src/Gtk/Internal.icl5
-rw-r--r--src/Gtk/State.dcl1
-rw-r--r--src/Gtk/State.icl9
4 files changed, 17 insertions, 0 deletions
diff --git a/src/Gtk/Internal.dcl b/src/Gtk/Internal.dcl
index fe5b749..450700a 100644
--- a/src/Gtk/Internal.dcl
+++ b/src/Gtk/Internal.dcl
@@ -32,6 +32,8 @@ gtk_dialog_run :: !Pointer !.a -> (!Int, !.a)
gtk_dialog_set_default_response :: !Pointer !Int !.a -> .a
gtk_dialog_set_modal :: !Pointer !Bool !.a -> .a
+gtk_events_pending :: !.a -> (!Bool, !.a)
+
gtk_file_chooser_add_filter :: !Pointer !Pointer !.a -> .a
gtk_file_chooser_dialog_new :: !(Maybe String) !Pointer !Int ![(String,Int)] !.a -> (!Pointer, !.a)
gtk_file_chooser_get_filename :: !Pointer !.a -> (!Maybe String, !.a)
diff --git a/src/Gtk/Internal.icl b/src/Gtk/Internal.icl
index 55d5744..e3982dd 100644
--- a/src/Gtk/Internal.icl
+++ b/src/Gtk/Internal.icl
@@ -111,6 +111,11 @@ gtk_dialog_set_modal dialog setting env = code {
ccall gtk_dialog_set_modal "pI:V:A"
}
+gtk_events_pending :: !.a -> (!Bool, !.a)
+gtk_events_pending _ = code {
+ ccall gtk_events_pending ":I:A"
+}
+
gtk_file_chooser_add_filter :: !Pointer !Pointer !.a -> .a
gtk_file_chooser_add_filter chooser filter env = code {
ccall gtk_file_chooser_add_filter "pp:V:A"
diff --git a/src/Gtk/State.dcl b/src/Gtk/State.dcl
index 43b5869..c4e17a2 100644
--- a/src/Gtk/State.dcl
+++ b/src/Gtk/State.dcl
@@ -41,3 +41,4 @@ appWorld :: !(*World -> *World) -> GtkM ()
accWorld :: !(*World -> (r,*World)) -> GtkM r
quit :: GtkM ()
+runWhileEventsPending :: GtkM ()
diff --git a/src/Gtk/State.icl b/src/Gtk/State.icl
index 4db51af..32c2b19 100644
--- a/src/Gtk/State.icl
+++ b/src/Gtk/State.icl
@@ -107,3 +107,12 @@ worldToVoid _ = ()
quit :: GtkM ()
quit = modState (\st -> {st & return=True}) >>| pure ()
+
+runWhileEventsPending :: GtkM ()
+runWhileEventsPending =
+ toStateR gtk_events_pending >>= \pending
+ | not pending ->
+ pure ()
+ | otherwise ->
+ toStateR gtk_main_iteration >>|
+ runWhileEventsPending