Browse Source

toggle-relative-mouse: add query option 'get'

K. Lange 2 years ago
parent
commit
aca47b862b
3 changed files with 21 additions and 2 deletions
  1. 16 2
      apps/toggle-abs-mouse.c
  2. 3 0
      modules/vbox.c
  3. 2 0
      modules/vmware.c

+ 16 - 2
apps/toggle-abs-mouse.c

@@ -17,7 +17,7 @@
 
 int main(int argc, char * argv[]) {
 	if (argc < 2) {
-		fprintf(stderr, "%s: argument (relative or absolute) expected\n", argv[0]);
+		fprintf(stderr, "%s: argument (relative, absolute, get) expected\n", argv[0]);
 		return 1;
 	}
 
@@ -38,11 +38,25 @@ int main(int argc, char * argv[]) {
 	if (!strcmp(argv[1],"absolute")) {
 		flag = 2;
 	}
+	if (!strcmp(argv[1],"get")) {
+		flag = 3;
+	}
 
 	if (!flag) {
 		fprintf(stderr, "%s: invalid argument\n", argv[0]);
 		return 1;
 	}
 
-	ioctl(fd, flag, NULL);
+	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;
 }

+ 3 - 0
modules/vbox.c

@@ -216,6 +216,9 @@ static int ioctl_mouse(fs_node_t * node, int request, void * argp) {
 		mouse_on_off(VBOX_MOUSE_ON);
 		return 0;
 	}
+	if (request == 3) {
+		return mouse_state == (VBOX_MOUSE_ON);
+	}
 	return -1;
 }
 

+ 2 - 0
modules/vmware.c

@@ -472,6 +472,8 @@ static int ioctl_mouse(fs_node_t * node, int request, void * argp) {
 			ps2_mouse_alternate = vmware_mouse;
 			mouse_absolute();
 			return 0;
+		case 3:
+			return ps2_mouse_alternate == vmware_mouse;
 		default:
 			return -EINVAL;
 	}