qtwebengine: enable video fullscreen

This commit is contained in:
2026-10-15 23:35:22 +02:00
parent 13c1488b0e
commit 1577ef49cd
3 changed files with 54 additions and 6 deletions
+44 -5
View File
@@ -14,9 +14,11 @@
#include <QMouseEvent>
#include <QRegularExpression>
#include <QVBoxLayout>
#include <QWebEngineFullScreenRequest>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <QWebEngineScript>
#include <QWebEngineSettings>
#include <QWebEngineView>
#include <QWidget>
@@ -92,6 +94,15 @@ void BrowserWindow::connectView()
setMode(Mode::Normal);
});
connect(m_view, &QWebEngineView::loadProgress, m_status, &StatusBar::setProgress);
// Off by default in QtWebEngine: without it, element.requestFullscreen()
// (YouTube's fullscreen button, double-clicking a video) silently fails.
m_view->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
connect(m_view->page(), &QWebEnginePage::fullScreenRequested, this,
[this](QWebEngineFullScreenRequest request) {
request.accept();
setPageFullScreen(request.toggleOn());
});
connect(m_view, &QWebEngineView::titleChanged, this, [this](const QString &title) {
setWindowTitle(title.isEmpty() ? QStringLiteral("att")
: QStringLiteral("%1 - att").arg(title));
@@ -123,23 +134,45 @@ void BrowserWindow::setMode(Mode mode)
switch (mode) {
case Mode::Normal:
m_status->setMode(QString());
m_status->show();
focusView();
break;
case Mode::Insert:
m_status->setMode(QStringLiteral("insert"));
m_status->show();
focusView();
break;
case Mode::Command:
m_status->hide();
updateCompletion();
break;
case Mode::Hint:
m_status->setMode(QStringLiteral("hint"));
m_status->show();
break;
}
updateStatusVisibility();
}
void BrowserWindow::setPageFullScreen(bool on)
{
if (on == m_pageFullScreen)
return;
m_pageFullScreen = on;
if (on) {
m_windowStateBeforeFullScreen = windowState();
showFullScreen();
} else {
setWindowState(m_windowStateBeforeFullScreen);
}
updateStatusVisibility();
}
void BrowserWindow::updateStatusVisibility()
{
// The command line replaces the status bar, and a fullscreen video gets the
// whole screen. Decided in one place so the bar is never shown just to be
// hidden again: toggling it while fullscreen knocks the window out of
// fullscreen.
m_status->setVisible(m_mode != Mode::Command && !m_pageFullScreen);
}
bool BrowserWindow::eventFilter(QObject *watched, QEvent *event)
@@ -154,7 +187,13 @@ bool BrowserWindow::eventFilter(QObject *watched, QEvent *event)
if (key->key() == Qt::Key_Escape
|| (key->key() == Qt::Key_BracketLeft && key->modifiers() == Qt::ControlModifier)) {
setMode(Mode::Normal);
// Escape is swallowed here, so the page would never see it to leave
// fullscreen itself. In insert/hint mode it still just returns to normal
// mode first, as everywhere else.
if (m_mode == Mode::Normal && m_pageFullScreen)
m_view->triggerPageAction(QWebEnginePage::ExitFullScreen);
else
setMode(Mode::Normal);
return true;
}