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
+3 -1
View File
@@ -39,7 +39,9 @@ Like qutebrowser, keys mean different things depending on the mode:
| `command` | `o`, `O`, `:` | keys go to the command line | | `command` | `o`, `O`, `:` | keys go to the command line |
| `hint` | `f` | keys pick a link label | | `hint` | `f` | keys pick a link label |
`Escape` (or `Ctrl-[`) always returns to normal mode. `Escape` (or `Ctrl-[`) always returns to normal mode. In normal mode, it also
leaves fullscreen when a page (e.g. a YouTube video) is fullscreen. The status bar
is hidden while a page is fullscreen.
> Note: unlike qutebrowser, att does not yet auto-switch to insert mode when you > Note: unlike qutebrowser, att does not yet auto-switch to insert mode when you
> click into a text field on a page — press `i` first. Doing it automatically > click into a text field on a page — press `i` first. Doing it automatically
+43 -4
View File
@@ -14,9 +14,11 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QRegularExpression> #include <QRegularExpression>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWebEngineFullScreenRequest>
#include <QWebEnginePage> #include <QWebEnginePage>
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QWebEngineScript> #include <QWebEngineScript>
#include <QWebEngineSettings>
#include <QWebEngineView> #include <QWebEngineView>
#include <QWidget> #include <QWidget>
@@ -92,6 +94,15 @@ void BrowserWindow::connectView()
setMode(Mode::Normal); setMode(Mode::Normal);
}); });
connect(m_view, &QWebEngineView::loadProgress, m_status, &StatusBar::setProgress); 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) { connect(m_view, &QWebEngineView::titleChanged, this, [this](const QString &title) {
setWindowTitle(title.isEmpty() ? QStringLiteral("att") setWindowTitle(title.isEmpty() ? QStringLiteral("att")
: QStringLiteral("%1 - att").arg(title)); : QStringLiteral("%1 - att").arg(title));
@@ -123,23 +134,45 @@ void BrowserWindow::setMode(Mode mode)
switch (mode) { switch (mode) {
case Mode::Normal: case Mode::Normal:
m_status->setMode(QString()); m_status->setMode(QString());
m_status->show();
focusView(); focusView();
break; break;
case Mode::Insert: case Mode::Insert:
m_status->setMode(QStringLiteral("insert")); m_status->setMode(QStringLiteral("insert"));
m_status->show();
focusView(); focusView();
break; break;
case Mode::Command: case Mode::Command:
m_status->hide();
updateCompletion(); updateCompletion();
break; break;
case Mode::Hint: case Mode::Hint:
m_status->setMode(QStringLiteral("hint")); m_status->setMode(QStringLiteral("hint"));
m_status->show();
break; 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) bool BrowserWindow::eventFilter(QObject *watched, QEvent *event)
@@ -154,6 +187,12 @@ bool BrowserWindow::eventFilter(QObject *watched, QEvent *event)
if (key->key() == Qt::Key_Escape if (key->key() == Qt::Key_Escape
|| (key->key() == Qt::Key_BracketLeft && key->modifiers() == Qt::ControlModifier)) { || (key->key() == Qt::Key_BracketLeft && key->modifiers() == Qt::ControlModifier)) {
// 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); setMode(Mode::Normal);
return true; return true;
} }
+7
View File
@@ -55,6 +55,8 @@ private:
void scrollPages(double factor); void scrollPages(double factor);
void scrollToEnd(bool bottom); void scrollToEnd(bool bottom);
void focusView(); void focusView();
void setPageFullScreen(bool on);
void updateStatusVisibility();
AdBlocker *m_adBlocker; AdBlocker *m_adBlocker;
QWebEngineView *m_view; QWebEngineView *m_view;
@@ -65,4 +67,9 @@ private:
Mode m_mode = Mode::Normal; Mode m_mode = Mode::Normal;
QString m_pendingKeys; QString m_pendingKeys;
// Set while the page (e.g. a video) is fullscreen; m_windowStateBeforeFullScreen
// is what to go back to afterwards, so a maximized window stays maximized.
bool m_pageFullScreen = false;
Qt::WindowStates m_windowStateBeforeFullScreen;
}; };