Bug 501829

Summary: Permanent focus stealing with non-sense Gtk4 code
Product: [Plasma] kwin Reporter: postix <postix>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: REOPENED ---    
Severity: normal    
Priority: NOR    
Version First Reported In: 6.3.3   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description postix 2025-03-21 13:53:57 UTC
SUMMARY

I've stumbled over the following two issues by accident:

If a Gtk4 popovermenu is set visible in the _closed_ event, it will re-open and steal the focus: 
You can basically no longer click anything else.

However, if you click fast and often enough onto the "x" button in the titlebar of the sample app, you can make it close eventually.

You can also click into into another app, e.g. Konsole, until eventually Konsole will gain focus. The main window will hide behind Konsole, but the popover keeps staying on top of all windows.

The code of course makes no sense, but I wanted to report it nonetheless. 


STEPS TO REPRODUCE

Here's a minimal  reproducer:

```
import gi
gi.require_version("Gtk", "4.0")

from gi.repository import Gtk
from gi.repository import GLib

def on_closed(popover):
    print("popover closed")
    popover.set_visible(True)

def on_activate(app):
    win = Gtk.ApplicationWindow(application=app)

    popovermenu = Gtk.PopoverMenu()
    popovermenu.connect("closed", on_closed)
    popovermenu.set_size_request(100, 100)

    win.set_child(popovermenu)
    win.present()

    popovermenu.popup()


app = Gtk.Application(application_id='org.gtk.Example')
app.connect('activate', on_activate)
app.run(None)
```

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20250318
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.12.0
Qt Version: 6.8.2
Kernel Version: 6.13.6-1-default (64-bit)
Comment 1 postix 2025-04-13 11:56:09 UTC
Fixed by the same commit as for #501828
Comment 2 postix 2025-04-19 11:24:09 UTC
Actually it's not fixed yet. Question: Is this behavior of automatic focus grabbing on re-showing the closed surface intended or something, which needs to be solved?

 Is this maybe "fixed" in 6.4 already?