]> git.proxmox.com Git - mirror_qemu.git/blame - backends/msmouse.c
backends: Clean up includes
[mirror_qemu.git] / backends / msmouse.c
CommitLineData
aa71cf80
AJ
1/*
2 * QEMU Microsoft serial mouse emulation
3 *
4 * Copyright (c) 2008 Lubomir Rintel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
9c058332 24#include "qemu/osdep.h"
28ecbaee 25#include "qemu-common.h"
dccfcd0e 26#include "sysemu/char.h"
28ecbaee 27#include "ui/console.h"
aa71cf80
AJ
28
29#define MSMOUSE_LO6(n) ((n) & 0x3f)
30#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
31
32static void msmouse_event(void *opaque,
33 int dx, int dy, int dz, int buttons_state)
34{
35 CharDriverState *chr = (CharDriverState *)opaque;
36
37 unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 };
38
39 /* Movement deltas */
40 bytes[0] |= (MSMOUSE_HI2(dy) << 2) | MSMOUSE_HI2(dx);
41 bytes[1] |= MSMOUSE_LO6(dx);
42 bytes[2] |= MSMOUSE_LO6(dy);
43
44 /* Buttons */
45 bytes[0] |= (buttons_state & 0x01 ? 0x20 : 0x00);
46 bytes[0] |= (buttons_state & 0x02 ? 0x10 : 0x00);
47 bytes[3] |= (buttons_state & 0x04 ? 0x20 : 0x00);
48
49 /* We always send the packet of, so that we do not have to keep track
50 of previous state of the middle button. This can potentially confuse
51 some very old drivers for two button mice though. */
fa5efccb 52 qemu_chr_be_write(chr, bytes, 4);
aa71cf80
AJ
53}
54
55static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
56{
57 /* Ignore writes to mouse port */
58 return len;
59}
60
61static void msmouse_chr_close (struct CharDriverState *chr)
62{
7267c094 63 g_free (chr);
aa71cf80
AJ
64}
65
96d885b9
PB
66static CharDriverState *qemu_chr_open_msmouse(const char *id,
67 ChardevBackend *backend,
68 ChardevReturn *ret,
69 Error **errp)
aa71cf80 70{
d0d7708b 71 ChardevCommon *common = qapi_ChardevDummy_base(backend->u.msmouse);
aa71cf80
AJ
72 CharDriverState *chr;
73
d0d7708b
DB
74 chr = qemu_chr_alloc(common, errp);
75 if (!chr) {
76 return NULL;
77 }
aa71cf80
AJ
78 chr->chr_write = msmouse_chr_write;
79 chr->chr_close = msmouse_chr_close;
bd5c51ee 80 chr->explicit_be_open = true;
aa71cf80
AJ
81
82 qemu_add_mouse_event_handler(msmouse_event, chr, 0, "QEMU Microsoft Mouse");
83
1f51470d 84 return chr;
aa71cf80 85}
5ab8211b
AL
86
87static void register_types(void)
88{
4ca17281 89 register_char_driver("msmouse", CHARDEV_BACKEND_KIND_MSMOUSE, NULL,
96d885b9 90 qemu_chr_open_msmouse);
5ab8211b
AL
91}
92
93type_init(register_types);