vcl/inc/osx/salframe.h | 2 vcl/osx/salframe.cxx | 111 +++++++++--------------------------------------- vcl/osx/salframeview.mm | 14 ------ 3 files changed, 24 insertions(+), 103 deletions(-)
New commits: commit ab8631f9feed2bbe19be28f7ee0e626d29ad74fb Author: Dan Williams <[email protected]> AuthorDate: Wed Feb 11 01:03:30 2026 -0600 Commit: Dan Williams <[email protected]> CommitDate: Wed Feb 18 13:53:16 2026 +0100 vcl/osx: convert Carbon key/mouse reading functions to AppKit Instead of GetCurrentEventButtonState() and GetCurrentEventKeyModifiers() use the almost equivalent AppKit NSEvent static properties pressedMouseButtons and modifierFlags. Thanks for Patrick Luby for the suggestion. Change-Id: I92c16bac626df7fbfe6a60b661ab865d5c6edcd7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199358 Tested-by: Jenkins Reviewed-by: Patrick Luby <[email protected]> Reviewed-by: Dan Williams <[email protected]> (cherry picked from commit 79e549dad4a0f9dd4c5419bc36ebee3a3b8568e7) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199511 diff --git a/vcl/inc/osx/salframe.h b/vcl/inc/osx/salframe.h index f96bd6bb07bf..3a1581560f7f 100644 --- a/vcl/inc/osx/salframe.h +++ b/vcl/inc/osx/salframe.h @@ -245,4 +245,6 @@ inline bool AquaSalFrame::isAlive( const AquaSalFrame* pFrame ) return pInst && pInst->isFrameAlive( pFrame ); } +sal_uInt16 ImplGetModifierMask( unsigned int nMask ); + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx index e2b331061c91..0a0ed6322fe9 100644 --- a/vcl/osx/salframe.cxx +++ b/vcl/osx/salframe.cxx @@ -49,14 +49,6 @@ #include <salwtype.hxx> -#include <premac.h> -#include <objc/objc-runtime.h> -// needed for theming -// FIXME: move theming code to salnativewidgets.cxx -#include <Carbon/Carbon.h> -#include <quartz/CGHelpers.hxx> -#include <postmac.h> - const int nMinBlinkCursorDelay = 500; AquaSalFrame* AquaSalFrame::s_pCaptureFrame = nullptr; @@ -1923,6 +1915,20 @@ void AquaSalFrame::GetWorkArea( AbsoluteScreenPixelRectangle& rRect ) rRect.SetBottom( static_cast<tools::Long>(aRect.origin.y + aRect.size.height - 1) ); } +sal_uInt16 ImplGetModifierMask( unsigned int nMask ) +{ + sal_uInt16 nRet = 0; + if( (nMask & NSEventModifierFlagShift) != 0 ) + nRet |= KEY_SHIFT; + if( (nMask & NSEventModifierFlagControl) != 0 ) + nRet |= KEY_MOD3; + if( (nMask & NSEventModifierFlagOption) != 0 ) + nRet |= KEY_MOD2; + if( (nMask & NSEventModifierFlagCommand) != 0 ) + nRet |= KEY_MOD1; + return nRet; +} + SalFrame::SalPointerState AquaSalFrame::GetPointerState() { OSX_SALDATA_RUNINMAIN_UNION( GetPointerState(), state ) @@ -1935,88 +1941,15 @@ SalFrame::SalPointerState AquaSalFrame::GetPointerState() CocoaToVCL( aPt, false ); state.maPos = Point(static_cast<tools::Long>(aPt.x), static_cast<tools::Long>(aPt.y)); - NSEvent* pCur = [NSApp currentEvent]; - bool bMouseEvent = false; - if( pCur ) - { - bMouseEvent = true; - switch( [pCur type] ) - { - case NSEventTypeLeftMouseDown: - state.mnState |= MOUSE_LEFT; - break; - case NSEventTypeLeftMouseUp: - break; - case NSEventTypeRightMouseDown: - state.mnState |= MOUSE_RIGHT; - break; - case NSEventTypeRightMouseUp: - break; - case NSEventTypeOtherMouseDown: - state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; - break; - case NSEventTypeOtherMouseUp: - break; - case NSEventTypeMouseMoved: - break; - case NSEventTypeLeftMouseDragged: - state.mnState |= MOUSE_LEFT; - break; - case NSEventTypeRightMouseDragged: - state.mnState |= MOUSE_RIGHT; - break; - case NSEventTypeOtherMouseDragged: - state.mnState |= ([pCur buttonNumber] == 2) ? MOUSE_MIDDLE : 0; - break; - default: - bMouseEvent = false; - break; - } - } - if( bMouseEvent ) - { - unsigned int nMask = static_cast<unsigned int>([pCur modifierFlags]); - if( (nMask & NSEventModifierFlagShift) != 0 ) - state.mnState |= KEY_SHIFT; - if( (nMask & NSEventModifierFlagControl) != 0 ) - state.mnState |= KEY_MOD3; - if( (nMask & NSEventModifierFlagOption) != 0 ) - state.mnState |= KEY_MOD2; - if( (nMask & NSEventModifierFlagCommand) != 0 ) - state.mnState |= KEY_MOD1; + NSUInteger buttons = [NSEvent pressedMouseButtons]; + if (buttons & 1) + state.mnState |= MOUSE_LEFT; + if (buttons & 2) + state.mnState |= MOUSE_RIGHT; + if (buttons & 4) + state.mnState |= MOUSE_MIDDLE; - } - else - { - // FIXME: replace Carbon by Cocoa - // Cocoa does not have an equivalent for GetCurrentEventButtonState - // and GetCurrentEventKeyModifiers. - // we could try to get away with tracking all events for modifierKeys - // and all mouse events for button state in VCL_NSApplication::sendEvent, - // but it is unclear whether this will get us the same result. - // leave in GetCurrentEventButtonState and GetCurrentEventKeyModifiers for now - - // fill in button state - UInt32 nState = GetCurrentEventButtonState(); - state.mnState = 0; - if( nState & 1 ) - state.mnState |= MOUSE_LEFT; // primary button - if( nState & 2 ) - state.mnState |= MOUSE_RIGHT; // secondary button - if( nState & 4 ) - state.mnState |= MOUSE_MIDDLE; // tertiary button - - // fill in modifier state - nState = GetCurrentEventKeyModifiers(); - if( nState & shiftKey ) - state.mnState |= KEY_SHIFT; - if( nState & controlKey ) - state.mnState |= KEY_MOD3; - if( nState & optionKey ) - state.mnState |= KEY_MOD2; - if( nState & cmdKey ) - state.mnState |= KEY_MOD1; - } + state.mnState |= ImplGetModifierMask([NSEvent modifierFlags]); return state; } diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm index 06b31daa245c..e15168ba8703 100644 --- a/vcl/osx/salframeview.mm +++ b/vcl/osx/salframeview.mm @@ -54,20 +54,6 @@ #define WHEEL_EVENT_FACTOR 1.5 -static sal_uInt16 ImplGetModifierMask( unsigned int nMask ) -{ - sal_uInt16 nRet = 0; - if( (nMask & NSEventModifierFlagShift) != 0 ) - nRet |= KEY_SHIFT; - if( (nMask & NSEventModifierFlagControl) != 0 ) - nRet |= KEY_MOD3; - if( (nMask & NSEventModifierFlagOption) != 0 ) - nRet |= KEY_MOD2; - if( (nMask & NSEventModifierFlagCommand) != 0 ) - nRet |= KEY_MOD1; - return nRet; -} - static sal_uInt16 ImplMapCharCode( sal_Unicode aCode ) { static sal_uInt16 aKeyCodeMap[ 128 ] =
