Skip to content

Commit

Permalink
feat: 窗口显示兼容 win 鼠标跟随 #8 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangelckc authored Jun 25, 2024
1 parent 4de6f41 commit 9f5847e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 48 deletions.
50 changes: 12 additions & 38 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tauri-plugin-sql = { git = "https://github.com/tauri-apps/plugins-workspace", br
window-shadows = "0.2.2"
clipboard-rs = "0.1.7"
tauri-plugin-context-menu = { git = "https://github.com/c2r0b/tauri-plugin-context-menu", branch = "main" }
device_query = "2.1.0"
mouse_position = "0.1.4"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
15 changes: 8 additions & 7 deletions src-tauri/src/plugins/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use device_query::{DeviceQuery, DeviceState};
use mouse_position::mouse_position::Mouse;

use tauri::{
command, generate_handler,
plugin::{Builder, TauriPlugin},
Result, Wry,
Result, Wry,Error
};

#[command]
async fn get_mouse_coords() -> Result<(i32, i32)> {
let device_state = DeviceState::new();

let mouse = device_state.get_mouse();

Ok(mouse.coords)
let position = Mouse::get_mouse_position();
match position {
Mouse::Position { x, y } => {Ok((x,y))},
Mouse::Error => Err(Error::InvokeKey),
}
}

pub fn init() -> TauriPlugin<Wry> {
Expand Down
6 changes: 4 additions & 2 deletions src/pages/Clipboard/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ const ClipboardHistory = () => {
size: { width: screenWidth, height: screenHeight },
} = monitor;

x = Math.min(x * scaleFactor, screenWidth - width);
y = Math.min(y * scaleFactor, screenHeight - height);
const factor = (await isWin()) ? 1 : scaleFactor;

x = Math.min(x * factor, screenWidth - width);
y = Math.min(y * factor, screenHeight - height);

appWindow.setPosition(new PhysicalPosition(x, y));
} else if (windowPosition === "center") {
Expand Down

0 comments on commit 9f5847e

Please sign in to comment.