MCPcopy Create free account
hub / github.com/clementgallet/libTAS / XWarpPointer

Function XWarpPointer

src/library/inputs/xpointer.cpp:152–219  ·  view source on GitHub ↗

Override */

Source from the content-addressed store, hash-verified

150}
151
152/* Override */ int XWarpPointer( Display* d, Window src_w, Window dest_w,
153 int src_x, int src_y, unsigned int src_width, unsigned int src_height,
154 int dest_x, int dest_y)
155{
156 RETURN_IF_NATIVE(XWarpPointer, (d, src_w, dest_w, src_x, src_y, src_width, src_height, dest_x, dest_y), nullptr);
157
158 LOG(LL_TRACE, LCF_MOUSE, "%s called with dest_w %d and dest_x %d and dest_y %d", __func__, dest_w, dest_x, dest_y);
159
160 /* We have to generate an MotionNotify event. */
161 if (XlibGameWindow::get()) {
162 XEvent event;
163 event.xmotion.type = MotionNotify;
164 event.xmotion.state = SingleInput::toXlibPointerMask(Inputs::game_ai.pointer.mask);
165 if (dest_w == None) {
166 /* Relative warp */
167 event.xmotion.x = Inputs::game_ai.pointer.x + dest_x;
168 event.xmotion.y = Inputs::game_ai.pointer.y + dest_y;
169 }
170 else {
171 /* Absolute warp */
172 event.xmotion.x = dest_x;
173 event.xmotion.y = dest_y;
174 }
175 event.xmotion.x_root = event.xmotion.x;
176 event.xmotion.y_root = event.xmotion.y;
177 event.xmotion.window = XlibGameWindow::get();
178
179 struct timespec time = DeterministicTimer::get().getTicks();
180 event.xmotion.time = time.tv_sec * 1000 + time.tv_nsec / 1000000;
181
182 xlibEventQueueList.insert(&event);
183 LOG(LL_DEBUG, LCF_EVENTS | LCF_MOUSE, "Generate Xlib event MotionNotify with new position (%d,%d)", Inputs::game_ai.pointer.x, Inputs::game_ai.pointer.y);
184 }
185
186 /* Update the pointer coordinates */
187 if (dest_w == None) {
188 /* Relative warp */
189 Inputs::game_ai.pointer.x += dest_x;
190 Inputs::game_ai.pointer.y += dest_y;
191 }
192 else {
193 /* Absolute warp */
194 Inputs::game_ai.pointer.x = dest_x;
195 Inputs::game_ai.pointer.y = dest_y;
196 }
197
198 if (Global::shared_config.mouse_prevent_warp) {
199 return 0; // Not sure what to return
200 }
201
202 /* When warping cursor, real and game cursor position are now synced.
203 * When mouse is disabled, we consider that the user doesn't move the mouse,
204 * so it is kept at the same position. */
205 if (Global::shared_config.mouse_support) {
206 if (dest_w == None) {
207 /* Relative warp */
208 Inputs::old_ai.pointer.x += dest_x;
209 Inputs::old_ai.pointer.y += dest_y;

Callers 1

Calls 2

getTicksMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected