X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FDDA3858405
Authentication-Results: sourceware.org;
 dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
 bh=jE+74qzUuOrfH/mzDeL27415T/S0gy051L0Px3MdRpo=;
 b=XATRaveW+MIdYYX4lrY/D1B2mj7zujoLULuB2zLEuWvzdd5HIm2U+S3grQmQGQ48rD
 0wG1/jBVALthB69eaEUoHze/es3lNXUbJuuYRGOgyNbTxiVHUTym6TURwPsXSV9Zh+j7
 IlnptZCRX3w/OGSFzlMkfT6sxYUc736XjiJgGLR9+pjrcOfclq9rsXAuPRyhnQTIDk8E
 ydi0ysFrQwctQ285pWN68xTNqEWxLkWTyx3i+Bzip3ydco/Rf0QoOaUUxQxeOuOMbc+k
 0HtgzZ1objbgvuVk2xZasxXvjCTvsS5MP1khdT6uDB6j3Y9BcKy7QlcfRGLDv2Q8audD
 Sz9w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to;
 bh=jE+74qzUuOrfH/mzDeL27415T/S0gy051L0Px3MdRpo=;
 b=b8810P3oY+5jXz1VaDXdyRvXeYBCgoO31/4m60HyanD++mDCGKrX8ONCjp1W5C+cZ0
 JdVJqVnxtp3Bcz3ptmxOmb6Pru/V6OS9CReWk8dIrdONjwPk3Y3G9ndQqoX/09pSe2Ie
 pyyH2e8WzILkvCi7B0xg0XYcMq8WQjzfF3pb4ltOg4ifjKnXYOtybD/6hGSutAT0D3zZ
 1Sk1kny6Jy15sFywKit5I0l1mZltYOIkZSTI2lQCbIBsXD/m1XUQz7hLCUqd8t9yGmJV
 YAAhQR1eP96v9DhFzpMAHCu1jxcUWPArB/HCimrGYTgwMpIA5vny5XtOvQffSKTYNdYK
 lbyA==
X-Gm-Message-State: AOAM5331GrquF2RWcS5t71GP3qk2FjzHpiF1naLW/d+Bv3hSoP/+0zUM
 yLN0I+Y66tqS5fMK9zTGvv9elOWW0ZZO7PiHI68rCEhzee8=
X-Google-Smtp-Source: ABdhPJz5lK8nAb2iOBMRouBhC265hpBYLJkXta/1QGOQy9q5RyUFeCW2N8l7wHzE8Br2jgWZPoVjURuhRGHWIiVKPs0=
X-Received: by 2002:a05:6602:150f:b0:64c:6878:1ec8 with SMTP id
 g15-20020a056602150f00b0064c68781ec8mr821244iow.143.1651282816301; Fri, 29
 Apr 2022 18:40:16 -0700 (PDT)
MIME-Version: 1.0
References: <CAMoHPCaPjj-XyzRXc4yv1U5=1PXK_tASbEd5Caxi0dSPZA89og@mail.gmail.com>
In-Reply-To: <CAMoHPCaPjj-XyzRXc4yv1U5=1PXK_tASbEd5Caxi0dSPZA89og@mail.gmail.com>
From: "S.J. Luo" <sjaluo@gmail.com>
Date: Sat, 30 Apr 2022 09:40:06 +0800
Message-ID: <CAMoHPCa9YQ7vbXwz+muscy_iBHNCrufqqD+UdypF+vvqvm==sA@mail.gmail.com>
Subject: Re: Window flickering problem in XWin multiwindow mode
To: cygwin@cygwin.com
X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_ASCII_DIVIDERS,
 RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=no autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

SL on Apr 26, 2022:

> I have some EDA tools running on a Linux machine and display on my Windows
> PC using xorg-server-21.1.3 XWin multiwindow mode
> Sometimes the application window flickers forever for an unknown reason.
> The problem became more severe after my PC upgrade to Windows10.

> After re-compiling and debugging, I found a calling loop triggered.
> Knowing the root cause, I am now able to demonstrate the issue with a small
> test case as well as a patch that works for me. Both are attached below.

Any one successfully duplicated the issue?

I minor revised the test case so it won't silently go exit on wrong DISPLAY
setting and added some comment. The running steps:

    gcc -o flicker2 flicker2.c -lX11
    /usr/bin/XWin.exe :11 -ac -multiwindow &
    DISPLAY=:11 flicker2.exe

On running, you would see a window switching rapidly between max and normal
states and never stops.

The key of triggering the window flickering(or flashing) are these two lines:

  SetWindowMax(display, win, _NET_WM_STATE_ADD);
  SetWindowMax(display, win, _NET_WM_STATE_REMOVE);

where they just set the window to be maximized and go back to normal.
Removing either of the two, the test case would become normal.
I've tried this test case on 3PCs including Windows 7 and Windows 10
and in all cases the issue happens.

This issue literally occurs on my work that runs some proprietary Linux
EDA software. I wish this can be solved on next update.

SL


flicker2.c
===================================================================
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define _NET_WM_STATE_REMOVE        0
#define _NET_WM_STATE_ADD           1

void SetWindowMax(Display *dpy, Window win, int state)
{
    XEvent xev;
    Atom wm_state  =  XInternAtom(dpy, "_NET_WM_STATE", False);
    Atom max_horz  =  XInternAtom(dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
    Atom max_vert  =  XInternAtom(dpy, "_NET_WM_STATE_MAXIMIZED_VERT", False);

    memset(&xev, 0, sizeof(xev));
    xev.type = ClientMessage;
    xev.xclient.window = win;
    xev.xclient.message_type = wm_state;
    xev.xclient.format = 32;
    xev.xclient.data.l[0] = state;
    xev.xclient.data.l[1] = max_horz;
    xev.xclient.data.l[2] = max_vert;

    XSendEvent(dpy, DefaultRootWindow(dpy), False,
               SubstructureNotifyMask, &xev);
}

int main(void) {
  Display *display;
  Window win;
  XEvent xev;
  int screen;

  if (!(display = XOpenDisplay(NULL))) {
    printf("Cannot open display. Please check DISPLAY environmet setting.\n");
    exit(1);
  }

  screen = DefaultScreen(display);
  win = XCreateSimpleWindow(display, RootWindow(display, screen),
        10, 10, 100, 100, 0,
        BlackPixel(display, screen), WhitePixel(display, screen));
  XMapWindow(display, win);

  // Uncomment either of the following two lines
  // and window would not go flashing
  SetWindowMax(display, win, _NET_WM_STATE_ADD);
  SetWindowMax(display, win, _NET_WM_STATE_REMOVE);

  while(1) {
    XNextEvent(display, &xev);
  }
  // It is supposed never get here
  XCloseDisplay(display);
  return 0;
}
===================================================================

-- 
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
