Make window snap in to the borders

Is there a way to make the window snap in, so being fullscreen basically except for the taskbar?

void setup() {
  surface.setSize(300,300);
  surface.setResizable(true);
}

this does the trick!

2 Likes

I mean rather in a way that it snaps in on startup, instead of having to click the button of the window myself, is there a way to do that?

One step further, but now we have to discover how to place it top left on startup.

import java.awt.*;

void setup() {
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  int screenHeight = screenSize.height;
  int screenWidth = screenSize.width;
  surface.setSize(screenWidth, screenHeight);
  surface.setResizable(true);
}
2 Likes

Okay, that was easy. Just add:
surface.setLocation(0, 0);

1 Like

Processing has screenWidth and screenHeight variables built in as displayWidth and displayHeight:

void setup() {
  size(displayWidth, displayHeight);
  surface.setResizable(true);
}

@qewer3322
Thanks, thus they placed it again. It was considered deprecated before. See here.

1 Like

I guess that almost does it, except it doesn’t account for taskbar size, it isn’t exactly equivalent to hitting the snap to screen button in windows, but I suppose I 'll just leave it at manually clicking that button every time.

There is also the window height without taskbar.
But I still adjust it a bit to see the borders.

import java.awt.*;

void setup() {
  Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
  println(winSize.height);
  println(displayHeight);
  surface.setSize(int(displayWidth*.99), int(winSize.height*.96));
  surface.setResizable(true);
  surface.setLocation(5, 5);
}