Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Monitor::from_point and Monitor::cursor_position #3057

Closed
OceanBelongsToMe opened this issue Dec 11, 2021 · 5 comments · Fixed by #9770
Closed

[feat] Monitor::from_point and Monitor::cursor_position #3057

OceanBelongsToMe opened this issue Dec 11, 2021 · 5 comments · Fixed by #9770
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: feature request

Comments

@OceanBelongsToMe
Copy link

OceanBelongsToMe commented Dec 11, 2021

Describe the bug

I have two available monitor, and I want to display the window on the current display,but the window.current_monitor() method does not seem to return the display screen where the mouse is located
It seems that the form always appears in the main display!
this is my code:

#[tauri::command]
fn register(app_handle: AppHandle, window: Window) {
  app_handle
    .global_shortcut_manager()
    .register("CTRL + U", move || {
      if window.is_visible().unwrap() {
        window.hide().unwrap();
      } else {
        println!("New version available: {:?}", window.available_monitors());
        window.center().unwrap();
        window.show().unwrap();
        window.set_focus().unwrap();
      }
    })
    .unwrap();
}

Platform and Versions (required):

➜  power-clip git:(master) ✗ tauri info
 app:spawn Running "/Users/ocean/Documents/workplace/mystudywork/rust/github/tauri/tooling/cli.js/bin/tauri-cli tauri info" +0ms


Operating System - Mac OS, version 11.6.1 X64

Node.js environment
  Node.js - 16.13.0
  @tauri-apps/cli - 1.0.0-beta.10
  @tauri-apps/api - 1.0.0-beta.8

Global packages
  npm - 8.1.0
  yarn - 1.22.17

Rust environment
  rustc - 1.57.0
  cargo - 1.57.0

App directory structure
/dist
/target
/node_modules
/src-tauri
/.git
/.idea
/src

App

  tauri.rs - 1.0.0-beta.8
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://localhost:10001/
  bundler - Rollup

Additional context

this is my monitors

Ok([Monitor { name: Some("Monitor #41012"), size: PhysicalSize { width: 2880, height: 1800 }, position: PhysicalPosition { x: 0, y: 0 }, scale_factor: 2.0 }, Monitor { name: Some("Monitor #30471"), size: PhysicalSize { width: 3840, height: 2160 }, position: PhysicalPosition { x: 0, y: -2160 }, scale_factor: 2.0 }])
@lucasfernog
Copy link
Member

The current_monitor API returns the monitor on which the window currently resides. It has nothing to do with where the mouse is located.

@OceanBelongsToMe
Copy link
Author

Yeah, I looked at the api again, it is indeed the monitor where the form is returned, so there is no api that can return the position of the mouse?

@lucasfernog
Copy link
Member

We do have it on tao and we could expose it here, but it wouldn't solve your problem since it doesn't give any information about the monitor of the mouse position.

@OceanBelongsToMe
Copy link
Author

Can you expose that? Maybe I can calculate the relevant information from the mouse position and monitor coordinates :)

@amrbashir amrbashir changed the title window.center() can not move the window to the real current monitor [feat] Monitor::from_point and Monitor::cursor_position Feb 2, 2022
@amrbashir amrbashir added status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: feature request and removed type: bug labels Feb 2, 2022
@amrbashir
Copy link
Member

amrbashir commented Feb 2, 2022

needs tauri-apps/tao#186 and tauri-apps/tao#187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: feature request
Projects
Status: 📬Proposal
Development

Successfully merging a pull request may close this issue.

3 participants