Clean up dead code and fix warnings while preserving Steam drop functionality and cross-platform skeleton code
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ mod unsupported;
|
||||
|
||||
// Export the platform-specific functions
|
||||
#[cfg(windows)]
|
||||
pub use windows::{hide_system_cursor, update_cursor_image, restore_cursor, handle_mouse_move};
|
||||
pub use windows::{hide_system_cursor, update_cursor_image, restore_cursor};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos::{hide_system_cursor, update_cursor_image, restore_cursor, render_cursor};
|
||||
|
||||
@@ -5,10 +5,10 @@ use std::ptr::null_mut;
|
||||
use std::sync::atomic::Ordering;
|
||||
use winapi::{
|
||||
um::winuser::{
|
||||
GetDC, ReleaseDC, GetCursorPos, LoadCursorW, SetSystemCursor, CopyIcon,
|
||||
CreateCursor, SystemParametersInfoW, SPI_SETCURSORS, SetCursor,
|
||||
GetDC, ReleaseDC, LoadCursorW, SetSystemCursor, CopyIcon,
|
||||
SystemParametersInfoW, SPI_SETCURSORS, SetCursor,
|
||||
MAKEINTRESOURCEW, IDC_ARROW, CreateIconIndirect, ICONINFO,
|
||||
GetIconInfo, DestroyIcon,
|
||||
DestroyIcon,
|
||||
},
|
||||
um::wingdi::{
|
||||
CreateCompatibleDC, DeleteDC, SelectObject, DeleteObject,
|
||||
@@ -16,7 +16,6 @@ use winapi::{
|
||||
},
|
||||
um::consoleapi::SetConsoleCtrlHandler,
|
||||
shared::minwindef::{TRUE, FALSE, DWORD},
|
||||
shared::windef::{POINT, HBITMAP},
|
||||
};
|
||||
use ::image::{RgbaImage, open as image_open};
|
||||
|
||||
@@ -364,6 +363,8 @@ pub fn restore_cursor() {
|
||||
}
|
||||
|
||||
// Function to handle mouse movement and update the cursor
|
||||
// Kept for potential future use but currently not needed with SetSystemCursor approach
|
||||
#[allow(dead_code)]
|
||||
pub fn handle_mouse_move() {
|
||||
// With SetSystemCursor, we don't need to constantly update the cursor on mouse move
|
||||
// This function is kept for API compatibility, but it's now a no-op
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
// Windows platform mouse hook management
|
||||
|
||||
use std::ptr::null_mut;
|
||||
use std::sync::atomic::Ordering;
|
||||
use winapi::{
|
||||
um::winuser::{
|
||||
SetWindowsHookExW, UnhookWindowsHookEx, CallNextHookEx,
|
||||
WH_MOUSE_LL, HC_ACTION, MSLLHOOKSTRUCT,
|
||||
},
|
||||
um::libloaderapi::GetModuleHandleW,
|
||||
shared::minwindef::{WPARAM, LPARAM, LRESULT},
|
||||
};
|
||||
|
||||
use super::types::*;
|
||||
use super::state::*;
|
||||
|
||||
// Low-level mouse hook procedure
|
||||
pub unsafe extern "system" fn low_level_mouse_proc(n_code: i32, w_param: WPARAM, l_param: LPARAM) -> LRESULT {
|
||||
if n_code == HC_ACTION {
|
||||
// Extract mouse position from the hook struct for any mouse event
|
||||
let p_msll_hook_struct = l_param as *const MSLLHOOKSTRUCT;
|
||||
if !p_msll_hook_struct.is_null() {
|
||||
let msll_hook_struct = *p_msll_hook_struct;
|
||||
let current_pos = msll_hook_struct.pt;
|
||||
|
||||
// Store the current position for reference
|
||||
*LAST_CURSOR_POS.lock().unwrap() = Some(current_pos);
|
||||
|
||||
// We don't need to do anything special for mouse movement anymore
|
||||
// since we're using SetSystemCursor to set all system cursors
|
||||
}
|
||||
}
|
||||
|
||||
// Call the next hook in the chain.
|
||||
// Pass the HHOOK of our own hook, loaded from CURRENT_HOOK_FOR_CALLBACK.
|
||||
CallNextHookEx(
|
||||
CURRENT_HOOK_FOR_CALLBACK.load(Ordering::Relaxed) as _,
|
||||
n_code,
|
||||
w_param,
|
||||
l_param,
|
||||
)
|
||||
}
|
||||
|
||||
// Install mouse hook function
|
||||
pub fn install_mouse_hook_if_needed() -> bool {
|
||||
let mut hook_guard = MOUSE_HOOK_HANDLE.lock().unwrap();
|
||||
if hook_guard.is_none() {
|
||||
unsafe {
|
||||
// GetModuleHandleW(null_mut()) gets the HMODULE for the current process (EXE)
|
||||
// which is correct for a hook procedure within the same process.
|
||||
let h_instance = GetModuleHandleW(null_mut());
|
||||
if h_instance.is_null() {
|
||||
eprintln!("Failed to get module handle for setting mouse hook: {}", std::io::Error::last_os_error());
|
||||
return false;
|
||||
}
|
||||
|
||||
let hook = SetWindowsHookExW(
|
||||
WH_MOUSE_LL, // Hook type: Low-level mouse
|
||||
Some(low_level_mouse_proc), // Pointer to hook procedure
|
||||
h_instance, // HMODULE of the DLL containing the hook proc (or current process)
|
||||
0 // Thread ID (0 for all threads on current desktop)
|
||||
);
|
||||
|
||||
if !hook.is_null() {
|
||||
// Create wrapped handle
|
||||
let sync_hook = SyncHHOOK(hook);
|
||||
*hook_guard = Some(sync_hook);
|
||||
CURRENT_HOOK_FOR_CALLBACK.store(hook as *mut _, Ordering::SeqCst);
|
||||
println!("Low-level mouse hook installed successfully.");
|
||||
return true;
|
||||
} else {
|
||||
eprintln!("Failed to install low-level mouse hook: {}", std::io::Error::last_os_error());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true // Already installed
|
||||
}
|
||||
|
||||
// Uninstall mouse hook function
|
||||
pub fn uninstall_mouse_hook() {
|
||||
let mut hook_guard = MOUSE_HOOK_HANDLE.lock().unwrap();
|
||||
if let Some(hook_wrapper) = hook_guard.take() { // .take() removes it from Option and returns it
|
||||
unsafe {
|
||||
// Extract the raw handle using .0
|
||||
let hook = hook_wrapper.0;
|
||||
if UnhookWindowsHookEx(hook) != 0 {
|
||||
CURRENT_HOOK_FOR_CALLBACK.store(std::ptr::null_mut(), Ordering::SeqCst);
|
||||
println!("Low-level mouse hook uninstalled successfully.");
|
||||
} else {
|
||||
eprintln!("Failed to uninstall low-level mouse hook: {}", std::io::Error::last_os_error());
|
||||
// Put it back if unhooking failed, though this is unlikely.
|
||||
*hook_guard = Some(hook_wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
mod types;
|
||||
mod cursor;
|
||||
mod window;
|
||||
mod hook;
|
||||
mod state;
|
||||
|
||||
// Re-export the public API
|
||||
pub use cursor::{hide_system_cursor, update_cursor_image, restore_cursor, handle_mouse_move};
|
||||
pub use cursor::{hide_system_cursor, update_cursor_image, restore_cursor};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Windows platform state management
|
||||
|
||||
use std::sync::{Mutex, atomic::{AtomicBool, AtomicPtr}};
|
||||
use std::time::Instant;
|
||||
use std::sync::{Mutex, atomic::AtomicBool};
|
||||
use winapi::{
|
||||
shared::windef::POINT,
|
||||
shared::minwindef::DWORD,
|
||||
shared::windef::POINT,
|
||||
};
|
||||
use ::image::RgbaImage;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
@@ -25,21 +24,8 @@ pub static LAST_CURSOR_POS: Lazy<Mutex<Option<POINT>>> = Lazy::new(|| Mutex::new
|
||||
// Use Lazy<Mutex<Option<Handle>>> for WinAPI handles with our thread-safe wrappers
|
||||
pub static CUSTOM_CURSOR: Lazy<Mutex<Option<SyncHCURSOR>>> = Lazy::new(|| Mutex::new(None));
|
||||
|
||||
// Legacy variables - deprecated, no longer used with direct system cursor approach
|
||||
// Kept only for API compatibility
|
||||
#[deprecated(since = "0.2.0", note = "No longer used with direct system cursor approach")]
|
||||
pub static CURSOR_WINDOW: Lazy<Mutex<Option<SyncHWND>>> = Lazy::new(|| Mutex::new(None));
|
||||
#[deprecated(since = "0.2.0", note = "No longer used with direct system cursor approach")]
|
||||
pub static CURSOR_BITMAP: Lazy<Mutex<Option<SyncHBITMAP>>> = Lazy::new(|| Mutex::new(None));
|
||||
#[deprecated(since = "0.2.0", note = "No longer used with direct system cursor approach")]
|
||||
pub static CURSOR_DC: Lazy<Mutex<Option<SyncHDC>>> = Lazy::new(|| Mutex::new(None));
|
||||
|
||||
// Mouse hook related variables - still used for tracking cursor position
|
||||
pub static MOUSE_HOOK_HANDLE: Lazy<Mutex<Option<SyncHHOOK>>> = Lazy::new(|| Mutex::new(None));
|
||||
pub static CURRENT_HOOK_FOR_CALLBACK: AtomicPtr<std::os::raw::c_void> =
|
||||
AtomicPtr::new(std::ptr::null_mut());
|
||||
#[deprecated(since = "0.2.0", note = "No longer used with direct system cursor approach")]
|
||||
pub static LAST_MOUSE_MOVE_TIME: Lazy<Mutex<Option<Instant>>> = Lazy::new(|| Mutex::new(None));
|
||||
// Note: Legacy variables for window-based cursor approach and mouse hook tracking
|
||||
// have been removed as part of code cleanup
|
||||
|
||||
// Use OnceCell for INIT to avoid `static mut`
|
||||
pub static INIT: OnceCell<()> = OnceCell::new();
|
||||
|
||||
@@ -1,44 +1,20 @@
|
||||
// Windows platform types and constants
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use winapi::{
|
||||
shared::windef::{HWND, HCURSOR, HBITMAP, HDC, HHOOK},
|
||||
shared::windef::HCURSOR,
|
||||
shared::minwindef::DWORD,
|
||||
};
|
||||
|
||||
// --- Thread-Safe Handle Wrappers ---
|
||||
// These wrappers make raw Windows handles safe to share between threads
|
||||
|
||||
// Wrapper for HWND (window handle)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SyncHWND(pub HWND);
|
||||
unsafe impl Send for SyncHWND {}
|
||||
unsafe impl Sync for SyncHWND {}
|
||||
|
||||
// Wrapper for HCURSOR (cursor handle)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SyncHCURSOR(pub HCURSOR);
|
||||
unsafe impl Send for SyncHCURSOR {}
|
||||
unsafe impl Sync for SyncHCURSOR {}
|
||||
|
||||
// Wrapper for HBITMAP (bitmap handle)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SyncHBITMAP(pub HBITMAP);
|
||||
unsafe impl Send for SyncHBITMAP {}
|
||||
unsafe impl Sync for SyncHBITMAP {}
|
||||
|
||||
// Wrapper for HDC (device context handle)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SyncHDC(pub HDC);
|
||||
unsafe impl Send for SyncHDC {}
|
||||
unsafe impl Sync for SyncHDC {}
|
||||
|
||||
// Wrapper for HHOOK (hook handle)
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SyncHHOOK(pub HHOOK);
|
||||
unsafe impl Send for SyncHHOOK {}
|
||||
unsafe impl Sync for SyncHHOOK {}
|
||||
|
||||
// --- Constants ---
|
||||
|
||||
// Constants for SystemParametersInfo
|
||||
@@ -46,11 +22,7 @@ pub const SPI_SETCURSORS_A: u32 = 0x0057;
|
||||
pub const SPIF_UPDATEINIFILE: u32 = 0x01;
|
||||
pub const SPIF_SENDCHANGE: u32 = 0x02;
|
||||
|
||||
// Window class name for our cursor window
|
||||
pub const CURSOR_WINDOW_CLASS: &str = "CursorRushOverlay";
|
||||
|
||||
// Mouse update interval (throttle to ~120Hz)
|
||||
pub const MOUSE_UPDATE_INTERVAL: Duration = Duration::from_millis(8);
|
||||
// Note: Constants for window-based cursor approach have been removed as part of code cleanup
|
||||
|
||||
// Define all system cursor IDs we'll replace
|
||||
pub static SYSTEM_CURSORS: [DWORD; 11] = [
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Windows platform window management
|
||||
// This file is kept for compatibility but no longer creates a transparent window
|
||||
// since we're now using SetSystemCursor to set the Windows cursor directly
|
||||
|
||||
use super::types::*;
|
||||
|
||||
// Create a cursor window - now a stub function that returns None
|
||||
// since we no longer need a transparent window for the cursor
|
||||
pub unsafe fn create_cursor_window() -> Option<SyncHWND> {
|
||||
// Return None to indicate no window was created
|
||||
// This is intentional as we're now using SetSystemCursor instead
|
||||
None
|
||||
}
|
||||
Reference in New Issue
Block a user