Open at cursor location

This commit is contained in:
Elizabeth Cray 2023-07-23 18:08:38 -04:00
parent 47e6b2a125
commit 49b11741cb
5 changed files with 1051 additions and 14 deletions

1032
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
enigo = "0.1.2"
arboard = "3.2.0"
tauri-plugin-positioner = "1.0.4"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem

View File

@ -1,11 +1,18 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use enigo::{Enigo, Key, KeyboardControllable};
use enigo::{Enigo, Key, KeyboardControllable, MouseControllable};
use std::thread;
use std::time::Duration;
use arboard::Clipboard;
#[tauri::command]
fn get_mouse_pos() -> String {
let enigo = Enigo::new();
let (x, y) = enigo.mouse_location();
format!("{{ \"x\": {}, \"y\": {} }}", x, y).into()
}
#[tauri::command]
fn type_str(input: String) {
#[cfg(dev)]
@ -42,7 +49,8 @@ fn type_str(input: String) {
fn main() {
// TODO: Set Window location on launch
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![type_str])
.plugin(tauri_plugin_positioner::init())
.invoke_handler(tauri::generate_handler![type_str, get_mouse_pos])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -52,7 +52,11 @@
"windows": [
{
"fullscreen": false,
"resizable": true,
"resizable": false,
"maximizable": false,
"minimizable": false,
"alwaysOnTop": true,
"decorations": true,
"title": "Drone Input",
"width": 400,
"height": 320

View File

@ -7,7 +7,7 @@ import "./App.css";
import { Command } from '@tauri-apps/api/shell'
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faGitAlt } from "@fortawesome/free-brands-svg-icons/faGitAlt";
import { PhysicalPosition, appWindow } from "@tauri-apps/api/window";
// TODO: Keyboard usage
@ -22,6 +22,17 @@ Modal.setAppElement("#root");
function App() {
// Set window to above the mouse cursor
invoke('get_mouse_pos', {}).then((posJson: any) => {
let pos = JSON.parse(posJson);
appWindow.innerSize().then((size: any) => {
pos.y -= size.height + 32 /*Standard windows titlebar height*/;
console.log(JSON.stringify(pos));
appWindow.setPosition(new PhysicalPosition(pos.x, pos.y));
});
});
const [subTopic, setSubTopic] = useState<string>("");
const [configModalOpen, setConfigModalOpen] = useState<boolean>(false);
const [droneId, setDroneId] = useState<string>(() => {
@ -152,6 +163,7 @@ function App() {
}}
/>
</div>
{/* TODO: Optional auto-send on pre-made messages */}
</div>
<div className="row modal-footer">
<div className="col-4" onClick={() => {