# Getting the window position in P2D

**URL:** <https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543>\
**Category:** Coding Questions\
**Created:** [December 22, 2023, 11:47pm UTC](https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543 "2023-12-22T23:47:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noodlybanan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noodlybanan/32/18897_2.png) [@Noodlybanan](https://discourse.processing.org/u/Noodlybanan)\
**Post date:** [December 22, 2023, 11:47pm UTC](https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543/1 "2023-12-22T23:47:55Z")

</div>

Hello 🙂  
I want to get the window position of a window to if the window is offscreen correct it & correctly implement 3d movement (rotation with mouse). However, the versions i saw don’t work on P2D, P3D or any other renderer.  
Does anyone know how to get the position?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 23, 2023, 2:29am UTC](https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543/2 "2023-12-23T02:29:02Z")

</div>

There’s this very old sketch I’ve been working on but never finished:

> <https://gist.github.com/GoToLoop/1d1eb18f468a7d5758469707276b6ea1>

But it has some techniques to capture the correct _window_ type according to current canvas type.

This is the part where the generic _window_ field is initialized:

```auto
public CanvasResizeWatcher(final PApplet pa, boolean now) {
  window = ( p = pa ).getSurface().getNative();
  pg = pa.getGraphics();
  immediate = now;
}

```

And the part where field _window_ is cast to the specific datatype for OPENGL (P2D & P3D) as field _win_, which is [Window](https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/Window.html):

```auto
public class SizeListenerOPENGL extends WindowAdapter implements SizeListener {
  public final Window win = (Window) window;

```

---

<div class="post-metadata">

**Author:** ![Noodlybanan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noodlybanan/32/18897_2.png) [@Noodlybanan](https://discourse.processing.org/u/Noodlybanan)\
**Post date:** [December 23, 2023, 11:20pm UTC](https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543/3 "2023-12-23T23:20:38Z")

</div>

Thanks, however i don’t know how to use this. Still thank you 😃

---

<div class="post-metadata">

**Author:** ![Edenstudent](https://avatars.discourse-cdn.com/v4/letter/e/58956e/32.png) [@Edenstudent](https://discourse.processing.org/u/Edenstudent)\
**Post date:** [February 15, 2024, 6:59am UTC](https://discourse.processing.org/t/getting-the-window-position-in-p2d/43543/4 "2024-02-15T06:59:14Z")

</div>

This came out for Processing3 (when surface replaced frame), it may work for getting the location:

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/17675/index.html#Comment_72991)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

As for setting it, use this:

> **[setLocation() / Reference](https://processing.org/reference/setLocation_.html)**
>
> The setLocation() function defines the position of the Processing sketch in relation to the upper-left corner of the computer screen. There are more features of PSurface documented…
