clipboard: make store idempotent to avoid re-init of in-use data source

This commit is contained in:
Ollie 2026-05-28 21:32:10 +02:00
parent 5d456d5b95
commit 1bcd815001
1 changed files with 13 additions and 0 deletions

View File

@ -5352,6 +5352,19 @@ static void wl_clipboard_store_to_seat(const char *text, int len)
if (!wl_state.seat || !text || len <= 0)
return;
/* If we already own the seat selection, just update the buffer
* instead of re-initializing the source (which can corrupt
* wlroots' internal state for subsequent paste requests). */
if (wl_state.seat->selection_source == &wl_seat_clipboard_source) {
if (wl_seat_clipboard_text)
free(wl_seat_clipboard_text);
wl_seat_clipboard_text = malloc(len + 1);
memcpy(wl_seat_clipboard_text, text, len);
wl_seat_clipboard_text[len] = '\0';
wl_seat_clipboard_len = len;
return;
}
if (wl_seat_clipboard_text)
free(wl_seat_clipboard_text);
wl_seat_clipboard_text = malloc(len + 1);