Skip to content

Commit

Permalink
MythDisplay: Cleanup SetWidget method
Browse files Browse the repository at this point in the history
- make it protected as it should only be accessed from MythMainWindow
- move screen for virtual desktops, otherwise set the screen - not both
  • Loading branch information
mark-kendall committed Nov 30, 2019
1 parent 2d3db8f commit 6955b12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
44 changes: 26 additions & 18 deletions mythtv/libs/libmythui/mythdisplay.cpp
Expand Up @@ -126,31 +126,39 @@ void MythDisplay::SetWidget(QWidget *MainWindow)
QWidget* old = m_widget;
m_widget = MainWindow;

if (m_widget)
if (!m_widget)
{
if (m_widget != old)
LOG(VB_GENERAL, LOG_INFO, LOC + "New main widget");
QWindow* window = m_widget->windowHandle();
if (window)
LOG(VB_GENERAL, LOG_INFO, LOC + "Widget removed");
return;
}

if (m_widget != old)
LOG(VB_GENERAL, LOG_INFO, LOC + "New main widget");
QWindow* window = m_widget->windowHandle();
if (window)
{
QScreen *desired = GetDesiredScreen();
if (desired && (desired != window->screen()))
{
QScreen *desired = GetDesiredScreen();
if (desired && (desired != window->screen()))
{
DebugScreen(desired, "Moving to");
DebugScreen(desired, "Moving to");

// If this is a virtual desktop, move the window into the screen,
// otherwise just set the screen - both of which should trigger a
// screenChanged event.
// TODO Confirm this check for non-virtual screens (OSX?)
// TODO If the screens are non-virtual - can we actually safely move?
// (SetWidget is only called from MythMainWindow before the render
// device is created - so should be safe).
if (desired->geometry() == desired->virtualGeometry())
window->setScreen(desired);
if (desired->geometry() != desired->virtualGeometry())
m_widget->move(desired->geometry().topLeft());
}
connect(window, &QWindow::screenChanged, this, &MythDisplay::ScreenChanged);
}
else
{
LOG(VB_GENERAL, LOG_WARNING, LOC + "Widget does not have a window");
else
m_widget->move(desired->geometry().topLeft());
}
connect(window, &QWindow::screenChanged, this, &MythDisplay::ScreenChanged);
}
else
{
LOG(VB_GENERAL, LOG_INFO, LOC + "Widget removed");
LOG(VB_GENERAL, LOG_WARNING, LOC + "Widget does not have a window!");
}
}

Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythui/mythdisplay.h
Expand Up @@ -39,6 +39,8 @@ class MUI_PUBLIC MythDisplay : public QObject, public ReferenceCounter
{
Q_OBJECT

friend class MythMainWindow;

public:
static MythDisplay* AcquireRelease(bool Acquire = true);

Expand All @@ -52,7 +54,6 @@ class MUI_PUBLIC MythDisplay : public QObject, public ReferenceCounter
MAX_MODES = 5,
} Mode;

void SetWidget (QWidget *MainWindow);
QScreen* GetCurrentScreen (void);
int GetScreenCount (void);
double GetPixelAspectRatio(void);
Expand Down Expand Up @@ -87,6 +88,7 @@ class MUI_PUBLIC MythDisplay : public QObject, public ReferenceCounter
MythDisplay();
virtual ~MythDisplay();

void SetWidget (QWidget *MainWindow);
QScreen* GetDesiredScreen (void);
static void DebugScreen (QScreen *qScreen, const QString &Message);
static float SanitiseRefreshRate(int Rate);
Expand Down

0 comments on commit 6955b12

Please sign in to comment.