ScenicFramework / scenic

Core Scenic library
Apache License 2.0
1.99k stars 137 forks source link

Starting the app in full screen #256

Closed jakzal closed 11 months ago

jakzal commented 2 years ago

What problem does this feature solve?

I'm building a digital frame app. I'm missing a functionality in Scenic to start the app in full screen. I wasn't able to find a workaround.

It feels to be a rather critical feature for kiosk-type devices.

Furthermore, I'd like the frame to be run on multiple screen sizes without the need to build a new version. It seems to go against scenic's principles. Perhaps it's not the right tool for my use case?

What is your proposed solution?

In the configuration, specify the fullscreen flag instead of the actual size:

use Mix.Config

# Configure the main viewport for the Scenic application
config :frame, :viewport, %{
  name: :main_viewport,
  fullscreen: true,
  # size: {1024, 800},
  default_scene: {Frame.Scene.Home, nil},
  drivers: [
    %{
      module: Scenic.Driver.Glfw,
      name: :glfw,
      opts: [resizeable: true, title: "frame"]
    }
  ]
}

Ideally, it should be possible to query the actual size of the screen. In my case it would be useful to define image boundaries.

Currently ViewPort.info(viewport) seems to be returning the configured size rather than the actual size. Specifically, after resizing the window ViewPort.info(viewport) returns the configured size instead of the one after resizing.

vacarsu commented 2 years ago

Depending on the system you're building on, this could already be possible. If you're using a linux system you can use x11 and OpenBox, and just set the window of your specific app to run in borderless window. This will give your app the feeling of fullscreen. This is how I currently achieve this.

As far as querying the viewport, this is already possible. The viewport struct lives on the scene struct. You can access the size of the viewport at %Scenic.Scene{viewport: %{size: {width, height}}}

There is also a input message for when the viewport gets reshaped (resized). In your init function (where you subscribe to the input depends on your specific use case) you can request or capture the input with request_input(scene, [:viewport]) or capture_input(scene, [:viewport]).

Next add the handle_input/3 function.

def handle_input({:viewport, {:reshape, {w, h}}}, _, scene) do
  {:noreply, assign(scene, v_width: w, v_height: h)}
end
crertel commented 11 months ago

Closing this out for now; let us know if you need more help!