Skip to content

Commit

Permalink
Merge pull request #6678 from spycrab/qt_pause_focusloss
Browse files Browse the repository at this point in the history
Qt: RenderWidget fixes
  • Loading branch information
Tilka committed Apr 22, 2018
2 parents c131b7c + caa18ed commit 50e80d6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt2/Config/Graphics/GeneralWidget.cpp
Expand Up @@ -165,7 +165,7 @@ void GeneralWidget::LoadSettings()
// Render to Main Window
m_render_main_window->setChecked(SConfig::GetInstance().bRenderToMain);
// Keep Window on Top
m_keep_window_top->setChecked(SConfig::GetInstance().bKeepWindowOnTop);
m_keep_window_top->setChecked(Settings::Instance().IsKeepWindowOnTopEnabled());
// Autoadjust Window size
m_autoadjust_window_size->setChecked(SConfig::GetInstance().bRenderWindowAutoSize);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ void GeneralWidget::SaveSettings()
// Render to Main Window
SConfig::GetInstance().bRenderToMain = m_render_main_window->isChecked();
// Keep Window on Top
SConfig::GetInstance().bKeepWindowOnTop = m_keep_window_top->isChecked();
Settings::Instance().SetKeepWindowOnTop(m_keep_window_top->isChecked());
// Autoadjust windowsize
SConfig::GetInstance().bRenderWindowAutoSize = m_autoadjust_window_size->isChecked();
}
Expand Down
17 changes: 17 additions & 0 deletions Source/Core/DolphinQt2/RenderWidget.cpp
Expand Up @@ -53,6 +53,9 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
connect(&Settings::Instance(), &Settings::HideCursorChanged, this,
&RenderWidget::OnHideCursorChanged);
OnHideCursorChanged();
connect(&Settings::Instance(), &Settings::KeepWindowOnTopChanged, this,
&RenderWidget::OnKeepOnTopChanged);
OnKeepOnTopChanged(Settings::Instance().IsKeepWindowOnTopEnabled());
m_mouse_timer->start(MOUSE_HIDE_DELAY);

SetFillBackground(true);
Expand All @@ -70,6 +73,14 @@ void RenderWidget::OnHideCursorChanged()
setCursor(Settings::Instance().GetHideCursor() ? Qt::BlankCursor : Qt::ArrowCursor);
}

void RenderWidget::OnKeepOnTopChanged(bool top)
{
setWindowFlags(top ? windowFlags() | Qt::WindowStaysOnTopHint :
windowFlags() & ~Qt::WindowStaysOnTopHint);

show();
}

void RenderWidget::HandleCursorTimer()
{
if (isActiveWindow())
Expand All @@ -90,6 +101,8 @@ bool RenderWidget::event(QEvent* event)
{
switch (event->type())
{
case QEvent::Paint:
return !autoFillBackground();
case QEvent::KeyPress:
{
QKeyEvent* ke = static_cast<QKeyEvent*>(event);
Expand All @@ -116,9 +129,13 @@ bool RenderWidget::event(QEvent* event)
break;
case QEvent::WindowActivate:
Host::GetInstance()->SetRenderFocus(true);
if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::State::Paused)
Core::SetState(Core::State::Running);
break;
case QEvent::WindowDeactivate:
Host::GetInstance()->SetRenderFocus(false);
if (SConfig::GetInstance().m_PauseOnFocusLost && Core::GetState() == Core::State::Running)
Core::SetState(Core::State::Paused);
break;
case QEvent::Resize:
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt2/RenderWidget.h
Expand Up @@ -29,6 +29,7 @@ class RenderWidget final : public QWidget
private:
void HandleCursorTimer();
void OnHideCursorChanged();
void OnKeepOnTopChanged(bool top);
void SetFillBackground(bool fill);

static constexpr int MOUSE_HIDE_DELAY = 3000;
Expand Down
14 changes: 14 additions & 0 deletions Source/Core/DolphinQt2/Settings.cpp
Expand Up @@ -130,6 +130,20 @@ bool Settings::GetHideCursor() const
return SConfig::GetInstance().bHideCursor;
}

void Settings::SetKeepWindowOnTop(bool top)
{
if (IsKeepWindowOnTopEnabled() == top)
return;

SConfig::GetInstance().bKeepWindowOnTop = top;
emit KeepWindowOnTopChanged(top);
}

bool Settings::IsKeepWindowOnTopEnabled() const
{
return SConfig::GetInstance().bKeepWindowOnTop;
}

int Settings::GetVolume() const
{
return SConfig::GetInstance().m_Volume;
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt2/Settings.h
Expand Up @@ -74,6 +74,8 @@ class Settings final : public QObject
// Graphics
void SetHideCursor(bool hide_cursor);
bool GetHideCursor() const;
void SetKeepWindowOnTop(bool top);
bool IsKeepWindowOnTopEnabled() const;

// Audio
int GetVolume() const;
Expand Down Expand Up @@ -126,6 +128,7 @@ class Settings final : public QObject
void DefaultGameChanged(const QString&);
void PathReloadRequested(const QString&);
void HideCursorChanged();
void KeepWindowOnTopChanged(bool top);
void VolumeChanged(int volume);
void NANDRefresh();
void RegistersVisibilityChanged(bool visible);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt2/Settings/InterfacePane.cpp
Expand Up @@ -178,7 +178,7 @@ void InterfacePane::LoadConfig()
{
const SConfig& startup_params = SConfig::GetInstance();
m_checkbox_auto_window->setChecked(startup_params.bRenderWindowAutoSize);
m_checkbox_top_window->setChecked(startup_params.bKeepWindowOnTop);
m_checkbox_top_window->setChecked(Settings::Instance().IsKeepWindowOnTopEnabled());
m_checkbox_render_to_window->setChecked(startup_params.bRenderToMain);
m_checkbox_use_builtin_title_database->setChecked(startup_params.m_use_builtin_title_database);
m_checkbox_show_debugging_ui->setChecked(Settings::Instance().IsDebugModeEnabled());
Expand All @@ -200,7 +200,7 @@ void InterfacePane::OnSaveConfig()
{
SConfig& settings = SConfig::GetInstance();
settings.bRenderWindowAutoSize = m_checkbox_auto_window->isChecked();
settings.bKeepWindowOnTop = m_checkbox_top_window->isChecked();
Settings::Instance().SetKeepWindowOnTop(m_checkbox_top_window->isChecked());
settings.bRenderToMain = m_checkbox_render_to_window->isChecked();
settings.m_use_builtin_title_database = m_checkbox_use_builtin_title_database->isChecked();
Settings::Instance().SetDebugModeEnabled(m_checkbox_show_debugging_ui->isChecked());
Expand Down

0 comments on commit 50e80d6

Please sign in to comment.