diff -r 458831c574f4 -r 0ec8a5f17782 ui/motif/toolkit.c --- a/ui/motif/toolkit.c Sat May 10 15:43:22 2014 +0200 +++ b/ui/motif/toolkit.c Sat May 10 18:52:22 2014 +0200 @@ -28,6 +28,8 @@ #include #include +#include +#include #include "toolkit.h" #include "toolbar.h" @@ -46,11 +48,18 @@ static int is_toplevel_realized = 0; +int event_pipe[2]; + static String fallback[] = { "*fontList: -dt-interface system-medium-r-normal-s*utf*:", NULL }; +void input_proc(XtPointer data, int *source, XtInputId *iid) { + void *ptr; + read(event_pipe[0], &ptr, sizeof(void*)); +} + void ui_init(char *appname, int argc, char **argv) { application_name = appname; @@ -69,6 +78,12 @@ ui_stock_init(); uic_load_app_properties(); + + if(pipe(event_pipe)) { + fprintf(stderr, "UiError: Cannot create event pipe\n"); + exit(-1); + } + XtAppAddInput(app, event_pipe[0], XtInputReadMask, input_proc, NULL); } char* ui_appname() { @@ -109,10 +124,66 @@ XtRealizeWidget(obj->widget); } +void ui_close(UiObject *obj) { + // TODO +} + void ui_set_enabled(UIWIDGET widget, int enabled) { XtSetSensitive(widget, enabled); } +void ui_set_show_all(UIWIDGET widget, int value) { + if(!value) { + XtUnmanageChild(widget); + } +} + +void ui_set_visible(UIWIDGET widget, int visible) { + if(visible) { + XtManageChild(widget); + } else { + XtUnmanageChild(widget); + } +} + +static Boolean ui_job_finished(void *data) { + printf("WorkProc\n"); + UiJob *job = data; + + UiEvent event; + event.obj = job->obj; + event.window = job->obj->window; + event.document = job->obj->document; + event.intval = 0; + event.eventdata = NULL; + + job->finish_callback(&event, job->finish_data); + free(job); + return TRUE; +} + +static void* ui_jobthread(void *data) { + UiJob *job = data; + int result = job->job_func(job->job_data); + if(!result) { + printf("XtAppAddWorkProc\n"); + write(event_pipe[1], &job, sizeof(void*)); // hack + XtAppAddWorkProc(app, ui_job_finished, job); + + } +} + +void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { + UiJob *job = malloc(sizeof(UiJob)); + job->obj = obj; + job->job_func = tf; + job->job_data = td; + job->finish_callback = f; + job->finish_data = fd; + pthread_t pid; + pthread_create(&pid, NULL, ui_jobthread, job); +} + void ui_clipboard_set(char *str) { printf("copy: {%s}\n", str); int length = strlen(str) + 1;