vcl/osx/vclnsapp.mm |   33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

New commits:
commit b147debad0cb980317c6915382a12f8dfcef6dfb
Author:     Patrick Luby <guibmac...@gmail.com>
AuthorDate: Thu Jul 25 21:09:34 2024 -0400
Commit:     Patrick Luby <guibomac...@gmail.com>
CommitDate: Sat Jul 27 03:06:28 2024 +0200

    tdf#162190 handle Command-w
    
    On macOS, Command-w should attempt to close the key window.
    
    Also, pressing Command-m would fail to close the key window
    due to the same cause as tdf#162010 if the resulting key
    event was an input method event.
    
    Change-Id: I0d90547d7a0833bcc18b36f6d888e1065e91ec57
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171086
    Reviewed-by: Patrick Luby <guibomac...@gmail.com>
    Tested-by: Jenkins

diff --git a/vcl/osx/vclnsapp.mm b/vcl/osx/vclnsapp.mm
index d023e9758879..215d80fb33ed 100644
--- a/vcl/osx/vclnsapp.mm
+++ b/vcl/osx/vclnsapp.mm
@@ -109,24 +109,49 @@
             [static_cast<SalFrameWindow*>(pKeyWin) endExtTextInput];
 
             AquaSalFrame* pFrame = [static_cast<SalFrameWindow*>(pKeyWin) 
getSalFrame];
-            unsigned int nModMask = ([pEvent modifierFlags] & 
(NSEventModifierFlagShift|NSEventModifierFlagControl|NSEventModifierFlagOption|NSEventModifierFlagCommand));
+
+            // Related tdf#162010: match against -[NSEvent characters]
+            // When using some non-Western European keyboard layouts, the
+            // event's "characters ignoring modifiers" will be set to the
+            // original Unicode character instead of the resolved key
+            // equivalent character so match against the -[NSEvent characters]
+            // instead.
+            NSEventModifierFlags nModMask = ([pEvent modifierFlags] & 
(NSEventModifierFlagShift|NSEventModifierFlagControl|NSEventModifierFlagOption|NSEventModifierFlagCommand));
+
+            // Note: when pressing Command-Option keys, some non-Western
+            // keyboards will set the "characters ignoring modifiers"
+            // property  to the key shortcut character instead of setting
+            // the "characters property. So check for both cases.
+            NSString *pCharacters = [pEvent characters];
+            NSString *pCharactersIgnoringModifiers = [pEvent 
charactersIgnoringModifiers];
+
             /*
              * #i98949# - Cmd-M miniaturize window, Cmd-Option-M miniaturize 
all windows
              */
-            if( [[pEvent charactersIgnoringModifiers] isEqualToString: @"m"] )
+            if( [pCharacters isEqualToString: @"m"] || 
[pCharactersIgnoringModifiers isEqualToString: @"m"] )
             {
                 if ( nModMask == NSEventModifierFlagCommand && 
([pFrame->getNSWindow() styleMask] & NSWindowStyleMaskMiniaturizable) )
                 {
                     [pFrame->getNSWindow() performMiniaturize: nil];
                     return;
                 }
-
-                if ( nModMask == ( NSEventModifierFlagCommand | 
NSEventModifierFlagOption ) )
+                else if ( nModMask == ( NSEventModifierFlagCommand | 
NSEventModifierFlagOption ) )
                 {
                     [NSApp miniaturizeAll: nil];
                     return;
                 }
             }
+            // tdf#162190 handle Command-w
+            // On macOS, Command-w should attempt to close the key window.
+            // TODO: Command-Option-w should attempt to close all windows.
+            else if( [pCharacters isEqualToString: @"w"] || 
[pCharactersIgnoringModifiers isEqualToString: @"w"] )
+            {
+                if ( nModMask == NSEventModifierFlagCommand && 
([pFrame->getNSWindow() styleMask] & NSWindowStyleMaskClosable ) )
+                {
+                    [pFrame->getNSWindow() performClose: nil];
+                    return;
+                }
+            }
 
             // get information whether the event was handled; keyDown returns 
nothing
             GetSalData()->maKeyEventAnswer[ pEvent ] = false;

Reply via email to