DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 61PAt2MQ410049 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 61PAt2MQ410049 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=WJ2ANTTV X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 209964B9DB6D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1772016901; bh=WZdAfnqtJQ+Mgx7jMErtDFDWdlI+3Y/9JvG1eu/3DRA=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WJ2ANTTV2QT70aeiegZC/9f9NAtMJkMUZCFDiJgWYeEAIG+f2Yj56xtoj3YtPIeKL +o+MSYZdpSiU0yJMWv452IYX9gsksSt2XjziNgt2DVdsUqOmlVwDusJFj/hKphaCkL xHfLtclSAHfTJo8hDr2igu1X1nYtxCGHxp3o+DF4= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 874AA4BA23CE ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 874AA4BA23CE ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772016848; cv=none; b=bTXWrbnIUbyZILXEg9yZnk+Rc4/yjL25R8DSPSjcMFO39gY2RcKlIVSqGPOh1aJaj8aMQkt1I5UgopXVQeyPZyh22HuC7zmQtU0k8cvPFXkKwww4V2+Sc9TWy92+qBBdZvBrwL53aeJrR4o3OZyqewtL5F8Op6u7SmznULdlV0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772016848; c=relaxed/simple; bh=rbzVsIVICzS0Ga2zAKi7jxjuDTRAGysUQt7LN+EjrPY=; h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature; b=RVHhorK03Yo8VpD4j2eC4SBsCo0cvvSQfponYWdfO5f+/cZGO+23F06f3gVAjpAe11gELlMnCAauutq1901FeAuia1MIBqgxvq5uOwXaytsyd/eSdjH41uLUZU6mxRJNCTeY8zutlcOIO2T5PabfxhRzFt0m4AR9e9qvP/j8P84= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 874AA4BA23CE Date: Wed, 25 Feb 2026 19:54:02 +0900 To: cygwin AT cygwin DOT com Subject: Re: General clipboard issue on cygwin (mintty, putclip, getclip, /dev/clipboard) Message-Id: <20260225195402.2b1135a6e4e8c3f38c15ffff@nifty.ne.jp> In-Reply-To: References: <20260224103628 DOT fdbd7396311092795834c24f AT nifty DOT ne DOT jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Hi Mark, On Wed, 25 Feb 2026 01:47:04 -0800 Mark Geisert via Cygwin wrote: > On 2/23/2026 5:36 PM, Takashi Yano via Cygwin wrote: > > Hi, > > > > I encountered a clipboard issue common to cygwin. > > > > Affected components: > > /dev/clipboard, putclip/getclip, mintty > > > > The issue: > > If the clipbard is opened by `OpenClipboard(NULL)`, occasionally > > SetClipboardData() and GetClipboardData() fails with > > ERROR_CLIPBOARD_NOT_OPEN. > > > > When UltraVNC Viewer (https://uvnc.com/) is opened, this issue > > happens with a very high probability (> ~90%). > > > > $ echo AAAA > /dev/clipboard > > echo: write error: Permission denied > > > > On mintty, text selection by mouse and clicking center button > > fails at the first attempt. > > > > For putlclip/getclip, the following command outputs nothing > > in a few attempts. ("ABCD" is lost.) > > $ echo ABCD |putclip; for a in `seq 100`; do getclip |putclip; done; getclip > > > > $ > > > > > > Solutions: > > This can be solved by passing non-zero HWND to OpenClipboard(). > > Therefore, as for mintty, the following patch is ok I think. > > diff --git a/src/winclip.c b/src/winclip.c > > index 12c54525..a7cbe365 100644 > > --- a/src/winclip.c > > +++ b/src/winclip.c > > @@ -1324,7 +1324,7 @@ static void > > do_win_paste(bool do_path) > > { > > //printf("OpenClipboard win_paste\n"); > > - if (!OpenClipboard(null)) > > + if (!OpenClipboard(wnd)) > > return; > > > > if (cfg.input_clears_selection) > > > > However, for /dev/clipbard and {put|get}clip, there is no > > suitable HWND to pass to OpenClipboard(). Fortunately, I > > found the patch attached solves the /dev/clipboard issue. > > > > This is not smart, however it works. > > > > I think similar patch is ok for putclip/getclip. > > > > Any suggestions and comments will be appreciated. > > I did not try your mintty or UltraVNC tests but the others worked fine > for me, even when in a loop of 10,000 attempts. In my environment, I also confirmed that a loop of 1,000 attempts worked without the issue if UltraVNC Viewer is not opened. I guess UltraVNC Viewer accesses clipboard very frequently. > IIUC you are finding OpenClipboard() returning as if it's opened the > clipboard, but a subsequent operation claims the clipboard is not open. > I'm curious if GetLastError() reports anything from this phantom open. Yeah, indeed. > As for the "not smart" patch :-) I'm leery of cpu-bound loops that might > not end for some unforeseen situation. I'd rather you make use of the > existing max_retry mechanism. Maybe with shorter Sleep()s, say 100ms, > and possibly larger retry count. > HTH, Thanks. That might be better. Current Sleep(1) is 1ms, so just increase max_retry is enough I think. -- Takashi Yano -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple