16
16
* Authored by: Robert Carr <robert.carr@canonical.com>
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"
21
23
#include "android_pointer_controller.h"
23
25
#include <algorithm>
25
namespace mg = mir::graphics;
26
27
namespace mi = mir::input;
27
28
namespace mia = mi::android;
29
namespace geom = mir::geometry;
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)
33
viewable_area(viewable_area),
36
input_region(input_region),
34
37
cursor_listener(std::shared_ptr<mi::CursorListener>())
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)
44
viewable_area(viewable_area),
47
input_region(input_region),
45
48
cursor_listener(cursor_listener)
71
74
float* out_max_y) const
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)
99
102
std::lock_guard<std::mutex> lg(guard);
100
float min_x, min_y, max_x, max_y;
102
get_bounds_locked(&min_x, &min_y, &max_x, &max_y);
104
x = std::max(min_x, std::min(max_x, new_x));
105
y = std::max(min_y, std::min(max_y, new_y));
104
geom::Point p{new_x, new_y};
105
input_region->confine(p);
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.