diff --git a/client/src/app.c b/client/src/app.c index adae5bab..f03ffd43 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -289,9 +289,9 @@ void app_clipboardNotifySize(const LG_ClipboardData type, size_t size) return; } - g_state.cbType = spiceType; - g_state.cbChunked = true; - g_state.cbXfer = size; + g_state.cbWriteType = spiceType; + g_state.cbChunked = true; + g_state.cbXfer = size; } void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) @@ -311,7 +311,7 @@ void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) if (g_state.cbChunked) { - if (spiceType != g_state.cbType) + if (spiceType != g_state.cbWriteType) { DEBUG_ERROR("SPICE clipboard transfer type changed"); return; @@ -332,8 +332,8 @@ void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) g_state.cbXfer -= size; if (g_state.cbXfer == 0) { - g_state.cbType = SPICE_DATA_NONE; - g_state.cbChunked = false; + g_state.cbWriteType = SPICE_DATA_NONE; + g_state.cbChunked = false; } return; } @@ -353,7 +353,8 @@ bool app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque) if (!g_params.clipboardToLocal || !replyFn || !g_state.cbRequestList) return false; - const PSDataType type = g_state.cbType; + const PSDataType type = atomic_load_explicit( + &g_state.cbRemoteType, memory_order_acquire); struct CBRequest * cbr = malloc(sizeof(*cbr)); if (!cbr) { diff --git a/client/src/clipboard.c b/client/src/clipboard.c index 9a747bbe..04a058cf 100644 --- a/client/src/clipboard.c +++ b/client/src/clipboard.c @@ -62,7 +62,8 @@ void cb_spiceNotice(const PSDataType type) if (!g_state.cbAvailable) return; - g_state.cbType = type; + atomic_store_explicit( + &g_state.cbRemoteType, type, memory_order_release); g_state.ds->cbNotice(cb_spiceTypeToLGType(type)); } @@ -113,6 +114,9 @@ void cb_spiceRelease(void) if (!g_params.clipboardToLocal) return; + atomic_store_explicit( + &g_state.cbRemoteType, SPICE_DATA_NONE, memory_order_release); + if (g_state.cbAvailable) g_state.ds->cbRelease(); } diff --git a/client/src/main.c b/client/src/main.c index 4a3397ac..4bcf2e17 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -75,7 +75,11 @@ static LGEvent *e_spice = NULL; static LGThread *t_spice = NULL; static LGThread *t_render = NULL; -struct AppState g_state = { 0 }; +struct AppState g_state = +{ + .cbRemoteType = SPICE_DATA_NONE, + .cbWriteType = SPICE_DATA_NONE, +}; struct CursorState g_cursor; // this structure is initialized in config.c diff --git a/client/src/main.h b/client/src/main.h index f14f1926..1beebde3 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -123,7 +123,8 @@ struct AppState bool useDMA; bool cbAvailable; - PSDataType cbType; + _Atomic(PSDataType) cbRemoteType; + PSDataType cbWriteType; bool cbChunked; size_t cbXfer; struct ll * cbRequestList;