diff --git a/client/src/core.c b/client/src/core.c index 01d5fcab..2af8907c 100644 --- a/client/src/core.c +++ b/client/src/core.c @@ -290,6 +290,30 @@ bool core_isValidPointerPos(int x, int y) return g_state.ds->isValidPointerPos(x, y); } +bool core_startCursorThread(void) +{ + if (g_state.cursorThread) + return true; + + g_state.stopVideo = false; + if (!lgCreateThread("cursorThread", main_cursorThread, NULL, + &g_state.cursorThread)) + { + DEBUG_ERROR("cursor create thread failed"); + return false; + } + return true; +} + +void core_stopCursorThread(void) +{ + g_state.stopVideo = true; + if (g_state.cursorThread) + lgJoinThread(g_state.cursorThread, NULL); + + g_state.cursorThread = NULL; +} + bool core_startFrameThread(void) { if (g_state.frameThread) diff --git a/client/src/core.h b/client/src/core.h index 5874b54c..574dbde3 100644 --- a/client/src/core.h +++ b/client/src/core.h @@ -31,6 +31,8 @@ bool core_warpPointer(int x, int y, bool exiting); void core_updatePositionInfo(void); void core_alignToGuest(void); bool core_isValidPointerPos(int x, int y); +bool core_startCursorThread(void); +void core_stopCursorThread(void); bool core_startFrameThread(void); void core_stopFrameThread(void); void core_handleGuestMouseUpdate(void); diff --git a/client/src/keybind.c b/client/src/keybind.c index 487f6967..d9fd89f3 100644 --- a/client/src/keybind.c +++ b/client/src/keybind.c @@ -43,9 +43,15 @@ static void bind_video(int sc, void * opaque) ); if (g_state.stopVideo) + { + core_stopCursorThread(); core_stopFrameThread(); + } else + { + core_startCursorThread(); core_startFrameThread(); + } } static void bind_rotate(int sc, void * opaque) diff --git a/client/src/main.c b/client/src/main.c index 1e5e23ac..f5179460 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -64,13 +64,11 @@ #include "util.h" // forwards -static int cursorThread(void * unused); static int renderThread(void * unused); static LGEvent *e_startup = NULL; static LGThread *t_spice = NULL; static LGThread *t_render = NULL; -static LGThread *t_cursor = NULL; struct AppState g_state = { 0 }; struct CursorState g_cursor; @@ -292,9 +290,7 @@ static int renderThread(void * unused) lgTimerDestroy(fpsTimer); - if (t_cursor) - lgJoinThread(t_cursor, NULL); - + core_stopCursorThread(); core_stopFrameThread(); RENDERER(deinitialize); @@ -304,7 +300,7 @@ static int renderThread(void * unused) return 0; } -static int cursorThread(void * unused) +int main_cursorThread(void * unused) { LGMP_STATUS status; LG_RendererCursor cursorType = LG_CURSOR_COLOR; @@ -330,7 +326,7 @@ static int cursorThread(void * unused) break; } - while(g_state.state == APP_STATE_RUNNING) + while(g_state.state == APP_STATE_RUNNING && !g_state.stopVideo) { LGMPMessage msg; if ((status = lgmpClientProcess(g_state.pointerQueue, &msg)) != LGMP_OK) @@ -1156,13 +1152,7 @@ restart: g_state.kvmfrFeatures = udata->features; - if (!lgCreateThread("cursorThread", cursorThread, NULL, &t_cursor)) - { - DEBUG_ERROR("cursor create thread failed"); - return 1; - } - - if (!core_startFrameThread()) + if (!core_startCursorThread() || !core_startFrameThread()) return -1; while(g_state.state == APP_STATE_RUNNING) @@ -1181,9 +1171,7 @@ restart: lgSignalEvent(g_state.frameEvent); core_stopFrameThread(); - - lgJoinThread(t_cursor, NULL); - t_cursor = NULL; + core_stopCursorThread(); lgInit(); diff --git a/client/src/main.h b/client/src/main.h index 19a4132c..106f85c2 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -110,6 +110,7 @@ struct AppState PLGMPClientQueue pointerQueue; KVMFRFeatureFlags kvmfrFeatures; + LGThread * cursorThread; LGThread * frameThread; LGEvent * frameEvent; atomic_bool invalidateWindow; @@ -287,6 +288,7 @@ extern struct AppState g_state; extern struct CursorState g_cursor; extern struct AppParams g_params; +int main_cursorThread(void * unused); int main_frameThread(void * unused); #define RENDERER(fn, ...) g_state.lgr->ops.fn(g_state.lgr, ##__VA_ARGS__)