Dynamically Setting the Window as Undecorated

  • What even IS this/?/1!?1?
    So you know how video games (like Minecraft!!1!) resize the window to ‘fullscreen’ when you press F11? This does that. Setting the window to “undecorated” means to remove the title bar, the window maximize, window minimize, and window close buttons.

  • How did you do it, ("o_O))?
    Right: here is an explanation as to how this works:
    Basically, the window.setUndecorated() method runs a new thread. If you continue to use draw(), you are rendering graphics to the screen, which disrupts, or interrupts that thread.
    To avoid that, I simply put a while loop to wait till the thread is done.
    The if exists to check if the window was already set to undecorated, and if it needs to be done again, since it takes a bit of time to set the window as undecorated!

  • Why do I set the window to invisible and then visible?
    Because for some reason, it resizes it perfectly to fit the screen, and also makes the taskbar disappear. It is needed even though there is a surface.setLocation(0, 0);

  • Why am I using a method called ‘post()’ and what is it?!
    Processing “handles” the draw() function inside a function called handleDraw(), which runs every frame. However, to ensure that the draw() function is ‘safe’ to use (so you didn’t change things and cause random errors all the time), the Processing development team made sure that you couldn’t access them. Problem: libraries need this functionality, and so do we! So they allowed it to be extended and made two more methods, called pre() and post(), which are called before and after draw() is executed, respectively.

  • Why so many ifs?!
    If you’ve ran this code, you know how long it takes to do the task! The ifs ensure that the task isn’t done every single frame - it’s an optimization. But the solution as a whole isn’t as optimized.
    I’ll post the ‘optimized’ version of the code soon!
    Check the solution answer here
    , ":D!

  • What’s this “window” object?!
    This is a way to dig into Processing’s workings and do some of this stuff. I myself came to know about it from here, months ago: Get location of a PApplet window - #10 by micycle
    To know what it contains, check the solution answer here

1 Like