mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
pikvm/pikvm#880: Fixed mouse position at edges
This commit is contained in:
parent
5273199e0b
commit
df8898684f
@ -590,8 +590,8 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
|
|||||||
move = (self._width, self._height, to_x, to_y)
|
move = (self._width, self._height, to_x, to_y)
|
||||||
if self.__mouse_move != move:
|
if self.__mouse_move != move:
|
||||||
await self._on_mouse_move_event(
|
await self._on_mouse_move_event(
|
||||||
tools.remap(to_x, 0, self._width, *MouseRange.RANGE),
|
tools.remap(to_x, 0, self._width - 1, *MouseRange.RANGE),
|
||||||
tools.remap(to_y, 0, self._height, *MouseRange.RANGE),
|
tools.remap(to_y, 0, self._height - 1, *MouseRange.RANGE),
|
||||||
)
|
)
|
||||||
self.__mouse_move = move
|
self.__mouse_move = move
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,8 @@ from typing import TypeVar
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
def remap(value: int, in_min: int, in_max: int, out_min: int, out_max: int) -> int:
|
def remap(value: int, in_min: int, in_max: int, out_min: int, out_max: int) -> int:
|
||||||
return int((value - in_min) * (out_max - out_min) // (in_max - in_min) + out_min)
|
result = int((value - in_min) * (out_max - out_min) // ((in_max - in_min) or 1) + out_min)
|
||||||
|
return min(max(result, out_min), out_max)
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@ -380,8 +380,8 @@ export function Mouse(__getGeometry, __recordWsEvent) {
|
|||||||
if (pos !== null && (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y)) {
|
if (pos !== null && (pos.x !== __sent_pos.x || pos.y !== __sent_pos.y)) {
|
||||||
let geo = __getGeometry();
|
let geo = __getGeometry();
|
||||||
let to = {
|
let to = {
|
||||||
"x": tools.remap(pos.x, geo.x, geo.width, -32768, 32767),
|
"x": tools.remap(pos.x - geo.x, 0, geo.width - 1, -32768, 32767),
|
||||||
"y": tools.remap(pos.y, geo.y, geo.height, -32768, 32767),
|
"y": tools.remap(pos.y - geo.y, 0, geo.height - 1, -32768, 32767),
|
||||||
};
|
};
|
||||||
tools.debug("Mouse: moved:", to);
|
tools.debug("Mouse: moved:", to);
|
||||||
__sendEvent("mouse_move", {"to": to});
|
__sendEvent("mouse_move", {"to": to});
|
||||||
|
|||||||
@ -137,10 +137,10 @@ export function Ocr(__getGeometry) {
|
|||||||
let rel_bottom = Math.max(__start_pos.y, __end_pos.y) - rect.top + offset;
|
let rel_bottom = Math.max(__start_pos.y, __end_pos.y) - rect.top + offset;
|
||||||
let geo = __getGeometry();
|
let geo = __getGeometry();
|
||||||
__sel = {
|
__sel = {
|
||||||
"left": tools.remap(rel_left, geo.x, geo.width, 0, geo.real_width),
|
"left": tools.remap(rel_left - geo.x, 0, geo.width, 0, geo.real_width),
|
||||||
"right": tools.remap(rel_right, geo.x, geo.width, 0, geo.real_width),
|
"right": tools.remap(rel_right - geo.x, 0, geo.width, 0, geo.real_width),
|
||||||
"top": tools.remap(rel_top, geo.y, geo.height, 0, geo.real_height),
|
"top": tools.remap(rel_top - geo.y, 0, geo.height, 0, geo.real_height),
|
||||||
"bottom": tools.remap(rel_bottom, geo.y, geo.height, 0, geo.real_height),
|
"bottom": tools.remap(rel_bottom - geo.y, 0, geo.height, 0, geo.real_height),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
__sel = null;
|
__sel = null;
|
||||||
|
|||||||
@ -136,14 +136,9 @@ export var tools = new function() {
|
|||||||
return `${hours}:${mins}:${secs}.${millis}`;
|
return `${hours}:${mins}:${secs}.${millis}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.remap = function(x, a1, b1, a2, b2) {
|
self.remap = function(value, in_min, in_max, out_min, out_max) {
|
||||||
let remapped = Math.round((x - a1) / b1 * (b2 - a2) + a2);
|
let result = Math.round((value - in_min) * (out_max - out_min) / ((in_max - in_min) || 1) + out_min);
|
||||||
if (remapped < a2) {
|
return Math.min(Math.max(result, out_min), out_max);
|
||||||
return a2;
|
|
||||||
} else if (remapped > b2) {
|
|
||||||
return b2;
|
|
||||||
}
|
|
||||||
return remapped;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.getRandomInt = function(min, max) {
|
self.getRandomInt = function(min, max) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user