ZaStoGram_desktop/Telegram/SourceFiles/ui/effects/zsg_thanos_overlay.h
loop-uh c63f4f6906
All checks were successful
Desktop source guards / guards (push) Successful in 5s
Накладка Thanos без Qt-родителя: Qt пересоздавал главное окно через неё
dev-67: приложение снова закрывалось при первом удалении. Стек тот же:
QWidget::setParent -> QWidgetPrivate::recreate -> WM_DESTROY главного окна.
Причина в том, как Qt ищет окно для переключения на RHI:
closestParentWidgetWithWindowHandle() идёт вверх по родителям, пока не найдёт
предка с нативным окном. У накладки своего окна ещё нет, поэтому поиск
перешагнул через неё и дошёл до её Qt-родителя, то есть до главного окна.

Накладка теперь окно верхнего уровня без Qt-родителя. Связь с главным окном
через владельца Windows (GWLP_HWNDPARENT, как MainWindow делает для панели
задач), заданного до первого показа: накладка остаётся над владельцем,
прячется вместе с ним и не попадает на панель задач. WA_QuitOnClose выключен.
Гард в test_zastogram_diag.py.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 12:18:11 -05:00

56 lines
2.2 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information see the local LEGAL file.
*/
#pragma once
#include "base/event_filter.h"
#include "rpl/lifetime.h"
#include <QtWidgets/QWidget>
namespace Ui {
// ZaStoGram: a transparent window over the client area of the main window
// that hosts the GPU surface of the message deletion effect (Thanos).
//
// Why it exists: a QRhiWidget added to a window that is already shown makes Qt
// switch that window to GPU composition by destroying and recreating its native
// handle (QWidgetPrivate::recreate). For the main window this is harmful twice:
// Platform::MainWindow takes the WM_DESTROY for a close and quits the app, and
// it caches the handle (psHwnd, frame, shadows, taskbar state), so a window that
// survived would be half dead. Switching the whole chat window to GPU
// composition also makes every frame wait for vsync (animations fall to
// ~30 fps on 60 Hz), see lib_ui 6d6e1f0.
//
// The overlay is created hidden and gets its GPU child before its own native
// window exists, so Qt creates it already configured and recreates nothing.
//
// It must NOT have a Qt parent: when the GPU widget is added, Qt looks for the
// closest ancestor that already has a native window and recreates THAT one
// (QWidget::setParent), walking over a child window that has no handle yet up
// to its parent. dev-67 had the main window as the parent and was closed by
// exactly this. So the overlay is a parentless top-level and is tied to the
// main window with the native Windows owner relation (GWLP_HWNDPARENT, as
// Platform::MainWindow does for the taskbar): Windows keeps it right above the
// owner, hides it together with the owner and keeps it out of the taskbar.
// It never takes focus or input. The owner of the object frees it.
class ThanosOverlay final : public QWidget {
public:
explicit ThanosOverlay(not_null<QWidget*> parent);
// Matches the client area of the parent and shows the overlay.
void present();
void dismiss();
private:
void syncGeometry();
const not_null<QWidget*> _parent;
rpl::lifetime _lifetime;
};
} // namespace Ui