openMSX
Event.hh
Go to the documentation of this file.
1#ifndef EVENT_HH
2#define EVENT_HH
3
4#include "ObjectPool.hh"
5#include "Keys.hh"
6#include "static_vector.hh"
7#include "StringStorage.hh"
8#include "stl.hh"
9#include "TclObject.hh"
10#include "Thread.hh"
11#include "Timer.hh"
12#include <cassert>
13#include <cstdint>
14#include <limits>
15#include <mutex>
16#include <string>
17#include <utility>
18#include <variant>
19
20namespace openmsx {
21
22class CliConnection;
23enum class EventType : uint8_t;
24struct RcEvent;
25
26// --- The Event class, this acts as a handle for the concrete event-type classes ---
27
28class Event {
29public:
30 template<typename T, typename ...Args>
31 [[nodiscard]] static Event create(Args&& ...args);
32
33 Event() = default;
34 Event(const Event& other) : ptr(other.ptr) { incr(); }
35 Event(Event&& other) noexcept : ptr(other.ptr) { other.ptr = nullptr; }
36 Event& operator=(const Event& other);
37 Event& operator=(Event&& other) noexcept;
38 ~Event() { decr(); }
39
40 [[nodiscard]] explicit operator bool() const { return ptr; }
41 [[nodiscard]] const RcEvent* getPtr() const { return ptr; }
42
43private:
44 explicit Event(RcEvent* ptr);
45 void incr();
46 void decr();
47
48private:
49 RcEvent* ptr = nullptr;
50};
51
52
53// --- Event class, free functions ---
54
55[[nodiscard]] EventType getType(const Event& event);
56
58[[nodiscard]] std::string toString(const Event& event);
59
61[[nodiscard]] TclObject toTclList(const Event& event);
62
63[[nodiscard]] bool operator==(const Event& x, const Event& y);
64
68[[nodiscard]] bool isRepeatStopper(const Event& self, const Event& other);
69
73[[nodiscard]] bool matches(const Event& self, const Event& other);
74
75
76// --- The actual event classes (the Event class refers to one of these) ---
77
78class EventBase {};
79
80class TimedEvent : public EventBase
81{
82public:
83 [[nodiscard]] uint64_t getRealTime() const { return realtime; }
84
85private:
86 const uint64_t realtime = Timer::getTime(); // TODO use SDL2 event timestamp
87};
88
89
90class KeyEvent : public TimedEvent
91{
92public:
93 [[nodiscard]] Keys::KeyCode getKeyCode() const { return keyCode; }
94 [[nodiscard]] Keys::KeyCode getScanCode() const { return scanCode; }
95 [[nodiscard]] uint32_t getUnicode() const { return unicode; }
96
97protected:
98 KeyEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
99 : keyCode(keyCode_), scanCode(scanCode_), unicode(unicode_) {}
100
101private:
102 const Keys::KeyCode keyCode;
103 const Keys::KeyCode scanCode; // 2nd class support, see comments in toTclList()
104 const uint32_t unicode;
105};
106
107class KeyUpEvent final : public KeyEvent
108{
109public:
110 explicit KeyUpEvent(Keys::KeyCode keyCode_)
111 : KeyUpEvent(keyCode_, keyCode_) {}
112
113 explicit KeyUpEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
114 : KeyEvent(keyCode_, scanCode_, 0) {}
115};
116
117class KeyDownEvent final : public KeyEvent
118{
119public:
120 explicit KeyDownEvent(Keys::KeyCode keyCode_)
121 : KeyDownEvent(keyCode_, keyCode_, 0) {}
122
123 explicit KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
124 : KeyDownEvent(keyCode_, scanCode_, 0) {}
125
126 explicit KeyDownEvent(Keys::KeyCode keyCode_, uint32_t unicode_)
127 : KeyDownEvent(keyCode_, keyCode_, unicode_) {}
128
129 explicit KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
130 : KeyEvent(keyCode_, scanCode_, unicode_) {}
131};
132
133
135{
136public:
137 static constexpr unsigned LEFT = 1;
138 static constexpr unsigned MIDDLE = 2;
139 static constexpr unsigned RIGHT = 3;
140
141 [[nodiscard]] unsigned getButton() const { return button; }
142
143protected:
144 explicit MouseButtonEvent(unsigned button_)
145 : button(button_) {}
146
147private:
148 const unsigned button;
149};
150
152{
153public:
154 explicit MouseButtonUpEvent(unsigned button_)
155 : MouseButtonEvent(button_) {}
156};
157
159{
160public:
161 explicit MouseButtonDownEvent(unsigned button_)
162 : MouseButtonEvent(button_) {}
163};
164
165class MouseWheelEvent final : public TimedEvent
166{
167public:
168 MouseWheelEvent(int x_, int y_)
169 : x(x_), y(y_) {}
170
171 [[nodiscard]] int getX() const { return x; }
172 [[nodiscard]] int getY() const { return y; }
173
174private:
175 const int x;
176 const int y;
177};
178
179class MouseMotionEvent final : public TimedEvent
180{
181public:
182 MouseMotionEvent(int xrel_, int yrel_, int xabs_, int yabs_)
183 : xrel(xrel_), yrel(yrel_)
184 , xabs(xabs_), yabs(yabs_) {}
185
186 [[nodiscard]] int getX() const { return xrel; }
187 [[nodiscard]] int getY() const { return yrel; }
188 [[nodiscard]] int getAbsX() const { return xabs; }
189 [[nodiscard]] int getAbsY() const { return yabs; }
190
191private:
192 const int xrel;
193 const int yrel;
194 const int xabs;
195 const int yabs;
196};
197
198
200{
201public:
202 [[nodiscard]] int getJoystick() const { return joystick; }
203
204protected:
205 explicit JoystickEvent(int joystick_)
206 : joystick(joystick_) {}
207
208private:
209 const int joystick;
210};
211
213{
214public:
215 [[nodiscard]] unsigned getButton() const { return button; }
216
217protected:
218 JoystickButtonEvent(int joystick_, unsigned button_)
219 : JoystickEvent(joystick_), button(button_) {}
220
221private:
222 const unsigned button;
223};
224
226{
227public:
228 JoystickButtonUpEvent(int joystick_, unsigned button_)
229 : JoystickButtonEvent(joystick_, button_) {}
230};
231
233{
234public:
235 JoystickButtonDownEvent(int joystick_, unsigned button_)
236 : JoystickButtonEvent(joystick_, button_) {}
237};
238
240{
241public:
242 static constexpr unsigned X_AXIS = 0;
243 static constexpr unsigned Y_AXIS = 1;
244
245 JoystickAxisMotionEvent(int joystick_, unsigned axis_, int value_)
246 : JoystickEvent(joystick_), axis(axis_), value(value_) {}
247
248 [[nodiscard]] unsigned getAxis() const { return axis; }
249 [[nodiscard]] int getValue() const { return value; }
250
251private:
252 const unsigned axis;
253 const int value;
254};
255
256class JoystickHatEvent final : public JoystickEvent
257{
258public:
259 JoystickHatEvent(int joystick_, unsigned hat_, unsigned value_)
260 : JoystickEvent(joystick_), hat(hat_), value(value_) {}
261
262 [[nodiscard]] unsigned getHat() const { return hat; }
263 [[nodiscard]] unsigned getValue() const { return value; }
264
265private:
266 const unsigned hat;
267 const unsigned value;
268};
269
270
271class FocusEvent final : public EventBase
272{
273public:
274 explicit FocusEvent(bool gain_)
275 : gain(gain_) {}
276
277 [[nodiscard]] bool getGain() const { return gain; }
278
279private:
280 const bool gain;
281};
282
283
284class ResizeEvent final : public EventBase
285{
286public:
287 ResizeEvent(unsigned x_, unsigned y_)
288 : x(x_), y(y_) {}
289
290 [[nodiscard]] unsigned getX() const { return x; }
291 [[nodiscard]] unsigned getY() const { return y; }
292
293private:
294 const unsigned x;
295 const unsigned y;
296};
297
298
299class FileDropEvent final : public EventBase
300{
301public:
302 explicit FileDropEvent(std::string_view fileName_)
303 : fileName(allocate_c_string(fileName_)) {}
304
305 [[nodiscard]] zstring_view getFileName() const { return fileName.get(); }
306
307private:
308 const StringStorage fileName;
309};
310
311
312class QuitEvent final : public EventBase {};
313
314
320{
321public:
324
325 [[nodiscard]] unsigned getButton() const { return button; }
326
331 [[nodiscard]] const Event& getOrigEvent() const { return origEvent; }
332
333protected:
334 OsdControlEvent(unsigned button_, Event origEvent_)
335 : origEvent(std::move(origEvent_)), button(button_) {}
336
337private:
338 const Event origEvent;
339 const unsigned button;
340};
341
343{
344public:
345 OsdControlReleaseEvent(unsigned button_, Event origEvent_)
346 : OsdControlEvent(button_, std::move(origEvent_)) {}
347};
348
350{
351public:
352 OsdControlPressEvent(unsigned button_, Event origEvent_)
353 : OsdControlEvent(button_, std::move(origEvent_)) {}
354};
355
356
357class GroupEvent final : public EventBase
358{
359public:
360 GroupEvent(std::initializer_list<EventType> typesToMatch_, TclObject tclListComponents_)
361 : typesToMatch(typesToMatch_)
362 , tclListComponents(std::move(tclListComponents_)) {}
363
364 [[nodiscard]] const auto& getTypesToMatch() const { return typesToMatch; }
365 [[nodiscard]] const auto& getTclListComponents() const { return tclListComponents; }
366
367private:
368 const static_vector<EventType, 3> typesToMatch;
369 const TclObject tclListComponents;
370};
371
383class FinishFrameEvent final : public EventBase
384{
385public:
386 FinishFrameEvent(int thisSource_, int selectedSource_,
387 bool skipped_)
388 : thisSource(thisSource_), selectedSource(selectedSource_)
389 , skipped(skipped_)
390 {
391 }
392
393 [[nodiscard]] int getSource() const { return thisSource; }
394 [[nodiscard]] int getSelectedSource() const { return selectedSource; }
395 [[nodiscard]] bool isSkipped() const { return skipped; }
396 [[nodiscard]] bool needRender() const { return !skipped && (thisSource == selectedSource); }
397
398private:
399 const int thisSource;
400 const int selectedSource;
401 const bool skipped;
402};
403
405class CliCommandEvent final : public EventBase
406{
407public:
408 CliCommandEvent(std::string_view command_, const CliConnection* id_)
409 : command(allocate_c_string(command_)), id(id_) {}
410
411 [[nodiscard]] zstring_view getCommand() const { return command.get(); }
412 [[nodiscard]] const CliConnection* getId() const { return id; }
413
414private:
415 const StringStorage command;
416 const CliConnection* id;
417};
418
419
420// Events that don't need additional data
421class SimpleEvent : public EventBase {};
422
424class BootEvent final : public SimpleEvent {};
425
430class FrameDrawnEvent final : public SimpleEvent {};
431
432class BreakEvent final : public SimpleEvent {};
433class SwitchRendererEvent final : public SimpleEvent {};
434
436class TakeReverseSnapshotEvent final : public SimpleEvent {};
437
439class AfterTimedEvent final : public SimpleEvent {};
440
442class MachineLoadedEvent final : public SimpleEvent {};
443
446class MachineActivatedEvent final : public SimpleEvent {};
447class MachineDeactivatedEvent final : public SimpleEvent {};
448
451class ExposeEvent final : public SimpleEvent {};
452
453class MidiInReaderEvent final : public SimpleEvent {};
454class MidiInWindowsEvent final : public SimpleEvent {};
455class MidiInCoreMidiEvent final : public SimpleEvent {};
457class MidiInALSAEvent final : public SimpleEvent {};
458class Rs232TesterEvent final : public SimpleEvent {};
459
460
461// --- Put all (non-abstract) Event classes into a std::variant ---
462
463using EventVariant = std::variant<
479 QuitEvent,
483 BootEvent,
499>;
500
501template<typename T>
503
504
505// --- Define an enum for all concrete event types. ---
506// Use the numeric value from the corresponding index in the EventVariant.
507enum class EventType : uint8_t
508{
509 KEY_UP = event_index<KeyUpEvent>,
510 KEY_DOWN = event_index<KeyDownEvent>,
511 MOUSE_MOTION = event_index<MouseMotionEvent>,
512 MOUSE_BUTTON_UP = event_index<MouseButtonUpEvent>,
513 MOUSE_BUTTON_DOWN = event_index<MouseButtonDownEvent>,
514 MOUSE_WHEEL = event_index<MouseWheelEvent>,
515 JOY_AXIS_MOTION = event_index<JoystickAxisMotionEvent>,
516 JOY_HAT = event_index<JoystickHatEvent>,
517 JOY_BUTTON_UP = event_index<JoystickButtonUpEvent>,
518 JOY_BUTTON_DOWN = event_index<JoystickButtonDownEvent>,
519 OSD_CONTROL_RELEASE = event_index<OsdControlReleaseEvent>,
520 OSD_CONTROL_PRESS = event_index<OsdControlPressEvent>,
521 FOCUS = event_index<FocusEvent>,
522 RESIZE = event_index<ResizeEvent>,
523 FILE_DROP = event_index<FileDropEvent>,
524 QUIT = event_index<QuitEvent>,
525 GROUP = event_index<GroupEvent>,
526 BOOT = event_index<BootEvent>,
527 FINISH_FRAME = event_index<FinishFrameEvent>,
528 FRAME_DRAWN = event_index<FrameDrawnEvent>,
529 BREAK = event_index<BreakEvent>,
530 SWITCH_RENDERER = event_index<SwitchRendererEvent>,
531 TAKE_REVERSE_SNAPSHOT = event_index<TakeReverseSnapshotEvent>,
532 CLICOMMAND = event_index<CliCommandEvent>,
533 AFTER_TIMED = event_index<AfterTimedEvent>,
534 MACHINE_LOADED = event_index<MachineLoadedEvent>,
535 MACHINE_ACTIVATED = event_index<MachineActivatedEvent>,
536 MACHINE_DEACTIVATED = event_index<MachineDeactivatedEvent>,
537 EXPOSE = event_index<ExposeEvent>,
538 MIDI_IN_READER = event_index<MidiInReaderEvent>,
539 MIDI_IN_WINDOWS = event_index<MidiInWindowsEvent>,
540 MIDI_IN_COREMIDI = event_index<MidiInCoreMidiEvent>,
541 MIDI_IN_COREMIDI_VIRTUAL = event_index<MidiInCoreMidiVirtualEvent>,
542 MIDI_IN_ALSA = event_index<MidiInALSAEvent>,
543 RS232_TESTER = event_index<Rs232TesterEvent>,
544
545 NUM_EVENT_TYPES // must be last
546};
547
548
549// --- Add a reference-count ---
551 template<typename ...Args>
552 RcEvent(Args&& ...args) : EventVariant(std::forward<Args>(args)...) {}
553
554 uint8_t refCount = 1;
555};
556
557// --- Store event objects into a pool ---
559// A note on threading:
560// * All threads are allowed to create and destroy Event objects.
561// * Copying Event objects within one thread is allowed. Copying across threads
562// is not.
563// * Moving an object from one thread to another is allowed, but only when that
564// object was not copied yet (when the internal reference count is still 1).
565// The technical reason for this is that we protect the 'eventPool' with a
566// mutex, but the reference count on each Event object is not protected. This is
567// sufficient for the following scenario:
568// * Most event handling in openMSX is solely done on the main thread. Here
569// events can be freely copied. And shared Event objects (objects with
570// reference count > 1) only exist on the main thread.
571// * In some cases a helper thread want to signal something to the main thread.
572// It can then construct an Event object (construction is allowed on non-main
573// thread), and _move_ this freshly created (not yet copied) object to the
574// EventDistributor. The EventDistributor may or may not move this object into
575// some queue. When it was moved then later the main-thread will pick it up
576// (and processes and eventually destroy it). When it was not moved the (same)
577// non-main thread will destroy the object.
578// So creation and destruction can be done in any thread and must be protected
579// with a mutex. Copying should only be done in the main-thread and thus it's
580// not required to protect the reference count.
581inline std::recursive_mutex eventPoolMutex;
582
583
584// --- Event class implementation, member functions ---
585
586template<typename T, typename ...Args>
587Event Event::create(Args&& ...args)
588{
589 std::scoped_lock lock(eventPoolMutex);
590 return Event(eventPool.emplace(std::in_place_type_t<T>{}, std::forward<Args>(args)...).ptr);
591}
592
593inline Event::Event(RcEvent* ptr_)
594 : ptr(ptr_)
595{
596 assert(ptr->refCount == 1);
597}
598
599inline Event& Event::operator=(const Event& other)
600{
601 if (this != &other) {
602 decr();
603 ptr = other.ptr;
604 incr();
605 }
606 return *this;
607}
608
609inline Event& Event::operator=(Event&& other) noexcept
610{
611 if (this != &other) {
612 decr();
613 ptr = other.ptr;
614 other.ptr = nullptr;
615 }
616 return *this;
617}
618
619inline void Event::incr()
620{
621 if (!ptr) return;
622 assert(Thread::isMainThread());
623 assert(ptr->refCount < std::numeric_limits<decltype(ptr->refCount)>::max());
624 ++ptr->refCount;
625}
626
627inline void Event::decr()
628{
629 if (!ptr) return;
630 assert(Thread::isMainThread());
631 --ptr->refCount;
632 if (ptr->refCount == 0) {
633 std::scoped_lock lock(eventPoolMutex);
634 eventPool.remove(ptr);
635 ptr = nullptr;
636 }
637}
638
639
640// --- Event class implementation, free functions ---
641
642inline const EventVariant& getVariant(const Event& event)
643{
644 return *event.getPtr();
645}
646
647inline EventType getType(const Event& event)
648{
649 assert(event);
650 return EventType(getVariant(event).index());
651}
652
653// Similar to std::visit()
654template<typename Visitor>
655auto visit(Visitor&& visitor, const Event& event)
656{
657 assert(event);
658 return std::visit(std::forward<Visitor>(visitor), getVariant(event));
659}
660template<typename Visitor>
661auto visit(Visitor&& visitor, const Event& event1, const Event& event2)
662{
663 assert(event1 && event2);
664 return std::visit(std::forward<Visitor>(visitor), getVariant(event1), getVariant(event2));
665}
666
667// Similar to std::get() and std::get_if()
668template<typename T>
669struct GetIfEventHelper { // standard std::get_if() behavior
670 const T* operator()(const Event& event) {
671 return std::get_if<T>(&getVariant(event));
672 }
673};
674template<>
675struct GetIfEventHelper<TimedEvent> { // extension for base-classes
676 const TimedEvent* operator()(const Event& event) {
677 const auto& var = getVariant(event);
678 switch (EventType(var.index())) {
679 case EventType::KEY_UP: return &std::get<KeyUpEvent>(var);
680 case EventType::KEY_DOWN: return &std::get<KeyDownEvent>(var);
681 case EventType::MOUSE_BUTTON_UP: return &std::get<MouseButtonUpEvent>(var);
682 case EventType::MOUSE_BUTTON_DOWN: return &std::get<MouseButtonDownEvent>(var);
683 case EventType::MOUSE_WHEEL: return &std::get<MouseWheelEvent>(var);
684 case EventType::MOUSE_MOTION: return &std::get<MouseMotionEvent>(var);
685 case EventType::JOY_BUTTON_UP: return &std::get<JoystickButtonUpEvent>(var);
686 case EventType::JOY_BUTTON_DOWN: return &std::get<JoystickButtonDownEvent>(var);
687 case EventType::JOY_AXIS_MOTION: return &std::get<JoystickAxisMotionEvent>(var);
688 case EventType::JOY_HAT: return &std::get<JoystickHatEvent>(var);
689 case EventType::OSD_CONTROL_RELEASE: return &std::get<OsdControlReleaseEvent>(var);
690 case EventType::OSD_CONTROL_PRESS: return &std::get<OsdControlPressEvent>(var);
691 default: return nullptr;
692 }
693 }
694};
695template<>
697 const KeyEvent* operator()(const Event& event) {
698 const auto& var = getVariant(event);
699 switch (EventType(var.index())) {
700 case EventType::KEY_UP: return &std::get<KeyUpEvent>(var);
701 case EventType::KEY_DOWN: return &std::get<KeyDownEvent>(var);
702 default: return nullptr;
703 }
704 }
705};
706template<>
708 const JoystickEvent* operator()(const Event& event) {
709 const auto& var = getVariant(event);
710 switch (EventType(var.index())) {
711 case EventType::JOY_BUTTON_UP: return &std::get<JoystickButtonUpEvent>(var);
712 case EventType::JOY_BUTTON_DOWN: return &std::get<JoystickButtonDownEvent>(var);
713 case EventType::JOY_AXIS_MOTION: return &std::get<JoystickAxisMotionEvent>(var);
714 case EventType::JOY_HAT: return &std::get<JoystickHatEvent>(var);
715 default: return nullptr;
716 }
717 }
718};
719template<typename T>
720const T* get_if(const Event& event)
721{
722 assert(event);
723 GetIfEventHelper<T> helper;
724 return helper(event);
725}
726template<typename T>
727const T& get(const Event& event)
728{
729 assert(event);
730 const T* t = get_if<T>(event);
731 assert(t);
732 return *t;
733}
734
735} // namespace openmsx
736
737#endif
std::unique_ptr< char, FreeStringStorage > StringStorage
StringStorage allocate_c_string(std::string_view s)
Allocate memory for and copy a c-string (zero-terminated string).
TclObject t
Send when an after-EmuTime command should be executed.
Definition: Event.hh:439
Sent when the MSX resets or powers up.
Definition: Event.hh:424
Command received on CliComm connection.
Definition: Event.hh:406
const CliConnection * getId() const
Definition: Event.hh:412
zstring_view getCommand() const
Definition: Event.hh:411
CliCommandEvent(std::string_view command_, const CliConnection *id_)
Definition: Event.hh:408
Event()=default
Event(const Event &other)
Definition: Event.hh:34
Event(Event &&other) noexcept
Definition: Event.hh:35
static Event create(Args &&...args)
Definition: Event.hh:587
Event & operator=(const Event &other)
Definition: Event.hh:599
const RcEvent * getPtr() const
Definition: Event.hh:41
Send when (part of) the openMSX window gets exposed, and thus should be repainted.
Definition: Event.hh:451
FileDropEvent(std::string_view fileName_)
Definition: Event.hh:302
zstring_view getFileName() const
Definition: Event.hh:305
This event is send when a device (v99x8, v9990, video9000, laserdisc) reaches the end of a frame.
Definition: Event.hh:384
FinishFrameEvent(int thisSource_, int selectedSource_, bool skipped_)
Definition: Event.hh:386
int getSource() const
Definition: Event.hh:393
bool isSkipped() const
Definition: Event.hh:395
int getSelectedSource() const
Definition: Event.hh:394
bool needRender() const
Definition: Event.hh:396
bool getGain() const
Definition: Event.hh:277
FocusEvent(bool gain_)
Definition: Event.hh:274
Sent when a FINISH_FRAME caused a redraw of the screen.
Definition: Event.hh:430
GroupEvent(std::initializer_list< EventType > typesToMatch_, TclObject tclListComponents_)
Definition: Event.hh:360
const auto & getTypesToMatch() const
Definition: Event.hh:364
const auto & getTclListComponents() const
Definition: Event.hh:365
unsigned getAxis() const
Definition: Event.hh:248
static constexpr unsigned X_AXIS
Definition: Event.hh:242
JoystickAxisMotionEvent(int joystick_, unsigned axis_, int value_)
Definition: Event.hh:245
static constexpr unsigned Y_AXIS
Definition: Event.hh:243
JoystickButtonDownEvent(int joystick_, unsigned button_)
Definition: Event.hh:235
unsigned getButton() const
Definition: Event.hh:215
JoystickButtonEvent(int joystick_, unsigned button_)
Definition: Event.hh:218
JoystickButtonUpEvent(int joystick_, unsigned button_)
Definition: Event.hh:228
int getJoystick() const
Definition: Event.hh:202
JoystickEvent(int joystick_)
Definition: Event.hh:205
JoystickHatEvent(int joystick_, unsigned hat_, unsigned value_)
Definition: Event.hh:259
unsigned getValue() const
Definition: Event.hh:263
unsigned getHat() const
Definition: Event.hh:262
KeyDownEvent(Keys::KeyCode keyCode_)
Definition: Event.hh:120
KeyDownEvent(Keys::KeyCode keyCode_, uint32_t unicode_)
Definition: Event.hh:126
KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
Definition: Event.hh:129
KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
Definition: Event.hh:123
Keys::KeyCode getKeyCode() const
Definition: Event.hh:93
KeyEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
Definition: Event.hh:98
Keys::KeyCode getScanCode() const
Definition: Event.hh:94
uint32_t getUnicode() const
Definition: Event.hh:95
KeyUpEvent(Keys::KeyCode keyCode_)
Definition: Event.hh:110
KeyUpEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
Definition: Event.hh:113
Send when a machine is (de)activated.
Definition: Event.hh:446
Send when a (new) machine configuration is loaded.
Definition: Event.hh:442
MouseButtonDownEvent(unsigned button_)
Definition: Event.hh:161
static constexpr unsigned RIGHT
Definition: Event.hh:139
static constexpr unsigned MIDDLE
Definition: Event.hh:138
MouseButtonEvent(unsigned button_)
Definition: Event.hh:144
static constexpr unsigned LEFT
Definition: Event.hh:137
unsigned getButton() const
Definition: Event.hh:141
MouseButtonUpEvent(unsigned button_)
Definition: Event.hh:154
int getAbsY() const
Definition: Event.hh:189
MouseMotionEvent(int xrel_, int yrel_, int xabs_, int yabs_)
Definition: Event.hh:182
int getAbsX() const
Definition: Event.hh:188
int getX() const
Definition: Event.hh:171
int getY() const
Definition: Event.hh:172
MouseWheelEvent(int x_, int y_)
Definition: Event.hh:168
OSD events are triggered by other events.
Definition: Event.hh:320
const Event & getOrigEvent() const
Get the event that actually triggered the creation of this event.
Definition: Event.hh:331
OsdControlEvent(unsigned button_, Event origEvent_)
Definition: Event.hh:334
unsigned getButton() const
Definition: Event.hh:325
OsdControlPressEvent(unsigned button_, Event origEvent_)
Definition: Event.hh:352
OsdControlReleaseEvent(unsigned button_, Event origEvent_)
Definition: Event.hh:345
unsigned getY() const
Definition: Event.hh:291
ResizeEvent(unsigned x_, unsigned y_)
Definition: Event.hh:287
unsigned getX() const
Definition: Event.hh:290
Used to schedule 'taking reverse snapshots' between Z80 instructions.
Definition: Event.hh:436
uint64_t getRealTime() const
Definition: Event.hh:83
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:285
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
bool isMainThread()
Returns true when called from the main thread.
Definition: Thread.cc:15
uint64_t getTime()
Get current (real) time in us.
Definition: Timer.cc:7
This file implemented 3 utility functions:
Definition: Autofire.cc:9
auto visit(Visitor &&visitor, const Event &event1, const Event &event2)
Definition: Event.hh:661
constexpr uint8_t event_index
Definition: Event.hh:502
EventType
Definition: Event.hh:508
bool operator==(const Event &x, const Event &y)
Definition: Event.cc:11
bool isRepeatStopper(const Event &self, const Event &other)
Should 'bind -repeat' be stopped by 'other' event.
Definition: Event.cc:185
const T & get(const Event &event)
Definition: Event.hh:727
bool matches(const Event &self, const Event &other)
Does this event 'match' the given event.
Definition: Event.cc:216
const T * get_if(const Event &event)
Definition: Event.hh:720
auto visit(Visitor &&visitor, const Event &event)
Definition: Event.hh:655
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, FocusEvent, ResizeEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, ExposeEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent > EventVariant
Definition: Event.hh:499
const EventVariant & getVariant(const Event &event)
Definition: Event.hh:642
TclObject toTclList(const Event &event)
Similar to toString(), but retains the structure of the event.
Definition: Event.cc:85
EventType getType(const Event &event)
Definition: Event.hh:647
std::recursive_mutex eventPoolMutex
Definition: Event.hh:581
ObjectPool< RcEvent > eventPool
Definition: Event.hh:558
std::string toString(const Event &event)
Get a string representation of this event.
Definition: Event.cc:180
STL namespace.
const JoystickEvent * operator()(const Event &event)
Definition: Event.hh:708
const KeyEvent * operator()(const Event &event)
Definition: Event.hh:697
const TimedEvent * operator()(const Event &event)
Definition: Event.hh:676
const T * operator()(const Event &event)
Definition: Event.hh:670
RcEvent(Args &&...args)
Definition: Event.hh:552
uint8_t refCount
Definition: Event.hh:554