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

Side by Side Diff: screen_locker_handler.cc

Issue 6011011: wm: Fade screen on signout. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/window_manager.git@master
Patch Set: apply review feedback Created 9 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « screen_locker_handler.h ('k') | screen_locker_handler_test.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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "window_manager/screen_locker_handler.h" 5 #include "window_manager/screen_locker_handler.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <tr1/unordered_set> 8 #include <tr1/unordered_set>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 30 matching lines...) Expand all
41 // How long should we take to fade the screen locker window in in the 41 // How long should we take to fade the screen locker window in in the
42 // background once the screen has been locked? 42 // background once the screen has been locked?
43 static const int kScreenLockerFadeInMs = 50; 43 static const int kScreenLockerFadeInMs = 50;
44 44
45 // How long we'll wait for another message after we enter the pre-lock or 45 // How long we'll wait for another message after we enter the pre-lock or
46 // pre-shutdown state before giving up and reverting back to the previous 46 // pre-shutdown state before giving up and reverting back to the previous
47 // state. This is just here as backup so we don't get stuck showing the 47 // state. This is just here as backup so we don't get stuck showing the
48 // snapshot onscreen forever if the power manager dies or something. 48 // snapshot onscreen forever if the power manager dies or something.
49 static const int kAbortAnimationMs = 2000; 49 static const int kAbortAnimationMs = 2000;
50 50
51 // How long should we take to fade the screen to black when the user signs out?
52 static const int kSignoutAnimMs = 100;
53
51 const float ScreenLockerHandler::kSlowCloseSizeRatio = 0.95; 54 const float ScreenLockerHandler::kSlowCloseSizeRatio = 0.95;
52 55
53 ScreenLockerHandler::ScreenLockerHandler(WindowManager* wm) 56 ScreenLockerHandler::ScreenLockerHandler(WindowManager* wm)
54 : wm_(wm), 57 : wm_(wm),
55 registrar_(new EventConsumerRegistrar(wm_, this)), 58 registrar_(new EventConsumerRegistrar(wm_, this)),
56 snapshot_pixmap_(0), 59 snapshot_pixmap_(0),
57 destroy_snapshot_timeout_id_(-1), 60 destroy_snapshot_timeout_id_(-1),
58 is_locked_(false), 61 is_locked_(false),
59 shutting_down_(false) { 62 session_ending_(false) {
60 registrar_->RegisterForChromeMessages( 63 registrar_->RegisterForChromeMessages(
61 chromeos::WM_IPC_MESSAGE_WM_NOTIFY_POWER_BUTTON_STATE); 64 chromeos::WM_IPC_MESSAGE_WM_NOTIFY_POWER_BUTTON_STATE);
62 registrar_->RegisterForChromeMessages( 65 registrar_->RegisterForChromeMessages(
63 chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN); 66 chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN);
67 registrar_->RegisterForChromeMessages(
68 chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SIGNING_OUT);
64 } 69 }
65 70
66 ScreenLockerHandler::~ScreenLockerHandler() { 71 ScreenLockerHandler::~ScreenLockerHandler() {
67 if (is_locked_) 72 if (is_locked_)
68 wm_->compositor()->ResetActiveVisibilityGroups(); 73 wm_->compositor()->ResetActiveVisibilityGroups();
69 74
70 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_); 75 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_);
71 if (snapshot_pixmap_) 76 if (snapshot_pixmap_)
72 wm_->xconn()->FreePixmap(snapshot_pixmap_); 77 wm_->xconn()->FreePixmap(snapshot_pixmap_);
73 } 78 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 HandlePreShutdown(); 174 HandlePreShutdown();
170 break; 175 break;
171 case chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN: 176 case chromeos::WM_IPC_POWER_BUTTON_ABORTED_SHUTDOWN:
172 HandleAbortedShutdown(); 177 HandleAbortedShutdown();
173 break; 178 break;
174 default: 179 default:
175 LOG(ERROR) << "Unexpected state in power button state message: " 180 LOG(ERROR) << "Unexpected state in power button state message: "
176 << state; 181 << state;
177 } 182 }
178 } else if (msg.type() == chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN) { 183 } else if (msg.type() == chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SHUTTING_DOWN) {
179 HandleShuttingDown(); 184 HandleSessionEnding(true); // shutting_down=true
185 } else if (msg.type() == chromeos::WM_IPC_MESSAGE_WM_NOTIFY_SIGNING_OUT) {
186 HandleSessionEnding(false); // shutting_down=false
180 } else { 187 } else {
181 NOTREACHED() << "Received unwanted Chrome message " 188 NOTREACHED() << "Received unwanted Chrome message "
182 << chromeos::WmIpcMessageTypeToString(msg.type()); 189 << chromeos::WmIpcMessageTypeToString(msg.type());
183 } 190 }
184 } 191 }
185 192
186 bool ScreenLockerHandler::HasWindowWithInitialPixmap() const { 193 bool ScreenLockerHandler::HasWindowWithInitialPixmap() const {
187 for (set<XWindow>::const_iterator it = screen_locker_xids_.begin(); 194 for (set<XWindow>::const_iterator it = screen_locker_xids_.begin();
188 it != screen_locker_xids_.end(); ++it) { 195 it != screen_locker_xids_.end(); ++it) {
189 if (wm_->GetWindowOrDie(*it)->has_initial_pixmap()) 196 if (wm_->GetWindowOrDie(*it)->has_initial_pixmap())
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 WmIpc::Message msg( 251 WmIpc::Message msg(
245 chromeos::WM_IPC_MESSAGE_CHROME_NOTIFY_SCREEN_REDRAWN_FOR_LOCK); 252 chromeos::WM_IPC_MESSAGE_CHROME_NOTIFY_SCREEN_REDRAWN_FOR_LOCK);
246 wm_->wm_ipc()->SendMessage(chrome_win->xid(), msg); 253 wm_->wm_ipc()->SendMessage(chrome_win->xid(), msg);
247 } 254 }
248 255
249 void ScreenLockerHandler::HandleUnlocked() { 256 void ScreenLockerHandler::HandleUnlocked() {
250 DCHECK(is_locked_); 257 DCHECK(is_locked_);
251 DCHECK(!HasWindowWithInitialPixmap()); 258 DCHECK(!HasWindowWithInitialPixmap());
252 is_locked_ = false; 259 is_locked_ = false;
253 260
254 if (shutting_down_) 261 if (session_ending_)
255 return; 262 return;
256 263
257 DLOG(INFO) << "Last screen locker window unmapped; unhiding other windows"; 264 DLOG(INFO) << "Last screen locker window unmapped; unhiding other windows";
258 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_); 265 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_);
259 266
260 // This is arguably incorrect if the user types their password on the lock 267 // This is arguably incorrect if the user types their password on the lock
261 // screen, starts holding the power button, and then hits Enter to unlock the 268 // screen, starts holding the power button, and then hits Enter to unlock the
262 // screen: we'll abort the pre-shutdown animation here. It's not an issue in 269 // screen: we'll abort the pre-shutdown animation here. It's not an issue in
263 // practice, though: if they release the power button before we'd shut down, 270 // practice, though: if they release the power button before we'd shut down,
264 // the snapshot is already gone and the aborted-shutdown message is a no-op; 271 // the snapshot is already gone and the aborted-shutdown message is a no-op;
265 // if they hold the power button and we start shutting down, we'll grab a new 272 // if they hold the power button and we start shutting down, we'll grab a new
266 // snapshot for the fast-close animation. 273 // snapshot for the fast-close animation.
267 DestroySnapshotAndUpdateVisibilityGroup(); 274 DestroySnapshotAndUpdateVisibilityGroup();
268 } 275 }
269 276
270 void ScreenLockerHandler::HandlePreShutdown() { 277 void ScreenLockerHandler::HandlePreShutdown() {
271 DLOG(INFO) << "Starting pre-shutdown animation"; 278 DLOG(INFO) << "Starting pre-shutdown animation";
272 if (snapshot_actor_.get()) { 279 if (snapshot_actor_.get()) {
273 // Make sure that we'll use a new snapshot. If the power button was 280 // Make sure that we'll use a new snapshot. If the power button was
274 // held since before the screen was locked, we don't want to reuse the 281 // held since before the screen was locked, we don't want to reuse the
275 // snapshot taken while the screen was unlocked. 282 // snapshot taken while the screen was unlocked.
276 DestroySnapshotAndUpdateVisibilityGroup(); 283 DestroySnapshotAndUpdateVisibilityGroup();
277 wm_->compositor()->Draw(); 284 wm_->compositor()->Draw();
278 } 285 }
279 StartSlowCloseAnimation(); 286 StartSlowCloseAnimation();
280 wm_->compositor()->SetActiveVisibilityGroup( 287 wm_->compositor()->SetActiveVisibilityGroup(
281 WindowManager::VISIBILITY_GROUP_SHUTDOWN); 288 WindowManager::VISIBILITY_GROUP_SESSION_ENDING);
282 } 289 }
283 290
284 void ScreenLockerHandler::HandleAbortedShutdown() { 291 void ScreenLockerHandler::HandleAbortedShutdown() {
285 DLOG(INFO) << "Shutdown aborted"; 292 DLOG(INFO) << "Shutdown aborted";
286 StartUndoSlowCloseAnimation(); 293 StartUndoSlowCloseAnimation();
287 } 294 }
288 295
289 void ScreenLockerHandler::HandleShuttingDown() { 296 void ScreenLockerHandler::HandleSessionEnding(bool shutting_down) {
290 LOG(INFO) << "System is shutting down"; 297 if (shutting_down)
291 if (shutting_down_) 298 LOG(INFO) << "System is shutting down";
299 else
300 LOG(INFO) << "User is signing out";
301
302 if (session_ending_)
292 return; 303 return;
293 shutting_down_ = true; 304 session_ending_ = true;
294 305
295 XID cursor = wm_->xconn()->CreateTransparentCursor(); 306 XID cursor = wm_->xconn()->CreateTransparentCursor();
296 wm_->xconn()->SetWindowCursor(wm_->root(), cursor); 307 wm_->xconn()->SetWindowCursor(wm_->root(), cursor);
297 wm_->xconn()->GrabPointer(wm_->root(), 0, 0, cursor); 308 wm_->xconn()->GrabPointer(wm_->root(), 0, 0, cursor);
298 if (cursor) 309 if (cursor)
299 wm_->xconn()->FreeCursor(cursor); 310 wm_->xconn()->FreeCursor(cursor);
300 wm_->xconn()->GrabKeyboard(wm_->root(), 0); 311 wm_->xconn()->GrabKeyboard(wm_->root(), 0);
301 312
302 StartFastCloseAnimation(false); 313 if (shutting_down)
314 StartFastCloseAnimation(false);
315 else
316 StartFadeoutAnimation();
303 wm_->compositor()->SetActiveVisibilityGroup( 317 wm_->compositor()->SetActiveVisibilityGroup(
304 WindowManager::VISIBILITY_GROUP_SHUTDOWN); 318 WindowManager::VISIBILITY_GROUP_SESSION_ENDING);
319 }
320
321 void ScreenLockerHandler::SetUpSnapshot() {
322 if (snapshot_actor_.get())
323 return;
324
325 DCHECK_EQ(snapshot_pixmap_, static_cast<XPixmap>(0));
326 snapshot_pixmap_ = wm_->xconn()->CreatePixmap(
327 wm_->root(), Size(wm_->width(), wm_->height()), wm_->root_depth());
328 wm_->xconn()->CopyArea(wm_->root(), // src
329 snapshot_pixmap_, // dest
330 Point(0, 0), // src_pos
331 Point(0, 0), // dest_pos
332 Size(wm_->width(), wm_->height()));
333 snapshot_actor_.reset(wm_->compositor()->CreateTexturePixmap());
334 snapshot_actor_->SetPixmap(snapshot_pixmap_);
335 wm_->stage()->AddActor(snapshot_actor_.get());
336 wm_->stacking_manager()->StackActorAtTopOfLayer(
337 snapshot_actor_.get(), StackingManager::LAYER_SCREEN_LOCKER_SNAPSHOT);
338 snapshot_actor_->AddToVisibilityGroup(
339 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER);
340 snapshot_actor_->AddToVisibilityGroup(
341 WindowManager::VISIBILITY_GROUP_SESSION_ENDING);
342 snapshot_actor_->Move(0, 0, 0);
343 snapshot_actor_->Scale(1.0, 1.0, 0);
305 } 344 }
306 345
307 void ScreenLockerHandler::StartSlowCloseAnimation() { 346 void ScreenLockerHandler::StartSlowCloseAnimation() {
308 if (!snapshot_actor_.get()) { 347 if (!snapshot_actor_.get()) {
309 DCHECK_EQ(snapshot_pixmap_, static_cast<XPixmap>(0)); 348 SetUpSnapshot();
310 snapshot_pixmap_ = wm_->xconn()->CreatePixmap( 349 } else {
311 wm_->root(), Size(wm_->width(), wm_->height()), wm_->root_depth()); 350 snapshot_actor_->Move(0, 0, 0);
312 wm_->xconn()->CopyArea(wm_->root(), // src 351 snapshot_actor_->Scale(1.0, 1.0, 0);
313 snapshot_pixmap_, // dest
314 Point(0, 0), // src_pos
315 Point(0, 0), // dest_pos
316 Size(wm_->width(), wm_->height()));
317 snapshot_actor_.reset(wm_->compositor()->CreateTexturePixmap());
318 snapshot_actor_->SetPixmap(snapshot_pixmap_);
319 wm_->stage()->AddActor(snapshot_actor_.get());
320 wm_->stacking_manager()->StackActorAtTopOfLayer(
321 snapshot_actor_.get(), StackingManager::LAYER_SCREEN_LOCKER_SNAPSHOT);
322 snapshot_actor_->AddToVisibilityGroup(
323 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER);
324 snapshot_actor_->AddToVisibilityGroup(
325 WindowManager::VISIBILITY_GROUP_SHUTDOWN);
326 } 352 }
327 353
328 snapshot_actor_->Move(0, 0, 0);
329 snapshot_actor_->Scale(1.0, 1.0, 0);
330
331 snapshot_actor_->Move( 354 snapshot_actor_->Move(
332 round(0.5 * (1.0 - kSlowCloseSizeRatio) * wm_->width()), 355 round(0.5 * (1.0 - kSlowCloseSizeRatio) * wm_->width()),
333 round(0.5 * (1.0 - kSlowCloseSizeRatio) * wm_->height()), 356 round(0.5 * (1.0 - kSlowCloseSizeRatio) * wm_->height()),
334 kSlowCloseAnimMs); 357 kSlowCloseAnimMs);
335 snapshot_actor_->Scale( 358 snapshot_actor_->Scale(
336 kSlowCloseSizeRatio, kSlowCloseSizeRatio, kSlowCloseAnimMs); 359 kSlowCloseSizeRatio, kSlowCloseSizeRatio, kSlowCloseAnimMs);
337 360
338 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_); 361 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_);
339 destroy_snapshot_timeout_id_ = 362 destroy_snapshot_timeout_id_ =
340 wm_->event_loop()->AddTimeout( 363 wm_->event_loop()->AddTimeout(
(...skipping 20 matching lines...) Expand all
361 NewPermanentCallback( 384 NewPermanentCallback(
362 this, 385 this,
363 &ScreenLockerHandler::HandleDestroySnapshotTimeout), 386 &ScreenLockerHandler::HandleDestroySnapshotTimeout),
364 kUndoSlowCloseAnimMs, 387 kUndoSlowCloseAnimMs,
365 0); // recurring timeout 388 0); // recurring timeout
366 } 389 }
367 390
368 void ScreenLockerHandler::StartFastCloseAnimation( 391 void ScreenLockerHandler::StartFastCloseAnimation(
369 bool destroy_snapshot_when_done) { 392 bool destroy_snapshot_when_done) {
370 if (!snapshot_actor_.get()) 393 if (!snapshot_actor_.get())
371 StartSlowCloseAnimation(); 394 SetUpSnapshot();
372 395
373 DCHECK(snapshot_actor_.get());
374 snapshot_actor_->Move( 396 snapshot_actor_->Move(
375 round(0.5 * wm_->width()), round(0.5 * wm_->height()), kFastCloseAnimMs); 397 round(0.5 * wm_->width()), round(0.5 * wm_->height()), kFastCloseAnimMs);
376 snapshot_actor_->Scale(0, 0, kFastCloseAnimMs); 398 snapshot_actor_->Scale(0, 0, kFastCloseAnimMs);
377 snapshot_actor_->SetOpacity(0, kFastCloseAnimMs); 399 snapshot_actor_->SetOpacity(0, kFastCloseAnimMs);
378 400
379 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_); 401 wm_->event_loop()->RemoveTimeoutIfSet(&destroy_snapshot_timeout_id_);
380 if (destroy_snapshot_when_done) { 402 if (destroy_snapshot_when_done) {
381 destroy_snapshot_timeout_id_ = 403 destroy_snapshot_timeout_id_ =
382 wm_->event_loop()->AddTimeout( 404 wm_->event_loop()->AddTimeout(
383 NewPermanentCallback( 405 NewPermanentCallback(
384 this, 406 this,
385 &ScreenLockerHandler::HandleDestroySnapshotTimeout), 407 &ScreenLockerHandler::HandleDestroySnapshotTimeout),
386 kFastCloseAnimMs, 408 kFastCloseAnimMs,
387 0); // recurring timeout 409 0); // recurring timeout
388 } 410 }
389 } 411 }
390 412
413 void ScreenLockerHandler::StartFadeoutAnimation() {
414 if (!snapshot_actor_.get()) {
415 SetUpSnapshot();
416 } else {
417 snapshot_actor_->Move(0, 0, 0);
418 snapshot_actor_->Scale(1.0, 1.0, 0);
419 }
420 snapshot_actor_->SetOpacity(0, kSignoutAnimMs);
421 }
422
391 void ScreenLockerHandler::DestroySnapshot() { 423 void ScreenLockerHandler::DestroySnapshot() {
392 snapshot_actor_.reset(); 424 snapshot_actor_.reset();
393 wm_->xconn()->FreePixmap(snapshot_pixmap_); 425 wm_->xconn()->FreePixmap(snapshot_pixmap_);
394 snapshot_pixmap_ = 0; 426 snapshot_pixmap_ = 0;
395 } 427 }
396 428
397 void ScreenLockerHandler::DestroySnapshotAndUpdateVisibilityGroup() { 429 void ScreenLockerHandler::DestroySnapshotAndUpdateVisibilityGroup() {
398 DestroySnapshot(); 430 DestroySnapshot();
399 431
400 // Let the real windows be visible again. 432 // Let the real windows be visible again.
401 if (is_locked_) { 433 if (is_locked_) {
402 wm_->compositor()->SetActiveVisibilityGroup( 434 wm_->compositor()->SetActiveVisibilityGroup(
403 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER); 435 WindowManager::VISIBILITY_GROUP_SCREEN_LOCKER);
404 } else { 436 } else {
405 wm_->compositor()->ResetActiveVisibilityGroups(); 437 wm_->compositor()->ResetActiveVisibilityGroups();
406 } 438 }
407 } 439 }
408 440
409 void ScreenLockerHandler::HandleDestroySnapshotTimeout() { 441 void ScreenLockerHandler::HandleDestroySnapshotTimeout() {
410 destroy_snapshot_timeout_id_ = -1; 442 destroy_snapshot_timeout_id_ = -1;
411 DestroySnapshotAndUpdateVisibilityGroup(); 443 DestroySnapshotAndUpdateVisibilityGroup();
412 } 444 }
413 445
414 } // namespace window_manager 446 } // namespace window_manager
OLDNEW
« no previous file with comments | « screen_locker_handler.h ('k') | screen_locker_handler_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698