toggle-abs-mouse.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2018 K. Lange
  5. *
  6. * toggle-abs-mouse - Toggle mouse modes
  7. *
  8. * Set the mouse mode under VirtualBox, VMware, or QEMU to either
  9. * relative or absolute via ioctl to the relevant absolute mouse
  10. * device driver interface.
  11. */
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <unistd.h>
  15. #include <fcntl.h>
  16. #include <sys/ioctl.h>
  17. int main(int argc, char * argv[]) {
  18. if (argc < 2) {
  19. fprintf(stderr, "%s: argument (relative or absolute) expected\n", argv[0]);
  20. return 1;
  21. }
  22. int fd = open("/dev/absmouse",O_WRONLY);
  23. if (fd < 0) {
  24. /* try vmmouse */
  25. fd = open("/dev/vmmouse",O_WRONLY);
  26. if (fd < 0) {
  27. fprintf(stderr, "%s: no valid mouse interface found.\n", argv[0]);
  28. return 1;
  29. }
  30. }
  31. int flag = 0;
  32. if (!strcmp(argv[1],"relative")) {
  33. flag = 1;
  34. }
  35. if (!strcmp(argv[1],"absolute")) {
  36. flag = 2;
  37. }
  38. if (!flag) {
  39. fprintf(stderr, "%s: invalid argument\n", argv[0]);
  40. return 1;
  41. }
  42. ioctl(fd, flag, NULL);
  43. }