Skip to content

Commit

Permalink
[controllers] Refresh controller list in GUI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed May 23, 2016
1 parent aa49b81 commit 4fa904f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
19 changes: 14 additions & 5 deletions xbmc/games/controllers/windows/GUIControllerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include "guilib/GUIButtonControl.h"
#include "guilib/GUIControlGroupList.h"
#include "guilib/GUIWindow.h"
#include "guilib/WindowIDs.h"
#include "input/joysticks/DefaultJoystick.h" // for DEFAULT_CONTROLLER_ID
#include "messaging/ApplicationMessenger.h"
#include "peripherals/Peripherals.h"

using namespace ADDON;
Expand Down Expand Up @@ -76,12 +78,12 @@ void CGUIControllerList::Deinitialize(void)
m_controllerButton = nullptr;
}

void CGUIControllerList::Refresh(void)
bool CGUIControllerList::Refresh(void)
{
CleanupButtons();

if (!RefreshControllers())
return;
return false;

CleanupButtons();

if (m_controllerList)
{
Expand All @@ -98,6 +100,8 @@ void CGUIControllerList::Refresh(void)
break;
}
}

return true;
}

void CGUIControllerList::OnFocus(unsigned int controllerIndex)
Expand Down Expand Up @@ -143,8 +147,13 @@ void CGUIControllerList::ResetController(void)

void CGUIControllerList::Notify(const Observable& obs, const ObservableMessage msg)
{
using namespace KODI::MESSAGING;

if (msg == ObservableMessageAddons)
Refresh();
{
CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow->GetID(), CONTROL_CONTROLLER_LIST);
CApplicationMessenger::GetInstance().SendGUIMessage(msg);
}
}

bool CGUIControllerList::RefreshControllers(void)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/controllers/windows/GUIControllerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace GAME
// implementation of IControllerList
virtual bool Initialize(void) override;
virtual void Deinitialize(void) override;
virtual void Refresh(void) override;
virtual bool Refresh(void) override;
virtual void OnFocus(unsigned int controllerIndex) override;
virtual void OnSelect(unsigned int controllerIndex) override;
virtual void ResetController(void) override;
Expand Down
14 changes: 14 additions & 0 deletions xbmc/games/controllers/windows/GUIControllerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ bool CGUIControllerWindow::OnMessage(CGUIMessage& message)
}
break;
}
case GUI_MSG_REFRESH_LIST:
{
int controlId = message.GetControlId();

if (controlId == CONTROL_CONTROLLER_LIST)
{
if (m_controllerList && m_controllerList->Refresh())
{
CGUIDialog::OnMessage(message);
return true;
}
}
break;
}
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion xbmc/games/controllers/windows/IConfigurationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ namespace GAME

/*!
* \brief Refresh the contents of the list
* \return True if the list was changed
*/
virtual void Refresh(void) = 0;
virtual bool Refresh(void) = 0;

/*
* \brief The specified controller has been focused
Expand Down

0 comments on commit 4fa904f

Please sign in to comment.