mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
ModifierKeys: Avoid direct access to currentModifiers when reading but not writing
This commit is contained in:
parent
0a71227126
commit
5d7208bb54
11 changed files with 64 additions and 64 deletions
|
|
@ -437,11 +437,11 @@ namespace Keys
|
|||
{
|
||||
if (modifierKeysAreStale)
|
||||
{
|
||||
const auto oldMods = ModifierKeys::currentModifiers;
|
||||
const auto oldMods = ModifierKeys::getCurrentModifiers();
|
||||
XWindowSystem::getInstance()->getNativeRealtimeModifiers();
|
||||
ModifierKeys::currentModifiers = oldMods.withoutMouseButtons()
|
||||
.withFlags (ModifierKeys::currentModifiers.withOnlyMouseButtons()
|
||||
.getRawFlags());
|
||||
.withFlags (ModifierKeys::getCurrentModifiers().withOnlyMouseButtons()
|
||||
.getRawFlags());
|
||||
modifierKeysAreStale = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -539,7 +539,7 @@ static void updateKeyModifiers (int status) noexcept
|
|||
if ((status & ControlMask) != 0) keyMods |= ModifierKeys::ctrlModifier;
|
||||
if ((status & Keys::AltMask) != 0) keyMods |= ModifierKeys::altModifier;
|
||||
|
||||
ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
|
||||
ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withOnlyMouseButtons().withFlags (keyMods);
|
||||
|
||||
Keys::numLock = ((status & Keys::NumLockMask) != 0);
|
||||
Keys::capsLock = ((status & LockMask) != 0);
|
||||
|
|
@ -581,8 +581,8 @@ static bool updateKeyModifiersFromSym (KeySym sym, bool press) noexcept
|
|||
break;
|
||||
}
|
||||
|
||||
ModifierKeys::currentModifiers = press ? ModifierKeys::currentModifiers.withFlags (modifier)
|
||||
: ModifierKeys::currentModifiers.withoutFlags (modifier);
|
||||
ModifierKeys::currentModifiers = press ? ModifierKeys::getCurrentModifiers().withFlags (modifier)
|
||||
: ModifierKeys::getCurrentModifiers().withoutFlags (modifier);
|
||||
|
||||
return isModifier;
|
||||
}
|
||||
|
|
@ -2531,10 +2531,10 @@ ModifierKeys XWindowSystem::getNativeRealtimeModifiers() const
|
|||
((mask & ControlMask) != 0 ? keyboardMods : keyboardClearMods) |= ModifierKeys::ctrlModifier;
|
||||
}
|
||||
|
||||
ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutMouseButtons()
|
||||
.withFlags (mouseMods)
|
||||
.withoutFlags (keyboardClearMods)
|
||||
.withFlags (keyboardMods);
|
||||
ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withoutMouseButtons()
|
||||
.withFlags (mouseMods)
|
||||
.withoutFlags (keyboardClearMods)
|
||||
.withFlags (keyboardMods);
|
||||
|
||||
// We are keeping track of the state of modifier keys and mouse buttons with the assumption that
|
||||
// for every mouse down we are going to receive a mouse up etc.
|
||||
|
|
@ -2548,7 +2548,7 @@ ModifierKeys XWindowSystem::getNativeRealtimeModifiers() const
|
|||
// receives an event again.
|
||||
Keys::modifierKeysAreStale = true;
|
||||
|
||||
return ModifierKeys::currentModifiers;
|
||||
return ModifierKeys::getCurrentModifiers();
|
||||
}
|
||||
|
||||
static bool hasWorkAreaData (const XWindowSystemUtilities::GetXProperty& prop)
|
||||
|
|
@ -3425,7 +3425,7 @@ void XWindowSystem::handleWindowMessage (LinuxComponentPeer* peer, XEvent& event
|
|||
|
||||
void XWindowSystem::handleKeyPressEvent (LinuxComponentPeer* peer, XKeyEvent& keyEvent) const
|
||||
{
|
||||
auto oldMods = ModifierKeys::currentModifiers;
|
||||
auto oldMods = ModifierKeys::getCurrentModifiers();
|
||||
Keys::refreshStaleModifierKeys();
|
||||
|
||||
char utf8 [64] = { 0 };
|
||||
|
|
@ -3450,7 +3450,7 @@ void XWindowSystem::handleKeyPressEvent (LinuxComponentPeer* peer, XKeyEvent& ke
|
|||
|
||||
if (keyCode < 0x20)
|
||||
keyCode = (int) X11Symbols::getInstance()->xkbKeycodeToKeysym (display, (::KeyCode) keyEvent.keycode, 0,
|
||||
ModifierKeys::currentModifiers.isShiftDown() ? 1 : 0);
|
||||
ModifierKeys::getCurrentModifiers().isShiftDown() ? 1 : 0);
|
||||
|
||||
keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
|
||||
}
|
||||
|
|
@ -3534,7 +3534,7 @@ void XWindowSystem::handleKeyPressEvent (LinuxComponentPeer* peer, XKeyEvent& ke
|
|||
if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
|
||||
keyPressed = true;
|
||||
|
||||
if (oldMods != ModifierKeys::currentModifiers)
|
||||
if (oldMods != ModifierKeys::getCurrentModifiers())
|
||||
peer->handleModifierKeysChange();
|
||||
|
||||
if (keyDownChange)
|
||||
|
|
@ -3572,10 +3572,10 @@ void XWindowSystem::handleKeyReleaseEvent (LinuxComponentPeer* peer, const XKeyE
|
|||
sym = X11Symbols::getInstance()->xkbKeycodeToKeysym (display, (::KeyCode) keyEvent.keycode, 0, 0);
|
||||
}
|
||||
|
||||
auto oldMods = ModifierKeys::currentModifiers;
|
||||
auto oldMods = ModifierKeys::getCurrentModifiers();
|
||||
auto keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
|
||||
|
||||
if (oldMods != ModifierKeys::currentModifiers)
|
||||
if (oldMods != ModifierKeys::getCurrentModifiers())
|
||||
peer->handleModifierKeysChange();
|
||||
|
||||
if (keyDownChange)
|
||||
|
|
@ -3598,10 +3598,10 @@ void XWindowSystem::handleWheelEvent (LinuxComponentPeer* peer, const XButtonPre
|
|||
|
||||
void XWindowSystem::handleButtonPressEvent (LinuxComponentPeer* peer, const XButtonPressedEvent& buttonPressEvent, int buttonModifierFlag) const
|
||||
{
|
||||
ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withFlags (buttonModifierFlag);
|
||||
ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withFlags (buttonModifierFlag);
|
||||
peer->toFront (true);
|
||||
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, getLogicalMousePos (buttonPressEvent, peer->getPlatformScaleFactor()),
|
||||
ModifierKeys::currentModifiers, MouseInputSource::defaultPressure,
|
||||
ModifierKeys::getCurrentModifiers(), MouseInputSource::defaultPressure,
|
||||
MouseInputSource::defaultOrientation, getEventTime (buttonPressEvent), {});
|
||||
}
|
||||
|
||||
|
|
@ -3638,9 +3638,9 @@ void XWindowSystem::handleButtonReleaseEvent (LinuxComponentPeer* peer, const XB
|
|||
{
|
||||
switch (pointerMap[mapIndex])
|
||||
{
|
||||
case Keys::LeftButton: ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier); break;
|
||||
case Keys::RightButton: ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier); break;
|
||||
case Keys::MiddleButton: ModifierKeys::currentModifiers = ModifierKeys::currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier); break;
|
||||
case Keys::LeftButton: ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withoutFlags (ModifierKeys::leftButtonModifier); break;
|
||||
case Keys::RightButton: ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withoutFlags (ModifierKeys::rightButtonModifier); break;
|
||||
case Keys::MiddleButton: ModifierKeys::currentModifiers = ModifierKeys::getCurrentModifiers().withoutFlags (ModifierKeys::middleButtonModifier); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
@ -3651,7 +3651,7 @@ void XWindowSystem::handleButtonReleaseEvent (LinuxComponentPeer* peer, const XB
|
|||
dragState.handleExternalDragButtonReleaseEvent();
|
||||
|
||||
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, getLogicalMousePos (buttonRelEvent, peer->getPlatformScaleFactor()),
|
||||
ModifierKeys::currentModifiers, MouseInputSource::defaultPressure, MouseInputSource::defaultOrientation, getEventTime (buttonRelEvent));
|
||||
ModifierKeys::getCurrentModifiers(), MouseInputSource::defaultPressure, MouseInputSource::defaultOrientation, getEventTime (buttonRelEvent));
|
||||
}
|
||||
|
||||
void XWindowSystem::handleMotionNotifyEvent (LinuxComponentPeer* peer, const XPointerMovedEvent& movedEvent) const
|
||||
|
|
@ -3665,7 +3665,7 @@ void XWindowSystem::handleMotionNotifyEvent (LinuxComponentPeer* peer, const XPo
|
|||
dragState.handleExternalDragMotionNotify();
|
||||
|
||||
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, getLogicalMousePos (movedEvent, peer->getPlatformScaleFactor()),
|
||||
ModifierKeys::currentModifiers, MouseInputSource::defaultPressure,
|
||||
ModifierKeys::getCurrentModifiers(), MouseInputSource::defaultPressure,
|
||||
MouseInputSource::defaultOrientation, getEventTime (movedEvent));
|
||||
}
|
||||
|
||||
|
|
@ -3674,11 +3674,11 @@ void XWindowSystem::handleEnterNotifyEvent (LinuxComponentPeer* peer, const XEnt
|
|||
if (peer->getParentWindow() != 0)
|
||||
peer->updateWindowBounds();
|
||||
|
||||
if (! ModifierKeys::currentModifiers.isAnyMouseButtonDown())
|
||||
if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
|
||||
{
|
||||
updateKeyModifiers ((int) enterEvent.state);
|
||||
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, getLogicalMousePos (enterEvent, peer->getPlatformScaleFactor()),
|
||||
ModifierKeys::currentModifiers, MouseInputSource::defaultPressure,
|
||||
ModifierKeys::getCurrentModifiers(), MouseInputSource::defaultPressure,
|
||||
MouseInputSource::defaultOrientation, getEventTime (enterEvent));
|
||||
}
|
||||
}
|
||||
|
|
@ -3688,12 +3688,12 @@ void XWindowSystem::handleLeaveNotifyEvent (LinuxComponentPeer* peer, const XLea
|
|||
// Suppress the normal leave if we've got a pointer grab, or if
|
||||
// it's a bogus one caused by clicking a mouse button when running
|
||||
// in a Window manager
|
||||
if (((! ModifierKeys::currentModifiers.isAnyMouseButtonDown()) && leaveEvent.mode == NotifyNormal)
|
||||
if (((! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()) && leaveEvent.mode == NotifyNormal)
|
||||
|| leaveEvent.mode == NotifyUngrab)
|
||||
{
|
||||
updateKeyModifiers ((int) leaveEvent.state);
|
||||
peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse, getLogicalMousePos (leaveEvent, peer->getPlatformScaleFactor()),
|
||||
ModifierKeys::currentModifiers, MouseInputSource::defaultPressure,
|
||||
ModifierKeys::getCurrentModifiers(), MouseInputSource::defaultPressure,
|
||||
MouseInputSource::defaultOrientation, getEventTime (leaveEvent));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue