MythTV master
jsmenu.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------
2** jsmenu.h
3** GPL license; Original copyright 2004 Jeremy White <jwhite@whitesen.org>
4**--------------------------------------------------------------------------*/
5
6#ifndef JSMENU_H_
7#define JSMENU_H_
8
9// C++ headers
10#include <utility>
11#include <vector>
12
13// QT headers
14#include <QString>
15
16// MythTV headers
17#include "libmythbase/mthread.h"
18
20{
21 int button;
22 QString keystring;
23 int chord;
24};
25
27{
28 int axis;
29 int from;
30 int to;
31 QString keystring;
32};
33
52{
53 public:
54 void AddButton(int in_button, QString in_keystr, int in_chord = -1)
55 {
56 buttonMapType new_button = { in_button, std::move(in_keystr), in_chord };
57 m_buttonMap.push_back(new_button);
58 }
59
60 void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
61 {
62 axisMapType new_axis = { in_axis, in_from, in_to, std::move(in_keystr)};
63 m_axisMap.push_back(new_axis);
64 }
65
66 void Clear(){
67 m_axisMap.clear();
68 m_buttonMap.clear();
69 }
70
71 using button_map_t = std::vector<buttonMapType>;
72 using axis_map_t = std::vector<axisMapType>;
73 const button_map_t &buttonMap() const { return m_buttonMap; }
74 const axis_map_t &axisMap() const { return m_axisMap; }
75
78};
79
88{
89 public:
90 explicit JoystickMenuThread(QObject *main_window)
91 : MThread("JoystickMenu"), m_mainWindow(main_window) {}
92 ~JoystickMenuThread() override;
93 bool Init(QString &config_file);
94
95 void ButtonUp(int button);
96 void AxisChange(int axis, int value);
97 void EmitKey(const QString& code);
98 bool ReadConfig(const QString& config_file);
99 void Stop(void) { m_bStop = true; }
100
101 private:
102 void run() override; // MThread
103
104 bool m_configRead {false};
105 bool m_readError {false};
106 // put here to avoid changing other classes
108
109 QObject *m_mainWindow {nullptr};
111 int m_fd {-1};
113
118 unsigned char m_buttonCount {0};
119
124 unsigned char m_axesCount {0};
125
126 int *m_buttons {nullptr};
127 int *m_axes {nullptr};
128
129 volatile bool m_bStop {false};
130};
131
132#endif
Holds the buttonMapType and axisMapType structs which map actions to events.
Definition: jsmenu.h:52
button_map_t m_buttonMap
Definition: jsmenu.h:76
const axis_map_t & axisMap() const
Definition: jsmenu.h:74
std::vector< axisMapType > axis_map_t
Definition: jsmenu.h:72
void AddButton(int in_button, QString in_keystr, int in_chord=-1)
Definition: jsmenu.h:54
const button_map_t & buttonMap() const
Definition: jsmenu.h:73
axis_map_t m_axisMap
Definition: jsmenu.h:77
std::vector< buttonMapType > button_map_t
Definition: jsmenu.h:71
void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
Definition: jsmenu.h:60
void Clear()
Definition: jsmenu.h:66
Main object for injecting key strokes based on joystick movements.
Definition: jsmenu.h:88
void EmitKey(const QString &code)
Send a keyevent to the main UI loop with the appropriate keycode.
Definition: jsmenu.cpp:381
~JoystickMenuThread() override
Definition: jsmenu.cpp:59
bool Init(QString &config_file)
Initialise the class variables with values from the config file.
Definition: jsmenu.cpp:77
void run() override
This function is the heart of a thread which looks for Joystick input and translates it into key pres...
Definition: jsmenu.cpp:222
JoystickMenuThread(QObject *main_window)
Definition: jsmenu.h:90
volatile bool m_bStop
Definition: jsmenu.h:129
void AxisChange(int axis, int value)
Handle a registered change in a joystick axis.
Definition: jsmenu.cpp:451
void Stop(void)
Definition: jsmenu.h:99
bool ReadConfig(const QString &config_file)
Read from action to key mappings from flat file config file.
Definition: jsmenu.cpp:156
QObject * m_mainWindow
Definition: jsmenu.h:109
JoystickMap m_map
Definition: jsmenu.h:112
void ButtonUp(int button)
Handle a button up event.
Definition: jsmenu.cpp:419
QString m_devicename
Definition: jsmenu.h:110
QString m_configFile
Definition: jsmenu.h:107
unsigned char m_axesCount
Track the status of the joystick axes as we do depend slightly on state.
Definition: jsmenu.h:124
unsigned char m_buttonCount
Track the status of the joystick buttons as we do depend slightly on state.
Definition: jsmenu.h:118
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
QString keystring
Definition: jsmenu.h:31
int to
Definition: jsmenu.h:30
int from
Definition: jsmenu.h:29
int axis
Definition: jsmenu.h:28
int button
Definition: jsmenu.h:21
QString keystring
Definition: jsmenu.h:22
int chord
Definition: jsmenu.h:23