Skip to content

Commit

Permalink
[controller dialog] Improve keyboard handling during mapping
Browse files Browse the repository at this point in the history
Right now, if Kodi receives a keyboard press while mapping a button, it will
unconditionally abort the prompt.

Empirically, I've observed users becoming confused when they press a
direction but the focus doesn't move.

Also, I've seen users press A and become confused as to why a "select"
button caused a "cancel" action.
  • Loading branch information
garbear committed Feb 9, 2017
1 parent b1330e4 commit 86edbd9
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 6 deletions.
41 changes: 39 additions & 2 deletions xbmc/games/controllers/windows/GUIConfigurationWizard.cpp
Expand Up @@ -24,6 +24,7 @@
#include "games/controllers/ControllerFeature.h"
#include "input/joysticks/IButtonMap.h"
#include "input/joysticks/IButtonMapCallback.h"
#include "input/keyboard/KeymapActionMap.h"
#include "input/InputManager.h"
#include "peripherals/Peripherals.h"
#include "threads/SingleLock.h"
Expand All @@ -41,11 +42,16 @@ using namespace GAME;
CGUIConfigurationWizard::CGUIConfigurationWizard(bool bEmulation, unsigned int controllerNumber /* = 0 */) :
CThread("GUIConfigurationWizard"),
m_bEmulation(bEmulation),
m_controllerNumber(controllerNumber)
m_controllerNumber(controllerNumber),
m_actionMap(new KEYBOARD::CKeymapActionMap)
{
InitializeState();
}

CGUIConfigurationWizard::~CGUIConfigurationWizard(void)
{
}

void CGUIConfigurationWizard::InitializeState(void)
{
m_currentButton = nullptr;
Expand Down Expand Up @@ -266,7 +272,38 @@ void CGUIConfigurationWizard::OnMotionless(const JOYSTICK::IButtonMap* buttonMap

bool CGUIConfigurationWizard::OnKeyPress(const CKey& key)
{
return Abort(false);
using namespace KEYBOARD;

bool bHandled = false;

switch (m_actionMap->GetActionID(key))
{
case ACTION_MOVE_LEFT:
case ACTION_MOVE_RIGHT:
case ACTION_MOVE_UP:
case ACTION_MOVE_DOWN:
case ACTION_PAGE_UP:
case ACTION_PAGE_DOWN:
// Abort and allow motion
Abort(false);
bHandled = false;
break;

case ACTION_PARENT_DIR:
case ACTION_PREVIOUS_MENU:
case ACTION_STOP:
// Abort and prevent action
Abort(false);
bHandled = true;
break;

default:
// Absorb keypress
bHandled = true;
break;
}

return bHandled;
}

bool CGUIConfigurationWizard::OnButtonPress(const std::string& button)
Expand Down
14 changes: 13 additions & 1 deletion xbmc/games/controllers/windows/GUIConfigurationWizard.h
Expand Up @@ -29,10 +29,19 @@
#include "threads/Thread.h"
#include "utils/Observer.h"

#include <memory>
#include <set>
#include <string>
#include <vector>

namespace KODI
{
namespace KEYBOARD
{
class IActionMap;
}
}

namespace GAME
{
class CGUIConfigurationWizard : public IConfigurationWizard,
Expand All @@ -45,7 +54,7 @@ namespace GAME
public:
CGUIConfigurationWizard(bool bEmulation, unsigned int controllerNumber = 0);

virtual ~CGUIConfigurationWizard(void) { }
virtual ~CGUIConfigurationWizard(void);

// implementation of IConfigurationWizard
virtual void Run(const std::string& strControllerId, const std::vector<IFeatureButton*>& buttons) override;
Expand Down Expand Up @@ -107,5 +116,8 @@ namespace GAME
CEvent m_motionlessEvent;
CCriticalSection m_motionMutex;
std::set<const KODI::JOYSTICK::IButtonMap*> m_bInMotion;

// Keyboard handling
std::unique_ptr<KODI::KEYBOARD::IActionMap> m_actionMap;
};
}
11 changes: 8 additions & 3 deletions xbmc/input/keyboard/CMakeLists.txt
@@ -1,6 +1,11 @@
set(SOURCES KeyboardEasterEgg.cpp)
set(SOURCES KeyboardEasterEgg.cpp
KeymapActionMap.cpp
)

set(HEADERS IKeyboardHandler.h
KeyboardEasterEgg.h)
set(HEADERS IActionMap.h
IKeyboardHandler.h
KeyboardEasterEgg.h
KeymapActionMap.h
)

core_add_library(input_keyboard)
47 changes: 47 additions & 0 deletions xbmc/input/keyboard/IActionMap.h
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once

class CKey;

namespace KODI
{
namespace KEYBOARD
{
/*!
* \brief Interface for translating keys to action IDs
*/
class IActionMap
{
public:
virtual ~IActionMap() = default;

/*!
* \brief Get the action ID mapped to the specified key
*
* \param key The key to look up
*
* \return The action ID from Action.h, or ACTION_NONE if no action is
* mapped to the specified key
*/
virtual unsigned int GetActionID(const CKey& key) = 0;
};
}
}
34 changes: 34 additions & 0 deletions xbmc/input/keyboard/KeymapActionMap.cpp
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "KeymapActionMap.h"
#include "guilib/GUIWindowManager.h"
#include "input/Action.h"
#include "input/ButtonTranslator.h"
#include "input/Key.h"

using namespace KODI;
using namespace KEYBOARD;

unsigned int CKeymapActionMap::GetActionID(const CKey& key)
{
CAction action = CButtonTranslator::GetInstance().GetAction(g_windowManager.GetActiveWindowID(), key);
return action.GetID();
}
39 changes: 39 additions & 0 deletions xbmc/input/keyboard/KeymapActionMap.h
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "input/keyboard/IActionMap.h"

namespace KODI
{
namespace KEYBOARD
{
class CKeymapActionMap : public IActionMap
{
public:
CKeymapActionMap(void) = default;

virtual ~CKeymapActionMap(void) = default;

// implementation of IActionMap
virtual unsigned int GetActionID(const CKey& key) override;
};
}
}

0 comments on commit 86edbd9

Please sign in to comment.