8000 Window focus events by jusax23 · Pull Request #369 · not-fl3/miniquad · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Window focus events #369

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 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions js/gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,18 @@ var importObject = {
wasm_exports.on_files_dropped_finish();
};

let lastFocus = document.hasFocus();
var checkFocus = function() {
let hasFocus = document.hasFocus();
if(lastFocus == hasFocus){
wasm_exports.focus(hasFocus);
lastFocus = hasFocus;
}
}
document.addEventListener("visibilitychange", checkFocus);
window.addEventListener("focus", checkFocus);
window.addEventListener("blur", checkFocus);

window.requestAnimationFrame(animation);
},

Expand Down
8 changes: 6 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,15 @@ pub trait EventHandler {
fn raw_mouse_motion(&mut self, _ctx: &mut Context, _dx: f32, _dy: f32) {}

/// Window has been minimized
/// Right now is only implemented on Android, and is called on a Pause ndk callback
/// Right now is only implemented on Android, 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.
fn window_minimized_event(&mut self, _ctx: &mut Context) {}

/// Window has been restored
/// Right now is only implemented on Android, and is called on a Resume ndk callback
/// Right now is only implemented on Android, 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.
fn window_restored_event(&mut self, _ctx: &mut Context) {}

/// This event is sent when the userclicks the window's close button
Expand Down
6 changes: 6 additions & 0 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ impl X11Display {
let y = (*event).xmotion.y as libc::c_float;
event_handler.mouse_motion_event(context.with_display(&mut *self), x, y);
}
9 => {
event_handler.window_restored_event(context.with_display(&mut *self));
}
10 => {
event_handler.window_minimized_event(context.with_display(&mut *self));
}
22 => {
if (*event).xconfigure.width != self.data.screen_width
|| (*event).xconfigure.height != self.data.screen_height
Expand Down
16 changes: 16 additions & 0 deletions src/native/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,22 @@ pub extern "C" fn touch(phase: u32, id: u32, x: f32, y: f32) {
});
}

#[no_mangle]
pub extern "C" fn focus(hasFocus: bool) {
with(|globals| {
if hasFocus {
globals.event_handler.window_restored_event(
globals.context.with_display(&mut globals.display)
);
} else {
globals.event_handler.window_minimized_event(
globals.context.with_display(&mut globals.display)
);
}

});
}

#[no_mangle]
pub extern "C" fn on_files_dropped_start() {
with(|globals| {
Expand Down
0