Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: ash/display/window_tree_host_manager.cc

Issue 2518233002: Enable setting primary display for 3+ displays (Closed)
Patch Set: Oshima's comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/display/window_tree_host_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/window_tree_host_manager.h" 5 #include "ash/display/window_tree_host_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ui::CursorController::GetInstance()->ClearCursorConfigForWindow( 156 ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
157 host->GetAcceleratedWidget()); 157 host->GetAcceleratedWidget());
158 #endif 158 #endif
159 } 159 }
160 160
161 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { 161 aura::Window* GetWindow(AshWindowTreeHost* ash_host) {
162 CHECK(ash_host->AsWindowTreeHost()); 162 CHECK(ash_host->AsWindowTreeHost());
163 return ash_host->AsWindowTreeHost()->window(); 163 return ash_host->AsWindowTreeHost()->window();
164 } 164 }
165 165
166 void SwapRecursive(
167 const std::map<int64_t, display::DisplayPlacement*>& id_to_placement,
168 int64_t current_primary_id,
169 int64_t display_id) {
170 if (display_id == current_primary_id)
171 return;
172
173 DCHECK(id_to_placement.count(display_id));
174 display::DisplayPlacement* placement = id_to_placement.at(display_id);
175 DCHECK(placement);
176 SwapRecursive(id_to_placement, current_primary_id,
177 placement->parent_display_id);
178 placement->Swap();
179 }
180
166 } // namespace 181 } // namespace
167 182
168 // A utility class to store/restore focused/active window 183 // A utility class to store/restore focused/active window
169 // when the display configuration has changed. 184 // when the display configuration has changed.
170 class FocusActivationStore { 185 class FocusActivationStore {
171 public: 186 public:
172 FocusActivationStore() 187 FocusActivationStore()
173 : activation_client_(nullptr), 188 : activation_client_(nullptr),
174 capture_client_(nullptr), 189 capture_client_(nullptr),
175 focus_client_(nullptr), 190 focus_client_(nullptr),
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return controllers; 408 return controllers;
394 } 409 }
395 410
396 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { 411 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) {
397 // TODO(oshima): Move primary display management to DisplayManager. 412 // TODO(oshima): Move primary display management to DisplayManager.
398 DCHECK_NE(display::Display::kInvalidDisplayID, id); 413 DCHECK_NE(display::Display::kInvalidDisplayID, id);
399 if (id == display::Display::kInvalidDisplayID || primary_display_id == id || 414 if (id == display::Display::kInvalidDisplayID || primary_display_id == id ||
400 window_tree_hosts_.size() < 2) { 415 window_tree_hosts_.size() < 2) {
401 return; 416 return;
402 } 417 }
403 // TODO(oshima): Implement swapping primary for 2> displays.
404 if (GetDisplayManager()->GetNumDisplays() > 2)
405 return;
406 418
407 const display::Display& new_primary_display = 419 const display::Display& new_primary_display =
408 GetDisplayManager()->GetDisplayForId(id); 420 GetDisplayManager()->GetDisplayForId(id);
409 if (!new_primary_display.is_valid()) { 421 if (!new_primary_display.is_valid()) {
410 LOG(ERROR) << "Invalid or non-existent display is requested:" 422 LOG(ERROR) << "Invalid or non-existent display is requested:"
411 << new_primary_display.ToString(); 423 << new_primary_display.ToString();
412 return; 424 return;
413 } 425 }
414 426
415 display::DisplayManager* display_manager = GetDisplayManager(); 427 display::DisplayManager* display_manager = GetDisplayManager();
(...skipping 25 matching lines...) Expand all
441 GetRootWindowSettings(GetWindow(non_primary_host))->display_id = 453 GetRootWindowSettings(GetWindow(non_primary_host))->display_id =
442 old_primary_display.id(); 454 old_primary_display.id();
443 455
444 const display::DisplayLayout& layout = 456 const display::DisplayLayout& layout =
445 GetDisplayManager()->GetCurrentDisplayLayout(); 457 GetDisplayManager()->GetCurrentDisplayLayout();
446 // The requested primary id can be same as one in the stored layout 458 // The requested primary id can be same as one in the stored layout
447 // when the primary id is set after new displays are connected. 459 // when the primary id is set after new displays are connected.
448 // Only update the layout if it is requested to swap primary display. 460 // Only update the layout if it is requested to swap primary display.
449 if (layout.primary_id != new_primary_display.id()) { 461 if (layout.primary_id != new_primary_display.id()) {
450 std::unique_ptr<display::DisplayLayout> swapped_layout(layout.Copy()); 462 std::unique_ptr<display::DisplayLayout> swapped_layout(layout.Copy());
451 swapped_layout->placement_list[0].Swap(); 463
464 std::map<int64_t, display::DisplayPlacement*> id_to_placement;
465 for (auto& placement : swapped_layout->placement_list)
466 id_to_placement[placement.display_id] = &placement;
467 SwapRecursive(id_to_placement, primary_display_id,
468 new_primary_display.id());
469
470 std::sort(swapped_layout->placement_list.begin(),
471 swapped_layout->placement_list.end(),
472 [](const display::DisplayPlacement& d1,
473 const display::DisplayPlacement& d2) {
474 return d1.display_id < d2.display_id;
475 });
476
452 swapped_layout->primary_id = new_primary_display.id(); 477 swapped_layout->primary_id = new_primary_display.id();
453 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 478 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
454 GetDisplayManager()->layout_store()->RegisterLayoutForDisplayIdList( 479 GetDisplayManager()->layout_store()->RegisterLayoutForDisplayIdList(
455 list, std::move(swapped_layout)); 480 list, std::move(swapped_layout));
456 } 481 }
457 482
458 primary_display_id = new_primary_display.id(); 483 primary_display_id = new_primary_display.id();
459 484
460 UpdateWorkAreaOfDisplayNearestWindow(GetWindow(primary_host), 485 UpdateWorkAreaOfDisplayNearestWindow(GetWindow(primary_host),
461 old_primary_display.GetWorkAreaInsets()); 486 old_primary_display.GetWorkAreaInsets());
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 SetDisplayPropertiesOnHost(ash_host, display); 895 SetDisplayPropertiesOnHost(ash_host, display);
871 896
872 #if defined(OS_CHROMEOS) 897 #if defined(OS_CHROMEOS)
873 if (switches::ConstrainPointerToRoot()) 898 if (switches::ConstrainPointerToRoot())
874 ash_host->ConfineCursorToRootWindow(); 899 ash_host->ConfineCursorToRootWindow();
875 #endif 900 #endif
876 return ash_host; 901 return ash_host;
877 } 902 }
878 903
879 } // namespace ash 904 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/display/window_tree_host_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698