|
KiCad PCB EDA Suite
|
#include <tool_dispatcher.h>
Classes | |
| struct | BUTTON_STATE |
| Store information about a mouse button state. More... | |
Public Member Functions | |
| TOOL_DISPATCHER (TOOL_MANAGER *aToolMgr) | |
| virtual | ~TOOL_DISPATCHER () |
| virtual void | ResetState () |
| Bring the dispatcher to its initial state. | |
| virtual void | DispatchWxEvent (wxEvent &aEvent) |
| Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those. | |
| std::optional< TOOL_EVENT > | GetToolEvent (wxKeyEvent *aKeyEvent, bool *aSpecialKeyFlag) |
| Map a wxWidgets key event to a TOOL_EVENT. | |
Static Public Member Functions | |
| static bool | ShouldDropAutoRepeat (int aKeyCode, wxLongLong aNowMs, bool aKeyIsDown, int &aLastKey, wxLongLong &aLastTimeMs) |
| Pure decision used to discard backlogged OS key auto-repeat events. | |
Static Public Attributes | |
| static const int | AutoRepeatWindowMs = 250 |
| The maximum gap (ms) between two events of the same key for them to count as one OS auto-repeat burst rather than two deliberate key presses. | |
Private Member Functions | |
| bool | handleMouseButton (wxEvent &aEvent, int aIndex, bool aMotion) |
| Handles mouse related events (click, motion, dragging). | |
| void | flushPendingClicks () |
| Processes any pending mouse clicks that have been physically completed but not yet dispatched. | |
| bool | isStaleAutoRepeat (const wxKeyEvent &aKeyEvent) |
| Decide whether a keyboard event must be dropped because it is a backlogged OS key auto-repeat event delivered after the key was physically released. | |
| KIGFX::VIEW * | getView () |
| Returns the instance of VIEW, used by the application. | |
Static Private Member Functions | |
| static int | decodeModifiers (const wxKeyboardState *aState) |
| Returns the state of key modifiers (Alt, Ctrl and so on) as OR'ed list of bits (MD_CTRL, MD_ALT ...) | |
Private Attributes | |
| int | m_sysDragMinX |
| Minimum distance before drag is activated in the X axis. | |
| int | m_sysDragMinY |
| Maximum distance before drag is activated in the Y axis. | |
| VECTOR2D | m_lastMousePos |
| The last mouse cursor position (in world coordinates). | |
| VECTOR2D | m_lastMousePosScreen |
| The last mouse cursor position (in screen coordinates). | |
| std::vector< BUTTON_STATE * > | m_buttons |
| int | m_lastKeyCode |
| Key code of the key that was last processed, or 0 when no key is armed. | |
| wxLongLong | m_lastKeyTime |
| Local time (ms) at which m_lastKeyCode was last processed. | |
| TOOL_MANAGER * | m_toolMgr |
| Instance of tool manager that cooperates with the dispatcher. | |
Static Private Attributes | |
| static const int | DragTimeThreshold = 300 |
| The time threshold for a mouse button press that distinguishes between a single mouse click and a beginning of drag event (expressed in milliseconds). | |
| static const int | DragDistanceThreshold = 8 |
| The distance threshold for mouse cursor that distinguishes between a single mouse click and a beginning of drag event (expressed in screen pixels). | |
Definition at line 49 of file tool_dispatcher.h.
| TOOL_DISPATCHER::TOOL_DISPATCHER | ( | TOOL_MANAGER * | aToolMgr | ) |
| aToolMgr | tool manager instance the events will be sent to. |
Definition at line 127 of file tool_dispatcher.cpp.
References BUT_AUX1, BUT_AUX2, BUT_LEFT, BUT_MIDDLE, BUT_RIGHT, DragDistanceThreshold, m_buttons, m_lastKeyCode, m_lastKeyTime, m_sysDragMinX, m_sysDragMinY, m_toolMgr, and ResetState().
|
virtual |
Definition at line 153 of file tool_dispatcher.cpp.
References m_buttons.
|
staticprivate |
Returns the state of key modifiers (Alt, Ctrl and so on) as OR'ed list of bits (MD_CTRL, MD_ALT ...)
Definition at line 159 of file tool_dispatcher.cpp.
References MD_ALT, MD_ALTGR, MD_CTRL, MD_META, MD_SHIFT, and MD_SUPER.
Referenced by DispatchWxEvent(), GetToolEvent(), and handleMouseButton().
|
virtual |
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
| aEvent | is the wxWidgets event to be processed. |
Definition at line 525 of file tool_dispatcher.cpp.
References decodeModifiers(), dump(), KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE, flushPendingClicks(), KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary(), GetToolEvent(), handleMouseButton(), KIUI::IsInputControlEditable(), KIUI::IsInputControlFocused(), isMouseClick(), isStaleAutoRepeat(), KIPLATFORM::UI::IsWindowActive(), kicadTraceKeyEvent, kicadTraceToolStack, m_buttons, m_lastMousePos, m_lastMousePosScreen, m_toolMgr, MD_MODIFIER_MASK, ACTION_MENU::OnMenuEvent(), TA_MOUSE_MOTION, TA_MOUSE_WHEEL, and TC_MOUSE.
Referenced by CVPCB_MAINFRAME::CVPCB_MAINFRAME(), FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME(), KICAD_MANAGER_FRAME::setupTools(), SIMULATOR_FRAME::setupTools(), SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME(), CVPCB_MAINFRAME::~CVPCB_MAINFRAME(), and KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME().
|
private |
Processes any pending mouse clicks that have been physically completed but not yet dispatched.
This ensures clicks are processed before cancel events when both happen in quick succession.
Definition at line 478 of file tool_dispatcher.cpp.
References m_buttons, m_toolMgr, TOOL_EVENT::SetMousePosition(), TA_MOUSE_CLICK, and TC_MOUSE.
Referenced by DispatchWxEvent().
| std::optional< TOOL_EVENT > TOOL_DISPATCHER::GetToolEvent | ( | wxKeyEvent * | aKeyEvent, |
| bool * | aSpecialKeyFlag ) |
Map a wxWidgets key event to a TOOL_EVENT.
Definition at line 398 of file tool_dispatcher.cpp.
References decodeModifiers(), dump(), ignore_unused(), isKeyModifierOnly(), isKeySpecialCode(), kicadTraceKeyEvent, MD_ALT, MD_CTRL, TA_CANCEL_TOOL, TA_KEY_PRESSED, TC_COMMAND, TC_KEYBOARD, and translateSpecialCode().
Referenced by DispatchWxEvent().
|
private |
Returns the instance of VIEW, used by the application.
Definition at line 207 of file tool_dispatcher.cpp.
References m_toolMgr.
|
private |
Handles mouse related events (click, motion, dragging).
Definition at line 213 of file tool_dispatcher.cpp.
References TOOL_DISPATCHER::BUTTON_STATE::button, TOOL_DISPATCHER::BUTTON_STATE::dblClickEvent, decodeModifiers(), down, TOOL_DISPATCHER::BUTTON_STATE::downEvent, TOOL_DISPATCHER::BUTTON_STATE::downPosition, TOOL_DISPATCHER::BUTTON_STATE::downTimestamp, TOOL_DISPATCHER::BUTTON_STATE::dragging, TOOL_DISPATCHER::BUTTON_STATE::dragOrigin, TOOL_DISPATCHER::BUTTON_STATE::dragOriginScreen, DragTimeThreshold, TOOL_DISPATCHER::BUTTON_STATE::GetState(), m_buttons, m_lastMousePos, m_lastMousePosScreen, m_sysDragMinX, m_sysDragMinY, m_toolMgr, TOOL_DISPATCHER::BUTTON_STATE::pressed, TA_MOUSE_CLICK, TA_MOUSE_DBLCLICK, TA_MOUSE_DOWN, TA_MOUSE_DRAG, TA_MOUSE_UP, TC_MOUSE, up, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by DispatchWxEvent().
|
private |
Decide whether a keyboard event must be dropped because it is a backlogged OS key auto-repeat event delivered after the key was physically released.
On Linux a hotkey whose action is slower than the OS auto-repeat interval lets repeat events accumulate in the wx event queue; once the key is released the queue keeps draining and the action keeps running. The first event of a burst always runs (so a quick tap still works), but later repeats only run while the key is still held down.
Definition at line 512 of file tool_dispatcher.cpp.
References m_lastKeyCode, m_lastKeyTime, and ShouldDropAutoRepeat().
Referenced by DispatchWxEvent().
|
virtual |
Bring the dispatcher to its initial state.
Definition at line 197 of file tool_dispatcher.cpp.
References m_buttons, m_lastKeyCode, and m_lastKeyTime.
Referenced by TOOL_DISPATCHER().
|
static |
Pure decision used to discard backlogged OS key auto-repeat events.
A repeat event is stale (and must be dropped) only when it belongs to the same burst as the previously processed event (same key seen less than AutoRepeatWindowMs ago) and the key is no longer physically held. The leading edge of every press is kept, so a quick tap whose key has already bounced up still runs once.
| aKeyCode | key code of the current event. |
| aNowMs | current time in milliseconds. |
| aKeyIsDown | whether the key is currently physically pressed. |
| aLastKey | in/out key code of the previously processed event; updated to aKeyCode. |
| aLastTimeMs | in/out time of the previously processed event; updated to aNowMs. |
Definition at line 500 of file tool_dispatcher.cpp.
References AutoRepeatWindowMs.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and isStaleAutoRepeat().
|
static |
The maximum gap (ms) between two events of the same key for them to count as one OS auto-repeat burst rather than two deliberate key presses.
Definition at line 79 of file tool_dispatcher.h.
Referenced by BOOST_AUTO_TEST_CASE(), and ShouldDropAutoRepeat().
|
staticprivate |
The distance threshold for mouse cursor that distinguishes between a single mouse click and a beginning of drag event (expressed in screen pixels).
System drag preferences take precedence if available
Definition at line 132 of file tool_dispatcher.h.
Referenced by TOOL_DISPATCHER().
|
staticprivate |
The time threshold for a mouse button press that distinguishes between a single mouse click and a beginning of drag event (expressed in milliseconds).
Definition at line 127 of file tool_dispatcher.h.
Referenced by handleMouseButton().
|
private |
Definition at line 142 of file tool_dispatcher.h.
Referenced by DispatchWxEvent(), flushPendingClicks(), handleMouseButton(), ResetState(), TOOL_DISPATCHER(), and ~TOOL_DISPATCHER().
|
private |
Key code of the key that was last processed, or 0 when no key is armed.
Used together with m_lastKeyTime to drop stale auto-repeat events that arrive after the key was released while still letting the leading edge of every fresh press through.
Definition at line 147 of file tool_dispatcher.h.
Referenced by isStaleAutoRepeat(), ResetState(), and TOOL_DISPATCHER().
|
private |
Local time (ms) at which m_lastKeyCode was last processed.
Definition at line 150 of file tool_dispatcher.h.
Referenced by isStaleAutoRepeat(), ResetState(), and TOOL_DISPATCHER().
|
private |
The last mouse cursor position (in world coordinates).
Definition at line 137 of file tool_dispatcher.h.
Referenced by DispatchWxEvent(), and handleMouseButton().
|
private |
The last mouse cursor position (in screen coordinates).
Definition at line 138 of file tool_dispatcher.h.
Referenced by DispatchWxEvent(), and handleMouseButton().
|
private |
Minimum distance before drag is activated in the X axis.
Definition at line 134 of file tool_dispatcher.h.
Referenced by handleMouseButton(), and TOOL_DISPATCHER().
|
private |
Maximum distance before drag is activated in the Y axis.
Definition at line 135 of file tool_dispatcher.h.
Referenced by handleMouseButton(), and TOOL_DISPATCHER().
|
private |
Instance of tool manager that cooperates with the dispatcher.
Definition at line 153 of file tool_dispatcher.h.
Referenced by DispatchWxEvent(), flushPendingClicks(), getView(), handleMouseButton(), and TOOL_DISPATCHER().