Skip to content

Commit

Permalink
[PR 119] Replaced deviceName with Location
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-pants authored and garbear committed Sep 16, 2020
1 parent 8baabae commit 1fc4006
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 33 deletions.
12 changes: 6 additions & 6 deletions xbmc/games/controllers/dialogs/GUIDialogAxisDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool CGUIDialogAxisDetection::MapPrimitiveInternal(JOYSTICK::IButtonMap* buttonM
const JOYSTICK::CDriverPrimitive& primitive)
{
if (primitive.Type() == JOYSTICK::PRIMITIVE_TYPE::SEMIAXIS)
AddAxis(buttonMap->DeviceName(), primitive.Index());
AddAxis(buttonMap->Location(), primitive.Index());

return true;
}
Expand All @@ -66,19 +66,19 @@ bool CGUIDialogAxisDetection::AcceptsPrimitive(JOYSTICK::PRIMITIVE_TYPE type) co
void CGUIDialogAxisDetection::OnLateAxis(const JOYSTICK::IButtonMap* buttonMap,
unsigned int axisIndex)
{
AddAxis(buttonMap->DeviceName(), axisIndex);
AddAxis(buttonMap->Location(), axisIndex);
}

void CGUIDialogAxisDetection::AddAxis(const std::string& deviceName, unsigned int axisIndex)
void CGUIDialogAxisDetection::AddAxis(const std::string& deviceLocation, unsigned int axisIndex)
{
auto it = std::find_if(m_detectedAxes.begin(), m_detectedAxes.end(),
[&deviceName, axisIndex](const AxisEntry& axis) {
return axis.first == deviceName && axis.second == axisIndex;
[&deviceLocation, axisIndex](const AxisEntry& axis) {
return axis.first == deviceLocation && axis.second == axisIndex;
});

if (it == m_detectedAxes.end())
{
m_detectedAxes.emplace_back(std::make_pair(deviceName, axisIndex));
m_detectedAxes.emplace_back(std::make_pair(deviceLocation, axisIndex));
m_captureEvent.Set();
}
}
2 changes: 1 addition & 1 deletion xbmc/games/controllers/dialogs/GUIDialogAxisDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CGUIDialogAxisDetection : public CGUIDialogButtonCapture
void OnClose(bool bAccepted) override {}

private:
void AddAxis(const std::string& deviceName, unsigned int axisIndex);
void AddAxis(const std::string& deviceLocation, unsigned int axisIndex);

// Axis types
using DeviceName = std::string;
Expand Down
14 changes: 7 additions & 7 deletions xbmc/games/controllers/dialogs/GUIDialogIgnoreInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ bool CGUIDialogIgnoreInput::MapPrimitiveInternal(JOYSTICK::IButtonMap* buttonMap
const JOYSTICK::CDriverPrimitive& primitive)
{
// Check if we have already started capturing primitives for a device
const bool bHasDevice = !m_deviceName.empty();
const bool bHasDevice = !m_location.empty();

// If a primitive comes from a different device, ignore it
if (bHasDevice && m_deviceName != buttonMap->DeviceName())
if (bHasDevice && m_location != buttonMap->Location())
{
CLog::Log(LOGDEBUG, "%s: ignoring input from device %s", buttonMap->ControllerID().c_str(),
buttonMap->DeviceName().c_str());
buttonMap->Location().c_str());
return false;
}

if (!bHasDevice)
{
CLog::Log(LOGDEBUG, "%s: capturing input for device %s", buttonMap->ControllerID().c_str(),
buttonMap->DeviceName().c_str());
m_deviceName = buttonMap->DeviceName();
buttonMap->Location().c_str());
m_location = buttonMap->Location();
}

if (AddPrimitive(primitive))
Expand All @@ -96,10 +96,10 @@ void CGUIDialogIgnoreInput::OnClose(bool bAccepted)
{
// See documentation of IButtonMapCallback::ResetIgnoredPrimitives()
// for why this call is needed
if (m_deviceName.empty())
if (m_location.empty())
callback.second->ResetIgnoredPrimitives();

if (m_deviceName.empty() || m_deviceName == callback.first)
if (m_location.empty() || m_location == callback.first)
callback.second->SaveButtonMap();
}
else
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/controllers/dialogs/GUIDialogIgnoreInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CGUIDialogIgnoreInput : public CGUIDialogButtonCapture
private:
bool AddPrimitive(const JOYSTICK::CDriverPrimitive& primitive);

std::string m_deviceName;
std::string m_location;
std::vector<JOYSTICK::CDriverPrimitive> m_capturedPrimitives;
};
} // namespace GAME
Expand Down
19 changes: 10 additions & 9 deletions xbmc/games/controllers/windows/GUIConfigurationWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void CGUIConfigurationWizard::InitializeState(void)
m_throttleDirection = JOYSTICK::THROTTLE_DIRECTION::NONE;
m_history.clear();
m_lateAxisDetected = false;
m_deviceName.clear();
m_location.clear();
}

void CGUIConfigurationWizard::Run(const std::string& strControllerId,
Expand Down Expand Up @@ -205,7 +205,7 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap,
bool bHandled = false;

// Abort if another controller cancels the prompt
if (IsMapping() && !IsMapping(buttonMap->DeviceName()))
if (IsMapping() && !IsMapping(buttonMap->Location()))
{
//! @todo This only succeeds for game.controller.default; no actions are
// currently defined for other controllers
Expand Down Expand Up @@ -282,8 +282,9 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap,
}
else
{
CLog::Log(LOGDEBUG, "%s: mapping feature \"%s\" for device %s", m_strControllerId.c_str(),
feature.Name().c_str(), buttonMap->DeviceName().c_str());
CLog::Log(LOGDEBUG, "%s: mapping feature \"%s\" for device at location %s",
m_strControllerId.c_str(), feature.Name().c_str(),
buttonMap->Location().c_str());

switch (feature.Type())
{
Expand Down Expand Up @@ -338,9 +339,9 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap,

m_inputEvent.Set();

if (m_deviceName.empty())
if (m_location.empty())
{
m_deviceName = buttonMap->DeviceName();
m_location = buttonMap->Location();
m_bIsKeyboard = (primitive.Type() == PRIMITIVE_TYPE::KEY);
}
}
Expand Down Expand Up @@ -443,12 +444,12 @@ bool CGUIConfigurationWizard::OnAction(unsigned int actionId)

bool CGUIConfigurationWizard::IsMapping() const
{
return !m_deviceName.empty();
return !m_location.empty();
}

bool CGUIConfigurationWizard::IsMapping(const std::string& deviceName) const
bool CGUIConfigurationWizard::IsMapping(const std::string& location) const
{
return m_deviceName == deviceName;
return m_location == location;
}

void CGUIConfigurationWizard::InstallHooks(void)
Expand Down
4 changes: 2 additions & 2 deletions xbmc/games/controllers/windows/GUIConfigurationWizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CGUIConfigurationWizard : public IConfigurationWizard,
void InitializeState(void);

bool IsMapping() const;
bool IsMapping(const std::string& deviceName) const;
bool IsMapping(const std::string& location) const;

void InstallHooks(void);
void RemoveHooks(void);
Expand All @@ -99,7 +99,7 @@ class CGUIConfigurationWizard : public IConfigurationWizard,
JOYSTICK::THROTTLE_DIRECTION m_throttleDirection;
std::set<JOYSTICK::CDriverPrimitive> m_history; // History to avoid repeated features
bool m_lateAxisDetected; // Set to true if an axis is detected during button mapping
std::string m_deviceName; // Name of device that we're mapping
std::string m_location; // Peripheral location of device that we're mapping
bool m_bIsKeyboard = false; // True if we're mapping keyboard keys
CCriticalSection m_stateMutex;

Expand Down
6 changes: 3 additions & 3 deletions xbmc/input/joysticks/interfaces/IButtonMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class IButtonMap
virtual std::string ControllerID(void) const = 0;

/*!
* \brief The name of the peripheral associated with this button map
* \brief The Location of the peripheral associated with this button map
*
* \return The peripheral's name
* \return The peripheral's location
*/
virtual std::string DeviceName(void) const = 0;
virtual std::string Location(void) const = 0;

/*!
* \brief Load the button map into memory
Expand Down
7 changes: 4 additions & 3 deletions xbmc/peripherals/addons/AddonButtonMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ CAddonButtonMap::~CAddonButtonMap(void)
addon->UnregisterButtonMap(this);
}

std::string CAddonButtonMap::DeviceName(void) const
std::string CAddonButtonMap::Location(void) const
{
return m_device->DeviceName();
return m_device->Location();
}

bool CAddonButtonMap::Load(void)
Expand All @@ -65,7 +65,8 @@ bool CAddonButtonMap::Load(void)
if (bSuccess)
driverMap = CreateLookupTable(features);
else
CLog::Log(LOGDEBUG, "Failed to load button map for \"%s\"", m_device->DeviceName().c_str());
CLog::Log(LOGDEBUG, "Failed to load button map for device at location \"%s\"",
m_device->Location().c_str());

{
CSingleLock lock(m_mutex);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/peripherals/addons/AddonButtonMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CAddonButtonMap : public KODI::JOYSTICK::IButtonMap
// Implementation of IButtonMap
std::string ControllerID(void) const override { return m_strControllerId; }

std::string DeviceName(void) const override;
std::string Location(void) const override;

bool Load(void) override;

Expand Down

0 comments on commit 1fc4006

Please sign in to comment.