Beispiel #1
0
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
      int16_t *res_x, int16_t *res_y, int16_t *res_screen_x, int16_t *res_screen_y)
{
   struct rarch_viewport vp = {0};
   if (driver.video->viewport_info)
      video_viewport_info_func(&vp);
   else
      return false;

   int scaled_screen_x = (2 * mouse_x * 0x7fff) / (int)vp.full_width - 0x7fff;
   int scaled_screen_y = (2 * mouse_y * 0x7fff) / (int)vp.full_height - 0x7fff;
   if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
      scaled_screen_x = -0x8000; // OOB
   if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
      scaled_screen_y = -0x8000; // OOB

   mouse_x -= vp.x;
   mouse_y -= vp.y;

   int scaled_x = (2 * mouse_x * 0x7fff) / (int)vp.width - 0x7fff;
   int scaled_y = (2 * mouse_y * 0x7fff) / (int)vp.height - 0x7fff;
   if (scaled_x < -0x7fff || scaled_x > 0x7fff)
      scaled_x = -0x8000; // OOB
   if (scaled_y < -0x7fff || scaled_y > 0x7fff)
      scaled_y = -0x8000; // OOB

   *res_x = scaled_x;
   *res_y = scaled_y;
   *res_screen_x = scaled_screen_x;
   *res_screen_y = scaled_screen_y;
   return true;
}
Beispiel #2
0
static void x_input_poll_mouse(x11_input_t *x11)
{
   Window root_win, child_win;
   int root_x, root_y, win_x, win_y;
   unsigned mask;

   x11->mouse_last_x = x11->mouse_x;
   x11->mouse_last_y = x11->mouse_y;

   XQueryPointer(x11->display,
            x11->win,
            &root_win, &child_win,
            &root_x, &root_y,
            &win_x, &win_y,
            &mask);

   x11->mouse_x = win_x;
   x11->mouse_y = win_y;
   x11->mouse_l = mask & Button1Mask; 
   x11->mouse_m = mask & Button2Mask; 
   x11->mouse_r = mask & Button3Mask; 

   // Somewhat hacky, but seem to do the job.
   if (x11->grab_mouse && video_focus_func())
   {
      struct rarch_viewport vp = {0};
      video_viewport_info_func(&vp);
      int mid_w = vp.full_width >> 1;
      int mid_h = vp.full_height >> 1;

      if (x11->mouse_x != mid_w || x11->mouse_y != mid_h)
      {
         XWarpPointer(x11->display, None,
               x11->win, 0, 0, 0, 0,
               mid_w, mid_h);
      }
      x11->mouse_last_x = mid_w;
      x11->mouse_last_y = mid_h;
   }
}