8000 fix and expand the support of the window_minimized_event by InnocentusLime · Pull Request #552 · not-fl3/miniquad · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix and expand the support of the window_minimized_event #552

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion js/gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,9 @@ var importObject = {

let lastFocus = document.hasFocus();
var checkFocus = function () {
let hasFocus = document.hasFocus();
// The element doesn't loose focus when the user switches tabs.
// However, the document becomes invisible
let hasFocus = document.hasFocus() && document.visibilityState == "visible";
if (lastFocus != hasFocus) {
wasm_exports.focus(hasFocus);
lastFocus = hasFocus;
Expand Down
4 changes: 2 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ pub trait EventHandler {
fn raw_mouse_motion(&mut self, _dx: f32, _dy: f32) {}

/// Window has been minimized
/// Right now is only implemented on Android, X11 and wasm,
/// Right now is only implemented on Android, Windows, OSX, X11 and wasm,
/// On Andoid window_minimized_event is called on a Pause ndk callback
/// On X11 and wasm it will be called on focus change events.
/// On X11, OSX, Windows and wasm it will be called on focus change events.
fn window_minimized_event(&mut self) {}

/// Window has been restored
Expand Down
23 changes: 23 additions & 0 deletions src/native/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ pub fn define_cocoa_window_delegate() -> *const Class {
// Startup: the gl_context has not yet been created.
return;
}
if let Some(event_handler) = payload.context() {
event_handler.window_minimized_event();
}
unsafe {
msg_send_![payload.gl_context, update];
}
Expand Down Expand Up @@ -355,6 +358,18 @@ pub fn define_cocoa_window_delegate() -> *const Class {
}
}
}
extern "C" fn window_did_become_key(this: &Object, _: Sel, _: ObjcId) {
let payload = get_window_payload(this);
if let Some(event_handler) = payload.context() {
event_handler.window_restored_event();
}
}
extern "C" fn window_did_resign_key(this: &Object, _: Sel, _: ObjcId) {
let payload = get_window_payload(this);
if let Some(event_handler) = payload.context() {
event_handler.window_minimized_event();
}
}

let superclass = class!(NSObject);
let mut decl = ClassDecl::new("RenderWindowDelegate", superclass).unwrap();
Expand Down Expand Up @@ -390,6 +405,14 @@ pub fn define_cocoa_window_delegate() -> *const Class {
sel!(windowDidChangeOcclusionState:),
window_did_change_occlusion_state as extern "C" fn(&Object, Sel, ObjcId),
);
decl.add_method(
sel!(windowDidBecomeKey:),
window_did_become_key as extern "C" fn(&Object, Sel, ObjcId),
);
decl.add_method(
sel!(windowDidResignKey:),
window_did_resign_key as extern "C" fn(&Object, Sel, ObjcId),
);
}
// Store internal state as user data
decl.add_ivar::<*mut c_void>("display_ptr");
Expand Down
7 changes: 7 additions & 0 deletions src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@ unsafe extern "system" fn win32_wndproc(
}
}
}
WM_ACTIVATE => {
if LOWORD(wparam as _) == WA_ACTIVE || LOWORD(wparam as _) == WA_CLICKACTIVE {
event_handler.window_restored_event();
} else {
event_handler.window_minimized_event();
}
}
_ => {}
}

Expand Down
Loading
0