1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_layout_store.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "ui/gfx/display.h"
17 DisplayLayoutStore::DisplayLayoutStore() {
18 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
19 if (command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
)) {
20 std::string value
= command_line
->GetSwitchValueASCII(
21 switches::kAshSecondaryDisplayLayout
);
24 if (sscanf(value
.c_str(), "%c,%d", &layout
, &offset
) == 2) {
26 default_display_layout_
.position
= DisplayLayout::TOP
;
27 else if (layout
== 'b')
28 default_display_layout_
.position
= DisplayLayout::BOTTOM
;
29 else if (layout
== 'r')
30 default_display_layout_
.position
= DisplayLayout::RIGHT
;
31 else if (layout
== 'l')
32 default_display_layout_
.position
= DisplayLayout::LEFT
;
33 default_display_layout_
.offset
= offset
;
38 DisplayLayoutStore::~DisplayLayoutStore() {
41 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout
& layout
) {
42 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
43 if (!command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
))
44 default_display_layout_
= layout
;
47 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair(
50 const DisplayLayout
& layout
) {
51 paired_layouts_
[std::make_pair(id1
, id2
)] = layout
;
54 DisplayLayout
DisplayLayoutStore::GetRegisteredDisplayLayout(
55 const DisplayIdPair
& pair
) {
56 std::map
<DisplayIdPair
, DisplayLayout
>::const_iterator iter
=
57 paired_layouts_
.find(pair
);
59 iter
!= paired_layouts_
.end() ? iter
->second
: CreateDisplayLayout(pair
);
62 DisplayLayout
DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair(
63 const DisplayIdPair
& pair
) {
64 DisplayLayout layout
= GetRegisteredDisplayLayout(pair
);
65 DCHECK_NE(layout
.primary_id
, gfx::Display::kInvalidDisplayID
);
66 // Invert if the primary was swapped. If mirrored, first is always
68 return (layout
.primary_id
== gfx::Display::kInvalidDisplayID
||
69 pair
.first
== layout
.primary_id
) ? layout
: layout
.Invert();
72 void DisplayLayoutStore::UpdateMultiDisplayState(const DisplayIdPair
& pair
,
74 bool default_unified
) {
75 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
76 CreateDisplayLayout(pair
);
77 paired_layouts_
[pair
].mirrored
= mirrored
;
78 paired_layouts_
[pair
].default_unified
= default_unified
;
81 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair
& pair
,
83 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
84 CreateDisplayLayout(pair
);
85 paired_layouts_
[pair
].primary_id
= display_id
;
88 DisplayLayout
DisplayLayoutStore::CreateDisplayLayout(
89 const DisplayIdPair
& pair
) {
90 DisplayLayout layout
= default_display_layout_
;
91 layout
.default_unified
=
92 Shell::GetInstance()->display_manager()->default_multi_display_mode() ==
93 DisplayManager::UNIFIED
;
94 layout
.primary_id
= pair
.first
;
95 paired_layouts_
[pair
] = layout
;