@@ -6,10 +6,14 @@ use std::{
66} ;
77
88use global_hotkey:: hotkey:: Code ;
9- use iced:: widget:: image:: Handle ;
9+ use iced:: { futures :: io :: Window , widget:: image:: Handle } ;
1010use icns:: IconFamily ;
1111use image:: RgbaImage ;
1212use rayon:: iter:: { IntoParallelIterator , ParallelIterator } ;
13+ use windows:: Win32 :: {
14+ Graphics :: Gdi :: MonitorFromPoint ,
15+ UI :: WindowsAndMessaging :: { GetCursor , GetCursorPos } ,
16+ } ;
1317
1418use crate :: { app:: App , commands:: Function } ;
1519
@@ -373,3 +377,35 @@ pub fn open_application(path: &String) {
373377 Command :: new ( "xdg-open" ) . arg ( path) . status ( ) . ok ( ) ;
374378 }
375379}
380+
381+ struct WindowPos {
382+ x : f32 ,
383+ y : f32 ,
384+ }
385+
386+ use crate :: app:: { DEFAULT_WINDOW_HEIGHT , WINDOW_WIDTH } ;
387+ pub fn open_on_focused_monitor ( ) -> iced:: Point {
388+ use windows:: Win32 :: Foundation :: POINT ;
389+ use windows:: Win32 :: Graphics :: Gdi :: {
390+ GetMonitorInfoW , MONITOR_DEFAULTTONEAREST , MONITORINFO , MonitorFromPoint ,
391+ } ;
392+ let mut point = POINT { x : 0 , y : 0 } ;
393+ let mut monitor_info = MONITORINFO {
394+ cbSize : std:: mem:: size_of :: < MONITORINFO > ( ) as u32 ,
395+ ..Default :: default ( )
396+ } ;
397+
398+ let cursor = unsafe { GetCursorPos ( & mut point) } ;
399+ let monitor = unsafe { MonitorFromPoint ( point, MONITOR_DEFAULTTONEAREST ) } ;
400+ let monitor_infos = unsafe { GetMonitorInfoW ( monitor, & mut monitor_info) } ;
401+
402+ let monitor_width = monitor_info. rcMonitor . right - monitor_info. rcMonitor . left ;
403+ let monitor_height = monitor_info. rcMonitor . bottom - monitor_info. rcMonitor . top ;
404+ let window_width = WINDOW_WIDTH ;
405+ let window_height = DEFAULT_WINDOW_HEIGHT ;
406+
407+ let x = monitor_info. rcMonitor . left as f32 + ( monitor_width as f32 - window_width) / 2.0 ;
408+ let y = monitor_info. rcMonitor . top as f32 + ( monitor_height as f32 - window_height) / 2.0 ;
409+
410+ return iced:: Point { x, y } ;
411+ }
0 commit comments