Exemplo n.º 1
0
void dispatch_mdown(uint8 *data,uint32 len,uint8 rclick)
{
    double w,h;

    if(data&&len==sizeof(MsgMouseClick))
    {
        MsgMouseDown *mouse=(MsgMouseDown *)data;

        int screen,cx,cy;
        // get current screen
        xdo_mouselocation(_options._xdo,&cx,&cy,&screen);
        // get w/h
        getdim(&w,&h,screen);
        // get message data
        mouse->_x=ntohs(mouse->_x);
        mouse->_width=ntohs(mouse->_width);
        mouse->_y=ntohs(mouse->_y);
        mouse->_height=ntohs(mouse->_height);

        // scale from android to screen
        cx=w*mouse->_x/mouse->_width;
        cy=h*mouse->_y/mouse->_height;
        // move the mouse
        xdo_mousemove(_options._xdo,cx,cy,screen);
        xdo_mousedown(_options._xdo,CURRENTWINDOW,rclick?3:1);
    }
}
Exemplo n.º 2
0
void dispatch_move(uint8 *data,uint32 len)
{
    double w,h;

    if(data&&len==sizeof(MsgMouseMove))
    {
        MsgMouseMove *mouse=(MsgMouseMove *)data;

        int screen,cx,cy;
        // get current screen
        xdo_mouselocation(_options._xdo,&cx,&cy,&screen);
        // get w/h
        getdim(&w,&h,screen);
        // get message data
        mouse->_x=ntohs(mouse->_x);
        mouse->_width=ntohs(mouse->_width);
        mouse->_y=ntohs(mouse->_y);
        mouse->_height=ntohs(mouse->_height);

        // scale from android to screen
        cx=w*mouse->_x/mouse->_width;
        cy=h*mouse->_y/mouse->_height;

        // printf("Move: [%d,%d]  [%d,%d] of [%d,%d]\n",
        //        cx,cy,mouse->_x,mouse->_y,mouse->_width,mouse->_height);

        // move the mouse
        xdo_mousemove(_options._xdo,cx,cy,screen);
    }
}
Exemplo n.º 3
0
int cmd_mousemove_relative(context_t *context) {
  int x, y;
  int ret = 0;
  char *cmd = *context->argv;
  int polar_coordinates = 0;
  int clear_modifiers = 0;
  int opsync = 0;
  int origin_x = -1, origin_y = -1;

  xdo_active_mods_t *active_mods = NULL;
  int c;
  typedef enum {
    opt_unused, opt_help, opt_sync, opt_clearmodifiers, opt_polar
  } optlist_t;
  static struct option longopts[] = {
    { "help", no_argument, NULL, opt_help },
    { "sync", no_argument, NULL, opt_sync },
    { "polar", no_argument, NULL, opt_polar },
    { "clearmodifiers", no_argument, NULL, opt_clearmodifiers },
    { 0, 0, 0, 0 },
  };
  static const char *usage =
      "Usage: %s [options] <x> <y>\n"
      "-c, --clearmodifiers      - reset active modifiers (alt, etc) while typing\n"
      "-p, --polar               - Use polar coordinates. X as an angle, Y as distance\n"
      "--sync                    - only exit once the mouse has moved\n"
      "\n"
      "Using polar coordinate mode makes 'x' the angle (in degrees) and\n"
      "'y' the distance.\n"
      "\n"
      "If you want to use negative numbers for a coordinate, you'll need to\n"
      "invoke it this way (with the '--'):\n"
      "   %s -- -20 -15\n"
      "otherwise, normal usage looks like this:\n"
      "   %s 100 140\n";
  int option_index;

  while ((c = getopt_long_only(context->argc, context->argv, "+cph",
                               longopts, &option_index)) != -1) {
    switch (c) {
      case 'h':
      case opt_help:
        printf(usage, cmd, cmd, cmd);
        consume_args(context, context->argc);
        return EXIT_SUCCESS;
        break;
      case 'p':
      case opt_polar:
        polar_coordinates = 1;
        break;
      case opt_sync:
        opsync = 1;
        break;
      case 'c':
      case opt_clearmodifiers:
        clear_modifiers = 1;
        break;
      default:
        fprintf(stderr, usage, cmd, cmd, cmd);
        return EXIT_FAILURE;
    }
  }

  consume_args(context, optind);

  if (context->argc < 2) {
    fprintf(stderr, usage, cmd, cmd, cmd);
    fprintf(stderr, "You specified the wrong number of args (expected 2).\n");
    return EXIT_FAILURE;
  }

  x = atoi(context->argv[0]);
  y = atoi(context->argv[1]);
  consume_args(context, 2);

  /* Quit early if we don't have to move. */
  if (x == 0 && y == 0) {
    return EXIT_SUCCESS;
  }

  if (polar_coordinates) {
    /* The original request for polar support was that '0' degrees is up
     * and that rotation was clockwise, so 0 is up, 90 right, 180 down, 270
     * left. This conversion can be done with (360 - degrees) + 90 */
    double radians = ((360 - x) + 90) * (M_PI / 180);
    double distance = y;
    x = (cos(radians) * distance);

    /* Negative sin, since screen Y coordinates are descending, where cartesian
     * is ascending */
    y = (-sin(radians) * distance);
  }
 
  if (clear_modifiers) {
    active_mods = xdo_get_active_modifiers(context->xdo);
    xdo_clear_active_modifiers(context->xdo, CURRENTWINDOW, active_mods);
  }

  if (opsync) {
    xdo_mouselocation(context->xdo, &origin_x, &origin_y, NULL);
  }

  ret = xdo_mousemove_relative(context->xdo, x, y);

  if (ret) {
    fprintf(stderr, "xdo_mousemove_relative reported an error\n");
  } else {
    if (opsync) {
      /* Wait until the mouse moves away from its current position */
      xdo_mouse_wait_for_move_from(context->xdo, origin_x, origin_y);
    }
  }

  if (clear_modifiers) {
    xdo_set_active_modifiers(context->xdo, CURRENTWINDOW, active_mods);
    xdo_free_active_modifiers(active_mods);
  }

  return ret;
}