Bug 494352

Summary: Intellij IDEA menus and popups are displayed at wrong position after (un)maximizing
Product: [Plasma] kwin Reporter: equeim
Component: xwaylandAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED DOWNSTREAM    
Severity: normal CC: giovanni.santoni72, oguilherme, postix, s.kde, zawertun
Priority: NOR    
Version: 6.2.0   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
URL: https://bugs.java.com/bugdatabase/view_bug?bug_id=8338751
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: patch

Description equeim 2024-10-09 15:48:11 UTC
SUMMARY
After upgrading to Plasma 6.2 Intellij IDEA (and Android Studio) now have issues with positioning of popup windows after (un)maximizing.

STEPS TO REPRODUCE
1. Open Intellij IDEA
2. Move pointer over something to trigger popup on open menu in menu bar
3. Maximize or unmaximize window

OBSERVED RESULT
Menus and popus are now show at wrong positions on screen

EXPECTED RESULT
Menus and popus are shown correctly

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: openSUSE Tumbleweed 20241007
KDE Plasma Version: 6.2.0
KDE Frameworks Version: 6.6.0
Qt Version: 6.7.3

ADDITIONAL INFORMATION
After moving the window the issue goes away, but that obviously doesn't work when window is maximized.
Comment 1 equeim 2024-10-09 15:52:27 UTC
I use Wayland session so IDEA runs through XWayland, and its version is "IntelliJ IDEA 2024.2.3 (Community Edition)"
Comment 2 Vlad Zahorodnii 2024-10-09 17:47:22 UTC
It's a bug in JDK, see the attached link.
Comment 3 Vlad Zahorodnii 2024-10-09 17:48:24 UTC
The fix for jdk should be a oneliner.
Comment 4 equeim 2024-10-09 17:51:24 UTC
Is there a y workaround that can be applied here? (I suppose I could also try IDEA's experimental Wayland support but that could create more issues than solve).
Comment 5 equeim 2024-10-09 17:52:15 UTC
Doesn't this also affect all Java apps, not just IDEA?
Comment 6 Vlad Zahorodnii 2024-10-09 18:00:02 UTC
Yeah, unfortunately, it affects **all** apps that use awt.
Comment 7 Bug Janitor Service 2024-10-09 18:04:50 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6587
Comment 8 Vlad Zahorodnii 2024-10-09 18:06:51 UTC
The patch above may help with some things, but JDK needs to re-adjust its code to handle new kwin behavior. In general, awt should not have any WM-specific code to avoid cases exactly like this.
Comment 9 Vlad Zahorodnii 2024-10-10 08:34:24 UTC
Git commit ce2ddeb2249eecc82f5d4d2c7ed331734a295949 by Vlad Zahorodnii.
Committed on 10/10/2024 at 08:21.
Pushed by vladz into branch 'Plasma/6.2'.

Workaround awt breaking due to not handling ConfigureNotify events as expected

awt has hardcoded behavior for most of the WMs. In 6.2, internal kwin
implementations had changed, which broke awt.

See https://bugs.java.com/bugdatabase/view_bug?bug_id=8338751

M  +5    -0    src/x11window.cpp

https://invent.kde.org/plasma/kwin/-/commit/ce2ddeb2249eecc82f5d4d2c7ed331734a295949
Comment 10 Giovanni Santoni 2024-10-10 09:26:59 UTC
Hi i tried to apply you path and now (In reply to Vlad Zahorodnii from comment #9)
> Git commit ce2ddeb2249eecc82f5d4d2c7ed331734a295949 by Vlad Zahorodnii.
> Committed on 10/10/2024 at 08:21.
> Pushed by vladz into branch 'Plasma/6.2'.
> 
> Workaround awt breaking due to not handling ConfigureNotify events as
> expected
> 
> awt has hardcoded behavior for most of the WMs. In 6.2, internal kwin
> implementations had changed, which broke awt.
> 
> See https://bugs.java.com/bugdatabase/view_bug?bug_id=8338751
> 
> M  +5    -0    src/x11window.cpp
> 
> https://invent.kde.org/plasma/kwin/-/commit/
> ce2ddeb2249eecc82f5d4d2c7ed331734a295949

I applied the patch from https://invent.kde.org/plasma/kwin/-/commit/ce2ddeb2249eecc82f5d4d2c7ed331734a295949 to KWin 6.2.0. 
While it partially resolves the issue, the fix only takes effect after I unmaximize and then remaximize the IntelliJ window. 
If IntelliJ opens directly in a maximized state, the menus remain misaligned. 

Interestingly, this issue did not occur with version 6.1.5, where everything worked as expected. I would greatly appreciate any advice or suggestions on how to fully resolve this.
Comment 11 Vlad Zahorodnii 2024-10-10 09:53:26 UTC
It's not a full proof solution, it only addresses one of the potential cases.
Comment 13 Giovanni Santoni 2024-10-10 10:00:12 UTC
(In reply to Vlad Zahorodnii from comment #12)
> see also
> https://mail.openjdk.org/pipermail/client-libs-dev/2024-October/023195.html

ok thanks for the info!
Comment 14 Vlad Zahorodnii 2024-10-10 10:01:57 UTC
Created attachment 174605 [details]
patch

@Giovanni Santoni if you apply this patch on top, is it better?
Comment 15 Bug Janitor Service 2024-10-10 10:20:02 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6588
Comment 16 Giovanni Santoni 2024-10-10 10:37:33 UTC
(In reply to Vlad Zahorodnii from comment #14)
> Created attachment 174605 [details]
> patch
> 
> @Giovanni Santoni if you apply this patch on top, is it better?

Yes!
Both patches are now applied, and everything is working, even when the application starts in fullscreen mode. 
Thanks!(In reply to Vlad Zahorodnii from comment #14)
> Created attachment 174605 [details]
> patch
> 
> @Giovanni Santoni if you apply this patch on top, is it better?

Yes! 
Both patches are now applied, and everything is working, even when the application starts in fullscreen mode.
Thanks!
Comment 17 Vlad Zahorodnii 2024-10-10 13:41:06 UTC
Git commit d7073839c2b9b3bdd6d4a95127853c2accb1e568 by Vlad Zahorodnii.
Committed on 10/10/2024 at 13:22.
Pushed by vladz into branch 'Plasma/6.2'.

Send synthetic configure notify also in manage()

Amends ce2ddeb2249eecc82f5d4d2c7ed331734a295949.

This is needed to handle the case when the window is initially maximized.

M  +5    -0    src/x11window.cpp

https://invent.kde.org/plasma/kwin/-/commit/d7073839c2b9b3bdd6d4a95127853c2accb1e568
Comment 18 Vlad Zahorodnii 2024-10-11 13:44:36 UTC
*** Bug 494532 has been marked as a duplicate of this bug. ***
Comment 19 Vlad Zahorodnii 2024-10-15 23:07:03 UTC
*** Bug 494834 has been marked as a duplicate of this bug. ***
Comment 20 Vlad Zahorodnii 2024-10-15 23:07:17 UTC
Downstream fix: https://github.com/openjdk/jdk/pull/21449
Comment 21 equeim 2024-10-25 23:02:58 UTC
I still have a similar issue with Plasma 6.2.2 in a double monitor setup. When IDEA is on the right monitor, and the system is "woken up" after monitors were turned off by timeout (*not* from suspend), menus and popups in IDEA appear on the left monitor (but the main window itself remains on the right one).
Comment 22 Vlad Zahorodnii 2024-11-06 22:26:32 UTC
(In reply to equeim from comment #21)
> I still have a similar issue with Plasma 6.2.2 in a double monitor setup.
> When IDEA is on the right monitor, and the system is "woken up" after
> monitors were turned off by timeout (*not* from suspend), menus and popups
> in IDEA appear on the left monitor (but the main window itself remains on
> the right one).

The fix has been backported to jdk 17. https://github.com/openjdk/jdk17u-dev/pull/2981