Bug 395034 - QMenu becomes invisible when cleared while still open
Summary: QMenu becomes invisible when cleared while still open
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: compositing (show other bugs)
Version: 5.12.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-04 21:49 UTC by Farid Boudedja
Modified: 2018-06-05 20:27 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
QMenu cleared by a timer with compositing enabled (189.89 KB, video/webm)
2018-06-04 21:49 UTC, Farid Boudedja
Details
QMenu cleared by a timer with compositing disabled (473.13 KB, video/webm)
2018-06-04 21:50 UTC, Farid Boudedja
Details
e.g. of QMenu working but invisible in Gwenview (476.32 KB, video/webm)
2018-06-04 21:50 UTC, Farid Boudedja
Details
Qt application reproducing the bug using a QTimer (4.16 KB, application/gzip)
2018-06-05 13:34 UTC, Farid Boudedja
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Farid Boudedja 2018-06-04 21:49:23 UTC
Created attachment 113078 [details]
QMenu cleared by a timer with compositing enabled

When an open QMenu is cleared through a function triggered by a signal (e.g. QTimer or a queued connection) it becomes invisible but its actions are working.

The bug can be replicated using the following Qt app:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QToolButton *button = new QToolButton(ui->mainToolBar);
    QMenu* menu = new QMenu(button);

    button->setText("Menu");
    button->setMenu(menu);
    button->setPopupMode(QToolButton::InstantPopup);

    QTimer* timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, [=](){
        menu->clear();
        menu->addAction("Menu 1");
        menu->addAction("Menu 2");
        menu->addAction("Menu 3");
    });
    timer->start(1000);

    ui->mainToolBar->addWidget(button);
}


- The menu should be cleared and populated every second but it appears and disappears. (See attachment) 
- When compositing is disable it works as expected and does not disappear. (See attachment)
- Although the menu is invisible it still works. (See attachment)
Comment 1 Farid Boudedja 2018-06-04 21:50:05 UTC
Created attachment 113079 [details]
QMenu cleared by a timer with compositing disabled
Comment 2 Farid Boudedja 2018-06-04 21:50:48 UTC
Created attachment 113080 [details]
e.g. of QMenu working but invisible in Gwenview
Comment 3 Martin Flöser 2018-06-05 04:29:06 UTC
Sorry, but KWin has nothing to do with that. It is not responsible for input handling. If the application reacts on input for a not visible window that is an application bug.
Comment 4 null 2018-06-05 07:21:23 UTC
Thanks for your response, Martin.

> KWin has nothing to do with that. It is not responsible for input handling.
Could you tell us why you think input handling is the problem (we are mainly interested in the menu showing, because that's not working right, input handling seems fine)?

> If the application reacts on input for a not visible window that is an 
> application bug.
That's not the problem. The problem is that the menu is _invisible_ with compositing on, while with compositing off it is perfectly visible as it should be.

Any suggestions in solving this on the application side?  I guess a different code path in the application when compositing is off is not the way to go, but what else are we doing wrong? Perhaps it's a bug in Qt, but then why is it working fine with KWin's compositing turned off (on X11)?
Comment 5 David Edmundson 2018-06-05 09:21:37 UTC
Henrik can you upload the sample code that you've written.
Comment 6 null 2018-06-05 13:13:02 UTC
Sorry David, I haven't written any additional sample code, I thought the code above was enough to show the nature of the problem. Is there any issue with Farid's code (besides omitting the boilerplate and not coming in tar.gz form)?

If you are interested, this bug originates from the discussion in https://phabricator.kde.org/D13312 (please don't mind the detours over there).
Comment 7 Farid Boudedja 2018-06-05 13:34:34 UTC
Created attachment 113094 [details]
Qt application reproducing the bug using a QTimer

I have attached the entire Qt Creator project of the test application reproducing the bug.
Comment 8 Martin Flöser 2018-06-05 17:18:22 UTC
Sorry I misunderstood from the description. Nevertheless I very much doubt that this is an issue in KWin. Relevant code areas haven't been touched in years. In such situations the fault is normally with the application or toolkit.
Comment 9 null 2018-06-05 20:27:04 UTC
Before the bug was reported, I checked with a KDE 4 based system, where the share button is working fine. The only change on Gwenview's side since then is [1], where David ported from KMenu to QMenu. However, in KMenu [2] I could not find anything special really.

Farid: I guess the last thing you could try is reporting this to https://bugreports.qt.io, and hope that it's a problem in Qt that is triggered by turning on KWin's compositing.

[1] https://phabricator.kde.org/R260:2e69abc63776f05668a188f5ea3f58d0c8243754#change-OOnyLJlEzc3C
[2] https://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/kmenu_8cpp_source.html