static void msmouse_queue_event(MouseState *mouse) { unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 }; int dx, dy, count = 3; dx = mouse->axis[INPUT_AXIS_X]; mouse->axis[INPUT_AXIS_X] = 0; dy = mouse->axis[INPUT_AXIS_Y]; mouse->axis[INPUT_AXIS_Y] = 0; /* Movement deltas */ bytes[0] |= (MSMOUSE_HI2(dy) << 2) | MSMOUSE_HI2(dx); bytes[1] |= MSMOUSE_LO6(dx); bytes[2] |= MSMOUSE_LO6(dy); /* Buttons */ bytes[0] |= (mouse->btns[INPUT_BUTTON_LEFT] ? 0x20 : 0x00); bytes[0] |= (mouse->btns[INPUT_BUTTON_RIGHT] ? 0x10 : 0x00); if (mouse->btns[INPUT_BUTTON_MIDDLE] || mouse->btnc[INPUT_BUTTON_MIDDLE]) { bytes[3] |= (mouse->btns[INPUT_BUTTON_MIDDLE] ? 0x20 : 0x00); mouse->btnc[INPUT_BUTTON_MIDDLE] = false; count = 4; } if (mouse->outlen <= sizeof(mouse->outbuf) - count) { memcpy(mouse->outbuf + mouse->outlen, bytes, count); mouse->outlen += count; } else { /* queue full -> drop event */ } }
static void msmouse_event(void *opaque, int dx, int dy, int dz, int buttons_state) { CharDriverState *chr = (CharDriverState *)opaque; unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 }; /* Movement deltas */ bytes[0] |= (MSMOUSE_HI2(dy) << 2) | MSMOUSE_HI2(dx); bytes[1] |= MSMOUSE_LO6(dx); bytes[2] |= MSMOUSE_LO6(dy); /* Buttons */ bytes[0] |= (buttons_state & 0x01 ? 0x20 : 0x00); bytes[0] |= (buttons_state & 0x02 ? 0x10 : 0x00); bytes[3] |= (buttons_state & 0x04 ? 0x20 : 0x00); /* We always send the packet of, so that we do not have to keep track of previous state of the middle button. This can potentially confuse some very old drivers for two button mice though. */ qemu_chr_be_write(chr, bytes, 4); }