[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt/compositor(s): Add activeFocusItem getter
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Fri Jan 7 09:59:50 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
c8b90454 by Benjamin Arnaud at 2022-01-07T09:35:44+00:00
qt/compositor(s): Add activeFocusItem getter
- - - - -
b066b7f1 by Benjamin Arnaud at 2022-01-07T09:35:44+00:00
qt/mainctx: Add the 'preferHotkeys' property
- - - - -
75f32c74 by Benjamin Arnaud at 2022-01-07T09:35:44+00:00
qt/main_interface: Make sendHotkey public
- - - - -
76eccbfb by Benjamin Arnaud at 2022-01-07T09:35:44+00:00
qt/interface_window_handler: Add filtering for hotkeys
fix #26203
- - - - -
c0756e0b by Benjamin Arnaud at 2022-01-07T09:35:44+00:00
qml/Player: Add 'preferHotkeys' implementation
- - - - -
18 changed files:
- modules/gui/qt/maininterface/compositor.hpp
- modules/gui/qt/maininterface/compositor_dcomp.cpp
- modules/gui/qt/maininterface/compositor_dcomp.hpp
- modules/gui/qt/maininterface/compositor_dcomp_uisurface.cpp
- modules/gui/qt/maininterface/compositor_dcomp_uisurface.hpp
- modules/gui/qt/maininterface/compositor_dummy.cpp
- modules/gui/qt/maininterface/compositor_dummy.hpp
- modules/gui/qt/maininterface/compositor_win7.cpp
- modules/gui/qt/maininterface/compositor_win7.hpp
- modules/gui/qt/maininterface/compositor_x11.cpp
- modules/gui/qt/maininterface/compositor_x11.hpp
- modules/gui/qt/maininterface/compositor_x11_uisurface.cpp
- modules/gui/qt/maininterface/compositor_x11_uisurface.hpp
- modules/gui/qt/maininterface/interface_window_handler.cpp
- modules/gui/qt/maininterface/interface_window_handler.hpp
- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/player/qml/Player.qml
Changes:
=====================================
modules/gui/qt/maininterface/compositor.hpp
=====================================
@@ -76,6 +76,7 @@ public:
virtual QWindow* interfaceMainWindow() const = 0;
+ virtual QQuickItem * activeFocusItem() const = 0;
};
/**
@@ -97,6 +98,8 @@ public:
public:
virtual QQmlEngine* engine() const = 0;
virtual void setContent(QQmlComponent *component, QQuickItem *item) = 0;
+
+ virtual QQuickItem * activeFocusItem() const = 0;
};
public:
explicit CompositorVideo(qt_intf_t* p_intf, QObject* parent = nullptr);
@@ -125,7 +128,6 @@ protected:
private:
bool commonGUICreateImpl(QWindow* window, CompositorVideo::Flags flags);
-
protected slots:
virtual void onSurfacePositionChanged(const QPointF&) {}
virtual void onSurfaceSizeChanged(const QSizeF&) {}
=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -387,4 +387,9 @@ void CompositorDirectComposition::removeVisual(Microsoft::WRL::ComPtr<IDComposit
m_dcompDevice->Commit();
}
+QQuickItem * CompositorDirectComposition::activeFocusItem() const /* override */
+{
+ return m_uiSurface->activeFocusItem();
+}
+
}
=====================================
modules/gui/qt/maininterface/compositor_dcomp.hpp
=====================================
@@ -58,6 +58,8 @@ public:
void addVisual(Microsoft::WRL::ComPtr<IDCompositionVisual> visual);
void removeVisual(Microsoft::WRL::ComPtr<IDCompositionVisual> visual);
+ QQuickItem * activeFocusItem() const override;
+
private slots:
void onSurfacePositionChanged(const QPointF& position) override;
void onSurfaceSizeChanged(const QSizeF& size) override;
=====================================
modules/gui/qt/maininterface/compositor_dcomp_uisurface.cpp
=====================================
@@ -516,6 +516,11 @@ void CompositorDCompositionUISurface::setContent(QQmlComponent*, QQuickItem* ro
requestUpdate();
}
+QQuickItem * CompositorDCompositionUISurface::activeFocusItem() const /* override */
+{
+ return m_uiWindow->activeFocusItem();
+}
+
void CompositorDCompositionUISurface::render()
{
EGLBoolean eglRet;
=====================================
modules/gui/qt/maininterface/compositor_dcomp_uisurface.hpp
=====================================
@@ -97,6 +97,8 @@ public:
void setContent(QQmlComponent* component, QQuickItem* rootItem) override;
+ QQuickItem * activeFocusItem() const override;
+
void timerEvent(QTimerEvent *event) override;
bool eventFilter(QObject* object, QEvent* event) override;
=====================================
modules/gui/qt/maininterface/compositor_dummy.cpp
=====================================
@@ -92,4 +92,9 @@ Compositor::Type CompositorDummy::type() const
return Compositor::DummyCompositor;
}
+QQuickItem * CompositorDummy::activeFocusItem() const /* override */
+{
+ return m_qmlWidget->activeFocusItem();
+}
+
}
=====================================
modules/gui/qt/maininterface/compositor_dummy.hpp
=====================================
@@ -61,6 +61,8 @@ public:
Type type() const override;
+ QQuickItem * activeFocusItem() const override;
+
protected:
qt_intf_t *m_intf;
=====================================
modules/gui/qt/maininterface/compositor_win7.cpp
=====================================
@@ -190,6 +190,11 @@ Compositor::Type CompositorWin7::type() const
return Compositor::Win7Compositor;
}
+QQuickItem * CompositorWin7::activeFocusItem() const /* override */
+{
+ return m_qmlView->activeFocusItem();
+}
+
bool CompositorWin7::eventFilter(QObject*, QEvent* ev)
{
if (!m_videoWidget || !m_qmlView)
=====================================
modules/gui/qt/maininterface/compositor_win7.hpp
=====================================
@@ -58,6 +58,8 @@ public:
Type type() const override;
+ QQuickItem * activeFocusItem() const override;
+
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
=====================================
modules/gui/qt/maininterface/compositor_x11.cpp
=====================================
@@ -209,3 +209,8 @@ bool CompositorX11::setupVoutWindow(vout_window_t* p_wnd, VoutDestroyCb destroyC
commonSetupVoutWindow(p_wnd, destroyCb);
return true;
}
+
+QQuickItem * CompositorX11::activeFocusItem() const /* override */
+{
+ return m_qmlView->activeFocusItem();
+}
=====================================
modules/gui/qt/maininterface/compositor_x11.hpp
=====================================
@@ -55,6 +55,8 @@ public:
inline QWindow* interfaceMainWindow() const override { return m_interfaceWindow; };
+ QQuickItem * activeFocusItem() const override;
+
private:
int windowEnable(const vout_window_cfg_t *) override;
void windowDisable() override;
=====================================
modules/gui/qt/maininterface/compositor_x11_uisurface.cpp
=====================================
@@ -90,6 +90,11 @@ void CompositorX11UISurface::setContent(QQmlComponent*, QQuickItem* rootItem)
updateSizes();
}
+QQuickItem * CompositorX11UISurface::activeFocusItem() const /* override */
+{
+ return m_uiWindow->activeFocusItem();
+}
+
void CompositorX11UISurface::createFbo()
{
//write to the immediate context
=====================================
modules/gui/qt/maininterface/compositor_x11_uisurface.hpp
=====================================
@@ -59,6 +59,8 @@ public:
void setContent(QQmlComponent*, QQuickItem* rootItem) override;
QQmlEngine* engine() const override { return m_qmlEngine; }
+ QQuickItem * activeFocusItem() const override;
+
signals:
void beforeRendering();
void afterRendering();
=====================================
modules/gui/qt/maininterface/interface_window_handler.cpp
=====================================
@@ -17,9 +17,13 @@
*****************************************************************************/
#include "interface_window_handler.hpp"
#include "mainctx.hpp"
+#include "compositor.hpp"
#include <player/player_controller.hpp>
#include <playlist/playlist_controller.hpp>
+#include "util/keyhelper.hpp"
#include <QScreen>
+#include <QQmlProperty>
+
InterfaceWindowHandler::InterfaceWindowHandler(qt_intf_t *_p_intf, MainCtx* mainCtx, QWindow* window, QObject *parent)
: QObject(parent)
@@ -178,6 +182,21 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
}
break;
}
+ case QEvent::KeyPress:
+ {
+ QKeyEvent * keyEvent = static_cast<QKeyEvent *> (event);
+
+ if (applyKeyEvent(keyEvent) == false)
+ return false;
+
+ m_mainCtx->sendHotkey(static_cast<Qt::Key> (keyEvent->key()), keyEvent->modifiers());
+
+ return true;
+ }
+ case QEvent::KeyRelease:
+ {
+ return applyKeyEvent(static_cast<QKeyEvent *> (event));
+ }
case QEvent::Wheel:
{
QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
@@ -330,3 +349,37 @@ void InterfaceWindowHandler::setInterfaceAlwaysOnTop( bool on_top )
{
WindowStateHolder::holdOnTop(m_window, WindowStateHolder::INTERFACE, on_top);
}
+
+// Functions private
+
+bool InterfaceWindowHandler::applyKeyEvent(QKeyEvent * event) const
+{
+ int key = event->key();
+
+ // NOTE: We have to make sure tab and backtab are never used as hotkeys.
+ if (key == Qt::Key_Tab || key == Qt::Key_Backtab)
+ return false;
+
+ // NOTE: When browsing the MediaLibrary, we let the view handle the navigation keys.
+ if (m_mainCtx->preferHotkeys() == false && (KeyHelper::matchLeft(event) ||
+ KeyHelper::matchRight(event) ||
+ KeyHelper::matchUp(event) ||
+ KeyHelper::matchDown(event) ||
+ KeyHelper::matchCancel(event)))
+ return false;
+
+ QQuickItem * item = p_intf->p_compositor->activeFocusItem();
+
+ if (item && item->inherits("QQuickControl"))
+ {
+ // NOTE: This item has visual focus so we let it handle the key.
+ if (QQmlProperty(item, "visualFocus", qmlContext(item)).read().toBool())
+ return false;
+
+ event->accept();
+
+ return true;
+ }
+
+ return false;
+}
=====================================
modules/gui/qt/maininterface/interface_window_handler.hpp
=====================================
@@ -55,6 +55,8 @@ signals:
void incrementIntfUserScaleFactor(bool increment);
private:
+ bool applyKeyEvent(QKeyEvent * event) const;
+
#if QT_CLIENT_SIDE_DECORATION_AVAILABLE
virtual void updateCSDWindowSettings();
#endif
=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -822,3 +822,18 @@ void MainCtx::setAcrylicActive(bool newAcrylicActive)
m_acrylicActive = newAcrylicActive;
emit acrylicActiveChanged();
}
+
+bool MainCtx::preferHotkeys() const
+{
+ return m_preferHotkeys;
+}
+
+void MainCtx::setPreferHotkeys(bool enable)
+{
+ if (m_preferHotkeys == enable)
+ return;
+
+ m_preferHotkeys = enable;
+
+ emit preferHotkeysChanged();
+}
=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -177,6 +177,9 @@ class MainCtx : public QObject
// This Property only works if hasAcrylicSurface is set
Q_PROPERTY(bool acrylicActive READ acrylicActive WRITE setAcrylicActive NOTIFY acrylicActiveChanged FINAL)
+ // NOTE: This is useful when we want to prioritize player hotkeys over QML keyboard navigation.
+ Q_PROPERTY(bool preferHotkeys READ preferHotkeys WRITE setPreferHotkeys NOTIFY preferHotkeysChanged FINAL)
+
public:
/* tors */
MainCtx(qt_intf_t *);
@@ -255,6 +258,9 @@ public:
bool acrylicActive() const;
void setAcrylicActive(bool newAcrylicActive);
+ bool preferHotkeys() const;
+ void setPreferHotkeys(bool enable);
+
protected:
/* Systray */
void createSystray();
@@ -318,6 +324,8 @@ protected:
bool m_smoothScroll = true;
+ bool m_preferHotkeys = false;
+
public slots:
void toggleUpdateSystrayMenu();
void showUpdateSystrayMenu();
@@ -336,6 +344,8 @@ public slots:
void onWindowVisibilityChanged(QWindow::Visibility);
void setHasAcrylicSurface(bool);
+ void sendHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers );
+
void emitBoss();
void emitRaise();
void emitShow();
@@ -350,8 +360,6 @@ protected slots:
void onInputChanged( bool );
- void sendHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers );
-
signals:
void minimalViewToggled( bool );
void fullscreenInterfaceToggled( bool );
@@ -391,6 +399,8 @@ signals:
void smoothScrollChanged();
+ void preferHotkeysChanged();
+
private:
void loadPrefs(bool callSignals);
void loadFromSettingsImpl(bool callSignals);
=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -47,7 +47,12 @@ FocusScope {
// NOTE: We force the night theme when playing a video.
readonly property VLCColors colors: (MainCtx.hasEmbededVideo) ? VLCStyle.nightColors
- : VLCStyle.colors
+ : VLCStyle.colors
+
+ // Events
+
+ Component.onCompleted: MainCtx.preferHotkeys = true
+ Component.onDestruction: MainCtx.preferHotkeys = false
Keys.priority: Keys.AfterItem
Keys.onPressed: {
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/56c4b6f13def4499826d74a0687477c46d614c86...c0756e0be47fc44f9888dca86f03e99f29e6122f
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/56c4b6f13def4499826d74a0687477c46d614c86...c0756e0be47fc44f9888dca86f03e99f29e6122f
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list