Skip to content

Commit

Permalink
fix: Fn+F fullscreen transitioning on macOS (#37822)
Browse files Browse the repository at this point in the history
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Apr 5, 2023
1 parent f5cb867 commit 922581a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions shell/browser/api/electron_api_web_contents_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
#include "shell/browser/web_contents_preferences.h"
#include "ui/base/cocoa/command_dispatcher.h"
#include "ui/base/cocoa/nsmenu_additions.h"
#include "ui/base/cocoa/nsmenuitem_additions.h"
#include "ui/events/keycodes/keyboard_codes.h"

#import <Cocoa/Cocoa.h>
Expand Down Expand Up @@ -52,9 +54,26 @@ - (void)redispatchKeyEvent:(NSEvent*)event;
return false;

// Send the event to the menu before sending it to the window
if (event.os_event.type == NSEventTypeKeyDown &&
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
return true;
if (event.os_event.type == NSEventTypeKeyDown) {
// If the keyboard event is a system shortcut, it's already sent to the
// NSMenu instance in
// content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm via
// keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv. If we let the
// NSMenu handle it here as well, it'll be sent twice with unexpected side
// effects.
bool is_a_keyboard_shortcut_event =
[[NSApp mainMenu] cr_menuItemForKeyEquivalentEvent:event.os_event] !=
nil;
bool is_a_system_shortcut_event =
is_a_keyboard_shortcut_event &&
(ui::cocoa::ModifierMaskForKeyEvent(event.os_event) &
NSEventModifierFlagFunction) != 0;
if (is_a_system_shortcut_event)
return false;

if ([[NSApp mainMenu] performKeyEquivalent:event.os_event])
return true;
}

// Let the window redispatch the OS event
if (event.os_event.window &&
Expand Down

0 comments on commit 922581a

Please sign in to comment.