diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index f5c21bed74e..5cb005a92ca 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -37,6 +37,7 @@ #include "atom/browser/ui/views/global_menu_bar_x11.h" #include "atom/browser/ui/views/frameless_view.h" #include "atom/browser/ui/views/native_frame_view.h" +#include "atom/browser/ui/x/event_disabler.h" #include "atom/browser/ui/x/window_state_watcher.h" #include "atom/browser/ui/x/x_window_utils.h" #include "base/strings/string_util.h" @@ -385,6 +386,10 @@ void NativeWindowViews::Disable() { #if defined(OS_WIN) ::EnableWindow(GetAcceleratedWidget(), FALSE); #elif defined(USE_X11) + event_disabler_.reset(new EventDisabler); + views::DesktopWindowTreeHostX11* tree_host = + views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget()); + tree_host->AddEventRewriter(event_disabler_.get()); #endif } @@ -392,14 +397,18 @@ void NativeWindowViews::Enable() { #if defined(OS_WIN) ::EnableWindow(GetAcceleratedWidget(), TRUE); #elif defined(USE_X11) + views::DesktopWindowTreeHostX11* tree_host = + views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget()); + tree_host->RemoveEventRewriter(event_disabler_.get()); + event_disabler_.reset(); #endif } bool NativeWindowViews::IsEnabled() { #if defined(OS_WIN) return ::IsWindowEnabled(GetAcceleratedWidget()); -#else - return false; +#elif defined(USE_X11) + return !event_disabler_.get(); #endif } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index b38572d9d2a..bdc2d36497b 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -32,6 +32,8 @@ class WindowStateWatcher; #if defined(OS_WIN) class AtomDesktopWindowTreeHostWin; +#elif defined(USE_X11) +class EventDisabler; #endif class NativeWindowViews : public NativeWindow, @@ -193,6 +195,9 @@ class NativeWindowViews : public NativeWindow, // Handles window state events. std::unique_ptr window_state_watcher_; + // To disable the mouse events. + std::unique_ptr event_disabler_; + // The "resizable" flag on Linux is implemented by setting size constraints, // we need to make sure size constraints are restored when window becomes // resizable again. diff --git a/atom/browser/ui/x/event_disabler.cc b/atom/browser/ui/x/event_disabler.cc new file mode 100644 index 00000000000..6d0e4cfeb04 --- /dev/null +++ b/atom/browser/ui/x/event_disabler.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/ui/x/event_disabler.h" + +namespace atom { + +EventDisabler::EventDisabler() { +} + +EventDisabler::~EventDisabler() { +} + +ui::EventRewriteStatus EventDisabler::RewriteEvent( + const ui::Event& event, + std::unique_ptr* rewritten_event) { + return ui::EVENT_REWRITE_DISCARD; +} + +ui::EventRewriteStatus EventDisabler::NextDispatchEvent( + const ui::Event& last_event, + std::unique_ptr* new_event) { + return ui::EVENT_REWRITE_CONTINUE; +} + +} // namespace atom diff --git a/atom/browser/ui/x/event_disabler.h b/atom/browser/ui/x/event_disabler.h new file mode 100644 index 00000000000..9a6645bcdca --- /dev/null +++ b/atom/browser/ui/x/event_disabler.h @@ -0,0 +1,32 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_UI_X_EVENT_DISABLER_H_ +#define ATOM_BROWSER_UI_X_EVENT_DISABLER_H_ + +#include "base/macros.h" +#include "ui/events/event_rewriter.h" + +namespace atom { + +class EventDisabler : public ui::EventRewriter { + public: + EventDisabler(); + ~EventDisabler() override; + + // ui::EventRewriter: + ui::EventRewriteStatus RewriteEvent( + const ui::Event& event, + std::unique_ptr* rewritten_event) override; + ui::EventRewriteStatus NextDispatchEvent( + const ui::Event& last_event, + std::unique_ptr* new_event) override; + + private: + DISALLOW_COPY_AND_ASSIGN(EventDisabler); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_UI_X_EVENT_DISABLER_H_ diff --git a/filenames.gypi b/filenames.gypi index 87ff5dc9813..af7080821b4 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -286,6 +286,8 @@ 'atom/browser/ui/win/notify_icon.h', 'atom/browser/ui/win/taskbar_host.cc', 'atom/browser/ui/win/taskbar_host.h', + 'atom/browser/ui/x/event_disabler.cc', + 'atom/browser/ui/x/event_disabler.h', 'atom/browser/ui/x/window_state_watcher.cc', 'atom/browser/ui/x/window_state_watcher.h', 'atom/browser/ui/x/x_window_utils.cc',