mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Handle PiP aspect ratio on Wayland synchronously
During testing with Qt 6.4 I now remember why I made a way complicated logic (yes, because the trivial one bugs with Qt 6.4) This restores it, but uses event filters rather than hardware integration override
This commit is contained in:
parent
85acf051c1
commit
dfb40dd216
2 changed files with 45 additions and 11 deletions
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "base/power_save_blocker.h"
|
#include "base/power_save_blocker.h"
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "ui/platform/ui_platform_utility.h"
|
#include "ui/platform/ui_platform_utility.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/wrap/fade_wrap.h"
|
#include "ui/wrap/fade_wrap.h"
|
||||||
|
@ -38,6 +39,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <qpa/qplatformwindow.h>
|
||||||
|
#include <qpa/qwindowsysteminterface.h>
|
||||||
|
|
||||||
namespace Media {
|
namespace Media {
|
||||||
namespace View {
|
namespace View {
|
||||||
|
@ -359,17 +362,40 @@ void PipPanel::init() {
|
||||||
Ui::Platform::ClearTransientParent(widget());
|
Ui::Platform::ClearTransientParent(widget());
|
||||||
}, rp()->lifetime());
|
}, rp()->lifetime());
|
||||||
|
|
||||||
rp()->sizeValue(
|
|
||||||
) | rpl::start_with_next([=](QSize size) {
|
|
||||||
handleResize(size);
|
|
||||||
}, rp()->lifetime());
|
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
widget()->windowHandle(),
|
widget()->windowHandle(),
|
||||||
&QWindow::screenChanged,
|
&QWindow::screenChanged,
|
||||||
[=](QScreen *screen) {
|
[=](QScreen *screen) {
|
||||||
handleScreenChanged(screen);
|
handleScreenChanged(screen);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (Platform::IsWayland()) {
|
||||||
|
rp()->sizeValue(
|
||||||
|
) | rpl::start_with_next([=](QSize size) {
|
||||||
|
handleWaylandResize(size);
|
||||||
|
}, rp()->lifetime());
|
||||||
|
|
||||||
|
base::install_event_filter(widget(), [=](not_null<QEvent*> event) {
|
||||||
|
if (event->type() == QEvent::Resize && _inHandleWaylandResize) {
|
||||||
|
return base::EventFilterResult::Cancel;
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
|
||||||
|
base::install_event_filter(widget()->windowHandle(), [=](not_null<QEvent*> event) {
|
||||||
|
if (event->type() == QEvent::Resize) {
|
||||||
|
if (_inHandleWaylandResize) {
|
||||||
|
return base::EventFilterResult::Cancel;
|
||||||
|
}
|
||||||
|
const auto newSize = static_cast<QResizeEvent*>(event.get())->size();
|
||||||
|
if (_suggestedWaylandSize == newSize) {
|
||||||
|
handleWaylandResize(newSize);
|
||||||
|
return base::EventFilterResult::Cancel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<QWidget*> PipPanel::widget() const {
|
not_null<QWidget*> PipPanel::widget() const {
|
||||||
|
@ -584,10 +610,9 @@ void PipPanel::setGeometry(QRect geometry) {
|
||||||
widget()->setGeometry(geometry);
|
widget()->setGeometry(geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipPanel::handleResize(QSize size) {
|
void PipPanel::handleWaylandResize(QSize size) {
|
||||||
if (!Platform::IsWayland()) {
|
_inHandleWaylandResize = true;
|
||||||
return;
|
_suggestedWaylandSize = size;
|
||||||
}
|
|
||||||
|
|
||||||
// Apply aspect ratio.
|
// Apply aspect ratio.
|
||||||
const auto max = std::max(size.width(), size.height());
|
const auto max = std::max(size.width(), size.height());
|
||||||
|
@ -605,8 +630,15 @@ void PipPanel::handleResize(QSize size) {
|
||||||
size.height() * scaled.width() / scaled.height(),
|
size.height() * scaled.width() / scaled.height(),
|
||||||
size.height())
|
size.height())
|
||||||
: scaled;
|
: scaled;
|
||||||
|
const auto newGeometry = QRect(widget()->geometry().topLeft(), normalized);
|
||||||
|
|
||||||
setGeometry(QRect(widget()->geometry().topLeft(), normalized));
|
QWindowSystemInterface::handleGeometryChange<QWindowSystemInterface::SynchronousDelivery>(
|
||||||
|
widget()->windowHandle(),
|
||||||
|
newGeometry);
|
||||||
|
setGeometry(newGeometry);
|
||||||
|
widget()->windowHandle()->handle()->setGeometry(newGeometry);
|
||||||
|
|
||||||
|
_inHandleWaylandResize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipPanel::handleScreenChanged(QScreen *screen) {
|
void PipPanel::handleScreenChanged(QScreen *screen) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
void setDragDisabled(bool disabled);
|
void setDragDisabled(bool disabled);
|
||||||
[[nodiscard]] bool dragging() const;
|
[[nodiscard]] bool dragging() const;
|
||||||
|
|
||||||
void handleResize(QSize size);
|
void handleWaylandResize(QSize size);
|
||||||
void handleScreenChanged(QScreen *screen);
|
void handleScreenChanged(QScreen *screen);
|
||||||
void handleMousePress(QPoint position, Qt::MouseButton button);
|
void handleMousePress(QPoint position, Qt::MouseButton button);
|
||||||
void handleMouseRelease(QPoint position, Qt::MouseButton button);
|
void handleMouseRelease(QPoint position, Qt::MouseButton button);
|
||||||
|
@ -105,6 +105,8 @@ private:
|
||||||
|
|
||||||
bool _useTransparency = true;
|
bool _useTransparency = true;
|
||||||
bool _dragDisabled = false;
|
bool _dragDisabled = false;
|
||||||
|
bool _inHandleWaylandResize = false;
|
||||||
|
QSize _suggestedWaylandSize;
|
||||||
style::margins _padding;
|
style::margins _padding;
|
||||||
|
|
||||||
RectPart _overState = RectPart();
|
RectPart _overState = RectPart();
|
||||||
|
|
Loading…
Add table
Reference in a new issue