feat: runs the selected program on the previously focused display if the display argument was provided
This commit is contained in:
@@ -26,6 +26,7 @@ pub struct Runner {
|
|||||||
input: String,
|
input: String,
|
||||||
window_size: (u32, u32),
|
window_size: (u32, u32),
|
||||||
settings: RunnerMenuSettings,
|
settings: RunnerMenuSettings,
|
||||||
|
target_display_index: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runner {
|
impl Runner {
|
||||||
@@ -83,6 +84,7 @@ impl Runner {
|
|||||||
let window = video
|
let window = video
|
||||||
.window("Practical runner", window_width, window_height)
|
.window("Practical runner", window_width, window_height)
|
||||||
.borderless()
|
.borderless()
|
||||||
|
.position_centered()
|
||||||
.always_on_top()
|
.always_on_top()
|
||||||
.build()
|
.build()
|
||||||
.expect("Error creating window");
|
.expect("Error creating window");
|
||||||
@@ -90,12 +92,32 @@ impl Runner {
|
|||||||
let mut canvas = window.into_canvas().build().expect("Error creating canvas");
|
let mut canvas = window.into_canvas().build().expect("Error creating canvas");
|
||||||
|
|
||||||
canvas.present();
|
canvas.present();
|
||||||
|
|
||||||
|
// If we don't call this before window.display_index() it always returns 0
|
||||||
|
let _ = context
|
||||||
|
.event_pump()
|
||||||
|
.expect("Error getting SDL event pump")
|
||||||
|
.poll_iter()
|
||||||
|
.count();
|
||||||
|
|
||||||
|
let target_display_index = if settings.display_index.is_some() {
|
||||||
|
Some(
|
||||||
|
canvas
|
||||||
|
.window()
|
||||||
|
.display_index()
|
||||||
|
.expect("Error getting window display index"),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
if window_x.ne(&0) || window_y.ne(&0) {
|
if window_x.ne(&0) || window_y.ne(&0) {
|
||||||
canvas.window_mut().set_position(
|
canvas.window_mut().set_position(
|
||||||
sdl2::video::WindowPos::Positioned(window_x),
|
sdl2::video::WindowPos::Positioned(window_x),
|
||||||
sdl2::video::WindowPos::Positioned(window_y),
|
sdl2::video::WindowPos::Positioned(window_y),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.window_mut().raise();
|
canvas.window_mut().raise();
|
||||||
|
|
||||||
let mut cloned_executables = executables.clone();
|
let mut cloned_executables = executables.clone();
|
||||||
@@ -111,6 +133,7 @@ impl Runner {
|
|||||||
window_size: (window_width, window_height),
|
window_size: (window_width, window_height),
|
||||||
settings,
|
settings,
|
||||||
font_path,
|
font_path,
|
||||||
|
target_display_index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,12 +352,33 @@ impl Runner {
|
|||||||
|
|
||||||
self.canvas.present();
|
self.canvas.present();
|
||||||
|
|
||||||
std::thread::sleep(Duration::from_millis(8))
|
std::thread::sleep(Duration::from_millis(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.input.is_empty() {
|
if self.input.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
match self.target_display_index {
|
||||||
|
Some(target_display_index) => {
|
||||||
|
let window = self.canvas.window_mut();
|
||||||
|
let target_display_bounds = self
|
||||||
|
.context
|
||||||
|
.video()
|
||||||
|
.expect("Error getting SDL video")
|
||||||
|
.display_bounds(target_display_index)
|
||||||
|
.expect("Error getting target display bounds");
|
||||||
|
|
||||||
|
window.set_position(
|
||||||
|
sdl2::video::WindowPos::Positioned(target_display_bounds.x()),
|
||||||
|
sdl2::video::WindowPos::Positioned(target_display_bounds.y()),
|
||||||
|
);
|
||||||
|
|
||||||
|
window.raise();
|
||||||
|
window.hide();
|
||||||
|
}
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
Some(self.input.clone())
|
Some(self.input.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user