From 0b5012f80aa4a9b91875d71b107a8ac36cb15eb5 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 23 Nov 2025 10:30:33 +0100 Subject: [PATCH] replace AppExecProc with ui_call_mainthread --- application/main.c | 7 ------- application/main.h | 2 -- application/player.c | 20 ++++++++++---------- application/settings.c | 10 +++++----- ui/motif/toolkit.c | 18 ++++++++++++++++++ 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/application/main.c b/application/main.c index 81c8c8f..451c4f6 100644 --- a/application/main.c +++ b/application/main.c @@ -237,13 +237,6 @@ void ApplicationExit(void) { XtAppSetExitFlag(app); } -void AppExecProc(XtWorkProc proc, XtPointer data) { - EventLoopCB cb; - cb.proc = proc; - cb.data = data; - write(event_pipe[1], &cb, sizeof(cb)); -} - CxList* GetOpenFileArgs(void) { return open_file_arg; } diff --git a/application/main.h b/application/main.h index 6d2b642..8c6863d 100644 --- a/application/main.h +++ b/application/main.h @@ -37,8 +37,6 @@ XtAppContext* GetAppContext(void); void ApplicationExit(void); -void AppExecProc(XtWorkProc proc, XtPointer data); - CxList* GetOpenFileArgs(void); void CleanOpenFileArgs(void); diff --git a/application/player.c b/application/player.c index b452fdf..9ae9d2a 100644 --- a/application/player.c +++ b/application/player.c @@ -254,7 +254,7 @@ static int connect_to_ipc(Player *player) { return 0; } -static Boolean update_player_window(XtPointer data) { +static int update_player_window(void *data) { MainWindow *win = data; WindowUpdate(win); return 0; @@ -292,7 +292,7 @@ static void* start_player(void *data) { win->player = player; // update main window - AppExecProc(update_player_window, win); + ui_call_mainthread(update_player_window, win); // IO player_io(player); @@ -370,7 +370,7 @@ static void handle_json_rpc_msg(Player *player, CxJsonValue *v) { //json_print(v, NULL, 0); } -static Boolean player_widget_set_size(XtPointer data) { +static int player_widget_set_size(void *data) { Player *player = data; MainWindow *win = GetMainWindow(); @@ -411,7 +411,7 @@ static void player_set_size(Player *player, int width, int height) { player->height = height; } if(player->width > 0 && player->height > 0) { - AppExecProc(player_widget_set_size, player); + ui_call_mainthread(player_widget_set_size, player); } } @@ -441,7 +441,7 @@ static void handle_json_rpc_reqid(Player *player, CxJsonValue *v, int reqid) { } } -static Boolean get_player_window(XtPointer data) { +static int get_player_window(void *data) { Player *p = data; MainWindow *win = GetMainWindow(); @@ -463,7 +463,7 @@ static Boolean get_player_window(XtPointer data) { #define CURSOR_AUTOHIDE_THRESHOLD_SEC 4 -static Boolean hide_cursor(XtPointer data) { +static int hide_cursor(void *data) { MainWindow *win = data; WindowHidePlayerCursor(win); return 0; @@ -474,7 +474,7 @@ static void check_hide_cursor(Player *p) { if(win->cursorhidden) return; if(p->playback_time - win->motion_playback_time > CURSOR_AUTOHIDE_THRESHOLD_SEC) { - AppExecProc(hide_cursor, win); + ui_call_mainthread(hide_cursor, win); } } @@ -507,7 +507,7 @@ static void handle_json_rpc_event(Player *p, CxJsonValue *v, CxJsonValue *event) write(p->ipc, cmd, strlen(cmd)); p->isstarted = TRUE; - AppExecProc(get_player_window, p); + ui_call_mainthread(get_player_window, p); } } @@ -607,7 +607,7 @@ static void json_print(CxJsonValue *value, char *name, int indent) { } } -static Boolean play_next(XtPointer data) { +static int play_next(void *data) { MainWindow *win = GetMainWindow(); PlayListPlayNext(win, false); return 0; @@ -621,7 +621,7 @@ void PlayerEOF(Player *p) { cmd = "{ \"command\": [\"set_property\", \"pause\", false] }\n"; write(p->ipc, cmd, strlen(cmd)); } else { - AppExecProc(play_next, NULL); + ui_call_mainthread(play_next, NULL); } } diff --git a/application/settings.c b/application/settings.c index bdba27f..e0cc967 100644 --- a/application/settings.c +++ b/application/settings.c @@ -215,7 +215,7 @@ static char* get_which_output(FILE *f, CxBuffer *buf) { return NULL; } -static Boolean finish_bin_search(XtPointer data) { +static int finish_bin_search(void *data) { PlayerInfo *playerInfo = data; cxMapPut(uwp_settings, cx_hash_key_str(UWP_PLAYER_BIN), playerInfo->bin); cxMapPut(uwp_settings, cx_hash_key_str(UWP_PLAYER_TYPE), playerInfo->type); @@ -234,7 +234,7 @@ static void* player_bin_search_thread(void *data) { PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); playerInfo->bin = strdup(bin); playerInfo->type = strdup("mpv"); - AppExecProc(finish_bin_search, playerInfo); + ui_call_mainthread(finish_bin_search, playerInfo); cxBufferDestroy(&buf); return NULL; @@ -248,7 +248,7 @@ static void* player_bin_search_thread(void *data) { PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); playerInfo->bin = strdup(bin); playerInfo->type = strdup("mplayer"); - AppExecProc(finish_bin_search, playerInfo); + ui_call_mainthread(finish_bin_search, playerInfo); } } @@ -359,7 +359,7 @@ int CreateSingleInstanceSocket(Display *dp, Bool *already_running) { static Boolean clearPlaylist = TRUE; -static Boolean cmd_open(XtPointer data) { +static int cmd_open(void *data) { MainWindow *win = GetMainWindow(); char *file = data; printf("open %s\n", file); @@ -390,7 +390,7 @@ static void process_msg(CxBuffer *msgbuf, size_t *rpos) { if(cx_strprefix(msg, CX_STR("open "))) { cxstring file = cx_strsubs(msg, 5); cxmutstr mfile = cx_strdup(file); - AppExecProc(cmd_open, mfile.ptr); + ui_call_mainthread(cmd_open, mfile.ptr); } else { fprintf(stderr, "unknown instance command: {%.*s}\n", (int)msg.length, msg.ptr); } diff --git a/ui/motif/toolkit.c b/ui/motif/toolkit.c index 22190f1..17b4726 100644 --- a/ui/motif/toolkit.c +++ b/ui/motif/toolkit.c @@ -226,6 +226,15 @@ static Boolean ui_job_finished(void *data) { return TRUE; } +static Boolean ui_mainthread_job(void *data) { + UiJob *job = data; + if(job->job_func) { + job->job_func(job->job_data); + } + free(job); + return TRUE; +} + static void* ui_jobthread(void *data) { UiJob *job = data; int result = job->job_func(job->job_data); @@ -237,6 +246,15 @@ static void* ui_jobthread(void *data) { return NULL; } +void ui_call_mainthread(ui_threadfunc tf, void* td) { + UiJob *job = malloc(sizeof(UiJob)); + memset(job, 0, sizeof(UiJob)); + job->job_func = tf; + job->job_data = td; + write(event_pipe[1], &job, sizeof(void*)); // hack + XtAppAddWorkProc(app, ui_mainthread_job, job); +} + void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { UiJob *job = malloc(sizeof(UiJob)); job->obj = obj; -- 2.47.3