Repository: qtile/qtile

Issue:
[Wayland] AssertionError in the log file when opening flatpak windows.
### The issue:

After running the 0.22.2.dev323+ge9915b12 version (installed right after https://github.com/qtile/qtile/pull/3985 has been merged) I've noticed the following errors in the logfile:

```
2023-08-04 23:05:10,231 ERROR pywayland.server listener.py:notify_func():L42 Exception in callback function
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pywayland/server/listener.py", line 40, in notify_func
    callback(listener, data)
  File "/usr/lib/python3.11/site-packages/libqtile/backend/wayland/core.py", line 852, in _on_xdg_activation_v1_request_activate
    win.handle_activation_request(focus_on_window_activation)
  File "/usr/lib/python3.11/site-packages/libqtile/backend/wayland/xdgwindow.py", line 191, in handle_activation_request
    assert self.qtile is not None and self.group
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError
```

The message appears every time I make flatpak app's window visible - after first run or unhidding them.

### Required:

- [X] I have searched past issues to see if this bug has already been reported.


Discussion:
I don't know if it's related (if not, please let me know and I'll open another issue), but one of my flatpak apps (`org.ferdium.Ferdium`) generates one more error every time it's window is made visible:

```
2023-08-04 23:12:27,036 ERROR libqtile loop.py:_handle_exception():L62 Exception in event loop:
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.11/site-packages/libqtile/widget/statusnotifier.py", line 563, in item_added
    success = future.result()
              ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/libqtile/widget/statusnotifier.py", line 163, in start
    await self._get_icon(icon)
  File "/usr/lib/python3.11/site-packages/libqtile/widget/statusnotifier.py", line 243, in _get_icon
    icon_pixmap = await pixmap()
                  ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dbus_next/aio/proxy_object.py", line 118, in property_getter
    BaseProxyInterface._check_method_return(msg, 'v')
  File "/usr/lib/python3.11/site-packages/dbus_next/proxy_object.py", line 62, in _check_method_return
    raise DBusError._from_message(msg)
dbus_next.errors.DBusError: The name :1.195 was not provided by any .service files
```
The status notifier bit is unrelated. Please move that to a new issue. 

It's odd as it looks like #4224 but I'll need to take s closer look.
I've installed Ferdium but not sure how to debug next. How can I run it with wayland (and no xwayland)? How can I get ferdium to request to be focussed? This is what the error suggests is happening, but it's different to what you said you're doing (focussing it yourself)
Got it reproduced using: `flatpak run --socket=wayland org.ferdium.Ferdium --ozone-platform=wayland`
The error is present every time the window is drawn - so both 'first run' (when the app is closed) or brining it back from the background/systray.

It may be worth to add that I can observe the problem only for electron apps from flatpak.
- When I run, for example, discord from flatpak, I have it; but when I run discord's version from my package manager, the error is not there. 
- When I run non-electron flatpak apps, I don't see the error.

Note: when I run electron apps (slack, discord) from the package manager, not flatpak, I have other errors in the log file:

```
2023-08-06 14:46:35,654 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 356, value 0
2023-08-06 14:46:41,824 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 426, value 0
2023-08-06 14:46:50,803 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 18:0, code 3, sequence 509, value 6291466
2023-08-06 14:46:52,742 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 546, value 0
2023-08-06 14:46:53,269 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 606, value 0
2023-08-06 14:46:53,270 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 607, value 0
2023-08-06 14:46:53,270 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 12:0, code 2, sequence 608, value 0
2023-08-06 14:47:05,792 ERROR wlroots log.py:log_func_callback():L16 [xwayland/xwm.c:1530] xcb error: op 18:0, code 3, sequence 737, value 6291466
```

Resolving patch:
diff --git a/libqtile/backend/wayland/xdgwindow.py b/libqtile/backend/wayland/xdgwindow.py
--- a/libqtile/backend/wayland/xdgwindow.py
+++ b/libqtile/backend/wayland/xdgwindow.py
@@ -188,7 +188,11 @@ def _update_fullscreen(self, do_full: bool) -> None:
 
     def handle_activation_request(self, focus_on_window_activation: str) -> None:
         """Respond to XDG activation requests targeting this window."""
-        assert self.qtile is not None and self.group
+        assert self.qtile is not None
+
+        if self.group is None:
+            # Likely still pending, ignore this request.
+            return
 
         if focus_on_window_activation == "focus":
             logger.debug("Focusing window (focus_on_window_activation='focus')")


Test patch: