Fix hanging when minimised on OSX
This commit is contained in:
@@ -35,3 +35,7 @@ winresource = "0.1"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc2 = "0.6.4"
|
||||
objc2-app-kit = { version = "0.3.2", default-features = false, features = ["std", "NSApplication", "NSResponder"] }
|
||||
|
||||
+14
-1
@@ -238,7 +238,7 @@ fn window_controls(ui: &mut Ui, area: Rect) {
|
||||
ui.painter().text(r.center(), Align2::CENTER_CENTER, glyph, egui::FontId::proportional(14.0), c);
|
||||
if resp.clicked() {
|
||||
match k {
|
||||
0 => ctx.send_viewport_cmd(ViewportCommand::Minimized(true)),
|
||||
0 => minimize_window(&ctx),
|
||||
1 => ctx.send_viewport_cmd(ViewportCommand::Maximized(!max)),
|
||||
_ => ctx.send_viewport_cmd(ViewportCommand::Close),
|
||||
}
|
||||
@@ -246,6 +246,19 @@ fn window_controls(ui: &mut Ui, area: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
/// `ViewportCommand::Minimized(true)` can leave eframe unresponsive after restore on macOS.
|
||||
/// Hiding the app follows the normal macOS app lifecycle and avoids that minimize event path.
|
||||
fn minimize_window(_ctx: &egui::Context) {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
if let Some(mtm) = objc2::MainThreadMarker::new() {
|
||||
objc2_app_kit::NSApplication::sharedApplication(mtm).hide(None);
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
_ctx.send_viewport_cmd(ViewportCommand::Minimized(true));
|
||||
}
|
||||
|
||||
/// Invisible window edges that resize the undecorated window.
|
||||
pub fn resize_edges(ctx: &egui::Context) {
|
||||
use egui::{CursorIcon, ResizeDirection as D};
|
||||
|
||||
Reference in New Issue
Block a user