qtwebengine: enable video fullscreen
This commit is contained in:
@@ -39,7 +39,9 @@ Like qutebrowser, keys mean different things depending on the mode:
|
||||
| `command` | `o`, `O`, `:` | keys go to the command line |
|
||||
| `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
|
||||
> click into a text field on a page — press `i` first. Doing it automatically
|
||||
|
||||
+44
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ private:
|
||||
void scrollPages(double factor);
|
||||
void scrollToEnd(bool bottom);
|
||||
void focusView();
|
||||
void setPageFullScreen(bool on);
|
||||
void updateStatusVisibility();
|
||||
|
||||
AdBlocker *m_adBlocker;
|
||||
QWebEngineView *m_view;
|
||||
@@ -65,4 +67,9 @@ private:
|
||||
|
||||
Mode m_mode = Mode::Normal;
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user