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/display/display_util.h"
11 #include "ash/shell.h"
12 #include "base/command_line.h"
13 #include "base/logging.h"
14 #include "ui/gfx/display.h"
18 DisplayLayoutStore::DisplayLayoutStore() {
19 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
20 if (command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
)) {
21 std::string value
= command_line
->GetSwitchValueASCII(
22 switches::kAshSecondaryDisplayLayout
);
25 if (sscanf(value
.c_str(), "%c,%d", &layout
, &offset
) == 2) {
27 default_display_layout_
.position
= DisplayLayout::TOP
;
28 else if (layout
== 'b')
29 default_display_layout_
.position
= DisplayLayout::BOTTOM
;
30 else if (layout
== 'r')
31 default_display_layout_
.position
= DisplayLayout::RIGHT
;
32 else if (layout
== 'l')
33 default_display_layout_
.position
= DisplayLayout::LEFT
;
34 default_display_layout_
.offset
= offset
;
39 DisplayLayoutStore::~DisplayLayoutStore() {
42 void DisplayLayoutStore::SetDefaultDisplayLayout(const DisplayLayout
& layout
) {
43 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
44 if (!command_line
->HasSwitch(switches::kAshSecondaryDisplayLayout
))
45 default_display_layout_
= layout
;
48 void DisplayLayoutStore::RegisterLayoutForDisplayIdPair(
51 const DisplayLayout
& layout
) {
52 auto key
= CreateDisplayIdPair(id1
, id2
);
53 paired_layouts_
[key
] = layout
;
56 DisplayLayout
DisplayLayoutStore::GetRegisteredDisplayLayout(
57 const DisplayIdPair
& pair
) {
58 std::map
<DisplayIdPair
, DisplayLayout
>::const_iterator iter
=
59 paired_layouts_
.find(pair
);
61 iter
!= paired_layouts_
.end() ? iter
->second
: CreateDisplayLayout(pair
);
64 DisplayLayout
DisplayLayoutStore::ComputeDisplayLayoutForDisplayIdPair(
65 const DisplayIdPair
& pair
) {
66 DisplayLayout layout
= GetRegisteredDisplayLayout(pair
);
67 DCHECK_NE(layout
.primary_id
, gfx::Display::kInvalidDisplayID
);
68 // Invert if the primary was swapped. If mirrored, first is always
70 return (layout
.primary_id
== gfx::Display::kInvalidDisplayID
||
71 pair
.first
== layout
.primary_id
) ? layout
: layout
.Invert();
74 void DisplayLayoutStore::UpdateMultiDisplayState(const DisplayIdPair
& pair
,
76 bool default_unified
) {
77 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
78 CreateDisplayLayout(pair
);
79 paired_layouts_
[pair
].mirrored
= mirrored
;
80 paired_layouts_
[pair
].default_unified
= default_unified
;
83 void DisplayLayoutStore::UpdatePrimaryDisplayId(const DisplayIdPair
& pair
,
85 if (paired_layouts_
.find(pair
) == paired_layouts_
.end())
86 CreateDisplayLayout(pair
);
87 paired_layouts_
[pair
].primary_id
= display_id
;
90 DisplayLayout
DisplayLayoutStore::CreateDisplayLayout(
91 const DisplayIdPair
& pair
) {
92 DisplayLayout layout
= default_display_layout_
;
93 layout
.primary_id
= pair
.first
;
94 paired_layouts_
[pair
] = layout
;