Fl4m3Ph03n1x
How to get Screen size in elixir?
Background
I am working on an Elixir desktop application, and I need it to adapt to the monitor/screen size of the user.
Using Elixir Desktop (GitHub - elixir-desktop/desktop: Building Local-First apps for Windows, MacOS, Linux, iOS and Android using Phoenix LiveView & Elixir! · GitHub), I would normally do something like this:
{Desktop.Window,
[
# simplified for the sake of brevity
title: "Market Manager",
size: {940, 980},
icon: "static/images/resized_logo_5_32x32.png"
]}
Where size will be the size (in pixels) of the window of the application.
This is all fine if all my users have monitors of the same size. However, this is not the case.
Problem
So I need to know the dimensions of the screen size of the user in order to create a Window that is, lets say, 60% width and 70% height.
Since the underlying library (Desktop) does not support relative sizes for the window afaik, I need to calculate them myself.
To this effect I found no library that gives me this.
Question
How can I find the screen dimensions ?
Trending in Discussions
Other Trending Topics
Latest in /Elixir Desktop
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security











First 6 of 6 Posts
D4no0
Take a look at wxdisplay, it should be exactly what you are looking for.
Fl4m3Ph03n1x
From the docs (wxDisplay — OTP 29.0.2 (wx 2.6)) I understand I need to:
Being the first time I am using this library, do I really need the first line
_wx = :wx.new()?Am I missing something?
D4no0
No idea, read some documentation on how this is done in wx, as this is just a erlang wrapper for wx library.
Fl4m3Ph03n1x
My guess is that it starts a process responsible for getting messages from requests, as in, a central point where everything has to go through. This is based on the docs:
However, I could not find any confirmation if my interpretation is correct, thus I asked.
dominicletz
Yes, you’re right. you can typically also get the same effect by using
:wx.set_env(env)using an existingwx_envfor this there is a helper inDesktop.Env: Desktop.Env — Desktop v1.5.3Fl4m3Ph03n1x
In my specific use case, I cannot use
:wx.set_env(Desktop.Env.wx_env())as the Desktop application has not yet started:See my
application.ex:If I replace
_wx_object = :wx.new()with:wx.set_env(Desktop.Env.wx_env())then the application crashes on startup:Therefore, the solution I found (and works for me) is to create a temporary wx_object and then kill it, to avoid conflicts with Desktop, just like in the code snippet I shared above.
This also reminds me of one question: