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 
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 
78 class EventBase {};
79 
80 class TimedEvent : public EventBase
81 {
82 public:
83  [[nodiscard]] uint64_t getRealTime() const { return realtime; }
84 
85 private:
86  const uint64_t realtime = Timer::getTime(); // TODO use SDL2 event timestamp
87 };
88 
89 
90 class KeyEvent : public TimedEvent
91 {
92 public:
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 
97 protected:
98  KeyEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
99  : keyCode(keyCode_), scanCode(scanCode_), unicode(unicode_) {}
100 
101 private:
102  const Keys::KeyCode keyCode;
103  const Keys::KeyCode scanCode; // 2nd class support, see comments in toTclList()
104  const uint32_t unicode;
105 };
106 
107 class KeyUpEvent final : public KeyEvent
108 {
109 public:
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 
117 class KeyDownEvent final : public KeyEvent
118 {
119 public:
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 {
136 public:
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 
143 protected:
144  explicit MouseButtonEvent(unsigned button_)
145  : button(button_) {}
146 
147 private:
148  const unsigned button;
149 };
150 
152 {
153 public:
154  explicit MouseButtonUpEvent(unsigned button_)
155  : MouseButtonEvent(button_) {}
156 };
157 
159 {
160 public:
161  explicit MouseButtonDownEvent(unsigned button_)
162  : MouseButtonEvent(button_) {}
163 };
164 
165 class MouseWheelEvent final : public TimedEvent
166 {
167 public:
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 
174 private:
175  const int x;
176  const int y;
177 };
178 
179 class MouseMotionEvent final : public TimedEvent
180 {
181 public:
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 
191 private:
192  const int xrel;
193  const int yrel;
194  const int xabs;
195  const int yabs;
196 };
197 
198 
199 class JoystickEvent : public TimedEvent
200 {
201 public:
202  [[nodiscard]] unsigned getJoystick() const { return joystick; }
203 
204 protected:
205  explicit JoystickEvent(unsigned joystick_)
206  : joystick(joystick_) {}
207 
208 private:
209  const unsigned joystick;
210 };
211 
213 {
214 public:
215  [[nodiscard]] unsigned getButton() const { return button; }
216 
217 protected:
218  JoystickButtonEvent(unsigned joystick_, unsigned button_)
219  : JoystickEvent(joystick_), button(button_) {}
220 
221 private:
222  const unsigned button;
223 };
224 
226 {
227 public:
228  JoystickButtonUpEvent(unsigned joystick_, unsigned button_)
229  : JoystickButtonEvent(joystick_, button_) {}
230 };
231 
233 {
234 public:
235  JoystickButtonDownEvent(unsigned joystick_, unsigned button_)
236  : JoystickButtonEvent(joystick_, button_) {}
237 };
238 
240 {
241 public:
242  static constexpr unsigned X_AXIS = 0;
243  static constexpr unsigned Y_AXIS = 1;
244 
245  JoystickAxisMotionEvent(unsigned 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 
251 private:
252  const unsigned axis;
253  const int value;
254 };
255 
256 class JoystickHatEvent final : public JoystickEvent
257 {
258 public:
259  JoystickHatEvent(unsigned 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 
265 private:
266  const unsigned hat;
267  const unsigned value;
268 };
269 
270 
271 class FocusEvent final : public EventBase
272 {
273 public:
274  explicit FocusEvent(bool gain_)
275  : gain(gain_) {}
276 
277  [[nodiscard]] bool getGain() const { return gain; }
278 
279 private:
280  const bool gain;
281 };
282 
283 
284 class ResizeEvent final : public EventBase
285 {
286 public:
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 
293 private:
294  const unsigned x;
295  const unsigned y;
296 };
297 
298 
299 class FileDropEvent final : public EventBase
300 {
301 public:
302  explicit FileDropEvent(std::string_view fileName_)
303  : fileName(allocate_c_string(fileName_)) {}
304 
305  [[nodiscard]] zstring_view getFileName() const { return fileName.get(); }
306 
307 private:
308  const StringStorage fileName;
309 };
310 
311 
312 class QuitEvent final : public EventBase {};
313 
314 
320 {
321 public:
324 
325  [[nodiscard]] unsigned getButton() const { return button; }
326 
331  [[nodiscard]] const Event& getOrigEvent() const { return origEvent; }
332 
333 protected:
334  OsdControlEvent(unsigned button_, Event origEvent_)
335  : origEvent(std::move(origEvent_)), button(button_) {}
336 
337 private:
338  const Event origEvent;
339  const unsigned button;
340 };
341 
343 {
344 public:
345  OsdControlReleaseEvent(unsigned button_, Event origEvent_)
346  : OsdControlEvent(button_, std::move(origEvent_)) {}
347 };
348 
350 {
351 public:
352  OsdControlPressEvent(unsigned button_, Event origEvent_)
353  : OsdControlEvent(button_, std::move(origEvent_)) {}
354 };
355 
356 
357 class GroupEvent final : public EventBase
358 {
359 public:
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 
367 private:
368  const static_vector<EventType, 3> typesToMatch;
369  const TclObject tclListComponents;
370 };
371 
383 class FinishFrameEvent final : public EventBase
384 {
385 public:
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 
398 private:
399  const int thisSource;
400  const int selectedSource;
401  const bool skipped;
402 };
403 
405 class CliCommandEvent final : public EventBase
406 {
407 public:
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 
414 private:
415  const StringStorage command;
416  const CliConnection* id;
417 };
418 
419 
420 // Events that don't need additional data
421 class SimpleEvent : public EventBase {};
422 
424 class BootEvent final : public SimpleEvent {};
425 
430 class FrameDrawnEvent final : public SimpleEvent {};
431 
432 class BreakEvent final : public SimpleEvent {};
433 class SwitchRendererEvent final : public SimpleEvent {};
434 
436 class TakeReverseSnapshotEvent final : public SimpleEvent {};
437 
439 class AfterTimedEvent final : public SimpleEvent {};
440 
442 class MachineLoadedEvent final : public SimpleEvent {};
443 
446 class MachineActivatedEvent final : public SimpleEvent {};
447 class MachineDeactivatedEvent final : public SimpleEvent {};
448 
451 class ExposeEvent final : public SimpleEvent {};
452 
453 class MidiInReaderEvent final : public SimpleEvent {};
454 class MidiInWindowsEvent final : public SimpleEvent {};
455 class MidiInCoreMidiEvent final : public SimpleEvent {};
456 class MidiInCoreMidiVirtualEvent final : public SimpleEvent {};
457 class Rs232TesterEvent final : public SimpleEvent {};
458 
459 
460 // --- Put all (non-abstract) Event classes into a std::variant ---
461 
462 using EventVariant = std::variant<
463  KeyUpEvent,
464  KeyDownEvent,
475  FocusEvent,
476  ResizeEvent,
478  QuitEvent,
481  GroupEvent,
482  BootEvent,
484  BreakEvent,
491  ExposeEvent,
497 >;
498 
499 template<typename T>
501 
502 
503 // --- Define an enum for all concrete event types. ---
504 // Use the numeric value from the corresponding index in the EventVariant.
505 enum class EventType : uint8_t
506 {
507  KEY_UP = event_index<KeyUpEvent>,
508  KEY_DOWN = event_index<KeyDownEvent>,
509  MOUSE_MOTION = event_index<MouseMotionEvent>,
510  MOUSE_BUTTON_UP = event_index<MouseButtonUpEvent>,
511  MOUSE_BUTTON_DOWN = event_index<MouseButtonDownEvent>,
512  MOUSE_WHEEL = event_index<MouseWheelEvent>,
513  JOY_AXIS_MOTION = event_index<JoystickAxisMotionEvent>,
514  JOY_HAT = event_index<JoystickHatEvent>,
515  JOY_BUTTON_UP = event_index<JoystickButtonUpEvent>,
516  JOY_BUTTON_DOWN = event_index<JoystickButtonDownEvent>,
517  OSD_CONTROL_RELEASE = event_index<OsdControlReleaseEvent>,
518  OSD_CONTROL_PRESS = event_index<OsdControlPressEvent>,
519  FOCUS = event_index<FocusEvent>,
520  RESIZE = event_index<ResizeEvent>,
521  FILEDROP = event_index<FileDropEvent>,
522  QUIT = event_index<QuitEvent>,
523  GROUP = event_index<GroupEvent>,
524  BOOT = event_index<BootEvent>,
525  FINISH_FRAME = event_index<FinishFrameEvent>,
526  FRAME_DRAWN = event_index<FrameDrawnEvent>,
527  BREAK = event_index<BreakEvent>,
528  SWITCH_RENDERER = event_index<SwitchRendererEvent>,
529  TAKE_REVERSE_SNAPSHOT = event_index<TakeReverseSnapshotEvent>,
530  CLICOMMAND = event_index<CliCommandEvent>,
531  AFTER_TIMED = event_index<AfterTimedEvent>,
532  MACHINE_LOADED = event_index<MachineLoadedEvent>,
533  MACHINE_ACTIVATED = event_index<MachineActivatedEvent>,
534  MACHINE_DEACTIVATED = event_index<MachineDeactivatedEvent>,
535  EXPOSE = event_index<ExposeEvent>,
536  MIDI_IN_READER = event_index<MidiInReaderEvent>,
537  MIDI_IN_WINDOWS = event_index<MidiInWindowsEvent>,
538  MIDI_IN_COREMIDI = event_index<MidiInCoreMidiEvent>,
539  MIDI_IN_COREMIDI_VIRTUAL = event_index<MidiInCoreMidiVirtualEvent>,
540  RS232_TESTER = event_index<Rs232TesterEvent>,
541 
542  NUM_EVENT_TYPES // must be last
543 };
544 
545 
546 // --- Add a reference-count ---
548  template<typename ...Args>
549  RcEvent(Args&& ...args) : EventVariant(std::forward<Args>(args)...) {}
550 
551  uint8_t refCount = 1;
552 };
553 
554 // --- Store event objects into a pool ---
556 // A note on threading:
557 // * All threads are allowed to create and destroy Event objects.
558 // * Copying Event objects within one thread is allowed. Copying across threads
559 // is not.
560 // * Moving an object from one thread to another is allowed, but only when that
561 // object was not copied yet (when the internal reference count is still 1).
562 // The technical reason for this is that we protect the 'eventPool' with a
563 // mutex, but the reference count on each Event object is not protected. This is
564 // sufficient for the following scenario:
565 // * Most event handling in openMSX is solely done on the main thread. Here
566 // events can be freely copied. And shared Event objects (objects with
567 // reference count > 1) only exist on the main thread.
568 // * In some cases a helper thread want to signal something to the main thread.
569 // It can then construct an Event object (construction is allowed on non-main
570 // thread), and _move_ this freshly created (not yet copied) object to the
571 // EventDistributor. The EventDistribtor may or may not move this object into
572 // some queue. When it was moved then later the main-thread will pick it up
573 // (and processes and eventually destroy it). When it was not moved the (same)
574 // non-main thread will destroy the object.
575 // So creation and destruction can be done in any thread and must be protected
576 // with a mutex. Copying should only be done in the main-thread and thus it's
577 // not required to protect the reference count.
578 inline std::recursive_mutex eventPoolMutex;
579 
580 
581 // --- Event class implementation, member functions ---
582 
583 template<typename T, typename ...Args>
584 Event Event::create(Args&& ...args)
585 {
586  std::scoped_lock lock(eventPoolMutex);
587  return Event(eventPool.emplace(std::in_place_type_t<T>{}, std::forward<Args>(args)...).ptr);
588 }
589 
590 inline Event::Event(RcEvent* ptr_)
591  : ptr(ptr_)
592 {
593  assert(ptr->refCount == 1);
594 }
595 
596 inline Event& Event::operator=(const Event& other)
597 {
598  if (this != &other) {
599  decr();
600  ptr = other.ptr;
601  incr();
602  }
603  return *this;
604 }
605 
606 inline Event& Event::operator=(Event&& other) noexcept
607 {
608  if (this != &other) {
609  decr();
610  ptr = other.ptr;
611  other.ptr = nullptr;
612  }
613  return *this;
614 }
615 
616 inline void Event::incr()
617 {
618  if (!ptr) return;
619  assert(Thread::isMainThread());
620  assert(ptr->refCount < std::numeric_limits<decltype(ptr->refCount)>::max());
621  ++ptr->refCount;
622 }
623 
624 inline void Event::decr()
625 {
626  if (!ptr) return;
627  assert(Thread::isMainThread());
628  --ptr->refCount;
629  if (ptr->refCount == 0) {
630  std::scoped_lock lock(eventPoolMutex);
631  eventPool.remove(ptr);
632  ptr = nullptr;
633  }
634 }
635 
636 
637 // --- Event class implementation, free functions ---
638 
639 inline const EventVariant& getVariant(const Event& event)
640 {
641  return *event.getPtr();
642 }
643 
644 inline EventType getType(const Event& event)
645 {
646  assert(event);
647  return EventType(getVariant(event).index());
648 }
649 
650 // Similar to std::visit()
651 template<typename Visitor>
652 auto visit(Visitor&& visitor, const Event& event)
653 {
654  assert(event);
655  return std::visit(std::forward<Visitor>(visitor), getVariant(event));
656 }
657 template<typename Visitor>
658 auto visit(Visitor&& visitor, const Event& event1, const Event& event2)
659 {
660  assert(event1 && event2);
661  return std::visit(std::forward<Visitor>(visitor), getVariant(event1), getVariant(event2));
662 }
663 
664 // Similar to std::get() and std::get_if()
665 template<typename T>
666 struct GetIfEventHelper { // standard std::get_if() behavior
667  const T* operator()(const Event& event) {
668  return std::get_if<T>(&getVariant(event));
669  }
670 };
671 template<>
672 struct GetIfEventHelper<TimedEvent> { // extension for base-classes
673  const TimedEvent* operator()(const Event& event) {
674  const auto& var = getVariant(event);
675  switch (EventType(var.index())) {
676  case EventType::KEY_UP: return &std::get<KeyUpEvent>(var);
677  case EventType::KEY_DOWN: return &std::get<KeyDownEvent>(var);
678  case EventType::MOUSE_BUTTON_UP: return &std::get<MouseButtonUpEvent>(var);
679  case EventType::MOUSE_BUTTON_DOWN: return &std::get<MouseButtonDownEvent>(var);
680  case EventType::MOUSE_WHEEL: return &std::get<MouseWheelEvent>(var);
681  case EventType::MOUSE_MOTION: return &std::get<MouseMotionEvent>(var);
682  case EventType::JOY_BUTTON_UP: return &std::get<JoystickButtonUpEvent>(var);
683  case EventType::JOY_BUTTON_DOWN: return &std::get<JoystickButtonDownEvent>(var);
684  case EventType::JOY_AXIS_MOTION: return &std::get<JoystickAxisMotionEvent>(var);
685  case EventType::JOY_HAT: return &std::get<JoystickHatEvent>(var);
686  case EventType::OSD_CONTROL_RELEASE: return &std::get<OsdControlReleaseEvent>(var);
687  case EventType::OSD_CONTROL_PRESS: return &std::get<OsdControlPressEvent>(var);
688  default: return nullptr;
689  }
690  }
691 };
692 template<>
694  const KeyEvent* operator()(const Event& event) {
695  const auto& var = getVariant(event);
696  switch (EventType(var.index())) {
697  case EventType::KEY_UP: return &std::get<KeyUpEvent>(var);
698  case EventType::KEY_DOWN: return &std::get<KeyDownEvent>(var);
699  default: return nullptr;
700  }
701  }
702 };
703 template<>
705  const JoystickEvent* operator()(const Event& event) {
706  const auto& var = getVariant(event);
707  switch (EventType(var.index())) {
708  case EventType::JOY_BUTTON_UP: return &std::get<JoystickButtonUpEvent>(var);
709  case EventType::JOY_BUTTON_DOWN: return &std::get<JoystickButtonDownEvent>(var);
710  case EventType::JOY_AXIS_MOTION: return &std::get<JoystickAxisMotionEvent>(var);
711  case EventType::JOY_HAT: return &std::get<JoystickHatEvent>(var);
712  default: return nullptr;
713  }
714  }
715 };
716 template<typename T>
717 const T* get_if(const Event& event)
718 {
719  assert(event);
720  GetIfEventHelper<T> helper;
721  return helper(event);
722 }
723 template<typename T>
724 const T& get(const Event& event)
725 {
726  assert(event);
727  const T* t = get_if<T>(event);
728  assert(t);
729  return *t;
730 }
731 
732 } // namespace openmsx
733 
734 #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
zstring_view getCommand() const
Definition: Event.hh:411
CliCommandEvent(std::string_view command_, const CliConnection *id_)
Definition: Event.hh:408
const CliConnection * getId() const
Definition: Event.hh:412
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:584
Event & operator=(const Event &other)
Definition: Event.hh:596
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
static constexpr unsigned Y_AXIS
Definition: Event.hh:243
JoystickAxisMotionEvent(unsigned joystick_, unsigned axis_, int value_)
Definition: Event.hh:245
JoystickButtonDownEvent(unsigned joystick_, unsigned button_)
Definition: Event.hh:235
unsigned getButton() const
Definition: Event.hh:215
JoystickButtonEvent(unsigned joystick_, unsigned button_)
Definition: Event.hh:218
JoystickButtonUpEvent(unsigned joystick_, unsigned button_)
Definition: Event.hh:228
JoystickEvent(unsigned joystick_)
Definition: Event.hh:205
unsigned getJoystick() const
Definition: Event.hh:202
JoystickHatEvent(unsigned 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:276
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:658
constexpr uint8_t event_index
Definition: Event.hh:500
const T & get(const Event &event)
Definition: Event.hh:724
EventType
Definition: Event.hh:506
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:497
bool isRepeatStopper(const Event &self, const Event &other)
Should 'bind -repeat' be stopped by 'other' event.
Definition: Event.cc:185
bool matches(const Event &self, const Event &other)
Does this event 'match' the given event.
Definition: Event.cc:216
const EventVariant & getVariant(const Event &event)
Definition: Event.hh:639
auto visit(Visitor &&visitor, const Event &event)
Definition: Event.hh:652
const T * get_if(const Event &event)
Definition: Event.hh:717
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:127
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:644
std::recursive_mutex eventPoolMutex
Definition: Event.hh:578
ObjectPool< RcEvent > eventPool
Definition: Event.hh:555
std::string toString(const Event &event)
Get a string representation of this event.
Definition: Event.cc:180
const JoystickEvent * operator()(const Event &event)
Definition: Event.hh:705
const KeyEvent * operator()(const Event &event)
Definition: Event.hh:694
const TimedEvent * operator()(const Event &event)
Definition: Event.hh:673
const T * operator()(const Event &event)
Definition: Event.hh:667
RcEvent(Args &&...args)
Definition: Event.hh:549
uint8_t refCount
Definition: Event.hh:551