summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt3
-rw-r--r--src/common/emu_window.cpp17
-rw-r--r--src/common/emu_window.h8
-rw-r--r--src/common/key_map.cpp25
-rw-r--r--src/common/key_map.h45
5 files changed, 98 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3a82f5b80..9d5a90762 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -4,10 +4,12 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
4set(SRCS 4set(SRCS
5 break_points.cpp 5 break_points.cpp
6 console_listener.cpp 6 console_listener.cpp
7 emu_window.cpp
7 extended_trace.cpp 8 extended_trace.cpp
8 file_search.cpp 9 file_search.cpp
9 file_util.cpp 10 file_util.cpp
10 hash.cpp 11 hash.cpp
12 key_map.cpp
11 log_manager.cpp 13 log_manager.cpp
12 math_util.cpp 14 math_util.cpp
13 mem_arena.cpp 15 mem_arena.cpp
@@ -39,6 +41,7 @@ set(HEADERS
39 file_search.h 41 file_search.h
40 file_util.h 42 file_util.h
41 hash.h 43 hash.h
44 key_map.h
42 linear_disk_cache.h 45 linear_disk_cache.h
43 log.h 46 log.h
44 log_manager.h 47 log_manager.h
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
new file mode 100644
index 000000000..7a2c50ac8
--- /dev/null
+++ b/src/common/emu_window.cpp
@@ -0,0 +1,17 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "emu_window.h"
6
7void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
8 HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
9
10 HID_User::PadButtonPress(mapped_key);
11}
12
13void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
14 HID_User::PadState mapped_key = KeyMap::GetPadKey(key);
15
16 HID_User::PadButtonRelease(mapped_key);
17}
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 5e2c33d7a..23f178fdf 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -7,6 +7,8 @@
7#include "common/common.h" 7#include "common/common.h"
8#include "common/scm_rev.h" 8#include "common/scm_rev.h"
9 9
10#include "common/key_map.h"
11
10// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, 12// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL,
11// QGLWidget, GLFW, etc...) 13// QGLWidget, GLFW, etc...)
12class EmuWindow 14class EmuWindow
@@ -32,6 +34,12 @@ public:
32 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread 34 /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
33 virtual void DoneCurrent() = 0; 35 virtual void DoneCurrent() = 0;
34 36
37 /// Signals a key press action to the HID module
38 static void KeyPressed(KeyMap::HostDeviceKey key);
39
40 /// Signals a key release action to the HID module
41 static void KeyReleased(KeyMap::HostDeviceKey key);
42
35 Config GetConfig() const { 43 Config GetConfig() const {
36 return m_config; 44 return m_config;
37 } 45 }
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
new file mode 100644
index 000000000..309caab98
--- /dev/null
+++ b/src/common/key_map.cpp
@@ -0,0 +1,25 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "key_map.h"
6#include <map>
7
8namespace KeyMap {
9
10static std::map<HostDeviceKey, HID_User::PadState> key_map;
11static int next_device_id = 0;
12
13int NewDeviceId() {
14 return next_device_id++;
15}
16
17void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState) {
18 key_map[key].hex = padState.hex;
19}
20
21HID_User::PadState GetPadKey(HostDeviceKey key) {
22 return key_map[key];
23}
24
25}
diff --git a/src/common/key_map.h b/src/common/key_map.h
new file mode 100644
index 000000000..b5acfbab0
--- /dev/null
+++ b/src/common/key_map.h
@@ -0,0 +1,45 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/hle/service/hid.h"
8
9namespace KeyMap {
10
11/**
12 * Represents a key for a specific host device.
13 */
14struct HostDeviceKey {
15 int key_code;
16 int device_id; ///< Uniquely identifies a host device
17
18 bool operator < (const HostDeviceKey &other) const {
19 if (device_id == other.device_id) {
20 return key_code < other.key_code;
21 }
22 return device_id < other.device_id;
23 }
24
25 bool operator == (const HostDeviceKey &other) const {
26 return device_id == other.device_id && key_code == other.key_code;
27 }
28};
29
30/**
31 * Generates a new device id, which uniquely identifies a host device within KeyMap.
32 */
33int NewDeviceId();
34
35/**
36 * Maps a device-specific key to a PadState.
37 */
38void SetKeyMapping(HostDeviceKey key, HID_User::PadState padState);
39
40/**
41 * Gets the PadState that's mapped to the provided device-specific key.
42 */
43HID_User::PadState GetPadKey(HostDeviceKey key);
44
45}