linux: Implement win.disable/enable/isEnabled() API

This commit is contained in:
Cheng Zhao 2016-06-19 17:35:56 +09:00
parent 074903ca33
commit 9aa7291627
5 changed files with 77 additions and 2 deletions

View file

@ -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
}

View file

@ -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<WindowStateWatcher> window_state_watcher_;
// To disable the mouse events.
std::unique_ptr<EventDisabler> 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.

View file

@ -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<ui::Event>* rewritten_event) {
return ui::EVENT_REWRITE_DISCARD;
}
ui::EventRewriteStatus EventDisabler::NextDispatchEvent(
const ui::Event& last_event,
std::unique_ptr<ui::Event>* new_event) {
return ui::EVENT_REWRITE_CONTINUE;
}
} // namespace atom

View file

@ -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<ui::Event>* rewritten_event) override;
ui::EventRewriteStatus NextDispatchEvent(
const ui::Event& last_event,
std::unique_ptr<ui::Event>* new_event) override;
private:
DISALLOW_COPY_AND_ASSIGN(EventDisabler);
};
} // namespace atom
#endif // ATOM_BROWSER_UI_X_EVENT_DISABLER_H_

View file

@ -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',