DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 61P9lxur391029 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 61P9lxur391029 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=bcvajOOb X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB86F4BAD164 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1772012878; bh=VvZcqTzutDz7D9U4rG5ZYJkxyi7k7mBHAHfyswpc0AI=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bcvajOObT0aroDBj6Kd0uNc5bV++7tVlqQHjQ+9PQY5CqnZPEXWklPRjMJDjmgoaX ANALw37W9mRrbK/c1W9ueosyoScjoVJC0ttXXuYUk2lfhWqqKnwP4ZlZDLivp2E1Aj TX/3xRDiQ2tFcwKQPPFLP0E4P7HOymgmrzEN3SN4= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB4A94B9DB7A ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB4A94B9DB7A ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772012829; cv=none; b=c5gpQriEu7y0zzwYXZkZd77QsMEySPKUw5A5+qW9ZVeLlQtLspAiPeDy+U2lrO+Equ3ON1VjoChD6F7MX7vVnT2gOw4/6LfKMP2JOgP44kG7lZ8+MN18CTz0TCrDxtHuumfgWKRaXNJgNAQbxokBcjyDl2Xxg1dpqhX1nyktKhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772012829; c=relaxed/simple; bh=laxUiz3iL5H/7r07pT7VEi4IaxE7T0fPFMbOeevfAVg=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=coJzGiAtekf0N+YE0vlXqLg8lKrM+g3GOvIklm1Nb2UUiBGDdQsM7dFp8JrNqD/ANpTd9mnh5jZFIZph/OJIozMT4NgJKWxf41WnhgJ3k3j3m4Z4JI2uamUZ6C+KGDZDpbiB0a8OReZtGJKL2v3tvu4UFBNaRR1LMRU8YYek6UY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB4A94B9DB7A Message-ID: Date: Wed, 25 Feb 2026 01:47:04 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: General clipboard issue on cygwin (mintty, putclip, getclip, /dev/clipboard) To: cygwin AT cygwin DOT com References: <20260224103628 DOT fdbd7396311092795834c24f AT nifty DOT ne DOT jp> Content-Language: en-US In-Reply-To: <20260224103628.fdbd7396311092795834c24f@nifty.ne.jp> 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: Mark Geisert via Cygwin Reply-To: Mark Geisert Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Hi Takashi, 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. 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. 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, ..mark -- 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