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