Skip to content

Commit

Permalink
fix: 0.2.1
Browse files Browse the repository at this point in the history
use relative (Client) Win32 API
fix absolute mode
  • Loading branch information
BlueGlassBlock committed Dec 19, 2023
1 parent fc6d414 commit 9af3a9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ crate-type = ["lib", "cdylib"]

[dependencies]
once_cell = "1.18.0"
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_System_WindowsProgramming", "Win32_UI_Input_KeyboardAndMouse", "Win32_System_Diagnostics_Debug", "Win32_System_Threading", "Win32_UI_Input_Pointer"] }
windows = { version = "0.52.0", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_System_WindowsProgramming", "Win32_UI_Input_KeyboardAndMouse", "Win32_System_Diagnostics_Debug", "Win32_System_Threading", "Win32_UI_Input_Pointer", "Win32_Graphics_Gdi"] }
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TouccaMode {
let mut res = vec![];
for (i, (st, end)) in ranges.iter().enumerate() {
if *st <= ring && ring <= *end {
res.push(Self::map_section_and_ring(i, ring));
res.push(Self::map_section_and_ring(section, i));
dprintln!("{} {} -> {}", section, i, res.last().unwrap());
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use utils::{lo_word, DebugUnwrap};
use windows::core::*;
use windows::Win32::Foundation::*;
use windows::Win32::System::Threading::*;
use windows::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState;
use windows::Win32::Graphics::Gdi::*;
use windows::Win32::UI::Input::KeyboardAndMouse::*;
use windows::Win32::UI::Input::Pointer::*;
use windows::Win32::UI::WindowsAndMessaging::*;

Expand Down Expand Up @@ -145,7 +146,7 @@ unsafe fn get_window_handle() -> HWND {
EnumWindows(Some(_enum_window), LPARAM(proc_id as isize)).dbg_unwrap();
dprintln!("Get window handle: {:?}", _HWND);
let mut guard = _WINDOW_RECT.lock().dbg_unwrap();
GetWindowRect(_HWND, &mut *guard).dbg_unwrap();
GetClientRect(_HWND, &mut *guard).dbg_unwrap();
drop(guard);
_HWND
}
Expand All @@ -168,6 +169,7 @@ fn update_pointer(_: HWND, param: WPARAM) {
if GetPointerInfo(lo_word(param) as u32, &mut ptr_info).is_err() {
return;
}
ScreenToClient(ptr_info.hwndTarget, &mut ptr_info.ptPixelLocation);
}
let mut guard = _ACTIVE_POINTERS.lock().dbg_unwrap();
if (ptr_info.pointerFlags & POINTER_FLAG_FIRSTBUTTON).0 == 0 {
Expand Down Expand Up @@ -197,8 +199,8 @@ const WM_WINDOW_CHANGED_LIST: [u32; 2] = [WM_MOVE, WM_SIZE];
fn update_window_rect(hwnd: HWND, _: LPARAM) {
let mut rect: RECT = RECT::default();
unsafe {
// Safety: GetWindowRect is safe-ish
if let Err(e) = GetWindowRect(hwnd, &mut rect) {
// Safety: GetClientRect is safe-ish
if let Err(e) = GetClientRect(hwnd, &mut rect) {
dprintln!("Toucca update window rect error: {:?}", e);
return;
}
Expand Down Expand Up @@ -258,6 +260,7 @@ fn parse_point(ptr_id: u32, abs_x: f64, abs_y: f64) -> Vec<usize> {
(rect.right + rect.left) as f64 / 2.0,
(rect.bottom + rect.top) as f64 / 2.0,
);
dprintln!(dbg, "Got center {}, {}", center.0, center.1);
let radius = std::cmp::min(rect.right - rect.left, rect.bottom - rect.top) as f64 / 2.0
+ radius_compensation;
let (rel_x, rel_y): (f64, f64) = (abs_x - center.0, center.1 - abs_y); // use center.y - abs_y to get Cartesian coordinate
Expand Down

0 comments on commit 9af3a9a

Please sign in to comment.