aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-09-19 16:53:02 +0200
committerStapleButter <thetotalworm@gmail.com>2017-09-19 16:53:02 +0200
commitedd33187b630d705b9915b7cf34fb76307db4d1e (patch)
tree6622b3500066852a7752c198f471d11b8ec93ce9 /src
parent4db1a51fa4cb6412c76a37329d23a00478c9f9ef (diff)
GTK: thread-safe refresh. doesn't freeze randomly anymore.
Diffstat (limited to 'src')
-rw-r--r--src/libui_sdl/libui/unix/area.c17
-rw-r--r--src/libui_sdl/libui/unix/main.c6
-rw-r--r--src/libui_sdl/libui/unix/window.c2
-rw-r--r--src/libui_sdl/main.cpp4
4 files changed, 24 insertions, 5 deletions
diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c
index c46447c..d0042e6 100644
--- a/src/libui_sdl/libui/unix/area.c
+++ b/src/libui_sdl/libui/unix/area.c
@@ -1,6 +1,8 @@
// 4 september 2015
#include "uipriv_unix.h"
+extern GThread* gtkthread;
+
// notes:
// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14)
#define areaWidgetType (areaWidget_get_type())
@@ -387,7 +389,7 @@ static int areaKeyEvent(uiArea *a, int up, GdkEventKey *e)
ke.Key = 0;
ke.ExtKey = 0;
ke.Modifier = 0;
-
+printf("keypress: %08X\n", e->hardware_keycode-8);
state = translateModifiers(e->state, e->window);
ke.Modifiers = toModifiers(state);
@@ -501,9 +503,20 @@ void uiAreaSetSize(uiArea *a, int width, int height)
gtk_widget_queue_resize(a->areaWidget);
}
+gboolean _threadsaferefresh(gpointer data)
+{
+ uiArea* a = (uiArea*)data;
+ gtk_widget_queue_draw(a->areaWidget);
+ return FALSE;
+}
+
void uiAreaQueueRedrawAll(uiArea *a)
{
- gtk_widget_queue_draw(a->areaWidget);
+ // TODO: figure out how we could generalize the "thread-safe function call" mechanism
+ if (g_thread_self() != gtkthread)
+ g_idle_add(_threadsaferefresh, a);
+ else
+ gtk_widget_queue_draw(a->areaWidget);
}
void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height)
diff --git a/src/libui_sdl/libui/unix/main.c b/src/libui_sdl/libui/unix/main.c
index 2998bf3..e645234 100644
--- a/src/libui_sdl/libui/unix/main.c
+++ b/src/libui_sdl/libui/unix/main.c
@@ -3,6 +3,9 @@
uiInitOptions options;
+// kind of a hack
+GThread* gtkthread;
+
const char *uiInit(uiInitOptions *o)
{
GError *err = NULL;
@@ -16,6 +19,9 @@ const char *uiInit(uiInitOptions *o)
}
initAlloc();
loadFutures();
+
+ gtkthread = g_thread_self();
+
return NULL;
}
diff --git a/src/libui_sdl/libui/unix/window.c b/src/libui_sdl/libui/unix/window.c
index 46d38be..43287a9 100644
--- a/src/libui_sdl/libui/unix/window.c
+++ b/src/libui_sdl/libui/unix/window.c
@@ -265,7 +265,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
// show everything in the vbox, but not the GtkWindow itself
gtk_widget_show_all(w->vboxWidget);
-printf("wbox %p\n", w->childHolderWidget);
+
// and connect our events
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
g_signal_connect(w->childHolderWidget, "size-allocate", G_CALLBACK(onSizeAllocate), w);
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index 5cbe750..ea745ff 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -133,7 +133,7 @@ int EmuThreadFunc(void* burp)
char melontitle[100];
sprintf(melontitle, "%d/%.0f FPS | melonDS " MELONDS_VERSION, fps, fpstarget);
- uiWindowSetTitle(MainWindow, melontitle);
+ //uiWindowSetTitle(MainWindow, melontitle);
}
}
else
@@ -321,7 +321,7 @@ int main(int argc, char** argv)
EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL);
uiControlShow(uiControl(MainWindow));
- uiControlSetFocus(uiControl(MainDrawArea)); // TODO: this needs to be done when the window regains focus
+ //uiControlSetFocus(uiControl(MainDrawArea)); // TODO: this needs to be done when the window regains focus
uiMain();
EmuRunning = 0;