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 = { .button=in_button,
57 .keystring=std::move(in_keystr),
58 .chord=in_chord };
59 m_buttonMap.push_back(new_button);
60 }
61
62 void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
63 {
64 axisMapType new_axis = { .axis=in_axis, .from=in_from, .to=in_to,
65 .keystring=std::move(in_keystr)};
66 m_axisMap.push_back(new_axis);
67 }
68
69 void Clear(){
70 m_axisMap.clear();
71 m_buttonMap.clear();
72 }
73
74 using button_map_t = std::vector<buttonMapType>;
75 using axis_map_t = std::vector<axisMapType>;
76 const button_map_t &buttonMap() const { return m_buttonMap; }
77 const axis_map_t &axisMap() const { return m_axisMap; }
78
81};
82
91{
92 public:
93 explicit JoystickMenuThread(QObject *main_window)
94 : MThread("JoystickMenu"), m_mainWindow(main_window) {}
95 ~JoystickMenuThread() override;
96 bool Init(QString &config_file);
97
98 void ButtonUp(int button);
99 void AxisChange(int axis, int value);
100 void EmitKey(const QString& code);
101 bool ReadConfig(const QString& config_file);
102 void Stop(void) { m_bStop = true; }
103
104 private:
105 void run() override; // MThread
106
107 bool m_configRead {false};
108 bool m_readError {false};
109 // put here to avoid changing other classes
111
112 QObject *m_mainWindow {nullptr};
114 int m_fd {-1};
116
121 unsigned char m_buttonCount {0};
122
127 unsigned char m_axesCount {0};
128
129 int *m_buttons {nullptr};
130 int *m_axes {nullptr};
131
132 volatile bool m_bStop {false};
133};
134
135#endif
Holds the buttonMapType and axisMapType structs which map actions to events.
Definition: jsmenu.h:52
button_map_t m_buttonMap
Definition: jsmenu.h:79
const axis_map_t & axisMap() const
Definition: jsmenu.h:77
std::vector< axisMapType > axis_map_t
Definition: jsmenu.h:75
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:76
axis_map_t m_axisMap
Definition: jsmenu.h:80
std::vector< buttonMapType > button_map_t
Definition: jsmenu.h:74
void AddAxis(int in_axis, int in_from, int in_to, QString in_keystr)
Definition: jsmenu.h:62
void Clear()
Definition: jsmenu.h:69
Main object for injecting key strokes based on joystick movements.
Definition: jsmenu.h:91
void EmitKey(const QString &code)
Send a keyevent to the main UI loop with the appropriate keycode.
Definition: jsmenu.cpp:383
~JoystickMenuThread() override
Definition: jsmenu.cpp:61
bool Init(QString &config_file)
Initialise the class variables with values from the config file.
Definition: jsmenu.cpp:79
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:224
JoystickMenuThread(QObject *main_window)
Definition: jsmenu.h:93
volatile bool m_bStop
Definition: jsmenu.h:132
void AxisChange(int axis, int value)
Handle a registered change in a joystick axis.
Definition: jsmenu.cpp:453
void Stop(void)
Definition: jsmenu.h:102
bool ReadConfig(const QString &config_file)
Read from action to key mappings from flat file config file.
Definition: jsmenu.cpp:158
QObject * m_mainWindow
Definition: jsmenu.h:112
JoystickMap m_map
Definition: jsmenu.h:115
void ButtonUp(int button)
Handle a button up event.
Definition: jsmenu.cpp:421
QString m_devicename
Definition: jsmenu.h:113
QString m_configFile
Definition: jsmenu.h:110
unsigned char m_axesCount
Track the status of the joystick axes as we do depend slightly on state.
Definition: jsmenu.h:127
unsigned char m_buttonCount
Track the status of the joystick buttons as we do depend slightly on state.
Definition: jsmenu.h:121
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