Skip to content

Redispatch events to handle native OSX shortcuts - #6068

Merged
zcbenz merged 13 commits into
masterfrom
redispatch-events
Jun 19, 2016
Merged

zcbenz merged 13 commits into
masterfrom
redispatch-events

Conversation

@kevinsawicki

@kevinsawicki kevinsawicki commented Jun 15, 2016 •

Copy link
Copy Markdown
Contributor

This pull request pulls in code from command_dispatcher.mm that redispatches events in an attempt to correctly handle native keyboard shortcuts like Ctrl+F2 and Cmd-~ on Mac OS X.

Tested Scenarios

  • Menu-based shortcuts like Cmd-R, Cmd-A, Cmd-Alt-I.
  • Native shortcuts like Cmd-~ and Ctrl-F2
  • Calling preventDefault() on a keydown event to disable something native like Cmd-A to select all
  • Typing and keybindings in <input> elements
  • Docked devtools window
  • Undocked devtools window
  • Others?

If anyone is able to test this branch for their app and verify menus and shortcuts still work as expected, that would be really helpful. /cc @electron/maintainers

Closes #5246
Closes #6016
Depends on electron-archive/brightray#227

Related reading:

https://www.chromium.org/developers/os-x-keyboard-handling
nwjs/nw.js@6658fbb

@kevinsawicki

Copy link
Copy Markdown
Contributor Author

@zcbenz do you think it makes more sense to try and use the Chromium classes directly here like CommandDispatcher, CommandDispatcherTarget, and CommandDispatcherDelegate?

}
}
if (event.os_event.window) {
AtomNSWindow* native_window = static_cast<AtomNSWindow*>(event.os_event.window);

@zcbenz zcbenz Jun 16, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For undocked devtools window, it is not an AtomNSWindow, we might need to add same code in brightray.

Also I haven't tried, but I think we should be able to just call [window redispatchKeyEvent:] without type conversion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I haven't tried, but I think we should be able to just call [window redispatchKeyEvent:] without type conversion.

Yeah, when I try that I get the following compiler error:

error: 'NSWindow' may not respond to 'redispatchKeyEvent:' [-Werror]

@zcbenz

zcbenz commented Jun 16, 2016

Copy link
Copy Markdown
Contributor

@zcbenz do you think it makes more sense to try and use the Chromium classes directly here like CommandDispatcher, CommandDispatcherTarget, and CommandDispatcherDelegate?

I think current implementation is perfect.

}
}
NSWindow* window = event.os_event.window;
if (window && [window isKindOfClass:[AtomNSWindow class]]) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zcbenz Switched it to use isKindOfClass instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinsawicki The devtools window also needs the same handling code, otherwise it won't respond to cmd+~, steps to reproduce:

  1. Open devtools window in detached state
  2. Press cmd+~ in it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, didn't realize that, thanks 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zcbenz I opened up a small brightray pull request that applies the minimal event redispatch to the UnderlayOpenGLHostingWindow used there for the devtools window.

Does that approach make sense?

electron-archive/brightray#227

@kevinsawicki

kevinsawicki commented Jun 17, 2016 •

Copy link
Copy Markdown
Contributor Author

@zcbenz I reworked this pull request to add an EventDispatchingWindow to brightray that gets extended by AtomNSWindow and used by the devtools undocked window as well.

EventDispatchingWindow does extend UnderlayOpenGLHostingWindow which means AtomNSWindow now extends UnderlayOpenGLHostingWindow (which extends NSWindow) instead of NSWindow directly.

This seems okay since UnderlayOpenGLHostingWindow is pretty simple: https://cs.chromium.org/chromium/src/ui/base/cocoa/underlay_opengl_hosting_window.mm

Let me know if you have concerns with this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants