How to detect display configuration?

#1

Hi there,

I’m switching again and again from my home station with multiple screens to my laptop… At home, I use the fullScreen(3) option, but working on my laptop screen I mostly use size(640,360).
Rather than always comment/uncomment lines, I’d like to add a statement in setup() —or maybe settings() — to decide by itself…

How could I get informations on the display configuration to do this ?
It’s a really small issue, I know, but it bother me anyway…

Thanks for reading.

1 Like
#2

You can check out displayWidth for example: :tv:
Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#displayWidth

1 Like
displayWidth: deprecation?
#3

Are you using the Processing IDE or some other tool?

The problem with looking at displayWidth/displayHeight is that fullScreen(…) / size(…) must be the first line in setup(). So you can’t do much there unless you evaluate a function or variable in there. You can’t pass width, height parameters to fullScreen and unless you want not to use fullScreen you shouldn’t use size(…) in Processing 3.x apparently.

You might be better off just leaving the fullScreen call the same and just changing which display to use in preferences. I don’t know how else Processing would have any idea which of the displays you want to run the sketch on at the moment.

1 Like
#4
#5

Well, thanks for your answers.

To answer questions, yes I’m using Processing IDE.
I’m running P 3.5.3 on OSX — I know, but it made sense to me once…

Indeed, displayWidth does the job with this little statement in settings() :

  if (displayWidth==1920) fullScreen(3);
   else  size(displayWidth/2, displayHeight/2);

Doing my researches, I found this post about surfaceLocation(), thanks to you GoToLoop :

https://forum.processing.org/two/discussion/14138/how-to-set-the-initial-location-of-the-canva-relative-to-screen-display

Using this, I’m able to set the location of the draw window in laptop only mode, so that it doesn’t overlap the editor and then, my issue is fixed…

… BUT there’s still things I don’t understand. Unplugging my third screen, I got these lines in my console :

Display 3 does not exist, using the default display instead.
Display 1 is sun.awt.CGraphicsDevice@5649fd9b
Display 2 is sun.awt.CGraphicsDevice@6adede5

It looks to me that if Processing can retrieve these informations, there should be a way for me to get and use them, no ?

1 Like
#6

There’s a difference between Java (and indirectly, Processing) knowing what displays exist and knowing which one you want to use. It might be possible to call a function inside size() or fullScreen() if you could work out what that function should do, but it needs to be able to do so without any input.

E.g.

void setup() {
    size( getDisplay(parameter).getWidth(), getDisplay(parameter).getHeight() );
}

or

void setup() {
    fullScreen( getDisplay(parameter).getId() );
}

Not sure if stuff in setup can safely use pre-defined variables, but if you always use the same screens you could create some kind of mapping from pre-defined sizes to the display you think it. That would be useless for production, so to speak, but fine for development purposes.

#7

It can’t – at least, size() in setup() can’t – but that is what settings() is for.

The settings() function is new with Processing 3.0. It’s not needed in most sketches. It’s only useful when it’s absolutely necessary to define the parameters to size() with a variable. https://processing.org/reference/settings_.html