summaryrefslogtreecommitdiffstats
path: root/ash/monitor
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 01:04:24 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 01:04:24 +0000
commite050ef1444006c87364b8bede8a0df8e463525dc (patch)
tree204fe03296b7e8c8918945768fefcf5cd5ead7be /ash/monitor
parent4a4c337c42676cdb024fd943a7c97400abe58cad (diff)
downloadchromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.zip
chromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.tar.gz
chromium_src-e050ef1444006c87364b8bede8a0df8e463525dc.tar.bz2
* MultiMonitorManager creates and manages mutliple monitor instance
* MonitorContrler controls root window <-> monitor mapping and resize/reposition root window to match monitor configuration. * Moved use_fullscreen_host_window to MonitorManager * Moved compositor initialize/terminate to Env as there can be more than one root window. BUG=115510 TEST=none Review URL: https://chromiumcodereview.appspot.com/9701098 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/monitor')
-rw-r--r--ash/monitor/monitor_controller.cc75
-rw-r--r--ash/monitor/monitor_controller.h43
-rw-r--r--ash/monitor/multi_monitor_manager.cc121
-rw-r--r--ash/monitor/multi_monitor_manager.h57
-rw-r--r--ash/monitor/secondary_monitor_view.cc45
-rw-r--r--ash/monitor/secondary_monitor_view.h25
6 files changed, 366 insertions, 0 deletions
diff --git a/ash/monitor/monitor_controller.cc b/ash/monitor/monitor_controller.cc
new file mode 100644
index 0000000..072aac5
--- /dev/null
+++ b/ash/monitor/monitor_controller.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/monitor/monitor_controller.h"
+
+#include "ash/monitor/multi_monitor_manager.h"
+#include "ash/monitor/secondary_monitor_view.h"
+#include "ash/shell.h"
+#include "ash/wm/base_layout_manager.h"
+#include "ash/wm/root_window_layout_manager.h"
+#include "base/stl_util.h"
+#include "ui/aura/env.h"
+#include "ui/aura/monitor.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+void SetupAsSecondaryMonitor(aura::RootWindow* root) {
+ root->SetLayoutManager(new internal::RootWindowLayoutManager(root));
+ aura::Window* container = new aura::Window(NULL);
+ container->SetName("SecondaryMonitorContainer");
+ container->Init(ui::Layer::LAYER_NOT_DRAWN);
+ root->AddChild(container);
+ container->Show();
+ container->SetLayoutManager(new internal::BaseLayoutManager(root));
+ CreateSecondaryMonitorWidget(container);
+ root->ShowRootWindow();
+}
+
+} // namespace
+
+MonitorController::MonitorController() {
+ aura::Env::GetInstance()->monitor_manager()->AddObserver(this);
+ Init();
+}
+
+MonitorController::~MonitorController() {
+ aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this);
+ // Remove the root first.
+ aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey);
+ root_windows_.erase(monitor);
+ STLDeleteContainerPairSecondPointers(
+ root_windows_.begin(), root_windows_.end());
+}
+
+void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) {
+ if (aura::MonitorManager::use_fullscreen_host_window())
+ root_windows_[monitor]->SetHostBounds(monitor->bounds());
+}
+
+void MonitorController::Init() {
+ aura::MonitorManager* monitor_manager =
+ aura::Env::GetInstance()->monitor_manager();
+ for (size_t i = 0; i < monitor_manager->GetNumMonitors(); ++i) {
+ aura::Monitor* monitor = monitor_manager->GetMonitorAt(i);
+ const aura::Monitor* key = monitor;
+ if (i == 0) {
+ // Primary monitor
+ root_windows_[key] = Shell::GetRootWindow();
+ } else {
+ aura::RootWindow* root =
+ monitor_manager->CreateRootWindowForMonitor(monitor);
+ root_windows_[key] = root;
+ SetupAsSecondaryMonitor(root);
+ }
+ }
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/monitor/monitor_controller.h b/ash/monitor/monitor_controller.h
new file mode 100644
index 0000000..52df5f7
--- /dev/null
+++ b/ash/monitor/monitor_controller.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_MONITOR_MONITOR_CONTROLLER_H_
+#define ASH_MONITOR_MONITOR_CONTROLLER_H_
+#pragma once
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/aura/monitor_manager.h"
+
+namespace aura {
+class RootWindow;
+}
+
+namespace ash {
+namespace internal {
+
+// MonitorController creates and maintains RootWindows for each
+// attached monitor, keeping them in sync with monitor configuration changes.
+class MonitorController : public aura::MonitorObserver {
+ public:
+ MonitorController();
+ virtual ~MonitorController();
+
+ // aura::MonitorObserver overrides:
+ virtual void OnMonitorBoundsChanged(const aura::Monitor* monitor) OVERRIDE;
+
+ private:
+ void Init();
+
+ std::map<const aura::Monitor*, aura::RootWindow*> root_windows_;
+
+ DISALLOW_COPY_AND_ASSIGN(MonitorController);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_MONITOR_MONITOR_CONTROLLER_H_
diff --git a/ash/monitor/multi_monitor_manager.cc b/ash/monitor/multi_monitor_manager.cc
new file mode 100644
index 0000000..a6a30f9
--- /dev/null
+++ b/ash/monitor/multi_monitor_manager.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/monitor/multi_monitor_manager.h"
+
+#include <string>
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/stl_util.h"
+#include "base/string_split.h"
+#include "ui/aura/aura_switches.h"
+#include "ui/aura/env.h"
+#include "ui/aura/monitor.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/root_window_host.h"
+#include "ui/gfx/rect.h"
+#include "ui/aura/window_property.h"
+
+DECLARE_WINDOW_PROPERTY_TYPE(aura::Monitor*);
+
+namespace ash {
+namespace internal {
+
+DEFINE_WINDOW_PROPERTY_KEY(aura::Monitor*, kMonitorKey, NULL);
+
+using std::string;
+using std::vector;
+using aura::Monitor;
+using aura::RootWindow;
+using aura::Window;
+
+MultiMonitorManager::MultiMonitorManager() {
+ Init();
+}
+
+MultiMonitorManager::~MultiMonitorManager() {
+ STLDeleteContainerPointers(monitors_.begin(), monitors_.end());
+}
+
+void MultiMonitorManager::OnNativeMonitorResized(const gfx::Size& size) {
+ // TODO(oshima): Update monitors using xrandr and notify observers
+ // Just update the primary for now.
+ if (use_fullscreen_host_window()) {
+ Monitor* monitor =
+ aura::Env::GetInstance()->monitor_manager()->GetMonitorAt(0);
+ monitor->set_size(size);
+ NotifyBoundsChanged(monitor);
+ }
+}
+
+RootWindow* MultiMonitorManager::CreateRootWindowForMonitor(
+ Monitor* monitor) {
+ RootWindow* root_window = new RootWindow(monitor->bounds());
+ root_window->AddObserver(this);
+ root_window->SetProperty(kMonitorKey, monitor);
+ return root_window;
+}
+
+const Monitor* MultiMonitorManager::GetMonitorNearestWindow(
+ const Window* window) const {
+ if (!window) {
+ MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this);
+ return manager->GetMonitorAt(0);
+ }
+ const RootWindow* root = window->GetRootWindow();
+ return root ? root->GetProperty(kMonitorKey) : NULL;
+}
+
+const Monitor* MultiMonitorManager::GetMonitorNearestPoint(
+ const gfx::Point& point) const {
+ // TODO(oshima): For m19, mouse is constrained within
+ // the primary window.
+ MultiMonitorManager* manager = const_cast<MultiMonitorManager*>(this);
+ return manager->GetMonitorAt(0);
+}
+
+Monitor* MultiMonitorManager::GetMonitorAt(size_t index) {
+ return index < monitors_.size() ? monitors_[index] : NULL;
+}
+
+size_t MultiMonitorManager::GetNumMonitors() const {
+ return monitors_.size();
+}
+
+Monitor* MultiMonitorManager::GetMonitorNearestWindow(const Window* window) {
+ const MonitorManager* manager = this;
+ return const_cast<Monitor*>(manager->GetMonitorNearestWindow(window));
+}
+
+void MultiMonitorManager::OnWindowBoundsChanged(
+ Window* window, const gfx::Rect& bounds) {
+ if (!use_fullscreen_host_window()) {
+ Monitor* monitor = window->GetProperty(kMonitorKey);
+ monitor->set_size(bounds.size());
+ NotifyBoundsChanged(monitor);
+ }
+}
+
+void MultiMonitorManager::OnWindowDestroying(Window* window) {
+ Monitor* monitor = window->GetProperty(kMonitorKey);
+ monitors_.erase(std::find(monitors_.begin(), monitors_.end(), monitor));
+ delete monitor;
+}
+
+void MultiMonitorManager::Init() {
+ const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kAuraHostWindowSize);
+ vector<string> parts;
+ base::SplitString(size_str, ',', &parts);
+ for (vector<string>::const_iterator iter = parts.begin();
+ iter != parts.end(); ++iter) {
+ monitors_.push_back(CreateMonitorFromSpec(*iter));
+ }
+ if (monitors_.empty())
+ monitors_.push_back(CreateMonitorFromSpec("" /* default */));
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/monitor/multi_monitor_manager.h b/ash/monitor/multi_monitor_manager.h
new file mode 100644
index 0000000..609f931
--- /dev/null
+++ b/ash/monitor/multi_monitor_manager.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_MONITOR_MULTI_MONITOR_MANAGER_H_
+#define ASH_MONITOR_MULTI_MONITOR_MANAGER_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/monitor_manager.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_observer.h"
+
+namespace ash {
+namespace internal {
+
+class MultiMonitorManager : public aura::MonitorManager,
+ public aura::WindowObserver {
+ public:
+ MultiMonitorManager();
+ virtual ~MultiMonitorManager();
+
+ // MonitorManager overrides:
+ virtual void OnNativeMonitorResized(const gfx::Size& size) OVERRIDE;
+ virtual aura::RootWindow* CreateRootWindowForMonitor(
+ aura::Monitor* monitor) OVERRIDE;
+ virtual const aura::Monitor* GetMonitorNearestWindow(
+ const aura::Window* window) const OVERRIDE;
+ virtual const aura::Monitor* GetMonitorNearestPoint(
+ const gfx::Point& point) const OVERRIDE;
+ virtual aura::Monitor* GetMonitorAt(size_t index) OVERRIDE;
+ virtual size_t GetNumMonitors() const OVERRIDE;
+ virtual aura::Monitor* GetMonitorNearestWindow(
+ const aura::Window* window) OVERRIDE;
+
+ // WindowObserver overrides:
+ virtual void OnWindowBoundsChanged(aura::Window* window,
+ const gfx::Rect& bounds) OVERRIDE;
+ virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
+
+ private:
+ typedef std::vector<aura::Monitor*> Monitors;
+
+ void Init();
+
+ Monitors monitors_;
+
+ DISALLOW_COPY_AND_ASSIGN(MultiMonitorManager);
+};
+
+extern const aura::WindowProperty<aura::Monitor*>* const kMonitorKey;
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_MONITOR_MULTI_MONITOR_MANAGER_H_
diff --git a/ash/monitor/secondary_monitor_view.cc b/ash/monitor/secondary_monitor_view.cc
new file mode 100644
index 0000000..a570932
--- /dev/null
+++ b/ash/monitor/secondary_monitor_view.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/monitor/secondary_monitor_view.h"
+
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/aura/window.h"
+#include "ui/views/view.h"
+#include "ui/views/background.h"
+#include "ui/views/widget/widget_delegate.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace {
+
+const SkColor kBackground = SkColorSetRGB(0x33, 0x33, 0x33);
+
+// A view to be displayed on secondary monitor.
+class SecondaryMonitorView : public views::WidgetDelegateView {
+ public:
+ SecondaryMonitorView() {
+ set_background(views::Background::CreateSolidBackground(kBackground));
+ }
+ ~SecondaryMonitorView() {
+ }
+};
+
+} // namespace
+
+views::Widget* CreateSecondaryMonitorWidget(aura::Window* parent) {
+ views::Widget* desktop_widget = new views::Widget;
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ SecondaryMonitorView* view = new SecondaryMonitorView();
+ params.delegate = view;
+ params.parent = parent;
+ desktop_widget->Init(params);
+ desktop_widget->SetContentsView(view);
+ desktop_widget->Show();
+ desktop_widget->GetNativeView()->SetName("SecondaryMonitor");
+ return desktop_widget;
+}
+
+} // namespace ash
diff --git a/ash/monitor/secondary_monitor_view.h b/ash/monitor/secondary_monitor_view.h
new file mode 100644
index 0000000..cca03d2
--- /dev/null
+++ b/ash/monitor/secondary_monitor_view.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_MONITOR_SECONDARY_MONITOR_VIEW_H_
+#define ASH_MONITOR_SECONDARY_MONITOR_VIEW_H_
+#pragma once
+
+namespace aura {
+class Window;
+}
+
+namespace views {
+class Widget;
+}
+
+namespace ash {
+
+// Creates the widget that hosts the static message displayed on the
+// secondary monitor.
+views::Widget* CreateSecondaryMonitorWidget(aura::Window* parent);
+
+} // namespace ash
+
+#endif // ASH_MONITOR_SECONDARY_MONITOR_VIEW_H_