Skip to content

Commit e5287b6

Browse files
committed
Add consistent command line option for position of mousemove
1 parent a6f9c1a commit e5287b6

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

Client/tool_mousemove.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@
3838

3939
static void show_help() {
4040
puts(
41-
"Usage: mousemove [OPTION]... -- <xpos> <ypos>\n"
41+
"Usage: mousemove [OPTION]... [-x <xpos> -y <ypos>] [-- <xpos> <ypos>]\n"
4242
"Move mouse pointer or wheel.\n"
4343
"\n"
4444
"Options:\n"
4545
" -w, --wheel Move mouse wheel relatively\n"
4646
" -a, --absolute Use absolute position, not applicable to wheel\n"
47+
" -x, --xpos X position\n"
48+
" -y, --ypos Y position\n"
4749
" -h, --help Display this help and exit\n"
50+
"\n"
51+
"You need to disable mouse speed acceleration for correct absolute movement."
4852
);
4953
}
5054

@@ -57,19 +61,24 @@ int tool_mousemove(int argc, char **argv) {
5761
int is_abs = 0;
5862
int is_wheel = 0;
5963

64+
int i = 0;
65+
int32_t pos[2] = {0, 0};
66+
6067
while (1) {
6168
int c;
6269

6370
static struct option long_options[] = {
6471
{"absolute", no_argument, 0, 'a'},
6572
{"help", no_argument, 0, 'h'},
6673
{"wheel", no_argument, 0, 'w'},
74+
{"xpos", required_argument, 0, 'x'},
75+
{"ypos", required_argument, 0, 'y'},
6776
{0, 0, 0, 0}
6877
};
6978
/* getopt_long stores the option index here. */
7079
int option_index = 0;
7180

72-
c = getopt_long (argc, argv, "haw",
81+
c = getopt_long (argc, argv, "hawx:y:",
7382
long_options, &option_index);
7483

7584
/* Detect the end of the options. */
@@ -97,6 +106,14 @@ int tool_mousemove(int argc, char **argv) {
97106
case 'w':
98107
is_wheel = 1;
99108
break;
109+
case 'x':
110+
pos[0] = strtol(optarg, NULL, 10);
111+
i++;
112+
break;
113+
case 'y':
114+
pos[1] = strtol(optarg, NULL, 10);
115+
i++;
116+
break;
100117

101118
case '?':
102119
/* getopt_long already printed an error message. */
@@ -107,12 +124,11 @@ int tool_mousemove(int argc, char **argv) {
107124
}
108125
}
109126

110-
int i = 0;
111-
int32_t arg[2] = {0, 0};
127+
112128

113129
if (optind < argc) {
114130
while (optind < argc) {
115-
arg[i] = strtol(argv[optind++], NULL, 10);
131+
pos[i] = strtol(argv[optind++], NULL, 10);
116132
i++;
117133
}
118134
}
@@ -129,11 +145,11 @@ int tool_mousemove(int argc, char **argv) {
129145
}
130146

131147
if (is_wheel) {
132-
uinput_emit(EV_REL, REL_HWHEEL, arg[0], 0);
133-
uinput_emit(EV_REL, REL_WHEEL, arg[1], 1);
148+
uinput_emit(EV_REL, REL_HWHEEL, pos[0], 0);
149+
uinput_emit(EV_REL, REL_WHEEL, pos[1], 1);
134150
} else {
135-
uinput_emit(EV_REL, REL_X, arg[0], 0);
136-
uinput_emit(EV_REL, REL_Y, arg[1], 1);
151+
uinput_emit(EV_REL, REL_X, pos[0], 0);
152+
uinput_emit(EV_REL, REL_Y, pos[1], 1);
137153
}
138154
} else {
139155
show_help();

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Close a window in graphical environment (Alt+F4):
6060

6161
Relatively move mouse pointer to -100,100:
6262

63-
ydotool mousemove -- -100 100
63+
ydotool mousemove -x -100 -y 100
6464

6565
Move mouse pointer to 100,100:
6666

67-
ydotool mousemove --absolute -- 100 100
67+
ydotool mousemove --absolute -x 100 -y 100
6868

6969
Mouse right click:
7070

0 commit comments

Comments
 (0)