[vlc-devel] [PATCH] Qt: Properly report vout size when HiDPI scaling enabled

Anatoliy Anischovich lin.aaa.lin at gmail.com
Sat Oct 15 20:09:17 CEST 2016


---
 modules/gui/qt/components/interface_widgets.cpp | 61 ++++++++++++++++++++++---
 modules/gui/qt/components/interface_widgets.hpp |  3 ++
 modules/gui/qt/qt.hpp                           |  1 +
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index db590c5..a7c0c25 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -62,6 +62,11 @@
 #   include <qx11info_x11.h>
 #endif
 
+#if defined(_WIN32) && HAS_QT5
+#include <QWindow>
+#include <qpa/qplatformnativeinterface.h>
+#endif
+
 #include <math.h>
 #include <assert.h>
 
@@ -178,6 +183,53 @@ WId VideoWidget::request( struct vout_window_t *p_wnd, unsigned int *pi_width,
     return stable->winId();
 }
 
+void VideoWidget::reportSize()
+{
+    if( !p_window )
+        return;
+
+    unsigned int w, h;
+
+#if defined(Q_WS_X11) && HAS_QT5
+    Display *p_x_display = QX11Info::display();
+    Window x_window = stable->winId();
+    XWindowAttributes x_attributes;
+
+    XGetWindowAttributes( p_x_display, x_window, &x_attributes );
+
+    w = x_attributes.width;
+    h = x_attributes.height;
+#elif defined(_WIN32) && HAS_QT5
+    HWND hwnd;
+    RECT rect;
+
+    QWindow *window = stable->windowHandle();
+    hwnd = static_cast<HWND>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", window));
+
+    GetClientRect(hwnd, &rect);
+
+    w = rect.right;
+    h = rect.bottom;
+#else
+    QSize current_size = size();
+
+#   if HAS_QT56
+    /* Android-like scaling */
+    current_size *= devicePixelRatioF();
+#   elif HAS_QT54
+    /* OSX-like scaling */
+    current_size *= devicePixelRatio();
+#   else
+#       warning "No HiDPI support"
+#   endif
+
+    w = current_size.width();
+    h = current_size.height();
+#endif
+
+    vout_window_ReportSize( p_window, w, h );
+}
+
 /* Set the Widget to the correct Size */
 /* Function has to be called by the parent
    Parent has to care about resizing itself */
@@ -188,8 +240,7 @@ void VideoWidget::setSize( unsigned int w, unsigned int h )
      */
     if( (unsigned)size().width() == w && (unsigned)size().height() == h )
     {
-        if( p_window != NULL )
-            vout_window_ReportSize( p_window, w, h );
+        reportSize();
         return;
     }
 
@@ -207,11 +258,9 @@ void VideoWidget::setSize( unsigned int w, unsigned int h )
 
 void VideoWidget::resizeEvent( QResizeEvent *event )
 {
-    if( p_window != NULL )
-        vout_window_ReportSize( p_window, event->size().width(),
-                                event->size().height() );
-
     QWidget::resizeEvent( event );
+
+    reportSize();
 }
 
 void VideoWidget::release( void )
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index a07119e..6257187 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -77,6 +77,9 @@ private:
 
     QWidget *stable;
     QLayout *layout;
+
+    void reportSize();
+
 signals:
     void sizeChanged( int, int );
 
diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
index 99ce132..9459896 100644
--- a/modules/gui/qt/qt.hpp
+++ b/modules/gui/qt/qt.hpp
@@ -47,6 +47,7 @@
 #endif
 
 #define HAS_QT5  ( QT_VERSION >= 0x050000 )
+#define HAS_QT54 ( QT_VERSION >= 0x050400 )
 #define HAS_QT56 ( QT_VERSION >= 0x050600 )
 
 /* Q_DECL_OVERRIDE is a Qt5 feature, add empty define to not break with Qt4 */
-- 
2.7.3



More information about the vlc-devel mailing list