2018-08-15 04:07:33 +03:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2018 K. Lange
|
|
|
|
*
|
|
|
|
* toggle-abs-mouse - Toggle mouse modes
|
|
|
|
*
|
|
|
|
* Set the mouse mode under VirtualBox, VMware, or QEMU to either
|
|
|
|
* relative or absolute via ioctl to the relevant absolute mouse
|
|
|
|
* device driver interface.
|
|
|
|
*/
|
2018-08-04 02:41:08 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
if (argc < 2) {
|
2018-11-27 14:40:46 +03:00
|
|
|
fprintf(stderr, "%s: argument (relative, absolute, get) expected\n", argv[0]);
|
2018-08-04 02:41:08 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = open("/dev/absmouse",O_WRONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
/* try vmmouse */
|
|
|
|
fd = open("/dev/vmmouse",O_WRONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "%s: no valid mouse interface found.\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int flag = 0;
|
|
|
|
if (!strcmp(argv[1],"relative")) {
|
|
|
|
flag = 1;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[1],"absolute")) {
|
|
|
|
flag = 2;
|
|
|
|
}
|
2018-11-27 14:40:46 +03:00
|
|
|
if (!strcmp(argv[1],"get")) {
|
|
|
|
flag = 3;
|
|
|
|
}
|
2018-08-04 02:41:08 +03:00
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
fprintf(stderr, "%s: invalid argument\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-27 14:40:46 +03:00
|
|
|
int result = ioctl(fd, flag, NULL);
|
|
|
|
|
|
|
|
if (flag == 3) {
|
|
|
|
if (result == 0) {
|
|
|
|
fprintf(stdout, "relative\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stdout, "absolute\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-08-04 02:41:08 +03:00
|
|
|
}
|