[client] clipboard: retain local Wayland offers

This commit is contained in:
Geoffrey McRae
2026-08-14 12:22:49 +10:00
parent 608e85fe5d
commit 20c63464a7
4 changed files with 52 additions and 35 deletions

View File

@@ -627,7 +627,7 @@ static void testRequest(void)
lgClipboard_free();
}
static void testRemoteReplacesLocal(void)
static void testRemoteKeepsLocalRequest(void)
{
init();
bind(&p);
@@ -651,17 +651,17 @@ static void testRemoteReplacesLocal(void)
notice(&q, types, 1);
CHECK(d.notice == 1);
/* Rebinding after a remote notice must not replay the superseded local
* offer back to the provider. */
lgClipboard_setTransport(&plainOps, &r);
CHECK(r.attach == 1);
CHECK(r.notice == 0);
CHECK(r.release == 1);
/* The two clipboard directions have independent generations. A late
* request can still refer to the local offer advertised before this remote
* notice, so its type must remain serviceable. */
CHECK(q.ev->request(q.evCtx, 43, LG_CLIPBOARD_DATA_TEXT));
CHECK(d.request == 1);
CHECK(d.reqType[0] == LG_CLIPBOARD_DATA_TEXT);
lgClipboard_free();
}
static void testPendingRemoteReplacesLocal(void)
static void testPendingRemoteKeepsLocalRequest(void)
{
init();
bind(&p);
@@ -677,10 +677,11 @@ static void testPendingRemoteReplacesLocal(void)
lgClipboard_setLocalAvailable(true);
CHECK(d.notice == 1);
lgClipboard_setTransport(&plainOps, &q);
CHECK(q.attach == 1);
CHECK(q.notice == 0);
CHECK(q.release == 1);
/* Publishing a notice which arrived while the local clipboard was
* unavailable must likewise retain the local request allow-list. */
CHECK(p.ev->request(p.evCtx, 44, LG_CLIPBOARD_DATA_TEXT));
CHECK(d.request == 1);
CHECK(d.reqType[0] == LG_CLIPBOARD_DATA_TEXT);
lgClipboard_free();
}
@@ -1129,8 +1130,8 @@ static const struct Test tests[] =
{
{ "preference", testPreference },
{ "request" , testRequest },
{ "remote-local", testRemoteReplacesLocal },
{ "pending-remote", testPendingRemoteReplacesLocal },
{ "remote-local", testRemoteKeepsLocalRequest },
{ "pending-remote", testPendingRemoteKeepsLocalRequest },
{ "invalid" , testInvalid },
{ "cancel" , testCancel },
{ "generation", testGeneration },

View File

@@ -706,12 +706,22 @@ static void testSelfCopy(void)
waylandCBNotice(LG_CLIPBOARD_DATA_TEXT);
struct Proxy * source = &proto.source[0];
CHECK(wlCb.selectionSource == (struct wl_data_source *)source);
CHECK(wlCb.offer == (struct wl_data_offer *)local);
CHECK(!local->dead);
/* A remote notice and its self echo must not erase the Wayland offer for a
* local clipboard generation that Windows can still request. */
const uint8_t localData[] = "local clipboard";
proto.receiveData = localData;
proto.receiveSize = sizeof(localData) - 1;
/* Losing focus before the compositor echoes our source must not release
* the remote clipboard. */
waylandCBInvalidate();
CHECK(rec.releaseN == 0);
CHECK(wlCb.selectionSource == (struct wl_data_source *)source);
CHECK(wlCb.offer == (struct wl_data_offer *)local);
CHECK(!local->dead);
struct Proxy * echo = newOffer();
offerMime(echo, "text/plain");
@@ -721,17 +731,28 @@ static void testSelfCopy(void)
CHECK(rec.noticeN == 1);
CHECK(rec.releaseN == 0);
CHECK(wlCb.selectionSource == (struct wl_data_source *)source);
CHECK(!wlCb.offer);
for (enum LG_ClipboardData i = 0; i < LG_CLIPBOARD_DATA_NONE; ++i)
CHECK(!wlCb.mimetypes[i]);
CHECK(local->dead);
CHECK(wlCb.offer == (struct wl_data_offer *)local);
CHECK(wlCb.mimetypes[LG_CLIPBOARD_DATA_TEXT]);
CHECK(!local->dead);
CHECK(echo->dead);
CHECK(proto.offerDestroyN == 2);
CHECK(proto.offerDestroyN == 1);
CHECK(!echo->user);
waylandCBInvalidate();
CHECK(rec.releaseN == 0);
CHECK(wlCb.selectionSource == (struct wl_data_source *)source);
CHECK(wlCb.offer == (struct wl_data_offer *)local);
waylandCBRequest(102, LG_CLIPBOARD_DATA_TEXT);
CHECK(proto.receiveN == 1);
CHECK(rec.pollN == 1);
pollFire(0, EPOLLIN);
pollFire(0, EPOLLIN);
CHECK(rec.streamData.request == 102);
CHECK(rec.streamData.size == sizeof(localData) - 1);
CHECK(rec.streamData.endN == 1);
CHECK(memcmp(rec.streamData.data, localData,
sizeof(localData) - 1) == 0);
int fds[2];
CHECK(pipe(fds) == 0);
@@ -754,6 +775,8 @@ static void testSelfCopy(void)
selectOffer(NULL);
CHECK(rec.releaseN == 1);
CHECK(!wlCb.selectionSource);
CHECK(local->dead);
CHECK(proto.offerDestroyN == 2);
CHECK(proto.dirtyDestroyN == 0);
finish();