Skip to content
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

is_fullscreen() #279

Open
simbleau opened this issue Dec 24, 2022 · 0 comments
Open

is_fullscreen() #279

simbleau opened this issue Dec 24, 2022 · 0 comments

Comments

@simbleau
Copy link
Contributor

simbleau commented Dec 24, 2022

Summary

We have the ability to Element::request_fullscreen, but no way to detect it.

This makes it hard to show/hide a fullscreen button.

Goal: Add a sugar function to detect if the window is fullscreen.

Motivation

It's a nightmare to figure out (with browser compatability).

Detailed Explanation

This is a translation of the top stack overflow answer: https://stackoverflow.com/questions/2863351/checking-if-browser-is-in-fullscreen

(web_sys needs Window, Screen)

    // A little bit of magic to detect if already fullscreen, translated from:
    // https://stackoverflow.com/questions/2863351/checking-if-browser-is-in-fullscreen
    let is_fullscreen = {
        let screen_top = window()
            .screen()
            .and_then(|s| s.top())
            .map(|top| JsValue::from(top))
            .map(|v| v.is_falsy());
        let screen_y = window().screen_y().map(|v| v.is_falsy());
        if let (Ok(true), Ok(true)) = (screen_top, screen_y) {
            true
        } else {
            false
        }
    };

Drawbacks, Rationale, and Alternatives

Does this design have drawbacks? Are there alternative approaches? Why is this
design the best of all designs available?

  • This is compatible for all browsers (according to the stack overflow article)

What prior art exists?

  • Not sure

Unresolved Questions

What is not clear yet? What do we expect to clarify through implementation
and/or usage experience?

I'm not sure where this would fit, API wise. Perhaps in gloo-utils.

My proposal would be to add gloo_utils::screen which is short for gloo_utils::window().screen(). This could provide a wrapped Screen which mirrors the inner, while providing additional functions such as is_fullscreen().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant