fix: Menu accelerators not working Unity (#15181)
This commit is contained in:
parent
7283b78aa2
commit
5cb50b0e33
3 changed files with 18 additions and 11 deletions
|
@ -873,14 +873,17 @@ void NativeWindowViews::SetFocusable(bool focusable) {
|
||||||
|
|
||||||
void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
if (menu_model == nullptr)
|
if (menu_model == nullptr) {
|
||||||
global_menu_bar_.reset();
|
global_menu_bar_.reset();
|
||||||
|
root_view_->UnregisterAcceleratorsWithFocusManager();
|
||||||
|
}
|
||||||
|
|
||||||
if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
|
if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
|
||||||
global_menu_bar_.reset(new GlobalMenuBarX11(this));
|
global_menu_bar_.reset(new GlobalMenuBarX11(this));
|
||||||
|
|
||||||
// Use global application menu bar when possible.
|
// Use global application menu bar when possible.
|
||||||
if (global_menu_bar_ && global_menu_bar_->IsServerStarted()) {
|
if (global_menu_bar_ && global_menu_bar_->IsServerStarted()) {
|
||||||
|
root_view_->RegisterAcceleratorsWithFocusManager(menu_model);
|
||||||
global_menu_bar_->SetMenu(menu_model);
|
global_menu_bar_->SetMenu(menu_model);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,15 +44,14 @@ RootView::~RootView() {}
|
||||||
void RootView::SetMenu(AtomMenuModel* menu_model) {
|
void RootView::SetMenu(AtomMenuModel* menu_model) {
|
||||||
if (menu_model == nullptr) {
|
if (menu_model == nullptr) {
|
||||||
// Remove accelerators
|
// Remove accelerators
|
||||||
accelerator_table_.clear();
|
UnregisterAcceleratorsWithFocusManager();
|
||||||
GetFocusManager()->UnregisterAccelerators(this);
|
|
||||||
// and menu bar.
|
// and menu bar.
|
||||||
SetMenuBarVisibility(false);
|
SetMenuBarVisibility(false);
|
||||||
menu_bar_.reset();
|
menu_bar_.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterAccelerators(menu_model);
|
RegisterAcceleratorsWithFocusManager(menu_model);
|
||||||
|
|
||||||
// Do not show menu bar in frameless window.
|
// Do not show menu bar in frameless window.
|
||||||
if (!window_->has_frame())
|
if (!window_->has_frame())
|
||||||
|
@ -178,12 +177,11 @@ bool RootView::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
||||||
accelerator);
|
accelerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
void RootView::RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model) {
|
||||||
// Clear previous accelerators.
|
// Clear previous accelerators.
|
||||||
views::FocusManager* focus_manager = GetFocusManager();
|
UnregisterAcceleratorsWithFocusManager();
|
||||||
accelerator_table_.clear();
|
|
||||||
focus_manager->UnregisterAccelerators(this);
|
|
||||||
|
|
||||||
|
views::FocusManager* focus_manager = GetFocusManager();
|
||||||
// Register accelerators with focus manager.
|
// Register accelerators with focus manager.
|
||||||
accelerator_util::GenerateAcceleratorTable(&accelerator_table_, menu_model);
|
accelerator_util::GenerateAcceleratorTable(&accelerator_table_, menu_model);
|
||||||
for (const auto& iter : accelerator_table_) {
|
for (const auto& iter : accelerator_table_) {
|
||||||
|
@ -192,4 +190,10 @@ void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RootView::UnregisterAcceleratorsWithFocusManager() {
|
||||||
|
views::FocusManager* focus_manager = GetFocusManager();
|
||||||
|
accelerator_table_.clear();
|
||||||
|
focus_manager->UnregisterAccelerators(this);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -34,6 +34,9 @@ class RootView : public views::View {
|
||||||
bool IsMenuBarVisible() const;
|
bool IsMenuBarVisible() const;
|
||||||
void HandleKeyEvent(const content::NativeWebKeyboardEvent& event);
|
void HandleKeyEvent(const content::NativeWebKeyboardEvent& event);
|
||||||
void ResetAltState();
|
void ResetAltState();
|
||||||
|
// Register/Unregister accelerators supported by the menu model.
|
||||||
|
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
|
||||||
|
void UnregisterAcceleratorsWithFocusManager();
|
||||||
|
|
||||||
// views::View:
|
// views::View:
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
@ -42,9 +45,6 @@ class RootView : public views::View {
|
||||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Register accelerators supported by the menu model.
|
|
||||||
void RegisterAccelerators(AtomMenuModel* menu_model);
|
|
||||||
|
|
||||||
// Parent window, weak ref.
|
// Parent window, weak ref.
|
||||||
NativeWindow* window_;
|
NativeWindow* window_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue