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

Side by Side Diff: pointer_position_watcher.cc

Issue 6902072: wm: Update a lot of code to use structs from geometry.h. (Closed) Base URL: ssh://gitrw.chromium.org:9222/window_manager.git@master
Patch Set: move override-redirect stacking and visibility into Window Created 9 years, 7 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
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/pointer_position_watcher.h" 5 #include "window_manager/pointer_position_watcher.h"
6 6
7 #include "window_manager/event_loop.h" 7 #include "window_manager/event_loop.h"
8 #include "window_manager/x11/x_connection.h" 8 #include "window_manager/x11/x_connection.h"
9 9
10 namespace window_manager { 10 namespace window_manager {
11 11
12 // How frequently should we query the pointer position, in milliseconds? 12 // How frequently should we query the pointer position, in milliseconds?
13 static const int kTimeoutMs = 200; 13 static const int kTimeoutMs = 200;
14 14
15 PointerPositionWatcher::PointerPositionWatcher( 15 PointerPositionWatcher::PointerPositionWatcher(
16 EventLoop* event_loop, 16 EventLoop* event_loop,
17 XConnection* xconn, 17 XConnection* xconn,
18 Closure* cb, 18 Closure* cb,
19 bool watch_for_entering_target, 19 bool watch_for_entering_target,
20 int target_x, int target_y, int target_width, int target_height) 20 const Rect& target_bounds)
21 : event_loop_(event_loop), 21 : event_loop_(event_loop),
22 xconn_(xconn), 22 xconn_(xconn),
23 cb_(cb), 23 cb_(cb),
24 watch_for_entering_target_(watch_for_entering_target), 24 watch_for_entering_target_(watch_for_entering_target),
25 target_x_(target_x), 25 target_bounds_(target_bounds),
26 target_y_(target_y),
27 target_width_(target_width),
28 target_height_(target_height),
29 timeout_id_(-1) { 26 timeout_id_(-1) {
30 DCHECK(event_loop); 27 DCHECK(event_loop);
31 DCHECK(xconn); 28 DCHECK(xconn);
32 DCHECK(cb); 29 DCHECK(cb);
33 timeout_id_ = 30 timeout_id_ =
34 event_loop_->AddTimeout( 31 event_loop_->AddTimeout(
35 NewPermanentCallback(this, &PointerPositionWatcher::HandleTimeout), 32 NewPermanentCallback(this, &PointerPositionWatcher::HandleTimeout),
36 0, kTimeoutMs); // recurring=true 33 0, kTimeoutMs); // recurring=true
37 } 34 }
38 35
(...skipping 11 matching lines...) Expand all
50 timeout_id_ = -1; 47 timeout_id_ = -1;
51 } 48 }
52 } 49 }
53 50
54 void PointerPositionWatcher::HandleTimeout() { 51 void PointerPositionWatcher::HandleTimeout() {
55 Point pointer_pos; 52 Point pointer_pos;
56 if (!xconn_->QueryPointerPosition(&pointer_pos)) 53 if (!xconn_->QueryPointerPosition(&pointer_pos))
57 return; 54 return;
58 55
59 // Bail out if we're not in the desired state yet. 56 // Bail out if we're not in the desired state yet.
60 bool in_target = pointer_pos.x >= target_x_ && 57 const bool in_target = target_bounds_.contains_point(pointer_pos);
61 pointer_pos.x < target_x_ + target_width_ &&
62 pointer_pos.y >= target_y_ &&
63 pointer_pos.y < target_y_ + target_height_;
64 if ((watch_for_entering_target_ && !in_target) || 58 if ((watch_for_entering_target_ && !in_target) ||
65 (!watch_for_entering_target_ && in_target)) 59 (!watch_for_entering_target_ && in_target))
66 return; 60 return;
67 61
68 // Otherwise, run the callback. Cancel the timeout first, in case the 62 // Otherwise, run the callback. Cancel the timeout first, in case the
69 // callback deletes this object. 63 // callback deletes this object.
70 CancelTimeoutIfActive(); 64 CancelTimeoutIfActive();
71 cb_->Run(); 65 cb_->Run();
72 } 66 }
73 67
74 } // namespace window_manager 68 } // namespace window_manager
OLDNEW
« no previous file with comments | « pointer_position_watcher.h ('k') | pointer_position_watcher_test.cc » ('j') | window.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698