Skip to content

Commit

Permalink
Merge pull request #12105 from xhaggi/cleanup-restore-modeless-dialogs
Browse files Browse the repository at this point in the history
[gui] no need to store/restore modeless dialogs while unload/load skin
  • Loading branch information
MartijnKaijser committed May 16, 2017
2 parents 98d9f5c + c48862b commit db1c544
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
46 changes: 22 additions & 24 deletions xbmc/Application.cpp
Expand Up @@ -1600,8 +1600,9 @@ bool CApplication::LoadSkin(const std::string& skinID)
skin = std::static_pointer_cast<ADDON::CSkinInfo>(addon);
}

bool bPreviousPlayingState=false;
bool bPreviousRenderingState=false;
// store player and rendering state
bool bPreviousPlayingState = false;
bool bPreviousRenderingState = false;
if (m_pPlayer->IsPlayingVideo())
{
bPreviousPlayingState = !m_pPlayer->IsPausedPlayback();
Expand All @@ -1614,17 +1615,18 @@ bool CApplication::LoadSkin(const std::string& skinID)
bPreviousRenderingState = true;
}
}
// close the music and video overlays (they're re-opened automatically later)

CSingleLock lock(g_graphicsContext);

// save the current window details and focused control
int currentWindow = g_windowManager.GetActiveWindow();
int iCtrlID = -1;
CGUIWindow* pWindow = g_windowManager.GetWindow(currentWindow);
if (pWindow)
iCtrlID = pWindow->GetFocusedControlID();
std::vector<int> currentModelessWindows;
g_windowManager.GetActiveModelessWindows(currentModelessWindows);
// store current active window with its focused control
int currentWindowID = g_windowManager.GetActiveWindow();
int currentFocusedControlID = -1;
if (currentWindowID != WINDOW_INVALID)
{
CGUIWindow* pWindow = g_windowManager.GetWindow(currentWindowID);
if (pWindow)
currentFocusedControlID = pWindow->GetFocusedControlID();
}

UnloadSkin();

Expand All @@ -1650,7 +1652,7 @@ bool CApplication::LoadSkin(const std::string& skinID)
g_colorManager.Load(m_ServiceManager->GetSettings().GetString(CSettings::SETTING_LOOKANDFEEL_SKINCOLORS));

g_SkinInfo->LoadIncludes();

g_fontManager.LoadFonts(m_ServiceManager->GetSettings().GetString(CSettings::SETTING_LOOKANDFEEL_FONT));

// load in the skin strings
Expand Down Expand Up @@ -1693,34 +1695,30 @@ bool CApplication::LoadSkin(const std::string& skinID)
// leave the graphics lock
lock.Leave();

// restore windows
if (currentWindow != WINDOW_INVALID)
// restore active window
if (currentWindowID != WINDOW_INVALID)
{
g_windowManager.ActivateWindow(currentWindow);
for (unsigned int i = 0; i < currentModelessWindows.size(); i++)
{
CGUIDialog *dialog = g_windowManager.GetDialog(currentModelessWindows[i]);
if (dialog)
dialog->Open();
}
if (iCtrlID != -1)
g_windowManager.ActivateWindow(currentWindowID);
if (currentFocusedControlID != -1)
{
pWindow = g_windowManager.GetWindow(currentWindow);
CGUIWindow *pWindow = g_windowManager.GetWindow(currentWindowID);
if (pWindow && pWindow->HasSaveLastControl())
{
CGUIMessage msg(GUI_MSG_SETFOCUS, currentWindow, iCtrlID, 0);
CGUIMessage msg(GUI_MSG_SETFOCUS, currentWindowID, currentFocusedControlID, 0);
pWindow->OnMessage(msg);
}
}
}

// restore player and rendering state
if (m_pPlayer->IsPlayingVideo())
{
if (bPreviousPlayingState)
m_pPlayer->Pause();
if (bPreviousRenderingState)
g_windowManager.ActivateWindow(WINDOW_FULLSCREEN_VIDEO);
}

return true;
}

Expand Down
23 changes: 16 additions & 7 deletions xbmc/guilib/GUIWindowManager.cpp
Expand Up @@ -1244,6 +1244,7 @@ void CGUIWindowManager::DeInitialize()
for (int i = 0; i < int(m_vecCustomWindows.size()); i++)
{
CGUIWindow *pWindow = m_vecCustomWindows[i];
RemoveFromWindowHistory(pWindow->GetID());
Remove(pWindow->GetID());
delete pWindow;
}
Expand Down Expand Up @@ -1548,15 +1549,23 @@ void CGUIWindowManager::AddToWindowHistory(int newWindowID)
}
}

void CGUIWindowManager::GetActiveModelessWindows(std::vector<int> &ids)
void CGUIWindowManager::RemoveFromWindowHistory(int windowID)
{
// run through our modeless windows, and construct a vector of them
// useful for saving and restoring the modeless windows on skin change etc.
CSingleLock lock(g_graphicsContext);
for (const auto& window : m_activeDialogs)
std::stack<int> stack = m_windowHistory;

// pop windows from stack until we found the window
while (!stack.empty())
{
if (stack.top() == windowID)
break;
stack.pop();
}

// found window in history
if (!stack.empty())
{
if (!window->IsModalDialog())
ids.push_back(window->GetID());
stack.pop(); // remove window from stack
m_windowHistory = stack;
}
}

Expand Down
11 changes: 10 additions & 1 deletion xbmc/guilib/GUIWindowManager.h
Expand Up @@ -210,7 +210,7 @@ class CGUIWindowManager : public KODI::MESSAGING::IMessageTarget
* \return true if the given window is a python window, otherwise false.
*/
bool IsPythonWindow(int id) const { return (id >= WINDOW_PYTHON_START && id <= WINDOW_PYTHON_END); };
void GetActiveModelessWindows(std::vector<int> &ids);

#ifdef _DEBUG
void DumpTextureUse();
#endif
Expand All @@ -220,6 +220,15 @@ class CGUIWindowManager : public KODI::MESSAGING::IMessageTarget
void LoadNotOnDemandWindows();
void UnloadNotOnDemandWindows();
void AddToWindowHistory(int newWindowID);

/*!
\brief Check if the given window id is in the window history, and if so, remove this
window and all overlying windows from the history so that we always have a predictable
"Back" behaviour for each window.
\param windowID the window id to remove from the window history
*/
void RemoveFromWindowHistory(int windowID);
void ClearWindowHistory();
void CloseWindowSync(CGUIWindow *window, int nextWindowID = 0);
CGUIWindow *GetTopMostDialog() const;
Expand Down

0 comments on commit db1c544

Please sign in to comment.