[vlc-commits] Qt: Properly report vout size when HiDPI scaling enabled
Anatoliy Anischovich
git at videolan.org
Wed Mar 15 17:30:57 CET 2017
vlc | branch: master | Anatoliy Anischovich <lin.aaa.lin at gmail.com> | Sat Oct 15 21:09:17 2016 +0300| [09ca4fc953c4c0de3d9f258f0ab13e0b55c41a8c] | committer: Hugo Beauzée-Luyssen
Qt: Properly report vout size when HiDPI scaling enabled
Fix #17484
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
Modified-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=09ca4fc953c4c0de3d9f258f0ab13e0b55c41a8c
---
modules/gui/qt/components/interface_widgets.cpp | 64 ++++++++++++++++++++++---
modules/gui/qt/components/interface_widgets.hpp | 4 ++
modules/gui/qt/qt.hpp | 1 +
3 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 6a5853b..4f1deee 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -59,6 +59,11 @@
# include <QWindow>
#endif
+#if defined(_WIN32) && HAS_QT5
+#include <QWindow>
+#include <qpa/qplatformnativeinterface.h>
+#endif
+
#include <math.h>
#include <assert.h>
@@ -176,6 +181,56 @@ bool VideoWidget::request( struct vout_window_t *p_wnd )
return true;
}
+QSize VideoWidget::physicalSize() const
+{
+#if defined(HAVE_X11_XLIB_H) && HAS_QT5
+ if ( QX11Info::isPlatformX11() )
+ {
+ Display *p_x_display = QX11Info::display();
+ Window x_window = stable->winId();
+ XWindowAttributes x_attributes;
+
+ XGetWindowAttributes( p_x_display, x_window, &x_attributes );
+
+ return QSize( x_attributes.width, x_attributes.height );
+ }
+#endif
+#if defined(_WIN32) && HAS_QT5
+ HWND hwnd;
+ RECT rect;
+
+ QWindow *window = stable->windowHandle();
+ hwnd = static_cast<HWND>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", window));
+
+ GetClientRect(hwnd, &rect);
+
+ return QSize( rect.right, rect.bottom );
+#endif
+
+ 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
+
+ return current_size;
+}
+
+void VideoWidget::reportSize()
+{
+ if( !p_window )
+ return;
+
+ QSize size = physicalSize();
+ vout_window_ReportSize( p_window, size.width(), size.height() );
+}
+
/* Set the Widget to the correct Size */
/* Function has to be called by the parent
Parent has to care about resizing itself */
@@ -186,8 +241,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;
}
@@ -205,11 +259,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();
}
int VideoWidget::qtMouseButton2VLC( Qt::MouseButton qtButton )
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index e41cdfb..9d084a9 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -74,6 +74,7 @@ protected:
void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ QSize physicalSize() const;
private:
int qtMouseButton2VLC( Qt::MouseButton );
@@ -82,6 +83,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 e416c56..f4c1d15 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 */
More information about the vlc-commits
mailing list