~mterry/mir/session-for-surface

« back to all changes in this revision

Viewing changes to src/server/input/android/android_pointer_controller.cpp

  • Committer: Michael Terry
  • Date: 2013-07-29 17:51:51 UTC
  • mfrom: (832.1.58 trunk)
  • Revision ID: michael.terry@canonical.com-20130729175151-3thcnlepeihhzbb8
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Robert Carr <robert.carr@canonical.com>
17
17
 */
18
18
 
19
 
#include "mir/graphics/viewable_area.h"
 
19
#include "mir/input/input_region.h"
 
20
#include "mir/geometry/rectangle.h"
 
21
#include "mir/geometry/point.h"
20
22
 
21
23
#include "android_pointer_controller.h"
22
24
 
23
25
#include <algorithm>
24
26
 
25
 
namespace mg = mir::graphics;
26
27
namespace mi = mir::input;
27
28
namespace mia = mi::android;
 
29
namespace geom = mir::geometry;
28
30
 
29
 
mia::PointerController::PointerController(std::shared_ptr<mg::ViewableArea> const& viewable_area)
 
31
mia::PointerController::PointerController(
 
32
    std::shared_ptr<mi::InputRegion> const& input_region)
30
33
        : state(0),
31
34
          x(0.0),
32
35
          y(0.0),
33
 
          viewable_area(viewable_area),
 
36
          input_region(input_region),
34
37
          cursor_listener(std::shared_ptr<mi::CursorListener>())
35
38
{
36
39
}
37
40
 
38
41
mia::PointerController::PointerController(
39
 
    std::shared_ptr<mg::ViewableArea> const& viewable_area,
 
42
    std::shared_ptr<mi::InputRegion> const& input_region,
40
43
    std::shared_ptr<mi::CursorListener> const& cursor_listener)
41
44
        : state(0),
42
45
          x(0.0),
43
46
          y(0.0),
44
 
          viewable_area(viewable_area),
 
47
          input_region(input_region),
45
48
          cursor_listener(cursor_listener)
46
49
 
47
50
{
70
73
    float* out_max_x,
71
74
    float* out_max_y) const
72
75
{
73
 
    auto bounds = viewable_area->view_area();
 
76
    auto bounds = input_region->bounding_rectangle();
74
77
    *out_min_x = bounds.top_left.x.as_float();
75
78
    *out_min_y = bounds.top_left.y.as_float();
76
79
    *out_max_x = bounds.top_left.x.as_float() + bounds.size.width.as_float();
97
100
void mia::PointerController::setPosition(float new_x, float new_y)
98
101
{
99
102
    std::lock_guard<std::mutex> lg(guard);
100
 
    float min_x, min_y, max_x, max_y;
101
 
 
102
 
    get_bounds_locked(&min_x, &min_y, &max_x, &max_y);
103
 
 
104
 
    x = std::max(min_x, std::min(max_x, new_x));
105
 
    y = std::max(min_y, std::min(max_y, new_y));
 
103
 
 
104
    geom::Point p{new_x, new_y};
 
105
    input_region->confine(p);
 
106
 
 
107
    x = p.x.as_float();
 
108
    y = p.y.as_float();
106
109
 
107
110
    // I think it's correct to hold this lock while notifying the listener (i.e. cursor rendering update)
108
111
    // to prevent the InputReader from getting ahead of rendering. This may need to be thought about later.