Skip to content

Commit 7fc91f8

Browse files
author
danalec
committed
linux: emulate relative mouse movement from absolute coordinates
1 parent 6ad5f97 commit 7fc91f8

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/input.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ namespace input {
270270

271271
input::touch_port_t touch_port; ///< Touch coordinate bounds for the current stream.
272272

273+
bool abs_mouse_initialized = false; ///< Whether the absolute mouse baseline is set.
274+
float last_abs_x = 0; ///< Last absolute mouse X in host coordinates.
275+
float last_abs_y = 0; ///< Last absolute mouse Y in host coordinates.
276+
273277
int32_t accumulated_vscroll_delta; ///< Accumulated vscroll delta.
274278
int32_t accumulated_hscroll_delta; ///< Accumulated hscroll delta.
275279
};
@@ -830,7 +834,25 @@ namespace input {
830834
touch_port_dim_y
831835
};
832836

833-
platf::abs_mouse(platf_input, abs_port, tpcoords->first, tpcoords->second);
837+
// Emulate relative mouse movement from absolute coordinates.
838+
// Absolute motion arrives as PointerMotionAbsolute in the compositor, which
839+
// moves the cursor but does NOT update the screen magnifier focal point
840+
// (pop-os/cosmic-comp #2760). The first event still places the cursor
841+
// absolutely; subsequent events are converted to relative deltas so the
842+
// magnifier tracks the cursor.
843+
if (input->abs_mouse_initialized) {
844+
platf::move_mouse(
845+
platf_input,
846+
(int)(tpcoords->first - input->last_abs_x),
847+
(int)(tpcoords->second - input->last_abs_y)
848+
);
849+
} else {
850+
platf::abs_mouse(platf_input, abs_port, tpcoords->first, tpcoords->second);
851+
input->abs_mouse_initialized = true;
852+
}
853+
854+
input->last_abs_x = tpcoords->first;
855+
input->last_abs_y = tpcoords->second;
834856
}
835857

836858
/**

0 commit comments

Comments
 (0)