From e8b1f69d633fe7aa2f692744a2fc41b43df3e78b Mon Sep 17 00:00:00 2001 From: Michel Dagenais Date: Fri, 22 May 2020 16:07:42 -0400 Subject: [PATCH] Meter widget on linux (#3454) Enable Meter Widgets overlaid on Video Window for Linux Meter Widgets, with a transparent background over the video window, use little screen estate while providing all the needed information. They were added for WIN32 first but actually work fine on Linux with minor flag adjustments. --- src/Train/MeterWidget.cpp | 7 ++++++- src/Train/VideoWindow.cpp | 29 +++++++++++------------------ src/Train/VideoWindow.h | 12 +++--------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/Train/MeterWidget.cpp b/src/Train/MeterWidget.cpp index a5ae0f586..23951f820 100644 --- a/src/Train/MeterWidget.cpp +++ b/src/Train/MeterWidget.cpp @@ -25,11 +25,16 @@ MeterWidget::MeterWidget(QString Name, QWidget *parent, QString Source) : QWidget(parent), m_Name(Name), m_container(parent), m_Source(Source) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setWindowFlags(Qt::Window | Qt::FramelessWindowHint); +#ifdef Q_OS_LINUX + setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); + setAttribute(Qt::WA_TranslucentBackground); +#else + setWindowFlags(Qt::Window | Qt::FramelessWindowHint); setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_PaintOnScreen); +#endif setAttribute(Qt::WA_TransparentForMouseEvents); diff --git a/src/Train/VideoWindow.cpp b/src/Train/VideoWindow.cpp index 619bce082..caa6ad644 100644 --- a/src/Train/VideoWindow.cpp +++ b/src/Train/VideoWindow.cpp @@ -86,30 +86,23 @@ VideoWindow::VideoWindow(Context *context) : //vlc_exceptions(&exceptions); - - /* This is a non working code that show how to hooks into a window, - * if we have a window around */ -#ifdef Q_OS_LINUX -#if QT_VERSION > 0x50000 - x11Container = new QWidget(this); //XXX PORT TO 5.1 BROKEN CODE XXX +#if (defined Q_OS_LINUX) && QT_VERSION <= 0x50000 + container = new QX11EmbedContainer(this); #else - x11Container = new QX11EmbedContainer(this); -#endif - layout->addWidget(x11Container); - libvlc_media_player_set_xwindow (mp, x11Container->winId()); + container = new QWidget(this); #endif -#ifdef Q_OS_MAC - container = new QWidget(this); layout->addWidget(container); - libvlc_media_player_set_nsobject (mp, (void*)(container->winId())); -#endif -#ifdef WIN32 - container = new QWidget(this); - layout->addWidget(container); +#if defined(WIN32) libvlc_media_player_set_hwnd (mp, (HWND)(container->winId())); +#elif defined(Q_OS_MAC) + libvlc_media_player_set_nsobject (mp, (void*)(container->winId())); +#elif defined(Q_OS_LINUX) + libvlc_media_player_set_xwindow (mp, container->winId()); +#endif +#if defined(WIN32) || defined(Q_OS_LINUX) // Video Overlays Initialization: if video config file is not present // copy a default one to be used as a model by the user. // An empty video-layout.xml file disables video overlays @@ -179,7 +172,7 @@ VideoWindow::~VideoWindow() #if (defined Q_OS_LINUX) && (QT_VERSION < 0x050000) && (defined GC_VIDEO_VLC) // unembed vlc backend first - x11Container->discardClient(); + container->discardClient(); #endif stopPlayback(); diff --git a/src/Train/VideoWindow.h b/src/Train/VideoWindow.h index e31fba6ca..b11b6833e 100644 --- a/src/Train/VideoWindow.h +++ b/src/Train/VideoWindow.h @@ -209,16 +209,10 @@ class VideoWindow : public GcChartWindow QMediaPlayer *mp; #endif -#ifdef Q_OS_LINUX -#if QT_VERSION > 0x050000 - QWidget *x11Container; -#else - QX11EmbedContainer *x11Container; -#endif -#endif - -#if defined(WIN32) || defined (Q_OS_MAC) +#if defined(WIN32) || defined (Q_OS_MAC) || (defined(Q_OS_LINUX) && QT_VERSION > 0x050000) QWidget *container; +#elif defined(Q_OS_LINUX) + QX11EmbedContainer *container; #endif bool init; // we initialised ok ?