|
Krita Source Code Documentation
|
Central object to manage canvas input. More...
#include <kis_input_manager.h>
Inheritance diagram for KisInputManager:Classes | |
| class | Private |
Public Member Functions | |
| void | addTrackedCanvas (KisCanvas2 *canvas) |
| void | attachPriorityEventFilter (QObject *filter, int priority=0) |
| attachPriorityEventFilter | |
| KisCanvas2 * | canvas () const |
| KisToolInvocationAction * | defaultInputAction () const |
| void | detachPriorityEventFilter (QObject *filter) |
| detachPriorityEventFilter | |
| bool | eventFilter (QObject *object, QEvent *event) override |
| KisInputManager (QObject *parent) | |
| void | registerPopupWidget (KisPopupWidgetInterface *popupWidget) |
| void | removeTrackedCanvas (KisCanvas2 *canvas) |
| void | setupAsEventFilter (QObject *receiver) |
| void | toggleTabletLogger () |
| QPointer< KisToolProxy > | toolProxy () const |
| ~KisInputManager () override | |
Private Slots | |
| void | deregisterPopupWidget () |
| void | profileChanged () |
| void | slotAboutToChangeTool () |
| void | slotCompressedMoveEvent () |
| void | slotConfigChanged () |
| void | slotTextModeChanged () |
| void | slotToolChanged () |
Private Member Functions | |
| template<class Event > | |
| bool | compressMoveEventCommon (Event *event) |
| bool | eventFilterImpl (QEvent *event) |
Private Attributes | |
| Private *const | d |
Central object to manage canvas input.
The Input Manager class manages all canvas input. It is created by KisCanvas2 and processes all events related to input sent to the canvas.
The Input Manager keeps track of a set of actions and a set of shortcuts. The actions are pre-defined while the shortcuts are set from configuration.
For each event, it will try to determine if there is a shortcut that matches the input. It will then activate this action and pass all consecutive events on to this action.
Definition at line 38 of file kis_input_manager.h.
| KisInputManager::KisInputManager | ( | QObject * | parent | ) |
Constructor.
Definition at line 58 of file kis_input_manager.cpp.
References d, KoToolManager::instance(), KisConfigNotifier::instance(), KisInputManager::Private::matcher, KisInputManager::Private::moveEventCompressor, KisInputManager::Private::setupActions(), slotAboutToChangeTool(), slotCompressedMoveEvent(), slotConfigChanged(), slotTextModeChanged(), and slotToolChanged().
|
override |
Destructor.
Definition at line 82 of file kis_input_manager.cpp.
References d.
| void KisInputManager::addTrackedCanvas | ( | KisCanvas2 * | canvas | ) |
Definition at line 90 of file kis_input_manager.cpp.
References KisInputManager::Private::CanvasSwitcher::addCanvas(), canvas(), KisInputManager::Private::canvasSwitcher, and d.
| void KisInputManager::attachPriorityEventFilter | ( | QObject * | filter, |
| int | priority = 0 ) |
attachPriorityEventFilter
| filter | |
| priority |
Definition at line 137 of file kis_input_manager.cpp.
References d, kismpl::mem_equal_to(), kismpl::mem_greater(), KisInputManager::Private::priorityEventFilter, and KisInputManager::Private::priorityEventFilterSeqNo.
| KisCanvas2 * KisInputManager::canvas | ( | ) | const |
Return the canvas this input manager is associated with.
Definition at line 805 of file kis_input_manager.cpp.
References KisInputManager::Private::canvas, and d.
|
private |
We construct a copy of this event object, so we must ensure it has a correct type.
Compress the events if the tool doesn't need high resolution input
On Linux Qt eats the rest of unneeded events if we ignore the first of the chunk of tablet events. So generally we should never activate this feature. Only for testing purposes!
Definition at line 233 of file kis_input_manager.cpp.
References KisInputManager::Private::compressedMoveEvent, d, KisInputManager::Private::handleCompressedTabletEvent(), KisInputManager::Private::matcher, KisInputManager::Private::moveEventCompressor, slotCompressedMoveEvent(), KisSignalCompressor::start(), KisShortcutMatcher::supportsHiResInputEvents(), KisInputManager::Private::testingAcceptCompressedTabletEvents, and KisInputManager::Private::testingCompressBrushEvents.
| KisToolInvocationAction * KisInputManager::defaultInputAction | ( | ) | const |
The built-in action that forwards primary strokes to the active tool.
Definition at line 815 of file kis_input_manager.cpp.
References d, and KisInputManager::Private::defaultInputAction.
|
privateslot |
Definition at line 110 of file kis_input_manager.cpp.
References d, KisPopupWidgetInterface::dismiss(), KIS_ASSERT, KisPopupWidgetInterface::onScreen(), and KisInputManager::Private::popupWidget.
| void KisInputManager::detachPriorityEventFilter | ( | QObject * | filter | ) |
detachPriorityEventFilter
| filter |
Definition at line 155 of file kis_input_manager.cpp.
References d, kismpl::mem_equal_to(), and KisInputManager::Private::priorityEventFilter.
|
override |
Event filter method. Overridden from QObject.
If the filter removed itself from the filters list or added something there, just exit the loop
Definition at line 185 of file kis_input_manager.cpp.
References d, KisInputManager::Private::eventEater, KisInputEventsEater::eventFilter(), eventFilterImpl(), KisInputManager::Private::eventsReceiver, KisShortcutMatcher::hasRunningShortcut(), KisInputManager::Private::matcher, KisInputManager::Private::priorityEventFilter, KisInputManager::Private::priorityEventFilterSeqNo, and KisInputManager::Private::toolProxy.
|
private |
When Krita (as an application) has no input focus, we cannot handle key events. But at the same time, when the user hovers Krita canvas, we should still show him the correct cursor.
So here we just add a simple workaround to resync shortcut matcher's state at least against the basic modifiers, like Shift, Control and Alt.
On Windows, when the user presses some global window manager shortcuts, e.g. Alt+Space (to show window title menu), events for these key presses and releases are not delivered (see bug 424319). This code is a workaround for this problem. It checks consistency of standard modifiers and resets shortcut's matcher state in case of a trouble.
Re-check the native platform key API against keys we are unsure about, and fix them in case they now show as released.
The other part of the fix is placed in the handler of ShortcutOverride, because it needs a custom set of the presset keys.
See a comment in the handler of KeyRelease event for shouldSynchronizeOnNextKeyPress explanation
There is also a case when Krita gets focus via Win+1 key, then the polled key '1' gets into the matcher, but OS does not deliver any signals for it (see bug 451424)
On some systems Qt fails to generate a correct sequence of events when the user releases a modifier key while some other key is pressed.
In such cases Qt doesn't understand that the key has changed its name in the meantime and sends incorrect key-release event for it (or an auto- repeated key-release/key-press pair).
Example (on en-US keyboard):
1) Press Shift (Key_Shift-press is delivered) 2) Press '2' (Key_At-press is delivered) 3) Release Shift (Key_Shift-release is delivered) 4) Release '2' (Key_2-release is delivered, which is unbalanced)
The same issue happens with non-latin keyboards, where Qt does auto-key-replace routines when Control modifier is pressed.
https://bugs.kde.org/show_bug.cgi?id=454256 https://bugreports.qt.io/browse/QTBUG-103868
Wayland sends us a duplicated ScrollBegin event (one for every axis), so we cannot rely just on status of the running stroke and should use hasTouchpadScrollShortcuts() instead.
When wheelEvent->phase() is not Qt::NoScrollPhase, the delta can be easily null, so we should ignore these events.
We don't try to pass unhandled events to the tool proxy (via toolProxy->forwardHoverEvent(event)) because of the following reasons:
On Windows and Linux touch evetns are generated for touch screens only. And touch screens have no "hover" state.
On MacOS touch events are also generated for the Apple's trackpad. Though, for single-finger movements, these touch events are usually unbalanced, i.e. they don't have a corresponding TouchBegin event.
We could theoretically pass these events to the tool on MacOS only, but it seems like the system-generated mouse events are more precise and granular. That is why we just allow these mouse events in EventEater when we detect they are coming from a touchpad/trackpad outside of TouchBegin/TouchEnd guards.
Definition at line 298 of file kis_input_manager.cpp.
References KisInputManager::Private::accumulatedScrollDelta, KisTouchShortcut::allTouchStates(), KisShortcutMatcher::autoRepeatedKeyPressed(), KisShortcutMatcher::buttonPressed(), KisShortcutMatcher::buttonReleased(), canvas(), KisCanvas2::canvasWidget, compressMoveEventCommon(), KisTouchShortcut::countTouchPoints(), d, KisShortcutMatcher::debugPressedKeys(), deregisterPopupWidget(), KisInputEventsEater::eatOneMousePress(), KisShortcutMatcher::enterEvent(), KisInputManager::Private::eventEater, KisInputManager::Private::eventsReceiver, KisInputManager::Private::fixShortcutMatcherModifiersState(), KisShortcutMatcher::hasPolledKeys(), KisShortcutMatcher::hasTouchpadScrollShortcuts(), KisShortcutMatcher::keyPressed(), KisShortcutMatcher::keyReleased(), KisShortcutMatcher::leaveEvent(), KisShortcutMatcher::lostFocusEvent(), KisInputManager::Private::matcher, KisShortcutMatcher::nativeGestureBeginEvent(), KisShortcutMatcher::nativeGestureEndEvent(), KisShortcutMatcher::nativeGestureEvent(), KisPopupWidgetInterface::onScreen(), KisInputManager::Private::popupWasActive, KisInputManager::Private::popupWidget, KisTouchShortcut::pressedOnlyTouchStates(), KisInputManager::Private::processUnhandledEvent(), KisExtendedModifiersMapper::queryExtendedModifiers(), KisExtendedModifiersMapper::queryStandardModifiers(), KisShortcutMatcher::reinitializeButtons(), KisInputManager::Private::resetCompressor(), KisShortcutMatcher::sanityCheckModifiersCorrectness(), KisAbstractInputAction::setInputManager(), shouldResetWheelDelta(), KisInputManager::Private::shouldSynchronizeOnNextKeyPress, KisAlgebra2D::signPZ(), KisInputManager::Private::tabletLatencyTracker, KisShortcutMatcher::touchBeginEvent(), KisShortcutMatcher::touchCancelEvent(), KisShortcutMatcher::touchEndEvent(), KisShortcutMatcher::touchpadScrollBeginEvent(), KisShortcutMatcher::touchpadScrollEndEvent(), KisShortcutMatcher::touchpadScrollEvent(), KisShortcutMatcher::touchUpdateEvent(), KisInputManager::Private::useUnbalancedKeyPressEventWorkaround, KisSingleActionShortcut::WheelDown, KisShortcutMatcher::wheelEvent(), KisSingleActionShortcut::WheelLeft, KisSingleActionShortcut::WheelRight, KisSingleActionShortcut::WheelUp, and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().
|
privateslot |
Definition at line 871 of file kis_input_manager.cpp.
References KisInputProfile::actionForId(), KisToolInvocationAction::ActivateShortcut, KisInputManager::Private::addKeyShortcut(), KisInputManager::Private::addNativeGestureShortcut(), KisInputManager::Private::addStrokeShortcut(), KisInputManager::Private::addTouchShortcut(), KisInputManager::Private::addWheelShortcut(), KisInputProfile::allShortcuts(), KisShortcutMatcher::clearShortcuts(), KisInputProfileManager::currentProfile, d, dbgUI, KisInputProfileManager::instance(), KisShortcutConfiguration::KeyCombinationType, KisInputManager::Private::matcher, KisShortcutConfiguration::MouseButtonType, KisShortcutConfiguration::MouseWheelType, KisShortcutConfiguration::NativeGestureType, KisShortcutConfiguration::OneFingerDrag, KisShortcutConfiguration::OneFingerTap, KisShortcutConfiguration::TouchGestureType, and warnUI.
| void KisInputManager::registerPopupWidget | ( | KisPopupWidgetInterface * | popupWidget | ) |
Definition at line 100 of file kis_input_manager.cpp.
References d, deregisterPopupWidget(), KIS_ASSERT, and KisInputManager::Private::popupWidget.
| void KisInputManager::removeTrackedCanvas | ( | KisCanvas2 * | canvas | ) |
Definition at line 95 of file kis_input_manager.cpp.
References canvas(), KisInputManager::Private::canvasSwitcher, d, and KisInputManager::Private::CanvasSwitcher::removeCanvas().
| void KisInputManager::setupAsEventFilter | ( | QObject * | receiver | ) |
Installs the input manager as an event filter for receiver. Please note that KisInputManager is supposed to handle events for a single receiver only. This is defined by the fact that it resends some of the events back through the Qt's queue to the receiver. That is why the input manager will assert when it gets an event with wrong destination.
Definition at line 168 of file kis_input_manager.cpp.
References d, and KisInputManager::Private::eventsReceiver.
|
privateslot |
Definition at line 820 of file kis_input_manager.cpp.
References canvas(), KisCanvas2::canvasWidget, d, KisShortcutMatcher::lostFocusEvent(), KisInputManager::Private::matcher, and KisAbstractInputAction::setInputManager().
|
privateslot |
Definition at line 797 of file kis_input_manager.cpp.
References KisInputManager::Private::compressedMoveEvent, d, KisInputManager::Private::handleCompressedTabletEvent(), and void().
|
privateslot |
Definition at line 124 of file kis_input_manager.cpp.
References d, KisInputManager::Private::fixShortcutMatcherModifiersState(), and KisConfig::ignoreHighFunctionKeys().
|
privateslot |
Definition at line 855 of file kis_input_manager.cpp.
References KoToolManager::activeToolId(), canvas(), KisInputManager::Private::canvas, d, KisInputManager::Private::forwardAllEventsToTool, KoToolManager::instance(), KoToolBase::isInTextMode(), KisInputManager::Private::matcher, KisShortcutMatcher::suppressAllKeyboardActions, and KoToolManager::toolById().
|
privateslot |
Definition at line 832 of file kis_input_manager.cpp.
References KoToolManager::activeToolId(), canvas(), KisInputManager::Private::canvas, d, KisInputManager::Private::forwardAllEventsToTool, KoToolManager::instance(), KoToolBase::isInTextMode(), KoToolBase::maskSyntheticEvents(), KisInputManager::Private::matcher, KisAbstractInputAction::setInputManager(), KisInputManager::Private::setMaskSyntheticEvents(), KisShortcutMatcher::suppressAllKeyboardActions, KisShortcutMatcher::suppressConflictingKeyActions(), KoToolManager::toolById(), KisShortcutMatcher::toolHasBeenActivated(), and toolProxy().
| void KisInputManager::toggleTabletLogger | ( | ) |
Definition at line 132 of file kis_input_manager.cpp.
References KisTabletDebugger::instance(), and KisTabletDebugger::toggleDebugging().
| QPointer< KisToolProxy > KisInputManager::toolProxy | ( | ) | const |
The tool proxy of the current application.
Definition at line 810 of file kis_input_manager.cpp.
References d, and KisInputManager::Private::toolProxy.
|
private |
Definition at line 119 of file kis_input_manager.h.