recovery: Correct touch position with overscan

Change-Id: I9739040cf968961944f9e1e6eae4929b57f51d41
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 9bc9a4e..cd01768 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -501,6 +501,24 @@
              : gr_draw->height - 2 * overscan_offset_y;
 }
 
+int gr_fb_width_real() {
+  return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT) ? gr_draw->height
+                                                                         : gr_draw->width;
+}
+
+int gr_fb_height_real() {
+  return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT) ? gr_draw->width
+                                                                         : gr_draw->height;
+}
+
+int gr_overscan_offset_x() {
+  return overscan_offset_x;
+}
+
+int gr_overscan_offset_y() {
+  return overscan_offset_y;
+}
+
 void gr_fb_blank(bool blank) {
   gr_backend->Blank(blank);
 }
diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h
index ff3e7b1..76d6cd7 100644
--- a/minui/include/minui/minui.h
+++ b/minui/include/minui/minui.h
@@ -125,6 +125,10 @@
 
 int gr_fb_width();
 int gr_fb_height();
+int gr_fb_width_real();
+int gr_fb_height_real();
+int gr_overscan_offset_x();
+int gr_overscan_offset_y();
 
 void gr_flip();
 void gr_fb_blank(bool blank);
diff --git a/recovery_ui/screen_ui.cpp b/recovery_ui/screen_ui.cpp
index f4dc2c5..95fce25 100644
--- a/recovery_ui/screen_ui.cpp
+++ b/recovery_ui/screen_ui.cpp
@@ -1357,7 +1357,10 @@
   return sel;
 }
 
-int ScreenRecoveryUI::SelectMenu(const Point& point) {
+int ScreenRecoveryUI::SelectMenu(const Point& p) {
+  // Correct position for overscan
+  const Point point(p.x() - gr_overscan_offset_x(), p.y() - gr_overscan_offset_y());
+
   int new_sel = Device::kNoAction;
   std::lock_guard<std::mutex> lg(updateMutex);
   if (menu_) {
diff --git a/recovery_ui/ui.cpp b/recovery_ui/ui.cpp
index 6aa08f1..8561120 100644
--- a/recovery_ui/ui.cpp
+++ b/recovery_ui/ui.cpp
@@ -265,7 +265,7 @@
 }
 
 void RecoveryUI::OnTouchTrack() {
-  if (touch_pos_.y() <= gr_fb_height()) {
+  if (touch_pos_.y() <= gr_fb_height_real()) {
     while (abs(touch_pos_.y() - touch_track_.y()) >= MenuItemHeight()) {
       int dy = touch_pos_.y() - touch_track_.y();
       int key = (dy < 0) ? KEY_SCROLLDOWN : KEY_SCROLLUP;
@@ -285,7 +285,7 @@
   }
 
   // Check vkeys.  Only report if touch both starts and ends in the vkey.
-  if (touch_start_.y() > gr_fb_height() && touch_pos_.y() > gr_fb_height()) {
+  if (touch_start_.y() > gr_fb_height_real() && touch_pos_.y() > gr_fb_height_real()) {
     for (const auto& vk : virtual_keys_) {
       if (vk.inside(touch_start_) && vk.inside(touch_pos_)) {
         ProcessKey(vk.keycode, 1);  // press key
@@ -377,7 +377,7 @@
       case ABS_MT_POSITION_X:
         touch_finger_down_ = true;
         touch_saw_x_ = true;
-        touch_pos_.x(ev.value * gr_fb_width() / (touch_max_.x() - touch_min_.x()));
+        touch_pos_.x(ev.value * gr_fb_width_real() / (touch_max_.x() - touch_min_.x()));
         if (touch_reported_ && touch_saw_y_) {
           OnTouchTrack();
           touch_saw_x_ = touch_saw_y_ = false;
@@ -387,7 +387,7 @@
       case ABS_MT_POSITION_Y:
         touch_finger_down_ = true;
         touch_saw_y_ = true;
-        touch_pos_.y(ev.value * gr_fb_height() / (touch_max_.y() - touch_min_.y()));
+        touch_pos_.y(ev.value * gr_fb_height_real() / (touch_max_.y() - touch_min_.y()));
         if (touch_reported_ && touch_saw_x_) {
           OnTouchTrack();
           touch_saw_x_ = touch_saw_y_ = false;