From 4ca6834e0345b44f52a028401dada13b9d7d4b37 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 Feb 2023 11:41:52 +0400 Subject: [PATCH] Fix (somehow) snap-grid in media viewer on Windows 11. --- .../media/view/media_view_overlay_widget.cpp | 20 +++++++++++++++++++ .../media/view/media_view_overlay_widget.h | 1 + 2 files changed, 21 insertions(+) diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 5dfe337831..a3ea689ce0 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -324,6 +324,7 @@ OverlayWidget::OverlayWidget() toggleFullScreen(maximized); })) , _body(_wrap->widget()) +, _titleBugWorkaround(std::make_unique(_body)) , _surface( Ui::GL::CreateSurface(_body, chooseRenderer(_wrap->backend()))) , _widget(_surface->rpWidget()) @@ -407,6 +408,25 @@ OverlayWidget::OverlayWidget() DEBUG_LOG(("Viewer Pos: Resized to %1, %2") .arg(size.width()) .arg(size.height())); + + // Somehow Windows 11 knows the geometry of first widget below + // the semi-native title control widgets and it uses + // it's geometry to show the snap grid popup around it when + // you put the mouse over the Maximize button. In the 4.6.4 beta + // the first widget was `_widget`, so the popup was shown + // either above the window or, if not enough space above, below + // the whole window, you couldn't even put the mouse on it. + // + // So now here is this weird workaround that places our + // `_titleBugWorkaround` widget as the first one under the title + // controls and the system shows the popup around its geometry, + // so we set it's height to the title controls height + // and everything works as expected. + // + // This doesn't make sense. But it works. :shrug: + _titleBugWorkaround->setGeometry( + { 0, 0, size.width(), st::callTitleButton.height }); + _widget->setGeometry({ QPoint(), size }); updateControlsGeometry(); } else if (type == QEvent::KeyPress) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 37c853a93a..91bd3cedef 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -464,6 +464,7 @@ private: const not_null _window; const std::unique_ptr _helper; const not_null _body; + const std::unique_ptr _titleBugWorkaround; const std::unique_ptr _surface; const not_null _widget; QRect _normalGeometry;